# -*- 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: SFC5xxx
# Version: 0.1.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 Sfc5xxxCmdAdvancedMeasurementsBase(ShdlcCommand):
"""
SHDLC command 0x30: "Advanced Measurements".
"""
[docs] def __init__(self, *args, **kwargs):
"""
Constructor.
"""
super(Sfc5xxxCmdAdvancedMeasurementsBase, self).__init__(
0x30, *args, **kwargs)
[docs]class Sfc5xxxCmdMeasureRawFlow(Sfc5xxxCmdAdvancedMeasurementsBase):
"""
Measure Raw Flow Command
Perform a flow measurement and return the measured raw flow ticks from the
sensor.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sfc5xxxCmdMeasureRawFlow, self).__init__(
data=b"".join([bytes(bytearray([0x00]))]),
max_response_time=0.05,
post_processing_time=0.0,
min_response_length=2,
max_response_length=2
)
[docs] @staticmethod
def interpret_response(data):
"""
:return: Measured raw flow in ticks.
:rtype: int
"""
flow = int(unpack(">H", data[0:2])[0]) # uint16
return flow
[docs]class Sfc5xxxCmdMeasureRawThermalConductivity(Sfc5xxxCmdAdvancedMeasurementsBase):
"""
Measure Raw Thermal Conductivity Command
Perform a thermal conductivity measurement and return the measured raw tick
value.
.. note:: The valve must be fully closed for at least 500ms to get correct
results!
"""
[docs] def __init__(self, use_temperature_compensation=None):
"""
Constructor.
:param int use_temperature_compensation:
This parameter (existing since V1.56) allows to choose between
uncompensated and temperature compensated measurement. If this
parameter is not used, the compensated value will be returned if
possible, otherwise the uncompensated value will be returned:
- 0x00: Read uncompensated thermal conductivity
- 0x01: Read temperature compensated thermal conductivity
This parameter is optional. When passing ``None`` (the default),
it is not sent to the device at all.
"""
super(Sfc5xxxCmdMeasureRawThermalConductivity, self).__init__(
data=b"".join([bytes(bytearray([0x01])),
pack(">B", use_temperature_compensation) if use_temperature_compensation is not None else b""]),
max_response_time=0.05,
post_processing_time=0.0,
min_response_length=2,
max_response_length=2
)
[docs] @staticmethod
def interpret_response(data):
"""
:return: Measured raw thermal conductivity in ticks.
:rtype: int
"""
thermal_conductivity = int(unpack(">H", data[0:2])[0]) # uint16
return thermal_conductivity
[docs]class Sfc5xxxCmdMeasureRawThermalConductivityWithClosedValve(Sfc5xxxCmdAdvancedMeasurementsBase):
"""
Measure Raw Thermal Conductivity With Closed Valve Command
Perform a thermal conductivity measurement and return the measured raw tick
value. The valve is automatically closed during the measurement.
"""
[docs] def __init__(self, use_temperature_compensation=None):
"""
Constructor.
:param int use_temperature_compensation:
This parameter (existing since V1.56) allows to choose between
uncompensated and temperature compensated measurement. If this
parameter is not used, the compensated value will be returned if
possible, otherwise the uncompensated value will be returned:
- 0x00: Read uncompensated thermal conductivity
- 0x01: Read temperature compensated thermal conductivity
This parameter is optional. When passing ``None`` (the default),
it is not sent to the device at all.
"""
super(Sfc5xxxCmdMeasureRawThermalConductivityWithClosedValve, self).__init__(
data=b"".join([bytes(bytearray([0x02])),
pack(">B", use_temperature_compensation) if use_temperature_compensation is not None else b""]),
max_response_time=0.6,
post_processing_time=0.0,
min_response_length=2,
max_response_length=2
)
[docs] @staticmethod
def interpret_response(data):
"""
:return: Measured raw thermal conductivity in ticks.
:rtype: int
"""
thermal_conductivity = int(unpack(">H", data[0:2])[0]) # uint16
return thermal_conductivity
[docs]class Sfc5xxxCmdMeasureTemperature(Sfc5xxxCmdAdvancedMeasurementsBase):
"""
Measure Temperature Command
Perform a gas temperature measurement.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sfc5xxxCmdMeasureTemperature, self).__init__(
data=b"".join([bytes(bytearray([0x10]))]),
max_response_time=0.05,
post_processing_time=0.0,
min_response_length=4,
max_response_length=4
)
[docs] @staticmethod
def interpret_response(data):
"""
:return: Measured temperature [°C].
:rtype: float
"""
temperature = float(unpack(">f", data[0:4])[0]) # float
return temperature