# -*- 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 Sfc5xxxCmdUserMemoryAccessBase(ShdlcCommand):
    """
    SHDLC command 0x6E: "User Memory Access".
    """
[docs]    def __init__(self, *args, **kwargs):
        """
        Constructor.
        """
        super(Sfc5xxxCmdUserMemoryAccessBase, self).__init__(
            0x6E, *args, **kwargs)  
[docs]class Sfc5xxxCmdReadUserMemory(Sfc5xxxCmdUserMemoryAccessBase):
    """
    Read User Memory Command
    Read data from the user memory.
    """
[docs]    def __init__(self, address, length):
        """
        Constructor.
        :param int address:
            Address from where to start reading.
        :param int length:
            Defines how many bytes should be read.
        """
        super(Sfc5xxxCmdReadUserMemory, self).__init__(
            data=b"".join([pack(">B", address),
                           pack(">B", length)]),
            max_response_time=0.01,
            post_processing_time=0.0,
            min_response_length=0,
            max_response_length=255
        ) 
[docs]    @staticmethod
    def interpret_response(data):
        """
        :return: The read data.
        :rtype: bytes
        """
        read_data = bytes(data[0:])  # bytearray
        return read_data  
[docs]class Sfc5xxxCmdWriteUserMemory(Sfc5xxxCmdUserMemoryAccessBase):
    """
    Write User Memory Command
    Write data into the user memory.
    """
[docs]    def __init__(self, address, length, write_data):
        """
        Constructor.
        :param int address:
            Address from where to start writing.
        :param int length:
            Defines how many bytes should be written.
        :param bytes write_data:
            The data to be written.
        """
        super(Sfc5xxxCmdWriteUserMemory, self).__init__(
            data=b"".join([pack(">B", address),
                           pack(">B", length),
                           bytes(bytearray(write_data))]),
            max_response_time=0.01,
            post_processing_time=0.0,
            min_response_length=0,
            max_response_length=0
        )