-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefaultpackets.py
190 lines (157 loc) · 5.64 KB
/
defaultpackets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import struct
from pylibrnp.rnppacket import RnpPacket
class TelemetryPacket(RnpPacket):
'''Telemetry Packer, Also shows how vars can be used to obtain the structure of the packet.
Constructor parameters also do not matter to serialization/deserialzation'''
struct_str = '<fffffffffffffffffflBfffffffffffffffHHfflLQhf'
size = struct.calcsize(struct_str)
packet_type = 0
def __init__(self):
self.pn:float = 0
self.pe:float = 0
self.pd:float = 0
self.vn:float = 0
self.ve:float = 0
self.vd:float = 0
self.an:float = 0
self.ae:float = 0
self.ad:float = 0
self.roll:float = 0
self.pitch:float = 0
self.yaw:float = 0
self.q0:float = 0
self.q1:float = 0
self.q2:float = 0
self.q3:float = 0
self.lat:float = 0
self.lng:float = 0
self.alt:int = 0
self.sat:int = 0
self.ax:float = 0
self.ay:float = 0
self.az:float = 0
self.h_ax:float = 0
self.h_ay:float = 0
self.h_az:float = 0
self.gx:float = 0
self.gy:float = 0
self.gz:float = 0
self.mx:float = 0
self.my:float = 0
self.mz:float = 0
self.baro_temp:float = 0
self.baro_press:float = 0
self.baro_alt:float = 0
self.batt_voltage:int = 0
self.batt_percent:int = 0
self.launch_lat:float = 0
self.launch_lng:float = 0
self.launch_alt:int = 0
self.system_status:int = 0
self.system_time:int = 0
self.rssi:int = 0
self.snr:float = 0
super().__init__(list(vars(self).keys()),
TelemetryPacket.struct_str,
TelemetryPacket.size,
TelemetryPacket.packet_type)
def __str__(self):
header_str = self.header.__str__() + '\ns'
desc_str = f'TELEMETRY PACKET BODY: Havent done this yet oops\n'
return header_str
class SimpleCommandPacket(RnpPacket):
'''Simple Command Packet, shows how to manually add keys to the member variables in the packet'''
struct_str = '<BI'
size = struct.calcsize(struct_str)
packet_type = 0
def __init__(self, command: int = 0, arg: int = 0):
self.command = command
self.arg = arg
super().__init__(['command','arg'],
SimpleCommandPacket.struct_str,
SimpleCommandPacket.size,
SimpleCommandPacket.packet_type)
def __str__(self):
header_str = self.header.__str__() + "\n"
param_str = f'SIMPLE COMMAND PACKET BODY: \tcommand = {self.command}\n \t\t\targument = {self.arg}\n'
return header_str + param_str
class servocalibrate(RnpPacket):
'''description'''
struct_str = '<BHHH'
size = struct.calcsize(struct_str)
packet_type = 105
def __init__(self, command: int = 0, angl_min: int = 0, angl_max: int = 0, home_angl: int = 0):
self.command:int = command
self.angl_min:int = angl_min
self.angl_max:int = angl_max
self.home_angl:int = home_angl
super().__init__(list(vars(self).keys()),
servocalibrate.struct_str,
servocalibrate.size,
servocalibrate.packet_type)
def __str__(self):
header_str = self.header.__str__() + '\ns'
desc_str = f'TELEMETRY PACKET BODY: Havent done this yet oops\n'
return header_str
class processedsensorpacket(RnpPacket):
'''description'''
struct_str = '<ffffffffffffffffffffLQ'
size = struct.calcsize(struct_str)
packet_type = 0
def __init__(self):
self.ch0sens:float = 0
self.ch1sens:float = 0
self.ch2sens:float = 0
self.ch3sens:float = 0
self.ch4sens:float = 0
self.ch5sens:float = 0
self.ch6sens:float = 0
self.ch7sens:float = 0
self.ch8sens:float = 0
self.ch9sens:float = 0
self.temp0:float = 0
self.temp1:float = 0
self.temp2:float = 0
self.temp3:float = 0
self.temp4:float = 0
self.temp5:float = 0
self.temp6:float = 0
self.temp7:float = 0
self.temp8:float = 0
self.temp9:float = 0
self.system_status:int = 0
self.system_time:int = 0
super().__init__(list(vars(self).keys()),
processedsensorpacket.struct_str,
processedsensorpacket.size,
processedsensorpacket.packet_type)
def __str__(self):
header_str = self.header.__str__() + '\ns'
desc_str = f'TELEMETRY PACKET BODY: Havent done this yet oops\n'
return header_str
class rawADCPacket(RnpPacket):
'''description'''
struct_str = '<LLLLLLLLLLLQ'
size = struct.calcsize(struct_str)
packet_type = 0
def __init__(self):
self.ch0:int = 0
self.ch1:int = 0
self.ch2:int = 0
self.ch3:int = 0
self.ch4:int = 0
self.ch5:int = 0
self.ch6:int = 0
self.ch7:int = 0
self.ch8:int = 0
self.ch9:int = 0
self.system_status:int = 0
self.system_time:int = 0
super().__init__(list(vars(self).keys()),
rawADCPacket.struct_str,
rawADCPacket.size,
rawADCPacket.packet_type)
def __str__(self):
header_str = self.header.__str__() + '\ns'
desc_str = f'TELEMETRY PACKET BODY: Havent done this yet oops\n'
return header_str