This commit is contained in:
2024-03-26 10:34:11 +08:00
parent ca33b6e342
commit 49919f3191
3 changed files with 86 additions and 74 deletions

View File

@@ -1,5 +1,6 @@
#include "EC800M.h"
char GPSDATA[GPSDATA_LENGTH];
int GPSDATA_LEN;
@@ -49,6 +50,7 @@ void reset_data()
GPSDATA_LEN = 0;
}
// 初始化EC800M串口
int EC800M_INIT()
{
uart_init(GPS_UART, 2400);
@@ -93,6 +95,7 @@ int EC800M_INIT()
return 0;
}
// 读取GPS信息
char *EC800M()
{
uart_send_string("AT+QGPSLOC=0\r\n");
@@ -105,12 +108,68 @@ char *EC800M()
return GPSDATA;
}
char *EC800M_GPS_DATA_PARSING(char *GPS_DATA)
// GPS 经纬度转10进制
long double convertToDecimal(long double coordinate)
{
char *p = NULL;
p = strstr(GPSDATA, "QGPSLOC:");
printf("%s\n", p);
return 0;
int degree = (int)(coordinate / 100);
long double minutes = coordinate - degree * 100;
return degree + minutes / 60;
}
// 解释GPS数据
void EC800M_GPS_DATA_PARSING(char *GPS_DATA, GPS_ * gps_)
{
int i = 1;
char *p = strchr(GPS_DATA, ':');
char *p1 = strstr(p + 2, "\r\n");
char GPS_DATA_[p1 - p];
memset(gps_->time, 0, 10);
memset(gps_->N, 0, 20);
memset(gps_->E, 0, 20);
memset(GPS_DATA_, 0, p1 - p);
memcpy(GPS_DATA_, p + 2, p1 - p - 2 + 1);
printf("%s\n", GPS_DATA_);
char *token = strtok(GPS_DATA_, ",");
while (token != NULL) {
if (i == 1) {
strcpy(gps_->time, token);
}
if (i == 2) {
strcpy(gps_->N, token);
}
if (i == 3) {
strcpy(gps_->E, token);
}
token = strtok(NULL, ",");
i++;
}
gps_->N[strlen(gps_->N) - 1] = '\0';
gps_->E[strlen(gps_->E) - 1] = '\0';
long double N,E;
N=atof(gps_->N);
E=atof(gps_->E);
//printf("GPS : %.9lf, %.9lf\n", N, E);
//printf("GPS : %.6lf, %.6lf\n", convertToDecimal(N), convertToDecimal(E));
// 095921.00
char hours[3] = { 0 };
char minutes[3] = { 0 };
char seconds[9] = { 0 };
char *p2 = gps_->time;
memcpy(hours, p2, 2);
memcpy(minutes, p2 + 2, 2);
memcpy(seconds, p2 + 4, 2);
//printf("GPS 修正时间: %d:%s:%s\n", atoi(hours) + 8, minutes, seconds);
sprintf(gps_->time, "%d:%s:%s", atoi(hours) + 8, minutes, seconds);
sprintf(gps_->N, "%.6lf", convertToDecimal(atof(gps_->N)));
sprintf(gps_->E, "%.6lf", convertToDecimal(atof(gps_->E)));
return ;
}