Subversion Repositories FlightCtrl

Rev

Rev 722 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 722 Rev 724
Line 2... Line 2...
2
#include "ubx.h"
2
#include "ubx.h"
3
#include "main.h"
3
#include "main.h"
4
#include <avr/io.h>
4
#include <avr/io.h>
Line 5... Line 5...
5
 
5
 
6
#include "uart.h"
-
 
Line 7... Line 6...
7
#include "timer0.h"
6
#include "uart.h"
8
 
7
 
9
// ubx protocol parser state machine
8
// ubx protocol parser state machine
10
#define UBXSTATE_IDLE   0
9
#define UBXSTATE_IDLE   0
Line 24... Line 23...
24
#define UBX_ID_STATUS   0x03
23
#define UBX_ID_STATUS   0x03
25
#define UBX_ID_VELNED   0x12
24
#define UBX_ID_VELNED   0x12
26
#define UBX_SYNC1_CHAR  0xB5
25
#define UBX_SYNC1_CHAR  0xB5
27
#define UBX_SYNC2_CHAR  0x62
26
#define UBX_SYNC2_CHAR  0x62
Line 28... Line -...
28
 
-
 
29
 
27
 
30
typedef struct {
28
typedef struct {
31
        uint32_t                ITOW;           // ms GPS Millisecond Time of Week
29
        uint32_t                ITOW;           // ms GPS Millisecond Time of Week
32
        uint8_t                 GPSfix;         // GPSfix Type, range 0..6
30
        uint8_t                 GPSfix;         // GPSfix Type, range 0..6
33
        uint8_t                 Flags;          // Navigation Status Flags
31
        uint8_t                 Flags;          // Navigation Status Flags
Line 104... Line 102...
104
        if (GpsVelNed.Status == VALID)                  // valid packet
102
        if (GpsVelNed.Status == VALID)                  // valid packet
105
        {
103
        {
106
                GPSInfo.veleast = GpsVelNed.VEL_E;
104
                GPSInfo.veleast = GpsVelNed.VEL_E;
107
                GPSInfo.velnorth = GpsVelNed.VEL_N;
105
                GPSInfo.velnorth = GpsVelNed.VEL_N;
108
                GPSInfo.veltop = -GpsVelNed.VEL_D;
106
                GPSInfo.veltop = -GpsVelNed.VEL_D;
109
                GpsPosUtm.Status = PROCESSED;                   // never update old data
107
                GpsVelNed.Status = PROCESSED;                   // never update old data
110
        }
108
        }
111
        if (GpsStatus.Status != INVALID)
109
        if (GpsStatus.Status != INVALID)
112
        {
110
        {
113
                GPSInfo.status = VALID;               // set valid if data are updated
111
                GPSInfo.status = VALID;               // set valid if data are updated
114
        }
112
        }
115
}
113
}
Line -... Line 114...
-
 
114
 
-
 
115
void ubx_init(void)
-
 
116
{
-
 
117
        GpsStatus.Status = INVALID;
-
 
118
        GpsPosLlh.Status = INVALID;
-
 
119
        GpsPosUtm.Status = INVALID;
-
 
120
        GpsVelNed.Status = INVALID;
-
 
121
        GPSInfo.status = INVALID;
-
 
122
}
116
 
123
 
117
// this function should be called within the UART RX ISR
124
// this function should be called within the UART RX ISR
118
void ubx_parser(uint8_t c)
125
void ubx_parser(uint8_t c)
119
{
126
{
120
        static uint8_t ubxstate = UBXSTATE_IDLE;
127
        static uint8_t ubxstate = UBXSTATE_IDLE;
Line 234... Line 241...
234
                        break;
241
                        break;
235
        }
242
        }
Line 236... Line 243...
236
 
243
 
Line -... Line 244...
-
 
244
}