puslib 0.4.0__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {puslib-0.4.0/src/puslib.egg-info → puslib-0.5.0}/PKG-INFO +2 -1
- {puslib-0.4.0 → puslib-0.5.0}/README.md +1 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/__init__.py +1 -1
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/process.py +31 -1
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/pus_001_request_verification.py +8 -8
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/pus_005_event_reporting.py +2 -2
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/pus_017_test.py +1 -1
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/pus_020_parameter_management.py +1 -1
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/service.py +45 -5
- {puslib-0.4.0 → puslib-0.5.0/src/puslib.egg-info}/PKG-INFO +2 -1
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib.egg-info/SOURCES.txt +1 -0
- puslib-0.5.0/tests/test_process.py +195 -0
- {puslib-0.4.0 → puslib-0.5.0}/LICENSE +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/pyproject.toml +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/setup.cfg +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/setup.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/crc_ccitt.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/exceptions.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/ident.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/packet.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/parameter.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/pus_policy.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/__init__.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/error_codes.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/param_report.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/pus_003_housekeeping.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/services/pus_008_function_management.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/streams/__init__.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/streams/buffer.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/streams/console.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/streams/file.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/streams/stream.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib/time.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib.egg-info/dependency_links.txt +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib.egg-info/requires.txt +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/src/puslib.egg-info/top_level.txt +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/tests/test_crc.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/tests/test_ident.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/tests/test_packet.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/tests/test_parameter.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/tests/test_policy.py +0 -0
- {puslib-0.4.0 → puslib-0.5.0}/tests/test_time.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: puslib
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: An implementation of the telemetry and telecommand packet utilization standard (PUS).
|
|
5
5
|
Home-page: https://github.com/pxntus/puslib
|
|
6
6
|
Author: Pontus Nyman
|
|
@@ -92,6 +92,7 @@ with open('telemetry.dump', 'rb') as f:
|
|
|
92
92
|
* PUS 8: Function Management
|
|
93
93
|
* PUS 17: Test (*partial support*)
|
|
94
94
|
* PUS 20: On-board Parameter Management (*partial support*)
|
|
95
|
+
* Custom (mission-specific) services
|
|
95
96
|
|
|
96
97
|
## Links
|
|
97
98
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sched
|
|
2
2
|
from enum import IntEnum
|
|
3
|
-
from typing import Any, Sequence, Callable
|
|
3
|
+
from typing import Any, Sequence, Callable, TypeVar
|
|
4
4
|
|
|
5
5
|
from puslib import services
|
|
6
6
|
from puslib.services.service import PusService, PusServiceType
|
|
@@ -10,6 +10,8 @@ from puslib.streams.stream import OutputStream
|
|
|
10
10
|
from puslib.parameter import Parameter
|
|
11
11
|
from puslib.packet import PusTcPacket
|
|
12
12
|
|
|
13
|
+
ServiceT = TypeVar("ServiceT", bound=PusService)
|
|
14
|
+
|
|
13
15
|
|
|
14
16
|
def periodic(scheduler: sched.scheduler, interval: int | float, priority: int, action: Callable[..., Any], actionargs: tuple[Any, ...] = (), _next: float | None = None) -> None:
|
|
15
17
|
now = scheduler.timefunc()
|
|
@@ -89,6 +91,32 @@ class Process:
|
|
|
89
91
|
"""
|
|
90
92
|
self._params[param_id] = param
|
|
91
93
|
|
|
94
|
+
def add_service(self, factory: Callable[[PusIdent, services.RequestVerification, OutputStream], ServiceT]) -> ServiceT:
|
|
95
|
+
"""Add a user-implemented PUS service to the application process.
|
|
96
|
+
|
|
97
|
+
The factory is called with the process' PUS identifier, PUS service 1
|
|
98
|
+
instance and TM output stream. A PusService subclass whose constructor
|
|
99
|
+
takes these arguments can be passed directly as factory.
|
|
100
|
+
|
|
101
|
+
This can be used both for mission-specific services and for standard
|
|
102
|
+
services not implemented by puslib. A standard service should pass its
|
|
103
|
+
PusServiceType to the PusService constructor.
|
|
104
|
+
|
|
105
|
+
Arguments:
|
|
106
|
+
factory -- callable creating the service
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
the created service
|
|
110
|
+
|
|
111
|
+
Raises:
|
|
112
|
+
ValueError: if the process already has a service with the same service type
|
|
113
|
+
"""
|
|
114
|
+
service = factory(self._ident, self._pus_service_1, self._tm_output_stream)
|
|
115
|
+
if service.service in self._pus_services:
|
|
116
|
+
raise ValueError(f"PUS service {service.service} already exists in application process (APID {self.apid})")
|
|
117
|
+
self._pus_services[service.service] = service
|
|
118
|
+
return service
|
|
119
|
+
|
|
92
120
|
def forward(self, tc_packet: PusTcPacket):
|
|
93
121
|
"""Forward TC packet to application service.
|
|
94
122
|
|
|
@@ -114,6 +142,7 @@ class Process:
|
|
|
114
142
|
def add_action(func):
|
|
115
143
|
self._actions[func.__name__] = func
|
|
116
144
|
periodic(self._scheduler, interval, priority, func)
|
|
145
|
+
return func
|
|
117
146
|
return add_action
|
|
118
147
|
|
|
119
148
|
def function(self, fid: int, args: Sequence[type[Parameter]]) -> Callable[..., Any]:
|
|
@@ -127,6 +156,7 @@ class Process:
|
|
|
127
156
|
if PusServiceType.FUNCTION_MANAGEMENT.value not in self._pus_services:
|
|
128
157
|
raise RuntimeError("Process has no function management service")
|
|
129
158
|
self._pus_service_8.add(func, fid, args)
|
|
159
|
+
return func
|
|
130
160
|
return add_function
|
|
131
161
|
|
|
132
162
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from enum import IntEnum
|
|
1
|
+
from enum import Enum, IntEnum
|
|
2
2
|
|
|
3
3
|
from puslib import get_policy
|
|
4
4
|
from puslib.packet import AckFlag
|
|
@@ -39,7 +39,7 @@ class RequestVerification(PusService):
|
|
|
39
39
|
def process(self) -> None:
|
|
40
40
|
raise RuntimeError("Request verification service (PUS 1) doesn't have a TC queue")
|
|
41
41
|
|
|
42
|
-
def accept(self, packet: PusTcPacket, success: bool = True, failure_code:
|
|
42
|
+
def accept(self, packet: PusTcPacket, success: bool = True, failure_code: Enum | None = None, failure_data: bytes | bytearray | None = None):
|
|
43
43
|
"""Generate acceptance verification report.
|
|
44
44
|
|
|
45
45
|
Arguments:
|
|
@@ -59,7 +59,7 @@ class RequestVerification(PusService):
|
|
|
59
59
|
failure_code,
|
|
60
60
|
failure_data)
|
|
61
61
|
|
|
62
|
-
def start(self, packet: PusTcPacket, success: bool = True, failure_code:
|
|
62
|
+
def start(self, packet: PusTcPacket, success: bool = True, failure_code: Enum | None = None, failure_data: bytes | bytearray | None = None):
|
|
63
63
|
"""Generate start of execution verification report.
|
|
64
64
|
|
|
65
65
|
Arguments:
|
|
@@ -79,7 +79,7 @@ class RequestVerification(PusService):
|
|
|
79
79
|
failure_code,
|
|
80
80
|
failure_data)
|
|
81
81
|
|
|
82
|
-
def progress(self, packet: PusTcPacket, success: bool = True, failure_code:
|
|
82
|
+
def progress(self, packet: PusTcPacket, success: bool = True, failure_code: Enum | None = None, failure_data: bytes | bytearray | None = None):
|
|
83
83
|
"""Generate progress of execution verification report.
|
|
84
84
|
|
|
85
85
|
Arguments:
|
|
@@ -99,7 +99,7 @@ class RequestVerification(PusService):
|
|
|
99
99
|
failure_code,
|
|
100
100
|
failure_data)
|
|
101
101
|
|
|
102
|
-
def complete(self, packet: PusTcPacket, success: bool = True, failure_code:
|
|
102
|
+
def complete(self, packet: PusTcPacket, success: bool = True, failure_code: Enum | None = None, failure_data: bytes | bytearray | None = None):
|
|
103
103
|
"""Generate completion of execution verification report.
|
|
104
104
|
|
|
105
105
|
Arguments:
|
|
@@ -119,17 +119,17 @@ class RequestVerification(PusService):
|
|
|
119
119
|
failure_code,
|
|
120
120
|
failure_data)
|
|
121
121
|
|
|
122
|
-
def _generate_report(self, packet: PusTcPacket, subservice: _SubService, success: bool, failure_code:
|
|
122
|
+
def _generate_report(self, packet: PusTcPacket, subservice: _SubService, success: bool, failure_code: Enum | None, failure_data: bytes | bytearray | None) -> None:
|
|
123
123
|
payload = packet.request_id()
|
|
124
124
|
if not success:
|
|
125
|
-
if
|
|
125
|
+
if failure_code is None:
|
|
126
126
|
failure_code = CommonErrorCode.ILLEGAL_APP_DATA
|
|
127
127
|
payload += failure_code.value.to_bytes(len(get_policy().request_verification.failure_code_type()), byteorder='big') + (failure_data if failure_data else b'')
|
|
128
128
|
time = get_policy().CucTime()
|
|
129
129
|
report = get_policy().PusTmPacket(
|
|
130
130
|
apid=self._ident.apid,
|
|
131
131
|
seq_count=self._ident.next_seq_count(),
|
|
132
|
-
service_type=self.
|
|
132
|
+
service_type=self.service,
|
|
133
133
|
service_subtype=subservice,
|
|
134
134
|
time=time,
|
|
135
135
|
data=payload
|
|
@@ -122,7 +122,7 @@ class EventReporting(PusService):
|
|
|
122
122
|
packet = get_policy().PusTmPacket(
|
|
123
123
|
apid=self._ident.apid,
|
|
124
124
|
seq_count=self._ident.next_seq_count(),
|
|
125
|
-
service_type=self.
|
|
125
|
+
service_type=self.service,
|
|
126
126
|
service_subtype=report.severity,
|
|
127
127
|
time=time,
|
|
128
128
|
data=payload
|
|
@@ -171,7 +171,7 @@ class EventReporting(PusService):
|
|
|
171
171
|
packet = get_policy().PusTmPacket(
|
|
172
172
|
apid=self._ident.apid,
|
|
173
173
|
seq_count=self._ident.next_seq_count(),
|
|
174
|
-
service_type=self.
|
|
174
|
+
service_type=self.service,
|
|
175
175
|
service_subtype=8,
|
|
176
176
|
time=time,
|
|
177
177
|
data=payload
|
|
@@ -56,7 +56,7 @@ class ParameterManagement(PusService):
|
|
|
56
56
|
packet = get_policy().PusTmPacket(
|
|
57
57
|
apid=self._ident.apid,
|
|
58
58
|
seq_count=self._ident.next_seq_count(),
|
|
59
|
-
service_type=self.
|
|
59
|
+
service_type=self.service,
|
|
60
60
|
service_subtype=2,
|
|
61
61
|
time=time,
|
|
62
62
|
data=source_data
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import queue
|
|
2
|
+
import warnings
|
|
2
3
|
from enum import Enum
|
|
3
4
|
from typing import TYPE_CHECKING, Any, Callable
|
|
4
5
|
|
|
@@ -44,10 +45,44 @@ class PusServiceType(bytes, Enum):
|
|
|
44
45
|
return self.description
|
|
45
46
|
|
|
46
47
|
|
|
48
|
+
_MAX_STANDARD_SERVICE = 127 # service types 0-127 are reserved for standard PUS services
|
|
49
|
+
|
|
50
|
+
|
|
47
51
|
class PusService:
|
|
48
52
|
"""Base class for PUS services."""
|
|
49
|
-
def __init__(self, service_type: PusServiceType, ident: PusIdent, pus_service_1: "RequestVerification | None" = None, tm_output_stream: OutputStream | None = None
|
|
50
|
-
|
|
53
|
+
def __init__(self, service_type: PusServiceType | int, ident: PusIdent, pus_service_1: "RequestVerification | None" = None, tm_output_stream: OutputStream | None = None,
|
|
54
|
+
*, name: str | None = None, description: str | None = None):
|
|
55
|
+
"""Create a PUS service instance.
|
|
56
|
+
|
|
57
|
+
Arguments:
|
|
58
|
+
service_type -- standard service type, or service type (0-255) of a custom service
|
|
59
|
+
ident -- PUS identifier
|
|
60
|
+
|
|
61
|
+
Keyword Arguments:
|
|
62
|
+
pus_service_1 -- PUS service 1 instance (default: {None})
|
|
63
|
+
tm_output_stream -- output stream (default: {None})
|
|
64
|
+
name -- service name, overrides the name of a standard service type (default: {None})
|
|
65
|
+
description -- service description, overrides the description of a standard service type (default: {None})
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
ValueError: if the service type is out of range
|
|
69
|
+
"""
|
|
70
|
+
if isinstance(service_type, PusServiceType): # standard service
|
|
71
|
+
self._service_type: PusServiceType | None = service_type
|
|
72
|
+
self._service_number = int(service_type.value)
|
|
73
|
+
self._name = name if name is not None else service_type.name
|
|
74
|
+
self._description = description if description is not None else service_type.description
|
|
75
|
+
else: # custom service
|
|
76
|
+
if isinstance(service_type, bool) or not isinstance(service_type, int):
|
|
77
|
+
raise TypeError("Service type must be a PusServiceType or an int")
|
|
78
|
+
if not 0 <= service_type <= 255:
|
|
79
|
+
raise ValueError(f"Service type must be in range 0-255, got {service_type}")
|
|
80
|
+
if service_type <= _MAX_STANDARD_SERVICE:
|
|
81
|
+
warnings.warn(f"Service type {service_type} is in the range reserved for standard PUS services (0-{_MAX_STANDARD_SERVICE})", stacklevel=2)
|
|
82
|
+
self._service_type = None
|
|
83
|
+
self._service_number = service_type
|
|
84
|
+
self._name = name if name is not None else f"SERVICE_{service_type}"
|
|
85
|
+
self._description = description if description is not None else ""
|
|
51
86
|
self._subservices: dict[int, Callable[..., Any]] = {}
|
|
52
87
|
self._ident = ident
|
|
53
88
|
self._incoming_tc_queue: queue.SimpleQueue[PusTcPacket] = queue.SimpleQueue()
|
|
@@ -56,15 +91,18 @@ class PusService:
|
|
|
56
91
|
|
|
57
92
|
@property
|
|
58
93
|
def service(self) -> int:
|
|
59
|
-
|
|
94
|
+
"""PUS service type number."""
|
|
95
|
+
return self._service_number
|
|
60
96
|
|
|
61
97
|
@property
|
|
62
98
|
def name(self) -> str:
|
|
63
|
-
|
|
99
|
+
"""Service name."""
|
|
100
|
+
return self._name
|
|
64
101
|
|
|
65
102
|
@property
|
|
66
103
|
def description(self) -> str:
|
|
67
|
-
|
|
104
|
+
"""Service description."""
|
|
105
|
+
return self._description
|
|
68
106
|
|
|
69
107
|
def enqueue(self, tc_packet: PusTcPacket):
|
|
70
108
|
"""Enqueue an incoming PUS TC packet.
|
|
@@ -83,6 +121,8 @@ class PusService:
|
|
|
83
121
|
tc_packet = self._incoming_tc_queue.get_nowait()
|
|
84
122
|
except queue.Empty:
|
|
85
123
|
break
|
|
124
|
+
if self._pus_service_1 is None:
|
|
125
|
+
raise RuntimeError(f"PUS service {self.service} has no request verification service")
|
|
86
126
|
subservice_handler = self._subservices[tc_packet.subservice]
|
|
87
127
|
ret = subservice_handler(app_data=tc_packet.app_data)
|
|
88
128
|
if isinstance(ret, bool):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: puslib
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: An implementation of the telemetry and telecommand packet utilization standard (PUS).
|
|
5
5
|
Home-page: https://github.com/pxntus/puslib
|
|
6
6
|
Author: Pontus Nyman
|
|
@@ -92,6 +92,7 @@ with open('telemetry.dump', 'rb') as f:
|
|
|
92
92
|
* PUS 8: Function Management
|
|
93
93
|
* PUS 17: Test (*partial support*)
|
|
94
94
|
* PUS 20: On-board Parameter Management (*partial support*)
|
|
95
|
+
* Custom (mission-specific) services
|
|
95
96
|
|
|
96
97
|
## Links
|
|
97
98
|
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import sched
|
|
2
|
+
import warnings
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from puslib.exceptions import TcPacketRoutingError
|
|
7
|
+
from puslib.ident import PusIdent
|
|
8
|
+
from puslib.packet import PusTcPacket, AckFlag
|
|
9
|
+
from puslib.parameter import UInt16Parameter
|
|
10
|
+
from puslib.process import Process, Router
|
|
11
|
+
from puslib.services import RequestVerification
|
|
12
|
+
from puslib.services.service import PusService, PusServiceType
|
|
13
|
+
from puslib.streams.buffer import QueuedOutput
|
|
14
|
+
from puslib.streams.stream import OutputStream
|
|
15
|
+
|
|
16
|
+
APID = 10
|
|
17
|
+
CUSTOM_SERVICE = 130
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class CustomService(PusService):
|
|
21
|
+
def __init__(self, ident: PusIdent, pus_service_1: RequestVerification, tm_output_stream: OutputStream):
|
|
22
|
+
super().__init__(CUSTOM_SERVICE, ident, pus_service_1, tm_output_stream, name="Custom", description="Custom service")
|
|
23
|
+
self.received: list[bytes] = []
|
|
24
|
+
self._register_sub_service(1, self._handler)
|
|
25
|
+
|
|
26
|
+
def _handler(self, app_data: bytes | bytearray) -> bool:
|
|
27
|
+
self.received.append(bytes(app_data))
|
|
28
|
+
return True
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class FakeClock:
|
|
32
|
+
def __init__(self):
|
|
33
|
+
self.now = 0.0
|
|
34
|
+
|
|
35
|
+
def time(self) -> float:
|
|
36
|
+
return self.now
|
|
37
|
+
|
|
38
|
+
def sleep(self, delay: float) -> None:
|
|
39
|
+
self.now += delay
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _create_tc(service_type: int, service_subtype: int, apid: int = APID, data: bytes | None = None) -> PusTcPacket:
|
|
43
|
+
return PusTcPacket.create(apid=apid, name=0, ack_flags=AckFlag.NONE,
|
|
44
|
+
service_type=service_type, service_subtype=service_subtype, data=data)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_forward_tc_with_wrong_apid_raises():
|
|
48
|
+
process = Process(APID, QueuedOutput(), sched.scheduler(), test=True)
|
|
49
|
+
with pytest.raises(TcPacketRoutingError):
|
|
50
|
+
process.forward(_create_tc(17, 1, apid=APID + 1))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_forward_tc_to_missing_service_raises():
|
|
54
|
+
process = Process(APID, QueuedOutput(), sched.scheduler(), test=False)
|
|
55
|
+
with pytest.raises(TcPacketRoutingError):
|
|
56
|
+
process.forward(_create_tc(17, 1))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_forward_tc_to_enabled_standard_service():
|
|
60
|
+
tm_stream = QueuedOutput()
|
|
61
|
+
process = Process(APID, tm_stream, sched.scheduler(), test=True)
|
|
62
|
+
process.forward(_create_tc(17, 1))
|
|
63
|
+
report = tm_stream.get()
|
|
64
|
+
assert report is not None
|
|
65
|
+
assert (report.service, report.subservice) == (17, 2)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_function_without_function_management_raises():
|
|
69
|
+
process = Process(APID, QueuedOutput(), sched.scheduler())
|
|
70
|
+
with pytest.raises(RuntimeError):
|
|
71
|
+
process.function(fid=0, args=())(lambda: True)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_function_is_called_by_tc():
|
|
75
|
+
process = Process(APID, QueuedOutput(), sched.scheduler(), function_management=True)
|
|
76
|
+
calls = []
|
|
77
|
+
|
|
78
|
+
@process.function(fid=3, args=(UInt16Parameter,))
|
|
79
|
+
def _func(arg1):
|
|
80
|
+
calls.append(arg1)
|
|
81
|
+
return True
|
|
82
|
+
|
|
83
|
+
process.forward(_create_tc(8, 1, data=bytes.fromhex("00030007")))
|
|
84
|
+
assert calls == [7]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_action_runs_periodically():
|
|
88
|
+
clock = FakeClock()
|
|
89
|
+
scheduler = sched.scheduler(clock.time, clock.sleep)
|
|
90
|
+
process = Process(APID, QueuedOutput(), scheduler)
|
|
91
|
+
runs = 0
|
|
92
|
+
|
|
93
|
+
@process.action(interval=1)
|
|
94
|
+
def _step():
|
|
95
|
+
nonlocal runs
|
|
96
|
+
runs += 1
|
|
97
|
+
|
|
98
|
+
assert runs == 1 # first run immediately when added
|
|
99
|
+
for now, expected_runs in ((0.9, 1), (1.0, 2), (2.5, 3)):
|
|
100
|
+
clock.now = now
|
|
101
|
+
scheduler.run(blocking=False)
|
|
102
|
+
assert runs == expected_runs
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_router_forwards_tc_by_apid():
|
|
106
|
+
router = Router()
|
|
107
|
+
services = {}
|
|
108
|
+
for apid in (10, 20):
|
|
109
|
+
process = Process(apid, QueuedOutput(), sched.scheduler())
|
|
110
|
+
services[apid] = process.add_service(CustomService)
|
|
111
|
+
router.register(process)
|
|
112
|
+
|
|
113
|
+
router.forward(_create_tc(CUSTOM_SERVICE, 1, apid=20, data=b'\x01'))
|
|
114
|
+
assert services[10].received == [] # no TC routed here
|
|
115
|
+
assert services[20].received == [b'\x01']
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_router_register_duplicate_apid_raises():
|
|
119
|
+
router = Router()
|
|
120
|
+
router.register(Process(APID, QueuedOutput(), sched.scheduler()))
|
|
121
|
+
with pytest.raises(ValueError):
|
|
122
|
+
router.register(Process(APID, QueuedOutput(), sched.scheduler()))
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def test_router_forward_tc_to_unknown_apid_raises():
|
|
126
|
+
router = Router()
|
|
127
|
+
router.register(Process(APID, QueuedOutput(), sched.scheduler()))
|
|
128
|
+
with pytest.raises(TcPacketRoutingError):
|
|
129
|
+
router.forward(_create_tc(17, 1, apid=APID + 1))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def test_add_custom_service_and_forward_tc():
|
|
133
|
+
tm_stream = QueuedOutput()
|
|
134
|
+
process = Process(APID, tm_stream, sched.scheduler())
|
|
135
|
+
service = process.add_service(CustomService)
|
|
136
|
+
|
|
137
|
+
assert service.service == CUSTOM_SERVICE
|
|
138
|
+
assert service.name == "Custom"
|
|
139
|
+
assert service.description == "Custom service"
|
|
140
|
+
|
|
141
|
+
packet = PusTcPacket.create(apid=APID, name=0, ack_flags=AckFlag.NONE,
|
|
142
|
+
service_type=CUSTOM_SERVICE, service_subtype=1, data=b'\x01\x02')
|
|
143
|
+
process.forward(packet)
|
|
144
|
+
|
|
145
|
+
assert service.received == [b'\x01\x02']
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_add_duplicate_service_raises():
|
|
149
|
+
process = Process(APID, QueuedOutput(), sched.scheduler())
|
|
150
|
+
process.add_service(CustomService)
|
|
151
|
+
with pytest.raises(ValueError):
|
|
152
|
+
process.add_service(CustomService)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def test_add_service_conflicting_with_standard_service_raises():
|
|
156
|
+
process = Process(APID, QueuedOutput(), sched.scheduler(), test=True)
|
|
157
|
+
with pytest.raises(ValueError), pytest.warns(UserWarning):
|
|
158
|
+
process.add_service(lambda ident, pus_service_1, tm: PusService(17, ident, pus_service_1, tm))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@pytest.mark.parametrize("service_type", [-1, 256])
|
|
162
|
+
def test_service_type_out_of_range_raises(service_type):
|
|
163
|
+
with pytest.raises(ValueError):
|
|
164
|
+
PusService(service_type, PusIdent(APID))
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@pytest.mark.parametrize("service_type", [0, 23, 127])
|
|
168
|
+
def test_custom_service_type_below_128_warns(service_type):
|
|
169
|
+
with pytest.warns(UserWarning):
|
|
170
|
+
PusService(service_type, PusIdent(APID))
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@pytest.mark.parametrize("service_type", [128, 255])
|
|
174
|
+
def test_custom_service_type_from_128_does_not_warn(service_type):
|
|
175
|
+
with warnings.catch_warnings():
|
|
176
|
+
warnings.simplefilter("error")
|
|
177
|
+
service = PusService(service_type, PusIdent(APID))
|
|
178
|
+
assert service.service == service_type
|
|
179
|
+
assert service.name == f"SERVICE_{service_type}"
|
|
180
|
+
assert service.description == ""
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def test_standard_service_type_properties_and_no_warning():
|
|
184
|
+
with warnings.catch_warnings():
|
|
185
|
+
warnings.simplefilter("error")
|
|
186
|
+
service = PusService(PusServiceType.TEST, PusIdent(APID))
|
|
187
|
+
assert service.service == 17
|
|
188
|
+
assert service.name == "TEST"
|
|
189
|
+
assert service.description == "Test"
|
|
190
|
+
assert service._service_type is PusServiceType.TEST # pylint: disable=protected-access
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def test_invalid_service_type_raises():
|
|
194
|
+
with pytest.raises(TypeError):
|
|
195
|
+
PusService("17", PusIdent(APID)) # type: ignore[arg-type]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|