Skip to content

Commit

Permalink
Merge pull request #193 from kmarwah/Issue-191
Browse files Browse the repository at this point in the history
Issue #191 – Add SLE plugins
  • Loading branch information
nttoole committed Aug 4, 2022
2 parents 2d287b7 + 721447b commit 777b2e8
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ait/dsn/plugins/create_cltu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
A plugin which adds CLTU start and tail bytes to incoming data
"""
from ait.core.server.plugins import Plugin

class CreateCLTU(Plugin):
"""
Adds CLTU start and tail bytes to incoming data (frames)
The input will normally be TC frames (either with or without BCH).
The output is CLTUs with the CCSDS standard start and tail byte sequences.
"""

def __init__(self, inputs=None, outputs=None, zmq_args=None):
super().__init__(inputs, outputs, zmq_args)
self.cltu_start = bytearray(b"\xEB\x90")
self.cltu_tail = bytearray(b"\xC5\xC5\xC5\xC5\xC5\xC5\xC5\x79")

def process(self, input_data, topic=None):
cltu_bytearray = self.cltu_start + input_data + self.cltu_tail
self.publish(cltu_bytearray)
55 changes: 55 additions & 0 deletions ait/dsn/plugins/raf_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
A plugin which creates an RAF connection with the DSN.
Frames received via the RAF connection are sent to the output stream
"""
import time
import ait
from ait.dsn.sle import RAF
from ait.core.server.plugins import Plugin

class RAFModified(RAF):
"""
A modified version of the RAF class which publishes received frames to a plugin"s output topic
(instead of sending them to a UDP socket)
"""
def __init__(self, publish_function, *args, **kwargs):
super().__init__(self, *args, **kwargs)
self.publish = publish_function

def _transfer_data_invoc_handler(self, pdu):
""""""
frame = pdu.getComponent()
if "data" in frame and frame["data"].isValue:
tm_data = frame["data"].asOctets()
else:
err = (
"RafTransferBuffer received but data cannot be located. "
"Skipping further processing of this PDU ..."
)
ait.core.log.info(err)
return

self.publish(tm_data)

class RAFPlugin(Plugin):
"""
A plugin which creates a RAF instance using the SLE parameters specified in config.yaml.
All received frames are published to the output topic.
"""
def __init__(self, inputs=None, outputs=None, zmq_args=None):
super().__init__(inputs, outputs, zmq_args)
self.raf_object = RAFModified(publish_function= self.publish)
self.raf_object.connect()
time.sleep(2)
self.raf_object.bind()
time.sleep(2)
self.raf_object.start(None, None)
time.sleep(2)

def process(self, input_data, topic = None):
pass

def __del__(self):
self.raf_object.stop()
self.raf_object.unbind()
self.raf_object.disconnect()
39 changes: 39 additions & 0 deletions ait/dsn/plugins/send_cltu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Creates a FCLTU instance and uploads any incoming CLTUs to the DSN via SLE
"""

import time
from ait.core.server.plugins import Plugin
import ait.core
from ait.dsn.sle import CLTU

class SendCLTU(Plugin):
"""
Creates a FCLTU instance and uploads any incoming CLTUs to the DSN via SLE
The input stream should consist of CLTUs (with appropriate start and tail sequences).
"""

def __init__(self, inputs=None, outputs=None, zmq_args=None):
super().__init__(inputs, outputs, zmq_args)
self.cltu_manager = CLTU()
self.cltu_manager.connect()
time.sleep(2)
self.cltu_manager.bind()
time.sleep(2)
self.cltu_manager.start()
time.sleep(2)

def process(self, input_data, topic=None):
if self.cltu_manager._state == "ready":
self.cltu_manager.upload_cltu(input_data)
self.publish(input_data)
ait.core.log.debug("uploaded CLTU")
else:
ait.core.log.error("CLTU Manager is not in ready state– check DSN connection")
return input_data

def __del__(self):
self.cltu_manager.stop()
self.cltu_manager.unbind()
self.cltu_manager.disconnect()
7 changes: 7 additions & 0 deletions doc/source/ait.dsn.plugins.create_cltu.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ait.dsn.plugins.create_cltu module
======================================

.. automodule:: ait.dsn.plugins.create_cltu
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions doc/source/ait.dsn.plugins.raf_plugin.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ait.dsn.plugins.raf_plugin module
======================================

.. automodule:: ait.dsn.plugins.raf_plugin
:members:
:undoc-members:
:show-inheritance:
3 changes: 3 additions & 0 deletions doc/source/ait.dsn.plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Submodules
ait.dsn.plugins.TCP
ait.dsn.plugins.TCTF_Manager
ait.dsn.plugins.vcid_routing
ait.dsn.plugins.create_cltu
ait.dsn.plugins.send_cltu
ait.dsn.plugins.raf_plugin

Module contents
---------------
Expand Down
7 changes: 7 additions & 0 deletions doc/source/ait.dsn.plugins.send_cltu.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ait.dsn.plugins.send_cltu module
======================================

.. automodule:: ait.dsn.plugins.send_cltu
:members:
:undoc-members:
:show-inheritance:

0 comments on commit 777b2e8

Please sign in to comment.