android gps 轨迹记录仪,怎么做一个GPS轨迹记录仪

该博客介绍了一个Arduino UNO项目,该项目从GPS模块接收数据,解析出经纬度、速度和时间信息,并在1602液晶显示屏上展示。代码中包含了对GPRMC NMEA数据的解析函数,以及将UTC时间转换为北京时间的逻辑。然而,编译时遇到了错误,作者请求帮助找出问题所在。
摘要由CSDN通过智能技术生成

串口接收GPS模块数据并在1602上显示坐标

用UNO接收GPS的数据,解析出位置,时间,并在1602液晶上显示出来,编译时提示错误,请教各位这是哪里出了问题

#include

#define GPRMC_TERM "$GPRMC,"        //定义要解析的指令,因为这条指令包含定位和时间信息

char nmeaSentence[68];

String latitude;        //纬度

String longitude;       //经度

String lndSpeed;        //速度

String gpsTime;         //UTC时间,本初子午线经度0度的时间,和北京时间差8小时

String beiJingTime;     //北京时间

LiquidCrystal lcd(12, 13, 5, 4, 3, 2);

void setup()    //初始化内容

{

lcd.begin (16,2);

Serial.begin(9600);           //定义波特率9600,和我们店铺的GPS模块输出的波特率一致

}

void loop()     //主循环

{

// For one second we parse GPS data and report some key values

for (unsigned long start = millis(); millis() - start < 1000;) //一秒钟内不停扫描GPS信息

{

while (Serial.available())  //串口获取到数据开始解析

{

char c = Serial.read();   //读取一个字节获取的数据

switch(c)                 //判断该字节的值

{

case '$':                 //若是$,则说明是一帧数据的开始

Serial.readBytesUntil('*', nmeaSentence, 67);       //读取接下来的数据,存放在nmeaSentence字符数组中,最大存放67个字节

latitude =parseGprmcLat(nmeaSentence);  //获取纬度值

longitude = parseGprmcLon(nmeaSentence);//获取经度值

lndSpeed = parseGprmcSpeed(nmeaSentence);//获取速度值

gpsTime = parseGprmcTime(nmeaSentence);//获取GPS时间

lcd.setCursor(0, 0);

lcd.write(latitude);

lcd.setCursor(0, 1);

lcd.write(longitude);

}

}

}

}

String getBeiJingTime(String s)

{

int hour = s.substring(0,2).toInt();

int minute = s.substring(2,4).toInt();

int second = s.substring(4,6).toInt();

hour += 8;

if(hour > 24)

hour -= 24;

s = String(hour) + String(minute) + String(second);

return s;

}

//Parse GPRMC NMEA sentence data from String

//String must be GPRMC or no data will be parsed

//Return Latitude

String parseGprmcLat(String s)

{

int pLoc = 0; //paramater location pointer

int lEndLoc = 0; //lat parameter end location

int dEndLoc = 0; //direction parameter end location

String lat;

/*make sure that we are parsing the GPRMC string.

Found that setting s.substring(0,5) == "GPRMC" caused a FALSE.

There seemed to be a 0x0D and 0x00 character at the end. */

if(s.substring(0,4) == "GPRM")

{

//Serial.println(s);

for(int i = 0; i < 5; i++)

{

if(i < 3)

{

pLoc = s.indexOf(',', pLoc+1);

/*Serial.print("i < 3, pLoc: ");

Serial.print(pLoc);

Serial.print(", ");

Serial.println(i);*/

}

if(i == 3)

{

lEndLoc = s.indexOf(',', pLoc+1);

lat = s.substring(pLoc+1, lEndLoc);

/*Serial.print("i = 3, pLoc: ");

Serial.println(pLoc);

Serial.print("lEndLoc: ");

Serial.println(lEndLoc);*/

}

else

{

dEndLoc = s.indexOf(',', lEndLoc+1);

lat = lat + " " + s.substring(lEndLoc+1, dEndLoc);

/*Serial.print("i = 4, lEndLoc: ");

Serial.println(lEndLoc);

Serial.print("dEndLoc: ");

Serial.println(dEndLoc);*/

}

}

return lat;

}

//}

//}

}

//Parse GPRMC NMEA sentence data from String

//String must be GPRMC or no data will be parsed

//Return Longitude

String parseGprmcLon(String s)

{

int pLoc = 0; //paramater location pointer

int lEndLoc = 0; //lat parameter end location

int dEndLoc = 0; //direction parameter end location

String lon;

/*make sure that we are parsing the GPRMC string.

Found that setting s.substring(0,5) == "GPRMC" caused a FALSE.

There seemed to be a 0x0D and 0x00 character at the end. */

if(s.substring(0,4) == "GPRM")

{

//Serial.println(s);

for(int i = 0; i < 7; i++)

{

if(i < 5)

{

pLoc = s.indexOf(',', pLoc+1);

/*Serial.print("i < 3, pLoc: ");

Serial.print(pLoc);

Serial.print(", ");

Serial.println(i);*/

}

if(i == 5)

{

lEndLoc = s.indexOf(',', pLoc+1);

lon = s.substring(pLoc+1, lEndLoc);

/*Serial.print("i = 3, pLoc: ");

Serial.println(pLoc);

Serial.print("lEndLoc: ");

Serial.println(lEndLoc);*/

}

else

{

dEndLoc = s.indexOf(',', lEndLoc+1);

lon = lon + " " + s.substring(lEndLoc+1, dEndLoc);

/*Serial.print("i = 4, lEndLoc: ");

Serial.println(lEndLoc);

Serial.print("dEndLoc: ");

Serial.println(dEndLoc);*/

}

}

return lon;

}

}

//Parse GPRMC NMEA sentence data from String

//String must be GPRMC or no data will be parsed

//Return Longitude

String parseGprmcSpeed(String s)

{

int pLoc = 0; //paramater location pointer

int lEndLoc = 0; //lat parameter end location

int dEndLoc = 0; //direction parameter end location

String lndSpeed;

/*make sure that we are parsing the GPRMC string.

Found that setting s.substring(0,5) == "GPRMC" caused a FALSE.

There seemed to be a 0x0D and 0x00 character at the end. */

if(s.substring(0,4) == "GPRM")

{

//Serial.println(s);

for(int i = 0; i < 8; i++)

{

if(i < 7)

{

pLoc = s.indexOf(',', pLoc+1);

/*Serial.print("i < 8, pLoc: ");

Serial.print(pLoc);

Serial.print(", ");

Serial.println(i);*/

}

else

{

lEndLoc = s.indexOf(',', pLoc+1);

lndSpeed = s.substring(pLoc+1, lEndLoc);

/*Serial.print("i = 8, pLoc: ");

Serial.println(pLoc);

Serial.print("lEndLoc: ");

Serial.println(lEndLoc);*/

}

}

return lndSpeed;

}

}

//Parse GPRMC NMEA sentence data from String

//String must be GPRMC or no data will be parsed

//Return Longitude

String parseGprmcTime(String s)

{

int pLoc = 0; //paramater location pointer

int lEndLoc = 0; //lat parameter end location

int dEndLoc = 0; //direction parameter end location

String gpsTime;

/*make sure that we are parsing the GPRMC string.

Found that setting s.substring(0,5) == "GPRMC" caused a FALSE.

There seemed to be a 0x0D and 0x00 character at the end. */

if(s.substring(0,4) == "GPRM")

{

//Serial.println(s);

for(int i = 0; i < 2; i++)

{

if(i < 1)

{

pLoc = s.indexOf(',', pLoc+1);

/*Serial.print("i < 8, pLoc: ");

Serial.print(pLoc);

Serial.print(", ");

Serial.println(i);*/

}

else

{

lEndLoc = s.indexOf(',', pLoc+1);

gpsTime = s.substring(pLoc+1, lEndLoc);

/*Serial.print("i = 8, pLoc: ");

Serial.println(pLoc);

Serial.print("lEndLoc: ");

Serial.println(lEndLoc);*/

}

}

return gpsTime;

}

}

// Turn char[] array into String object

String charToString(char *c)

{

String val = "";

for(int i = 0; i <= sizeof(c); i++)

{

val = val + c;

}

return val;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值