Source code for sensirion_shdlc_sfc5xxx.commands.read_device_status

# -*- 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 Sfc5xxxCmdReadDeviceStatusBase(ShdlcCommand): """ SHDLC command 0xD2: "Read Device Status". """
[docs] def __init__(self, *args, **kwargs): """ Constructor. """ super(Sfc5xxxCmdReadDeviceStatusBase, self).__init__( 0xD2, *args, **kwargs)
[docs]class Sfc5xxxCmdReadDeviceStatus(Sfc5xxxCmdReadDeviceStatusBase): """ Read Device Status Command Read the current device status. .. note:: When the device is running, some error situations can be detected. These errors will be memorized as flags in the state register of the device. If one or more of the error flags are set, this will be signalized to the master by setting the "Device Error Flag" in the state information byte of the MISO frame (see frame description). With this command you can readout the state register containing the 32 flags. Find a list of all flags in the appendix. """
[docs] def __init__(self, clear): """ Constructor. :param bool clear: Set to true to clear the error flags after reading. Note: if the error situation remains after clearing, the flag will be set again (except the boot error flag #0). """ super(Sfc5xxxCmdReadDeviceStatus, self).__init__( data=b"".join([pack(">?", clear)]), max_response_time=0.01, post_processing_time=0.0, min_response_length=5, max_response_length=5 )
[docs] @staticmethod def interpret_response(data): """ :return: - device_status (int) - The device status as a register where 32 independent flags can be signalized. The meaning of the bits is defined in the appendix. - boot_error (int) - If an error occurred during system boot, this will be marked by setting flag #0 in the status register. In addition to the flag, this error code defines what exactly went wrong. :rtype: tuple """ device_status = int(unpack(">I", data[0:4])[0]) # uint32 boot_error = int(unpack(">B", data[4:5])[0]) # uint8 return device_status,\ boot_error