forked from nimaltd/NMEA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPS.c
More file actions
72 lines (68 loc) · 2.59 KB
/
Copy pathGPS.c
File metadata and controls
72 lines (68 loc) · 2.59 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
#include "GPSConfig.h"
#include "GPS.h"
#include "usart.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
GPS_t GPS;
//##################################################################################################################
double convertDegMinToDecDeg (float degMin)
{
double min = 0.0;
double decDeg = 0.0;
//get the minutes, fmod() requires double
min = fmod((double)degMin, 100.0);
//rebuild coordinates in decimal degrees
degMin = (int) ( degMin / 100 );
decDeg = degMin + ( min / 60 );
return decDeg;
}
//##################################################################################################################
void GPS_Init(void)
{
GPS.rxIndex=0;
HAL_UART_Receive_IT(&_GPS_USART,&GPS.rxTmp,1);
}
//##################################################################################################################
void GPS_CallBack(void)
{
GPS.LastTime=HAL_GetTick();
if(GPS.rxIndex < sizeof(GPS.rxBuffer)-2)
{
GPS.rxBuffer[GPS.rxIndex] = GPS.rxTmp;
GPS.rxIndex++;
}
HAL_UART_Receive_IT(&_GPS_USART,&GPS.rxTmp,1);
}
//##################################################################################################################
void GPS_Process(void)
{
if( (HAL_GetTick()-GPS.LastTime>50) && (GPS.rxIndex>0))
{
char *str;
#if (_GPS_DEBUG==1)
printf("%s",GPS.rxBuffer);
#endif
str=strstr((char*)GPS.rxBuffer,"$GPGGA,");
if(str!=NULL)
{
memset(&GPS.GPGGA,0,sizeof(GPS.GPGGA));
sscanf(str,"$GPGGA,%2hhd%2hhd%2hhd.%3hd,%f,%c,%f,%c,%hhd,%hhd,%f,%f,%c,%hd,%s,*%2s\r\n",&GPS.GPGGA.UTC_Hour,&GPS.GPGGA.UTC_Min,&GPS.GPGGA.UTC_Sec,&GPS.GPGGA.UTC_MicroSec,&GPS.GPGGA.Latitude,&GPS.GPGGA.NS_Indicator,&GPS.GPGGA.Longitude,&GPS.GPGGA.EW_Indicator,&GPS.GPGGA.PositionFixIndicator,&GPS.GPGGA.SatellitesUsed,&GPS.GPGGA.HDOP,&GPS.GPGGA.MSL_Altitude,&GPS.GPGGA.MSL_Units,&GPS.GPGGA.AgeofDiffCorr,GPS.GPGGA.DiffRefStationID,GPS.GPGGA.CheckSum);
if(GPS.GPGGA.NS_Indicator==0)
GPS.GPGGA.NS_Indicator='-';
if(GPS.GPGGA.EW_Indicator==0)
GPS.GPGGA.EW_Indicator='-';
if(GPS.GPGGA.Geoid_Units==0)
GPS.GPGGA.Geoid_Units='-';
if(GPS.GPGGA.MSL_Units==0)
GPS.GPGGA.MSL_Units='-';
GPS.GPGGA.LatitudeDecimal=convertDegMinToDecDeg(GPS.GPGGA.Latitude);
GPS.GPGGA.LongitudeDecimal=convertDegMinToDecDeg(GPS.GPGGA.Longitude);
}
memset(GPS.rxBuffer,0,sizeof(GPS.rxBuffer));
GPS.rxIndex=0;
}
HAL_UART_Receive_IT(&_GPS_USART,&GPS.rxTmp,1);
}
//##################################################################################################################