Skip to content

Commit

Permalink
Updated CCSDSHandler class
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlu99 authored and MJJoyce committed Sep 4, 2019
1 parent 68d4568 commit bb4856c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 376 deletions.
217 changes: 0 additions & 217 deletions .idea/workspace.xml

This file was deleted.

36 changes: 22 additions & 14 deletions ait/core/server/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,44 +88,52 @@ def handle(self, input_data):


class CCSDSPacketHandler(Handler):

"""
This CCSDS handler provides a way to accept multiple packet types on a
single stream and have them be processed. This handler takes a string of
packed binary data (packed by struct) containing CCSDS packet data. It then
maps the APID of the packet to a packet name from the config. Using this
packet name, it returns the UID and user data field.
"""
def __init__(self, input_type=None, output_type=None, **kwargs):
"""
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: (required) APID values: packet name pairs
(optional) Secondary header length
packet_types: (required) APID value : packet name pairs
packet_secondary_header_length: (optional) Length of secondary header in octets.
Defaults to 0.
Raises:
ValueError: If packet in config is not present in default tlm dict.
"""
super(CCSDSPacketHandler, self).__init__(input_type, output_type)
self.packet_types = kwargs['packet_types']
ait.core.log.info(self.packet_types)
self.packet_secondary_header_length = kwargs.get('packet_secondary_header_length', 0)
ait.core.log.info(self.packet_secondary_header_length)
tlm_dict = tlm.getDefaultDict()
for packet_name in self.packet_types.values():
if packet_name not in tlm_dict.keys():
msg = 'CCSDSPacketHandler: Packet name {} not present in telemetry dictionary.'.format(packet_name)
msg += ' Available packet types are {}'.format(tlm_dict.keys())
raise ValueError(msg)

def handle(self, input_data):
"""
Params:
packet: CCSDS packet
Returns:
tuple of packet UID and packet data field
Raises:
ValueError: If packet is specified but not present in default tlm dict.
"""
packet = bytearray(input_data)
packet_apid = int(binascii.hexlify(packet[6:8]), 16) & 0x7FF
packet_apid = int(binascii.hexlify(packet[6:8]), 16) & 0x07FF
if packet_apid not in self.packet_types:
msg = 'CCSDSPacketHandler: Packet APID {} not present in config'.format(packet_apid)
msg = 'CCSDSPacketHandler: Packet APID {} not present in config.'.format(packet_apid)
msg += ' Available packet APIDs are {}'.format(self.packet_types.keys())
raise ValueError(msg)
ait.core.log.info(msg)
return
packet_name = self.packet_types[packet_apid]
tlm_dict = tlm.getDefaultDict()
if packet_name not in tlm_dict:
msg = 'CCSDSPacketHandler: Packet name {} not present in telemetry dictionary'.format(packet_name)
msg += ' Available packet types are {}'.format(tlm_dict.keys())
raise ValueError(msg)
packet_uid = tlm_dict[packet_name].uid

packet_data_length = int(binascii.hexlify(packet[10:12]), 16) + 1
Expand Down
Loading

0 comments on commit bb4856c

Please sign in to comment.