FreeDATA/modem/beacon.py

54 lines
1.4 KiB
Python
Raw Normal View History

2023-11-26 14:23:20 +00:00
import threading
import data_frame_factory
import time
2023-11-26 14:45:41 +00:00
import command_beacon
2023-11-26 20:51:19 +00:00
from state_manager import StateManager
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
2023-11-26 20:51:19 +00:00
def __init__(self, config, modem_states: StateManager, 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 = modem_states
self.event_queue = event_queue
self.log = logger
self.tx_frame_queue = modem_tx_queue
2023-11-26 14:23:20 +00:00
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
2023-11-26 20:51:19 +00:00
def refresh(self):
self.event.set()
self.event.clear()
def run_beacon(self) -> None:
"""
Controlling function for running a beacon
Args:
self: arq class
Returns:
"""
2023-11-26 14:23:20 +00:00
while True:
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)