citysu / csiread

A fast channel state information parser for Intel, Atheros, Nexmon, ESP32 and PicoScenes
MIT License
111 stars 29 forks source link

Parsing Nexmon .pcap files #36

Open munir01 opened 4 months ago

munir01 commented 4 months ago

Thank you for this amazing work! I have a question about parsing CSI and RSSI data using csiread. If I know that the CSI data was collected using RPi 4B using this precompiled binary of Nexmon, is there a way to tell if I should use csiread.Nexmon or csiread.NexmonPull46? Alternatively, given a .pcap file, how can I decide if we should use csiread.Nexmon or csiread.NexmonPull46? I would like to get RSSI in addition to CSI and the only way to get it through csiread.NexmonPull46

Also, there is no csiread.NexmonPull46.read() function. So, I created a similar one like csiread.Nexmon.read(), which basically calls super().read().

Here is the sample code that I am using:

csi_file_path = './abc.pcap'
csidata = csiread.NexmonPull46(csi_file_path, chip='43455c0', bw=80) 
csidata.read()
csidata.display(0)

Here is the output:

63045 packets parsed
0th packet:
  file                : ./abc.pcap
  count               : 63045
  nano                : False
  sec                 : 1720688287
  usec                : 331678
  caplen              : 1084
  wirelen             : 1084
  magic               : 0x1111
  src_addr            : 7c:10:c9:e0:20:dc
  seq                 : 0
  core                : 0
  spatial             : 0
  chan_spec           : 0xe02a
  chip_version        : 0x65
  csi                 : (256,)
  rssi                : 192
  fc                  : 148

Looking at value 192, does it look like it is reading the correct RSSI?

Thank you!

citysu commented 4 months ago
  1. When using NexmonPull46, if magic number is 0x1111 and rssi (1byte) is not 0x11 and fc (1byte) is not 0x11, your choice is right. infer_device function in example/utils.py can also tell you which one should be used.
  2. NexmonPull46 inherits Nexmon in _csiread.pyx, NexmonPull46.read() does exist (but is not wrapped in core.py, maybe I forgot it ?).
  3. _autoscale in NexmonPull46 is 0 while it is 1 in Nexmon. This was introduced in nexmon_csi pull 256. You can set csidata._autoscale = 1 before calling csidata.read() if you don't think the change is right.
munir01 commented 4 months ago

Thank you for the prompt response. To follow up,

  1. By looking at the values of my magic number (0x1111), rssi (192, not 0x11), and fc (148, not 0x11), I think I should be able to NexmonPull46
  2. Yes, I do not see that function in core.py. But I added it manually.
  3. I did try autoscale, but the values remain the same. Here is the code:
    csidata = csiread.NexmonPull46(csi_file_path, chip='43455c0', bw=80) 
    csidata._autoscale = 1
    csidata.read()
    csidata.display(0)

    My concern with RSSI value is that 192 does not seem a reasonable value. But when I used CSIKit library to parse the same file, I get RSSI value -64 for the first packet. I noticed that 192-256=-64. Is there an issue for parsing the RSSI bytes? Thanks again!

citysu commented 4 months ago

-64 is right, I'll fix it. You can also use csidata.rssi.astype(np.int8) to fix the value by yourself.

munir01 commented 4 months ago

csidata.rssi.astype(np.int8) works like a charm! Will do. Thanks a lot!