1"""
2Example using get_next_packet().
3"""
4
5import trek
6
7
8
9
10
11def main() -> None:
12 """
13 Main Routine
14 """
15
16 try:
19 packet_buffer = bytearray(4096)
20 token: int = 0
21 last_token: int = 0
22 status: int
23
24
25 tlm_api.connect("DefaultDataStore")
26
27
28
29
30 tlm_api.cleanse()
31
32
33
34 tlm_api.get_packet_definition("PdssPayload.RT.PL.7", pkt)
35
36
37 tlm_api.register_packet_semaphore("PdssPayload.RT.PL.7")
38
39
40
41
42 event_triggered: int = 0
43 while True:
44
45 while True:
46 (token, ret_size, status) = tlm_api.get_next_packet(
47 "PdssPayload.RT.PL.7", token, packet_buffer
48 )
49
50 if status in (
51 trek.SUCCESS,
52 trek.TLM_API_MORE_DATA_AVAILABLE,
53 trek.TLM_API_MISSING_DATA,
54 ):
55
56 try:
57
58 _ = pkt.extract(packet_buffer, ret_size)
60 print("Could not extract parameter data from the packet.")
61 continue
62
63 if last_token == token:
64
65
66
67 pass
68 else:
69
70
71 last_token = token
72 print("Printing all parameter values:")
73 print(f"{pkt.print_values()}")
74
75 if status == trek.SUCCESS:
76 break
77
78
79
80
81 if not tlm_api.wait_for_packet("PdssPayload.RT.PL.7"):
82
83
84
85 print("Packet did not arrive in timeout period.")
86
87 event_triggered += 1
88
89 if event_triggered < 100:
90 break
91
92
93 tlm_api.unregister_packet_semaphore("PdssPayload.RT.PL.7")
94
95
96
97
98 tlm_api.disconnect()
99
101
102 print(err.find_error_code())
103 print(err)
104
105
106if __name__ == "__main__":
107 main()
This class describes a packet composed of one or more parameters.
Definition: trek.py:5009
Provides access to telemetry features of TReK.
Definition: trek.py:12090
The TReK C++ was designed to return error codes.
Definition: trek.py:12835