gps could receive but not parese

This commit is contained in:
2025-07-01 21:40:02 +08:00
parent 4d36d07b2c
commit 69d790d5e2
19 changed files with 8046 additions and 7547 deletions

269
fun/gps.c
View File

@@ -26,68 +26,206 @@ _GPSData GPS;
void GPS_Init(void)
{
HAL_UARTEx_ReceiveToIdle_IT(&huart2, GPS_DMA_RX_BUF, GPS_DMA_RX_BUF_LEN);
// __HAL_DMA_DISABLE_IT(&handle_GPDMA1_Channel3, DMA_IT_HT); // <20><><EFBFBD>ð봫<C3B0><EBB4AB>
// HAL_UARTEx_ReceiveToIdle_DMA(&huart2,GPS_DMA_RX_BUF,GPS_DMA_RX_BUF_LEN);
}
#ifdef parse
// GPS<50><53><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>
void parseGpsBuffer()
//void parseGpsBuffer()
//{
// char *subString;
// char *subStringNext;
// char i = 0;
//
// if(GPS.isGetData)
// {
// GPS.isGetData = 0; // <20>ѱ<EFBFBD>־λ<D6BE><CEBB>Ϊ1
//
// char usefullBuffer[2] = {0};
// for(i = 0; i <= 6; i++)
// {
// if(i == 0)
// {
//
// subString = strstr(GPS.GPS_Buffer,",");
// if(!subString)return;
// }
// else
// {
// subString++;
// subStringNext = strstr(subString,",");
// if(!subStringNext)return;
//
// switch(i)
// {
// case 1:
// memcpy(GPS.UTCTime,subString,subStringNext - subString);
// break;
// case 2:
// memcpy(usefullBuffer,subString,subStringNext - subString);
// break;
// case 3:
// memcpy(GPS.latitude,subString,subStringNext - subString);
// break;
// case 4:
// memcpy(GPS.N_S,subString,subStringNext - subString);
// break;
// case 5:
// memcpy(GPS.longitude,subString,subStringNext - subString);
// break;
// case 6:
// memcpy(GPS.E_W,subString,subStringNext - subString);
// break;
// default:break;
// }
//
// subString = subStringNext;
// }
//
// }
// GPS.isParseData = 1;
// GPS.isUsefull = (usefullBuffer[0] == 'A') ? 1 : 0;
// }
//
//}
//void parseGpsBuffer(void)
//{
// if (!GPS.isGetData) return;
// GPS.isGetData = 0;
// /* ----------- <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD> ------------ */
// const char *p = GPS.GPS_Buffer;
// /* <20><> RMC ----------------------------------------------------- */
// if (!strncmp(p, "$GNRMC", 6) || !strncmp(p, "$GPRMC", 6))
// {
// char status, lat[16], ns[3], lon[16], ew[3];
// if (sscanf(p,
// "$%*[^,],%*[^,],%c,%15[^,],%2[^,],%15[^,],%2[^,],",
// &status, lat, ns, lon, ew) == 5)
// {
// if (status == 'A') /* <20><>λ<EFBFBD><CEBB>Ч */
// {
// strcpy(GPS.latitude, lat);
// strcpy(GPS.N_S, ns);
// strcpy(GPS.longitude, lon);
// strcpy(GPS.E_W, ew);
// GPS.isParseData = 1;
// GPS.isUsefull = 1;
// }
// }
// return;
// }
// /* <20><> GGA ----------------------------------------------------- */
// if (!strncmp(p, "$GNGGA", 6) || !strncmp(p, "$GPGGA", 6))
// {
// int q; char lat[16], ns[3], lon[16], ew[3];
// if (sscanf(p,
// "$%*[^,],%*[^,],%15[^,],%2[^,],%15[^,],%2[^,],%d,",
// lat, ns, lon, ew, &q) == 5)
// {
// if (q > 0) /* q=0 <20>޶<EFBFBD>λ */
// {
// strcpy(GPS.latitude, lat);
// strcpy(GPS.N_S, ns);
// strcpy(GPS.longitude, lon);
// strcpy(GPS.E_W, ew);
// GPS.isParseData = 1;
// GPS.isUsefull = 1;
// }
// }
// return;
// }
// /* <20><> GLL ----------------------------------------------------- */
// if (!strncmp(p, "$GNGLL", 6) || !strncmp(p, "$GPGLL", 6))
// {
// char status, lat[16], ns[3], lon[16], ew[3];
// if (sscanf(p,
// "$%*[^,],%15[^,],%2[^,],%15[^,],%2[^,],%*[^,],%c",
// lat, ns, lon, ew, &status) == 5)
// {
// if (status == 'A')
// {
// strcpy(GPS.latitude, lat);
// strcpy(GPS.N_S, ns);
// strcpy(GPS.longitude, lon);
// strcpy(GPS.E_W, ew);
// GPS.isParseData = 1;
// GPS.isUsefull = 1;
// }
// }
// }
//}
/* === <20><> <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD> & <20><><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD> === */
static char line_buf[GPS_Buffer_Length];
static uint16_t line_w = 0;
void GPS_LinePush(uint8_t ch)
{
char *subString;
char *subStringNext;
char i = 0;
if(GPS.isGetData)
{
GPS.isGetData = 0; // <20>ѱ<EFBFBD>־λ<D6BE><CEBB>Ϊ1
char usefullBuffer[2] = {0};
for(i = 0; i <= 6; i++)
{
if(i == 0)
{
subString = strstr(GPS.GPS_Buffer,",");
if(!subString)return;
}
else
{
subString++;
subStringNext = strstr(subString,",");
if(!subStringNext)return;
switch(i)
{
case 1:
memcpy(GPS.UTCTime,subString,subStringNext - subString);
break;
case 2:
memcpy(usefullBuffer,subString,subStringNext - subString);
break;
case 3:
memcpy(GPS.latitude,subString,subStringNext - subString);
break;
case 4:
memcpy(GPS.N_S,subString,subStringNext - subString);
break;
case 5:
memcpy(GPS.longitude,subString,subStringNext - subString);
break;
case 6:
memcpy(GPS.E_W,subString,subStringNext - subString);
break;
default:break;
}
subString = subStringNext;
}
}
GPS.isParseData = 1;
GPS.isUsefull = (usefullBuffer[0] == 'A') ? 1 : 0;
}
if (ch == '\n') { /* һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
line_buf[line_w] = '\0';
strncpy(GPS.GPS_Buffer, line_buf, GPS_Buffer_Length);
line_w = 0;
GPS.isGetData = 1;
tx_event_flags_set(&system_events, EVENT_GPS_DATA_READY, TX_OR);
return;
}
if (line_w < GPS_Buffer_Length - 1)
line_buf[line_w++] = ch; /* <20><>ͨ<EFBFBD>ַ<EFBFBD> */
}
/* === <20><> <20>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻҪ<D6BB><D2AA>γ<EFBFBD><CEB3> === */
void parseGpsBuffer(void)
{
if (!GPS.isGetData) return;
GPS.isGetData = 0;
GPS.isParseData = 0;
GPS.isUsefull = 0;
const char *p = GPS.GPS_Buffer;
/* ---- $GxRMC ---- */
if (!strncmp(p, "$GNRMC", 6) || !strncmp(p, "$GPRMC", 6)) {
char s, lat[16], ns[3], lon[16], ew[3];
if (sscanf(p,
"$%*[^,],%*[^,],%c,%15[^,],%2[^,],%15[^,],%2[^,],",
&s, lat, ns, lon, ew) == 5 && s == 'A') {
strcpy(GPS.latitude, lat); strcpy(GPS.N_S, ns);
strcpy(GPS.longitude, lon); strcpy(GPS.E_W, ew);
GPS.isParseData = GPS.isUsefull = 1;
}
return;
}
/* ---- $GxGGA ---- */
if (!strncmp(p, "$GNGGA", 6) || !strncmp(p, "$GPGGA", 6)) {
int q; char lat[16], ns[3], lon[16], ew[3];
if (sscanf(p,
"$%*[^,],%*[^,],%15[^,],%2[^,],%15[^,],%2[^,],%d,",
lat, ns, lon, ew, &q) == 5 && q > 0) {
strcpy(GPS.latitude, lat); strcpy(GPS.N_S, ns);
strcpy(GPS.longitude, lon); strcpy(GPS.E_W, ew);
GPS.isParseData = GPS.isUsefull = 1;
}
return;
}
/* ---- $GxGLL ---- */
if (!strncmp(p, "$GNGLL", 6) || !strncmp(p, "$GPGLL", 6)) {
char s, lat[16], ns[3], lon[16], ew[3];
if (sscanf(p,
"$%*[^,],%15[^,],%2[^,],%15[^,],%2[^,],%*[^,],%c",
lat, ns, lon, ew, &s) == 5 && s == 'A') {
strcpy(GPS.latitude, lat); strcpy(GPS.N_S, ns);
strcpy(GPS.longitude, lon); strcpy(GPS.E_W, ew);
GPS.isParseData = GPS.isUsefull = 1;
}
}
}
#else // <20><><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6>ڸĽ<DAB8><C4BD><EFBFBD><EFBFBD><EFBFBD>parse <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>в<EFBFBD><D0B2><EFBFBD>
void parseGpsBuffer()
{
@@ -172,7 +310,7 @@ void GPS_Data_CLR(void)
//
// tx_event_flags_set(&system_events, EVENT_GPS_DATA_READY, TX_OR);
// //<2F><><EFBFBD>¿<EFBFBD><C2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// HAL_UARTEx_ReceiveToIdle_DMA(&huart2,GPS_DMA_RX_BUF,GPS_DMA_RX_BUF_LEN);
// HAL_UARTEx_ReceiveToIdle_IT(&huart2,GPS_DMA_RX_BUF,GPS_DMA_RX_BUF_LEN);
// }
//
//}
@@ -186,25 +324,28 @@ void gps_thread_entry(ULONG thread_input)
{
GPS_Init();
static int gps_first_fix_sent = 0;
BleMessage msg;
while (1)
{
ULONG events;
tx_event_flags_get(&system_events, EVENT_GPS_DATA_READY, TX_OR_CLEAR, &events, TX_WAIT_FOREVER);
parseGpsBuffer();
HCBle_SendData("[GPS] isGetData=%d, isParseData=%d, isUsefull=%d, Buffer=%s\r\n",
GPS.isGetData, GPS.isParseData, GPS.isUsefull, GPS.GPS_Buffer);
if (GPS.isParseData && GPS.isUsefull)
{
current_location.lat = Convert_to_degrees(GPS.latitude);
current_location.lon = Convert_to_degrees(GPS.longitude);
tx_event_flags_set(&system_events, EVENT_LOCATION_UPDATED, TX_OR);
char msg[128];
snprintf(msg, sizeof(msg), "#{\"lat\":%.6f,\"lon\":%.6f,\"angle\":%.2f}\n",
current_location.lat,
current_location.lon,
current_location.angle);
msg.lat = current_location.lat;
msg.lon = current_location.lon;
// snprintf(msg, sizeof(msg), "#{\"lat\":%.6f,\"lon\":%.6f,\"angle\":%.2f}\n",
// current_location.lat,
// current_location.lon,
// current_location.angle);
tx_queue_send(&ble_tx_queue, &msg, TX_WAIT_FOREVER);
}