-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addressed errors Michael pointed out
- Loading branch information
1 parent
921b1ad
commit 4e12180
Showing
2 changed files
with
110 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,63 @@ | ||
import pickle | ||
|
||
from ait.core.server.handler import Handler | ||
from ait.core import tlm | ||
from ait.core import tlm, log | ||
|
||
|
||
class PacketHandler(Handler): | ||
def __init__(self, input_type=None, output_type=None, **kwargs): | ||
""" | ||
This handler provides a way to accept multiple packet types | ||
(e.g. '1553_HS_Packet' and 'Ethernet_HS_Packet') single stream | ||
and have them be processed. This handler takes a string of | ||
raw binary data containing the packet data. It gets the UID from | ||
the telemetry dictionary. A tuple of the UID and user data | ||
field is returned. | ||
Params: | ||
input_type: (optional) Specifies expected input type, used to | ||
validate handler workflow. Defaults to None. | ||
output_type: (optional) Specifies expected output type, used to | ||
validate handler workflow. Defaults to None | ||
**kwargs: | ||
packet: (required) Name of packet, present in default tlm dict. | ||
packet_type: (required) Type of packet (e.g. '1553_HS_Packet', 'Ethernet_HS_Packet') | ||
Present in default tlm dict. | ||
Raises: | ||
ValueError: If packet is not present in kwargs. | ||
ValueError: If packet type is not present in kwargs. | ||
If packet is specified but not present in default tlm dict. | ||
""" | ||
""" | ||
super(PacketHandler, self).__init__(input_type, output_type) | ||
self.packet_name = kwargs.get("packet", None) | ||
self.packet_type = kwargs.get("packet_type", None) | ||
self.tlm_dict = tlm.getDefaultDict() | ||
|
||
if not self.packet_name: | ||
msg = f'PacketHandler: No packet type provided in handler config as key "packet"' | ||
if not self.packet_type: | ||
msg = f'PacketHandler: No packet type provided in handler config as key "packet_type"' | ||
raise ValueError(msg) | ||
|
||
if self.packet_name not in self.tlm_dict: | ||
msg = f"PacketHandler: Packet name '{self.packet_name}' not present in telemetry dictionary." | ||
if self.packet_type not in self.tlm_dict: | ||
msg = f"PacketHandler: Packet name '{self.packet_type}' not present in telemetry dictionary." | ||
msg += f" Available packet types are {self.tlm_dict.keys()}" | ||
raise ValueError(msg) | ||
|
||
self._pkt_defn = self.tlm_dict[self.packet_name] | ||
self._pkt_defn = self.tlm_dict[self.packet_type] | ||
|
||
def handle(self, packet): | ||
def handle(self, input_data): | ||
""" | ||
Test the input_data length against the length in the telemetry | ||
Params: | ||
packet: message received by stream (packet) | ||
input_data : byteArray | ||
message received by stream (raw data) | ||
Returns: | ||
tuple of packet UID and message received by stream | ||
""" | ||
|
||
if self._pkt_defn.nbytes != packet.nbytes: | ||
msg = f"PacketHandler: Packet data length does not match packet definition." | ||
raise ValueError(msg) | ||
if self._pkt_defn.nbytes != len(input_data): | ||
log.error( | ||
f"PacketHandler: Packet data length does not match packet definition." | ||
) | ||
return 0 | ||
else: | ||
return pickle.dumps((self._pkt_defn.uid, input_data), 2) | ||
|
||
return pickle.dumps((self._pkt_defn.uid, packet), 2) | ||
return pickle.dumps((self._pkt_defn.uid, input_data), 2) |
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