Projects STRLCPY CatSniffer Commits a89922b0
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    firmware/pycatsniffer/devpycatsniffer.py
    skipped 1 lines
    2 2  import time
    3 3  import sys
    4 4   
     5 +import argparse
    5 6  import binascii
    6 7  import threading
    7 8  import logging.handlers
    skipped 14 lines
    22 23  logger = logging.getLogger(__name__)
    23 24  stats = {}
    24 25   
     26 +ping = bytearray([0x40, 0x53, 0x40, 0x00, 0x00, 0x40, 0x40, 0x45])
     27 +stop = bytearray([0x40, 0x53, 0x42, 0x00, 0x00, 0x42, 0x40, 0x45])
     28 +cfgphy = bytearray([0x40, 0x53, 0x47, 0x01, 0x00, 0x09, 0x51, 0x40, 0x45])
     29 +cfgfreq = bytearray([0x40, 0x53, 0x45, 0x04, 0x00, 0x62, 0x09, 0x00, 0x00, 0xb4, 0x40, 0x45])
     30 +initiator = bytearray([0x40, 0x53, 0x70, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x40, 0x45])
     31 +start = bytearray([0x40, 0x53, 0x41, 0x00, 0x00, 0x41, 0x40, 0x45])
     32 + 
    25 33  class CC1352:
    26 34   
    27 35   DEFAULT_CHANNEL = 0x0B # 11
    skipped 15 lines
    43 51   HEARTBEAT_FRAME = 0x01
    44 52   COMMAND_FRAME = 0x00
    45 53   
    46  - def __init__(self, callback, port):
     54 + def __init__(self, port, callback):
    47 55   
    48 56   stats['Captured'] = 0
    49 57   stats['Non-Frame'] = 0
    50 58   
    51  - self.callback = callback
     59 + #self.callback = callback
    52 60   self.thread = None
    53 61   self.running = False
    54 62   self.serial_port = serial.Serial(port, 921600, 8, 'N', 1, timeout=1)
    skipped 1 lines
    56 64   def close(self):
    57 65   self.serial_port.close()
    58 66   
     67 + def pingc(self):
     68 + self.serial_port.write(ping)
     69 +
     70 + def stopc(self):
     71 + self.serial_port.write(stop)
     72 +
     73 + def cfgphyc(self):
     74 + self.serial_port.write(cfgphy)
     75 +
     76 + def cfgfreqc(self):
     77 + self.serial_port.write(cfgfreq)
     78 + 
     79 + def initiatorc(self):
     80 + self.serial_port.write(initiator)
     81 + 
     82 + def startc(self):
     83 + self.serial_port.write(start)
     84 +
     85 + 
    59 86   def start(self):
    60 87   # start sniffing
    61 88   self.running = True
    skipped 33 lines
    95 122   frame = payload[5:]
    96 123   
    97 124   if len(frame) == pktLen:
    98  - self.callback(timestamp, frame.tobytes())
     125 + pass
     126 + #self.callback(timestamp, frame.tobytes())
    99 127   else:
    100 128   logger.warning(
    101 129   f'Received a frame with incorrect length, pktLen:{pktLen}, len(frame):{len(frame)}'
    skipped 43 lines
    145 173   else:
    146 174   return "Not connected"
    147 175   
     176 + 
     177 +#cc1352.pingc()
     178 +#cc1352.stopc()
     179 +#cc1352.cfgphyc()
     180 +#cc1352.cfgfreqc()
     181 +#cc1352.initiatorc()
     182 +#cc1352.startc()
     183 +#print ("start")
     184 +#cc1352.close()
     185 + 
     186 +class Packet:
     187 + 
     188 + def __init__(self, timestamp, channel, header, payload, rssi, crc_ok, correlation):
     189 + self.timestamp = timestamp
     190 + self.channel = channel
     191 + self.header = header
     192 + self.payload = payload
     193 + self.rssi = rssi
     194 + self.crc_ok = crc_ok
     195 + self.correlation = correlation
     196 + 
     197 + def __repr__(self):
     198 +
     199 + ret = []
     200 + ret.append("Channel: %d" % self.channel)
     201 + ret.append("Timestamp: %s" % time.strftime("%H:%M:%S", self.timestamp))
     202 + ret.append("Header: %s" % binascii.hexlify(self.header))
     203 + ret.append("RSSI: %d" % self.rssi)
     204 + ret.append("CRC OK: %s" % self.crc_ok)
     205 + ret.append("Correlation: %d" % self.correlation)
     206 + ret.append("Payload: %s" % binascii.hexlify(self.payload))
     207 + 
     208 + return "\n".join(ret)
     209 + 
     210 +if __name__ == "__main__":
     211 + 
     212 + def callback(packet):
     213 + print("-"*30)
     214 + #print(packet)
     215 + print("-"*30)
     216 +
     217 + sniffer = CC1352('/dev/ttyACM0', callback)
     218 + #sniffer = CC1352(callback)
     219 +
     220 + #print(sniffer)
     221 + #sniffer.startc()
     222 + sniffer.pingc()
     223 + time.sleep(2)
     224 + sniffer.stopc()
     225 + 
Please wait...
Page is in error, reload to recover