TReK Python  5.3.3
Telemetry/Command API
ex_telem_get_newest.py
1"""
2Example using get_newest_packet().
3"""
4import trek
5
6# NOTE: This example requires the TReK Data GUI to be started and the PDSS Payload
7# Packet with APID 7 to be activated with a Real-Time data mode.
8
9tlm_api = trek.TelemetryApi()
10pkt = trek.Packet()
11packet_buffer = bytearray(4096)
12
13
14def main() -> None:
15 """
16 Main Routine
17 """
18
19 try:
20 pkt_key_list: list[str]
21
22 # Connect to a data store.
23 tlm_api.connect("DefaultDataStore")
24
25 # Calling this method allows the API to clean up resources that may be
26 # left over from a user program that crashed. Not checking the return
27 # value as it is safe to continue if this method fails.
28 tlm_api.cleanse()
29
30 # Get a list of the packet keys currently being processed. If you know
31 # your packet key already, this isn't needed.
32 pkt_key_list = tlm_api.get_source_list()
33
34 for idx, key in enumerate(pkt_key_list):
35 print(f"Packet key {idx+1}: {key}")
36
37 # Get the packet definition so that parameters can be extracted
38 # from the packet.
39 tlm_api.get_packet_definition("PdssPayload.RT.PL.7", pkt)
40
41 # Get the latest packet from the data store.
42 tlm_api.get_newest_packet("PdssPayload.RT.PL.7", packet_buffer)
43
44 # Use the packet definition to extract the data.
45 _ = pkt.extract(packet_buffer, len(packet_buffer))
46
47 # The packet has been extracted and can now get the values using the Packet class
48 # methods. Look up a parameter and get its value.
49 param = pkt.find_parameter("MSID016")
50
51 param_value = param.get_value()
52
53 print(f"Value is: {param_value}")
54
55 # It is always best to call Disconnect when you are finished with the
56 # API. There are system resources that can be freed when you no
57 # longer need the API.
58 tlm_api.disconnect()
59
60 except trek.TrekError as err:
61 # Locate friendly message why it failed.
62 print(err.find_error_code())
63 print(err)
64
65
66if __name__ == "__main__":
67 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