Compare commits
20 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dd5295c3fb | ||
![]() |
f856c7b619 | ||
![]() |
44ce4b07d3 | ||
![]() |
9598a855c4 | ||
![]() |
b823c0d6d8 | ||
![]() |
7935441d91 | ||
![]() |
c575625013 | ||
![]() |
4a1640d1c3 | ||
![]() |
2458fb3616 | ||
![]() |
2ff27a652d | ||
![]() |
9b58ca7528 | ||
![]() |
41356f5922 | ||
![]() |
9728b5cc98 | ||
![]() |
652e122d30 | ||
![]() |
a9a7e1eead | ||
![]() |
813783c9f9 | ||
![]() |
9cb4e1f74c | ||
![]() |
5fd6c6a753 | ||
![]() |
ac51bd67f6 | ||
![]() |
c24a62e503 |
62
interface/sat_infc.py
Normal file
62
interface/sat_infc.py
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
import asyncio, telnetlib3
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def shell(reader, writer):
|
||||||
|
writer.write('\r\nWelcome to the BoSLOO Primitive Interface!\r\nBPI for debugging and has no checking or feedback, use with caution!\r\n-=>')
|
||||||
|
go = True
|
||||||
|
com = ""
|
||||||
|
while go:
|
||||||
|
inp = yield from reader.read(1)
|
||||||
|
for c in inp:
|
||||||
|
com += c
|
||||||
|
if c == '\x7f':
|
||||||
|
writer.write("\r" + " "*(len(com)+1))
|
||||||
|
com = com[:-2]
|
||||||
|
writer.write("\r-=>" + com + " ")
|
||||||
|
writer.write("\r-=>" + com)
|
||||||
|
yield from writer.drain()
|
||||||
|
else:
|
||||||
|
writer.echo(inp)
|
||||||
|
if c == '\r':
|
||||||
|
print(com)
|
||||||
|
writer.write('\r\n')
|
||||||
|
com = com.strip()
|
||||||
|
if com == "bye":
|
||||||
|
writer.close()
|
||||||
|
go = False
|
||||||
|
elif com[:4] == "help":
|
||||||
|
writer.write('ops: GET/SET/EXE\r\n')
|
||||||
|
writer.write('Op:MTE(s):Subsystem:Field:Parameter\r\n')
|
||||||
|
writer.write('Parameter only for SET\r\n')
|
||||||
|
writer.write('MTE to get current time\r\n')
|
||||||
|
yield from writer.drain()
|
||||||
|
elif com[:4].upper() == "GET:" or com[:4].upper() == "SET:" or com[:4].upper() == "EXE:":
|
||||||
|
parts = com.split(":")
|
||||||
|
if (parts[0].upper() == "GET" or parts[0].upper() == "EXE") and len(parts) == 4:
|
||||||
|
print("wrote command = ", parts[1]+":"+parts[0].upper()+":"+parts[2]+":"+parts[3])
|
||||||
|
with open('../satsim/command_q', "a") as q:
|
||||||
|
q.write(parts[1]+":"+parts[0].upper()+":"+parts[2]+":"+parts[3]+"\n")
|
||||||
|
elif parts[0].upper() == "SET" and len(parts) == 5:
|
||||||
|
print("wrote command = ", parts[1]+":"+parts[0].upper()+":"+parts[2]+":"+parts[3]+":"+parts[4])
|
||||||
|
with open('../satsim/command_q', "a") as q:
|
||||||
|
q.write(parts[1]+":"+parts[0].upper()+":"+parts[2]+":"+parts[3]+":"+parts[4]+"\n")
|
||||||
|
else:
|
||||||
|
writer.write("BAD OP COMMAND\r\n")
|
||||||
|
yield from writer.drain()
|
||||||
|
elif com[:3].upper() == "MTE" and len(com) == 3:
|
||||||
|
with open("../satsim/status", "r") as statfile:
|
||||||
|
mte = statfile.read()
|
||||||
|
writer.write(mte + "\r\n")
|
||||||
|
yield from writer.drain()
|
||||||
|
else:
|
||||||
|
writer.write("BAD COMMAND\r\n")
|
||||||
|
yield from writer.drain()
|
||||||
|
if go:
|
||||||
|
writer.write('-=>')
|
||||||
|
yield from writer.drain()
|
||||||
|
com = ""
|
||||||
|
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
coro = telnetlib3.create_server(port=7000, shell=shell)
|
||||||
|
server = loop.run_until_complete(coro)
|
||||||
|
loop.run_until_complete(server.wait_closed())
|
10
satsim/command_q
Normal file
10
satsim/command_q
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
2:GET:heartbeat:MTE
|
||||||
|
4:GET:location:coords
|
||||||
|
5:SET:memory:filename:shark.bmp
|
||||||
|
6:SET:memory:buffer:Qk1+BgAAAAAAAD4AAAAoAAAAZAAAAGQAAAABAAEAAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wD////////////////wAAAA////////////////8AAAAP////////////////AAAAD//////////8/////wAAAA//////////+P////8AAAAP//////////j/////AAAAD//////////4f////wAAAA///////////H////8AAAAP//////////x/////AAAAD//n//////x8f////wAAAA//x//////4fD////8AAAAP/8P/+fgH/H4/////AAAAD//j//HwB/w+H////wAAAA//4//x+Af8Px////8AAAAP/+P/8f/H/j8P////AAAAD//h//D/x/4AD////wAAAA//8f/4/8f+AAf///8AAAAP//H/+P/H/wAH////AAAAD//w//j/x/+Hw////wAAAA//+P/4f4f/x+P///8AAAAP//j4PH+P/8Pj////AAAAD//4ABx/j//h4////wAAAA//+AAcf4//4eP///8AAAAP//gDPD+H8/H3////AAAAD//4//4/g8P7/////wAAAA//+P/+P8AD//////8AAAAP//h//j/gB///////AAAAD//8f/9/8B///////wAAAA///Hx///////////8AAAAP//wAf///////////AAAAD//8AP///////////wAAAA///gH/+P////////8AAAAP//////D/////////AAAAD//////w/////////wAAAA//////4P////////8AAAAP/////+D/////////AAAAD/////+Af////f///wAAAA//////AH////H///8AAAAP/////gx////A////AAAAD////8AAA///AP///wAAAA////+AAAAH/gD///8AAAAP///+AAAAAPgY////AAAAD////Bx/+AAgeP///wAAAA////g+///wAPj///8AAAAP///wf////AP4////AAAAD///4B////AD+P///wAAAA///8AP///gYfD///8AAAAP///Dz///wfBw////AAAAD///h////gP4MP///wAAAA///4////wP/BH///8AAAAP//+P4//wH/4B////AAAAD///j8P/wP//Af///wAAAA///w/D/gH//8H///8AAAAP//8f5/wH///h////AAAAD///H//gB///8f///wAAAA///w//AMf///H///8AAAAP//8P/AGH////////AAAAD///gAAPj////////wAAAA///4AAB4////////8AAAAP///AAAGP////////AAAAD//////Aj////////wAAAA//////8A////////8AAAAP//////gP////////AAAAD//////8D////////wAAAA///////g////////8AAAAP//////+f////////AAAAD////////////////wAAAA////////////////8AAAAP////////////////AAAAD////////////////wAAAA////////////////8AAAAP////////////////AAAAD////////////////wAAAA////////////////8AAAAP////////////////AAAAD////////////////wAAAA////////////////8AAAAP////////////////AAAAD/////gf/n///////wAAAA/n///wH/x///////8AAAAPx/8B8A/8P///////AAAAD8f+APuP/j///////wAAAA/H/gD/j/4///////8AAAAPx/45/4/+H///////AAAAD8f+P/+P/x///////wAAAA/H/j//D/8f//////8AAAAPx/4//x//H///////AAAAD8f+P/4f/w///////wAAAA+H/AH8P/+MH/////8AAAAPj/gB+H/ngB//////AAAAD4/8A/j/wAA//////wAAAA8P/h/4H8AB//////8AAAAPH/4/+APgD///////AAAADx/+AAwD/////////wAAAAAf/gAPx/////////8AAAAAAA8AH///////////AAAAAAAP/////////////wAAAA4AH/////////////8AAAAP////////////////AAAAD////////////////wAAAA
|
||||||
|
7:EXE:memory
|
||||||
|
8:GET:memory:freeSpace
|
||||||
|
8:SET:memory:mode:download
|
||||||
|
8:SET:memory:filename:badtest
|
||||||
|
9:EXE:memory
|
||||||
|
10:SET:heartbeat:kill:1
|
BIN
satsim/datastore/shark_decoded.bmp
Normal file
BIN
satsim/datastore/shark_decoded.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
0
satsim/modules/__init__.py
Normal file
0
satsim/modules/__init__.py
Normal file
43
satsim/modules/gamma.py
Normal file
43
satsim/modules/gamma.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
from .module import module
|
||||||
|
from random import randint
|
||||||
|
class gamma_sensor(module):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("gammaSensor")
|
||||||
|
self.fields["detections"] = 0
|
||||||
|
self.fields["detections_str"] = []
|
||||||
|
self.fields["threshold"] = 90
|
||||||
|
self.fields["flush"] = 0
|
||||||
|
self.writable = ["threshold","flush"]
|
||||||
|
|
||||||
|
def mod_get(self, field="none"):
|
||||||
|
if field not in self.fields:
|
||||||
|
return (-1, "GET FATAL: field '" + field + "'' does not exist in module: " + self.fields["name"])
|
||||||
|
return (self.fields[field], "GET OK")
|
||||||
|
|
||||||
|
def mod_set(self, field="none", value="none"):
|
||||||
|
if field not in self.fields:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "'' does not exist in module: " + self.fields["name"])
|
||||||
|
if field not in self.writable:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "' is not writable in module: " + self.fields["name"])
|
||||||
|
try:
|
||||||
|
self.fields[field] = int(value)
|
||||||
|
return (0, "SET OK")
|
||||||
|
except:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "' in module: " + self.fields["name"] + " takes int")
|
||||||
|
|
||||||
|
def mod_exe(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def mod_not(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def mod_update(self):
|
||||||
|
if self.fields["flush"] != 0:
|
||||||
|
self.fields["detections"] = 0
|
||||||
|
self.fields["detections_str"] = []
|
||||||
|
self.fields["flush"] = 0
|
||||||
|
for i in range(0,randint(4,100)):
|
||||||
|
strength = randint(0,100)
|
||||||
|
if strength > self.fields["threshold"]:
|
||||||
|
self.fields["detections"] += 1
|
||||||
|
self.fields["detections_str"].append(strength)
|
33
satsim/modules/heartbeat.py
Normal file
33
satsim/modules/heartbeat.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
from .module import module
|
||||||
|
|
||||||
|
class heartbeat_module(module):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("heartbeat")
|
||||||
|
self.fields["MTE"] = 0
|
||||||
|
self.fields["kill"] = 0
|
||||||
|
self.writable = ["kill"]
|
||||||
|
|
||||||
|
def mod_get(self, field="none"):
|
||||||
|
if field not in self.fields:
|
||||||
|
return (-1, "GET FATAL: field '" + field + "'' does not exist in module: " + self.fields["name"])
|
||||||
|
return (self.fields[field], "GET OK")
|
||||||
|
|
||||||
|
def mod_set(self, field="none", value="none"):
|
||||||
|
if field not in self.fields:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "'' does not exist in module: " + self.fields["name"])
|
||||||
|
if field not in self.writable:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "' is not writable in module: " + self.fields["name"])
|
||||||
|
try:
|
||||||
|
self.fields[field] = int(value)
|
||||||
|
return (0, "SET OK")
|
||||||
|
except:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "' in module: " + self.fields["name"] + " takes int")
|
||||||
|
|
||||||
|
def mod_exe(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def mod_not(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def mod_update(self):
|
||||||
|
self.fields["MTE"] += 1
|
28
satsim/modules/location.py
Normal file
28
satsim/modules/location.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
from .module import module
|
||||||
|
class location_module(module):
|
||||||
|
id_c = 0
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("location")
|
||||||
|
self.fields["coords"] = "space"
|
||||||
|
|
||||||
|
def mod_get(self, field="none"):
|
||||||
|
if field not in self.fields:
|
||||||
|
return (-1, "GET FATAL: field '" + field + "'' does not exist in module: " + self.fields["name"])
|
||||||
|
return (self.fields[field], "GET OK")
|
||||||
|
|
||||||
|
def mod_set(self, field="none", value="none"):
|
||||||
|
if field not in self.fields:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "'' does not exist in module: " + self.fields["name"])
|
||||||
|
if field not in self.writable:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "' is not writable in module: " + self.fields["name"])
|
||||||
|
try:
|
||||||
|
self.fields[field] = int(value)
|
||||||
|
return (0, "SET OK")
|
||||||
|
except:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "' in module: " + self.fields["name"] + " takes int")
|
||||||
|
|
||||||
|
def mod_not(self):
|
||||||
|
print("[!] NOT CALLED ON PRIMITIVE MODULE")
|
||||||
|
|
||||||
|
def mod_update(self):
|
||||||
|
pass
|
51
satsim/modules/memory.py
Normal file
51
satsim/modules/memory.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
from .module import module
|
||||||
|
|
||||||
|
class memory_module(module):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__("memoryBank")
|
||||||
|
self.fields["files"] = []
|
||||||
|
self.fields["freeSpace"] = 4000
|
||||||
|
self.fields["mode"] = "upload"
|
||||||
|
self.fields["buffer"] = 0
|
||||||
|
self.fields["filename"] = ""
|
||||||
|
self.writable = ["buffer","filename", "mode"]
|
||||||
|
|
||||||
|
|
||||||
|
def mod_get(self, field="none"):
|
||||||
|
if field not in self.fields:
|
||||||
|
return (-1, "GET FATAL: field '" + field + "'' does not exist in module: " + self.fields["name"])
|
||||||
|
return (self.fields[field], "GET OK")
|
||||||
|
|
||||||
|
def mod_set(self, field="none", value="none"):
|
||||||
|
if field not in self.fields:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "'' does not exist in module: " + self.fields["name"])
|
||||||
|
if field not in self.writable:
|
||||||
|
return (-1, "SET FATAL: field '" + field + "' is not writable in module: " + self.fields["name"])
|
||||||
|
if field == "mode" and (value == "upload" or value == "download"):
|
||||||
|
self.fields[field] = value
|
||||||
|
return (0, "SET OK")
|
||||||
|
self.fields[field] = value
|
||||||
|
return (0, "SET OK")
|
||||||
|
|
||||||
|
def mod_exe(self):
|
||||||
|
if self.fields["mode"] == "upload":
|
||||||
|
if self.fields["freeSpace"] - len(self.fields["buffer"]) >= 0:
|
||||||
|
self.fields["freeSpace"] -= len(self.fields["buffer"])
|
||||||
|
with open("./datastore/"+self.fields["filename"],"wb+") as f:
|
||||||
|
f.write(bytes(self.fields["buffer"],encoding="UTF-8"))
|
||||||
|
return (0, "WRITE OK")
|
||||||
|
else:
|
||||||
|
return (-1, "WRITE FATAL: OUT OF MEMORY")
|
||||||
|
if self.fields["mode"] == "download":
|
||||||
|
try:
|
||||||
|
with open("./datastore/"+self.fields["filename"],"rb") as f:
|
||||||
|
return (f.read(), "READ OK")
|
||||||
|
except:
|
||||||
|
return (-1, "READ FATAL: FILE NOT FOUND")
|
||||||
|
|
||||||
|
|
||||||
|
def mod_not(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def mod_update(self):
|
||||||
|
pass
|
22
satsim/modules/module.py
Normal file
22
satsim/modules/module.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
class module:
|
||||||
|
id_c = 0
|
||||||
|
def __init__(self, name):
|
||||||
|
self.fields = {}
|
||||||
|
self.fields["name"] = name
|
||||||
|
self.id = module.id_c
|
||||||
|
module.id_c += 1
|
||||||
|
|
||||||
|
def mod_get(self):
|
||||||
|
print("[!] GET CALLED ON PRIMITIVE MODULE")
|
||||||
|
|
||||||
|
def mod_set(self):
|
||||||
|
print("[!] SET CALLED ON PRIMITIVE MODULE")
|
||||||
|
|
||||||
|
def mod_exe(self):
|
||||||
|
print("[!] EXE CALLED ON PRIMITIVE MODULE")
|
||||||
|
|
||||||
|
def mod_not(self):
|
||||||
|
print("[!] NOT CALLED ON PRIMITIVE MODULE")
|
||||||
|
|
||||||
|
def mod_update(self):
|
||||||
|
pass
|
77
satsim/satsim.py
Normal file
77
satsim/satsim.py
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
import numpy as np
|
||||||
|
from modules.gamma import gamma_sensor
|
||||||
|
from modules.heartbeat import heartbeat_module
|
||||||
|
from modules.location import location_module
|
||||||
|
from modules.memory import memory_module
|
||||||
|
from time import sleep
|
||||||
|
from os import system
|
||||||
|
|
||||||
|
#debugg to rebuild the file every test
|
||||||
|
system('cp command_q test_q')
|
||||||
|
|
||||||
|
ONSAT_FILESTORE = "DATA"
|
||||||
|
DOWNLINK_FILESTORE = "../store/data"
|
||||||
|
|
||||||
|
class sat:
|
||||||
|
def __init__(self):
|
||||||
|
self.attitude = "Fellin pretty good" #astropy is broke rn
|
||||||
|
self.battery = 100.00
|
||||||
|
self.maneuver_TTC = 0 #time to completion
|
||||||
|
self.gyro_saturation = 0
|
||||||
|
self.modules = {
|
||||||
|
"heartbeat" : heartbeat_module(),
|
||||||
|
"location" : location_module(),
|
||||||
|
#"power" : power_manager(),
|
||||||
|
#"attitude" : attitude_module(),
|
||||||
|
"memory" : memory_module(),
|
||||||
|
"gamma_sensor" : gamma_sensor()
|
||||||
|
}
|
||||||
|
|
||||||
|
def check_command_q(self):
|
||||||
|
cur_batch = []
|
||||||
|
with open("command_q","r") as q:
|
||||||
|
com_q = q.read().splitlines()
|
||||||
|
for com in com_q:
|
||||||
|
if int(com.split(":")[0]) == self.modules["heartbeat"].mod_get("MTE")[0]:
|
||||||
|
cur_batch.append(com)
|
||||||
|
return cur_batch
|
||||||
|
|
||||||
|
|
||||||
|
def spin(self):
|
||||||
|
while True:
|
||||||
|
MTE = self.modules["heartbeat"].mod_get("MTE")[0]
|
||||||
|
print(MTE)
|
||||||
|
batch = self.check_command_q()
|
||||||
|
|
||||||
|
for c in batch:
|
||||||
|
print(c)
|
||||||
|
com = c.split(":")
|
||||||
|
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) == 3:
|
||||||
|
res = self.modules[com[2]].mod_exe()
|
||||||
|
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")
|
||||||
|
return
|
||||||
|
|
||||||
|
with open("MTE", "r+") as statfile:
|
||||||
|
statfile.seek(0)
|
||||||
|
statfile.truncate()
|
||||||
|
statfile.write(str(MTE))
|
||||||
|
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
BoSLOO = sat()
|
||||||
|
BoSLOO.spin()
|
||||||
|
|
1
satsim/status
Normal file
1
satsim/status
Normal file
|
@ -0,0 +1 @@
|
||||||
|
43
|
Loading…
Reference in a new issue