ingests GET/SET/EXE commands

This commit is contained in:
Laika 2021-07-03 11:37:47 -04:00
parent 41356f5922
commit 9b58ca7528

View file

@ -1,5 +1,7 @@
import numpy as np import numpy as np
from sensor_module import gamma_sensor from gamma import gamma_sensor
from heartbeat import heartbeat_module
from location import location_module
from time import sleep from time import sleep
from astropy.coordinates import SkyCoord as sc from astropy.coordinates import SkyCoord as sc
from os import system from os import system
@ -12,51 +14,52 @@ DOWNLINK_FILESTORE = "../store/data"
class sat: class sat:
def __init__(self): def __init__(self):
self.location = self.get_loc()
self.attitude = sc(0,0, unit='deg', frame='icrs') self.attitude = sc(0,0, unit='deg', frame='icrs')
self.battery = 100.00 self.battery = 100.00
self.MTE = 0
self.kill = False
self.maneuver_q = []
self.maneuver_TTC = 0 #time to completion self.maneuver_TTC = 0 #time to completion
self.gyro_saturation = 0 self.gyro_saturation = 0
self.modules = [gamma_sensor(),gamma_sensor()] self.modules = {
"heartbeat" : heartbeat_module(),
def get_loc(self): "location" : location_module(),
""" #"power" : power_manager(),
retrieve location from orbit sim #"attitude" : attitude_module(),
""" "gamma_sensor" : gamma_sensor()
return (10,10,10) }
def get_status(self, command="null"):
status_string = ""
def check_command_q(self): def check_command_q(self):
cur_batch = [] cur_batch = []
with open("test_q","r") as q: with open("test_q","r") as q:
com_q = q.read().splitlines() com_q = q.read().splitlines()
for com in com_q: for com in com_q:
if int(com.split(":")[0]) == self.MTE: if int(com.split(":")[0]) == self.modules["heartbeat"].mod_get("MTE")[0]:
cur_batch.append(com) cur_batch.append(com)
return cur_batch return cur_batch
def spin(self): def spin(self):
while True: while True:
for m in self.modules: MTE = self.modules["heartbeat"].mod_get("MTE")[0]
m.mod_update() print(MTE)
print(m.mod_get("detections"))
if self.MTE % 10 == 0:
m.mod_set("flush", 1)
batch = self.check_command_q() batch = self.check_command_q()
print("MTE:", self.MTE)
print("COMS:", batch) for c in batch:
if self.MTE == 5: print(c)
self.kill = False com = c.split(":")
if self.kill: if com[1] == "GET" and len(com) == 4:
res = self.modules[com[2]].mod_get(com[3])
elif com[1] == "SET" and len(com) == 5:
res = self.modules[com[2]].mod_set(com[3],com[4])
elif com[1] == "EXE" and len(com) == 5:
res = self.modules[com[2]].mod_exe(com[3],com[4])
else:
res = (-1, "BAD COMMAND: " + c)
print(res)
for m in self.modules:
self.modules[m].mod_update()
if self.modules["heartbeat"].mod_get("kill")[0] == 1:
print("heading to bed") print("heading to bed")
return return
self.MTE += 1
sleep(1) sleep(1)