Example #1
0
 def queue_6F_command(p_controller_obj, p_light_obj, p_code, p_flag, p_data):
     """Manage All-Link Record (11 bytes)"""
     LOG.info("Command to manage all-link record (6F).")
     l_command = Utility._create_command_message('manage_all_link_record')
     l_command[2] = p_code
     l_command[3] = p_flag
     l_command[4] = p_light_obj.GroupNumber
     Util.int2message(p_light_obj.InsteonAddress, l_command, 5)
     l_command[8:11] = p_data
     Utility._queue_command(p_controller_obj, l_command)
Example #2
0
 def queue_6F_command(p_controller_obj, p_light_obj, p_code, p_flag,
                      p_data):
     """Manage All-Link Record (11 bytes)"""
     LOG.info("Command to manage all-link record (6F).")
     l_command = Utility._create_command_message('manage_all_link_record')
     l_command[2] = p_code
     l_command[3] = p_flag
     l_command[4] = p_light_obj.GroupNumber
     Util.int2message(p_light_obj.InsteonAddress, l_command, 5)
     l_command[8:11] = p_data
     Utility._queue_command(p_controller_obj, l_command)
Example #3
0
 def queue_0x6F_command(p_controller_obj, p_light_obj, p_code, p_flag, p_data):
     """Manage All-Link Record (11 bytes)
      See p 252(265) of 2009 developers guide.
    """
     LOG.info("Command to manage all-link record (6F).")
     l_command = Insteon_utils.create_command_message('manage_all_link_record')
     l_command[2] = p_code
     l_command[3] = p_flag
     l_command[4] = p_light_obj.GroupNumber
     Util.int2message(p_light_obj.InsteonAddress, l_command, 5)
     l_command[8:11] = p_data
     Insteon_utils.queue_command(p_controller_obj, l_command)
Example #4
0
    def decode_message(self, p_controller_obj):
        """Decode a message that was ACKed / NAked.
        see Insteon Developers Manual pages 238-241

        Since a controller response may contain multiple messages and the last message may not be complete.
        This should be invoked every time we pick up more messages from the controller.
        It should loop and decode each message present and leave when done

        @return: a flag that is True for ACK and False for NAK/Invalid response.
        """
        #  LOG.info('Message = {}'.format(PrintBytes(p_controller_obj._Message)))
        while len(p_controller_obj._Message) >= 2:
            l_stx = p_controller_obj._Message[0]
            if l_stx == STX:
                #  LOG.info("{}".format(PrintBytes(p_controller_obj._Message)))
                l_need_len = utilUtil.get_message_length(
                    p_controller_obj._Message)
                l_cur_len = len(p_controller_obj._Message)
                if l_cur_len >= l_need_len:
                    self._decode_dispatch(p_controller_obj)
                else:
                    #  LOG.warning('Message was too short - waiting for rest of message.')
                    return
            else:
                utilDecode.drop_first_byte(p_controller_obj)
Example #5
0
    def queue_62_command(p_controller_obj, p_obj, p_cmd1, p_cmd2):
        """Send Insteon Standard Length Message (8 bytes).
        See page 243 of Insteon Developers Guide.

        @param p_obj: is the device object.
        @param p_cmd1: is the first command byte
        @param p_cmd2: is the second command byte
        """
        try:
            l_command = Utility._create_command_message('insteon_send')
            Util.int2message(p_obj.InsteonAddress, l_command, 2)
            l_command[5] = FLAG_MAX_HOPS + FLAG_HOPS_LEFT  #  0x0F
            l_command[6] = p_obj._Command1 = p_cmd1
            l_command[7] = p_obj._Command2 = p_cmd2
            Utility._queue_command(p_controller_obj, l_command)
        except Exception as e_err:
            LOG.error('Error creating command {}'.format(PrettyFormatAny.form(p_obj, 'Device')))
Example #6
0
    def queue_62_command(p_controller_obj, p_obj, p_cmd1, p_cmd2):
        """Send Insteon Standard Length Message (8 bytes).
        See page 243 of Insteon Developers Guide.

        @param p_obj: is the device object.
        @param p_cmd1: is the first command byte
        @param p_cmd2: is the second command byte
        """
        try:
            l_command = Utility._create_command_message('insteon_send')
            Util.int2message(p_obj.InsteonAddress, l_command, 2)
            l_command[5] = FLAG_MAX_HOPS + FLAG_HOPS_LEFT  #  0x0F
            l_command[6] = p_obj._Command1 = p_cmd1
            l_command[7] = p_obj._Command2 = p_cmd2
            Utility._queue_command(p_controller_obj, l_command)
        except Exception as e_err:
            LOG.error('Error creating command {}'.format(
                PrettyFormatAny.form(p_obj, 'Device')))
Example #7
0
 def check_for_more_decoding(self, p_controller_obj, p_ret = True):
     """Chop off the current message from the head of the buffered response stream from the controller.
     @param p_ret: is the result to return.
     """
     l_ret = p_ret
     l_cur_len = len(p_controller_obj._Message)
     l_chop = utilUtil.get_message_length(p_controller_obj._Message)
     if l_cur_len >= l_chop:
         p_controller_obj._Message = p_controller_obj._Message[l_chop:]
         l_ret = self.decode_message(p_controller_obj)
     else:
         l_msg = "check_for_more_decoding() trying to chop an incomplete message - {}".format(
                 PrintBytes(p_controller_obj._Message))
         LOG.error(l_msg)
     return l_ret
Example #8
0
 def check_for_more_decoding(self, p_controller_obj, p_ret=True):
     """Chop off the current message from the head of the buffered response stream from the controller.
     @param p_ret: is the result to return.
     """
     l_ret = p_ret
     l_cur_len = len(p_controller_obj._Message)
     l_chop = utilUtil.get_message_length(p_controller_obj._Message)
     if l_cur_len >= l_chop:
         p_controller_obj._Message = p_controller_obj._Message[l_chop:]
         l_ret = self.decode_message(p_controller_obj)
     else:
         l_msg = "check_for_more_decoding() trying to chop an incomplete message - {}".format(
             PrintBytes(p_controller_obj._Message))
         LOG.error(l_msg)
     return l_ret
Example #9
0
    def receive_loop(self, p_controller_obj):
        """Check the driver to see if the controller returned any messages.

        Decode message only when we get enough bytes to complete a message.
        Note that there may be more bytes than we need - preserve them.

        TODO: instead of fixed time, callback to here from driver when bytes are rx'ed.
        """
        self.m_pyhouse_obj.Twisted.Reactor.callLater(RECEIVE_TIMEOUT, self.receive_loop, p_controller_obj)
        if p_controller_obj._DriverAPI != None:
            self._append_message(p_controller_obj)
            l_cur_len = len(p_controller_obj._Message)
            if l_cur_len < 2:
                return
            #  LOG.info('Receive message is now {}'.format(PrintBytes(p_controller_obj._Message)))
            l_response_len = Util.get_message_length(p_controller_obj._Message)
            if l_cur_len >= l_response_len:
                self.m_decoder.decode_message(p_controller_obj)
        else:
            LOG.error('Driver missing for {}'.format(p_controller_obj.Name))
Example #10
0
    def receive_loop(self, p_controller_obj):
        """Check the driver to see if the controller returned any messages.

        Decode message only when we get enough bytes to complete a message.
        Note that there may be more bytes than we need - preserve them.

        TODO: instead of fixed time, callback to here from driver when bytes are rx'ed.
        """
        self.m_pyhouse_obj.Twisted.Reactor.callLater(RECEIVE_TIMEOUT,
                                                     self.receive_loop,
                                                     p_controller_obj)
        if p_controller_obj._DriverAPI != None:
            self._append_message(p_controller_obj)
            l_cur_len = len(p_controller_obj._Message)
            if l_cur_len < 2:
                return
            #  LOG.info('Receive message is now {}'.format(PrintBytes(p_controller_obj._Message)))
            l_response_len = Util.get_message_length(p_controller_obj._Message)
            if l_cur_len >= l_response_len:
                self.m_decoder.decode_message(p_controller_obj)
        else:
            LOG.error('Driver missing for {}'.format(p_controller_obj.Name))
Example #11
0
    def decode_message(self, p_controller_obj):
        """Decode a message that was ACKed / NAked.
        see Insteon Developers Manual pages 238-241

        Since a controller response may contain multiple messages and the last message may not be complete.
        This should be invoked every time we pick up more messages from the controller.
        It should loop and decode each message present and leave when done

        @return: a flag that is True for ACK and False for NAK/Invalid response.
        """
        #  LOG.info('Message = {}'.format(PrintBytes(p_controller_obj._Message)))
        while len(p_controller_obj._Message) >= 2:
            l_stx = p_controller_obj._Message[0]
            if l_stx == STX:
                #  LOG.info("{}".format(PrintBytes(p_controller_obj._Message)))
                l_need_len = utilUtil.get_message_length(p_controller_obj._Message)
                l_cur_len = len(p_controller_obj._Message)
                if l_cur_len >= l_need_len:
                    self._decode_dispatch(p_controller_obj)
                else:
                    #  LOG.warning('Message was too short - waiting for rest of message.')
                    return
            else:
                utilDecode.drop_first_byte(p_controller_obj)