当前位置: 首页>>代码示例>>Python>>正文


Python Packet.fromMessage方法代码示例

本文整理汇总了Python中packet.Packet.fromMessage方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.fromMessage方法的具体用法?Python Packet.fromMessage怎么用?Python Packet.fromMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在packet.Packet的用法示例。


在下文中一共展示了Packet.fromMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import fromMessage [as 别名]
    def update(self, message):
        if len(message) != 16:
            self.logger.warning("The received message is not 16 bytes long")
            return
        message = self.aes.decrypt([ord(x) for x in message], self.key, AES.keySize["SIZE_128"])
        message = "".join([chr(x) for x in message])

        self.logger.debug("Decoded message: %s" % str(list(message)))

        p = Packet.fromMessage(message)
        if p.cmd == 83:
            self.supply_voltage = ord(p.data[3]) * 0.1

            pressed_buttons = ord(p.data[0])
            self.logger.debug("master: pressed_buttons = %d", pressed_buttons)

            if pressed_buttons & 0x01 and not self.pressed_buttons & 0x01:
                self.pressed_buttons |= 0x01
                self.command_queue.put("lock")
            elif not pressed_buttons & 0x01:
                self.pressed_buttons &= ~0x01

            if pressed_buttons & 0x02 and not self.pressed_buttons & 0x02:
                self.pressed_buttons |= 0x02
                self.command_queue.put("toggle_announce")
            elif not pressed_buttons & 0x02:
                self.pressed_buttons &= ~0x02

            if pressed_buttons & 0x04 and not self.pressed_buttons & 0x04:
                self.pressed_buttons |= 0x04
            elif not pressed_buttons & 0x04:
                self.pressed_buttons &= ~0x04

            self.logger.info("Master state: %s" % self.get_state())
开发者ID:nictally,项目名称:luftschleuse2,代码行数:36,代码来源:mastercontroller.py

示例2: update

# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import fromMessage [as 别名]
    def update(self, message):
        if len(message) != 16:
            self.logger.warning("The received message is not 16 bytes long")
            return

        # self.logger.debug("Decoded message: %s"%str(list(message)))

        p = Packet.fromMessage(message)
        if p.cmd == ord("S"):
            self.supply_voltage = ord(p.data[3]) * 0.1

            pressed_buttons = ord(p.data[0])
            self.logger.debug("master: pressed_buttons = %d", pressed_buttons)
            for pin in self.buttons:
                if pressed_buttons & pin and not self.pressed_buttons & pin:
                    self.pressed_buttons |= pin
                    self.input_queue.put(
                        {
                            "origin_name": "master",
                            "origin_type": DoorLogic.Origin.CONTROL_PANNEL,
                            "input_name": self.buttons[pin],
                            "input_type": DoorLogic.Input.BUTTON,
                            "input_value": True,
                        }
                    )
                elif not pressed_buttons & pin and self.pressed_buttons & pin:
                    self.input_queue.put(
                        {
                            "origin_name": "master",
                            "origin_type": DoorLogic.Origin.CONTROL_PANNEL,
                            "input_name": self.buttons[pin],
                            "input_type": DoorLogic.Input.BUTTON,
                            "input_value": False,
                        }
                    )
                    self.pressed_buttons &= ~pin

            self.logger.info("Master state: %s" % self.get_state())
开发者ID:schneider42,项目名称:luftschleuse2,代码行数:40,代码来源:mastercontroller.py

示例3: update

# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import fromMessage [as 别名]
    def update(self, message):
    	if len(message) != 16:
            self.logger.warning("The received message is not 16 bytes long")
    	    return
        message = self.aes.decrypt([ord(x) for x in message], self.key,
                    AES.keySize["SIZE_128"])
        message = ''.join([chr(x) for x in message])

        self.logger.debug("Decoded message: %s"%str(list(message)))
        
        p = Packet.fromMessage(message)
        if p.cmd==83:
            self.supply_voltage = ord(p.data[3])*0.1
            
            '''
            pressed_buttons = 0
            if self.buttons_toggle_state == None:
                self.buttons_toggle_state = ord(p.data[0])
            else:
                pressed_buttons = self.buttons_toggle_state ^ ord(p.data[0])
                self.buttons_toggle_state = ord(p.data[0])
            if pressed_buttons:
                self.logger.info('Got pressed buttons: %d' % pressed_buttons)
                if pressed_buttons & 0x01:

            '''
            pressed_buttons = ord(p.data[0])
            if pressed_buttons & 0x01 and not self.pressed_buttons & 0x01:
                self.pressed_buttons |= 0x01
                if self.desired_state == Door.LOCK_LOCKED:
                    self.desired_state = Door.LOCK_UNLOCKED
                elif self.desired_state == Door.LOCK_UNLOCKED:
                    self.desired_state = Door.LOCK_LOCKED 
            elif not pressed_buttons & 0x01:
                self.pressed_buttons &= ~0x01
           
            doorstate = ord(p.data[1])
            state = ''
            self.closed = doorstate & Door.DOOR_CLOSED \
                            == Door.DOOR_CLOSED
            self.locked = doorstate & Door.LOCK_LOCKED \
                            == Door.LOCK_LOCKED 
            self.unlocked = doorstate & Door.LOCK_UNLOCKED \
                            == Door.LOCK_UNLOCKED
            self.locking = doorstate & Door.LOCK_LOCKING \
                            == Door.LOCK_LOCKING
            self.unlocking = doorstate & Door.LOCK_UNLOCKING \
                            == Door.LOCK_UNLOCKING
            self.handle_pressed = doorstate & Door.HANDLE_PRESSED \
                            == Door.HANDLE_PRESSED
            self.perm_unlocked = doorstate & Door.LOCK_PERM_UNLOCKED \
                            == Door.LOCK_PERM_UNLOCKED
            self.logger.info('Door state: %s'%self.get_state())
            self.logger.info('Desired door state: %s'%self.get_desired_state())

        elif p.cmd==ord('A'):
            accepted = ord(p.data[0]) == 1
            if not self.command_accepted:
                if accepted:
                    self.logger.info('Command at %d was accepted'%self.command_time)
                    self.command_accepted = True
                else:
                    self.logger.warning('Command at %d was NOT accepted'% self.command_time)
开发者ID:nictally,项目名称:luftschleuse2,代码行数:65,代码来源:door.py

示例4: update

# 需要导入模块: from packet import Packet [as 别名]
# 或者: from packet.Packet import fromMessage [as 别名]
    def update(self, message):
    	if len(message) != 16:
            self.logger.warning("%s: The received message is not 16 bytes long"%(self.name))
    	    return False
        
        p = Packet.fromMessage(message, key = self.key)
        
        if p == None:
            self.logger.debug("%s: Decoded packet was invalid" % self.name)
            self._set_bad_key(True)
            return False
        
        self._set_bad_key(False)

        if p.seq_sync:
            self.logger.debug("%s: Sync packet with seq: %d" % (self.name, p.seq))
            # This message contains a synchronization message for our
            # tx sequence number.
            self.tx_seq = p.seq
            return False

        if not p.seq >= self.min_rx_seq:
            self.logger.debug("%s: Seq %d not ok. Sending seq update to %d." %
                    (self.name, p.seq, self.min_rx_seq))
            self._set_wrong_rx_seq(True)

            # The door sent a sequence number which is too low.
            # Inform it about what we expect.
            p = Packet(seq=self.min_rx_seq, cmd=0, data='', seq_sync=True)
            msg = p.toMessage(key = self.key)

            self.logger.debug('%s: Msg to door: %s' %
                    (self.name, list(p.toMessage())))
            self.interface.writeMessage(self.priority, self.address, msg, self.tx_msg_queue)
            return False
        
        self._set_wrong_rx_seq(False)

        if p.seq >= self.persisted_min_rx_seq:
            self.persisted_min_rx_seq = p.seq + self.min_rx_seq_leap
            self.write_rx_sequence_number_to_container(self.persisted_min_rx_seq)

        self.min_rx_seq  = p.seq + 1


        if p.cmd == ord('S'):
            self.status_update_timestamp = time.time()
            self.supply_voltage = ord(p.data[3])*0.1
            
            pressed_buttons = ord(p.data[0])
            self.logger.debug('master: pressed_buttons = %d' % pressed_buttons)
            for pin in self.buttons:
                if pressed_buttons & pin and not self.pressed_buttons & pin:
                    self.pressed_buttons |= pin
                    self.input_queue.put({'origin_name': self.name,
                        'origin_type': DoorLogic.Origin.DOOR,
                        'input_name': self.buttons[pin],
                        'input_type': DoorLogic.Input.BUTTON,
                        'input_value': True})
                elif not pressed_buttons & pin and self.pressed_buttons & pin:
                    self.input_queue.put({'origin_name': self.name,
                        'origin_type': DoorLogic.Origin.DOOR,
                        'input_name': self.buttons[pin],
                        'input_type': DoorLogic.Input.BUTTON,
                        'input_value': False})
                    self.pressed_buttons &= ~pin
           
            doorstate = ord(p.data[1])
            self.closed = doorstate & Door.DOOR_CLOSED \
                            == Door.DOOR_CLOSED
            self.locked = doorstate & Door.LOCK_LOCKED \
                            == Door.LOCK_LOCKED 
            self.unlocked = doorstate & Door.LOCK_UNLOCKED \
                            == Door.LOCK_UNLOCKED
            self.locking = doorstate & Door.LOCK_LOCKING \
                            == Door.LOCK_LOCKING
            self.unlocking = doorstate & Door.LOCK_UNLOCKING \
                            == Door.LOCK_UNLOCKING
            self.handle_pressed = doorstate & Door.HANDLE_PRESSED \
                            == Door.HANDLE_PRESSED
            self.manual_unlocked = doorstate & Door.LOCK_MANUAL_UNLOCKED \
                            == Door.LOCK_MANUAL_UNLOCKED
            self.logger.info('%s: Door state: %s'%(self.name, self.get_state()))
            self.logger.info('%s: Desired door state: %s'%(self.name, self.get_desired_state()))
            
            if self._old_state != p.data:
                self._old_state = p.data
                self.notify_state_listeners()
        return True
开发者ID:muccc,项目名称:luftschleuse2,代码行数:91,代码来源:door.py


注:本文中的packet.Packet.fromMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。