Skip to content

Commit

Permalink
Parse Wifi SSIDs and convert to Capture and add back NavVis test data (
Browse files Browse the repository at this point in the history
…#68)

This PR does 2 things

1 Parse and convert the Wifi SSIDs from NavVis into Capture
---------

Co-authored-by: Lukas Gruber <[email protected]>
  • Loading branch information
vjlux and Lukas Gruber authored Jun 20, 2024
1 parent fa6f540 commit f4d83cb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
4 changes: 3 additions & 1 deletion scantools/run_navvis_to_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ def run(input_path: Path, capture: Capture, tiles_format: str, session_id: Optio
freq_khz = measurement.center_channel_freq_khz
rssi_dbm = measurement.signal_strength_dbm
time_offset_us = int(measurement.time_offset_ms) / 1_000
ssid = measurement.ssid
if (timestamp_us, sensor_id) not in wifi_signals:
wifi_signals[timestamp_us, sensor_id] = RecordWifi()
wifi_signals[timestamp_us, sensor_id][mac_addr] = RecordWifiSignal(
frequency_khz=freq_khz, rssi_dbm=rssi_dbm, scan_time_start_us=(timestamp_us - time_offset_us)
frequency_khz=freq_khz, rssi_dbm=rssi_dbm, name=ssid,
scan_time_start_us=(timestamp_us - time_offset_us)
)

bluetooth_signals = RecordsBluetooth()
Expand Down
18 changes: 12 additions & 6 deletions scantools/scanners/navvis/iwconfig_parser.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import collections

from pytijo import parser
import re

IWConfigData = collections.namedtuple('IWConfigData',
['mac_address',
'signal_strength_dbm',
'frequency_khz',
'time_offset_ms'])
'time_offset_ms',
'ssid'])

WifiMeasurement = collections.namedtuple(
'WifiMeasurement', [
'timestamp_s',
'mac_address',
'signal_strength_dbm',
'center_channel_freq_khz',
'time_offset_ms'])

'time_offset_ms',
'ssid'])

def frequency_string_to_khz(frequency_str):

Expand Down Expand Up @@ -49,15 +51,17 @@ def parse_iwconfig(data):
'mac_address': r'Address:\s((?:[a-fA-F0-9]{2}[:|\-]?){6})',
'signal_level': r'Signal level=(-?\d{1,2}) dBm',
'frequency': r'Frequency:(\d{1,2}.\d{1,6}\s([ G|M|k]Hz))',
'time_offset': r'Extra: Last beacon: (\d{1,6})ms'
'time_offset': r'Extra: Last beacon: (\d{1,6})ms',
'ssid': r'ESSID:"(.{1,32})"'
}]
}, {
'wifi samples': [{
'#id': r'(BSS (?:[a-fA-F0-9]{2}[:|\-]?){6})',
'mac_address': r'\s((?:[a-fA-F0-9]{2}[:|\-]?){6})',
'signal_level': r'signal: (-?\d{1,2}.\d{1,2}) dBm',
'frequency': r'freq: (\d{1,4})',
'time_offset': r'last seen: (\d{1,6}) ms'
'time_offset': r'last seen: (\d{1,6}) ms',
'ssid': r'SSID: (.{1,32})'
}]
}]

Expand All @@ -76,12 +80,14 @@ def parse_iwconfig(data):
assert -127 <= float(wifi_sample['signal_level']) <= 127
assert wifi_sample['frequency'] is not None
assert wifi_sample['time_offset'] is not None
assert wifi_sample['ssid'] is not None

wifi_sample = IWConfigData(
wifi_sample['mac_address'],
float(wifi_sample['signal_level']),
frequency_string_to_khz(wifi_sample['frequency']),
wifi_sample['time_offset'])
wifi_sample['time_offset'],
wifi_sample['ssid'])

parsed_samples.append(wifi_sample)

Expand Down
18 changes: 12 additions & 6 deletions scantools/tests/test_iwconfig_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ def test_parse_iwconfig():
iwconfig_parser.IWConfigData(mac_address='82:2A:A8:9B:DA:E7',
signal_strength_dbm=-70.0,
frequency_khz=5180000,
time_offset_ms='24'),
time_offset_ms='24',
ssid='THA-MDE-CH'),
iwconfig_parser.IWConfigData(mac_address='82:2A:DA:E7:A8:9B',
signal_strength_dbm=-56.0,
frequency_khz=2437000,
time_offset_ms='0'),
time_offset_ms='0',
ssid='OFT_E-READING'),
iwconfig_parser.IWConfigData(mac_address='82:2A:A8:9A:DA:E7',
signal_strength_dbm=56.0,
frequency_khz=2437000,
time_offset_ms='5160')
time_offset_ms='5160',
ssid='THA-MDE-CH')
]

with open(data_path, 'r') as f:
Expand All @@ -57,15 +60,18 @@ def test_parse_iwconfig():
iwconfig_parser.IWConfigData(mac_address='5e:fb:3a:c4:1b:77',
signal_strength_dbm=-72.0,
frequency_khz=2437000,
time_offset_ms='0'),
time_offset_ms='0',
ssid='DIRECT-77-HP M255 LaserJet'),
iwconfig_parser.IWConfigData(mac_address='e0:28:6d:c3:d9:cb',
signal_strength_dbm=-58.0,
frequency_khz=2437000,
time_offset_ms='10023'),
time_offset_ms='10023',
ssid='FRITZ!Box 7560 YG'),
iwconfig_parser.IWConfigData(mac_address='ec:b1:d7:d5:f8:81',
signal_strength_dbm=48.0,
frequency_khz=5180000,
time_offset_ms='488')
time_offset_ms='488',
ssid='HP-Print-81-Officejet 4630')
]

with open(data_path, 'r') as f:
Expand Down

0 comments on commit f4d83cb

Please sign in to comment.