-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from robamu-org/eive
PDU Updates
- Loading branch information
Showing
13 changed files
with
372 additions
and
172 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,35 +1,39 @@ | ||
from __future__ import annotations | ||
from tmtccmd.ccsds.log import LOGGER | ||
|
||
|
||
class CfdpLv: | ||
def __init__(self,serialize: bool, value: bytearray = None): | ||
def __init__(self, value: bytearray): | ||
"""This class encapsulates CFDP LV fields | ||
:raise ValueError: If value is invalid and serilization is enabled or if length of bytearray | ||
is too large | ||
:param serialize: | ||
:param value: | ||
""" | ||
if serialize and value is None: | ||
LOGGER.warning('All parameter have to be valid for serialization') | ||
raise ValueError | ||
if len > 255: | ||
if len(value) > 255: | ||
LOGGER.warning('Length too large for LV field') | ||
raise ValueError | ||
self.len = len(value) | ||
self.value = value | ||
|
||
def get_len(self): | ||
"""Returns length of full LV packet""" | ||
return self.len + 1 | ||
|
||
def pack(self): | ||
packet = bytearray() | ||
packet.append(self.len) | ||
packet.extend(self.value) | ||
|
||
def unpack(self, raw_bytes: bytearray): | ||
@classmethod | ||
def unpack(cls, raw_bytes: bytearray) -> CfdpLv: | ||
"""Parses LV field at the start of the given bytearray | ||
:raise ValueError: Invalid lenght found | ||
:raise ValueError: Invalid length found | ||
""" | ||
self.len = raw_bytes[0] | ||
if self.len > 255: | ||
detected_len = raw_bytes[0] | ||
if detected_len > 255: | ||
LOGGER.warning('Length too large for LV field') | ||
raise ValueError | ||
elif self.len > 0: | ||
self.value = raw_bytes[1: 1 + self.len] | ||
return cls( | ||
value=raw_bytes[1:] | ||
) |
This file contains 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 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 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 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
Oops, something went wrong.