Example #1
0
 def read_ucan_config():  # type: () -> UCANCommandSpec
     """ Reads the full uCAN config """
     return UCANCommandSpec(
         sid=SID.NORMAL_COMMAND,
         identifier=AddressField('ucan_address', 3),
         instructions=[Instruction(instruction=[0, 199])],
         response_instructions=[
             Instruction(instruction=[i, 199], checksum_byte=7)
             for i in range(1, 14)
         ],
         response_fields=[
             ByteField('input_link_0'),
             ByteField('input_link_1'),
             ByteField('input_link_2'),
             ByteField('input_link_3'),
             ByteField('input_link_4'),
             ByteField('input_link_5'),
             ByteField('sensor_link_0'),
             ByteField('sensor_link_1'),
             ByteField('sensor_type'),
             VersionField('firmware_version'),
             ByteField('bootloader'),
             ByteField('new_indicator'),
             ByteField('min_led_brightness'),
             ByteField('max_led_brightness'),
             WordField('adc_input_2'),
             WordField('adc_input_3'),
             WordField('adc_input_4'),
             WordField('adc_input_5'),
             WordField('adc_dc_input')
         ])
Example #2
0
 def error_information():  # type: () -> CoreCommandSpec
     """ Error information """
     return CoreCommandSpec(instruction='ER',
                            response_fields=[
                                ByteField('type'),
                                ByteField('parameter_a'),
                                WordField('parameter_b'),
                                WordField('parameter_c')
                            ])
Example #3
0
 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')
                            ])
Example #4
0
 def basic_action():  # type: () -> CoreCommandSpec
     """ Basic action spec """
     return CoreCommandSpec(instruction='BA',
                            request_fields=[
                                ByteField('type'),
                                ByteField('action'),
                                WordField('device_nr'),
                                WordField('extra_parameter')
                            ],
                            response_fields=[
                                ByteField('type'),
                                ByteField('action'),
                                WordField('device_nr'),
                                WordField('extra_parameter')
                            ])
Example #5
0
    def __init__(self, controller_serial=INJECTED):
        # type: (Serial) -> None
        self._verbose = logger.level >= logging.DEBUG
        self._serial = controller_serial
        self._serial_write_lock = Lock()
        self._cid_lock = Lock()
        self._serial_bytes_written = 0
        self._serial_bytes_read = 0

        self._cid = None  # type: Optional[int]  # Reserved CIDs: 0 = Core events, 1 = uCAN transport, 2 = Slave transport
        self._cids_in_use = set()  # type: Set[int]
        self._consumers = {
        }  # type: Dict[int, List[Union[Consumer, BackgroundConsumer]]]
        self._last_success = 0.0
        self._stop = False

        self._word_helper = WordField('')
        self._read_thread = None  # type: Optional[BaseThread]

        self._command_total_histogram = Counter()  # type: Counter
        self._command_success_histogram = Counter()  # type: Counter
        self._command_timeout_histogram = Counter()  # type: Counter

        self._communication_stats = {
            'calls_succeeded': [],
            'calls_timedout': [],
            'bytes_written': 0,
            'bytes_read': 0
        }  # type: Dict[str,Any]
        self._debug_buffer = {
            'read': {},
            'write': {}
        }  # type: Dict[str, Dict[float, bytearray]]
        self._debug_buffer_duration = 300
Example #6
0
 def __init__(self, data):
     self._type = data['type']
     self._action = data['action']
     self._device_nr = data['device_nr']
     self._data = data['data']
     self._word_helper = WordField('')
     self._address_helper = AddressField('', length=3)
Example #7
0
 def memory_write(length):  # type: (int) -> CoreCommandSpec
     """ Writes memory """
     return CoreCommandSpec(instruction='MW',
                            request_fields=[
                                CharField('type'),
                                WordField('page'),
                                ByteField('start'),
                                RawByteArrayField('data', length)
                            ],
                            response_fields=[
                                CharField('type'),
                                WordField('page'),
                                ByteField('start'),
                                ByteField('length'),
                                CharField('result')
                            ])
Example #8
0
 def memory_read():  # type: () -> CoreCommandSpec
     """ Reads memory """
     return CoreCommandSpec(instruction='MR',
                            request_fields=[
                                CharField('type'),
                                WordField('page'),
                                ByteField('start'),
                                ByteField('length')
                            ],
                            response_fields=[
                                CharField('type'),
                                WordField('page'),
                                ByteField('start'),
                                RawByteArrayField('data',
                                                  lambda length: length - 4)
                            ])
Example #9
0
 def execute_basic_action_series(length):  # type: (int) -> CoreCommandSpec
     """ Executes a Basic action on multiple devices """
     if not 2 <= length <= 40:
         raise ValueError('Amount of device numbers should be 2 <= n <= 40')
     return CoreCommandSpec(instruction='ES',
                            request_fields=[
                                ByteField('type'),
                                ByteField('action'),
                                WordField('extra_parameter'),
                                WordArrayField('device_nrs', length)
                            ],
                            response_fields=[
                                ByteField('type'),
                                ByteField('action'),
                                WordField('extra_parameter')
                            ])
Example #10
0
 def write_firmware_block():  # type: () -> SlaveCommandSpec
     """ Writes a single 64-byte firmware block to a given address """
     return SlaveCommandSpec(instruction=Instruction(instruction='FD'),
                             request_fields=[
                                 WordField('address'),
                                 ByteArrayField('payload', length=64)
                             ],
                             response_fields=[ByteField('return_code')])
Example #11
0
 def event_information():  # type: () -> CoreCommandSpec
     """ Event information """
     return CoreCommandSpec(instruction='EV',
                            response_fields=[
                                ByteField('type'),
                                ByteField('action'),
                                WordField('device_nr'),
                                RawByteArrayField('data', 4)
                            ])
Example #12
0
 def output_detail():  # type: () -> CoreCommandSpec
     """ Received output detail information """
     return CoreCommandSpec(instruction='OD',
                            request_fields=[WordField('device_nr')],
                            response_fields=[
                                WordField('device_nr'),
                                ByteField('status'),
                                ByteField('dimmer'),
                                ByteField('dimmer_min'),
                                ByteField('dimmer_max'),
                                ByteField('timer_type'),
                                ByteField('timer_type_standard'),
                                WordField('timer'),
                                WordField('timer_standard'),
                                WordField('group_action'),
                                ByteField('dali_output'),
                                ByteField('output_lock')
                            ])
Example #13
0
 def module_information():  # type: () -> CoreCommandSpec
     """ Receives module information """
     return CoreCommandSpec(instruction='MC',
                            request_fields=[
                                ByteField('module_nr'),
                                ByteField('module_family')
                            ],
                            response_fields=[
                                ByteField('module_nr'),
                                ByteField('module_family'),
                                ByteField('module_type'),
                                AddressField('address'),
                                WordField('bus_errors'),
                                ByteField('module_status')
                            ])
Example #14
0
 def __init__(self,
              action_type,
              action,
              device_nr=None,
              extra_parameter=None
              ):  # type: (int, int, Optional[int], Optional[int]) -> None
     self._word_helper = WordField('')
     self._byte_helper = ByteField('')
     self._action_type = self._byte_helper.encode(
         action_type)  # type: bytearray
     self._action = self._byte_helper.encode(action)  # type: bytearray
     self._device_nr = self._word_helper.encode(
         device_nr if device_nr is not None else 0)  # type: bytearray
     self._extra_parameter = self._word_helper.encode(
         extra_parameter
         if extra_parameter is not None else 0)  # type: bytearray
Example #15
0
 def __init__(self, data):
     self._type = data['type']
     self._action = data['action']
     self._device_nr = data['device_nr']
     self._data = data['data']
     self._word_helper = WordField('')
Example #16
0
 def setUp(self):
     self.maxDiff = None
     self._word_helper = WordField('')