mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Improve beacon
This commit is contained in:
parent
7c5cdc1290
commit
ff0e4c25a2
|
@ -2,64 +2,53 @@ import threading
|
||||||
import data_frame_factory
|
import data_frame_factory
|
||||||
import time
|
import time
|
||||||
import command_beacon
|
import command_beacon
|
||||||
|
from state_manager import StateManager
|
||||||
|
|
||||||
modem_config = None
|
class Beacon:
|
||||||
states = None
|
|
||||||
beacon_interval = 0
|
|
||||||
beacon_interval_timer = 0
|
|
||||||
beacon_paused = False
|
|
||||||
beacon_thread = None
|
|
||||||
frame_factory = None
|
|
||||||
event_manager = None
|
|
||||||
log = None
|
|
||||||
|
|
||||||
def init(config, modem_states, ev_manager, logger):
|
BEACON_LOOP_INTERVAL = 1
|
||||||
modem_config = config
|
|
||||||
states = modem_states
|
|
||||||
frame_factory = data_frame_factory.DataFrameFactory(modem_config)
|
|
||||||
event_manager = ev_manager
|
|
||||||
log = logger
|
|
||||||
|
|
||||||
def start():
|
def __init__(self, config, modem_states: StateManager, event_queue, logger, modem_tx_queue):
|
||||||
beacon_thread = threading.Thread(
|
|
||||||
target=start, name="beacon", daemon=True
|
|
||||||
)
|
|
||||||
|
|
||||||
beacon_thread.start()
|
self.modem_config = config
|
||||||
|
self.states = modem_states
|
||||||
|
self.event_queue = event_queue
|
||||||
|
self.log = logger
|
||||||
|
self.tx_frame_queue = modem_tx_queue
|
||||||
|
|
||||||
def run_beacon() -> None:
|
self.paused = False
|
||||||
"""
|
self.thread = None
|
||||||
Controlling function for running a beacon
|
self.event = threading.Event()
|
||||||
Args:
|
|
||||||
|
|
||||||
self: arq class
|
self.frame_factory = data_frame_factory.DataFrameFactory(config)
|
||||||
|
|
||||||
Returns:
|
def start(self):
|
||||||
|
beacon_thread = threading.Thread(target=self.run_beacon, name="beacon", daemon=True)
|
||||||
|
beacon_thread.start()
|
||||||
|
|
||||||
"""
|
def refresh(self):
|
||||||
try:
|
self.event.set()
|
||||||
|
self.event.clear()
|
||||||
|
|
||||||
|
def run_beacon(self) -> None:
|
||||||
|
"""
|
||||||
|
Controlling function for running a beacon
|
||||||
|
Args:
|
||||||
|
|
||||||
|
self: arq class
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
while True:
|
while True:
|
||||||
threading.Event().wait(0.5)
|
while (self.states.is_beacon_running and
|
||||||
while states.is_beacon_running:
|
not self.paused and
|
||||||
if (
|
True):
|
||||||
not states.is_arq_session
|
#not self.states.channel_busy):
|
||||||
#and not arq_file_transfer
|
|
||||||
and not beacon_paused
|
|
||||||
#and not states.channel_busy
|
|
||||||
and not states.is_modem_busy
|
|
||||||
and not states.is_arq_state
|
|
||||||
):
|
|
||||||
|
|
||||||
cmd = command_beacon.BeaconCommand(modem_config, log)
|
cmd = command_beacon.BeaconCommand(self.modem_config, self.log)
|
||||||
cmd.run()
|
cmd.run(self.event_queue, self.tx_frame_queue)
|
||||||
|
self.event.wait(self.modem_config['MODEM']['beacon_interval'])
|
||||||
|
|
||||||
beacon_interval_timer = time.time() + beacon_interval
|
self.event.wait(self.BEACON_LOOP_INTERVAL)
|
||||||
while (
|
|
||||||
time.time() < beacon_interval_timer
|
|
||||||
and states.is_beacon_running
|
|
||||||
and not beacon_paused
|
|
||||||
):
|
|
||||||
threading.Event().wait(0.01)
|
|
||||||
|
|
||||||
except Exception as err:
|
|
||||||
log.debug("[Modem] run_beacon: ", exception=err)
|
|
||||||
|
|
|
@ -2,15 +2,11 @@ from command import TxCommand
|
||||||
|
|
||||||
class BeaconCommand(TxCommand):
|
class BeaconCommand(TxCommand):
|
||||||
|
|
||||||
def set_params_from_api(self, apiParams):
|
|
||||||
self.enable_morse = apiParams['enable_morse']
|
|
||||||
return super().set_params_from_api(apiParams)
|
|
||||||
|
|
||||||
def build_frame(self):
|
def build_frame(self):
|
||||||
return self.frame_factory.build_beacon()
|
return self.frame_factory.build_beacon()
|
||||||
|
|
||||||
def transmit(self, tx_frame_queue):
|
def transmit(self, tx_frame_queue):
|
||||||
super().transmit(tx_frame_queue)
|
super().transmit(tx_frame_queue)
|
||||||
if self.enable_morse:
|
if self.config['MODEM']['enable_morse_identifier']:
|
||||||
mycall = f"{self.config['STATION']['mycall']}-{self.config['STATION']['myssid']}"
|
mycall = f"{self.config['STATION']['mycall']}-{self.config['STATION']['myssid']}"
|
||||||
tx_frame_queue.put(["morse", 1, 0, mycall])
|
tx_frame_queue.put(["morse", 1, 0, mycall])
|
||||||
|
|
|
@ -29,8 +29,8 @@ class BROADCAST(DATA):
|
||||||
|
|
||||||
self.event_manager = event_manager.EventManager([event_queue])
|
self.event_manager = event_manager.EventManager([event_queue])
|
||||||
|
|
||||||
beacon.init(self.config, self.states, self.event_manager, self.log)
|
self.beacon = beacon.Beacon(self.config, self.states, event_queue, self.log, MODEM_TRANSMIT_QUEUE)
|
||||||
beacon.start()
|
self.beacon.start()
|
||||||
|
|
||||||
# length of signalling frame
|
# length of signalling frame
|
||||||
self.length_sig0_frame = 14
|
self.length_sig0_frame = 14
|
||||||
|
|
Loading…
Reference in a new issue