Skip to content

Commit eebbd39

Browse files
authored
Merge pull request #2540 from OpenC3/restricted
2 parents ccc3d63 + 5ff6917 commit eebbd39

File tree

4 files changed

+79
-26
lines changed

4 files changed

+79
-26
lines changed

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST/cmd_tlm/inst_cmds.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ COMMAND <%= target_name %> ARYCMD BIG_ENDIAN "Command with array parameter"
6363
PARAMETER CRC -8 8 UINT MIN MAX 0 "CRC"
6464

6565
COMMAND <%= target_name %> SLRPNLDEPLOY BIG_ENDIAN "Deploy solar array panels"
66+
RESTRICTED
6667
VALIDATOR inst_cmd_validator.rb
6768
<%= render "_ccsds_cmd.txt", locals: {id: 8} %>
6869
RELATED_ITEM <%= target_name %> MECH SLRPNL1
@@ -72,6 +73,7 @@ COMMAND <%= target_name %> SLRPNLDEPLOY BIG_ENDIAN "Deploy solar array panels"
7273
RELATED_ITEM <%= target_name %> MECH SLRPNL5
7374

7475
COMMAND <%= target_name %> SLRPNLRESET BIG_ENDIAN "Reset solar array panels"
76+
RESTRICTED
7577
VALIDATOR inst_cmd_validator.rb
7678
<%= render "_ccsds_cmd.txt", locals: {id: 9} %>
7779
RELATED_ITEM <%= target_name %> MECH SLRPNL1

openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/cmd_tlm/inst_cmds.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ COMMAND <%= target_name %> ARYCMD BIG_ENDIAN "Command with array parameter"
6363
PARAMETER CRC -8 8 UINT MIN MAX 0 "CRC"
6464

6565
COMMAND <%= target_name %> SLRPNLDEPLOY BIG_ENDIAN "Deploy solar array panels"
66+
RESTRICTED
6667
VALIDATOR inst2_cmd_validator.py
6768
<%= render "_ccsds_cmd.txt", locals: {id: 8} %>
6869
RELATED_ITEM <%= target_name %> MECH SLRPNL1
@@ -72,6 +73,7 @@ COMMAND <%= target_name %> SLRPNLDEPLOY BIG_ENDIAN "Deploy solar array panels"
7273
RELATED_ITEM <%= target_name %> MECH SLRPNL5
7374

7475
COMMAND <%= target_name %> SLRPNLRESET BIG_ENDIAN "Reset solar array panels"
76+
RESTRICTED
7577
VALIDATOR inst2_cmd_validator.py
7678
<%= render "_ccsds_cmd.txt", locals: {id: 9} %>
7779
RELATED_ITEM <%= target_name %> MECH SLRPNL1

openc3/python/openc3/packets/packet_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def process_file(self, filename, process_target_name):
206206
| "APPEND_ARRAY_PARAMETER"
207207
| "ALLOW_SHORT"
208208
| "HAZARDOUS"
209+
| "RESTRICTED"
209210
| "PROCESSOR"
210211
| "META"
211212
| "DISABLE_MESSAGES"
@@ -456,6 +457,8 @@ def process_current_packet(self, parser, keyword, params):
456457
# Allow this packet to be received with less data than the defined length
457458
# without generating a warning.
458459
case "ALLOW_SHORT":
460+
usage = keyword
461+
parser.verify_num_parameters(0, 0, usage)
459462
self.current_packet.short_buffer_allowed = True
460463

461464
# Mark the current command as hazardous
@@ -725,15 +728,14 @@ def process_current_item(self, parser, keyword, params):
725728
parser.verify_num_parameters(2, 2, usage)
726729
self.current_item.units_full = params[0]
727730
self.current_item.units = params[1]
728-
731+
729732
# Obfuscate the parameter in logs
730733
case "OBFUSCATE":
731734
usage = "OBFUSCATE"
732735
parser.verify_num_parameters(0, 0, usage)
733736
self.current_item.obfuscate = True
734737
self.current_packet.update_obfuscated_items_cache(self.current_item)
735738

736-
737739
# Update the description for the current telemetry item
738740
case "DESCRIPTION":
739741
usage = "DESCRIPTION <DESCRIPTION>"

openc3/python/test/packets/test_packet_config.py

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,56 @@ def test_creates_unknown_cmd_tlm_packets(self):
8484

8585
# context "with all telemetry keywords" do
8686
# before(:all) do
87-
# top level keywords
87+
# Top level keywords (don't require current packet or item)
8888
top_keywords = [
8989
"SELECT_COMMAND",
9090
"SELECT_TELEMETRY",
9191
"LIMITS_GROUP",
9292
"LIMITS_GROUP_ITEM",
9393
]
94-
# Keywords that require a current packet from TELEMETRY keyword
94+
# Keywords that require a current TELEMETRY packet (telemetry-specific ITEM keywords)
9595
tlm_keywords = [
9696
"SELECT_ITEM",
97+
"DELETE_ITEM",
9798
"ITEM",
9899
"ID_ITEM",
99100
"ARRAY_ITEM",
100101
"APPEND_ITEM",
101102
"APPEND_ID_ITEM",
102103
"APPEND_ARRAY_ITEM",
104+
"ALLOW_SHORT",
103105
"PROCESSOR",
104106
"META",
105107
]
108+
# Keywords that require a current COMMAND packet (command-specific PARAMETER keywords)
109+
cmd_keywords = [
110+
"SELECT_PARAMETER",
111+
"DELETE_PARAMETER",
112+
"PARAMETER",
113+
"ID_PARAMETER",
114+
"ARRAY_PARAMETER",
115+
"APPEND_PARAMETER",
116+
"APPEND_ID_PARAMETER",
117+
"APPEND_ARRAY_PARAMETER",
118+
]
119+
# Keywords that apply to both COMMAND and TELEMETRY packets
120+
packet_keywords = [
121+
"HAZARDOUS",
122+
"RESTRICTED",
123+
"DISABLE_MESSAGES",
124+
"HIDDEN",
125+
"DISABLED",
126+
"VIRTUAL",
127+
"ACCESSOR",
128+
"VALIDATOR",
129+
"TEMPLATE",
130+
"TEMPLATE_FILE",
131+
"RESPONSE",
132+
"ERROR_RESPONSE",
133+
"SCREEN",
134+
"RELATED_ITEM",
135+
"IGNORE_OVERLAP",
136+
]
106137
# Keywords that require both a current packet and current item
107138
item_keywords = [
108139
"STATE",
@@ -161,6 +192,11 @@ def test_complains_if_there_are_not_enough_parameters(self):
161192
tf.close()
162193

163194
for keyword in TestPacketConfig.tlm_keywords:
195+
# Skip keywords that don't require parameters or are tested elsewhere
196+
ignore_tlm = ["PROCESSOR", "META", "ALLOW_SHORT"]
197+
if keyword in ignore_tlm:
198+
continue
199+
164200
tf = tempfile.NamedTemporaryFile(mode="w")
165201
tf.write('TELEMETRY tgt1 pkt1 LITTLE_ENDIAN "Packet"\n')
166202
tf.write(keyword)
@@ -188,28 +224,24 @@ def test_complains_if_there_are_not_enough_parameters(self):
188224
tf.close()
189225

190226
def test_builds_the_id_value_hash(self):
191-
for keyword in TestPacketConfig.tlm_keywords:
192-
if keyword == "PROCESSOR" or keyword == "META":
193-
continue
194-
195-
tf = tempfile.NamedTemporaryFile(mode="w")
196-
tf.write('TELEMETRY tgt1 pkt1 BIG_ENDIAN "Packet"\n')
197-
tf.write('ID_ITEM myitem 0 8 UINT 13 "Test Item id=1"\n')
198-
tf.write('APPEND_ID_ITEM myitem 8 UINT 114 "Test Item id=1"\n')
199-
tf.write('COMMAND tgt1 pkt1 BIG_ENDIAN "Packet"\n')
200-
tf.write('ID_PARAMETER myitem 0 8 UINT 12 12 12 "Test Item id=1"\n')
201-
tf.write('APPEND_ID_PARAMETER myitem 8 UINT 115 115 115 "Test Item id=1"\n')
202-
tf.seek(0)
203-
self.pc.process_file(tf.name, "TGT1")
204-
expected_tlm_hash = {}
205-
expected_tlm_hash["TGT1"] = {}
206-
expected_tlm_hash["TGT1"]["[13, 114]"] = self.pc.telemetry["TGT1"]["PKT1"]
207-
expected_cmd_hash = {}
208-
expected_cmd_hash["TGT1"] = {}
209-
expected_cmd_hash["TGT1"]["[12, 115]"] = self.pc.commands["TGT1"]["PKT1"]
210-
self.assertEqual(self.pc.tlm_id_value_hash, expected_tlm_hash)
211-
self.assertEqual(self.pc.cmd_id_value_hash, expected_cmd_hash)
212-
tf.close()
227+
tf = tempfile.NamedTemporaryFile(mode="w")
228+
tf.write('TELEMETRY tgt1 pkt1 BIG_ENDIAN "Packet"\n')
229+
tf.write('ID_ITEM myitem 0 8 UINT 13 "Test Item id=1"\n')
230+
tf.write('APPEND_ID_ITEM myitem 8 UINT 114 "Test Item id=1"\n')
231+
tf.write('COMMAND tgt1 pkt1 BIG_ENDIAN "Packet"\n')
232+
tf.write('ID_PARAMETER myitem 0 8 UINT 12 12 12 "Test Item id=1"\n')
233+
tf.write('APPEND_ID_PARAMETER myitem 8 UINT 115 115 115 "Test Item id=1"\n')
234+
tf.seek(0)
235+
self.pc.process_file(tf.name, "TGT1")
236+
expected_tlm_hash = {}
237+
expected_tlm_hash["TGT1"] = {}
238+
expected_tlm_hash["TGT1"]["[13, 114]"] = self.pc.telemetry["TGT1"]["PKT1"]
239+
expected_cmd_hash = {}
240+
expected_cmd_hash["TGT1"] = {}
241+
expected_cmd_hash["TGT1"]["[12, 115]"] = self.pc.commands["TGT1"]["PKT1"]
242+
self.assertEqual(self.pc.tlm_id_value_hash, expected_tlm_hash)
243+
self.assertEqual(self.pc.cmd_id_value_hash, expected_cmd_hash)
244+
tf.close()
213245

214246
def test_complains_if_there_are_too_many_parameters(self):
215247
for keyword in TestPacketConfig.top_keywords:
@@ -250,6 +282,10 @@ def test_complains_if_there_are_too_many_parameters(self):
250282
case "SELECT_ITEM":
251283
tf.write("ITEM myitem 0 8 UINT\n")
252284
tf.write("SELECT_ITEM myitem extra\n")
285+
case "DELETE_ITEM":
286+
tf.write("DELETE_ITEM myitem extra\n")
287+
case "ALLOW_SHORT":
288+
tf.write("ALLOW_SHORT extra\n")
253289
tf.seek(0)
254290
with self.assertRaisesRegex(ConfigParser.Error, f"Too many parameters for {keyword}"):
255291
self.pc.process_file(tf.name, "TGT1")
@@ -863,6 +899,17 @@ def test_hazardous_takes_a_description(self):
863899
)
864900
tf.close()
865901

902+
def test_marks_the_packet_as_restricted(self):
903+
tf = tempfile.NamedTemporaryFile(mode="w")
904+
tf.write('COMMAND tgt2 pkt1 LITTLE_ENDIAN "Description"\n')
905+
tf.write("RESTRICTED\n")
906+
tf.write('COMMAND tgt2 pkt2 LITTLE_ENDIAN "Description"\n')
907+
tf.seek(0)
908+
self.pc.process_file(tf.name, "SYSTEM")
909+
self.assertTrue(self.pc.commands["TGT2"]["PKT1"].restricted)
910+
self.assertFalse(self.pc.commands["TGT2"]["PKT2"].restricted)
911+
tf.close()
912+
866913
def test_complains_about_missing_conversion_file(self):
867914
self.pc = PacketConfig()
868915

0 commit comments

Comments
 (0)