Пример #1
0
    def _send_command(self, cid, command, fields):
        """
        Send a command over the serial port

        :param cid: The command ID
        :type cid: int
        :param command: The Core CommandSpec
        :type command: master_core.core_command.CoreCommandSpec
        :param fields: A dictionary with the command input field values
        :type fields dict
        :raises: serial_utils.CommunicationTimedOutException
        """

        payload = command.create_request_payload(fields)

        checked_payload = (str(chr(cid)) + command.instruction +
                           WordField.encode(len(payload)) + payload)

        data = (CoreCommunicator.START_OF_REQUEST + str(chr(cid)) +
                command.instruction + WordField.encode(len(payload)) +
                payload + 'C' +
                str(chr(CoreCommunicator._calculate_crc(checked_payload))) +
                CoreCommunicator.END_OF_REQUEST)

        self._write_to_serial(data)
Пример #2
0
 def read_ucan_config():
     """ Reads the full uCAN config """
     return UCANCommandSpec(sid=SID.NORMAL_COMMAND,
                            instruction=Instruction(instruction=[0, 199]),
                            identifier=AddressField('ucan_address', 3),
                            response_instructions=[
                                Instruction(instruction=[i, 199],
                                            checksum_byte=7)
                                for i in xrange(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')
                            ])
Пример #3
0
 def error_information():
     """ Error information """
     return CoreCommandSpec(instruction='ER',
                            response_fields=[
                                ByteField('type'),
                                ByteField('parameter_a'),
                                WordField('parameter_b'),
                                WordField('parameter_c')
                            ])
Пример #4
0
 def basic_action():
     """ 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')
                            ])
Пример #5
0
 def general_configuration_max_specs():
     """ 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')
                            ])
Пример #6
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')
                            ])
Пример #7
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)
                            ])
Пример #8
0
 def output_detail():
     """ 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')
                            ])
Пример #9
0
 def event_information():
     """ Event information """
     return CoreCommandSpec(instruction='EV',
                            response_fields=[
                                ByteField('type'),
                                ByteField('action'),
                                WordField('device_nr'),
                                ByteArrayField('data', 4)
                            ])
Пример #10
0
 def module_information():
     """ 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')
                            ])
Пример #11
0
 def _word_decode(data):
     return WordField.decode(str(chr(data[0])) + str(chr(data[1])))