Beispiel #1
0
    def dispatch_pkt(self, notif_type, data_notif):
        """Parse and dispatch an OAP packet to the correct handler based on its type"""
        if data_notif.dstPort != OAPMessage.OAP_PORT:
            return

        payload = array('B', data_notif.data)
        # first two bytes are transport header
        trans = OAPMessage.extract_oap_header(payload)
        # third byte is OAP command type
        cmd_type = payload[2]

        #print trans
        #print int(cmd_type)

        if trans['response']:
            oap_resp = OAPMessage.parse_oap_response(payload, 2)
            self._response_callbacks(data_notif.macAddress, oap_resp, trans)
            self.last_response = oap_resp

        elif cmd_type == OAPMessage.CmdType.NOTIF:
            oap_notif = OAPNotif.parse_oap_notif(payload, 3)
            self._notif_callbacks(data_notif.macAddress, oap_notif)
            self.last_notif = oap_notif