Skip to content

Commit

Permalink
Add gps settings/initialization to scos-sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
cheroy-ntia committed Mar 1, 2024
1 parent 26394a7 commit a6c6fb3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ SECRET_KEY="$(python3 -c 'import secrets; print(secrets.token_urlsafe(64))')"
SIGAN_CLASS=TekRSASigan
SIGAN_MODULE=scos_tekrsa.hardware.tekrsa_sigan

GPS_CLASS=MockGPS
GPS_MODULE=scos_action.hardware.mocks.mock_gps

# SECURITY WARNING: You should be using certs from a trusted authority.
# If you don't have any, try letsencrypt or a similar service.
# Provide the absolute path to your ssl certificate and key
Expand Down
31 changes: 31 additions & 0 deletions src/initialization/sensor_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,47 @@ def load_sensor(sensor_capabilities: dict) -> Sensor:
except Exception as ex:
logger.warning(f"unable to create signal analyzer: {ex}")

gps = None
try:
if not settings.RUNNING_MIGRATIONS:
check_for_required_gps_settings()
gps_module_setting = settings.GPS_MODULE
gps_module = importlib.import_module(gps_module_setting)
logger.info(
"Creating " + settings.GPS_CLASS + " from " + settings.GPS_MODULE
)
gps_constructor = getattr(gps_module, settings.GPS_CLASS)
gps = gps_constructor()
register_component_with_status.send(gps, component=gps)
else:
logger.info("Running migrations. Not loading GPS.")
except Exception as ex:
logger.warning(f"unable to create GPS: {ex}")

sensor = Sensor(
signal_analyzer=sigan,
capabilities=sensor_capabilities,
preselector=preselector,
switches=switches,
location=location,
gps=gps,
)
return sensor


def check_for_required_gps_settings():
error = ""
raise_exception = False
if settings.GPS_MODULE is None:
raise_exception = True
error = "GPS_MODULE environment variable must be set. "
if settings.GPS_CLASS is None:
raise_exception = True
error += "GPS_CLASS environment variable. "
if raise_exception:
raise Exception(error)


def check_for_required_sigan_settings():
error = ""
raise_exception = False
Expand Down

0 comments on commit a6c6fb3

Please sign in to comment.