1"""
2Example TReK Building a Packet
3
4This example builds the packet described by the define_packet example. If
5that example hasn't run, you will need to do that now. The file that is
6created must be located where this program can find it.
7The table below shows what is defined in the packet:
8Name Data Type Size Notes
9Version unsigned integer 4 Should always be zero
10PktId unsigned integer 12 For this packet, the value is 54
11PktLen unsigned integer 16 Length of packet after this point
12PktCnt unsigned integer 8 Packet counter
13Time system time 32 A.k.a. DT_UNIX_TIME
14IntParam signed integer 16 First data parameter
15UintParam unsigned integer 32 Three consecutive values
16FloatParam double 64 Little-endian floating point
17StrParam string 800 Varible length string
18Checksum unsigned integer 32 CRC-32 checksum
19"""
20
21import trek
22
23
24def main() -> None:
25 """
26 Main Routine
27 """
28
29 try:
30
31
32
33
34
35
37 param_value: float = 0.0
38
39
40 pkt.load_file("my_file.xml")
41
42
43 pkt.create_global_packet_map()
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 param = pkt.find_parameter("IntParam")
59
60
61
62
63
64
65
66
67 param_value = -2
68 param.set_value(param_value)
69
70
71
72
73
74
75
76
77
78 param = pkt.find_parameter("UintParam")
79 param.set_value(1024, 1)
80 param.set_value(2048, 2)
81 param.set_value(4096, 3)
82
83
84 param = pkt.find_parameter("FloatParam")
85 param_value = 1.2345
86 param.set_value(param_value)
87
88
89
90 param = pkt.find_parameter("StrParam")
91 param.set_value("Howdy Y'all")
92
93
94
95
96
97
98
99
100
101 buf = bytearray(1000)
102 _ = pkt.build(buf)
103
104
105
106
107
108
109
110
111
112
113
114
116
117 print(err.find_error_code())
118 print(err)
119
120
121if __name__ == "__main__":
122 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:12846