dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
uavohottbridge.h
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  */
28 
29 #include "openpilot.h"
30 #include "modulesettings.h"
31 #include "hottsettings.h"
32 #include "attitudeactual.h"
33 #include "baroaltitude.h"
34 #include "flightbatterystate.h"
35 #include "flightstatus.h"
36 #include "gyros.h"
37 #include "gpsposition.h"
38 #include "gpstime.h"
39 #include "homelocation.h"
40 #include "positionactual.h"
41 #include "systemalarms.h"
42 #include "velocityactual.h"
43 
44 // timing variables
45 #define IDLE_TIME 10 // idle line delay to prevent data crashes on telemetry line.
46 #define DATA_TIME 3 // time between 2 transmitted bytes
47 
48 // sizes and lengths
49 #define climbratesize 50 // defines size of ring buffer for climbrate calculation
50 #define statussize 21 // number of characters in status line
51 #define HOTT_MAX_MESSAGE_LENGTH 200
52 
53 // scale factors
54 #define M_TO_CM 100 // scale m to cm or m/s to cm/s
55 #define MS_TO_KMH 3.6f // scale m/s to km/h
56 #define DEG_TO_UINT 0.5f // devide degrees by 2. then the value fits into a byte.
57 
58 // offsets. used to make transmitted values unsigned.
59 #define OFFSET_ALTITUDE 500 // 500m
60 #define OFFSET_CLIMBRATE 30000 // 30000cm/s or 300m/s
61 #define OFFSET_CLIMBRATE3S 120 // 120m/s
62 #define OFFSET_TEMPERATURE 20 // 20 degrees
63 
64 // Bits to invert display areas or values
65 #define VARIO_INVERT_ALT (1<<0) // altitude
66 #define VARIO_INVERT_MAX (1<<1) // max altitude
67 #define VARIO_INVERT_MIN (1<<2) // min altitude
68 #define VARIO_INVERT_CR1S (1<<3) // climbrate 1s
69 #define VARIO_INVERT_CR3S (1<<4) // climbrate 3s
70 #define VARIO_INVERT_CR10S (1<<5) // climbrate 10s
71 
72 #define GPS_INVERT_HDIST (1<<0) // home distance
73 #define GPS_INVERT_SPEED (1<<1) // speed (kmh)
74 #define GPS_INVERT_ALT (1<<2) // altitude
75 #define GPS_INVERT_CR1S (1<<3) // climbrate 1s
76 #define GPS_INVERT_CR3S (1<<4) // climbrate 3s
77 #define GPS_INVERT2_POS (1<<0) // GPS postion values
78 
79 #define GAM_INVERT_CELL (1<<0) // cell voltage
80 #define GAM_INVERT_BATT1 (1<<1) // battery 1 voltage
81 #define GAM_INVERT_BATT2 (1<<2) // battery 1 voltage
82 #define GAM_INVERT_TEMP1 (1<<3) // temperature 1
83 #define GAM_INVERT_TEMP2 (1<<4) // temperature 2
84 #define GAM_INVERT_FUEL (1<<5) // fuel
85 #define GAM_INVERT2_CURRENT (1<<0) // current
86 #define GAM_INVERT2_VOLTAGE (1<<1) // voltage
87 #define GAM_INVERT2_ALT (1<<2) // altitude
88 #define GAM_INVERT2_CR1S (1<<3) // climbrate 1s
89 #define GAM_INVERT2_CR3S (1<<4) // climbrate 3s
90 
91 #define EAM_INVERT_CAPACITY (1<<0) // capacity
92 #define EAM_INVERT_BATT1 (1<<1) // battery 1 voltage
93 #define EAM_INVERT_BATT2 (1<<2) // battery 1 voltage
94 #define EAM_INVERT_TEMP1 (1<<3) // temperature 1
95 #define EAM_INVERT_TEMP2 (1<<4) // temperature 2
96 #define EAM_INVERT_ALT (1<<5) // altitude
97 #define EAM_INVERT_CURRENT (1<<6) // current
98 #define EAM_INVERT_VOLTAGE (1<<7) // voltage
99 #define EAM_INVERT2_ALT (1<<2) // altitude
100 #define EAM_INVERT2_CR1S (1<<3) // climbrate 1s
101 #define EAM_INVERT2_CR3S (1<<4) // climbrate 3s
102 
103 #define ESC_INVERT_VOLTAGE (1<<0) // voltage
104 #define ESC_INVERT_TEMP1 (1<<1) // temperature 1
105 #define ESC_INVERT_TEMP2 (1<<2) // temperature 2
106 #define ESC_INVERT_CURRENT (1<<3) // current
107 #define ESC_INVERT_RPM (1<<4) // rpm
108 #define ESC_INVERT_CAPACITY (1<<5) // capacity
109 #define ESC_INVERT_MAXCURRENT (1<<6) // maximum current
110 
111 // message codes
112 #define HOTT_TEXT_ID 0x7f // Text request
113 #define HOTT_BINARY_ID 0x80 // Binary request
114 #define HOTT_VARIO_ID 0x89 // Vario Module ID
115 #define HOTT_VARIO_TEXT_ID 0x90 // Vario Module TEXT ID
116 #define HOTT_GPS_ID 0x8a // GPS Module ID
117 #define HOTT_GPS_TEXT_ID 0xa0 // GPS Module TEXT ID
118 #define HOTT_ESC_ID 0x8c // ESC Module ID
119 #define HOTT_ESC_TEXT_ID 0xc0 // ESC Module TEXT ID
120 #define HOTT_GAM_ID 0x8d // General Air Module ID
121 #define HOTT_GAM_TEXT_ID 0xd0 // General Air Module TEXT ID
122 #define HOTT_EAM_ID 0x8e // Electric Air Module ID
123 #define HOTT_EAM_TEXT_ID 0xe0 // Electric Air Module TEXT ID
124 #define HOTT_TEXT_START 0x7b // Start byte Text mode
125 #define HOTT_START 0x7c // Start byte Binary mode
126 #define HOTT_STOP 0x7d // End byte
127 #define HOTT_BUTTON_DEC 0xEB // minus button
128 #define HOTT_BUTTON_INC 0xED // plus button
129 #define HOTT_BUTTON_SET 0xE9 // set button
130 #define HOTT_BUTTON_NIL 0x0F // esc button
131 #define HOTT_BUTTON_NEXT 0xEE // next button
132 #define HOTT_BUTTON_PREV 0xE7 // previous button
133 
134 // prefined signal tones or spoken announcments
135 #define HOTT_TONE_A 1 // minimum speed
136 #define HOTT_TONE_B 2 // sink rate 3 seconds
137 #define HOTT_TONE_C 3 // sink rate 1 second
138 #define HOTT_TONE_D 4 // maximum distance
139 #define HOTT_TONE_E 5 // -
140 #define HOTT_TONE_F 6 // minimum temperature sensor 1
141 #define HOTT_TONE_G 7 // minimum temperature sensor 2
142 #define HOTT_TONE_H 8 // maximum temperature sensor 1
143 #define HOTT_TONE_I 9 // maximum temperature sensor 2
144 #define HOTT_TONE_J 10 // overvoltage sensor 1
145 #define HOTT_TONE_K 11 // overvoltage sensor 2
146 #define HOTT_TONE_L 12 // maximum speed
147 #define HOTT_TONE_M 13 // climb rate 3 seconds
148 #define HOTT_TONE_N 14 // climb rate 1 second
149 #define HOTT_TONE_O 15 // minimum height
150 #define HOTT_TONE_P 16 // minimum input voltage
151 #define HOTT_TONE_Q 17 // minimum cell voltage
152 #define HOTT_TONE_R 18 // undervoltage sensor 1
153 #define HOTT_TONE_S 19 // undervoltage sensor 2
154 #define HOTT_TONE_T 20 // minimum rpm
155 #define HOTT_TONE_U 21 // fuel reserve
156 #define HOTT_TONE_V 22 // capacity
157 #define HOTT_TONE_W 23 // maximum current
158 #define HOTT_TONE_X 24 // maximum input voltage
159 #define HOTT_TONE_Y 25 // maximum rpm
160 #define HOTT_TONE_Z 26 // maximum height
161 #define HOTT_TONE_20M 37 // 20 meters
162 #define HOTT_TONE_40M 38 // 40 meters
163 #define HOTT_TONE_60M 39 // 60 meters
164 #define HOTT_TONE_80M 40 // 80 meters
165 #define HOTT_TONE_100M 41 // 100 meters
166 #define HOTT_TONE_42 42 // receiver voltage
167 #define HOTT_TONE_43 43 // receiver temperature
168 #define HOTT_TONE_200M 46 // 200 meters
169 #define HOTT_TONE_400M 47 // 400 meters
170 #define HOTT_TONE_600M 48 // 600 meters
171 #define HOTT_TONE_800M 49 // 800 meters
172 #define HOTT_TONE_1000M 50 // 10000 meters
173 #define HOTT_TONE_51 51 // maximum servo temperature
174 #define HOTT_TONE_52 52 // maximum servo position difference
175 
176 
177 // Private types
178 typedef struct {
179  uint8_t l;
180  uint8_t h;
181 } uword_t;
182 
183 // Private structures
185  HoTTSettingsData Settings;
186  AttitudeActualData Attitude;
187  BaroAltitudeData Baro;
188  FlightBatteryStateData Battery;
189  FlightStatusData FlightStatus;
190  GPSPositionData GPS;
191  GPSTimeData GPStime;
192  GyrosData Gyro;
193  HomeLocationData Home;
194  PositionActualData Position;
195  SystemAlarmsData SysAlarms;
196  VelocityActualData Velocity;
199  float altitude;
203  float climbrate1s;
204  float climbrate3s;
207  float homecourse;
208  uint8_t last_armed;
210 };
211 
212 // VARIO Module message structure
214  uint8_t start; // start byte
215  uint8_t sensor_id; // VARIO sensor ID
216  uint8_t warning; // 0…= warning beeps
217  uint8_t sensor_text_id; // VARIO sensor text ID
218  uint8_t alarm_inverse; // this inverts specific parts of display
219  uword_t altitude; // altitude (meters), offset 500, 500 == 0m
220  uword_t max_altitude; // max. altitude (meters)
221  uword_t min_altitude; // min. altitude (meters)
222  uword_t climbrate; // climb rate (0.01m/s), offset 30000, 30000 == 0.00m/s
223  uword_t climbrate3s; // climb rate (0.01m/3s)
224  uword_t climbrate10s; // climb rate (0.01m/10s)
225  uint8_t ascii[21]; // 21 chars of text
226  uint8_t ascii1; // ASCII Free character [1] (next to Alt)
227  uint8_t ascii2; // ASCII Free character [2] (next to Dir)
228  uint8_t ascii3; // ASCII Free character [3] (next to I)
229  int8_t compass; // 1=2°, -1=-2°
230  uint8_t version; // version number
231  uint8_t stop; // stop byte
232  uint8_t checksum; // Lower 8-bits of all bytes summed
233 };
234 
235 // GPS Module message structure
237  uint8_t start; // start byte
238  uint8_t sensor_id; // GPS sensor ID
239  uint8_t warning; // 0…= warning beeps
240  uint8_t sensor_text_id; // GPS Sensor text mode ID
241  uint8_t alarm_inverse1; // this inverts specific parts of display
242  uint8_t alarm_inverse2;
243  uint8_t flight_direction; // flight direction (1 = 2°; 0° = north, 90° = east , 180° = south , 270° west)
244  uword_t gps_speed; // GPS speed (km/h)
245  uint8_t latitude_ns; // GPS latitude north/south (0 = N)
246  uword_t latitude_min; // GPS latitude (min)
247  uword_t latitude_sec; // GPS latitude (sec)
248  uint8_t longitude_ew; // GPS longitude east/west (0 = E)
249  uword_t longitude_min; // GPS longitude (min)
250  uword_t longitude_sec; // GPS longitude (sec)
251  uword_t distance; // distance from home location (meters)
252  uword_t altitude; // altitude (meters), offset 500, 500 == 0m
253  uword_t climbrate; // climb rate (0.01m/s), offset of 30000, 30000 = 0.00 m/s
254  uint8_t climbrate3s; // climb rate in (m/3s). offset of 120, 120 == 0m/3sec
255  uint8_t gps_num_sat; // GPS number of satelites
256  uint8_t gps_fix_char; // GPS FixChar ('D'=DGPS, '2'=2D, '3'=3D)
257  uint8_t home_direction; // home direction (1=2°, direction from starting point to model position)
258  int8_t angle_roll; // angle x-direction (roll 1=2°, 255=-2°)
259  int8_t angle_nick; // angle y-direction (nick)
260  int8_t angle_compass; // angle z-direction (yaw)
261  uint8_t gps_hour; // GPS time hours
262  uint8_t gps_min; // GPS time minutes
263  uint8_t gps_sec; // GPS time seconds
264  uint8_t gps_msec; // GPS time .sss
265  uword_t msl; // MSL or NN altitude
266  uint8_t vibration; // vibration
267  uint8_t ascii4; // ASCII Free Character [4] (next to home distance)
268  uint8_t ascii5; // ASCII Free Character [5] (next to home direction)
269  uint8_t ascii6; // ASCII Free Character [6] (next to number of sats)
270  uint8_t version; // version number (0=gps, 1=gyro, 255=multicopter)
271  uint8_t stop; // stop byte
272  uint8_t checksum; // Lower 8-bits of all bytes summed
273 };
274 
275 // General Air Module message structure
277  uint8_t start; // start byte
278  uint8_t sensor_id; // GAM sensor ID
279  uint8_t warning; // 0…= warning beeps
280  uint8_t sensor_text_id; // EAM Sensor text mode ID
281  uint8_t alarm_inverse1; // this inverts specific parts of display
282  uint8_t alarm_inverse2;
283  uint8_t cell1; // cell voltages in 0.02V steps, 210 == 4.2V
284  uint8_t cell2;
285  uint8_t cell3;
286  uint8_t cell4;
287  uint8_t cell5;
288  uint8_t cell6;
289  uword_t batt1_voltage; // battery sensor 1 in 0.1V steps, 50 == 5.5V
290  uword_t batt2_voltage; // battery sensor 2 voltage
291  uint8_t temperature1; // temperature 1 in °C, offset of 20, 20 == 0°C
292  uint8_t temperature2; // temperature 2
293  uint8_t fuel_procent; // fuel capacity in %, values from 0..100
294  uword_t fuel_ml; // fuel capacity in ml, values from 0..65535
295  uword_t rpm; // rpm, scale factor 10, 300 == 3000rpm
296  uword_t altitude; // altitude in meters, offset of 500, 500 == 0m
297  uword_t climbrate; // climb rate (0.01m/s), offset of 30000, 30000 = 0.00 m/s
298  uint8_t climbrate3s; // climb rate (m/3sec). offset of 120, 120 == 0m/3sec
299  uword_t current; // current in 0.1A steps
300  uword_t voltage; // main power voltage in 0.1V steps
301  uword_t capacity; // used battery capacity in 10mAh steps
302  uword_t speed; // speed in km/h
303  uint8_t min_cell_volt; // lowest cell voltage in 20mV steps. 124 == 2.48V
304  uint8_t min_cell_volt_num; // number of the cell with the lowest voltage
305  uword_t rpm2; // rpm2 in 10 rpm steps, 300 == 3000rpm
306  uint8_t g_error_number; // general error number (Voice error == 12)
307  uint8_t pressure; // pressure up to 15bar, 0.1bar steps
308  uint8_t version; // version number
309  uint8_t stop; // stop byte
310  uint8_t checksum; // Lower 8-bits of all bytes summed
311 };
312 
313 // Electric Air Module message structure
315  uint8_t start; // Start byte
316  uint8_t sensor_id; // EAM sensor id
317  uint8_t warning;
318  uint8_t sensor_text_id; // EAM Sensor text mode ID
319  uint8_t alarm_inverse1; // this inverts specific parts of display
320  uint8_t alarm_inverse2;
321  uint8_t cell1_L; // cell voltages of the lower battery
322  uint8_t cell2_L;
323  uint8_t cell3_L;
324  uint8_t cell4_L;
325  uint8_t cell5_L;
326  uint8_t cell6_L;
327  uint8_t cell7_L;
328  uint8_t cell1_H; // cell voltages of higher battery
329  uint8_t cell2_H;
330  uint8_t cell3_H;
331  uint8_t cell4_H;
332  uint8_t cell5_H;
333  uint8_t cell6_H;
334  uint8_t cell7_H;
335  uword_t batt1_voltage; // battery sensor 1 voltage, in steps of 0.02V
336  uword_t batt2_voltage; // battery sensor 2 voltage, in steps of 0.02V
337  uint8_t temperature1; // temperature sensor 1. 20 = 0 degrees
338  uint8_t temperature2; // temperature sensor 2. 20 = 0 degrees
339  uword_t altitude; // altitude (meters). 500 = 0 meters
340  uword_t current; // current (A) in steps of 0.1A
341  uword_t voltage; // main power voltage in steps of 0.1V
342  uword_t capacity; // used battery capacity in steps of 10mAh
343  uword_t climbrate; // climb rate in 0.01m/s. 0m/s = 30000
344  uint8_t climbrate3s; // climb rate in m/3sec. 0m/3sec = 120
345  uword_t rpm; // rpm in steps of 10 rpm
346  uint8_t electric_min; // estaminated flight time in minutes.
347  uint8_t electric_sec; // estaminated flight time in seconds.
348  uword_t speed; // speed in km/h in steps of 1 km/h
349  uint8_t stop; // Stop byte
350  uint8_t checksum; // Lower 8-bits of all bytes summed.
351 };
352 
353 // ESC Module message structure
355  uint8_t start; // Start byte
356  uint8_t sensor_id; // EAM sensor id
357  uint8_t warning;
358  uint8_t sensor_text_id; // ESC Sensor text mode ID
359  uint8_t alarm_inverse1;
360  uint8_t alarm_inverse2;
361  uword_t batt_voltage; // battery voltage in steps of 0.1V
362  uword_t min_batt_voltage; // min battery voltage
363  uword_t batt_capacity; // used battery capacity in steps of 10mAh
364  uint8_t temperatureESC; // temperature of ESC . 20 = 0 degrees
365  uint8_t max_temperatureESC; // max temperature of ESC
366  uword_t current; // Current in steps of 0.1A
367  uword_t max_current; // maximal current
368  uword_t rpm; // rpm in steps of 10 rpm
369  uword_t max_rpm; // max rpm
370  uint8_t temperatureMOT; // motor temperature
371  uint8_t max_temperatureMOT; // maximal motor temperature
372  uint8_t dummy[19]; // 19 dummy bytes
373  uint8_t stop; // Stop byte
374  uint8_t checksum; // Lower 8-bits of all bytes summed.
375 };
376 
377 // TEXT message structure
379  uint8_t start; // Start byte
380  uint8_t sensor_id; // TEXT id
381  uint8_t warning;
382  uint8_t text[21][8]; // text field 21 columns and 8 rows (bit 7=1 for inverse display)
383  uint8_t stop; // Stop byte
384  uint8_t checksum; // Lower 8-bits of all bytes summed.
385 };
386 
387 
uint8_t text[21][8]
HomeLocationData Home
uint8_t dummy[19]
PositionActualData Position
uword_t min_batt_voltage
uint8_t flight_direction
SystemAlarmsData SysAlarms
#define statussize
uint8_t last_armed
uint8_t max_temperatureESC
HoTTSettingsData Settings
GyrosData Gyro
uint8_t min_cell_volt_num
char statusline[statussize]
GPSPositionData GPS
FlightStatusData FlightStatus
uint8_t climbrate_pointer
AttitudeActualData Attitude
BaroAltitudeData Baro
uint8_t l
int16_t climbratebuffer[climbratesize]
GPSTimeData GPStime
Includes PiOS and core architecture components.
#define climbratesize
FlightBatteryStateData Battery
uint8_t max_temperatureMOT
uint8_t h
VelocityActualData Velocity