-
Notifications
You must be signed in to change notification settings - Fork 3
/
com_interface_base.py
84 lines (73 loc) · 2.5 KB
/
com_interface_base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
"""
:file: tmtcc_com_interface_base.py
:data: 01.11.2019
:details:
Generic Communication Interface. Defines the syntax of the communication functions.
Abstract methods must be implemented by child class (e.g. Ethernet Com IF)
:author: R. Mueller
"""
from abc import abstractmethod
from tmtccmd.ecss.tc import PusTelecommand
from tmtccmd.pus_tm.factory import PusTmListT
from tmtccmd.utility.tmtc_printer import TmTcPrinter
# pylint: disable=useless-return
# pylint: disable=no-self-use
# pylint: disable=unused-argument
class CommunicationInterface:
"""
Generic form of a communication interface to separate communication logic from
the underlying interface.
"""
def __init__(self, tmtc_printer: TmTcPrinter):
self.tmtc_printer = tmtc_printer
self.valid = True
@abstractmethod
def initialize(self, args: any = None) -> any:
"""
Perform initializations step which can not be done in constructor or which require
returnvalues.
"""
@abstractmethod
def open(self, args: any = None) -> None:
"""
Opens the communication interface to allow communication.
@return:
"""
@abstractmethod
def close(self, args: any = None) -> None:
"""
Closes the ComIF and releases any held resources (for example a Communication Port)
:return:
"""
@abstractmethod
def send_data(self, data: bytearray):
"""
Send raw data
"""
@abstractmethod
def send_telecommand(self, tc_packet: bytearray, tc_packet_obj: PusTelecommand) -> None:
"""
Send telecommands.
:param tc_packet: TC wiretapping_packet to send
:param tc_packet_obj: TC packet object representation
:return: None for now
"""
@abstractmethod
def receive_telemetry(self, parameters: any = 0) -> PusTmListT:
"""
Returns a list of packets. The child class can use a separate thread to poll for
the packets or use some other mechanism and container like a deque to store packets
to be returned here.
:param parameters:
:return:
"""
packet_list = []
return packet_list
@abstractmethod
def data_available(self, parameters: any) -> int:
"""
Check whether TM data is available
:param parameters: Can be an arbitrary parameter like a timeout
:return: 0 if no data is available, number of bytes or anything > 0 otherwise.
"""