-
Notifications
You must be signed in to change notification settings - Fork 16
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
Xtce generator #145
Xtce generator #145
Conversation
Done as part of issue #104 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Thank you for making these changes for more flexible use!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making it more generic!
data_type_data, | ||
data_type_event_data, | ||
sci_byte, | ||
data_types, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the doc string of this function as well?
if size == sci_byte: | ||
parameter_type_ref = ( | ||
"BYTE" # Use BYTE type for both "Data" and "Event_Data" | ||
) | ||
elif size == self.sci_byte: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is difference between this function input parameter sci_byte
and self.sci_byte
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I actually removed the sci_byte
input to this function and moved it entirely to the class variable. In the future, hopefully we can move this variable, since it is codice specific (?). In glows, I override this function and don't use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was built for packets with BYTE as a dataType. So, it is optional I think I put it as.
Parameters | ||
---------- | ||
output_xml_path: the path for the final xml file | ||
mnemonic_names: a list or single name for mnemonics for extracting data types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is where we give in names of science data that are specific to each instrument such as SCIENCE_DATA
or HIST_DATA
field in packet definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly!
parameter_type_ref = data_types[ | ||
"Data" | ||
] # use dataType of "Data" in data_types dict | ||
elif data_types["EventData"] and size == self.sci_byte: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is "EventData" a CoDICE specific thing? I'm getting an error because I don't have "EventData" defined as a key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is codice specific. But you can change the mnemonic. I also think Maxine might have fixed this, so when pushed, it should work..... If this helps, I have packets with "Data" OR "Event_Data" so it was my way of calling the correct one depending on what was in the row.
- data_type_event_data: The data type for the "Event_Data" mnemonic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, it is codice specific. In my GLOWs code, I override it:
def create_parameter_types(
self,
parameter_type_set,
unique_lengths,
data_types,
sci_byte=None,
):
"""
Create parameter types based on 'dataType' for the unique 'lengthInBits' values.
This will loop through the unique lengths and create a ParameterType element
for each length representing a UINT type.
Parameters:
- parameter_type_set: The ParameterTypeSet element where parameter types are.
- unique_lengths: Unique values from the 'lengthInBits' column.
- data_type_data: The data type for the "Data" mnemonic.
- data_type_event_data: The data type for the "Event_Data" mnemonic.
- sci_byte: The BYTE number of lengthInBits in both "Data" and "Event_Data"
Returns:
- parameter_type_set: The updated ParameterTypeSet element.
"""
for size in unique_lengths:
# All bins equal?
# Are bins the only thing that matters? -> check glows code for this
parameter_type_ref = data_types["BIN"] # Use UINT for other sizes
print(parameter_type_ref)
parameter_type = Et.SubElement(parameter_type_set, "xtce:ParameterType")
parameter_type.attrib["name"] = f"uint{size}"
parameter_type.attrib["signed"] = "false"
encoding = Et.SubElement(parameter_type, "xtce:IntegerDataEncoding")
encoding.attrib["sizeInBits"] = str(size)
encoding.attrib["encoding"] = "unsigned"
# Create BinaryParameterType if parameter_type_ref is "BYTE"
if parameter_type_ref == "BYTE":
binary_parameter_type = Et.SubElement(
parameter_type_set, "xtce:BinaryParameterType"
)
binary_parameter_type.attrib["name"] = parameter_type_ref
Et.SubElement(binary_parameter_type, "xtce:UnitSet")
binary_data_encoding = Et.SubElement(
binary_parameter_type, "xtce:BinaryDataEncoding"
)
binary_data_encoding.attrib["bitOrder"] = "mostSignificantBitFirst"
size_in_bits = Et.SubElement(binary_data_encoding, "xtce:SizeInBits")
fixed_value = Et.SubElement(size_in_bits, "xtce:FixedValue")
fixed_value.text = str(sci_byte) # Set the size in bits to sci_byte
return parameter_type_set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, in the future, this will be something that is probably overridden in most instruments, or the more generic code above can be modified so it can be used in all cases where there are very simple parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Updating telemetry generator based on review comments Update tools/xtce_generation/telemetry_generator.py Co-authored-by: Tenzin Choedon <36522642+tech3371@users.noreply.github.com>
34e99b1
to
c444e49
Compare
096e654
into
IMAP-Science-Operations-Center:dev
…/xtce-generator Xtce generator
Change Summary
Updates to the XTCE generator code to make it more generic, including some API changes.
Overview
Codice needs two events for scientific data from telemetry. Rather than hardcoding these two event mnemonics, I changed the code to accept a dictionary. This makes it easier to overwrite methods for instrument specific changes without needing to update the writer/generator parts.
Making this change also required updating all the codice python files to provide the events through a dictionary instead of assuming them.
Long term, codice could benefit from a specific CodiceTelemetryGenerator class which has codice-specific code or helper functions. I have an example of this in my GLOWS code, which is still incomplete.
I also split up some methods which people may want to override in the future.
Please double check my docstrings, I'm not sure if I accurately represented what the mnemonics are used for.
New Files
Updated Files
Testing
I checked, and the output codice file matches the existing one in the repository. So I didn't change any functionality.