diff --git a/modem/config.py b/modem/config.py index 65a59552..ac8e0ee0 100644 --- a/modem/config.py +++ b/modem/config.py @@ -112,21 +112,23 @@ class CONFIG: # is_writing means data from a dict being writen to the config file # if False, it means the opposite direction def handle_setting(self, section, setting, value, is_writing = False): + try: + if self.config_types[section][setting] == list: + if (is_writing): + return json.dumps(value) + else: + return json.loads(value) + + elif self.config_types[section][setting] == bool and not is_writing: + return self.parser.getboolean(section, setting) + + elif self.config_types[section][setting] == int and not is_writing: + return self.parser.getint(section, setting) - if self.config_types[section][setting] == list: - if (is_writing): - return json.dumps(value) else: - return json.loads(value) - - elif self.config_types[section][setting] == bool and not is_writing: - return self.parser.getboolean(section, setting) - - elif self.config_types[section][setting] == int and not is_writing: - return self.parser.getint(section, setting) - - 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 def write(self, data): diff --git a/modem/frame_handler.py b/modem/frame_handler.py index a66ab8b4..7f3d4efb 100644 --- a/modem/frame_handler.py +++ b/modem/frame_handler.py @@ -73,13 +73,13 @@ class FrameHandler(): def make_event(self): event = { - "freedata": "modem-message", + "type": "frame-handler", "received": self.details['frame']['frame_type'], - "uuid": str(uuid.uuid4()), "timestamp": int(time.time()), "mycallsign": self.config['STATION']['mycall'], + "myssid": self.config['STATION']['myssid'], "snr": str(self.details['snr']), - } + } if 'origin' in self.details['frame']: event['dxcallsign'] = self.details['frame']['origin'] return event @@ -101,7 +101,6 @@ class FrameHandler(): pass def log(self): - return 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): @@ -114,5 +113,5 @@ class FrameHandler(): self.log() self.add_to_heard_stations() self.add_to_activity_list() - self.emit_event() + #self.emit_event() self.follow_protocol() diff --git a/modem/service_manager.py b/modem/service_manager.py index 6909a8f3..b352f4ac 100644 --- a/modem/service_manager.py +++ b/modem/service_manager.py @@ -27,9 +27,7 @@ class SM: ) runner_thread.start() - # optionally start explorer module - if self.config['STATION']['enable_explorer']: - explorer.explorer(self.app, self.config, self.states) + self.start_explorer_publishing() def runner(self): while True: @@ -102,12 +100,15 @@ class SM: self.event_manager.modem_stopped() def test_audio(self): - audio_test = audio.test_audio_devices(self.config['AUDIO']['input_device'], - self.config['AUDIO']['output_device']) - self.log.info("tested audio devices", result=audio_test) - - return audio_test + try: + audio_test = audio.test_audio_devices(self.config['AUDIO']['input_device'], + self.config['AUDIO']['output_device']) + self.log.info("tested audio devices", result=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): 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): 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) \ No newline at end of file