Paparazzi UAS  v5.15_devel-132-gbbc6108
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gps_ubx.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Antoine Drouin <poinix@gmail.com>
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 
22 
23 #include "subsystems/gps/gps_ubx.h"
24 #include "subsystems/abi.h"
25 #include "led.h"
26 
27 #ifndef USE_GPS_UBX_RTCM
28 #define USE_GPS_UBX_RTCM 0
29 #endif
30 
31 
32 #if USE_GPS_UBX_RTCM
34 #define RTCM3_PREAMBLE 0xD3
35 #define RTCM3_MSG_1005 0x69
36 #define RTCM3_MSG_1077 0xB1
37 #define RTCM3_MSG_4072 0x72
38 #define RTCM3_MSG_1230 0xE6
39 #define RTCM3_MSG_1087 0xBB
40 #endif
41 
42 #if PRINT_DEBUG_GPS_UBX
43 #define DEBUG_PRINT(...) printf(__VA_ARGS__)
44 #else
45 #define DEBUG_PRINT(...) {}
46 #endif
47 
49 #include "ubx_protocol.h"
50 
51 /* parser status */
52 #define UNINIT 0
53 #define GOT_SYNC1 1
54 #define GOT_SYNC2 2
55 #define GOT_CLASS 3
56 #define GOT_ID 4
57 #define GOT_LEN1 5
58 #define GOT_LEN2 6
59 #define GOT_PAYLOAD 7
60 #define GOT_CHECKSUM1 8
61 
62 #define RXM_RTCM_VERSION 0x02
63 #define NAV_RELPOSNED_VERSION 0x00
64 /* last error type */
65 #define GPS_UBX_ERR_NONE 0
66 #define GPS_UBX_ERR_OVERRUN 1
67 #define GPS_UBX_ERR_MSG_TOO_LONG 2
68 #define GPS_UBX_ERR_CHECKSUM 3
69 #define GPS_UBX_ERR_UNEXPECTED 4
70 #define GPS_UBX_ERR_OUT_OF_SYNC 5
71 
72 #define UTM_HEM_NORTH 0
73 #define UTM_HEM_SOUTH 1
74 
75 struct GpsUbx gps_ubx;
76 
77 #if USE_GPS_UBX_RXM_RAW
78 struct GpsUbxRaw gps_ubx_raw;
79 #endif
80 
81 #if USE_GPS_UBX_RTCM
82 extern struct GpsRelposNED gps_relposned;
83 extern struct RtcmMan rtcm_man;
84 
85 #ifndef INJECT_BUFF_SIZE
86 #define INJECT_BUFF_SIZE 512
87 #endif
88 /* RTCM control struct type */
89 struct rtcm_t {
90  uint32_t nbyte;
91  uint32_t len;
92  uint8_t buff[INJECT_BUFF_SIZE+1];
93 };
94 struct rtcm_t rtcm = { 0 };
95 
96 #endif
97 
98 bool safeToInject = true;
100 
101 void gps_ubx_init(void)
102 {
104  gps_ubx.msg_available = false;
105  gps_ubx.error_cnt = 0;
107 
109 }
110 
111 void gps_ubx_event(void)
112 {
113  struct link_device *dev = &((UBX_GPS_LINK).device);
114 
115  while (dev->char_available(dev->periph)) {
116  gps_ubx_parse(dev->get_byte(dev->periph));
117  if (gps_ubx.msg_available) {
118  gps_ubx_msg();
119  }
120  }
121 }
122 
124 {
125 
126  if (gps_ubx.msg_class == UBX_NAV_ID) {
127  if (gps_ubx.msg_id == UBX_NAV_SOL_ID) {
128  /* get hardware clock ticks */
130  gps_ubx_time_sync.t0_tow = UBX_NAV_SOL_ITOW(gps_ubx.msg_buf);
131  gps_ubx_time_sync.t0_tow_frac = UBX_NAV_SOL_Frac(gps_ubx.msg_buf);
132  gps_ubx.state.tow = UBX_NAV_SOL_ITOW(gps_ubx.msg_buf);
133  gps_ubx.state.week = UBX_NAV_SOL_week(gps_ubx.msg_buf);
134 #if ! USE_GPS_UBX_RTCM
135  gps_ubx.state.fix = UBX_NAV_SOL_GPSfix(gps_ubx.msg_buf);
136 #endif
137  gps_ubx.state.ecef_pos.x = UBX_NAV_SOL_ECEF_X(gps_ubx.msg_buf);
138  gps_ubx.state.ecef_pos.y = UBX_NAV_SOL_ECEF_Y(gps_ubx.msg_buf);
139  gps_ubx.state.ecef_pos.z = UBX_NAV_SOL_ECEF_Z(gps_ubx.msg_buf);
141  gps_ubx.state.pacc = UBX_NAV_SOL_Pacc(gps_ubx.msg_buf);
142  gps_ubx.state.ecef_vel.x = UBX_NAV_SOL_ECEFVX(gps_ubx.msg_buf);
143  gps_ubx.state.ecef_vel.y = UBX_NAV_SOL_ECEFVY(gps_ubx.msg_buf);
144  gps_ubx.state.ecef_vel.z = UBX_NAV_SOL_ECEFVZ(gps_ubx.msg_buf);
146  gps_ubx.state.sacc = UBX_NAV_SOL_Sacc(gps_ubx.msg_buf);
147  gps_ubx.state.pdop = UBX_NAV_SOL_PDOP(gps_ubx.msg_buf);
148  gps_ubx.state.num_sv = UBX_NAV_SOL_numSV(gps_ubx.msg_buf);
149 #ifdef GPS_LED
150  if (gps_ubx.state.fix == GPS_FIX_3D) {
151  LED_ON(GPS_LED);
152  } else {
153  LED_TOGGLE(GPS_LED);
154  }
155 #endif
156  } else if (gps_ubx.msg_id == UBX_NAV_POSLLH_ID) {
157  gps_ubx.state.lla_pos.lat = UBX_NAV_POSLLH_LAT(gps_ubx.msg_buf);
158  gps_ubx.state.lla_pos.lon = UBX_NAV_POSLLH_LON(gps_ubx.msg_buf);
159  gps_ubx.state.lla_pos.alt = UBX_NAV_POSLLH_HEIGHT(gps_ubx.msg_buf);
160  gps_ubx.state.hacc = UBX_NAV_POSLLH_Hacc(gps_ubx.msg_buf);
161  gps_ubx.state.vacc = UBX_NAV_POSLLH_Vacc(gps_ubx.msg_buf);
163  gps_ubx.state.hmsl = UBX_NAV_POSLLH_HMSL(gps_ubx.msg_buf);
165  } else if (gps_ubx.msg_id == UBX_NAV_POSUTM_ID) {
166  gps_ubx.state.utm_pos.east = UBX_NAV_POSUTM_EAST(gps_ubx.msg_buf);
167  gps_ubx.state.utm_pos.north = UBX_NAV_POSUTM_NORTH(gps_ubx.msg_buf);
168  uint8_t hem = UBX_NAV_POSUTM_HEM(gps_ubx.msg_buf);
169  if (hem == UTM_HEM_SOUTH) {
170  gps_ubx.state.utm_pos.north -= 1000000000; /* Subtract false northing: -10000km */
171  }
172  gps_ubx.state.utm_pos.alt = UBX_NAV_POSUTM_ALT(gps_ubx.msg_buf) * 10;
173  gps_ubx.state.utm_pos.zone = UBX_NAV_POSUTM_ZONE(gps_ubx.msg_buf);
175 
178  } else if (gps_ubx.msg_id == UBX_NAV_VELNED_ID) {
179  gps_ubx.state.speed_3d = UBX_NAV_VELNED_Speed(gps_ubx.msg_buf);
180  gps_ubx.state.gspeed = UBX_NAV_VELNED_GSpeed(gps_ubx.msg_buf);
181  gps_ubx.state.ned_vel.x = UBX_NAV_VELNED_VEL_N(gps_ubx.msg_buf);
182  gps_ubx.state.ned_vel.y = UBX_NAV_VELNED_VEL_E(gps_ubx.msg_buf);
183  gps_ubx.state.ned_vel.z = UBX_NAV_VELNED_VEL_D(gps_ubx.msg_buf);
185  // Ublox gives I4 heading in 1e-5 degrees, apparenty from 0 to 360 degrees (not -180 to 180)
186  // I4 max = 2^31 = 214 * 1e5 * 100 < 360 * 1e7: overflow on angles over 214 deg -> casted to -214 deg
187  // solution: First to radians, and then scale to 1e-7 radians
188  // First x 10 for loosing less resolution, then to radians, then multiply x 10 again
189  gps_ubx.state.course = (RadOfDeg(UBX_NAV_VELNED_Heading(gps_ubx.msg_buf) * 10)) * 10;
191  gps_ubx.state.cacc = (RadOfDeg(UBX_NAV_VELNED_CAcc(gps_ubx.msg_buf) * 10)) * 10;
192  gps_ubx.state.tow = UBX_NAV_VELNED_ITOW(gps_ubx.msg_buf);
193  } else if (gps_ubx.msg_id == UBX_NAV_SVINFO_ID) {
194  gps_ubx.state.nb_channels = Min(UBX_NAV_SVINFO_NCH(gps_ubx.msg_buf), GPS_NB_CHANNELS);
195  uint8_t i;
196  for (i = 0; i < gps_ubx.state.nb_channels; i++) {
197  gps_ubx.state.svinfos[i].svid = UBX_NAV_SVINFO_SVID(gps_ubx.msg_buf, i);
198  gps_ubx.state.svinfos[i].flags = UBX_NAV_SVINFO_Flags(gps_ubx.msg_buf, i);
199  gps_ubx.state.svinfos[i].qi = UBX_NAV_SVINFO_QI(gps_ubx.msg_buf, i);
200  gps_ubx.state.svinfos[i].cno = UBX_NAV_SVINFO_CNO(gps_ubx.msg_buf, i);
201  gps_ubx.state.svinfos[i].elev = UBX_NAV_SVINFO_Elev(gps_ubx.msg_buf, i);
202  gps_ubx.state.svinfos[i].azim = UBX_NAV_SVINFO_Azim(gps_ubx.msg_buf, i);
203  }
204  } else if (gps_ubx.msg_id == UBX_NAV_STATUS_ID) {
205 #if !USE_GPS_UBX_RTCM
206  gps_ubx.state.fix = UBX_NAV_STATUS_GPSfix(gps_ubx.msg_buf);
207 #endif
208  gps_ubx.status_flags = UBX_NAV_STATUS_Flags(gps_ubx.msg_buf);
209  gps_ubx.sol_flags = UBX_NAV_SOL_Flags(gps_ubx.msg_buf);
210  } else if (gps_ubx.msg_id == UBX_NAV_RELPOSNED_ID) {
211 #if USE_GPS_UBX_RTCM
212  uint8_t version = UBX_NAV_RELPOSNED_VERSION(gps_ubx.msg_buf);
213  if (version == NAV_RELPOSNED_VERSION) {
214  gps_relposned.iTOW = UBX_NAV_RELPOSNED_ITOW(gps_ubx.msg_buf);
215  gps_relposned.refStationId = UBX_NAV_RELPOSNED_refStationId(gps_ubx.msg_buf);
216  gps_relposned.relPosN = UBX_NAV_RELPOSNED_RELPOSN(gps_ubx.msg_buf);
217  gps_relposned.relPosE = UBX_NAV_RELPOSNED_RELPOSE(gps_ubx.msg_buf);
218  gps_relposned.relPosD = UBX_NAV_RELPOSNED_RELPOSD(gps_ubx.msg_buf) ;
219  gps_relposned.relPosHPN = UBX_NAV_RELPOSNED_RELPOSNHP(gps_ubx.msg_buf);
220  gps_relposned.relPosHPE = UBX_NAV_RELPOSNED_RELPOSEHP(gps_ubx.msg_buf);
221  gps_relposned.relPosHPD = UBX_NAV_RELPOSNED_RELPOSDHP(gps_ubx.msg_buf);
222  gps_relposned.accN = UBX_NAV_RELPOSNED_Nacc(gps_ubx.msg_buf);
223  gps_relposned.accE = UBX_NAV_RELPOSNED_Eacc(gps_ubx.msg_buf);
224  gps_relposned.accD = UBX_NAV_RELPOSNED_Dacc(gps_ubx.msg_buf);
225  uint8_t flags = UBX_NAV_RELPOSNED_Flags(gps_ubx.msg_buf);
226  gps_relposned.carrSoln = RTCMgetbitu(&flags, 3, 2);
227  gps_relposned.relPosValid = RTCMgetbitu(&flags, 5, 1);
228  gps_relposned.diffSoln = RTCMgetbitu(&flags, 6, 1);
229  gps_relposned.gnssFixOK = RTCMgetbitu(&flags, 7, 1);
230  if (gps_relposned.gnssFixOK > 0) {
231  if (gps_relposned.diffSoln > 0) {
232  if (gps_relposned.carrSoln == 2) {
233  gps_ubx.state.fix = 5; // rtk
234  } else {
235  gps_ubx.state.fix = 4; // dgnss
236  }
237  } else {
238  gps_ubx.state.fix = 3; // 3D
239  }
240  } else {
241  gps_ubx.state.fix = 0;
242  }
243  DEBUG_PRINT("GNSS Fix OK: %i\tDGNSS: %i\tRTK: %i\trelPosValid: %i\trefStationId: %i\n", gps_relposned.gnssFixOK,
245  }
246 #endif // USE_GPS_UBX_RTCM
247  }
248  } else if (gps_ubx.msg_class == UBX_RXM_ID) {
249  if (gps_ubx.msg_id == UBX_RXM_RAW_ID) {
250 #if USE_GPS_UBX_RXM_RAW
251  gps_ubx_raw.iTOW = UBX_RXM_RAW_iTOW(gps_ubx.msg_buf);
252  gps_ubx_raw.week = UBX_RXM_RAW_week(gps_ubx.msg_buf);
253  gps_ubx_raw.numSV = UBX_RXM_RAW_numSV(gps_ubx.msg_buf);
254  uint8_t i;
255  uint8_t max_SV = Min(gps_ubx_raw.numSV, GPS_UBX_NB_CHANNELS);
256  for (i = 0; i < max_SV; i++) {
257  gps_ubx_raw.measures[i].cpMes = UBX_RXM_RAW_cpMes(gps_ubx.msg_buf, i);
258  gps_ubx_raw.measures[i].prMes = UBX_RXM_RAW_prMes(gps_ubx.msg_buf, i);
259  gps_ubx_raw.measures[i].doMes = UBX_RXM_RAW_doMes(gps_ubx.msg_buf, i);
260  gps_ubx_raw.measures[i].sv = UBX_RXM_RAW_sv(gps_ubx.msg_buf, i);
261  gps_ubx_raw.measures[i].mesQI = UBX_RXM_RAW_mesQI(gps_ubx.msg_buf, i);
262  gps_ubx_raw.measures[i].cno = UBX_RXM_RAW_cno(gps_ubx.msg_buf, i);
263  gps_ubx_raw.measures[i].lli = UBX_RXM_RAW_lli(gps_ubx.msg_buf, i);
264  }
265 #endif // USE_GPS_UBX_RXM_RAW
266  } else if (gps_ubx.msg_id == UBX_RXM_RTCM_ID) {
267 #if USE_GPS_UBX_RTCM
268  uint8_t version = UBX_RXM_RTCM_version(gps_ubx.msg_buf);
269  if (version == RXM_RTCM_VERSION) {
270  // uint8_t flags = UBX_RXM_RTCM_flags(gps_ubx.msg_buf);
271  // bool crcFailed = RTCMgetbitu(&flags, 7, 1);
272  // uint16_t refStation = UBX_RXM_RTCM_refStation(gps_ubx.msg_buf);
273  // uint16_t msgType = UBX_RXM_RTCM_msgType(gps_ubx.msg_buf);
274  // DEBUG_PRINT("Message %i from refStation %i processed (CRCfailed: %i)\n", msgType, refStation, crcFailed);
275 
276  rtcm_man.RefStation = UBX_RXM_RTCM_refStation(gps_ubx.msg_buf);
277  rtcm_man.MsgType = UBX_RXM_RTCM_msgType(gps_ubx.msg_buf);
278  uint8_t flags = UBX_RXM_RTCM_flags(gps_ubx.msg_buf);
279  bool crcFailed = RTCMgetbitu(&flags, 7, 1);
280  switch (rtcm_man.MsgType) {
281  case 1005:
282  rtcm_man.Cnt105 += 1;
283  rtcm_man.Crc105 += crcFailed;
284  break;
285  case 1077:
286  rtcm_man.Cnt177 += 1;
287  rtcm_man.Crc177 += crcFailed;;
288  break;
289  case 1087:
290  rtcm_man.Cnt187 += 1;
291  rtcm_man.Crc187 += crcFailed;;
292  break;
293  default:
294  break;
295  }
296  } else {
297  DEBUG_PRINT("Unknown RXM_RTCM version: %i\n", version);
298  }
299 #endif // USE_GPS_UBX_RTCM
300  }
301  }
302 }
303 
304 #if LOG_RAW_GPS
306 #endif
307 
308 /* UBX parsing */
310 {
311 #if LOG_RAW_GPS
312  sdLogWriteByte(pprzLogFile, c);
313 #endif
314  if (gps_ubx.status < GOT_PAYLOAD) {
315  gps_ubx.ck_a += c;
317  }
318  switch (gps_ubx.status) {
319  case UNINIT:
320  if (c == UBX_SYNC1) {
321  gps_ubx.status++;
322  }
323  break;
324  case GOT_SYNC1:
325  if (c != UBX_SYNC2) {
327  goto error;
328  }
329  gps_ubx.ck_a = 0;
330  gps_ubx.ck_b = 0;
331  gps_ubx.status++;
332  break;
333  case GOT_SYNC2:
334  if (gps_ubx.msg_available) {
335  /* Previous message has not yet been parsed: discard this one */
337  goto error;
338  }
339  gps_ubx.msg_class = c;
340  gps_ubx.status++;
341  break;
342  case GOT_CLASS:
343  gps_ubx.msg_id = c;
344  gps_ubx.status++;
345  break;
346  case GOT_ID:
347  gps_ubx.len = c;
348  gps_ubx.status++;
349  break;
350  case GOT_LEN1:
351  gps_ubx.len |= (c << 8);
354  goto error;
355  }
356  gps_ubx.msg_idx = 0;
357  gps_ubx.status++;
358  break;
359  case GOT_LEN2:
361  gps_ubx.msg_idx++;
362  if (gps_ubx.msg_idx >= gps_ubx.len) {
363  gps_ubx.status++;
364  }
365  break;
366  case GOT_PAYLOAD:
367  if (c != gps_ubx.ck_a) {
369  goto error;
370  }
371  gps_ubx.status++;
372  break;
373  case GOT_CHECKSUM1:
374  if (c != gps_ubx.ck_b) {
376  goto error;
377  }
378  gps_ubx.msg_available = true;
379  goto restart;
380  break;
381  default:
383  goto error;
384  }
385  return;
386 error:
387  gps_ubx.error_cnt++;
388 restart:
390  return;
391 }
392 
393 static void ubx_send_1byte(struct link_device *dev, uint8_t byte)
394 {
395  dev->put_byte(dev->periph, 0, byte);
398 }
399 
400 void ubx_header(struct link_device *dev, uint8_t nav_id, uint8_t msg_id, uint16_t len)
401 {
402  dev->put_byte(dev->periph, 0, UBX_SYNC1);
403  dev->put_byte(dev->periph, 0, UBX_SYNC2);
404  gps_ubx.send_ck_a = 0;
405  gps_ubx.send_ck_b = 0;
406  ubx_send_1byte(dev, nav_id);
407  ubx_send_1byte(dev, msg_id);
408  ubx_send_1byte(dev, (uint8_t)(len&0xFF));
409  ubx_send_1byte(dev, (uint8_t)(len>>8));
410 }
411 
412 void ubx_trailer(struct link_device *dev)
413 {
414  dev->put_byte(dev->periph, 0, gps_ubx.send_ck_a);
415  dev->put_byte(dev->periph, 0, gps_ubx.send_ck_b);
416  dev->send_message(dev->periph, 0);
417 }
418 
419 void ubx_send_bytes(struct link_device *dev, uint8_t len, uint8_t *bytes)
420 {
421  int i;
422  for (i = 0; i < len; i++) {
423  ubx_send_1byte(dev, bytes[i]);
424  }
425 }
426 
427 void ubx_send_cfg_rst(struct link_device *dev, uint16_t bbr , uint8_t reset_mode)
428 {
429 #ifdef UBX_GPS_LINK
430  UbxSend_CFG_RST(dev, bbr, reset_mode, 0x00);
431 #endif /* else less harmful for HITL */
432 }
433 
434 #ifndef GPS_UBX_UCENTER
435 #define gps_ubx_ucenter_event() {}
436 #else
438 #endif
439 
440 void gps_ubx_msg(void)
441 {
442  // current timestamp
443  uint32_t now_ts = get_sys_time_usec();
444 
449  if (gps_ubx.msg_class == UBX_NAV_ID &&
450  (gps_ubx.msg_id == UBX_NAV_VELNED_ID ||
451  (gps_ubx.msg_id == UBX_NAV_SOL_ID &&
453  if (gps_ubx.state.fix >= GPS_FIX_3D) {
456  }
457  AbiSendMsgGPS(GPS_UBX_ID, now_ts, &gps_ubx.state);
458  }
459  gps_ubx.msg_available = false;
460 }
461 
462 /*
463  * Write bytes to the ublox UART connection
464  * This is a wrapper functions used in the librtcm library
465  */
466 void gps_ublox_write(struct link_device *dev, uint8_t *buff, uint32_t n);
467 void gps_ublox_write(struct link_device *dev, uint8_t *buff, uint32_t n)
468 {
469  uint32_t i = 0;
470  for (i = 0; i < n; i++) {
471  dev->put_byte(dev->periph, 0, buff[i]);
472  }
473  dev->send_message(dev->periph, 0);
474  return;
475 }
476 
480 #if USE_GPS_UBX_RTCM
481 void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data)
482 {
483  uint8_t i;
484 
485  // nothing to do
486  if (length == 0) {
487  return;
488  }
489 
490 #ifdef GPS_UBX_UCENTER
491  // not ready
492  if (gps_ubx_ucenter_get_status() != 0) {
493  return;
494  }
495 #endif
496 
497  // go through buffer
498  for (i = 0; i < length; i++) {
499  if (rtcm.nbyte == 0) {
500  // wait for frame start byte
501  if (data[i] == RTCM3_PREAMBLE) {
502  rtcm.buff[rtcm.nbyte++] = data[i];
503  }
504  } else {
505  // fill buffer
506  if (rtcm.nbyte < INJECT_BUFF_SIZE) {
507  rtcm.buff[rtcm.nbyte++] = data[i];
508  if (rtcm.nbyte == 3) {
509  // extract length
510  rtcm.len = RTCMgetbitu(rtcm.buff, 14, 10) + 3;
511  } else {
512  // wait complete frame
513  if (rtcm.nbyte == rtcm.len + 3) {
514  // check CRC
515  unsigned int crc1 = crc24q(rtcm.buff, rtcm.len);
516  unsigned int crc2 = RTCMgetbitu(rtcm.buff, rtcm.len * 8, 24);
517 
518  if (crc1 == crc2) {
519  // write to GPS
520  gps_ublox_write(&(UBX_GPS_LINK).device, rtcm.buff, rtcm.len + 3);
521  switch (packet_id) {
522  case RTCM3_MSG_1005 : break;
523  case RTCM3_MSG_1077 : break;
524  case RTCM3_MSG_1087 : break;
525  case RTCM3_MSG_4072 : break;
526  case RTCM3_MSG_1230 : break;
527  default: DEBUG_PRINT("Unknown type: %i", packet_id); break;
528  }
529  } else {
530  DEBUG_PRINT("Skipping message %i (CRC failed) - %d", packet_id, rtcm.buff[0]);
531  unsigned int j;
532  for (j = 1; j < rtcm.len; j++) {
533  DEBUG_PRINT(",%d", rtcm.buff[j]);
534  }
535  DEBUG_PRINT("\n");
536  }
537 
538  // reset index
539  rtcm.nbyte = 0;
540  }
541  }
542  } else {
543  // reset index
544  rtcm.nbyte = 0;
545  }
546  }
547  }
548 }
549 
550 #endif
uint8_t qi
quality bitfield (GPS receiver specific)
Definition: gps.h:80
unsigned short uint16_t
Definition: types.h:16
#define GOT_CLASS
Definition: gps_ubx.c:55
int32_t z
in centimeters
unsigned int RTCMgetbitu(unsigned char *buff, int pos, int lenb)
Definition: CRC24Q.h:54
#define UTM_HEM_SOUTH
Definition: gps_ubx.c:73
uint32_t t0_tow
GPS time of week in ms from last message.
Definition: gps.h:123
int32_t north
in centimeters
struct SVinfo svinfos[GPS_NB_CHANNELS]
holds information from the Space Vehicles (Satellites)
Definition: gps.h:112
int16_t azim
azimuth in deg
Definition: gps.h:83
#define Min(x, y)
Definition: esc_dshot.c:85
#define GOT_CHECKSUM1
Definition: gps_ubx.c:60
uint32_t pacc
position accuracy in cm
Definition: gps.h:100
#define GOT_ID
Definition: gps_ubx.c:56
void ubx_trailer(struct link_device *dev)
Definition: gps_ubx.c:412
#define RXM_RTCM_VERSION
Definition: gps_ubx.c:62
void ubx_send_bytes(struct link_device *dev, uint8_t len, uint8_t *bytes)
Definition: gps_ubx.c:419
#define gps_ubx_ucenter_event()
Definition: gps_ubx.c:435
void gps_ubx_event(void)
Definition: gps_ubx.c:111
uint8_t nb_channels
Number of scanned satellites.
Definition: gps.h:111
uint32_t Cnt187
Definition: gps.h:152
uint32_t t0_ticks
hw clock ticks when GPS message is received
Definition: gps.h:125
#define GPS_VALID_VEL_NED_BIT
Definition: gps.h:52
uint8_t sol_flags
Definition: gps_ubx.h:69
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
Definition: gps.h:88
int32_t y
in centimeters
uint8_t carrSoln
Definition: gps.h:141
uint32_t hacc
horizontal accuracy in cm
Definition: gps.h:101
uint16_t week
GPS week.
Definition: gps.h:108
UBX protocol specific code.
Definition: gps_ubx.h:54
#define GPS_NB_CHANNELS
Definition: gps.h:57
#define RTCM3_MSG_1077
Definition: rtcm3.h:22
void gps_ubx_parse(uint8_t c)
Definition: gps_ubx.c:309
int32_t relPosE
Definition: gps.h:133
#define GPS_UBX_ID
Main include for ABI (AirBorneInterface).
uint32_t vacc
vertical accuracy in cm
Definition: gps.h:102
struct RtcmMan rtcm_man
Definition: gps.c:73
void gps_ubx_init(void)
Definition: gps_ubx.c:101
#define RTCM3_PREAMBLE
Definition: rtcm3.h:19
uint16_t len
Definition: gps_ubx.h:61
struct GpsUbx gps_ubx
Definition: gps_ubx.c:75
uint8_t msg_buf[GPS_UBX_MAX_PAYLOAD]
Definition: gps_ubx.h:56
int32_t east
in centimeters
int8_t relPosHPD
Definition: gps.h:137
uint8_t svid
Satellite ID.
Definition: gps.h:78
volatile uint32_t nb_tick
SYS_TIME_TICKS since startup.
Definition: sys_time.h:74
uint16_t speed_3d
norm of 3d speed in cm/s
Definition: gps.h:98
#define GPS_FIX_3D
3D GPS fix
Definition: gps.h:39
int32_t z
Down.
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over MSL)
Definition: gps.h:93
static void ubx_send_1byte(struct link_device *dev, uint8_t byte)
Definition: gps_ubx.c:393
uint8_t diffSoln
Definition: gps.h:143
uint32_t Crc187
Definition: gps.h:155
#define GPS_UBX_ERR_OUT_OF_SYNC
Definition: gps_ubx.c:70
uint8_t msg_id
Definition: gps_ubx.h:57
uint8_t error_cnt
Definition: gps_ubx.h:65
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
Definition: gps.h:114
int8_t elev
elevation in deg
Definition: gps.h:82
uint16_t msg_idx
Definition: gps_ubx.h:62
int32_t alt
in millimeters above WGS84 reference ellipsoid
#define GPS_UBX_MAX_PAYLOAD
Definition: gps_ubx.h:53
uint32_t accN
Definition: gps.h:138
uint32_t sacc
speed accuracy in cm/s
Definition: gps.h:103
struct GpsTimeSync gps_ubx_time_sync
Definition: gps_ubx.c:99
#define NAV_RELPOSNED_VERSION
Definition: gps_ubx.c:63
int32_t y
East.
#define GOT_SYNC2
Definition: gps_ubx.c:54
uint32_t last_msg_time
cpu time in sec at last received GPS message
Definition: gps.h:117
uint32_t cacc
course accuracy in rad*1e7
Definition: gps.h:104
uint8_t zone
UTM zone number.
#define GPS_VALID_COURSE_BIT
Definition: gps.h:54
Configure Ublox GPS.
#define GPS_UBX_ERR_UNEXPECTED
Definition: gps_ubx.c:69
int8_t relPosHPE
Definition: gps.h:136
uint32_t Crc105
Definition: gps.h:153
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:94
uint8_t cno
Carrier to Noise Ratio (Signal Strength) in dbHz.
Definition: gps.h:81
uint32_t tow
GPS time of week in ms.
Definition: gps.h:109
uint32_t Cnt177
Definition: gps.h:151
uint8_t ck_b
Definition: gps_ubx.h:63
unsigned int crc24q(const unsigned char *buff, int len)
Definition: CRC24Q.h:44
void gps_ublox_write(struct link_device *dev, uint8_t *buff, uint32_t n)
Definition: gps_ubx.c:467
uint16_t pdop
position dilution of precision scaled by 100
Definition: gps.h:105
uint8_t ck_a
Definition: gps_ubx.h:63
void ubx_header(struct link_device *dev, uint8_t nav_id, uint8_t msg_id, uint16_t len)
Definition: gps_ubx.c:400
#define RTCM3_MSG_1087
Definition: rtcm3.h:23
bool safeToInject
Definition: gps_ubx.c:98
int32_t x
North.
Definition: gps.h:147
unsigned long uint32_t
Definition: types.h:18
#define GPS_UBX_NB_CHANNELS
Definition: gps_ubx.h:51
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:91
void ubx_send_cfg_rst(struct link_device *dev, uint16_t bbr, uint8_t reset_mode)
Definition: gps_ubx.c:427
#define GPS_VALID_HMSL_BIT
Definition: gps.h:53
int32_t lon
in degrees*1e7
FileDes pprzLogFile
Definition: sdlog_chibios.c:85
uint32_t iTOW
Definition: gps.h:130
#define RTCM3_MSG_4072
Definition: rtcm3.h:21
#define GPS_UBX_ERR_MSG_TOO_LONG
Definition: gps_ubx.c:67
int32_t relPosD
Definition: gps.h:134
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
Definition: sys_time.h:73
#define LED_TOGGLE(i)
Definition: led_hw.h:53
#define RTCM3_MSG_1230
Definition: rtcm3.h:24
uint8_t send_ck_b
Definition: gps_ubx.h:64
int32_t relPosN
Definition: gps.h:132
bool msg_available
Definition: gps_ubx.h:55
uint8_t relPosValid
Definition: gps.h:142
uint8_t status
Definition: gps_ubx.h:60
struct GpsRelposNED gps_relposned
Definition: gps.c:72
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
void gps_ubx_read_message(void)
Definition: gps_ubx.c:123
uint8_t status_flags
Definition: gps_ubx.h:68
int gps_ubx_ucenter_get_status(void)
int8_t relPosHPN
Definition: gps.h:135
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition: gps.h:115
int32_t alt
in millimeters (above WGS84 reference ellipsoid or above MSL)
uint32_t accE
Definition: gps.h:139
#define GOT_LEN1
Definition: gps_ubx.c:57
unsigned char uint8_t
Definition: types.h:14
#define GPS_UBX_ERR_OVERRUN
Definition: gps_ubx.c:66
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:99
#define GOT_PAYLOAD
Definition: gps_ubx.c:59
uint16_t MsgType
Definition: gps.h:149
uint8_t comp_id
id of current gps
Definition: gps.h:89
#define byte
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
int32_t t0_tow_frac
fractional ns remainder of tow [ms], range -500000 .. 500000
Definition: gps.h:124
#define GPS_VALID_POS_ECEF_BIT
Definition: gps.h:48
data structures for GPS with RTK capabilities
Definition: gps.h:129
uint32_t accD
Definition: gps.h:140
struct GpsState state
Definition: gps_ubx.h:71
uint8_t flags
bitfield with GPS receiver specific flags
Definition: gps.h:79
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
Definition: gps.h:116
#define GPS_VALID_POS_LLA_BIT
Definition: gps.h:49
#define GOT_LEN2
Definition: gps_ubx.c:58
uint8_t num_sv
number of sat in fix
Definition: gps.h:106
uint8_t gnssFixOK
Definition: gps.h:144
arch independent LED (Light Emitting Diodes) API
int32_t x
in centimeters
#define UNINIT
Includes macros generated from ubx.xml.
Definition: gps_ubx.c:52
uint32_t Cnt105
Definition: gps.h:150
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:97
#define LED_ON(i)
Definition: led_hw.h:51
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:95
data structure for GPS time sync
Definition: gps.h:122
uint8_t send_ck_a
Definition: gps_ubx.h:64
#define GPS_VALID_VEL_ECEF_BIT
Definition: gps.h:51
uint32_t Crc177
Definition: gps.h:154
void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data)
Override the default GPS packet injector to inject the data trough UART.
Definition: gps_piksi.c:408
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:92
#define RTCM3_MSG_1005
Definition: rtcm3.h:20
void gps_ubx_msg(void)
Definition: gps_ubx.c:440
#define DEBUG_PRINT(...)
Definition: gps_ubx.c:45
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
int32_t lat
in degrees*1e7
uint8_t fix
status of fix
Definition: gps.h:107
uint8_t error_last
Definition: gps_ubx.h:66
#define GPS_VALID_POS_UTM_BIT
Definition: gps.h:50
#define GOT_SYNC1
Definition: gps_ubx.c:53
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:96
uint16_t RefStation
Definition: gps.h:148
#define GPS_UBX_ERR_NONE
Definition: gps_ubx.c:65
uint8_t msg_class
Definition: gps_ubx.h:58
uint8_t buff[25]
Buffer used for general comunication over SPI (in buffer)
uint16_t refStationId
Definition: gps.h:131
#define GPS_UBX_ERR_CHECKSUM
Definition: gps_ubx.c:68