# -*- 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 Sfc5xxxCmdSlaveAddressBase(ShdlcCommand):
"""
SHDLC command 0x90: "Slave Address".
"""
[docs] def __init__(self, *args, **kwargs):
"""
Constructor.
"""
super(Sfc5xxxCmdSlaveAddressBase, self).__init__(
0x90, *args, **kwargs)
[docs]class Sfc5xxxCmdGetSlaveAddress(Sfc5xxxCmdSlaveAddressBase):
"""
Get Slave Address Command
Get the SHDLC slave address of the device.
"""
[docs] def __init__(self):
"""
Constructor.
"""
super(Sfc5xxxCmdGetSlaveAddress, self).__init__(
data=[],
max_response_time=0.01,
post_processing_time=0.0,
min_response_length=1,
max_response_length=1
)
[docs] @staticmethod
def interpret_response(data):
"""
:return: The current slave address of the device.
:rtype: int
"""
slave_address = int(unpack(">B", data[0:1])[0]) # uint8
return slave_address
[docs]class Sfc5xxxCmdSetSlaveAddress(Sfc5xxxCmdSlaveAddressBase):
"""
Set Slave Address Command
Set the SHDLC slave address of the device.
.. note:: The slave address is stored in non-volatile memory of the device
and thus persists after a device reset. So the next time
connecting to the device, you have to use the new address. When
changing the address of a slave, make sure there isn't already a
slave with that address on the same bus! In that case you would
get communication issues which can only be fixed by disconnecting
one of the slaves.
"""
[docs] def __init__(self, slave_address):
"""
Constructor.
:param int slave_address:
The new slave address to set.
"""
super(Sfc5xxxCmdSetSlaveAddress, self).__init__(
data=b"".join([pack(">B", slave_address)]),
max_response_time=0.01,
post_processing_time=0.0,
min_response_length=0,
max_response_length=0
)