# -*- coding: utf-8 -*-
# (c) Copyright 2020 Sensirion AG, Switzerland
##############################################################################
##############################################################################
# _____ _ _ _______ _____ ____ _ _
# / ____| /\ | | | |__ __|_ _/ __ \| \ | |
# | | / \ | | | | | | | || | | | \| |
# | | / /\ \| | | | | | | || | | | . ` |
# | |____ / ____ \ |__| | | | _| || |__| | |\ |
# \_____/_/ \_\____/ |_| |_____\____/|_| \_|
#
# THIS FILE IS AUTOMATICALLY GENERATED AND MUST NOT BE EDITED MANUALLY!
#
# Generator: sensirion-shdlc-interface-generator 0.8.2
# Product: SVM40
# Version: 0.3.0
#
##############################################################################
##############################################################################
# flake8: noqa
from __future__ import absolute_import, division, print_function
from sensirion_shdlc_driver.command import ShdlcCommand
from struct import pack, unpack
import logging
log = logging.getLogger(__name__)
[docs]class Svm40CmdAlgorithmParametersBase(ShdlcCommand):
"""
SHDLC command 0x60: "Algorithm Parameters".
"""
[docs] def __init__(self, *args, **kwargs):
"""
Constructor.
"""
super(Svm40CmdAlgorithmParametersBase, self).__init__(
0x60, *args, **kwargs)
[docs]class Svm40CmdGetTemperatureOffsetForRhtMeasurements(Svm40CmdAlgorithmParametersBase):
"""
Get Temperature Offset For Rht Measurements Command
Gets the T-Offset for the temperature compensation of the RHT algorithm.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Svm40CmdGetTemperatureOffsetForRhtMeasurements, self).__init__(
data=b"".join([bytes(bytearray([0x01]))]),
max_response_time=0.05,
post_processing_time=0.0,
min_response_length=0,
max_response_length=255
)
[docs] @staticmethod
def interpret_response(data):
"""
:return: Temperature offset whith is used for the RHT measurements.
Firmware versions prior to 2.0 will return a float value (4
bytes). For firmware version >= 2.0 an int16 value (2 bytes)
is returned. Float temperature values are in degrees celsius
with no scaling. Integer temperature values are in degrees
celsius with a scaling of 200.
:rtype: bytes
"""
t_offset = bytes(data[0:]) # bytearray
return t_offset
[docs]class Svm40CmdGetVocTuningParameters(Svm40CmdAlgorithmParametersBase):
"""
Get Voc Tuning Parameters Command
Gets the currently set parameters for customizing the VOC algorithm
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Svm40CmdGetVocTuningParameters, self).__init__(
data=b"".join([bytes(bytearray([0x08]))]),
max_response_time=0.05,
post_processing_time=0.0,
min_response_length=8,
max_response_length=8
)
[docs] @staticmethod
def interpret_response(data):
"""
:return:
- voc_index_offset (int) -
VOC index representing typical (average) conditions. The default
value is 100.
- learning_time_hours (int) -
Time constant of long-term estimator in hours. Past events will
be forgotten after about twice the learning time. The default
value is 12 hours.
- gating_max_duration_minutes (int) -
Maximum duration of gating in minutes (freeze of estimator during
high VOC index signal). Zero disables the gating. The default
value is 180 minutes.
- std_initial (int) -
Initial estimate for standard deviation. Lower value boosts
events during initial learning period, but may result in larger
device-to-device variations. The default value is 50.
:rtype: tuple
"""
voc_index_offset = int(unpack(">h", data[0:2])[0]) # int16
learning_time_hours = int(unpack(">h", data[2:4])[0]) # int16
gating_max_duration_minutes = int(unpack(">h", data[4:6])[0]) # int16
std_initial = int(unpack(">h", data[6:8])[0]) # int16
return voc_index_offset,\
learning_time_hours,\
gating_max_duration_minutes,\
std_initial
[docs]class Svm40CmdStoreNvData(Svm40CmdAlgorithmParametersBase):
"""
Store Nv Data Command
Stores all algorithm parameters to the non-volatile memory.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Svm40CmdStoreNvData, self).__init__(
data=b"".join([bytes(bytearray([0x80]))]),
max_response_time=0.5,
post_processing_time=0.0,
min_response_length=0,
max_response_length=0
)
[docs]class Svm40CmdSetTemperatureOffsetForRhtMeasurements(Svm40CmdAlgorithmParametersBase):
"""
Set Temperature Offset For Rht Measurements Command
Sets the T-Offset for the temperature compensation of the RHT algorithm.
.. note:: Execute the store command after writing the parameter to store it
in the non-volatile memory of the device otherwise the parameter
will be reset upton a device reset.
"""
[docs] def __init__(self, t_offset):
"""
Constructor.
:param bytes t_offset:
Temperature offset in degrees celsius. Accepted data formats are
either a float value (4 bytes) or an int16 value (2 bytes). Float
temperature values are in degrees celsius with no scaling. Integer
temperature values are in degrees celsius with a scaling of 200.
"""
super(Svm40CmdSetTemperatureOffsetForRhtMeasurements, self).__init__(
data=b"".join([bytes(bytearray([0x81])),
bytes(bytearray(t_offset))]),
max_response_time=0.05,
post_processing_time=0.0,
min_response_length=0,
max_response_length=0
)
[docs]class Svm40CmdSetVocTuningParameters(Svm40CmdAlgorithmParametersBase):
"""
Set Voc Tuning Parameters Command
Sets parameters to customize the VOC algorithm. This command is only
available in idle mode.
.. note:: Execute the store command after writing the parameter to store it
in the non-volatile memory of the device otherwise the parameter
will be reset upton a device reset.
"""
[docs] def __init__(self, voc_index_offset, learning_time_hours, gating_max_duration_minutes, std_initial):
"""
Constructor.
:param int voc_index_offset:
VOC index representing typical (average) conditions. The default
value is 100.
:param int learning_time_hours:
Time constant of long-term estimator in hours. Past events will be
forgotten after about twice the learning time. The default value is
12 hours.
:param int gating_max_duration_minutes:
Maximum duration of gating in minutes (freeze of estimator during
high VOC index signal). Set to zero to disable the gating. The
default value is 180 minutes.
:param int std_initial:
Initial estimate for standard deviation. Lower value boosts events
during initial learning period, but may result in larger
device-to-device variations. The default value is 50.
"""
super(Svm40CmdSetVocTuningParameters, self).__init__(
data=b"".join([bytes(bytearray([0x88])),
pack(">h", voc_index_offset),
pack(">h", learning_time_hours),
pack(">h", gating_max_duration_minutes),
pack(">h", std_initial)]),
max_response_time=0.05,
post_processing_time=0.0,
min_response_length=0,
max_response_length=0
)