-
Notifications
You must be signed in to change notification settings - Fork 5
/
gps.c
224 lines (200 loc) · 5.86 KB
/
gps.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <msp430.h>
#include <inttypes.h>
/*
* gps_set_gps_only
*
* tells the uBlox to only use the GPS satellites
*/
void gps_set_gps_only(void) {
int i;
char gpsonly[] = {
0xB5, 0x62, 0x06, 0x3E, 36, 0x00, /* UBX-CFG-GNSS */
0x00, 32, 32, 4, /* use 32 channels, 4 configs following */
0x00, 16, 32, 0, 0x01, 0x00, 0x00, 0x00, /* GPS enable, all channels */
0x03, 0, 0, 0, 0x00, 0x00, 0x00, 0x00, /* BeiDou disable, 0 channels */
0x05, 0, 0, 0, 0x00, 0x00, 0x00, 0x00, /* QZSS disable, 0 channels */
0x06, 0, 0, 0, 0x00, 0x00, 0x00, 0x00, /* GLONASS disable, 0 channels */
0xeb, 0x72 /* checksum */
};
for (i = 0; i < sizeof(gpsonly); i++) {
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = gpsonly[i];
}
}
/*
* gps_set_gga_only
*
* tells the GPS to only output GPGGA-messages
* by default, the uBlox outputs RMC, VTG, GGA, GSA, GSV and GLL-Messages
*
* working uBlox-M8Q
*/
void gps_set_gga_only(void) {
// default: transmits RMC, VTG, GGA, GSA, GSV, GLL
int i;
char ggaonly[] =
"$PUBX,40,RMC,0,0,0,0,0,0*47\r\n"
"$PUBX,40,VTG,0,0,0,0,0,0*5E\r\n"
"$PUBX,40,GSA,0,0,0,0,0,0*4E\r\n"
"$PUBX,40,GSV,0,0,0,0,0,0*59\r\n"
"$PUBX,40,GLL,0,0,0,0,0,0*5C\r\n";
for (i = 0; i < sizeof(ggaonly); i++) {
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = ggaonly[i];
}
}
/*
* gps_set_airborne_model
*
* tells the GPS to use the airborne positioning model. Should be used to
* get stable lock up to 50km altitude
*
* working uBlox MAX-M8Q
*
*/
void gps_set_airborne_model(void) {
int i;
char model6[] = {
0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06,
0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00,
0x05, 0x00, 0xFA, 0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC
};
for (i = 0; i < sizeof(model6); i++) {
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = model6[i];
}
}
/*
* gps_set_power_save
*
* enables cyclic tracking on the uBlox M8Q
*/
void gps_set_power_save(void) {
int i;
char powersave[] = {
0xB5, 0x62, 0x06, 0x3B, 44, 0, /* UBX-CFG-PM2 */
0x01, 0x00, 0x00, 0x00, /* v1, reserved 1..3 */
0x00, 0b00010000, 0b00000010, 0x00, /* cyclic tracking, update ephemeris */
0x10, 0x27, 0x00, 0x00, /* update period, ms */
0x10, 0x27, 0x00, 0x00, /* search period, ms */
0x00, 0x00, 0x00, 0x00, /* grid offset */
0x00, 0x00, /* on-time after first fix */
0x01, 0x00, /* minimum acquisition time */
0x00, 0x00, 0x00, 0x00, /* reserved 4,5 */
0x00, 0x00, 0x00, 0x00, /* reserved 6 */
0x00, 0x00, 0x00, 0x00, /* reserved 7 */
0x00, 0x00, 0x00, 0x00, /* reserved 8,9,10 */
0x00, 0x00, 0x00, 0x00, /* reserved 11 */
0xef, 0x29
};
for (i = 0; i < sizeof(powersave); i++) {
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = powersave[i];
}
}
/*
* gps_power_save
*
* enables or disables the power save mode (which was configured before)
*/
void gps_power_save(int on) {
int i;
char recvmgmt[] = {
0xB5, 0x62, 0x06, 0x11, 2, 0, /* UBX-CFG-RXM */
0x08, 0x01, /* reserved, enable power save mode */
0x22, 0x92
};
if (!on) {
recvmgmt[7] = 0x00; /* continuous mode */
recvmgmt[8] = 0x21; /* new checksum */
recvmgmt[9] = 0x91;
}
for (i = 0; i < sizeof(recvmgmt); i++) {
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = recvmgmt[i];
}
}
/*
* gps_set_nmea
*
* sets the GPS into compatibility mode, forcing it to output 82 chars max and using 4 decimal places.
* should go away when using the UBX-protocol for position aquisition.
*/
void gps_set_nmea(void) {
int i;
char compatibility[] = {
0xB5, 0x62, 0x06, 0x17, 20, 0x00, /* UBX-CFG-NMEA */
0x00, 0x21, 0x08, 0x05, /* no filter, NMEA v2.1, 8SV, NMEA compat & 82limit */
0x00, 0x00, 0x00, 0x00, /* no GNSS to filter */
0x00, 0x01, 0x00, 0x01, /* strict SV, main talker = GP, GSV main id, v1 */
0x00, 0x00, 0x00, 0x00, /* beidou talker default, reserved */
0x00, 0x00, 0x00, 0x00, /* reserved */
0x61, 0xc5
};
for (i = 0; i < sizeof(compatibility); i++) {
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = compatibility[i];
}
}
/*
* gps_save_settings
*
* saves the GPS settings to flash. should be done when power save is disabled and all
* settings are configured. in case of unexpected GPS reboot, it should load the correct configuration.
*/
void gps_save_settings(void) {
int i;
char cfg[] = {
0xB5, 0x62, 0x06, 0x09, 12, 0, /* UBX-CFG-CFG */
0x00, 0x00, 0x00, 0x00, /* clear no sections */
0x1f, 0x1e, 0x00, 0x00, /* save all sections */
0x00, 0x00, 0x00, 0x00, /* load no sections */
0x58, 0x59
};
for (i = 0; i < sizeof(cfg); i++) {
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = cfg[i];
}
}
#define TP_FREQ 16000000UL
void gps_enable_timepulse(void) {
int i;
char timepulse[] = {
0xB5, 0x62, 0x06, 0x31, 32, 0x00, /* UBX-CFG-TP5 */
0x00, 0x01, 0x00, 0x00, /* timepulse1, version 1, reserved1 */
0x00, 0x00, 0x00, 0x00, /* no cable delay, no RF group delay */
(uint8_t) (TP_FREQ), /* frequency setting, little endian */
(uint8_t) (TP_FREQ >> 8),
(uint8_t) (TP_FREQ >> 16),
(uint8_t) (TP_FREQ >> 24),
0x00, 0x00, 0x00, 0x00, /* same setting if lock is acquired */
0x00, 0x00, 0x00, 0x80, /* pulse width 50% */
0x00, 0x00, 0x00, 0x00, /* same setting if lock is acquired */
0x00, 0x00, 0x00, 0x00, /* no user delay */
0b00001001, 0x00, 0x00, 0x00, /* enable TP, lock to GNSS, setting is frequency */
0xf9, 0xc2 /* checksum */
};
for (i = 0; i < sizeof(timepulse); i++) {
while (!(UCA0IFG&UCTXIFG));
UCA0TXBUF = timepulse[i];
}
}
/*
* gps_startup_delay
*
* waits for the GPS to start up. this value is empirical.
* we could also wait for the startup string
*/
void gps_startup_delay(void) {
/* wait for the GPS to startup */
__delay_cycles(60000);
__delay_cycles(60000);
__delay_cycles(60000);
__delay_cycles(60000);
__delay_cycles(60000);
__delay_cycles(60000);
__delay_cycles(60000);
__delay_cycles(60000);
}