From 2d355a1f9dc82983ec26dcab58d645963a65cb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Sun, 15 Jun 2014 20:10:47 +0200 Subject: [PATCH] Debug patch diff --git a/SnifferAPI/Packet.py b/SnifferAPI/Packet.py index 011eacd..757bac9 100644 --- a/SnifferAPI/Packet.py +++ b/SnifferAPI/Packet.py @@ -148,6 +148,7 @@ class PacketReader: self.sendPacket(REQ_FOLLOW, addr, timeout) def sendPingReq(self, timeout = 1): + print("ping req") self.sendPacket(PING_REQ, [], timeout) def sendTK(self, TK, timeout = None): @@ -208,7 +209,33 @@ class Packet: def __repr__(self): - return "UART packet, type: "+str(self.id)+", PC: "+str(self.packetCounter) + pkt_str = { + 0x00 : 'REQ_FOLLOW', + 0x01 : 'RESP_FOLLOW', + 0x02 : 'EVENT_DEVICE', + 0x03 : 'REQ_SINGLE_PACKET', + 0x04 : 'RESP_SINGLE_PACKET', + 0x05 : 'EVENT_CONNECT', + 0x06 : 'EVENT_PACKET', + 0x07 : 'REQ_SCAN_CONT', + 0x08 : 'RESP_SCAN_CONT', + 0x09 : 'EVENT_DISCONNECT', + 0x0A : 'EVENT_ERROR', + 0x0B : 'EVENT_EMPTY_DATA_PACKET', + 0x0C : 'SET_TEMPORARY_KEY', + 0x0D : 'PING_REQ', + 0x0E : 'PING_RESP', + 0x0F : 'TEST_COMMAND_ID', + 0x10 : 'TEST_RESULT_ID', + 0x11 : 'UART_TEST_START', + 0x12 : 'UART_DUMMY_PACKET', + 0x13 : 'SWITCH_BAUD_RATE_REQ', + 0x14 : 'SWITCH_BAUD_RATE_RESP', + 0x15 : 'UART_OUT_START', + 0x16 : 'UART_OUT_STOP', + 0xFE : 'GO_IDLE', + } + return "UART packet, type: "+pkt_str[self.id]+", PC: "+str(self.packetCounter) def readFlags(self): self.crcOK = not not (self.flags & 1) @@ -300,4 +327,4 @@ def toLittleEndian(value, size): for i in range(size): list[i] = (value >> (i*8)) % 256 return list - \ No newline at end of file + diff --git a/SnifferAPI/Sniffer.py b/SnifferAPI/Sniffer.py index d3e2c25..060a282 100644 --- a/SnifferAPI/Sniffer.py +++ b/SnifferAPI/Sniffer.py @@ -29,7 +29,7 @@ class Sniffer(threading.Thread): self.__collector = None self.daemon = True - self.noUI = True + self.noUI = False self.portnum = portnum self.initSniffer() @@ -155,8 +155,10 @@ class Sniffer(threading.Thread): startTime = time.time() continueLoop = True packetCounter = 0 + print('here') while continueLoop and (time.time() < (startTime+1)): packet = myPacketReader.getPacket(timeout = readTimeout) + print(packet) if packet == None: continueLoop = False @@ -212,7 +214,7 @@ class Sniffer(threading.Thread): print - portnum = self.portnum + portnum = None fwversion = None while portnum is None: diff --git a/SnifferAPI/SnifferCollector.py b/SnifferAPI/SnifferCollector.py index 826403c..4e01283 100644 --- a/SnifferAPI/SnifferCollector.py +++ b/SnifferAPI/SnifferCollector.py @@ -40,7 +40,8 @@ ADV_ACCESS_ADDRESS = [0xD6, 0xBE, 0x89, 0x8E] class SnifferCollector: - def __init__(self, portnum = 1, swversion = 0, fwversion = 0, pluginversion_btle = None, pluginversion_nordic = None): + def __init__(self, portnum = 1, swversion = 0, fwversion = 0, pluginversion_btle = None, pluginversion_nordic = None, something=None): + logging.info(str(something)) self.swversion = swversion self.fwversion = fwversion self.pluginversion_btle = pluginversion_btle @@ -130,6 +131,7 @@ class SnifferCollector: msvcrt.getch() raise Exceptions.SnifferExit("Lost contact with sniffer hardware.") else: + print(packet) if packet.id == EVENT_PACKET: self.processBLEPacket(packet) elif packet.id == EVENT_FOLLOW: @@ -144,8 +146,6 @@ class SnifferCollector: if self.inConnection: self.packetsInLastConnection = packet.packetCounter - self.connectEventPacketCounterValue self.inConnection = False - - def findPacketByPacketCounter(self, packetCounterValue): with self.packetListLock: @@ -171,6 +171,7 @@ class SnifferCollector: self.state = STATE_SCANNING if hasattr(self, "packetReader"): + logging.info("sendScan") self.packetReader.sendScan() self.packetReader.sendTK([0]) diff --git a/example.py b/example.py index 540e46c..4ce97ed 100644 --- a/example.py +++ b/example.py @@ -8,24 +8,11 @@ def setup(): global mySniffer # Start the sniffer on COM port COM19. - mySniffer = Sniffer.Sniffer("COM19") + mySniffer = Sniffer.Sniffer("COM20") # Start the sniffer module. This call is mandatory. mySniffer.start() # Open Wireshark. Instance can later be closed by mySniffer.closeWireshark() - mySniffer.openWireshark() - - # Wait to allow the sniffer to discover devicemySniffer. - time.sleep(5) - # Retrieve list of discovered devicemySniffer. - d = mySniffer.getDevices() - # Find device with name "Example". - dev = d.find('Example') - - if dev is not None: - # Follow (sniff) device "Example". This call sends a REQ_FOLLOW command over UART. - mySniffer.follow(dev) - else: - print "Could not find device" + # mySniffer.openWireshark() def loop(): # Enter main loop @@ -49,6 +36,7 @@ def loop(): # Takes list of packets def processPackets(packets): for packet in packets: + print(packet) # packet is of type Packet # packet.blePacket is of type BlePacket global nPackets -- 1.7.3.1.msysgit.0