887
|
1 /*
|
|
2 * GNSS.c
|
|
3 *
|
|
4 * Created on: 03.10.2020
|
|
5 * Author: SimpleMethod
|
|
6 *
|
|
7 *Copyright 2020 SimpleMethod
|
|
8 *
|
|
9 *Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
10 *this software and associated documentation files (the "Software"), to deal in
|
|
11 *the Software without restriction, including without limitation the rights to
|
|
12 *use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
13 *of the Software, and to permit persons to whom the Software is furnished to do
|
|
14 *so, subject to the following conditions:
|
|
15 *
|
|
16 *The above copyright notice and this permission notice shall be included in all
|
|
17 *copies or substantial portions of the Software.
|
|
18 *
|
|
19 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25 *THE SOFTWARE.
|
|
26 ******************************************************************************
|
|
27 */
|
|
28
|
931
|
29 #include <string.h>
|
887
|
30 #include "GNSS.h"
|
|
31
|
|
32 union u_Short uShort;
|
|
33 union i_Short iShort;
|
|
34 union u_Long uLong;
|
|
35 union i_Long iLong;
|
|
36
|
|
37 /*!
|
|
38 * Structure initialization.
|
|
39 * @param GNSS Pointer to main GNSS structure.
|
|
40 * @param huart Pointer to uart handle.
|
|
41 */
|
|
42 void GNSS_Init(GNSS_StateHandle *GNSS, UART_HandleTypeDef *huart) {
|
|
43 GNSS->huart = huart;
|
|
44 GNSS->year = 0;
|
|
45 GNSS->month = 0;
|
|
46 GNSS->day = 0;
|
|
47 GNSS->hour = 0;
|
|
48 GNSS->min = 0;
|
|
49 GNSS->sec = 0;
|
|
50 GNSS->fixType = 0;
|
|
51 GNSS->lon = 0;
|
|
52 GNSS->lat = 0;
|
|
53 GNSS->height = 0;
|
|
54 GNSS->hMSL = 0;
|
|
55 GNSS->hAcc = 0;
|
|
56 GNSS->vAcc = 0;
|
|
57 GNSS->gSpeed = 0;
|
|
58 GNSS->headMot = 0;
|
|
59 }
|
|
60
|
|
61 /*!
|
|
62 * Parse data to unique chip ID standard.
|
|
63 * Look at: 32.19.1.1 u-blox 8 Receiver description
|
|
64 * @param GNSS Pointer to main GNSS structure.
|
|
65 */
|
|
66 void GNSS_ParseUniqID(GNSS_StateHandle *GNSS) {
|
942
|
67 for (int var = 0; var < 5; var++) {
|
887
|
68 GNSS->uniqueID[var] = GNSS_Handle.uartWorkingBuffer[10 + var];
|
|
69 }
|
|
70 }
|
|
71
|
|
72 /*!
|
|
73 * Parse data to navigation position velocity time solution standard.
|
|
74 * Look at: 32.17.15.1 u-blox 8 Receiver description.
|
|
75 * @param GNSS Pointer to main GNSS structure.
|
|
76 */
|
|
77 void GNSS_ParsePVTData(GNSS_StateHandle *GNSS) {
|
919
|
78
|
|
79 static float searchCnt = 1.0;
|
|
80
|
887
|
81 uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[10];
|
|
82 GNSS->yearBytes[0]=GNSS_Handle.uartWorkingBuffer[10];
|
|
83 uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[11];
|
|
84 GNSS->yearBytes[1]=GNSS_Handle.uartWorkingBuffer[11];
|
|
85 GNSS->year = uShort.uShort;
|
|
86 GNSS->month = GNSS_Handle.uartWorkingBuffer[12];
|
|
87 GNSS->day = GNSS_Handle.uartWorkingBuffer[13];
|
|
88 GNSS->hour = GNSS_Handle.uartWorkingBuffer[14];
|
|
89 GNSS->min = GNSS_Handle.uartWorkingBuffer[15];
|
|
90 GNSS->sec = GNSS_Handle.uartWorkingBuffer[16];
|
|
91 GNSS->fixType = GNSS_Handle.uartWorkingBuffer[26];
|
|
92
|
|
93 for (int var = 0; var < 4; ++var) {
|
|
94 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 30];
|
|
95 GNSS->lonBytes[var]= GNSS_Handle.uartWorkingBuffer[var + 30];
|
|
96 }
|
|
97 GNSS->lon = iLong.iLong;
|
|
98 GNSS->fLon=(float)iLong.iLong/10000000.0;
|
|
99 for (int var = 0; var < 4; ++var) {
|
|
100 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 34];
|
|
101 GNSS->latBytes[var]=GNSS_Handle.uartWorkingBuffer[var + 34];
|
|
102 }
|
|
103 GNSS->lat = iLong.iLong;
|
|
104 GNSS->fLat=(float)iLong.iLong/10000000.0;
|
|
105 for (int var = 0; var < 4; ++var) {
|
|
106 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 38];
|
|
107 }
|
|
108 GNSS->height = iLong.iLong;
|
|
109
|
|
110 for (int var = 0; var < 4; ++var) {
|
|
111 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 42];
|
|
112 GNSS->hMSLBytes[var] = GNSS_Handle.uartWorkingBuffer[var + 42];
|
|
113 }
|
|
114 GNSS->hMSL = iLong.iLong;
|
|
115
|
|
116 for (int var = 0; var < 4; ++var) {
|
|
117 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 46];
|
|
118 }
|
|
119 GNSS->hAcc = uLong.uLong;
|
|
120
|
|
121 for (int var = 0; var < 4; ++var) {
|
|
122 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 50];
|
|
123 }
|
|
124 GNSS->vAcc = uLong.uLong;
|
|
125
|
|
126 for (int var = 0; var < 4; ++var) {
|
|
127 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 66];
|
|
128 GNSS->gSpeedBytes[var] = GNSS_Handle.uartWorkingBuffer[var + 66];
|
|
129 }
|
|
130 GNSS->gSpeed = iLong.iLong;
|
|
131
|
|
132 for (int var = 0; var < 4; ++var) {
|
|
133 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 70];
|
|
134 }
|
|
135 GNSS->headMot = iLong.iLong * 1e-5; // todo I'm not sure this good options.
|
919
|
136
|
|
137 if((GNSS->fLat == 0.0) && (GNSS->fLon == 0.0))
|
|
138 {
|
|
139 GNSS->fLat = searchCnt++;
|
|
140 }
|
940
|
141
|
|
142 GNSS->alive = !GNSS->alive;
|
887
|
143 }
|
|
144
|
|
145 /*!
|
|
146 * Parse data to UTC time solution standard.
|
|
147 * Look at: 32.17.30.1 u-blox 8 Receiver description.
|
|
148 * @param GNSS Pointer to main GNSS structure.
|
|
149 */
|
931
|
150 void GNSS_ParseNavSatData(GNSS_StateHandle *GNSS) {
|
|
151
|
|
152 uint8_t loop = 0;
|
|
153 uint8_t searchIndex = 0;
|
|
154 uint8_t statIndex = 0; /* only 4 state information will be forwarded */
|
|
155 uint8_t signalQuality = 0;
|
|
156 GNSS->numSat = GNSS_Handle.uartWorkingBuffer[11];
|
|
157
|
|
158 memset(GNSS->statSat, 0, sizeof(GNSS->statSat));
|
|
159
|
|
160 if(GNSS->numSat > 0)
|
|
161 {
|
|
162 searchIndex = 0;
|
|
163 while((searchIndex < GNSS->numSat) && (statIndex < 4)) /* get good signal quality */
|
|
164 {
|
|
165 signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
|
|
166 if(signalQuality > 4)
|
|
167 {
|
|
168 GNSS->statSat[statIndex++] = signalQuality;
|
|
169 }
|
|
170 if(statIndex == 4) break;
|
|
171 searchIndex++;
|
|
172 }
|
|
173 searchIndex = 0;
|
|
174 while((searchIndex < GNSS->numSat) && (statIndex < 4)) /* get medium signal quality */
|
|
175 {
|
|
176 signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
|
|
177 if((signalQuality > 2) && (signalQuality <= 4))
|
|
178 {
|
|
179 GNSS->statSat[statIndex++] = signalQuality;
|
|
180 }
|
|
181 if(statIndex == 4) break;
|
|
182 searchIndex++;
|
|
183 }
|
|
184 searchIndex = 0;
|
|
185 while((searchIndex < GNSS->numSat) && (statIndex < 4)) /* get poor signal quality */
|
|
186 {
|
|
187 signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
|
|
188 if(signalQuality <= 2)
|
|
189 {
|
|
190 GNSS->statSat[statIndex++] = signalQuality;
|
|
191 }
|
|
192 if(statIndex == 4) break;
|
|
193 searchIndex++;
|
|
194 }
|
|
195 loop++;
|
|
196 }
|
|
197 }
|
|
198
|
887
|
199 void GNSS_ParseNavigatorData(GNSS_StateHandle *GNSS) {
|
|
200 uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[18];
|
|
201 uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[19];
|
|
202 GNSS->year = uShort.uShort;
|
|
203 GNSS->month = GNSS_Handle.uartWorkingBuffer[20];
|
|
204 GNSS->day = GNSS_Handle.uartWorkingBuffer[21];
|
|
205 GNSS->hour = GNSS_Handle.uartWorkingBuffer[22];
|
|
206 GNSS->min = GNSS_Handle.uartWorkingBuffer[23];
|
|
207 GNSS->sec = GNSS_Handle.uartWorkingBuffer[24];
|
|
208 }
|
|
209
|
931
|
210
|
887
|
211 /*!
|
|
212 * Parse data to geodetic position solution standard.
|
|
213 * Look at: 32.17.14.1 u-blox 8 Receiver description.
|
|
214 * @param GNSS Pointer to main GNSS structure.
|
|
215 */
|
|
216 void GNSS_ParsePOSLLHData(GNSS_StateHandle *GNSS) {
|
|
217 for (int var = 0; var < 4; ++var) {
|
|
218 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 10];
|
|
219 }
|
|
220 GNSS->lon = iLong.iLong;
|
|
221 GNSS->fLon=(float)iLong.iLong/10000000.0;
|
|
222
|
|
223 for (int var = 0; var < 4; ++var) {
|
|
224 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 14];
|
|
225 }
|
|
226 GNSS->lat = iLong.iLong;
|
|
227 GNSS->fLat=(float)iLong.iLong/10000000.0;
|
|
228
|
|
229 for (int var = 0; var < 4; ++var) {
|
|
230 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 18];
|
|
231 }
|
|
232 GNSS->height = iLong.iLong;
|
|
233
|
|
234 for (int var = 0; var < 4; ++var) {
|
|
235 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 22];
|
|
236 }
|
|
237 GNSS->hMSL = iLong.iLong;
|
|
238
|
|
239 for (int var = 0; var < 4; ++var) {
|
|
240 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 26];
|
|
241 }
|
|
242 GNSS->hAcc = uLong.uLong;
|
|
243
|
|
244 for (int var = 0; var < 4; ++var) {
|
|
245 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 30];
|
|
246 }
|
|
247 GNSS->vAcc = uLong.uLong;
|
|
248 }
|