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

77
main.c
View File

@@ -1,66 +1,6 @@
#include "main.h"
#include "EC800M.h"
typedef struct GPS_ {
char time[10];
char N[20];
char E[20];
} GPS_;
float convertToDecimal(float coordinate)
{
int degree = (int)(coordinate / 100);
float minutes = coordinate - degree * 100;
return degree + minutes / 60;
}
void Data_parsing(char *gps_data, GPS_ * gps_)
{
char *p = strchr(gps_data, ':');
char *p1 = strstr(p + 2, "\r\n");
char GPS_DATA_[p1 - p];
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_, ",");
int i = 1;
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';
//printf("GPS : %.6f, %.6f\n", convertToDecimal(atof(gps_->N)), convertToDecimal(atof(gps_->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, "%.6f", convertToDecimal(atof(gps_->N)));
sprintf(gps_->E, "%.6f", convertToDecimal(atof(gps_->E)));
}
int main(void)
{
stdio_init_all();
@@ -75,17 +15,24 @@ int main(void)
watchdog_enable(8300, 1); // 8秒检测是否重新加载看门狗计数器. (不更新计数器则重启硬件, 最高8秒)
watchdog_start_tick(12);
printf("EC800M\n");
EC800M_INIT();
char gps_data[1024] = { 0 };
printf("EC800M\n");
static char GPS_DATA[1024] = { 0 };
EC800M_INIT();
GPS_ gps_;
memset(gps_.time, 0, 10);
memset(gps_.N, 0, 20);
memset(gps_.E, 0, 20);
while (1) {
watchdog_update(); // 喂狗
strcpy(gps_data, EC800M());
Data_parsing(gps_data, &gps_);
strcpy(GPS_DATA, EC800M());
EC800M_GPS_DATA_PARSING(GPS_DATA, &gps_);
printf(" T: %s\n N: %s\n E: %s\n", gps_.time, gps_.N, gps_.E);
printf(" NE: %s, %s\n", gps_.N, gps_.E);
printf("\r\n");
sleep_ms(3000);