Skip to content

Commit

Permalink
Modify update-param-sys.py to use Adamant defs when checking dumped…
Browse files Browse the repository at this point in the history
… parameter table
  • Loading branch information
Jbsco committed Sep 22, 2024
1 parent 84d2ca9 commit b974015
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
27 changes: 15 additions & 12 deletions test/scripts/update-param-sys.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
########################################################################
# This script is designed to function with OpenC3 COSMOS's Script Runner
########################################################################
import struct, sys
import struct, sys, bitstring
sys.path.append('/plugins/DEFAULT/targets_modified')
import crc_16
import test_setup
Expand All @@ -17,21 +17,23 @@
record = Table_Record.Linux_Example_Parameter_Table_Record(
Crc_Calculated=0,
Header=Table_Record.Parameter_Table_Header(),
Oscillator_A_Frequency=Table_Record.Packed_F32(0.30),
Oscillator_A_Frequency=Table_Record.Packed_F32(0.25),
Oscillator_A_Amplitude=Table_Record.Packed_F32(5.00),
Oscillator_A_Offset=Table_Record.Packed_F32(2.50),
Oscillator_B_Frequency=Table_Record.Packed_F32(0.30),
Oscillator_B_Frequency=Table_Record.Packed_F32(0.25),
Oscillator_B_Amplitude=Table_Record.Packed_F32(-5.00),
Oscillator_B_Offset=Table_Record.Packed_F32(-2.50)
)
record_byte_array = record._to_byte_array().tobytes()
record.Crc_Calculated = int.from_bytes(crc_16.crc_16(record_byte_array[4:]))
record.Header.Crc_Table = record.Crc_Calculated
record.Header.Version = 0.0
record_len = len(record_byte_array[8:])
record_crc = int.from_bytes(crc_16.crc_16(record_byte_array[4:]), 'big')

# Send nominal Update_Parameter_Table command expecting success:
cmd("Linux_Example", "Parameter_Manager_Instance-Update_Parameter_Table", {
"Header.Table_Buffer_Length": record_len,
"Header.Crc_Table": record_crc,
"Header.Crc_Table": record.Crc_Calculated,
"Table_Buffer": list(record_byte_array[8:])
})
# Check successful command count is 3 and that it was Update_Parameter_Table:
Expand All @@ -57,7 +59,7 @@
# Working_Table_Update_Failure, and Command_Execution_Failure:
cmd("Linux_Example", "Parameter_Manager_Instance-Update_Parameter_Table", {
"Header.Table_Buffer_Length": record_len + 1,
"Header.Crc_Table": record_crc,
"Header.Crc_Table": record.Crc_Calculated,
"Table_Buffer": list(record_byte_array[8:])
})
# Check last failed command count was 2 and that it was Update_Parameter_Table with Status FAILURE:
Expand All @@ -74,9 +76,10 @@
check("Linux_Example Software_Status_Packet Command_Router_Instance.Last_Successful_Command.Id == 30")
Active_Parameters_Buffer = get_tlm_buffer("Linux_Example Active_Parameters")
Buffer = Active_Parameters_Buffer['buffer']
# Check CRC
if list(Buffer[16:18]) == record_crc:
print("Dump_Parameters CRC OK")
# Check Active_Parameters table buffer:
if Buffer[18:46] == list(record_byte_array[8:]):
print("Dump_Parameters values OK")
# Check dumped record against the original sent record:
dump_record = Table_Record.Linux_Example_Parameter_Table_Record()
dump_record._from_byte_array(bitstring.ConstBitStream(Buffer[14:]))
print(record.to_tuple_string())
print(dump_record.to_tuple_string())
if dump_record == record:
print("Dump_Parameters match OK")
18 changes: 10 additions & 8 deletions test/scripts/validate-param-sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
Oscillator_B_Offset=Table_Record.Packed_F32(-2.50)
)
record_byte_array = record._to_byte_array().tobytes()
record.Crc_Calculated = int.from_bytes(crc_16.crc_16(record_byte_array[4:]))
record.Header.Crc_Table = record.Crc_Calculated
record_len = len(record_byte_array[8:])
record_crc = int.from_bytes(crc_16.crc_16(record_byte_array[4:]), 'big')

# Send nominal Validate_Parameter_Table command expecting success:
cmd("Linux_Example", "Parameter_Manager_Instance-Validate_Parameter_Table", {
"Header.Table_Buffer_Length": record_len,
"Header.Crc_Table": record_crc,
"Header.Crc_Table": record.Crc_Calculated,
"Table_Buffer": list(record_byte_array[8:])
})
# Check successful command count is 3 and that it was Validate_Parameter_Table with Status SUCCESS:
Expand All @@ -40,7 +41,7 @@
# Check Last_Validation_Version, Crc_Table, and Last_Validation_Status:
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Last_Validation_Status == 'SUCCESS'")
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Last_Validation_Version == 0.00")
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Crc_Table == " + str(record_crc))
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Crc_Table == " + str(record.Crc_Calculated))
print("Validate_Parameter_Table SUCCESS OK")

# Send test Validate_Parameter_Table command with bad CRC expecting Memory_Region_Crc_Invalid, Table_Validation_Failure, and
Expand All @@ -65,7 +66,7 @@
# Command_Execution_Failure:
cmd("Linux_Example", "Parameter_Manager_Instance-Validate_Parameter_Table", {
"Header.Table_Buffer_Length": record_len + 1,
"Header.Crc_Table": record_crc,
"Header.Crc_Table": record.Crc_Calculated,
"Table_Buffer": list(record_byte_array[8:])
})
# Check last failed command count was 2 and that it was Validate_Parameter_Table with Status LENGTH_ERROR:
Expand All @@ -76,7 +77,7 @@
# Check Last_Validation_Version, Crc_Table, and Last_Validation_Status:
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Last_Validation_Status == 'LENGTH_ERROR'")
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Last_Validation_Version == 0.00")
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Crc_Table == " + str(record_crc))
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Crc_Table == " + str(record.Crc_Calculated))
print("Validate_Parameter_Table last Status LENGTH_ERROR OK")

# Send test Validate_Parameter_Table command with nominal values, and Osc_A_Freq = 999.0 to trigger the user implemented Validate_Parameters
Expand All @@ -94,12 +95,13 @@
Oscillator_B_Offset=Table_Record.Packed_F32(-2.50)
)
record_byte_array = record._to_byte_array().tobytes()
record.Crc_Calculated = int.from_bytes(crc_16.crc_16(record_byte_array[4:]))
record.Header.Crc_Table = record.Crc_Calculated
record_len = len(record_byte_array[8:])
record_crc = int.from_bytes(crc_16.crc_16(record_byte_array[4:]), 'big')

cmd("Linux_Example", "Parameter_Manager_Instance-Validate_Parameter_Table", {
"Header.Table_Buffer_Length": record_len,
"Header.Crc_Table": record_crc,
"Header.Crc_Table": record.Crc_Calculated,
"Table_Buffer": list(record_byte_array[8:])
})
# Check last failed command count was 3 and that it was Validate_Parameter_Table with Status PARAMETER_ERROR:
Expand All @@ -110,5 +112,5 @@
# Check Last_Validation_Version, Crc_Table, and Last_Validation_Status:
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Last_Validation_Status == 'PARAMETER_ERROR'")
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Last_Validation_Version == 0.00")
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Crc_Table == " + str(record_crc))
check("Linux_Example Software_Status_Packet Parameter_Manager_Instance.Validation_Status.Crc_Table == " + str(record.Crc_Calculated))
print("Validate_Parameter_Table last Status PARAMETER_ERROR OK")

0 comments on commit b974015

Please sign in to comment.