Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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)