Skip to content

Commit

Permalink
Include Update_Parameter_Table in COSMOS parameter system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbsco committed Aug 22, 2024
1 parent b8a826b commit 1425128
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions test/scripts/update-param-sys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
########################################################################
# This script is designed to function with OpenC3 COSMOS's Script Runner
########################################################################
from openc3.script import *
import struct

# Clear counts and data products from prior tests:
cmd("Linux_Example Ccsds_Command_Depacketizer_Instance-Reset_Counts")
cmd("Linux_Example Command_Router_Instance-Reset_Data_Products")
wait(1.0)

# Send Noop_Arg command expecting success:
cmd("Linux_Example Command_Router_Instance-Noop_Arg with Value 1")
wait(1.0)
# Check succesful command count is 2 and that the last success was Noop_Arg with last Value 1:
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Command_Success_Count.Value == '2'")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Last_Successful_Command.Id == '3'")
print("Noop_Arg success OK")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Noop_Arg_Last_Value.Value == '1'")
print("Noop_Arg last Value OK")

# Send Noop command expecting failure:
cmd("Linux_Example Command_Router_Instance-Noop_Arg with Value 868")
wait(1.0)
# Check last failed command count was 1 and that it was Noop_Arg with last Value 1:
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Command_Failure_Count.Value == '1'")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Last_Failed_Command.ID == '3'")
print("Noop_Arg failure OK")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Noop_Arg_Last_Value.Value == '868'")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Last_Failed_Command.Status == 'FAILURE'")
print("Noop_Arg last Value failure OK")

#########################################################################
# If this point was reached then begin testing parameter update functions
#########################################################################

# Build a parameter table using bytearrays:
#Osc_A_Freq
Test_Packed_Table = bytearray(struct.pack(">f", 0.30))
#Osc_A_Amp
Test_Packed_Table += bytearray(struct.pack(">f", 5.00))
#Osc_A_Off
Test_Packed_Table += bytearray(struct.pack(">f", 2.50))
#Osc_B_Freq
Test_Packed_Table += bytearray(struct.pack(">f", 0.30))
#Osc_B_Amp
Test_Packed_Table += bytearray(struct.pack(">f", -5.00))
#Osc_B_Off
Test_Packed_Table += bytearray(struct.pack(">f", -2.50))
#Version
Test_Packed_Table += bytearray(struct.pack(">f", 0.0))
#Crc_Table
Test_Packed_Table += bytearray(struct.pack(">h", 0))
#Buffer_Length
Test_Packed_Table += bytearray(struct.pack(">h", 55))

# Send nominal Update_Parameter_Table command expecting success:
cmd("Linux_Example", "Parameter_Manager_Instance-Update_Parameter_Table", { "Header.Table_Buffer_Length": 24, "Header.Crc_Table": 19692, "Table_Buffer": list(Test_Packed_Table) })
wait(1.0)
# Check succesful command count is 3 and that it was Update_Parameter_Table:
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Command_Success_Count.Value == '3'")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Last_Successful_Command.Id == '5200'")
print("Update_Parameter_Table success OK")

# Send test Update_Parameter_Table command with bad CRC expecting Memory_Region_Crc_Invalid, Parameter_Table_Copy_Failure, Working_Table_Update_Failure, and Command_Execution_Failure:
cmd("Linux_Example", "Parameter_Manager_Instance-Update_Parameter_Table", { "Header.Table_Buffer_Length": 24, "Header.Crc_Table": 0, "Table_Buffer": list(Test_Packed_Table) })
wait(1.0)
# Check last failed command count was 2 and that it was Update_Parameter_Table with Status FAILURE:
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Command_Failure_Count.Value == '2'")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Last_Failed_Command.ID == '5200'")
print("Update_Parameter_Table failure OK")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Last_Failed_Command.Status == 'FAILURE'")
print("Update_Parameter_Table last Status FAILURE OK")

# Send test Update_Parameter_Table command with bad length expecting Memory_Region_Length_Mismatch, Parameter_Table_Copy_Failure, Working_Table_Update_Failure, and Command_Execution_Failure:
cmd("Linux_Example", "Parameter_Manager_Instance-Update_Parameter_Table", { "Header.Table_Buffer_Length": 26, "Header.Crc_Table": 19692, "Table_Buffer": list(Test_Packed_Table) })
wait(1.0)
# Check last failed command count was 3 and that it was Update_Parameter_Table with Status FAILURE:
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Command_Failure_Count.Value == '3'")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Last_Failed_Command.ID == '5200'")
print("Update_Parameter_Table failure OK")
check_formatted("Linux_Example Software_Status_Packet Command_Router_Instance.Last_Failed_Command.Status == 'FAILURE'")
print("Update_Parameter_Table last Status FAILURE OK")

0 comments on commit 1425128

Please sign in to comment.