From f9b464ee16960308acda85b2832301bb538614a1 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Sat, 30 Mar 2024 14:54:39 -0600 Subject: [PATCH 1/2] Add python code --- plugin.txt | 2 +- targets/FAKESAT/lib/fake_sat.py | 5 ++ targets/FAKESAT/procedures/mem_load.py | 10 ++++ targets/FAKESAT/procedures/ops_suite.rb | 9 ++-- .../procedures/set_override_inject_tlm.py | 51 +++++++++++++++++++ 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 targets/FAKESAT/lib/fake_sat.py create mode 100644 targets/FAKESAT/procedures/mem_load.py create mode 100644 targets/FAKESAT/procedures/set_override_inject_tlm.py diff --git a/plugin.txt b/plugin.txt index 0a07c50..7dfb165 100644 --- a/plugin.txt +++ b/plugin.txt @@ -1,5 +1,5 @@ # Set VARIABLEs here to allow variation in your plugin -# See https://openc3.com/docs/v5/plugins for more information +# See https://docs.openc3.com/docs/configuration/plugins for more information VARIABLE fakesat_target_name FAKESAT VARIABLE fakesat_int_name FAKESAT_INT diff --git a/targets/FAKESAT/lib/fake_sat.py b/targets/FAKESAT/lib/fake_sat.py new file mode 100644 index 0000000..0826e48 --- /dev/null +++ b/targets/FAKESAT/lib/fake_sat.py @@ -0,0 +1,5 @@ +from openc3.script import * + + +class FakeSat: + pass diff --git a/targets/FAKESAT/procedures/mem_load.py b/targets/FAKESAT/procedures/mem_load.py new file mode 100644 index 0000000..3529aec --- /dev/null +++ b/targets/FAKESAT/procedures/mem_load.py @@ -0,0 +1,10 @@ +# Note hex 0x20 is ASCII space ' ' character +data = "\x20" * 10 +cmd(f"FAKESAT TABLE_LOAD with DATA {data}") +cmd("FAKESAT", "TABLE_LOAD", {"DATA": data}) +wait(2) # Allow telemetry to change +# Can't use check for binary data so we grab the data +# and check simply using Ruby comparison +block = tlm("FAKESAT HEALTH_STATUS TABLE_DATA") +if data != block: + raise RuntimeError("TABLE_DATA not updated correctly!") diff --git a/targets/FAKESAT/procedures/ops_suite.rb b/targets/FAKESAT/procedures/ops_suite.rb index 9815541..eda3eb0 100644 --- a/targets/FAKESAT/procedures/ops_suite.rb +++ b/targets/FAKESAT/procedures/ops_suite.rb @@ -29,13 +29,16 @@ def script_special_collect class ModeGroup < OpenC3::Group def script_safe - FakeSat.new.safe + fakesat = FakeSat.new + fakesat.safe end def script_checkout - FakeSat.new.checkout + fakesat = FakeSat.new + fakesat.checkout end def script_operate - FakeSat.new.operate + fakesat = FakeSat.new + fakesat.operate end end diff --git a/targets/FAKESAT/procedures/set_override_inject_tlm.py b/targets/FAKESAT/procedures/set_override_inject_tlm.py new file mode 100644 index 0000000..2746853 --- /dev/null +++ b/targets/FAKESAT/procedures/set_override_inject_tlm.py @@ -0,0 +1,51 @@ +set_line_delay(1) +screen_def = """ + SCREEN AUTO AUTO 0.1 FIXED + VERTICAL + VERTICALBOX + LABELVALUE FAKESAT HEALTH_STATUS MODE + END + END +""" +# Here we pass in the screen definition as a string +local_screen("TESTING", screen_def) +prompt("Watch the screen for mode changes ...") + +cmd("FAKESAT SET_MODE with MODE SAFE") +wait_check("FAKESAT HEALTH_STATUS MODE == 'SAFE'", 5) + +# Call set_tlm twice to ensure it gets processed as real tlm flows +set_tlm("FAKESAT HEALTH_STATUS MODE = 'OPERATE'") +wait(0.2) +set_tlm("FAKESAT HEALTH_STATUS MODE = 'OPERATE'") +wait(5) # Should see value briefly +# This check fails as we receive data and revert back to 'SAFE' +check("FAKESAT HEALTH_STATUS MODE == 'OPERATE'") +# set_tlm back to SAFE to restore in the disconnected version +set_tlm("FAKESAT HEALTH_STATUS MODE = 'SAFE'") +set_tlm("FAKESAT HEALTH_STATUS MODE = 0", type="RAW") + +override_tlm("FAKESAT HEALTH_STATUS MODE = 'OPERATE'") +wait(2) +# By default it overrides all the value types with the value +# This includes types that might not make sense like :RAW +check("FAKESAT HEALTH_STATUS MODE == 'OPERATE'", type="RAW") +check("FAKESAT HEALTH_STATUS MODE == 'OPERATE'", type="CONVERTED") +check("FAKESAT HEALTH_STATUS MODE == 'OPERATE'", type="FORMATTED") +check("FAKESAT HEALTH_STATUS MODE == 'OPERATE'", type="WITH_UNITS") +wait() +# Clear the overrides +normalize_tlm("FAKESAT HEALTH_STATUS MODE") +wait_check("FAKESAT HEALTH_STATUS MODE == 0", 5, type="RAW") +wait_check("FAKESAT HEALTH_STATUS MODE == 'SAFE'", 5) # default CONVERTED +wait_check("FAKESAT HEALTH_STATUS MODE == 'SAFE'", 5, type="FORMATTED") +wait_check("FAKESAT HEALTH_STATUS MODE == 'SAFE'", 5, type="WITH_UNITS") +wait() + +# Call inject_tlm twice to ensure it gets processed as real tlm flows +inject_tlm("FAKESAT", "HEALTH_STATUS", {"MODE": "OPERATE"}) +wait(0.2) +inject_tlm("FAKESAT", "HEALTH_STATUS", {"MODE": "OPERATE"}) +wait(2) +# With flowing tlm, the next received packet overwrites so we're back +wait_check("FAKESAT HEALTH_STATUS MODE == 'SAFE'", 2) From 4ea6f7558167c4e973f85f3fedee77fe13b096eb Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Sun, 31 Mar 2024 08:58:21 -0600 Subject: [PATCH 2/2] Add ops_suite.py --- targets/FAKESAT/procedures/mem_load.py | 2 +- targets/FAKESAT/procedures/ops_suite.py | 51 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 targets/FAKESAT/procedures/ops_suite.py diff --git a/targets/FAKESAT/procedures/mem_load.py b/targets/FAKESAT/procedures/mem_load.py index 3529aec..0912c07 100644 --- a/targets/FAKESAT/procedures/mem_load.py +++ b/targets/FAKESAT/procedures/mem_load.py @@ -4,7 +4,7 @@ cmd("FAKESAT", "TABLE_LOAD", {"DATA": data}) wait(2) # Allow telemetry to change # Can't use check for binary data so we grab the data -# and check simply using Ruby comparison +# and check simply using comparison block = tlm("FAKESAT HEALTH_STATUS TABLE_DATA") if data != block: raise RuntimeError("TABLE_DATA not updated correctly!") diff --git a/targets/FAKESAT/procedures/ops_suite.py b/targets/FAKESAT/procedures/ops_suite.py new file mode 100644 index 0000000..c3dc216 --- /dev/null +++ b/targets/FAKESAT/procedures/ops_suite.py @@ -0,0 +1,51 @@ +from openc3.script.suite import Suite, Group + +load_utility("FAKESAT/lib/fake_sat.py") + + +class CollectGroup(Group): + def script_normal_collect(self): + print( + f"Running {Group.current_suite()}:{Group.current_group()}:{Group.current_script()}" + ) + Group.print("Perform Normal Collect") + + cmd_cnt = tlm("FAKESAT HEALTH_STATUS CMD_ACPT_CNT") + collect_cnt = tlm("FAKESAT IMAGER COLLECTS") + cmd("FAKESAT COLLECT with TYPE NORMAL, DURATION 5") + wait_check(f"FAKESAT HEALTH_STATUS CMD_ACPT_CNT == {cmd_cnt + 1}", 5) + wait_check(f"FAKESAT IMAGER COLLECTS == {collect_cnt + 1}", 5) + wait_check("FAKESAT IMAGER COLLECT_TYPE == 'NORMAL'", 5) + + def script_special_collect(self): + print( + f"Running {Group.current_suite()}:{Group.current_group()}:{Group.current_script()}" + ) + Group.print("Perform Special Collect") + + cmd_cnt = tlm("FAKESAT HEALTH_STATUS CMD_ACPT_CNT") + collect_cnt = tlm("FAKESAT IMAGER COLLECTS") + cmd("FAKESAT COLLECT with TYPE SPECIAL, DURATION 5") + wait_check(f"FAKESAT HEALTH_STATUS CMD_ACPT_CNT == {cmd_cnt + 1}", 5) + wait_check(f"FAKESAT IMAGER COLLECTS == {collect_cnt + 1}", 5) + wait_check("FAKESAT IMAGER COLLECT_TYPE == 'SPECIAL'", 5) + + +class ModeGroup(Group): + def script_safe(self): + fakesat = FakeSat() + fakesat.safe() + + def script_checkout(self): + fakesat = FakeSat() + fakesat.checkout() + + def script_operate(self): + fakesat = FakeSat() + fakesat.operate() + + +class OpsSuite(Suite): + def __init__(self): + self.add_group(CollectGroup) + self.add_group(ModeGroup)