Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test CCSDS header across all instrument packet definitions #184

Merged
merged 11 commits into from
Oct 11, 2023
Merged
27 changes: 6 additions & 21 deletions imap_processing/swe/packet_definitions/swe_packet_definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<xtce:IntegerDataEncoding sizeInBits="32" encoding="unsigned" />
</xtce:IntegerParameterType>
<xtce:BinaryParameterType name="BYTE10080">
<xtce:UnitSet />
<xtce:BinaryDataEncoding bitOrder="mostSignificantBitFirst">
<xtce:SizeInBits>
<xtce:FixedValue>10080</xtce:FixedValue>
Expand All @@ -61,47 +60,41 @@
</xtce:BinaryParameterType>
<!-- ENUM Parameter Types -->
<xtce:EnumeratedParameterType name="NOMINAL_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="NOT_NOMINAL" value="0"/>
<xtce:Enumeration label="NOMINAL" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="VALID_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="INVALID" value="0"/>
<xtce:Enumeration label="VALID" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="SPIN_PERIOD_SOURCE_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="STAR_TRACKER" value="0"/>
<xtce:Enumeration label="SUN_SENSOR" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="ACTIVE_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="INACTIVE" value="0"/>
<xtce:Enumeration label="ACTIVE" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="SAFED_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="NOT_SAFED" value="0"/>
<xtce:Enumeration label="SAFED" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="APP_MODE_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="4" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="OFF" value="0"/>
Expand All @@ -114,7 +107,6 @@
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="LAST_ACC_OPCODE_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="16" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="NONE" value="0"/>
Expand Down Expand Up @@ -169,47 +161,41 @@
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="PLUG_INSERTED_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="NOT_INSERTED" value="0"/>
<xtce:Enumeration label="INSERTED" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="ENABLE_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="NOT_ENABLED" value="0"/>
<xtce:Enumeration label="ENABLED" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="DISABLE_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="DISABLED" value="0"/>
<xtce:Enumeration label="ENABLED" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="ESA_RANGE_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="HIGH_RANGE" value="0"/>
<xtce:Enumeration label="LOW_RANGE" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="MIN_MAX_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="MIN" value="0"/>
<xtce:Enumeration label="MAX" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="FDC_LAST_TRIGGER_ACTION_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="8" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="REPORT_ONLY" value="0"/>
Expand All @@ -235,7 +221,6 @@
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="ACTIVE_MACRO_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="5" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="NONE" value="0"/>
Expand All @@ -258,7 +243,6 @@
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="ACTIVE_MACRO_TRIGGER_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="3" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="NONE" value="0"/>
Expand All @@ -268,15 +252,13 @@
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="YES_NO_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="1" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="NO" value="0"/>
<xtce:Enumeration label="YES" value="1"/>
</xtce:EnumerationList>
</xtce:EnumeratedParameterType>
<xtce:EnumeratedParameterType name="QUARTER_CYCLE_ENUM" signed="false">
<xtce:UnitSet/>
<xtce:IntegerDataEncoding sizeInBits="5" encoding="unsigned"/>
<xtce:EnumerationList>
<xtce:Enumeration label="FIRST" value="0"/>
Expand All @@ -300,7 +282,7 @@
<xtce:Parameter name="PKT_APID" parameterTypeRef="UINT11">
<xtce:LongDescription>CCSDS Packet Application Process ID</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SEG_FLGS" parameterTypeRef="UINT2">
<xtce:Parameter name="SEQ_FLGS" parameterTypeRef="UINT2">
<xtce:LongDescription>CCSDS Packet Grouping Flags (3=not part of group)</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SRC_SEQ_CTR" parameterTypeRef="UINT14">
Expand Down Expand Up @@ -731,10 +713,9 @@
<xtce:ParameterRefEntry parameterRef="TYPE"/>
<xtce:ParameterRefEntry parameterRef="SEC_HDR_FLG"/>
<xtce:ParameterRefEntry parameterRef="PKT_APID"/>
<xtce:ParameterRefEntry parameterRef="SEG_FLGS"/>
<xtce:ParameterRefEntry parameterRef="SEQ_FLGS"/>
<xtce:ParameterRefEntry parameterRef="SRC_SEQ_CTR"/>
<xtce:ParameterRefEntry parameterRef="PKT_LEN"/>
<xtce:ParameterRefEntry parameterRef="SHCOARSE" />
</xtce:EntryList>
</xtce:SequenceContainer>

Expand All @@ -746,6 +727,7 @@
</xtce:RestrictionCriteria>
</xtce:BaseContainer>
<xtce:EntryList>
<xtce:ParameterRefEntry parameterRef="SHCOARSE" />
<xtce:ParameterRefEntry parameterRef="ACQ_START_COARSE" />
<xtce:ParameterRefEntry parameterRef="ACQ_START_FINE" />
<xtce:ParameterRefEntry parameterRef="CEM_NOMINAL_ONLY" />
Expand Down Expand Up @@ -776,6 +758,7 @@
</xtce:RestrictionCriteria>
</xtce:BaseContainer>
<xtce:EntryList>
<xtce:ParameterRefEntry parameterRef="SHCOARSE" />
<xtce:ParameterRefEntry parameterRef="APP_MODE" />
<xtce:ParameterRefEntry parameterRef="SAFED" />
<xtce:ParameterRefEntry parameterRef="ITF_ERR_CNT" />
Expand Down Expand Up @@ -855,6 +838,7 @@
</xtce:RestrictionCriteria>
</xtce:BaseContainer>
<xtce:EntryList>
<xtce:ParameterRefEntry parameterRef="SHCOARSE" />
<xtce:ParameterRefEntry parameterRef="THRESHOLD_DAC" />
<xtce:ParameterRefEntry parameterRef="STIM_CFG_REG" />
<xtce:ParameterRefEntry parameterRef="CEM1_COUNTS" />
Expand All @@ -875,6 +859,7 @@
</xtce:RestrictionCriteria>
</xtce:BaseContainer>
<xtce:EntryList>
<xtce:ParameterRefEntry parameterRef="SHCOARSE" />
<xtce:ParameterRefEntry parameterRef="QMSG_CNT" />
<xtce:ParameterRefEntry parameterRef="EVENT_TIME_COARSE_LO8" />
<xtce:ParameterRefEntry parameterRef="EVENT_TIME_FINE_HI8" />
Expand Down
Empty file.
64 changes: 64 additions & 0 deletions imap_processing/tests/test_decom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Tests aspects of the decommutation process that is generic to all instruments"""

import pytest

from imap_processing import imap_module_directory

# Scrape the repo for all packet definition XML files
xtce_document_list = imap_module_directory.glob("*/packet_definitions/*.xml")


@pytest.fixture(params=xtce_document_list, scope="session")
def xtce_document(request):
if "idex" in str(request.param):
pytest.xfail(
"Packet Definition does not include properly formatted CCSDS Header"
)
else:
return request.param


def test_ccsds_header(xtce_document):
"""Test if the XTCE document contains the proper CCSDS header information"""

# Define what is expected in the XTCE document
header_keys = [
("VERSION", "UINT3"),
("TYPE", "UINT1"),
("SEC_HDR_FLG", "UINT1"),
("PKT_APID", "UINT11"),
("SEQ_FLGS", "UINT2"),
("SRC_SEQ_CTR", "UINT14"),
("PKT_LEN", "UINT16"),
]
header_entry_list = (
"<xtce:EntryList>"
' <xtce:ParameterRefEntry parameterRef="VERSION" />'
' <xtce:ParameterRefEntry parameterRef="TYPE" />'
' <xtce:ParameterRefEntry parameterRef="SEC_HDR_FLG" />'
' <xtce:ParameterRefEntry parameterRef="PKT_APID" />'
' <xtce:ParameterRefEntry parameterRef="SEQ_FLGS" />'
' <xtce:ParameterRefEntry parameterRef="SRC_SEQ_CTR" />'
' <xtce:ParameterRefEntry parameterRef="PKT_LEN" />'
"</xtce:EntryList>"
)

# Read in the XTCE document
with open(xtce_document) as f:
document = f.read()

# Check that each header key is defined as a Parameter
for key in header_keys:
assert (
f'<xtce:Parameter name="{key[0]}" parameterTypeRef="{key[1]}"' in document
or f'<xtce:Parameter name="{key[0]}" parameterTypeRef="{key[1].lower()}"'
in document
)

# Check that the header is defined as a SequenceContainer in the XTCE file
# First remove discrepancies in whitespace, tabs, and newlines
header_entry_list = (
header_entry_list.replace(" ", "").replace("\t", "").replace("\n", "")
)
document = document.replace(" ", "").replace("\t", "").replace("\n", "")
assert header_entry_list in document
6 changes: 3 additions & 3 deletions imap_processing/ultra/packet_definitions/P_U45_AUXILIARY.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
<xtce:Parameter name="PKT_APID" parameterTypeRef="uint11">
<xtce:LongDescription>CCSDS Packet Application Process ID</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SEG_FLGS" parameterTypeRef="uint2">
<xtce:Parameter name="SEQ_FLGS" parameterTypeRef="uint2">
<xtce:LongDescription>CCSDS Packet Grouping Flags (3=not part of group)</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SRC_SEQ_CTR" parameterTypeRef="uint14">
Expand Down Expand Up @@ -358,14 +358,14 @@
</xtce:ParameterSet>
<!-- End metadata -->
<xtce:ContainerSet>
<!--CCSDS Header Elements-->
<xtce:SequenceContainer name="CCSDSPacket" abstract="true">
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laspsandoval Do you know what abstract="true" does here? I had to remove it in order to get these tests to pass, and the other instrument's packet definitions don't have it. I am thinking that it is not important?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now see that removing this caused test_decom_apid_88*.py to fail, so I guess it is important afterall!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up just making my header tests a bit more generalized to allow for this abstract parameter.

<xtce:EntryList>
<!--CCSDS Header Elements-->
<xtce:ParameterRefEntry parameterRef="VERSION" />
<xtce:ParameterRefEntry parameterRef="TYPE" />
<xtce:ParameterRefEntry parameterRef="SEC_HDR_FLG" />
<xtce:ParameterRefEntry parameterRef="PKT_APID" />
<xtce:ParameterRefEntry parameterRef="SEG_FLGS" />
<xtce:ParameterRefEntry parameterRef="SEQ_FLGS" />
<xtce:ParameterRefEntry parameterRef="SRC_SEQ_CTR" />
<xtce:ParameterRefEntry parameterRef="PKT_LEN" />
</xtce:EntryList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<xtce:Parameter name="PKT_APID" parameterTypeRef="uint11">
<xtce:LongDescription>CCSDS Packet Application Process ID</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SEG_FLGS" parameterTypeRef="uint2">
<xtce:Parameter name="SEQ_FLGS" parameterTypeRef="uint2">
<xtce:LongDescription>CCSDS Packet Grouping Flags (3=not part of group)</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SRC_SEQ_CTR" parameterTypeRef="uint14">
Expand Down Expand Up @@ -199,7 +199,7 @@
<xtce:ParameterRefEntry parameterRef="TYPE" />
<xtce:ParameterRefEntry parameterRef="SEC_HDR_FLG" />
<xtce:ParameterRefEntry parameterRef="PKT_APID" />
<xtce:ParameterRefEntry parameterRef="SEG_FLGS" />
<xtce:ParameterRefEntry parameterRef="SEQ_FLGS" />
<xtce:ParameterRefEntry parameterRef="SRC_SEQ_CTR" />
<xtce:ParameterRefEntry parameterRef="PKT_LEN" />
</xtce:EntryList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<xtce:Parameter name="PKT_APID" parameterTypeRef="uint11">
<xtce:LongDescription>CCSDS Packet Application Process ID</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SEG_FLGS" parameterTypeRef="uint2">
<xtce:Parameter name="SEQ_FLGS" parameterTypeRef="uint2">
<xtce:LongDescription>CCSDS Packet Grouping Flags (3=not part of group)</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SRC_SEQ_CTR" parameterTypeRef="uint14">
Expand All @@ -183,7 +183,7 @@
<xtce:ParameterRefEntry parameterRef="TYPE" />
<xtce:ParameterRefEntry parameterRef="SEC_HDR_FLG" />
<xtce:ParameterRefEntry parameterRef="PKT_APID" />
<xtce:ParameterRefEntry parameterRef="SEG_FLGS" />
<xtce:ParameterRefEntry parameterRef="SEQ_FLGS" />
<xtce:ParameterRefEntry parameterRef="SRC_SEQ_CTR" />
<xtce:ParameterRefEntry parameterRef="PKT_LEN" />
</xtce:EntryList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<xtce:Parameter name="PKT_APID" parameterTypeRef="uint11">
<xtce:LongDescription>CCSDS Packet Application Process ID</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SEG_FLGS" parameterTypeRef="uint2">
<xtce:Parameter name="SEQ_FLGS" parameterTypeRef="uint2">
<xtce:LongDescription>CCSDS Packet Grouping Flags (3=not part of group)</xtce:LongDescription>
</xtce:Parameter>
<xtce:Parameter name="SRC_SEQ_CTR" parameterTypeRef="uint14">
Expand Down Expand Up @@ -198,7 +198,7 @@
<xtce:ParameterRefEntry parameterRef="TYPE" />
<xtce:ParameterRefEntry parameterRef="SEC_HDR_FLG" />
<xtce:ParameterRefEntry parameterRef="PKT_APID" />
<xtce:ParameterRefEntry parameterRef="SEG_FLGS" />
<xtce:ParameterRefEntry parameterRef="SEQ_FLGS" />
<xtce:ParameterRefEntry parameterRef="SRC_SEQ_CTR" />
<xtce:ParameterRefEntry parameterRef="PKT_LEN" />
</xtce:EntryList>
Expand Down