Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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
56 
57 #if HOTT_SIM_GPS_SENSOR
58 bool_t HOTT_REQ_UPDATE_GPS = FALSE;
59 #endif
60 #if HOTT_SIM_EAM_SENSOR
61 bool_t HOTT_REQ_UPDATE_EAM = FALSE;
62 #endif
63 #if HOTT_SIM_VARIO_SENSOR
64 bool_t HOTT_REQ_UPDATE_VARIO = FALSE;
65 #endif
66 #if HOTT_SIM_GAM_SENSOR
67 bool_t 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 #if HOTT_SIM_EAM_SENSOR
94  hott_init_eam_msg(&hott_eam_msg);
95 #endif
96 #if HOTT_SIM_GAM_SENSOR
97  hott_init_gam_msg(&hott_gam_msg);
98 #endif
99 #if HOTT_SIM_GPS_SENSOR
100  hott_init_gps_msg(&hott_gam_msg);
101 #endif
102 #if HOTT_SIM_VARIO_SENSOR
103  hott_init_vario_msg(&hott_gam_msg);
104 #endif
105 #if HOTT_SIM_TEXTMODE
106  hott_init_text_msg(&hott_gam_msg);
107 #endif
108 }
109 
110 static void hott_enable_transmitter(void) {
111  //enables serial transmitter, disables receiver
112  uart_periph_set_mode(&HOTT_PORT, TRUE, FALSE, FALSE);
113 }
114 
115 static void hott_enable_receiver(void) {
116  //enables serial receiver, disables transmitter
117  uart_periph_set_mode(&HOTT_PORT, TRUE, TRUE, FALSE);
118 }
119 
120 void hott_init(void) {
121  hott_msgs_init();
122 }
123 
124 
125 void hott_periodic(void) {
126 #if HOTT_SIM_EAM_SENSOR
128  HOTT_REQ_UPDATE_EAM == TRUE) {
129  hott_update_eam_msg(&hott_eam_msg);
130  HOTT_REQ_UPDATE_EAM = FALSE;
131  }
132 #endif
133 #if HOTT_SIM_GAM_SENSOR
135  HOTT_REQ_UPDATE_GAM == TRUE) {
136  hott_update_gam_msg(&hott_gam_msg);
137  HOTT_REQ_UPDATE_GAM = FALSE;
138  }
139 #endif
140 #if HOTT_SIM_GPS_SENSOR
142  HOTT_REQ_UPDATE_GPS == TRUE) {
143  hott_update_gps_msg(&hott_gam_msg);
144  HOTT_REQ_UPDATE_GPS = FALSE;
145  }
146 #endif
147 #if HOTT_SIM_VARIO_SENSOR
149  HOTT_REQ_UPDATE_VARIO == TRUE) {
150  hott_update_vario_msg(&hott_gam_msg);
151  HOTT_REQ_UPDATE_VARIO = FALSE;
152  }
153 #endif
154 }
155 
156 static void hott_send_msg(int8_t *buffer, int16_t len) {
157  if (hott_telemetry_is_sending == TRUE) return;
159  hott_msg_len = len + 1; //len + 1 byte for crc
160  hott_telemetry_sendig_msgs_id = buffer[1]; //HoTT msgs id is the 2. byte
161 }
162 
163 static void hott_send_telemetry_data(void) {
164  static int16_t msg_crc = 0;
168  }
169 
170  if (hott_msg_len == 0) {
171  hott_msg_ptr = 0;
174  msg_crc = 0;
176  while(uart_char_available(&HOTT_PORT))
177  uart_getch(&HOTT_PORT);
178  }
179  else {
180  --hott_msg_len;
181  if (hott_msg_len != 0) {
182  msg_crc += *hott_msg_ptr;
183  uart_transmit(&HOTT_PORT, *hott_msg_ptr++);
184  } else
185  uart_transmit(&HOTT_PORT, (int8_t)msg_crc);
186  }
187 }
188 
189 static void hott_check_serial_data(uint32_t tnow) {
190  static uint32_t hott_serial_request_timer = 0;
191  if (hott_telemetry_is_sending == TRUE) return;
192  if (uart_char_available(&HOTT_PORT) > 1) {
193  if (uart_char_available(&HOTT_PORT) == 2) {
194  if (hott_serial_request_timer == 0) {
195  hott_serial_request_timer = tnow;
196  return;
197  } else {
198  if (tnow - hott_serial_request_timer < 4600) //wait ca. 5ms
199  return;
200  hott_serial_request_timer = 0;
201  }
202  uint8_t c = uart_getch(&HOTT_PORT);
203  uint8_t addr = uart_getch(&HOTT_PORT);
204 
205  switch(c) {
206 #if HOTT_SIM_TEXTMODE
208  //Text mode, handle only if not armed!
209  if (!autopilot_motors_on) {
210  hott_txt_msg.start_byte = 0x7b;
211  hott_txt_msg.stop_byte = 0x7d;
212  uint8_t tmp = (addr >> 4); // Sensor type
213  if (tmp == (HOTT_SIM_TEXTMODE_ADDRESS & 0x0f)) {
214  HOTT_Clear_Text_Screen();
215  HOTT_HandleTextMode(addr);
216  hott_send_text_msg();
217  }
218  }
219  break;
220 #endif
222 #if HOTT_SIM_EAM_SENSOR
223  if (addr == HOTT_TELEMETRY_EAM_SENSOR_ID) {
224  hott_send_msg((int8_t *)&hott_eam_msg, sizeof(struct HOTT_EAM_MSG));
225  HOTT_REQ_UPDATE_EAM = TRUE;
226  break;
227  }
228 #endif
229 #if HOTT_SIM_GAM_SENSOR
230  if (addr == HOTT_TELEMETRY_GAM_SENSOR_ID) {
231  hott_send_msg((int8_t *)&hott_gam_msg, sizeof(struct HOTT_GAM_MSG));
232  HOTT_REQ_UPDATE_GAM = TRUE;
233  break;
234  }
235 #endif
236 #if HOTT_SIM_GPS_SENSOR
237  if (addr == HOTT_TELEMETRY_GPS_SENSOR_ID) {
238  hott_send_msg((int8_t *)&hott_gps_msg, sizeof(struct HOTT_GPS_MSG));
239  HOTT_REQ_UPDATE_GPS = TRUE;
240  break;
241  }
242 #endif
243 #if HOTT_SIM_VARIO_SENSOR
244  if (addr == HOTT_TELEMETRY_VARIO_SENSOR_ID) {
245  hott_send_msg((int8_t *)&hott_vario_msg, sizeof(struct HOTT_VARIO_MSG));
246  HOTT_REQ_UPDATE_VARIO = TRUE;
247  break;
248  }
249 #endif
250  break; // HOTT_BINARY_MODE_REQUEST_ID:
251 
252  default:
253  break;
254  }
255  }
256  else {
257  while(uart_char_available(&HOTT_PORT))
258  uart_getch(&HOTT_PORT);
259  hott_serial_request_timer = 0;
260  }
261  }
262 }
263 
264 static void hott_periodic_event(uint32_t tnow) {
265  static uint32_t hott_serial_timer;
266 
268  if (hott_msg_ptr == 0) return;
270  if (tnow - hott_serial_timer < 3000) //delay ca. 3,5 mS. 19200 baud = 520uS / int8_t + 3ms required delay
271  return;
272  }
273  else
274  tnow = get_sys_time_usec();
276  hott_serial_timer = tnow;
277 }
278 
279 void hott_event(void) {
280  if (SysTimeTimer(hott_event_timer) > 1000) {
283  }
284 }
unsigned short uint16_t
Definition: types.h:16
static void hott_send_telemetry_data(void)
Definition: hott.c:163
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
Graupner HOTT telemetry control module.
uint8_t uart_getch(struct uart_periph *p)
Definition: uart.c:204
void hott_event(void)
Definition: hott.c:279
static void hott_enable_transmitter(void)
Definition: hott.c:110
static int16_t hott_msg_len
Definition: hott.c:73
static bool_t hott_telemetry_is_sending
Definition: hott.c:54
static uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition: uart.h:87
bool_t autopilot_motors_on
Definition: autopilot.c:54
#define HOTT_TELEMETRY_VARIO_SENSOR_ID
Definition: hott.c:51
static uint32_t hott_event_timer
Definition: hott.c:53
#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
unsigned char buffer[4096]
Definition: ahrs_ardrone2.c:47
static void hott_check_serial_data(uint32_t tnow)
Definition: hott.c:189
void uart_transmit(struct uart_periph *p, uint8_t data)
Definition: uart_arch.c:75
#define FALSE
Definition: imu_chimu.h:141
static void hott_enable_receiver(void)
Definition: hott.c:115
#define HOTT_BINARY_MODE_REQUEST_ID
Definition: hott.c:45
static void hott_update_eam_msg(struct HOTT_EAM_MSG *hott_eam_msg)
Definition: hott_eam.h:139
static int8_t * hott_msg_ptr
Definition: hott.c:71
static void hott_send_msg(int8_t *buffer, int16_t len)
Definition: hott.c:156
Architecture independent timing functions.
unsigned long uint32_t
Definition: types.h:18
signed short int16_t
Definition: types.h:17
void uart_periph_set_mode(struct uart_periph *p, bool_t tx_enabled, bool_t rx_enabled, bool_t hw_flow_control)
Definition: uart_arch.c:88
#define SysTimeTimer(_t)
Definition: sys_time.h:199
#define TRUE
Definition: imu_chimu.h:144
#define HOTT_TELEMETRY_EAM_SENSOR_ID
Definition: hott_eam.h:36
unsigned char uint8_t
Definition: types.h:14
Graupner HOTT electric air module description.
static uint16_t hott_telemetry_sendig_msgs_id
Definition: hott.c:55
#define HOTT_TELEMETRY_GPS_SENSOR_ID
Definition: hott.c:49
void hott_init(void)
Definition: hott.c:120
void hott_periodic(void)
Definition: hott.c:125
#define SysTimeTimerStart(_t)
Definition: sys_time.h:198
signed char int8_t
Definition: types.h:15
static void hott_msgs_init(void)
Initializes a HoTT GPS message (Receiver answer type !Not Smartbox)
Definition: hott.c:91
static uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.h:67
#define HOTT_TEXT_MODE_REQUEST_ID
Definition: hott.c:44
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:133
static void hott_periodic_event(uint32_t tnow)
Definition: hott.c:264