TReK Python  5.3.2
Telemetry/Command API
ex_command.py

ex_command.py

1"""
2Example TReK Command Demonstration
3"""
4import trek
5
6
7def main() -> None:
8 """
9 Main Routine
10 """
11
12 try:
13 api = trek.CommandApi()
14
15 # Connect to a destination. The name passed into the Connect() call is
16 # the name used when configuring the destination in the TReK Command
17 # application.
18 api.connect("POIC")
19
20 # Calling this method allows the API to clean up resources that may be
21 # left over from a user program that crashed. Not checking the return
22 # value as it is safe to continue if this method fails.
23 api.cleanse()
24
25 # Once connected to the API, you can make calls to the API to see what is
26 # available for the interface. Call to see if there are any status
27 # messages. If there are, print out all of the information in each
28 # message.
29
30 status_list = api.get_status_message_list()
31 print(f"There are {len(status_list)} status messages for this destination.\n")
32
33 for msg in status_list:
34 print(f"Status Message: {msg}\n")
36
37 _ = api.get_status_message(msg, pc)
38
39 # get all of the parameters that make up the status message
40 param_list = pc.get_sorted_parameter_list(False)
41
42 for param_name in param_list:
43 # print each name/value in status mesesage
44 param = pc.find_parameter(param_name)
45 print(f"{param_name}: {param.get_value_as_string()}\n")
46
47 # Check to see if there are command responses associated with this
48 # destination. If there is, get a copy of the responses so we can
49 # check any errors that are received when sending commands. Store
50 # the responses in a map for quick lookup.
51 resp_list = api.get_command_response_list()
52
53 response_dictionary = {}
54 for cr_name in resp_list:
55 response = trek.CommandResponse()
56 try:
57 api.get_command_response(cr_name, response)
58 except trek.TrekError as err:
59 print(f"Error {err.code}: Could not retrieve response {cr_name}.\n")
60 # Not fatal! Should never occur unless API has coding error.
61 continue
62 response_dictionary[cr_name] = response
63
64 # Send a command by initiating an uplink from the destination. This method
65 # of sending commands is not avaiable for all destinations, but will fail
66 # gracefully. The token will be used to get command track information.
67 token = api.initiate_command("ACCELERATE")
68
69 track_item = trek.TrackItem()
70 api.get_track(token, track_item)
71
72 for idx in range(track_item.get_number_of_responses()):
73 resp_item = track_item.get_response(idx)
74
75 if resp_item.name in response_dictionary:
76 my_command_res: trek.CommandResponse = response_dictionary[
77 resp_item.name
78 ]
79 resp_info = my_command_res.get_error_details(resp_item.value)
80 print(f"Response {resp_item.name}: {resp_info.info}.\n")
81
82 #
83 # It is always best to call Disconnect when you are finished with the
84 # API. There are system resources that can be freed when you no
85 # longer need the API.
86 #
87 api.disconnect()
88
89 except trek.TrekError as err:
90 # Locate friendly message why it failed.
91 print(err.find_error_code())
92 print(err)
93
94
95if __name__ == "__main__":
96 main()
Provides access to command features of TReK.
Definition: trek.py:603
This class holds all the responses associated with a single command uplink.
Definition: trek.py:1363
This class describes a parameter collection.
Definition: trek.py:9144
This class holds all of the responses associated with a single command uplink.
Definition: trek.py:12479
The TReK C++ was designed to return error codes.
Definition: trek.py:12846