def test_multi_messages(self): core_communicator = Mock() ucan_communicator = UCANCommunicator(master_communicator=core_communicator) cc_address = '000.000.000.000' ucan_address = '000.000.000' command = UCANCommandSpec(sid=SID.NORMAL_COMMAND, identifier=AddressField('ucan_address', 3), instructions=[Instruction(instruction=[0, 10]), Instruction(instruction=[0, 10])], request_fields=[[LiteralBytesField(1)], [LiteralBytesField(2)]], response_instructions=[Instruction(instruction=[1, 10], checksum_byte=7), Instruction(instruction=[2, 10], checksum_byte=7)], response_fields=[ByteArrayField('foo', 4)]) ucan_communicator.do_command(cc_address, command, ucan_address, {}, timeout=None) consumer = ucan_communicator._consumers[cc_address][0] # Build and validate fake reply from Core payload_reply_1 = bytearray([1, 10, 0, 0, 0, 20, 21]) payload_reply_2 = bytearray([2, 10, 0, 0, 0, 22, 23]) ucan_communicator._process_transport_message({'cc_address': cc_address, 'nr_can_bytes': 8, 'sid': 5, 'payload': payload_reply_1 + bytearray([UCANCommandSpec.calculate_crc(payload_reply_1)])}) ucan_communicator._process_transport_message({'cc_address': cc_address, 'nr_can_bytes': 8, 'sid': 5, 'payload': payload_reply_2 + bytearray([UCANCommandSpec.calculate_crc(payload_reply_2)])}) self.assertDictEqual(consumer.get(1), {'foo': [20, 21, 22, 23]})
def get_amount_of_ucans(): # type: () -> CoreCommandSpec """ Receives amount of uCAN modules """ return CoreCommandSpec(instruction='FS', request_fields=[ AddressField('cc_address'), LiteralBytesField(0), LiteralBytesField(0) ], response_fields=[ AddressField('cc_address'), PaddingField(2), ByteField('amount'), PaddingField(2) ])
def get_firmware_version(): # type: () -> CoreCommandSpec """ Receives the Core firmware version """ return CoreCommandSpec( instruction='ST', request_fields=[LiteralBytesField(1)], response_fields=[ByteField('info_type'), VersionField('version')])
def get_slave_bus_mode(): # type: () -> CoreCommandSpec """ Receives the slave bus mode """ return CoreCommandSpec( instruction='ST', request_fields=[LiteralBytesField(0)], response_fields=[ByteField('info_type'), ByteField('mode')])
def request_slave_firmware_versions(): # type: () -> CoreCommandSpec """ Requests the slave firmware versions, which will be send to the GW in separate FW calls """ return CoreCommandSpec( instruction='ST', request_fields=[LiteralBytesField(2)], response_fields=[ByteField('info_type'), PaddingField(2)])
def device_information_list_inputs(): # type: () -> CoreCommandSpec """ Device information list for inputs """ return CoreCommandSpec(instruction='DL', request_fields=[LiteralBytesField(1)], response_fields=[ ByteField('type'), ByteArrayField('information', lambda length: length - 1) ])
def get_master_modes(): # type: () -> CoreCommandSpec """ Receives various master modes (rs485 bus mode, BA debug mode) """ return CoreCommandSpec(instruction='ST', request_fields=[LiteralBytesField(0)], response_fields=[ ByteField('info_type'), ByteField('rs485_mode'), ByteField('ba_debug_mode') ])
def get_version(): # type: () -> UCANCommandSpec """ Gets a uCAN version """ return UCANCommandSpec(sid=SID.NORMAL_COMMAND, identifier=AddressField('ucan_address', 3), instructions=[ Instruction(instruction=[0, 198]), Instruction(instruction=[0, 198]) ], request_fields=[[LiteralBytesField(5)], [LiteralBytesField(6)]], response_instructions=[ Instruction(instruction=[5, 199], checksum_byte=7), Instruction(instruction=[6, 199], checksum_byte=7) ], response_fields=[ ByteField('sensor_type'), VersionField('firmware_version') ])
def _sensor_values(instruction, field): # type: (int, Field) -> CoreCommandSpec """ Receive sensor byte values """ return CoreCommandSpec( instruction='SI', request_fields=[ ByteField('module_nr'), LiteralBytesField(instruction) ], response_fields=[ByteField('module_nr'), PaddingField(1), field])
def get_ucan_address(): # type: () -> CoreCommandSpec """ Receives the uCAN address of a specific uCAN """ return CoreCommandSpec(instruction='FS', request_fields=[ AddressField('cc_address'), LiteralBytesField(1), ByteField('ucan_nr') ], response_fields=[ AddressField('cc_address'), PaddingField(2), AddressField('ucan_address', 3) ])
def get_date_time(): # type: () -> CoreCommandSpec """ Reads the date/time from the Core """ return CoreCommandSpec(instruction='TR', request_fields=[LiteralBytesField(0)], response_fields=[ ByteField('info_type'), ByteField('hours'), ByteField('minutes'), ByteField('seconds'), ByteField('weekday'), ByteField('day'), ByteField('month'), ByteField('year') ])
def general_configuration_max_specs(): # type: () -> CoreCommandSpec """ Receives general configuration regarding maximum specifications (e.g. max number of input modules, max number of basic actions, ...) """ return CoreCommandSpec(instruction='GC', request_fields=[LiteralBytesField(1)], response_fields=[ ByteField('type'), ByteField('output'), ByteField('input'), ByteField('sensor'), ByteField('ucan'), WordField('groups'), WordField('basic_actions'), ByteField('shutters'), ByteField('shutter_groups') ])
def general_configuration_number_of_modules( ): # type: () -> CoreCommandSpec """ Receives general configuration regarding number of modules """ return CoreCommandSpec(instruction='GC', request_fields=[LiteralBytesField(0)], response_fields=[ ByteField('type'), ByteField('output'), ByteField('input'), ByteField('sensor'), ByteField('ucan'), ByteField('ucan_input'), ByteField('ucan_sensor'), ByteField('power_rs485'), ByteField('power_can') ])