1"""
2This example extracts the packet described by the define_packet example. If
3that example hasn't run, you will need to do that now. The file that is
4created must be located where this program can find it.
5The table below shows what is defined in the packet:
6Name Data Type Size Notes
7Version unsigned integer 4 Should always be zero
8PktId unsigned integer 12 For this packet, the value is 54
9PktLen unsigned integer 16 Length of packet after this point
10PktCnt unsigned integer 8 Packet counter
11Time system time 32 A.k.a. DT_UNIX_TIME
12IntParam signed integer 16 First data parameter
13UintParam unsigned integer 32 Three consecutive values
14FloatParam double 64 Little-endian floating point
15StrParam string 800 Varible length string
16Checksum unsigned integer 32 CRC-32 checksum
17"""
18import trek
19
20
21def main() -> None:
22 """
23 Main Routine
24 """
25
26 try:
27
28
29
30
31
32
33
35
36
37 pkt.load_file("my_file.xml")
38
39
40 pkt.create_global_packet_map()
41
42
43
44
45
46 buf = bytearray(100)
47 buf_size: int = 0
48
49 buf[0] = 0x00
50 buf[1] = 0x36
51 buf[2] = 0x00
52 buf[3] = 0x24
53 buf[4] = 0xFE
54 buf[5] = 0x53
55 buf[6] = 0x11
56 buf[7] = 0x06
57 buf[8] = 0x5B
58 buf[9] = 0xFF
59 buf[10] = 0xFF
60 buf[11] = 0x00
61 buf[12] = 0x00
62 buf[13] = 0x00
63 buf[14] = 0xFF
64 buf[15] = 0x00
65 buf[16] = 0x00
66 buf[17] = 0x01
67 buf[18] = 0x00
68 buf[19] = 0x00
69 buf[20] = 0x01
70 buf[21] = 0x00
71 buf[22] = 0x00
72 buf[23] = 0x00
73 buf[24] = 0x00
74 buf[25] = 0x00
75 buf[26] = 0x00
76 buf[27] = 0x10
77 buf[28] = 0x88
78 buf[29] = 0xC3
79 buf[30] = 0xC0
80 buf[31] = 0x48
81 buf[32] = 0x65
82 buf[33] = 0x6C
83 buf[34] = 0x70
84 buf[35] = 0x21
85 buf[36] = 0x00
86 buf[37] = 0x20
87 buf[38] = 0x96
88 buf[39] = 0x54
89 buf[40] = 0x1C
90 buf_size: int = 41
91
92 _ = pkt.extract(buf, buf_size)
93
94
95
96 all_params = pkt.get_sorted_parameter_list()
97 for param_name in all_params:
98 param = pkt.find_parameter(param_name)
99
100
101 for sample in range(1, param.get_number_of_samples() + 1):
102 print(
103 f"{param_name} (sample {sample}): {param.get_value_as_string(sample)}"
104 )
105
107
108 print(err.find_error_code())
109 print(err)
110
111
112if __name__ == "__main__":
113 main()
This class describes a packet composed of one or more parameters.
Definition: trek.py:5009
The TReK C++ was designed to return error codes.
Definition: trek.py:12835