FreeDATA/modem/beacon.py

47 lines
1.3 KiB
Python
Raw Normal View History

2023-11-26 14:23:20 +00:00
import threading
import data_frame_factory
2023-11-26 14:45:41 +00:00
import command_beacon
2023-11-26 14:23:20 +00:00
2023-11-26 20:51:19 +00:00
class Beacon:
2023-11-26 14:23:20 +00:00
2023-11-26 20:51:19 +00:00
BEACON_LOOP_INTERVAL = 1
2023-11-26 14:23:20 +00:00
def __init__(self, config, states, event_queue, logger, modem_tx_queue):
2023-11-26 14:23:20 +00:00
2023-11-26 20:51:19 +00:00
self.modem_config = config
self.states = states
2023-11-26 20:51:19 +00:00
self.event_queue = event_queue
self.log = logger
self.tx_frame_queue = modem_tx_queue
2023-11-26 14:23:20 +00:00
self.loop_running = True
2023-11-26 20:51:19 +00:00
self.paused = False
self.thread = None
self.event = threading.Event()
2023-11-26 14:23:20 +00:00
2023-11-26 20:51:19 +00:00
self.frame_factory = data_frame_factory.DataFrameFactory(config)
2023-11-26 14:23:20 +00:00
2023-11-26 20:51:19 +00:00
def start(self):
beacon_thread = threading.Thread(target=self.run_beacon, name="beacon", daemon=True)
beacon_thread.start()
2023-11-26 14:23:20 +00:00
def stop(self):
self.loop_running = False
2023-11-26 20:51:19 +00:00
def refresh(self):
self.event.set()
self.event.clear()
def run_beacon(self) -> None:
while self.loop_running:
2023-11-26 20:51:19 +00:00
while (self.states.is_beacon_running and
not self.paused and
True):
#not self.states.channel_busy):
2023-11-26 14:23:20 +00:00
2023-11-26 20:51:19 +00:00
cmd = command_beacon.BeaconCommand(self.modem_config, self.log)
cmd.run(self.event_queue, self.tx_frame_queue)
self.event.wait(self.modem_config['MODEM']['beacon_interval'])
2023-11-26 14:23:20 +00:00
2023-11-26 20:51:19 +00:00
self.event.wait(self.BEACON_LOOP_INTERVAL)