Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.
72 changes: 49 additions & 23 deletions communications/command_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def __init__(self, parent: MainSatelliteThread):
NormalCommandEnum.SudoCommand.value: self.sudo_command,
NormalCommandEnum.Picberry.value: self.picberry,
NormalCommandEnum.ExecPyFile.value: self.exec_py_file,
NormalCommandEnum.IgnoreLowBatt.value: self.ignore_low_battery,
NormalCommandEnum.MissionMode.value: self.set_mission_mode,
NormalCommandEnum.InitOpnav.value: self.init_opnav_parameters,
NormalCommandEnum.SetCommsOffTimes: self.set_comms_off_times
}

self.low_battery_commands = {
Expand All @@ -131,11 +135,8 @@ def __init__(self, parent: MainSatelliteThread):
self.sensor_commands = {}

self.test_commands = {
2: self.split,
3: self.run_opnav,
TestCommandEnum.ADCTest.value: self.adc_test,
TestCommandEnum.SeparationTest.value: self.separation_test,
6: self.gom_outputs,
7: self.comms_driver_test,
TestCommandEnum.LongString.value: self.print_long_string,
TestCommandEnum.PiShutdown.value: self.pi_shutdown,
Expand All @@ -160,6 +161,8 @@ def __init__(self, parent: MainSatelliteThread):
CommandCommandEnum.ShellCommand.value: self.shell_command
}

self.attitude_commands = {}

self.COMMAND_DICT = {
FMEnum.Boot.value: self.bootup_commands,
FMEnum.Restart.value: self.restart_commands,
Expand All @@ -171,7 +174,8 @@ def __init__(self, parent: MainSatelliteThread):
FMEnum.SensorMode.value: self.sensor_commands,
FMEnum.TestMode.value: self.test_commands,
FMEnum.CommsMode: self.comms_commands,
FMEnum.Command.value: self.command_commands
FMEnum.Command.value: self.command_commands,
FMEnum.AttitudeAdjustment.value: self.attitude_commands
}

for value in self.COMMAND_DICT.values():
Expand Down Expand Up @@ -277,13 +281,9 @@ def set_parameter(self, **kwargs):
def set_exit_lowbatt_threshold(self, **kwargs):
"""Does the same thing as set_parameter, but only for the EXIT_LOW_BATTERY_MODE_THRESHOLD parameter. Only
requires one kwarg and does some basic sanity checks on the passed value"""
value = kwargs['value']
value = kwargs['vbatt']
try:
assert 0 < value < 1.0 and float(value) is float
if value >= params.ENTER_LOW_BATTERY_MODE_THRESHOLD:
self.parent.logger.error(
f"New value for Exit LB thresh must be less than current Enter LB thresh value")
assert False
assert 4 < value < 8.5 and float(value) is float
self.set_parameter(name="EXIT_LOW_BATTERY_MODE_THRESHOLD", value=value)
except AssertionError:
self.parent.logger.error(f"Incompatible value {value} for EXIT_LOW_BATTERY_MODE_THRESHOLD")
Expand Down Expand Up @@ -340,8 +340,14 @@ def electrolysis(self, **kwargs):
state = kwargs[STATE]
delay = kwargs.get(DELAY, 0)
assert type(state) is bool
params.WANT_TO_ELECTROLYZE = state
self.parent.gom.set_electrolysis(state, delay=delay)

def ignore_low_battery(self, **kwargs):
"""This is obviously a very dangerous command. It's mainly meant for testing on the ground"""
ignore = kwargs[IGNORE]
params.IGNORE_LOW_BATTERY = ignore

# def burn(self, **kwargs):
# time_burn = kwargs['time']
# absolute = kwargs['absolute']
Expand Down Expand Up @@ -370,11 +376,13 @@ def reboot_pi():
os.system("reboot")
# add something here that adds to the restarts db that this restart was commanded

def cease_comms(self):
# I'm actually unsure of how to do this. Maybe do something with the GPIO pins so that the pi can't transmit
self.parent.logger.critical("Ceasing all communications")
# definitely should implement some sort of password and double verification to prevent accidental triggering
raise NotImplementedError
def cease_comms(self, **kwargs):
pword = kwargs[PASSWORD]
if pword == 123: # TODO, change
# I'm actually unsure of how to do this. Maybe do something with the GPIO pins so that the pi can't transmit
self.parent.logger.critical("Ceasing all communications")
# definitely should implement some sort of password and double verification to prevent accidental triggering
raise NotImplementedError

def set_system_clock(self, **kwargs): # Needs validation (talk to Viraj)
# need to validate this works, and need to integrate updating RTC
Expand Down Expand Up @@ -661,14 +669,6 @@ def get_gom_conf2(self, **kwargs):
# **current_config2_dict)
# self.parent.downlink_queue.put(acknowledgement)

def get_gom_conf1(self, **kwargs):
raise NotImplementedError

def set_gom_conf2(self, **kwargs):
raise NotImplementedError

def get_gom_conf2(self, **kwargs):
raise NotImplementedError

def shell_command(self, **kwargs):
cmd: str = kwargs.get(CMD)
Expand Down Expand Up @@ -698,6 +698,32 @@ def exec_py_file(self, **kwargs):
self.parent.logger.debug(f"CWD: {os.getcwd()}")
exec(open(filename).read())

def set_mission_mode(self, **kwargs):
mission_mode = kwargs[MISSION_MODE]
self.set_parameter(name='CURRENT_MISSION_MODE', value=mission_mode, hard_set=True)
self.parent.flight_mode.update_mission_mode(mission_mode)

return {MISSION_MODE: params.CURRENT_MISSION_MODE}

def init_opnav_parameters(self, **kwargs):
pos_x = kwargs[POSITION_X]
pos_y = kwargs[POSITION_Y]
pos_z = kwargs[POSITION_Z]
pos_t = kwargs[NASA_PROVIDED_TIME]

# TODO write above values to opnav db

self.set_parameter(name="WANT_TO_OPNAV", value=True, hard_set=True)

def set_comms_off_times(self, **kwargs):
comms_off_start = kwargs[COMMS_OFF_START]
comms_off_end = kwargs[COMMS_OFF_END]

self.set_parameter(name="COMMS_OFF_TIME_START", value=comms_off_start, hard_set=True)
self.set_parameter(name="COMMS_OFF_TIME_END", value=comms_off_end, hard_set=True)

return {COMMS_OFF_START: comms_off_start, COMMS_OFF_END: comms_off_end}


def dict_from_eps_config(config: ps.eps_config_t) -> dict:
return {PPT_MODE: config.ppt_mode,
Expand Down
2 changes: 1 addition & 1 deletion flight_modes/attitude_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def C3(theta):
"""

class AAMode(PauseBackgroundMode):
"""Attitude adjustment flight mode"""
"""FMID 11: Attitude adjustment flight mode"""

flight_mode_id = FMEnum.AttitudeAdjustment.value
command_codecs = {}
Expand Down
Loading