Projects STRLCPY CatSniffer Commits 46a23968
🤬
  • ■ ■ ■ ■ ■ ■
    firmware/pycatsniffer/devpycatsniffer.py
    skipped 27 lines
    28 28  cfgphy = bytearray([0x40, 0x53, 0x47, 0x01, 0x00, 0x09, 0x51, 0x40, 0x45])
    29 29  cfgfreq = bytearray([0x40, 0x53, 0x45, 0x04, 0x00, 0x62, 0x09, 0x00, 0x00, 0xb4, 0x40, 0x45])
    30 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])
     31 +letsgo = bytearray([0x40, 0x53, 0x41, 0x00, 0x00, 0x41, 0x40, 0x45])
    32 32   
    33 33  class CC1352:
    34 34   
    skipped 18 lines
    53 53   
    54 54   def __init__(self, port, callback):
    55 55   
     56 + baudrate = 921600
     57 + rts_cts = False
     58 +
    56 59   stats['Captured'] = 0
    57 60   stats['Non-Frame'] = 0
    58 61   
    59  - #self.callback = callback
     62 + self.callback = callback
    60 63   self.thread = None
    61 64   self.running = False
    62  - self.serial_port = serial.Serial(port, 921600, 8, 'N', 1, timeout=1)
     65 +
     66 + try:
     67 + #self.serial_port = serial.Serial(port, baudrate, 8, 'N', 1, timeout=1)
     68 + self.serial_port = serial.Serial(port = port,
     69 + baudrate = baudrate,
     70 + bytesize = serial.EIGHTBITS,
     71 + parity = serial.PARITY_NONE,
     72 + stopbits = serial.STOPBITS_ONE,
     73 + xonxoff = False,
     74 + rtscts = rts_cts,
     75 + timeout = 0.1)
     76 + self.serial_port.flushInput()
     77 + self.serial_port.flushOutput()
     78 + except (serial.SerialException, ValueError, IOError, OSError) as e:
     79 + logger.error('Error opening port: %s' % (port,))
     80 + logger.error('The error was: %s' % (e.args,))
     81 + sys.exit(1)
     82 + logger.info('Serial port %s opened' % (self.serial_port.name))
    63 83  
    64 84   def close(self):
    65 85   self.serial_port.close()
    skipped 13 lines
    79 99   def initiatorc(self):
    80 100   self.serial_port.write(initiator)
    81 101   
    82  - def startc(self):
    83  - self.serial_port.write(start)
     102 + #def startc(self):
     103 + # self.serial_port.write(letsgo)
    84 104  
    85 105   
    86  - def start(self):
     106 + def startc(self):
    87 107   # start sniffing
    88 108   self.running = True
    89 109   #self.dev.ctrl_transfer(CC2531.DIR_OUT, CC2531.SET_START)
     110 +
     111 + self.serial_port.write(letsgo)
     112 +
    90 113   self.thread = threading.Thread(target=self.recv)
    91  - self.thread.daemon = True
     114 + #self.thread.daemon = True
    92 115   self.thread.start()
    93 116   
    94 117   def stop(self):
    skipped 5 lines
    100 123   def isRunning(self):
    101 124   return self.running
    102 125   
     126 + 
    103 127   def recv(self):
    104 128   
    105 129   while self.running:
    skipped 3 lines
    109 133   #print(bytesteam.hex())
    110 134   print ("RECV>> %s" % binascii.hexlify(bytesteam))
    111 135  
    112  - if len(bytesteam) >= 3:
    113  - (cmd, cmdLen) = struct.unpack_from("<BH", bytesteam)
    114  - payload = bytesteam[3:]
    115  - if len(payload) == cmdLen:
    116  - # buffer contains the correct number of bytes
    117  - if CC1352.COMMAND_FRAME == cmd:
    118  - logger.info(f'Read a frame of size {cmdLen}')
    119  - stats['Captured'] += 1
    120  - (timestamp,
    121  - pktLen) = struct.unpack_from("<IB", payload)
    122  - frame = payload[5:]
    123  - 
    124  - if len(frame) == pktLen:
    125  - pass
    126  - #self.callback(timestamp, frame.tobytes())
    127  - else:
    128  - logger.warning(
    129  - f'Received a frame with incorrect length, pktLen:{pktLen}, len(frame):{len(frame)}'
    130  - )
     136 + #if ret[0] == 0:
     137 + # packet = self.parse_packet(ret)
     138 + # if packet:
     139 + # self.callback(packet)
    131 140  
    132  - # elif cmd == CC2531.COMMAND_CHANNEL:
    133  - # logger.info('Received a command response: [%02x %02x]' % (cmd, payload[0]))
    134  - # # We'll only ever see this if the user asked for it, so we are
    135  - # # running interactive.
    136  - elif CC1352.HEARTBEAT_FRAME == cmd:
    137  - logger.debug(f'Heartbeat - {payload[0]}')
    138  - else:
    139  - logger.warning(
    140  - 'Received a command response with unknown code - CMD:{:02x} byte:{}'
    141  - .format(cmd, bytesteam))
    142 141   
    143 142   def set_channel(self, channel):
    144 143   was_running = self.running
    skipped 28 lines
    173 172   else:
    174 173   return "Not connected"
    175 174   
    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 175  class Packet:
    187 176   
    188 177   def __init__(self, timestamp, channel, header, payload, rssi, crc_ok, correlation):
    skipped 22 lines
    211 200   
    212 201   def callback(packet):
    213 202   print("-"*30)
    214  - #print(packet)
     203 + print(packet)
    215 204   print("-"*30)
    216 205  
    217 206   sniffer = CC1352('/dev/ttyACM0', callback)
    skipped 1 lines
    219 208  
    220 209   #print(sniffer)
    221 210   #sniffer.startc()
     211 + #sniffer.pingc()
     212 + #time.sleep(2)
     213 + #sniffer.stopc()
     214 +
    222 215   sniffer.pingc()
    223  - time.sleep(2)
    224 216   sniffer.stopc()
     217 + sniffer.cfgphyc()
     218 + sniffer.cfgfreqc()
     219 + sniffer.initiatorc()
     220 + sniffer.startc()
     221 + print ("start")
     222 + #sniffer.close()
    225 223   
Please wait...
Page is in error, reload to recover