Ejemplo n.º 1
0
 def event_information():
     """ Event information """
     return CoreCommandSpec(instruction='EV',
                            response_fields=[
                                ByteField('type'),
                                ByteField('action'),
                                WordField('device_nr'),
                                ByteArrayField('data', 4)
                            ])
Ejemplo n.º 2
0
 def device_information_list_inputs():
     """ Device information list for inputs """
     return CoreCommandSpec(instruction='DL',
                            request_fields=[LiteralBytesField(1)],
                            response_fields=[
                                ByteField('type'),
                                ByteArrayField('information',
                                               lambda length: length - 1)
                            ])
Ejemplo n.º 3
0
 def ucan_rx_transport_message():
     """ uCAN transport layer packages """
     return CoreCommandSpec(instruction='FM',
                            response_fields=[
                                AddressField('cc_address'),
                                ByteField('nr_can_bytes'),
                                ByteField('sid'),
                                ByteArrayField('payload', 8)
                            ])
Ejemplo n.º 4
0
 def write_flash(data_length):
     """
     Writes uCAN flash
     Note: uCAN needs to be in bootloader
     """
     return UCANPalletCommandSpec(
         identifier=AddressField('ucan_address', 3),
         pallet_type=PalletType.FLASH_WRITE_REQUEST,
         request_fields=[
             Int32Field('start_address'),
             ByteArrayField('data', data_length)
         ])
Ejemplo n.º 5
0
    def test_pallet_reconstructing(self):
        received_commands = []

        def send_command(_cid, _command, _fields):
            received_commands.append(_fields)

        core_communicator = CoreCommunicator(controller_serial=Mock(), verbose=True)
        core_communicator._send_command = send_command
        ucan_communicator = UCANCommunicator(master_communicator=core_communicator, verbose=True)
        cc_address = '000.000.000.000'
        ucan_address = '000.000.000'
        pallet_type = PalletType.MCU_ID_REQUEST  # Not important for this test

        for length in [1, 3]:
            # Build command
            command = UCANPalletCommandSpec(identifier=AddressField('ucan_address', 3),
                                            pallet_type=pallet_type,
                                            request_fields=[ByteField('foo'), ByteField('bar')],
                                            response_fields=[ByteArrayField('other', length)])

            # Send command to mocked Core communicator
            received_commands = []
            ucan_communicator.do_command(cc_address, command, ucan_address, {'foo': 1, 'bar': 2}, timeout=None)

            # Validate whether the correct data was send to the Core
            self.assertEqual(len(received_commands), 2)
            self.assertDictEqual(received_commands[0], {'cc_address': cc_address,
                                                        'nr_can_bytes': 8,
                                                        'payload': [129, 0, 0, 0, 0, 0, 0, pallet_type],
                                                        #                +--------------+ = source and destination uCAN address
                                                        'sid': SID.BOOTLOADER_PALLET})
            self.assertDictEqual(received_commands[1], {'cc_address': cc_address,
                                                        'nr_can_bytes': 7,
                                                        'payload': [0, 1, 2, 219, 155, 250, 178, 0],
                                                        #              |  |  +----------------+ = checksum
                                                        #              |  + = bar
                                                        #              + = foo
                                                        'sid': SID.BOOTLOADER_PALLET})

            # Build fake reply from Core
            consumer = ucan_communicator._consumers[cc_address][0]
            fixed_payload = [0, 0, 0, 0, 0, 0, pallet_type]
            variable_payload = range(7, 7 + length)  # [7] or [7, 8, 9]
            crc_payload = Int32Field.encode_bytes(UCANPalletCommandSpec.calculate_crc(fixed_payload + variable_payload))
            ucan_communicator._process_transport_message({'cc_address': cc_address,
                                                          'nr_can_bytes': 8,
                                                          'sid': 1,
                                                          'payload': [129] + fixed_payload})
            ucan_communicator._process_transport_message({'cc_address': cc_address,
                                                          'nr_can_bytes': length + 5,
                                                          'sid': 1,
                                                          'payload': [0] + variable_payload + crc_payload})
            self.assertDictEqual(consumer.get(1), {'other': variable_payload})
Ejemplo n.º 6
0
 def read_flash(data_length):
     """
     Reads uCAN flash
     Note: uCAN needs to be in bootloader
     """
     return UCANPalletCommandSpec(
         identifier=AddressField('ucan_address', 3),
         pallet_type=PalletType.FLASH_READ_REQUEST,
         request_fields=[
             UInt32Field('start_address'),
             ByteField('data_length')
         ],
         response_fields=[ByteArrayField('data', data_length)])
Ejemplo n.º 7
0
 def ucan_module_information():
     """ Receives information from a uCAN module """
     return CoreCommandSpec(instruction='CD',
                            response_fields=[
                                AddressField('ucan_address', 3),
                                WordArrayField('input_links', 6),
                                ByteArrayField('sensor_links', 2),
                                ByteField('sensor_type'),
                                VersionField('version'),
                                ByteField('bootloader'),
                                CharField('new_indicator'),
                                ByteField('min_led_brightness'),
                                ByteField('max_led_brightness')
                            ])
Ejemplo n.º 8
0
 def memory_write(length):
     """ Writes memory """
     return CoreCommandSpec(instruction='MW',
                            request_fields=[
                                CharField('type'),
                                WordField('page'),
                                ByteField('start'),
                                ByteArrayField('data', length)
                            ],
                            response_fields=[
                                CharField('type'),
                                WordField('page'),
                                ByteField('start'),
                                ByteField('length'),
                                CharField('result')
                            ])
Ejemplo n.º 9
0
 def memory_read():
     """ Reads memory """
     return CoreCommandSpec(instruction='MR',
                            request_fields=[
                                CharField('type'),
                                WordField('page'),
                                ByteField('start'),
                                ByteField('length')
                            ],
                            response_fields=[
                                CharField('type'),
                                WordField('page'),
                                ByteField('start'),
                                ByteArrayField('data',
                                               lambda length: length - 4)
                            ])