annotate Small_CPU/Src/GNSS.c @ 956:083afabc6578 Evo_2_23

Bugfix UART sensor MUX channel selection after sleep: In case only one UART sensor is connected to the MUX, to a channel other than 0 then the sensor operation could fail in case the initial mux address selection was not successfull. To fix this problem the MUX address is selected again in case a timeout occures during sensor setup.
author Ideenmodellierer
date Mon, 06 Jan 2025 17:55:34 +0100
parents 9b29995d6619
children 3420e3ba698d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
887
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
1 /*
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
2 * GNSS.c
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
3 *
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
4 * Created on: 03.10.2020
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
5 * Author: SimpleMethod
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
6 *
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
7 *Copyright 2020 SimpleMethod
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
8 *
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
9 *Permission is hereby granted, free of charge, to any person obtaining a copy of
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
10 *this software and associated documentation files (the "Software"), to deal in
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
11 *the Software without restriction, including without limitation the rights to
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
12 *use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
13 *of the Software, and to permit persons to whom the Software is furnished to do
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
14 *so, subject to the following conditions:
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
15 *
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
16 *The above copyright notice and this permission notice shall be included in all
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
17 *copies or substantial portions of the Software.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
18 *
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
19 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
20 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
21 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
22 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
23 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
24 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
25 *THE SOFTWARE.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
26 ******************************************************************************
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
27 */
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
28
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
29 #include <string.h>
887
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
30 #include "GNSS.h"
947
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
31 #include "data_exchange.h"
955
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
32 #include "rtc.h"
887
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
33
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
34 union u_Short uShort;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
35 union i_Short iShort;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
36 union u_Long uLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
37 union i_Long iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
38
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
39 /*!
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
40 * Structure initialization.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
41 * @param GNSS Pointer to main GNSS structure.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
42 * @param huart Pointer to uart handle.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
43 */
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
44 void GNSS_Init(GNSS_StateHandle *GNSS, UART_HandleTypeDef *huart) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
45 GNSS->huart = huart;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
46 GNSS->year = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
47 GNSS->month = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
48 GNSS->day = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
49 GNSS->hour = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
50 GNSS->min = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
51 GNSS->sec = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
52 GNSS->fixType = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
53 GNSS->lon = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
54 GNSS->lat = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
55 GNSS->height = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
56 GNSS->hMSL = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
57 GNSS->hAcc = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
58 GNSS->vAcc = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
59 GNSS->gSpeed = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
60 GNSS->headMot = 0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
61 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
62
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
63 /*!
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
64 * Parse data to unique chip ID standard.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
65 * Look at: 32.19.1.1 u-blox 8 Receiver description
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
66 * @param GNSS Pointer to main GNSS structure.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
67 */
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
68 void GNSS_ParseUniqID(GNSS_StateHandle *GNSS) {
942
06aaccaf2e02 Power down gnss module during dive:
Ideenmodellierer
parents: 940
diff changeset
69 for (int var = 0; var < 5; var++) {
887
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
70 GNSS->uniqueID[var] = GNSS_Handle.uartWorkingBuffer[10 + var];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
71 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
72 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
73
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
74 /*!
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
75 * Parse data to navigation position velocity time solution standard.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
76 * Look at: 32.17.15.1 u-blox 8 Receiver description.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
77 * @param GNSS Pointer to main GNSS structure.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
78 */
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
79 void GNSS_ParsePVTData(GNSS_StateHandle *GNSS) {
919
c0553dd70608 GNSS support for external UART interface:
Ideenmodellierer
parents: 899
diff changeset
80
c0553dd70608 GNSS support for external UART interface:
Ideenmodellierer
parents: 899
diff changeset
81 static float searchCnt = 1.0;
c0553dd70608 GNSS support for external UART interface:
Ideenmodellierer
parents: 899
diff changeset
82
955
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
83 RTC_TimeTypeDef sTimeNow;
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
84
887
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
85 uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[10];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
86 GNSS->yearBytes[0]=GNSS_Handle.uartWorkingBuffer[10];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
87 uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[11];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
88 GNSS->yearBytes[1]=GNSS_Handle.uartWorkingBuffer[11];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
89 GNSS->year = uShort.uShort;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
90 GNSS->month = GNSS_Handle.uartWorkingBuffer[12];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
91 GNSS->day = GNSS_Handle.uartWorkingBuffer[13];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
92 GNSS->hour = GNSS_Handle.uartWorkingBuffer[14];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
93 GNSS->min = GNSS_Handle.uartWorkingBuffer[15];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
94 GNSS->sec = GNSS_Handle.uartWorkingBuffer[16];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
95 GNSS->fixType = GNSS_Handle.uartWorkingBuffer[26];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
96
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
97 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
98 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 30];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
99 GNSS->lonBytes[var]= GNSS_Handle.uartWorkingBuffer[var + 30];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
100 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
101 GNSS->lon = iLong.iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
102 GNSS->fLon=(float)iLong.iLong/10000000.0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
103 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
104 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 34];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
105 GNSS->latBytes[var]=GNSS_Handle.uartWorkingBuffer[var + 34];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
106 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
107 GNSS->lat = iLong.iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
108 GNSS->fLat=(float)iLong.iLong/10000000.0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
109 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
110 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 38];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
111 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
112 GNSS->height = iLong.iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
113
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
114 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
115 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 42];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
116 GNSS->hMSLBytes[var] = GNSS_Handle.uartWorkingBuffer[var + 42];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
117 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
118 GNSS->hMSL = iLong.iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
119
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
120 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
121 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 46];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
122 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
123 GNSS->hAcc = uLong.uLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
124
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
125 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
126 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 50];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
127 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
128 GNSS->vAcc = uLong.uLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
129
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
130 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
131 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 66];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
132 GNSS->gSpeedBytes[var] = GNSS_Handle.uartWorkingBuffer[var + 66];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
133 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
134 GNSS->gSpeed = iLong.iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
135
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
136 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
137 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 70];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
138 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
139 GNSS->headMot = iLong.iLong * 1e-5; // todo I'm not sure this good options.
919
c0553dd70608 GNSS support for external UART interface:
Ideenmodellierer
parents: 899
diff changeset
140
c0553dd70608 GNSS support for external UART interface:
Ideenmodellierer
parents: 899
diff changeset
141 if((GNSS->fLat == 0.0) && (GNSS->fLon == 0.0))
c0553dd70608 GNSS support for external UART interface:
Ideenmodellierer
parents: 899
diff changeset
142 {
c0553dd70608 GNSS support for external UART interface:
Ideenmodellierer
parents: 899
diff changeset
143 GNSS->fLat = searchCnt++;
c0553dd70608 GNSS support for external UART interface:
Ideenmodellierer
parents: 899
diff changeset
144 }
940
4a406e873a95 GNSS improvments:
Ideenmodellierer
parents: 932
diff changeset
145
947
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
146 if(GNSS->alive & GNSS_ALIVE_STATE_ALIVE) /* alive */
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
147 {
955
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
148 GNSS->alive &= ~GNSS_ALIVE_STATE_ALIVE;
947
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
149 }
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
150 else
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
151 {
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
152 GNSS->alive |= GNSS_ALIVE_STATE_ALIVE;
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
153 }
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
154 if((GNSS_Handle.uartWorkingBuffer[17] & 0x03) == 0x03) /* date/time valid */
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
155 {
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
156 GNSS->alive |= GNSS_ALIVE_STATE_TIME;
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
157 }
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
158 else
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
159 {
955
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
160 GNSS->alive &= ~GNSS_ALIVE_STATE_TIME;
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
161 }
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
162
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
163 if(GNSS->fixType >= 2)
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
164 {
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
165 RTC_GetTime(&sTimeNow);
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
166 GNSS->alive |= GNSS_ALIVE_BACKUP_POS;
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
167 GNSS->last_fLat = GNSS->fLat;
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
168 GNSS->last_fLon = GNSS->fLon;
9b29995d6619 GNSS backup position:
Ideenmodellierer
parents: 947
diff changeset
169 GNSS->last_hour = sTimeNow.Hours;
947
96cf6c53c934 GNSS sleep mode:
Ideenmodellierer
parents: 942
diff changeset
170 }
887
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
171 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
172
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
173 /*!
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
174 * Parse data to UTC time solution standard.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
175 * Look at: 32.17.30.1 u-blox 8 Receiver description.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
176 * @param GNSS Pointer to main GNSS structure.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
177 */
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
178 void GNSS_ParseNavSatData(GNSS_StateHandle *GNSS) {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
179
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
180 uint8_t loop = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
181 uint8_t searchIndex = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
182 uint8_t statIndex = 0; /* only 4 state information will be forwarded */
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
183 uint8_t signalQuality = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
184 GNSS->numSat = GNSS_Handle.uartWorkingBuffer[11];
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
185
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
186 memset(GNSS->statSat, 0, sizeof(GNSS->statSat));
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
187
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
188 if(GNSS->numSat > 0)
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
189 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
190 searchIndex = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
191 while((searchIndex < GNSS->numSat) && (statIndex < 4)) /* get good signal quality */
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
192 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
193 signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
194 if(signalQuality > 4)
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
195 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
196 GNSS->statSat[statIndex++] = signalQuality;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
197 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
198 if(statIndex == 4) break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
199 searchIndex++;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
200 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
201 searchIndex = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
202 while((searchIndex < GNSS->numSat) && (statIndex < 4)) /* get medium signal quality */
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
203 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
204 signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
205 if((signalQuality > 2) && (signalQuality <= 4))
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
206 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
207 GNSS->statSat[statIndex++] = signalQuality;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
208 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
209 if(statIndex == 4) break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
210 searchIndex++;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
211 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
212 searchIndex = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
213 while((searchIndex < GNSS->numSat) && (statIndex < 4)) /* get poor signal quality */
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
214 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
215 signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
216 if(signalQuality <= 2)
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
217 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
218 GNSS->statSat[statIndex++] = signalQuality;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
219 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
220 if(statIndex == 4) break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
221 searchIndex++;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
222 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
223 loop++;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
224 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
225 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
226
887
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
227 void GNSS_ParseNavigatorData(GNSS_StateHandle *GNSS) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
228 uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[18];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
229 uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[19];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
230 GNSS->year = uShort.uShort;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
231 GNSS->month = GNSS_Handle.uartWorkingBuffer[20];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
232 GNSS->day = GNSS_Handle.uartWorkingBuffer[21];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
233 GNSS->hour = GNSS_Handle.uartWorkingBuffer[22];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
234 GNSS->min = GNSS_Handle.uartWorkingBuffer[23];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
235 GNSS->sec = GNSS_Handle.uartWorkingBuffer[24];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
236 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
237
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 919
diff changeset
238
887
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
239 /*!
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
240 * Parse data to geodetic position solution standard.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
241 * Look at: 32.17.14.1 u-blox 8 Receiver description.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
242 * @param GNSS Pointer to main GNSS structure.
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
243 */
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
244 void GNSS_ParsePOSLLHData(GNSS_StateHandle *GNSS) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
245 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
246 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 10];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
247 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
248 GNSS->lon = iLong.iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
249 GNSS->fLon=(float)iLong.iLong/10000000.0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
250
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
251 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
252 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 14];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
253 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
254 GNSS->lat = iLong.iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
255 GNSS->fLat=(float)iLong.iLong/10000000.0;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
256
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
257 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
258 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 18];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
259 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
260 GNSS->height = iLong.iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
261
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
262 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
263 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 22];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
264 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
265 GNSS->hMSL = iLong.iLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
266
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
267 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
268 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 26];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
269 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
270 GNSS->hAcc = uLong.uLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
271
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
272 for (int var = 0; var < 4; ++var) {
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
273 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 30];
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
274 }
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
275 GNSS->vAcc = uLong.uLong;
17f02ac9da67 adding GNSS code
heinrichsweikamp
parents:
diff changeset
276 }