Skip to content

Commit a0bfb7f

Browse files
committed
optimize gps demo, fix gps reboot bug when gprs register
1 parent bcdcda5 commit a0bfb7f

File tree

2 files changed

+48
-30
lines changed

2 files changed

+48
-30
lines changed

demo/gps/src/demo_gps.c

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define MAIN_TASK_NAME "GPS Test Task"
1717

1818
static HANDLE gpsTaskHandle = NULL;
19-
19+
bool flag = false;
2020

2121

2222
// const uint8_t nmea[]="$GNGGA,000021.263,2228.7216,N,11345.5625,E,0,0,,153.3,M,-3.3,M,,*4E\r\n$GPGSA,A,1,,,,,,,,,,,,,,,*1E\r\n$BDGSA,A,1,,,,,,,,,,,,,,,*0F\r\n$GPGSV,1,1,00*79\r\n$BDGSV,1,1,00*68\r\n$GNRMC,000021.263,V,2228.7216,N,11345.5625,E,0.000,0.00,060180,,,N*5D\r\n$GNVTG,0.00,T,,M,0.000,N,0.000,K,N*2C\r\n";
@@ -25,6 +25,11 @@ void EventDispatch(API_Event_t* pEvent)
2525
{
2626
switch(pEvent->id)
2727
{
28+
case API_EVENT_ID_NETWORK_REGISTERED_HOME:
29+
case API_EVENT_ID_NETWORK_REGISTERED_ROAMING:
30+
Trace(1,"gprs register complete");
31+
flag = true;
32+
break;
2833
case API_EVENT_ID_GPS_UART_RECEIVED:
2934
// Trace(1,"received GPS data,length:%d, data:%s,flag:%d",pEvent->param1,pEvent->pParam1,flag);
3035
GPS_Update(pEvent->pParam1,pEvent->param1);
@@ -48,10 +53,6 @@ void EventDispatch(API_Event_t* pEvent)
4853
}
4954
}
5055
break;
51-
case API_EVENT_ID_NETWORK_REGISTERED_HOME:
52-
case API_EVENT_ID_NETWORK_REGISTERED_ROAMING:
53-
Trace(1,"register success");
54-
break;
5556
default:
5657
break;
5758
}
@@ -63,19 +64,34 @@ void gps_testTask(void *pData)
6364
uint8_t buffer[150];
6465
char buff1[15],buff2[15];
6566

66-
//wait for gps start up
67-
while(gpsInfo->rmc.latitude.value == 0)
68-
OS_Sleep(1000);
69-
//set gps nmea output interval
70-
for(uint8_t i = 0;i<3;++i)
67+
//wait for gprs register complete
68+
//The process of GPRS registration network may cause the power supply voltage of GPS to drop,
69+
//which resulting in GPS restart.
70+
while(!flag)
7171
{
72-
bool ret = GPS_SetOutputInterval(10000);
73-
Trace(1,"set gps ret:%d",ret);
74-
if(ret)
75-
break;
76-
OS_Sleep(1000);
72+
Trace(1,"wait for gprs regiter complete");
73+
OS_Sleep(2000);
7774
}
7875

76+
//open GPS hardware(UART2 open either)
77+
GPS_Init();
78+
GPS_Open(NULL);
79+
80+
//wait for gps start up, or gps will not response command
81+
while(gpsInfo->rmc.latitude.value == 0)
82+
OS_Sleep(1000);
83+
84+
85+
// set gps nmea output interval
86+
// for(uint8_t i = 0;i<3;++i)
87+
// {
88+
// bool ret = GPS_SetOutputInterval(10000);
89+
// Trace(1,"set gps ret:%d",ret);
90+
// if(ret)
91+
// break;
92+
// OS_Sleep(1000);
93+
// }
94+
7995
// if(!GPS_ClearInfoInFlash())
8096
// Trace(1,"erase gps fail");
8197

@@ -88,16 +104,16 @@ void gps_testTask(void *pData)
88104
// if(!GPS_SetSBASEnable(true))
89105
// Trace(1,"enable sbas fail");
90106

91-
if(!GPS_GetVersion(buffer,150))
92-
Trace(1,"get gps firmware version fail");
93-
else
94-
Trace(1,"gps firmware version:%s",buffer);
107+
// if(!GPS_GetVersion(buffer,150))
108+
// Trace(1,"get gps firmware version fail");
109+
// else
110+
// Trace(1,"gps firmware version:%s",buffer);
95111

96-
if(!GPS_SetFixMode(GPS_FIX_MODE_NORMAL))
97-
Trace(1,"set fix mode fail");
112+
// if(!GPS_SetFixMode(GPS_FIX_MODE_LOW_SPEED))
113+
// Trace(1,"set fix mode fail");
98114

99-
if(!GPS_SetOutputInterval(1000))
100-
Trace(1,"set nmea output interval fail");
115+
// if(!GPS_SetOutputInterval(1000))
116+
// Trace(1,"set nmea output interval fail");
101117

102118
Trace(1,"init ok");
103119

@@ -109,7 +125,12 @@ void gps_testTask(void *pData)
109125
if(isFixed == 2)
110126
isFixedStr = "2D fix";
111127
else if(isFixed == 3)
112-
isFixedStr = "3D fix";
128+
{
129+
if(gpsInfo->gga.fix_quality == 1)
130+
isFixedStr = "3D fix";
131+
else if(gpsInfo->gga.fix_quality == 2)
132+
isFixedStr = "3D/DGPS fix";
133+
}
113134
else
114135
isFixedStr = "no fix";
115136

@@ -124,8 +145,8 @@ void gps_testTask(void *pData)
124145

125146
//you can copy ` buff1,buff2 `(latitude,longitude) to http://www.gpsspg.com/maps.htm check location on map
126147

127-
snprintf(buffer,sizeof(buffer),"GPS fix mode:%d, BDS fix mode:%d, is fixed:%s, coordinate:WGS84, Latitude:%s, Longitude:%s",gpsInfo->gsa[0].fix_type, gpsInfo->gsa[1].fix_type,
128-
isFixedStr, buff1,buff2);
148+
snprintf(buffer,sizeof(buffer),"GPS fix mode:%d, BDS fix mode:%d, fix quality:%d, is fixed:%s, coordinate:WGS84, Latitude:%s, Longitude:%s, unit:degree",gpsInfo->gsa[0].fix_type, gpsInfo->gsa[1].fix_type,
149+
gpsInfo->gga.fix_quality,isFixedStr, buff1,buff2);
129150
//show in tracer
130151
Trace(2,buffer);
131152
//send to UART1
@@ -141,9 +162,6 @@ void gps_MainTask(void *pData)
141162
{
142163
API_Event_t* event=NULL;
143164

144-
//open GPS hardware(UART2 open either)
145-
GPS_Init();
146-
GPS_Open(NULL);
147165

148166
//open UART1 to print NMEA infomation
149167
UART_Config_t config = {

libs/gps/include/gps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C"{
2525
#define GPS_NMEA_FRAME_BUFFER_LENGTH 1024
2626
#define GPS_DATA_BUFFER_MAX_LENGTH 2048
2727

28-
#define GPS_DEBUG 1
28+
#define GPS_DEBUG 0
2929

3030
/////////////////////////////////////////
3131

0 commit comments

Comments
 (0)