# Path: conpot/utils/networking.py
# def chr_py3(x):
#     return bytearray((x,))


import logging
from crc16.crc16pure import crc16xmodem
from conpot.utils.networking import chr_py3
from . import kamstrup_constants
                # unknown_byte_B = msg[i + 2]

                # Payload
                register_value = 0
                for p in range(length):
                    register_value += msg[i + 5 + p] << (8 * ((length - p) - 1))
                if register in Decoder382.REGISTERS:
                    return_value += "{0}({1}):{2}, ".format(
                        register, Decoder382.REGISTERS[register], register_value
                    )
                else:
                    return_value += "{0}:{1}, ".format(register, register_value)
                i += 5 + length

        return return_value

    # meter type
    def _decode_cmd_get_type(self):
        assert self.in_data[2] == 0x01
        return "Request for GetType"

    def _decode_cmd_login(self):
        assert self.in_data[2] == 0x92
        pin_code = self.in_data[3] * 256 + self.in_data[4]
        return "Login command with pin_code: {0}".format(pin_code)

    # supplied message should be stripped of leading and trailing magic
    @classmethod
    def valid_crc(cls, message):
        supplied_crc = message[-2] * 256 + message[-1]

# Path: conpot/utils/networking.py
# def chr_py3(x):
#     return bytearray((x,))


# Path: conpot/protocols/kamstrup_meter/decoder_382.py
import logging
from crc16.crc16pure import crc16xmodem
from conpot.utils.networking import chr_py3
from . import kamstrup_constants

                # unknown_byte_B = msg[i + 2]

                # Payload
                register_value = 0
                for p in range(length):
                    register_value += msg[i + 5 + p] << (8 * ((length - p) - 1))
                if register in Decoder382.REGISTERS:
                    return_value += "{0}({1}):{2}, ".format(
                        register, Decoder382.REGISTERS[register], register_value
                    )
                else:
                    return_value += "{0}:{1}, ".format(register, register_value)
                i += 5 + length

        return return_value

    # meter type
    def _decode_cmd_get_type(self):
        assert self.in_data[2] == 0x01
        return "Request for GetType"

    def _decode_cmd_login(self):
        assert self.in_data[2] == 0x92
        pin_code = self.in_data[3] * 256 + self.in_data[4]
        return "Login command with pin_code: {0}".format(pin_code)

    # supplied message should be stripped of leading and trailing magic
    @classmethod
    def valid_crc(cls, message):
        supplied_crc = message[-2] * 256 + message[-1]

        calculated_crc = crc16xmodem(b"".join([chr_py3(item) for item in message[:-2]]))