Paparazzi UAS  v5.15_devel-81-gd13dafb
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
hott.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Sergey Krukowski <softsr@yahoo.de>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #include "hott/hott.h"
28 #if HOTT_SIM_GAM_SENSOR
29 #include "hott/hott_gam.h"
30 #endif
31 #if HOTT_SIM_EAM_SENSOR
32 #include "hott/hott_eam.h"
33 #endif
34 #if HOTT_SIM_GPS_SENSOR
35 #include "hott/hott_gps.h"
36 #endif
37 #if HOTT_SIM_VARIO_SENSOR
38 #include "hott/hott_vario.h"
39 #endif
40 
41 #include "mcu_periph/sys_time.h"
42 #include "mcu_periph/uart.h"
43 
44 #define HOTT_TEXT_MODE_REQUEST_ID 0x7f
45 #define HOTT_BINARY_MODE_REQUEST_ID 0x80
46 //Sensor Ids
47 
48 //Graupner #33600 GPS Module
49 #define HOTT_TELEMETRY_GPS_SENSOR_ID 0x8A
50 //Graupner #33601 Vario Module
51 #define HOTT_TELEMETRY_VARIO_SENSOR_ID 0x89
52 
53 static uint32_t hott_event_timer; // 1ms software timer
54 static bool hott_telemetry_is_sending = false;
56 
57 #if HOTT_SIM_GPS_SENSOR
58 bool HOTT_REQ_UPDATE_GPS = false;
59 #endif
60 #if HOTT_SIM_EAM_SENSOR
61 bool HOTT_REQ_UPDATE_EAM = false;
62 #endif
63 #if HOTT_SIM_VARIO_SENSOR
64 bool HOTT_REQ_UPDATE_VARIO = false;
65 #endif
66 #if HOTT_SIM_GAM_SENSOR
67 bool HOTT_REQ_UPDATE_GAM = false;
68 #endif
69 
70 // HoTT serial send buffer pointer
71 static int8_t *hott_msg_ptr = 0;
72 // Len of HoTT serial buffer
73 static int16_t hott_msg_len = 0;
74 
75 #if HOTT_SIM_GAM_SENSOR
76 static struct HOTT_GAM_MSG hott_gam_msg;
77 #endif
78 #if HOTT_SIM_EAM_SENSOR
79 static struct HOTT_EAM_MSG hott_eam_msg;
80 #endif
81 #if HOTT_SIM_GPS_SENSOR
82 static struct HOTT_GPS_MSG hott_gps_msg;
83 #endif
84 #if HOTT_SIM_VARIO_SENSOR
85 static struct HOTT_VARIO_MSG hott_vario_msg;
86 #endif
87 
91 static void hott_msgs_init(void)
92 {
93 
94 #if HOTT_SIM_EAM_SENSOR
95  hott_init_eam_msg(&hott_eam_msg);
96 #endif
97 #if HOTT_SIM_GAM_SENSOR
98  hott_init_gam_msg(&hott_gam_msg);
99 #endif
100 #if HOTT_SIM_GPS_SENSOR
101  hott_init_gps_msg(&hott_gam_msg);
102 #endif
103 #if HOTT_SIM_VARIO_SENSOR
104  hott_init_vario_msg(&hott_gam_msg);
105 #endif
106 #if HOTT_SIM_TEXTMODE
107  hott_init_text_msg(&hott_gam_msg);
108 #endif
109 }
110 
111 static void hott_enable_transmitter(void)
112 {
113  //enables serial transmitter, disables receiver
114  uart_periph_set_mode(&HOTT_PORT, TRUE, FALSE, FALSE);
115 }
116 
117 static void hott_enable_receiver(void)
118 {
119  //enables serial receiver, disables transmitter
120  uart_periph_set_mode(&HOTT_PORT, TRUE, TRUE, FALSE);
121 }
122 
123 void hott_init(void)
124 {
125  hott_msgs_init();
126 }
127 
128 
129 void hott_periodic(void)
130 {
131 #if HOTT_SIM_EAM_SENSOR
133  HOTT_REQ_UPDATE_EAM == TRUE) {
134  hott_update_eam_msg(&hott_eam_msg);
135  HOTT_REQ_UPDATE_EAM = false;
136  }
137 #endif
138 #if HOTT_SIM_GAM_SENSOR
140  HOTT_REQ_UPDATE_GAM == TRUE) {
141  hott_update_gam_msg(&hott_gam_msg);
142  HOTT_REQ_UPDATE_GAM = false;
143  }
144 #endif
145 #if HOTT_SIM_GPS_SENSOR
147  HOTT_REQ_UPDATE_GPS == TRUE) {
148  hott_update_gps_msg(&hott_gam_msg);
149  HOTT_REQ_UPDATE_GPS = false;
150  }
151 #endif
152 #if HOTT_SIM_VARIO_SENSOR
154  HOTT_REQ_UPDATE_VARIO == TRUE) {
155  hott_update_vario_msg(&hott_gam_msg);
156  HOTT_REQ_UPDATE_VARIO = false;
157  }
158 #endif
159 }
160 
161 static void hott_send_msg(int8_t *buffer, int16_t len)
162 {
163  if (hott_telemetry_is_sending == TRUE) { return; }
164  hott_msg_ptr = buffer;
165  hott_msg_len = len + 1; //len + 1 byte for crc
166  hott_telemetry_sendig_msgs_id = buffer[1]; //HoTT msgs id is the 2. byte
167 }
168 
169 static void hott_send_telemetry_data(void)
170 {
171  static int16_t msg_crc = 0;
175  }
176 
177  if (hott_msg_len == 0) {
178  hott_msg_ptr = 0;
181  msg_crc = 0;
183  while (uart_char_available(&HOTT_PORT)) {
184  uart_getch(&HOTT_PORT);
185  }
186  } else {
187  --hott_msg_len;
188  if (hott_msg_len != 0) {
189  msg_crc += *hott_msg_ptr;
190  uart_put_byte(&HOTT_PORT, 0, *hott_msg_ptr++);
191  } else {
192  uart_put_byte(&HOTT_PORT, 0, (int8_t)msg_crc);
193  }
194  }
195 }
196 
198 {
199  static uint32_t hott_serial_request_timer = 0;
200  if (hott_telemetry_is_sending == TRUE) { return; }
201  if (uart_char_available(&HOTT_PORT) > 1) {
202  if (uart_char_available(&HOTT_PORT) == 2) {
203  if (hott_serial_request_timer == 0) {
204  hott_serial_request_timer = tnow;
205  return;
206  } else {
207  if (tnow - hott_serial_request_timer < 4600) { //wait ca. 5ms
208  return;
209  }
210  hott_serial_request_timer = 0;
211  }
212  uint8_t c = uart_getch(&HOTT_PORT);
213  uint8_t addr = uart_getch(&HOTT_PORT);
214 
215  switch (c) {
216 #if HOTT_SIM_TEXTMODE
218  //Text mode, handle only if not armed!
219  if (!autopilot_get_motors_on()) {
220  hott_txt_msg.start_byte = 0x7b;
221  hott_txt_msg.stop_byte = 0x7d;
222  uint8_t tmp = (addr >> 4); // Sensor type
223  if (tmp == (HOTT_SIM_TEXTMODE_ADDRESS & 0x0f)) {
224  HOTT_Clear_Text_Screen();
225  HOTT_HandleTextMode(addr);
226  hott_send_text_msg();
227  }
228  }
229  break;
230 #endif
232 #if HOTT_SIM_EAM_SENSOR
233  if (addr == HOTT_TELEMETRY_EAM_SENSOR_ID) {
234  hott_send_msg((int8_t *)&hott_eam_msg, sizeof(struct HOTT_EAM_MSG));
235  HOTT_REQ_UPDATE_EAM = true;
236  break;
237  }
238 #endif
239 #if HOTT_SIM_GAM_SENSOR
240  if (addr == HOTT_TELEMETRY_GAM_SENSOR_ID) {
241  hott_send_msg((int8_t *)&hott_gam_msg, sizeof(struct HOTT_GAM_MSG));
242  HOTT_REQ_UPDATE_GAM = true;
243  break;
244  }
245 #endif
246 #if HOTT_SIM_GPS_SENSOR
247  if (addr == HOTT_TELEMETRY_GPS_SENSOR_ID) {
248  hott_send_msg((int8_t *)&hott_gps_msg, sizeof(struct HOTT_GPS_MSG));
249  HOTT_REQ_UPDATE_GPS = true;
250  break;
251  }
252 #endif
253 #if HOTT_SIM_VARIO_SENSOR
254  if (addr == HOTT_TELEMETRY_VARIO_SENSOR_ID) {
255  hott_send_msg((int8_t *)&hott_vario_msg, sizeof(struct HOTT_VARIO_MSG));
256  HOTT_REQ_UPDATE_VARIO = true;
257  break;
258  }
259 #endif
260  break; // HOTT_BINARY_MODE_REQUEST_ID:
261 
262  default:
263  break;
264  }
265  } else {
266  while (uart_char_available(&HOTT_PORT)) {
267  uart_getch(&HOTT_PORT);
268  }
269  hott_serial_request_timer = 0;
270  }
271  }
272 }
273 
274 static void hott_periodic_event(uint32_t tnow)
275 {
276  static uint32_t hott_serial_timer;
277 
279  if (hott_msg_ptr == 0) { return; }
281  if (tnow - hott_serial_timer < 3000) { //delay ca. 3,5 mS. 19200 baud = 520uS / int8_t + 3ms required delay
282  return;
283  }
284  } else {
285  tnow = get_sys_time_usec();
286  }
288  hott_serial_timer = tnow;
289 }
290 
291 void hott_event(void)
292 {
293  if (SysTimeTimer(hott_event_timer) > 1000) {
296  }
297 }
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint8_t uart_getch(struct uart_periph *p)
Definition: uart_arch.c:845
bool autopilot_get_motors_on(void)
get motors status
Definition: autopilot.c:212
static void hott_msgs_init(void)
Initializes a HoTT GPS message (Receiver answer type !Not Smartbox)
Definition: hott.c:91
uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart_arch.c:323
static void hott_periodic_event(uint32_t tnow)
Definition: hott.c:274
static void hott_check_serial_data(uint32_t tnow)
Definition: hott.c:197
#define HOTT_TELEMETRY_GAM_SENSOR_ID
Definition: hott_gam.h:33
static void hott_init_gam_msg(struct HOTT_GAM_MSG *hott_gam_msg)
Definition: hott_gam.h:125
#define HOTT_TEXT_MODE_REQUEST_ID
Definition: hott.c:44
void uart_periph_set_mode(struct uart_periph *p, bool tx_enabled, bool rx_enabled, bool hw_flow_control)
Set mode (not necessary, or can be set by SerialConfig)
Definition: uart_arch.c:876
#define FALSE
Definition: std.h:5
#define TRUE
Definition: std.h:4
static void hott_update_eam_msg(struct HOTT_EAM_MSG *hott_eam_msg)
Definition: hott_eam.h:140
static int16_t hott_msg_len
Definition: hott.c:73
void hott_event(void)
Definition: hott.c:291
void hott_init(void)
Definition: hott.c:123
Architecture independent timing functions.
unsigned long uint32_t
Definition: types.h:18
static bool hott_telemetry_is_sending
Definition: hott.c:54
signed short int16_t
Definition: types.h:17
void hott_periodic(void)
Definition: hott.c:129
static void hott_send_telemetry_data(void)
Definition: hott.c:169
static void hott_enable_transmitter(void)
Definition: hott.c:111
#define HOTT_BINARY_MODE_REQUEST_ID
Definition: hott.c:45
#define SysTimeTimer(_t)
Definition: sys_time.h:219
static void hott_enable_receiver(void)
Definition: hott.c:117
void uart_put_byte(struct uart_periph *p, long fd, uint8_t data)
Uart transmit implementation.
Definition: uart_arch.c:972
#define HOTT_TELEMETRY_EAM_SENSOR_ID
Definition: hott_eam.h:36
static uint32_t hott_event_timer
Definition: hott.c:53
#define HOTT_TELEMETRY_VARIO_SENSOR_ID
Definition: hott.c:51
unsigned char uint8_t
Definition: types.h:14
Graupner HOTT electric air module description.
static void hott_send_msg(int8_t *buffer, int16_t len)
Definition: hott.c:161
static int8_t * hott_msg_ptr
Definition: hott.c:71
#define HOTT_TELEMETRY_GPS_SENSOR_ID
Definition: hott.c:49
#define SysTimeTimerStart(_t)
Definition: sys_time.h:218
signed char int8_t
Definition: types.h:15
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
static void hott_init_eam_msg(struct HOTT_EAM_MSG *hott_eam_msg)
Definition: hott_eam.h:131
static void hott_update_gam_msg(struct HOTT_GAM_MSG *hott_gam_msg)
Definition: hott_gam.h:134
static uint16_t hott_telemetry_sendig_msgs_id
Definition: hott.c:55