Subversion Repositories FlightCtrl

Rev

Rev 1179 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1179 Rev 1180
-
 
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
2
// + Copyright (c) 04.2007 Holger Buss
-
 
3
// + Nur für den privaten Gebrauch
-
 
4
// + www.MikroKopter.com
-
 
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
-
 
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
-
 
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
-
 
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
-
 
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
-
 
11
// + Verkauf von Luftbildaufnahmen, usw.
-
 
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
-
 
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
-
 
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
-
 
17
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
-
 
18
// + eindeutig als Ursprung verlinkt werden
-
 
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
-
 
21
// + Benutzung auf eigene Gefahr
-
 
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
-
 
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
-
 
25
// + mit unserer Zustimmung zulässig
-
 
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
-
 
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
-
 
30
// + this list of conditions and the following disclaimer.
-
 
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
-
 
32
// +     from this software without specific prior written permission.
-
 
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
-
 
34
// +     for non-commercial use (directly or indirectly)
-
 
35
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
-
 
36
// +     with our written permission
-
 
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
-
 
38
// +     clearly linked as origin
-
 
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
-
 
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-
 
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-
 
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-
 
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-
 
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-
 
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-
 
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-
 
48
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-
 
49
// +  POSSIBILITY OF SUCH DAMAGE.
-
 
50
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
#include <inttypes.h>
51
#include <inttypes.h>
2
#include "ubx.h"
52
#include "ubx.h"
3
#include "main.h"
53
#include "main.h"
4
#include <avr/io.h>
54
#include <avr/io.h>
5
 
55
 
6
#include "uart.h"
56
//#include "uart0.h"
7
 
57
 
8
// ubx protocol parser state machine
58
// ubx protocol parser state machine
9
#define UBXSTATE_IDLE   0
59
#define UBXSTATE_IDLE   0
10
#define UBXSTATE_SYNC1  1
60
#define UBXSTATE_SYNC1  1
11
#define UBXSTATE_SYNC2  2
61
#define UBXSTATE_SYNC2  2
12
#define UBXSTATE_CLASS  3
62
#define UBXSTATE_CLASS  3
13
#define UBXSTATE_LEN1   4
63
#define UBXSTATE_LEN1   4
14
#define UBXSTATE_LEN2   5
64
#define UBXSTATE_LEN2   5
15
#define UBXSTATE_DATA   6
65
#define UBXSTATE_DATA   6
16
#define UBXSTATE_CKA    7
66
#define UBXSTATE_CKA    7
17
#define UBXSTATE_CKB    8
67
#define UBXSTATE_CKB    8
18
 
68
 
19
// ublox protocoll identifier
69
// ublox protocoll identifier
20
#define UBX_CLASS_NAV   0x01
70
#define UBX_CLASS_NAV   0x01
21
 
71
 
22
#define UBX_ID_POSLLH   0x02
72
#define UBX_ID_POSLLH   0x02
23
#define UBX_ID_SOL              0x06
73
#define UBX_ID_SOL              0x06
24
#define UBX_ID_VELNED   0x12
74
#define UBX_ID_VELNED   0x12
25
 
75
 
26
#define UBX_SYNC1_CHAR  0xB5
76
#define UBX_SYNC1_CHAR  0xB5
27
#define UBX_SYNC2_CHAR  0x62
77
#define UBX_SYNC2_CHAR  0x62
28
 
78
 
29
typedef struct {
79
typedef struct {
30
        uint32_t                ITOW;           // ms GPS Millisecond Time of Week
80
        uint32_t                ITOW;           // ms GPS Millisecond Time of Week
31
        int32_t                 Frac;           // ns remainder of rounded ms above
81
        int32_t                 Frac;           // ns remainder of rounded ms above
32
        int16_t                 week;           // GPS week
82
        int16_t                 week;           // GPS week
33
        uint8_t                 GPSfix;         // GPSfix Type, range 0..6
83
        uint8_t                 GPSfix;         // GPSfix Type, range 0..6
34
        uint8_t                 Flags;          // Navigation Status Flags
84
        uint8_t                 Flags;          // Navigation Status Flags
35
        int32_t                 ECEF_X;         // cm ECEF X coordinate
85
        int32_t                 ECEF_X;         // cm ECEF X coordinate
36
        int32_t                 ECEF_Y;         // cm ECEF Y coordinate
86
        int32_t                 ECEF_Y;         // cm ECEF Y coordinate
37
        int32_t                 ECEF_Z;         // cm ECEF Z coordinate
87
        int32_t                 ECEF_Z;         // cm ECEF Z coordinate
38
        uint32_t                PAcc;           // cm 3D Position Accuracy Estimate
88
        uint32_t                PAcc;           // cm 3D Position Accuracy Estimate
39
        int32_t                 ECEFVX;         // cm/s ECEF X velocity
89
        int32_t                 ECEFVX;         // cm/s ECEF X velocity
40
        int32_t                 ECEFVY;         // cm/s ECEF Y velocity
90
        int32_t                 ECEFVY;         // cm/s ECEF Y velocity
41
        int32_t                 ECEFVZ;         // cm/s ECEF Z velocity
91
        int32_t                 ECEFVZ;         // cm/s ECEF Z velocity
42
        uint32_t                SAcc;           // cm/s Speed Accuracy Estimate
92
        uint32_t                SAcc;           // cm/s Speed Accuracy Estimate
43
        uint16_t                PDOP;           // 0.01 Position DOP
93
        uint16_t                PDOP;           // 0.01 Position DOP
44
        uint8_t                 res1;           // reserved
94
        uint8_t                 res1;           // reserved
45
        uint8_t                 numSV;          // Number of SVs used in navigation solution
95
        uint8_t                 numSV;          // Number of SVs used in navigation solution
46
        uint32_t                res2;           // reserved
96
        uint32_t                res2;           // reserved
47
        Status_t                Status;
97
        Status_t                Status;
48
} UBX_SOL_t;
98
} UBX_SOL_t;
49
 
99
 
50
typedef struct {
100
typedef struct {
51
        uint32_t                ITOW;           // ms GPS Millisecond Time of Week
101
        uint32_t                ITOW;           // ms GPS Millisecond Time of Week
52
        int32_t                 LON;            // 1e-07 deg Longitude
102
        int32_t                 LON;            // 1e-07 deg Longitude
53
        int32_t                 LAT;            // 1e-07 deg Latitude
103
        int32_t                 LAT;            // 1e-07 deg Latitude
54
        int32_t                 HEIGHT;         // mm Height above Ellipsoid
104
        int32_t                 HEIGHT;         // mm Height above Ellipsoid
55
        int32_t                 HMSL;           // mm Height above mean sea level
105
        int32_t                 HMSL;           // mm Height above mean sea level
56
        uint32_t                Hacc;           // mm Horizontal Accuracy Estimate
106
        uint32_t                Hacc;           // mm Horizontal Accuracy Estimate
57
        uint32_t                Vacc;           // mm Vertical Accuracy Estimate
107
        uint32_t                Vacc;           // mm Vertical Accuracy Estimate
58
        Status_t                Status;
108
        Status_t                Status;
59
} UBX_POSLLH_t;
109
} UBX_POSLLH_t;
60
 
110
 
61
typedef struct {
111
typedef struct {
62
        uint32_t                ITOW;           // ms  GPS Millisecond Time of Week
112
        uint32_t                ITOW;           // ms  GPS Millisecond Time of Week
63
        int32_t                 VEL_N;          // cm/s  NED north velocity
113
        int32_t                 VEL_N;          // cm/s  NED north velocity
64
        int32_t                 VEL_E;          // cm/s  NED east velocity
114
        int32_t                 VEL_E;          // cm/s  NED east velocity
65
        int32_t                 VEL_D;          // cm/s  NED down velocity
115
        int32_t                 VEL_D;          // cm/s  NED down velocity
66
        uint32_t                Speed;          // cm/s  Speed (3-D)
116
        uint32_t                Speed;          // cm/s  Speed (3-D)
67
        uint32_t                GSpeed;         // cm/s  Ground Speed (2-D)
117
        uint32_t                GSpeed;         // cm/s  Ground Speed (2-D)
68
        int32_t                 Heading;        // 1e-05 deg  Heading 2-D
118
        int32_t                 Heading;        // 1e-05 deg  Heading 2-D
69
        uint32_t                SAcc;           // cm/s  Speed Accuracy Estimate
119
        uint32_t                SAcc;           // cm/s  Speed Accuracy Estimate
70
        uint32_t                CAcc;           // deg  Course / Heading Accuracy Estimate
120
        uint32_t                CAcc;           // deg  Course / Heading Accuracy Estimate
71
        Status_t                Status;
121
        Status_t                Status;
72
} UBX_VELNED_t;
122
} UBX_VELNED_t;
73
 
123
 
74
UBX_SOL_t               UbxSol    = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, INVALID};
124
UBX_SOL_t               UbxSol    = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, INVALID};
75
UBX_POSLLH_t    UbxPosLlh = {0,0,0,0,0,0,0, INVALID};
125
UBX_POSLLH_t    UbxPosLlh = {0,0,0,0,0,0,0, INVALID};
76
UBX_VELNED_t    UbxVelNed = {0,0,0,0,0,0,0,0,0, INVALID};
126
UBX_VELNED_t    UbxVelNed = {0,0,0,0,0,0,0,0,0, INVALID};
77
GPS_INFO_t      GPSInfo   = {0,0,0,0,0,0,0,0,0,0, INVALID};
127
GPS_INFO_t      GPSInfo   = {0,0,0,0,0,0,0,0,0,0, INVALID};
78
 
128
 
79
volatile uint8_t GPSTimeout = 0;
129
volatile uint8_t GPSTimeout = 0;
80
 
130
 
81
void UpdateGPSInfo (void)
131
void UpdateGPSInfo (void)
82
{
132
{
83
 
133
 
84
        if ((UbxSol.Status == NEWDATA) && (UbxPosLlh.Status == NEWDATA) && (UbxVelNed.Status == NEWDATA))
134
        if ((UbxSol.Status == NEWDATA) && (UbxPosLlh.Status == NEWDATA) && (UbxVelNed.Status == NEWDATA))
85
        {
135
        {
86
                RED_FLASH;
136
                RED_FLASH;
87
                if(GPSInfo.status != NEWDATA)
137
                if(GPSInfo.status != NEWDATA)
88
                {
138
                {
89
                        GPSInfo.status = INVALID;
139
                        GPSInfo.status = INVALID;
90
                        // NAV SOL
140
                        // NAV SOL
91
                        GPSInfo.flags = UbxSol.Flags;
141
                        GPSInfo.flags = UbxSol.Flags;
92
                        GPSInfo.satfix = UbxSol.GPSfix;
142
                        GPSInfo.satfix = UbxSol.GPSfix;
93
                        GPSInfo.satnum = UbxSol.numSV;
143
                        GPSInfo.satnum = UbxSol.numSV;
94
                        GPSInfo.PAcc = UbxSol.PAcc;
144
                        GPSInfo.PAcc = UbxSol.PAcc;
95
                        GPSInfo.VAcc = UbxSol.SAcc;
145
                        GPSInfo.VAcc = UbxSol.SAcc;
96
                        // NAV POSLLH
146
                        // NAV POSLLH
97
                        GPSInfo.longitude = UbxPosLlh.LON;
147
                        GPSInfo.longitude = UbxPosLlh.LON;
98
                        GPSInfo.latitude = UbxPosLlh.LAT;
148
                        GPSInfo.latitude = UbxPosLlh.LAT;
99
                        GPSInfo.altitude = UbxPosLlh.HEIGHT;
149
                        GPSInfo.altitude = UbxPosLlh.HEIGHT;
100
 
150
 
101
                        GPSInfo.veleast = UbxVelNed.VEL_E;
151
                        GPSInfo.veleast = UbxVelNed.VEL_E;
102
                        GPSInfo.velnorth = UbxVelNed.VEL_N;
152
                        GPSInfo.velnorth = UbxVelNed.VEL_N;
103
                        GPSInfo.veltop = -UbxVelNed.VEL_D;
153
                        GPSInfo.veltop = -UbxVelNed.VEL_D;
104
                        GPSInfo.velground = UbxVelNed.GSpeed;
154
                        GPSInfo.velground = UbxVelNed.GSpeed;
105
 
155
 
106
                        GPSInfo.status = NEWDATA;
156
                        GPSInfo.status = NEWDATA;
107
 
157
 
108
                }
158
                }
109
                // set state to collect new data
159
                // set state to collect new data
110
                UbxSol.Status = PROCESSED;                      // never update old data
160
                UbxSol.Status = PROCESSED;                      // never update old data
111
                UbxPosLlh.Status = PROCESSED;           // never update old data
161
                UbxPosLlh.Status = PROCESSED;           // never update old data
112
                UbxVelNed.Status = PROCESSED;           // never update old data
162
                UbxVelNed.Status = PROCESSED;           // never update old data
113
        }
163
        }
114
 
164
 
115
 
165
 
116
}
166
}
117
 
167
 
118
 
168
 
119
// this function should be called within the UART RX ISR
169
// this function should be called within the UART RX ISR
120
void ubx_parser(uint8_t c)
170
void ubx_parser(uint8_t c)
121
{
171
{
122
        static uint8_t ubxstate = UBXSTATE_IDLE;
172
        static uint8_t ubxstate = UBXSTATE_IDLE;
123
        static uint8_t cka, ckb;
173
        static uint8_t cka, ckb;
124
        static uint16_t msglen;
174
        static uint16_t msglen;
125
        static int8_t *ubxP, *ubxEp, *ubxSp; // pointers to data currently transfered
175
        static int8_t *ubxP, *ubxEp, *ubxSp; // pointers to data currently transfered
126
 
176
 
127
        switch(ubxstate)
177
        switch(ubxstate)
128
        {
178
        {
129
                case UBXSTATE_IDLE: // check 1st sync byte
179
                case UBXSTATE_IDLE: // check 1st sync byte
130
                        if (c == UBX_SYNC1_CHAR) ubxstate = UBXSTATE_SYNC1;
180
                        if (c == UBX_SYNC1_CHAR) ubxstate = UBXSTATE_SYNC1;
131
                        else ubxstate = UBXSTATE_IDLE; // out of synchronization
181
                        else ubxstate = UBXSTATE_IDLE; // out of synchronization
132
                        break;
182
                        break;
133
 
183
 
134
                case UBXSTATE_SYNC1: // check 2nd sync byte
184
                case UBXSTATE_SYNC1: // check 2nd sync byte
135
                        if (c == UBX_SYNC2_CHAR) ubxstate = UBXSTATE_SYNC2;
185
                        if (c == UBX_SYNC2_CHAR) ubxstate = UBXSTATE_SYNC2;
136
                        else ubxstate = UBXSTATE_IDLE; // out of synchronization
186
                        else ubxstate = UBXSTATE_IDLE; // out of synchronization
137
                        break;
187
                        break;
138
 
188
 
139
                case UBXSTATE_SYNC2: // check msg class to be NAV
189
                case UBXSTATE_SYNC2: // check msg class to be NAV
140
                        if (c == UBX_CLASS_NAV) ubxstate = UBXSTATE_CLASS;
190
                        if (c == UBX_CLASS_NAV) ubxstate = UBXSTATE_CLASS;
141
                        else ubxstate = UBXSTATE_IDLE; // unsupported message class
191
                        else ubxstate = UBXSTATE_IDLE; // unsupported message class
142
                        break;
192
                        break;
143
 
193
 
144
                case UBXSTATE_CLASS: // check message identifier
194
                case UBXSTATE_CLASS: // check message identifier
145
                        switch(c)
195
                        switch(c)
146
                        {
196
                        {
147
                                case UBX_ID_POSLLH: // geodetic position
197
                                case UBX_ID_POSLLH: // geodetic position
148
                                        ubxP =  (int8_t *)&UbxPosLlh; // data start pointer
198
                                        ubxP =  (int8_t *)&UbxPosLlh; // data start pointer
149
                                        ubxEp = (int8_t *)(&UbxPosLlh + 1); // data end pointer
199
                                        ubxEp = (int8_t *)(&UbxPosLlh + 1); // data end pointer
150
                                        ubxSp = (int8_t *)&UbxPosLlh.Status; // status pointer
200
                                        ubxSp = (int8_t *)&UbxPosLlh.Status; // status pointer
151
                                        break;
201
                                        break;
152
 
202
 
153
                                case UBX_ID_SOL: // navigation solution
203
                                case UBX_ID_SOL: // navigation solution
154
                                        ubxP =  (int8_t *)&UbxSol; // data start pointer
204
                                        ubxP =  (int8_t *)&UbxSol; // data start pointer
155
                                        ubxEp = (int8_t *)(&UbxSol + 1); // data end pointer
205
                                        ubxEp = (int8_t *)(&UbxSol + 1); // data end pointer
156
                                        ubxSp = (int8_t *)&UbxSol.Status; // status pointer
206
                                        ubxSp = (int8_t *)&UbxSol.Status; // status pointer
157
                                        break;
207
                                        break;
158
 
208
 
159
                                case UBX_ID_VELNED: // velocity vector in tangent plane
209
                                case UBX_ID_VELNED: // velocity vector in tangent plane
160
                                        ubxP =  (int8_t *)&UbxVelNed; // data start pointer
210
                                        ubxP =  (int8_t *)&UbxVelNed; // data start pointer
161
                                        ubxEp = (int8_t *)(&UbxVelNed + 1); // data end pointer
211
                                        ubxEp = (int8_t *)(&UbxVelNed + 1); // data end pointer
162
                                        ubxSp = (int8_t *)&UbxVelNed.Status; // status pointer
212
                                        ubxSp = (int8_t *)&UbxVelNed.Status; // status pointer
163
                                        break;
213
                                        break;
164
 
214
 
165
                                default:                        // unsupported identifier
215
                                default:                        // unsupported identifier
166
                                        ubxstate = UBXSTATE_IDLE;
216
                                        ubxstate = UBXSTATE_IDLE;
167
                                        break;
217
                                        break;
168
                        }
218
                        }
169
                        if (ubxstate != UBXSTATE_IDLE)
219
                        if (ubxstate != UBXSTATE_IDLE)
170
                        {
220
                        {
171
                                ubxstate = UBXSTATE_LEN1;
221
                                ubxstate = UBXSTATE_LEN1;
172
                                cka = UBX_CLASS_NAV + c;
222
                                cka = UBX_CLASS_NAV + c;
173
                                ckb = UBX_CLASS_NAV + cka;
223
                                ckb = UBX_CLASS_NAV + cka;
174
                        }
224
                        }
175
                        break;
225
                        break;
176
 
226
 
177
                case UBXSTATE_LEN1: // 1st message length byte
227
                case UBXSTATE_LEN1: // 1st message length byte
178
                        msglen = c;
228
                        msglen = c;
179
                        cka += c;
229
                        cka += c;
180
                        ckb += cka;
230
                        ckb += cka;
181
                        ubxstate = UBXSTATE_LEN2;
231
                        ubxstate = UBXSTATE_LEN2;
182
                        break;
232
                        break;
183
 
233
 
184
                case UBXSTATE_LEN2: // 2nd message length byte
234
                case UBXSTATE_LEN2: // 2nd message length byte
185
                        msglen += ((uint16_t)c)<<8;
235
                        msglen += ((uint16_t)c)<<8;
186
                        cka += c;
236
                        cka += c;
187
                        ckb += cka;
237
                        ckb += cka;
188
                        // if the old data are not processed so far then break parsing now
238
                        // if the old data are not processed so far then break parsing now
189
                        // to avoid writing new data in ISR during reading by another function
239
                        // to avoid writing new data in ISR during reading by another function
190
                        if ( *ubxSp == NEWDATA )
240
                        if ( *ubxSp == NEWDATA )
191
                        {
241
                        {
192
                                UpdateGPSInfo(); //update GPS info respectively
242
                                UpdateGPSInfo(); //update GPS info respectively
193
                                ubxstate = UBXSTATE_IDLE;
243
                                ubxstate = UBXSTATE_IDLE;
194
                        }
244
                        }
195
                        else // data invalid or allready processd
245
                        else // data invalid or allready processd
196
                        {
246
                        {
197
                                *ubxSp = INVALID;
247
                                *ubxSp = INVALID;
198
                                ubxstate = UBXSTATE_DATA;
248
                                ubxstate = UBXSTATE_DATA;
199
                        }
249
                        }
200
                        break;
250
                        break;
201
 
251
 
202
                case UBXSTATE_DATA:
252
                case UBXSTATE_DATA:
203
                        if (ubxP < ubxEp) *ubxP++ = c; // copy curent data byte if any space is left
253
                        if (ubxP < ubxEp) *ubxP++ = c; // copy curent data byte if any space is left
204
                        cka += c;
254
                        cka += c;
205
                        ckb += cka;
255
                        ckb += cka;
206
                        if (--msglen == 0)      ubxstate = UBXSTATE_CKA; // switch to next state if all data was read
256
                        if (--msglen == 0)      ubxstate = UBXSTATE_CKA; // switch to next state if all data was read
207
                        break;
257
                        break;
208
 
258
 
209
                case UBXSTATE_CKA:
259
                case UBXSTATE_CKA:
210
                        if (c == cka) ubxstate = UBXSTATE_CKB;
260
                        if (c == cka) ubxstate = UBXSTATE_CKB;
211
                        else
261
                        else
212
                        {
262
                        {
213
                                *ubxSp = INVALID;
263
                                *ubxSp = INVALID;
214
                                ubxstate = UBXSTATE_IDLE;
264
                                ubxstate = UBXSTATE_IDLE;
215
                        }
265
                        }
216
                        break;
266
                        break;
217
 
267
 
218
                case UBXSTATE_CKB:
268
                case UBXSTATE_CKB:
219
                        if (c == ckb)
269
                        if (c == ckb)
220
                        {
270
                        {
221
                                *ubxSp = NEWDATA; // new data are valid
271
                                *ubxSp = NEWDATA; // new data are valid
222
                                UpdateGPSInfo(); //update GPS info respectively
272
                                UpdateGPSInfo(); //update GPS info respectively
223
                                GPSTimeout = 255;
273
                                GPSTimeout = 255;
224
                        }
274
                        }
225
                        else
275
                        else
226
                        {       // if checksum not fit then set data invalid
276
                        {       // if checksum not fit then set data invalid
227
                                *ubxSp = INVALID;
277
                                *ubxSp = INVALID;
228
                        }
278
                        }
229
                        ubxstate = UBXSTATE_IDLE; // ready to parse new data
279
                        ubxstate = UBXSTATE_IDLE; // ready to parse new data
230
                        break;
280
                        break;
231
 
281
 
232
                default: // unknown ubx state
282
                default: // unknown ubx state
233
                        ubxstate = UBXSTATE_IDLE;
283
                        ubxstate = UBXSTATE_IDLE;
234
                        break;
284
                        break;
235
        }
285
        }
236
 
286
 
237
}
287
}
238
 
288
 
239
 
289
 
240
 
290