From 44ce4b07d30cbbabab89e253adb0c20985f450dc Mon Sep 17 00:00:00 2001 From: Laika Date: Thu, 8 Jul 2021 21:37:03 -0400 Subject: [PATCH] Added basic file read/write module --- satsim/command_q | 9 ++++- satsim/datastore/shark_decoded.bmp | Bin 0 -> 1662 bytes satsim/modules/memory.py | 51 +++++++++++++++++++++++++++++ satsim/satsim.py | 10 +++--- 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 satsim/datastore/shark_decoded.bmp create mode 100644 satsim/modules/memory.py diff --git a/satsim/command_q b/satsim/command_q index cf78fc3..d06f0aa 100644 --- a/satsim/command_q +++ b/satsim/command_q @@ -1,3 +1,10 @@ 2:GET:heartbeat:MTE 4:GET:location:coords -70:SET:heartbeat:kill:1 +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 diff --git a/satsim/datastore/shark_decoded.bmp b/satsim/datastore/shark_decoded.bmp new file mode 100644 index 0000000000000000000000000000000000000000..8fb2676f473cd53a6809930a4764413da4eb0385 GIT binary patch literal 1662 zcmd7Sy^ho{5CC8Yq+1H4v{&Jlp7yjx^t=TRaRoYOwMEK(gnJD-vPzNi9^rgSL5Wjg zq>+aiC;nMW3oVwC-OuAVH4x=jc7vs$1NUE+z?UFm5QZU0{!`$ zpQ`xjAMUI8bj@B<1g8{-;C`gakPj$)?DRB8dxcWy@uhU9$E7sr*(OVDK^q?EIzEXf zw!W~raDYJVf!*dN?cHgcEjG@?<*Z0-)vGPZYK z(R`b1P&62uY(Y^Fk{7QBjXoR0@+DieZ*?(07Kd9hm34k-I$U7(eQBD$+tM_eHT8#`W72^G*D3;|Kf^lH~c| z9r9@t<1;$s(= 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 \ No newline at end of file diff --git a/satsim/satsim.py b/satsim/satsim.py index 73367b5..e3925e3 100644 --- a/satsim/satsim.py +++ b/satsim/satsim.py @@ -2,6 +2,7 @@ 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 astropy.coordinates import SkyCoord as sc from os import system @@ -22,7 +23,8 @@ class sat: "heartbeat" : heartbeat_module(), "location" : location_module(), #"power" : power_manager(), - #"attitude" : attitude_module(), + #"attitude" : attitude_module(), + "memory" : memory_module(), "gamma_sensor" : gamma_sensor() } @@ -49,8 +51,8 @@ class sat: 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[3]) + elif com[1] == "EXE" and len(com) == 3: + res = self.modules[com[2]].mod_exe() else: res = (-1, "BAD COMMAND: " + c) print(res) @@ -62,7 +64,7 @@ class sat: print("heading to bed") return - with open("status", "r+") as statfile: + with open("MTE", "r+") as statfile: statfile.seek(0) statfile.truncate() statfile.write(str(MTE))