# -*- 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 Sfc5xxxCmdMediumUnitConfigurationBase(ShdlcCommand):
"""
SHDLC command 0x21: "Medium Unit Configuration".
"""
[docs] def __init__(self, *args, **kwargs):
"""
Constructor.
"""
super(Sfc5xxxCmdMediumUnitConfigurationBase, self).__init__(
0x21, *args, **kwargs)
[docs]class Sfc5xxxCmdGetUserDefinedMediumUnit(Sfc5xxxCmdMediumUnitConfigurationBase):
"""
Get User Defined Medium Unit Command
Get the user defined medium unit.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sfc5xxxCmdGetUserDefinedMediumUnit, self).__init__(
data=b"".join([bytes(bytearray([0x00]))]),
max_response_time=0.005,
post_processing_time=0.0,
min_response_length=3,
max_response_length=3
)
[docs] @staticmethod
def interpret_response(data):
"""
:return:
- prefix (int) -
Medium unit prefix, see appendix for encoding. 0x7F = Use medium
unit prefix from calibration.
- unit (int) -
Medium unit, see appendix for encoding. 0xFF = Use medium unit
from calibration.
- timebase (int) -
Timebase, see appendix for encoding. 0xFF = Use timebase from
calibration.
:rtype: tuple
"""
prefix = int(unpack(">b", data[0:1])[0]) # int8
unit = int(unpack(">B", data[1:2])[0]) # uint8
timebase = int(unpack(">B", data[2:3])[0]) # uint8
return prefix,\
unit,\
timebase
[docs]class Sfc5xxxCmdSetUserDefinedMediumUnit(Sfc5xxxCmdMediumUnitConfigurationBase):
"""
Set User Defined Medium Unit Command
Set the user defined medium unit.
.. note:: This configuration is stored in non-volatile memory of the device
and thus persists after a device reset.
"""
[docs] def __init__(self, prefix, unit, timebase):
"""
Constructor.
:param int prefix:
Medium unit prefix, see appendix for encoding. 0x7F = Use medium
unit prefix from calibration.
:param int unit:
Medium unit, see appendix for encoding. 0xFF = Use medium unit from
calibration.
:param int timebase:
Timebase, see appendix for encoding. 0xFF = Use timebase from
calibration.
"""
super(Sfc5xxxCmdSetUserDefinedMediumUnit, self).__init__(
data=b"".join([bytes(bytearray([0x00])),
pack(">b", prefix),
pack(">B", unit),
pack(">B", timebase)]),
max_response_time=0.005,
post_processing_time=0.0,
min_response_length=0,
max_response_length=0
)
[docs]class Sfc5xxxCmdGetUserDefinedMediumUnitWithoutWildcards(Sfc5xxxCmdMediumUnitConfigurationBase):
"""
Get User Defined Medium Unit Without Wildcards Command
Get the user defined medium unit with wildcards substituted with their
actual units.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sfc5xxxCmdGetUserDefinedMediumUnitWithoutWildcards, self).__init__(
data=b"".join([bytes(bytearray([0x01]))]),
max_response_time=0.005,
post_processing_time=0.0,
min_response_length=3,
max_response_length=3
)
[docs] @staticmethod
def interpret_response(data):
"""
:return:
- prefix (int) -
Medium unit prefix, see appendix for encoding.
- unit (int) -
Medium unit, see appendix for encoding.
- timebase (int) -
Timebase, see appendix for encoding.
:rtype: tuple
"""
prefix = int(unpack(">b", data[0:1])[0]) # int8
unit = int(unpack(">B", data[1:2])[0]) # uint8
timebase = int(unpack(">B", data[2:3])[0]) # uint8
return prefix,\
unit,\
timebase
[docs]class Sfc5xxxCmdGetUserDefinedFullscale(Sfc5xxxCmdMediumUnitConfigurationBase):
"""
Get User Defined Fullscale Command
Get the fullscale flow in the user defined medium unit.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sfc5xxxCmdGetUserDefinedFullscale, self).__init__(
data=b"".join([bytes(bytearray([0x0A]))]),
max_response_time=0.005,
post_processing_time=0.0,
min_response_length=4,
max_response_length=4
)
[docs] @staticmethod
def interpret_response(data):
"""
:return: Fullscale for user defined medium unit.
:rtype: float
"""
fullscale = float(unpack(">f", data[0:4])[0]) # float
return fullscale