-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgps.c
More file actions
131 lines (99 loc) · 3.11 KB
/
gps.c
File metadata and controls
131 lines (99 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "gps.h"
void GPS_WaitForLine(void){
while(EUSART_Read() != '$');
}
double GPS_NMEAToDouble(char * RXBuffer, char startPos){
char coordinateBuffer[11];
int i;
double coordinate, degrees, seconds;
for(i=0; i<10; i++){
coordinateBuffer[i] = RXBuffer[i+startPos] ;
}
coordinateBuffer[i+1] = '\0';
coordinate = atof(coordinateBuffer);
degrees = (int)(coordinate/100);
seconds = coordinate - degrees * 100;
coordinate = degrees + seconds/60;
if(RXBuffer[startPos+11] == 'S' || RXBuffer[startPos+11] == 'W')
coordinate *= -1; //Negate
return coordinate;
}
void GPS_Get_Satellites(char * GPGGALine, char * satBuf){
for(int i=0; i<2; i++){
satBuf[i] = GPGGALine[39+i];
}
satBuf[2] = '\0';
}
void GPS_Get_Height(char * GPGGALine, char * heightBuf){
uint8_t startIndex=44;
uint8_t i=0;
//First we have to skip some commas
while(1){
startIndex++;
if(GPGGALine[startIndex] == ',') break;
}
//Skip the next comma
startIndex++;
do{
heightBuf[i] = GPGGALine[startIndex+i];
i++;
} while(heightBuf[i-1] != ',');
heightBuf[i-1] = '\0';
}
void GPS_Get_Velocity(char * GPGVTGLine, char * velocityBuf){
uint8_t startIndex=12;
uint8_t i=0;
//First we have to skip some commas
while(1){
startIndex++;
//Go to the end of the knots index
if(GPGVTGLine[startIndex] == 'N') break;
}
//Skip the next comma
startIndex++;
do{
velocityBuf[i] = GPGVTGLine[startIndex+i];
i++;
} while(velocityBuf[i-1] != ',');
velocityBuf[i-1] = '\0';
}
char GPS_GetGPGGALine(char * RXBuffer){
char toMatch[6] = "GPGGA,";
char breakCondition = 0;
while(1){
//Wait for a new GPS line
GPS_WaitForLine();
//Set break condition to true
char breakCondition = 1;
//Start matching the first 6 characters
for(int i=0; i<6; i++){
//If one of them doesnt match, set the breakcondition to false
if(toMatch[i] != EUSART_Read()) breakCondition = 0;
}
if(breakCondition) break;
}
//Start reading the rest of the line
EUSART_ReadLn(RXBuffer, BUFFER_SIZE);
//Check if the 7th character is not a comma as this would mean
//There is no gps data available yet
if (RXBuffer[11] == ',') return 0;
return 1;
}
void GPS_GetGPVTGLine(char * RXBuffer){
char toMatch[6] = "GPVTG,";
char breakCondition = 0;
while(1){
//Wait for a new GPS line
GPS_WaitForLine();
//Set break condition to true
char breakCondition = 1;
//Start matching the first 6 characters
for(int i=0; i<6; i++){
//If one of them doesnt match, set the breakcondition to false
if(toMatch[i] != EUSART_Read()) breakCondition = 0;
}
if(breakCondition) break;
}
//Start reading the rest of the line
EUSART_ReadLn(RXBuffer, BUFFER_SIZE);
}