mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
better error handling for config
This commit is contained in:
parent
e22736ae02
commit
ef8b309fa6
3 changed files with 36 additions and 26 deletions
|
@ -112,7 +112,7 @@ class CONFIG:
|
||||||
# is_writing means data from a dict being writen to the config file
|
# is_writing means data from a dict being writen to the config file
|
||||||
# if False, it means the opposite direction
|
# if False, it means the opposite direction
|
||||||
def handle_setting(self, section, setting, value, is_writing = False):
|
def handle_setting(self, section, setting, value, is_writing = False):
|
||||||
|
try:
|
||||||
if self.config_types[section][setting] == list:
|
if self.config_types[section][setting] == list:
|
||||||
if (is_writing):
|
if (is_writing):
|
||||||
return json.dumps(value)
|
return json.dumps(value)
|
||||||
|
@ -127,6 +127,8 @@ class CONFIG:
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
except KeyError as key:
|
||||||
|
self.log.error("[CFG] key error in logfile, please check 'config.ini.example' for help", key=key)
|
||||||
|
|
||||||
# Sets and writes config data from a dict containing data settings
|
# Sets and writes config data from a dict containing data settings
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
|
|
|
@ -73,11 +73,11 @@ class FrameHandler():
|
||||||
|
|
||||||
def make_event(self):
|
def make_event(self):
|
||||||
event = {
|
event = {
|
||||||
"freedata": "modem-message",
|
"type": "frame-handler",
|
||||||
"received": self.details['frame']['frame_type'],
|
"received": self.details['frame']['frame_type'],
|
||||||
"uuid": str(uuid.uuid4()),
|
|
||||||
"timestamp": int(time.time()),
|
"timestamp": int(time.time()),
|
||||||
"mycallsign": self.config['STATION']['mycall'],
|
"mycallsign": self.config['STATION']['mycall'],
|
||||||
|
"myssid": self.config['STATION']['myssid'],
|
||||||
"snr": str(self.details['snr']),
|
"snr": str(self.details['snr']),
|
||||||
}
|
}
|
||||||
if 'origin' in self.details['frame']:
|
if 'origin' in self.details['frame']:
|
||||||
|
@ -101,7 +101,6 @@ class FrameHandler():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def log(self):
|
def log(self):
|
||||||
return
|
|
||||||
self.logger.info(f"[Frame Handler] Handling frame {self.details['frame']['frame_type']}")
|
self.logger.info(f"[Frame Handler] Handling frame {self.details['frame']['frame_type']}")
|
||||||
|
|
||||||
def handle(self, frame, snr, frequency_offset, freedv_inst, bytes_per_frame):
|
def handle(self, frame, snr, frequency_offset, freedv_inst, bytes_per_frame):
|
||||||
|
@ -114,5 +113,5 @@ class FrameHandler():
|
||||||
self.log()
|
self.log()
|
||||||
self.add_to_heard_stations()
|
self.add_to_heard_stations()
|
||||||
self.add_to_activity_list()
|
self.add_to_activity_list()
|
||||||
self.emit_event()
|
#self.emit_event()
|
||||||
self.follow_protocol()
|
self.follow_protocol()
|
||||||
|
|
|
@ -27,9 +27,7 @@ class SM:
|
||||||
)
|
)
|
||||||
runner_thread.start()
|
runner_thread.start()
|
||||||
|
|
||||||
# optionally start explorer module
|
self.start_explorer_publishing()
|
||||||
if self.config['STATION']['enable_explorer']:
|
|
||||||
explorer.explorer(self.app, self.config, self.states)
|
|
||||||
|
|
||||||
def runner(self):
|
def runner(self):
|
||||||
while True:
|
while True:
|
||||||
|
@ -102,12 +100,15 @@ class SM:
|
||||||
self.event_manager.modem_stopped()
|
self.event_manager.modem_stopped()
|
||||||
|
|
||||||
def test_audio(self):
|
def test_audio(self):
|
||||||
|
try:
|
||||||
audio_test = audio.test_audio_devices(self.config['AUDIO']['input_device'],
|
audio_test = audio.test_audio_devices(self.config['AUDIO']['input_device'],
|
||||||
self.config['AUDIO']['output_device'])
|
self.config['AUDIO']['output_device'])
|
||||||
self.log.info("tested audio devices", result=audio_test)
|
self.log.info("tested audio devices", result=audio_test)
|
||||||
|
|
||||||
return audio_test
|
return audio_test
|
||||||
|
except Exception as e:
|
||||||
|
self.log.error("Error testing audio devices", e=e)
|
||||||
|
return [False, False]
|
||||||
|
|
||||||
def start_beacon(self):
|
def start_beacon(self):
|
||||||
self.beacon = beacon.Beacon(self.config, self.states, self.event_manager, self.log, self.modem)
|
self.beacon = beacon.Beacon(self.config, self.states, self.event_manager, self.log, self.modem)
|
||||||
|
@ -115,3 +116,11 @@ class SM:
|
||||||
|
|
||||||
def stop_beacon(self):
|
def stop_beacon(self):
|
||||||
del self.beacon
|
del self.beacon
|
||||||
|
|
||||||
|
def start_explorer_publishing(self):
|
||||||
|
try:
|
||||||
|
# optionally start explorer module
|
||||||
|
if self.config['STATION']['enable_explorer']:
|
||||||
|
explorer.explorer(self.app, self.config, self.states)
|
||||||
|
except Exception as e:
|
||||||
|
self.log.warning("[EXPLORER] Publishin not started because of error", e=e)
|
Loading…
Reference in a new issue