Skip to content

Commit 963e2a2

Browse files
committed
Keep valid toolbar settings after capture restart
1 parent 2af7e4a commit 963e2a2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

nrf802154_sniffer/nrf802154_sniffer.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ def control_reader(self, fifo):
305305
if typ == Nrf802154Sniffer.CTRL_CMD_INITIALIZED:
306306
self.initialized.set()
307307
elif arg == Nrf802154Sniffer.CTRL_ARG_CHANNEL and typ == Nrf802154Sniffer.CTRL_CMD_SET and payload:
308+
self.channel = int(payload)
309+
while self.running.is_set() and not self.setup_done.is_set():
310+
time.sleep(0.1)
308311
self.serial_queue.put(b'channel ' + payload)
309312

310313
self.stop_sig_handler()
@@ -375,7 +378,7 @@ def serial_writer(self):
375378
except Queue.Empty:
376379
break
377380

378-
def serial_reader(self, dev, channel, queue):
381+
def serial_reader(self, dev, queue):
379382
"""
380383
Thread responsible for reading from serial port, parsing the output and storing parsed packets into queue.
381384
"""
@@ -396,7 +399,7 @@ def serial_reader(self, dev, channel, queue):
396399
init_cmd = []
397400
init_cmd.append(b'')
398401
init_cmd.append(b'sleep')
399-
init_cmd.append(b'channel ' + bytes(str(channel).encode()))
402+
init_cmd.append(b'channel ' + bytes(str(self.channel).encode()))
400403
for cmd in init_cmd:
401404
self.serial_queue.put(cmd)
402405

@@ -427,7 +430,7 @@ def serial_reader(self, dev, channel, queue):
427430
rssi = int(m.group(2))
428431
lqi = int(m.group(3))
429432
timestamp = int(m.group(4)) & 0xffffffff
430-
channel = int(channel)
433+
channel = int(self.channel)
431434
queue.put(self.pcap_packet(packet, channel, rssi, lqi, self.correct_time(timestamp)))
432435
buf = b''
433436

@@ -473,19 +476,23 @@ def extcap_capture(self, fifo, dev, channel, control_in=None, control_out=None):
473476

474477
if control_out:
475478
self.threads.append(threading.Thread(target=self.control_writer, args=(control_out,)))
476-
if self.channel:
477-
self.control_send(Nrf802154Sniffer.CTRL_ARG_CHANNEL, Nrf802154Sniffer.CTRL_CMD_SET, self.channel.encode())
478479

479480
if control_in:
480481
self.threads.append(threading.Thread(target=self.control_reader, args=(control_in,)))
481482

482-
self.threads.append(threading.Thread(target=self.serial_reader, args=(self.dev, self.channel, packet_queue), name="serial_reader"))
483+
self.threads.append(threading.Thread(target=self.serial_reader, args=(self.dev, packet_queue), name="serial_reader"))
483484
self.threads.append(threading.Thread(target=self.serial_writer, name="serial_writer"))
484485
self.threads.append(threading.Thread(target=self.fifo_writer, args=(fifo, packet_queue), name="fifo_writer"))
485486

486487
for thread in self.threads:
487488
thread.start()
488489

490+
while self.running.is_set() and not self.initialized.is_set():
491+
time.sleep(0.1)
492+
493+
time.sleep(0.1)
494+
self.control_send(Nrf802154Sniffer.CTRL_ARG_CHANNEL, Nrf802154Sniffer.CTRL_CMD_SET, str(self.channel).encode())
495+
489496
while is_standalone and self.running.is_set():
490497
time.sleep(1)
491498

0 commit comments

Comments
 (0)