Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Wifi SSIDs and convert to Capture and add back NavVis test data #68

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locals like these do not bring much value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know.. was rather following the pattern

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we verify we can do this? we've recently found that some WiFi samples on some other platforms do not contain ssid so flagging here whether we're certain this is always available

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For NavVis I have not seen any wifi sample without it. And I would argue we should also be strict here. Thanks for checking.


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