-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
booz_gps_skytraq.c
155 lines (139 loc) · 4.65 KB
/
booz_gps_skytraq.c
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
/*
* $Id$
*
* Copyright (C) 2010 Antoine Drouin <poinix@gmail.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "booz_gps.h"
struct BoozGpsSkytraq booz_gps_skytraq;
/* parser status */
#define UNINIT 0
#define GOT_SYNC1 1
#define GOT_SYNC2 2
#define GOT_LEN1 3
#define GOT_LEN2 4
#define GOT_ID 5
#define GOT_PAYLOAD 6
#define GOT_CHECKSUM 7
#define GOT_SYNC3 8
//#include "my_debug_servo.h"
#include "led.h"
void booz_gps_impl_init(void) {
booz_gps_skytraq.status = UNINIT;
//DEBUG_SERVO1_INIT();
}
void booz_gps_skytraq_read_message(void) {
//DEBUG_S1_ON();
if (booz_gps_skytraq.msg_id == SKYTRAQ_ID_NAVIGATION_DATA) {
booz_gps_state.ecef_pos.x = SKYTRAQ_NAVIGATION_DATA_ECEFX(booz_gps_skytraq.msg_buf);
booz_gps_state.ecef_pos.y = SKYTRAQ_NAVIGATION_DATA_ECEFY(booz_gps_skytraq.msg_buf);
booz_gps_state.ecef_pos.z = SKYTRAQ_NAVIGATION_DATA_ECEFZ(booz_gps_skytraq.msg_buf);
booz_gps_state.ecef_vel.x = SKYTRAQ_NAVIGATION_DATA_ECEFVX(booz_gps_skytraq.msg_buf);
booz_gps_state.ecef_vel.y = SKYTRAQ_NAVIGATION_DATA_ECEFVY(booz_gps_skytraq.msg_buf);
booz_gps_state.ecef_vel.z = SKYTRAQ_NAVIGATION_DATA_ECEFVZ(booz_gps_skytraq.msg_buf);
booz_gps_state.lla_pos.lat = SKYTRAQ_NAVIGATION_DATA_LAT(booz_gps_skytraq.msg_buf);
booz_gps_state.lla_pos.lon = SKYTRAQ_NAVIGATION_DATA_LON(booz_gps_skytraq.msg_buf);
booz_gps_state.lla_pos.alt = SKYTRAQ_NAVIGATION_DATA_AEL(booz_gps_skytraq.msg_buf);
booz_gps_state.hmsl = SKYTRAQ_NAVIGATION_DATA_ASL(booz_gps_skytraq.msg_buf);
// pacc;
// sacc;
// booz_gps_state.pdop = SKYTRAQ_NAVIGATION_DATA_PDOP(booz_gps_skytraq.msg_buf);
booz_gps_state.num_sv = SKYTRAQ_NAVIGATION_DATA_NumSV(booz_gps_skytraq.msg_buf);
booz_gps_state.fix = SKYTRAQ_NAVIGATION_DATA_FixMode(booz_gps_skytraq.msg_buf);
booz_gps_state.tow = SKYTRAQ_NAVIGATION_DATA_TOW(booz_gps_skytraq.msg_buf);
//DEBUG_S2_TOGGLE();
#ifdef GPS_LED
if (booz_gps_state.fix == BOOZ2_GPS_FIX_3D) {
LED_ON(GPS_LED);
}
else {
LED_TOGGLE(GPS_LED);
}
#endif
}
//DEBUG_S1_OFF();
}
void booz_gps_skytraq_parse(uint8_t c) {
if (booz_gps_skytraq.status < GOT_PAYLOAD)
booz_gps_skytraq.checksum ^= c;
switch (booz_gps_skytraq.status) {
case UNINIT:
if (c == SKYTRAQ_SYNC1)
booz_gps_skytraq.status = GOT_SYNC1;
break;
case GOT_SYNC1:
if (c != SKYTRAQ_SYNC2) {
booz_gps_skytraq.error_last = GPS_SKYTRAQ_ERR_OUT_OF_SYNC;
goto error;
}
booz_gps_skytraq.status = GOT_SYNC2;
break;
case GOT_SYNC2:
booz_gps_skytraq.len = c<<8;
booz_gps_skytraq.status = GOT_LEN1;
break;
case GOT_LEN1:
booz_gps_skytraq.len += c;
booz_gps_skytraq.status = GOT_LEN2;
if (booz_gps_skytraq.len > GPS_SKYTRAQ_MAX_PAYLOAD) {
booz_gps_skytraq.error_last = GPS_SKYTRAQ_ERR_MSG_TOO_LONG;
goto error;
}
break;
case GOT_LEN2:
booz_gps_skytraq.msg_id = c;
booz_gps_skytraq.msg_idx = 0;
booz_gps_skytraq.checksum = c;
booz_gps_skytraq.status = GOT_ID;
break;
case GOT_ID:
booz_gps_skytraq.msg_buf[booz_gps_skytraq.msg_idx] = c;
booz_gps_skytraq.msg_idx++;
if (booz_gps_skytraq.msg_idx >= booz_gps_skytraq.len-1) {
booz_gps_skytraq.status = GOT_PAYLOAD;
}
break;
case GOT_PAYLOAD:
if (c != booz_gps_skytraq.checksum) {
booz_gps_skytraq.error_last = GPS_SKYTRAQ_ERR_CHECKSUM;
goto error;
}
booz_gps_skytraq.status = GOT_CHECKSUM;
break;
case GOT_CHECKSUM:
if (c != SKYTRAQ_SYNC3) {
booz_gps_skytraq.error_last = GPS_SKYTRAQ_ERR_OUT_OF_SYNC;
goto error;
}
booz_gps_skytraq.status = GOT_SYNC3;
break;
case GOT_SYNC3:
booz_gps_skytraq.msg_available = TRUE;
goto restart;
default:
booz_gps_skytraq.error_last = GPS_SKYTRAQ_ERR_UNEXPECTED;
goto error;
}
return;
error:
booz_gps_skytraq.error_cnt++;
restart:
booz_gps_skytraq.status = UNINIT;
return;
}