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) {
|
|
67 for (int var = 0; var < 5; ++var) {
|
|
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 }
|
887
|
141 }
|
|
142
|
|
143 /*!
|
|
144 * Parse data to UTC time solution standard.
|
|
145 * Look at: 32.17.30.1 u-blox 8 Receiver description.
|
|
146 * @param GNSS Pointer to main GNSS structure.
|
|
147 */
|
931
|
148 void GNSS_ParseNavSatData(GNSS_StateHandle *GNSS) {
|
|
149
|
|
150 uint8_t loop = 0;
|
|
151 uint8_t searchIndex = 0;
|
|
152 uint8_t statIndex = 0; /* only 4 state information will be forwarded */
|
|
153 uint8_t signalQuality = 0;
|
|
154 GNSS->numSat = GNSS_Handle.uartWorkingBuffer[11];
|
|
155
|
|
156 memset(GNSS->statSat, 0, sizeof(GNSS->statSat));
|
|
157
|
|
158 if(GNSS->numSat > 0)
|
|
159 {
|
|
160 searchIndex = 0;
|
|
161 while((searchIndex < GNSS->numSat) && (statIndex < 4)) /* get good signal quality */
|
|
162 {
|
|
163 signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
|
|
164 if(signalQuality > 4)
|
|
165 {
|
|
166 GNSS->statSat[statIndex++] = signalQuality;
|
|
167 }
|
|
168 if(statIndex == 4) break;
|
|
169 searchIndex++;
|
|
170 }
|
|
171 searchIndex = 0;
|
|
172 while((searchIndex < GNSS->numSat) && (statIndex < 4)) /* get medium signal quality */
|
|
173 {
|
|
174 signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
|
|
175 if((signalQuality > 2) && (signalQuality <= 4))
|
|
176 {
|
|
177 GNSS->statSat[statIndex++] = signalQuality;
|
|
178 }
|
|
179 if(statIndex == 4) break;
|
|
180 searchIndex++;
|
|
181 }
|
|
182 searchIndex = 0;
|
|
183 while((searchIndex < GNSS->numSat) && (statIndex < 4)) /* get poor signal quality */
|
|
184 {
|
|
185 signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
|
|
186 if(signalQuality <= 2)
|
|
187 {
|
|
188 GNSS->statSat[statIndex++] = signalQuality;
|
|
189 }
|
|
190 if(statIndex == 4) break;
|
|
191 searchIndex++;
|
|
192 }
|
|
193 loop++;
|
|
194 }
|
|
195 }
|
|
196
|
887
|
197 void GNSS_ParseNavigatorData(GNSS_StateHandle *GNSS) {
|
|
198 uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[18];
|
|
199 uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[19];
|
|
200 GNSS->year = uShort.uShort;
|
|
201 GNSS->month = GNSS_Handle.uartWorkingBuffer[20];
|
|
202 GNSS->day = GNSS_Handle.uartWorkingBuffer[21];
|
|
203 GNSS->hour = GNSS_Handle.uartWorkingBuffer[22];
|
|
204 GNSS->min = GNSS_Handle.uartWorkingBuffer[23];
|
|
205 GNSS->sec = GNSS_Handle.uartWorkingBuffer[24];
|
|
206 }
|
|
207
|
931
|
208
|
887
|
209 /*!
|
|
210 * Parse data to geodetic position solution standard.
|
|
211 * Look at: 32.17.14.1 u-blox 8 Receiver description.
|
|
212 * @param GNSS Pointer to main GNSS structure.
|
|
213 */
|
|
214 void GNSS_ParsePOSLLHData(GNSS_StateHandle *GNSS) {
|
|
215 for (int var = 0; var < 4; ++var) {
|
|
216 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 10];
|
|
217 }
|
|
218 GNSS->lon = iLong.iLong;
|
|
219 GNSS->fLon=(float)iLong.iLong/10000000.0;
|
|
220
|
|
221 for (int var = 0; var < 4; ++var) {
|
|
222 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 14];
|
|
223 }
|
|
224 GNSS->lat = iLong.iLong;
|
|
225 GNSS->fLat=(float)iLong.iLong/10000000.0;
|
|
226
|
|
227 for (int var = 0; var < 4; ++var) {
|
|
228 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 18];
|
|
229 }
|
|
230 GNSS->height = iLong.iLong;
|
|
231
|
|
232 for (int var = 0; var < 4; ++var) {
|
|
233 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 22];
|
|
234 }
|
|
235 GNSS->hMSL = iLong.iLong;
|
|
236
|
|
237 for (int var = 0; var < 4; ++var) {
|
|
238 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 26];
|
|
239 }
|
|
240 GNSS->hAcc = uLong.uLong;
|
|
241
|
|
242 for (int var = 0; var < 4; ++var) {
|
|
243 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 30];
|
|
244 }
|
|
245 GNSS->vAcc = uLong.uLong;
|
|
246 }
|