Skip to content

Commit

Permalink
Merge pull request #2 from OpenC3/python
Browse files Browse the repository at this point in the history
Add python code
  • Loading branch information
jmthomas authored Mar 31, 2024
2 parents d111d66 + 4ea6f75 commit 28a60b5
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugin.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 5 additions & 0 deletions targets/FAKESAT/lib/fake_sat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from openc3.script import *


class FakeSat:
pass
10 changes: 10 additions & 0 deletions targets/FAKESAT/procedures/mem_load.py
Original file line number Diff line number Diff line change
@@ -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 comparison
block = tlm("FAKESAT HEALTH_STATUS TABLE_DATA")
if data != block:
raise RuntimeError("TABLE_DATA not updated correctly!")
51 changes: 51 additions & 0 deletions targets/FAKESAT/procedures/ops_suite.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 6 additions & 3 deletions targets/FAKESAT/procedures/ops_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 51 additions & 0 deletions targets/FAKESAT/procedures/set_override_inject_tlm.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 28a60b5

Please sign in to comment.