Skip to content

Commit

Permalink
Rework entry positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
fqqb committed Apr 15, 2024
1 parent 424fbc1 commit 3f42aec
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 44 deletions.
48 changes: 40 additions & 8 deletions src/yamcs/pymdb/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,18 +395,34 @@ def __init__(
argument: Argument,
*,
short_description: str | None = None,
absolute: bool = False,
location_in_bits: int = 0,
bitpos: int | None = None,
offset: int = 0,
condition: Expression | None = None,
) -> None:
self.argument: Argument = argument

self.short_description: str | None = short_description
"""Oneline description"""

self.absolute: bool = absolute
self.location_in_bits: int = location_in_bits
self.bitpos: int | None = bitpos
"""
Absolute position within the container, in bits.
If unspecified, this entry is positioned relative to the preceding
entry.
"""

self.offset: int = offset
"""
Distance in bits to the preceding entry.
While not expected, if both :attr:`bitpos` and :attr:`offset` are
specified, the two are added together for establishing the real
absolute bit position.
"""

self.condition: Expression | None = condition
"""If set, this entry is only present when the condition is met"""


class FixedValueEntry:
Expand All @@ -416,8 +432,8 @@ def __init__(
name: str | None = None,
*,
short_description: str | None = None,
absolute: bool = False,
location_in_bits: int = 0,
bitpos: int | None = None,
offset: int = 0,
condition: Expression | None = None,
bits: int | None = None,
) -> None:
Expand All @@ -442,9 +458,25 @@ def __init__(
self.short_description: str | None = short_description
"""Oneline description"""

self.absolute: bool = absolute
self.location_in_bits: int = location_in_bits
self.bitpos: int | None = bitpos
"""
Absolute position within the container, in bits.
If unspecified, this entry is positioned relative to the preceding
entry.
"""

self.offset: int = offset
"""
Distance in bits to the preceding entry.
While not expected, if both :attr:`bitpos` and :attr:`offset` are
specified, the two are added together for establishing the real
absolute bit position.
"""

self.condition: Expression | None = condition
"""If set, encode this entry only when the condition is met"""

self.bits: int | None = bits
"""
Expand Down
55 changes: 44 additions & 11 deletions src/yamcs/pymdb/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class ParameterEntry:
def __init__(
self,
parameter: Parameter,
location_in_bits: int = 0,
bitpos: int | None = None,
*,
absolute: bool = False,
offset: int = 0,
short_description: str | None = None,
condition: Expression | None = None,
) -> None:
Expand All @@ -26,9 +26,25 @@ def __init__(
self.short_description: str | None = short_description
"""Oneline description"""

self.absolute: bool = absolute
self.location_in_bits: int = location_in_bits
self.bitpos: int | None = bitpos
"""
Absolute position within the container, in bits.
If unspecified, this entry is positioned relative to the preceding
entry.
"""

self.offset: int = offset
"""
Distance in bits to the preceding entry.
While not expected, if both :attr:`bitpos` and :attr:`offset` are
specified, the two are added together for establishing the real
absolute bit position.
"""

self.condition: Expression | None = condition
"""If set, this entry is only present when the condition is met"""

def __str__(self) -> str:
return self.parameter.__str__()
Expand All @@ -39,18 +55,34 @@ def __init__(
self,
container: Container,
short_description: str | None = None,
absolute: bool = False,
location_in_bits: int = 0,
bitpos: int | None = None,
offset: int = 0,
condition: Expression | None = None,
) -> None:
self.container: Container = container

self.short_description: str | None = short_description
"""Oneline description"""

self.absolute: bool = absolute
self.location_in_bits: int = location_in_bits
self.bitpos: int | None = bitpos
"""
Absolute position within the container, in bits.
If unspecified, this entry is positioned relative to the preceding
entry.
"""

self.offset: int = offset
"""
Distance in bits to the preceding entry.
While not expected, if both :attr:`bitpos` and :attr:`offset` are
specified, the two are added together for establishing the real
absolute bit position.
"""

self.condition: Expression | None = condition
"""If set, this entry is only present when the condition is met"""

def __str__(self) -> str:
return self.container.__str__()
Expand Down Expand Up @@ -187,10 +219,11 @@ def fit_entries(self):
if not bits:
raise Exception(f"Cannot determine size of {entry.parameter}")

pos = entry.location_in_bits
if not entry.absolute:
pos += prev_pos
pos = entry.bitpos
if pos is None:
pos = prev_pos

pos += entry.offset
pos += bits

prev_pos = pos
Expand Down
2 changes: 1 addition & 1 deletion src/yamcs/pymdb/csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def add_csp_header(
ParameterEntry(tm_dst),
ParameterEntry(tm_dport),
ParameterEntry(tm_sport),
ParameterEntry(tm_hmac, location_in_bits=4),
ParameterEntry(tm_hmac, offset=4),
ParameterEntry(tm_xtea),
ParameterEntry(tm_rdp),
ParameterEntry(tm_crc),
Expand Down
52 changes: 28 additions & 24 deletions src/yamcs/pymdb/xtce.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,14 @@ def add_fixed_value_entry(

loc_el = ET.SubElement(el, "LocationInContainerInBits")

if entry.absolute:
loc_el.attrib["referenceLocation"] = "containerStart"
else:
if entry.bitpos is None:
loc_el.attrib["referenceLocation"] = "previousEntry"

fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.location_in_bits)
fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.offset)
else:
loc_el.attrib["referenceLocation"] = "containerStart"
fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.bitpos + entry.offset)

if entry.condition:
cond_el = ET.SubElement(el, "IncludeCondition")
Expand All @@ -495,13 +496,14 @@ def add_argument_ref_entry(

loc_el = ET.SubElement(el, "LocationInContainerInBits")

if entry.absolute:
loc_el.attrib["referenceLocation"] = "containerStart"
else:
if entry.bitpos is None:
loc_el.attrib["referenceLocation"] = "previousEntry"

fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.location_in_bits)
fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.offset)
else:
loc_el.attrib["referenceLocation"] = "containerStart"
fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.bitpos + entry.offset)

if entry.condition:
cond_el = ET.SubElement(el, "IncludeCondition")
Expand Down Expand Up @@ -1914,13 +1916,14 @@ def add_parameter_ref_entry(

loc_el = ET.SubElement(el, "LocationInContainerInBits")

if entry.absolute:
loc_el.attrib["referenceLocation"] = "containerStart"
else:
if entry.bitpos is None:
loc_el.attrib["referenceLocation"] = "previousEntry"

fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.location_in_bits)
fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.offset)
else:
loc_el.attrib["referenceLocation"] = "containerStart"
fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.bitpos + entry.offset)

if entry.condition:
cond_el = ET.SubElement(el, "IncludeCondition")
Expand All @@ -1947,13 +1950,14 @@ def add_container_ref_entry(

loc_el = ET.SubElement(el, "LocationInContainerInBits")

if entry.absolute:
loc_el.attrib["referenceLocation"] = "containerStart"
else:
if entry.bitpos is None:
loc_el.attrib["referenceLocation"] = "previousEntry"

fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.location_in_bits)
fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.offset)
else:
loc_el.attrib["referenceLocation"] = "containerStart"
fv_el = ET.SubElement(loc_el, "FixedValue")
fv_el.text = str(entry.bitpos + entry.offset)

if entry.condition:
cond_el = ET.SubElement(el, "IncludeCondition")
Expand Down

0 comments on commit 3f42aec

Please sign in to comment.