-
Notifications
You must be signed in to change notification settings - Fork 29
IDEX l1a event messages #2870
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
Merged
lacoak21
merged 6 commits into
IMAP-Science-Operations-Center:dev
from
lacoak21:idex_event_message_products
Mar 27, 2026
+1,702
−99
Merged
IDEX l1a event messages #2870
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0cbfae3
write out all event messages
lacoak21 c1bdac6
add validation csv
lacoak21 1f42f05
pr comments
lacoak21 c22a3f2
idex comment out tests
lacoak21 08c01bb
pr comments - varaible name changes
lacoak21 85b12e7
variable name
lacoak21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| """Helper functions for decoding event messages.""" | ||
|
|
||
| import re | ||
|
|
||
| # Regex to match spaces where we need to embed params in the event message templates, | ||
| # e.g. {p0}, {p1+2}, {p3:dict}, {p4+1|dict} | ||
| EMBEDDED_PARAM_RE = re.compile(r"\{p(\d+)(?:\+(\d+))?(?::[\w]+)?(?:\|(\w+))?\}") | ||
|
|
||
|
|
||
| def render_event_template( | ||
| event_description_template: str, params_bytes: list, msg_json_data: dict | ||
| ) -> str: | ||
| """ | ||
| Produce an event message string by replacing placeholders with parameter values. | ||
|
|
||
| Example template: | ||
lacoak21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "Event {p0} occurred with value {p1+2:dictName}" | ||
|
|
||
| This would replace {p0} with the hex value of params[0], and replace {p1+2:dictName} | ||
| with the combined hex value of params[1] and params[2] (treated as big-endian bytes) | ||
| looked up in the dictionary named "dictName" for a human-readable string, or | ||
| rendered as hex if not found in the dictionary. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| event_description_template : str | ||
| The event message template containing placeholders like {p0}, {p1+2}, | ||
| {p3:dict}, {p4+1|dict}. | ||
| params_bytes : list | ||
| The list of parameter values to substitute into the template. | ||
| msg_json_data : dict | ||
| Mapping of parameter values to human-readable strings for decoding event | ||
| messages. | ||
|
|
||
| Returns | ||
| ------- | ||
| str | ||
| The rendered event message with placeholders replaced by parameter values. | ||
| """ | ||
|
|
||
| def replace(m: re.Match[str]) -> str: | ||
| """ | ||
| Replace a single placeholder match with the corresponding parameter value. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| m : re.Match[str] | ||
| A regex match object for a placeholder in the template. | ||
|
|
||
| Returns | ||
| ------- | ||
| str | ||
| The string to replace the placeholder with. | ||
| """ | ||
| # We are parsing the placeholder value here to determine which parameter | ||
| # to substitute and how to format them. | ||
| # group one is the parameter index e.g. p0-3 | ||
lacoak21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| idx = int(m.group(1)) | ||
| # group two is the optional byte length e.g. +2 (so we know how many params | ||
| # to combine) | ||
| n_bytes = int(m.group(2)) if m.group(2) else 1 | ||
lacoak21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # group three is an optional dictionary name to use for decoding this parameter | ||
| dict_name = m.group(3) | ||
| value = 0 | ||
| for i in range(n_bytes): | ||
| # combine the next n_bytes params into a single integer value, treating | ||
| # them as big-endian bytes | ||
| value = (value << 8) | ( | ||
| params_bytes[idx + i] if idx + i < len(params_bytes) else 0 | ||
| ) | ||
| # If a dictionary name is provided use it to decode the value, otherwise just | ||
| # render as hex. | ||
| if dict_name: | ||
| resolved = msg_json_data.get(dict_name, {}).get( | ||
| value, f"0x{value:0{2 * n_bytes}X}" | ||
| ) | ||
| return f"{dict_name}({resolved})" # wrap with dict name | ||
|
|
||
| return f"{value:02x}" | ||
|
|
||
| # Replace all placeholders in the template using the replace function defined above. | ||
| return EMBEDDED_PARAM_RE.sub(replace, event_description_template) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.