我是靠谱客的博主 踏实发卡,最近开发中收集的这篇文章主要介绍基于Arduino的GPS数据解析程序这篇博客讲了我利用arduino来解析和转发原始nema 0813数据的思想和实现方法。因为arduino比较简单,无法实现串口数据接收中断,所以都写在主循环里面了。不知道代码存在何种缺陷和漏洞,欢迎大家批评指正。GPS软件要求,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

这篇博客讲了我利用arduino来解析和转发原始nema 0813数据的思想和实现方法。因为arduino比较简单,无法实现串口数据接收中断,所以都写在主循环里面了。不知道代码存在何种缺陷和漏洞,欢迎大家批评指正。

GPS软件要求

·         Ardiuno软件

·         监控串口1,接收数据。

·         数据格式:NEMA0813

·         解析出经纬度原始格式,xxxx.xxxxx, xxxx.xxxxx,保存,解析出短格式,2B 经度,2B 维度,保存

·         短格式:经纬度都是0.0ABCD格式小数最末4位,例如信号中经度是1234.56789,则得到67 和 89

·         经纬度都正常则LED亮。

·         串口2收到AddressWHR的时候:

·         经纬度按原始格式向串口2发送,以AddressFLT开头,跟着固定格式经纬度xxxx.xxxxx,xxxx.xxxxx,CRC结尾

·         经纬度按短格式向串口2发送:{ AddressLCT,2B 经度,2B 维度,1B CRC}

/***
* The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)
***/
#include
SoftwareSerial mySerial(10, 11);
char rmc_flag = 0;
char command_flag = 0;
char gps_data_nema[220] = {0};
char gps_data_rmc[72] = {0};
char gps_data_anal[20] = {'0','0','0','0','0','.','0','0','0','0',
'0','0','0','0','0','.','0','0','0','0'};//经纬度分
char gps_data_byte[4] = {0};
char *gprmc = "$GPRMC";
char *command = "Ad";
char command_code[2] = {0};
void memcpy(char *dest, char *src, int n)
{
int i = 0;
for(i = 0; i < n; i++)
{
*dest = *src;
dest++;
src++;
}
}
int memcmp(char *s1, char *s2, int n)
{
int i = 0;
for(i = 0; i < n; i++)
{
if(*s1 != *s2)return 0;
s1++;
s2++;
}
return 1;
}
void setup()
{
Serial.begin(57600);
mySerial.begin(4800);
}
void loop() {
static char i = 0;
static char j = 0;
char k = 0;
char l = 0;
char comma[12] = {0}; //一共有12个逗号
// put your main code here, to run repeatedly:
if(Serial.available())
{
gps_data_nema[i] = Serial.read();
Serial.print(gps_data_nema[i]);
if(i == 0)
{
if(gps_data_nema[i] != '$')
Serial.println("Warning:the data input is wrong!");
}
if(gps_data_nema[i] == '$')
{
i = 0;
gps_data_nema[i] = '$';
}
if(gps_data_nema[i] == 0x0A) //if the end of string
{
if(memcmp(gps_data_nema, gprmc, 6))
{
memcpy(gps_data_rmc, gps_data_nema, i);
rmc_flag = 1;
};
i = 0;
}
if(i > 210) //if the data is out range
Serial.println("Warning:the data formation is false!");
i++;
}
if(rmc_flag == 1)
{
l = 0;
for(k = 0; k < 72; k++)
{
if(gps_data_rmc[k] == ',')
{
comma[l] = k;
l ++;
}
}
if((comma[3]-comma[2]) == 10)
{
k = comma[2] + 1;
memcpy(&gps_data_anal[11], &gps_data_rmc[k], 9);
}
if((comma[5]-comma[4]) == 11)
{
l = comma[4] + 1;
memcpy(&gps_data_anal[0], &gps_data_rmc[l], 10);
}
gps_data_byte[0] = gps_data_anal[8];
gps_data_byte[1] = gps_data_anal[9];
gps_data_byte[2] = gps_data_anal[18];
gps_data_byte[3] = gps_data_anal[19];
rmc_flag = 0;
}
if(mySerial.available()&&(command_flag == 0))
{
command_code[j] = mySerial.read();
mySerial.print(command_code[j]);
j = j + 1;
if(j == 2)
{
mySerial.print("AddressWHR");
command_flag = 1;
j = 0;
}
}
if(command_flag == 1)
{
if(memcmp(command, command_code, 2))
{
mySerial.print("AddressFLT");
for(k = 0; k < 20; k++)mySerial.print(gps_data_anal[k]);
mySerial.print("CRC");
mySerial.print("AddressLCT");
for(l = 0; l < 4; l++)mySerial.print(gps_data_byte[l]);
mySerial.print("CRC");
}
command_flag = 0;
}
}

SoftwareSerial mySerial(10, 11);
char rmc_flag = 0;
char command_flag = 0;
char gps_data_nema[220] = {0};
char gps_data_rmc[72] = {0};
char gps_data_anal[20] = {'0','0','0','0','0','.','0','0','0','0',
'0','0','0','0','0','.','0','0','0','0'};//经纬度分
char gps_data_byte[4] = {0};
char *gprmc = "$GPRMC";
char *command = "Ad";
char command_code[2] = {0};
void memcpy(char *dest, char *src, int n)
{
int i = 0;
for(i = 0; i < n; i++)
{
*dest = *src;
dest++;
src++;
}
}
int memcmp(char *s1, char *s2, int n)
{
int i = 0;
for(i = 0; i < n; i++)
{
if(*s1 != *s2)return 0;
s1++;
s2++;
}
return 1;
}
void setup()
{
Serial.begin(57600);
mySerial.begin(4800);
}
void loop() {
static char i = 0;
static char j = 0;
char k = 0;
char l = 0;
char comma[12] = {0}; //一共有12个逗号
// put your main code here, to run repeatedly:
if(Serial.available())
{
gps_data_nema[i] = Serial.read();
Serial.print(gps_data_nema[i]);
if(i == 0)
{
if(gps_data_nema[i] != '$')
Serial.println("Warning:the data input is wrong!");
}
if(gps_data_nema[i] == '$')
{
i = 0;
gps_data_nema[i] = '$';
}
if(gps_data_nema[i] == 0x0A) //if the end of string
{
if(memcmp(gps_data_nema, gprmc, 6))
{
memcpy(gps_data_rmc, gps_data_nema, i);
rmc_flag = 1;
};
i = 0;
}
if(i > 210) //if the data is out range
Serial.println("Warning:the data formation is false!");
i++;
}
if(rmc_flag == 1)
{
l = 0;
for(k = 0; k < 72; k++)
{
if(gps_data_rmc[k] == ',')
{
comma[l] = k;
l ++;
}
}
if((comma[3]-comma[2]) == 10)
{
k = comma[2] + 1;
memcpy(&gps_data_anal[11], &gps_data_rmc[k], 9);
}
if((comma[5]-comma[4]) == 11)
{
l = comma[4] + 1;
memcpy(&gps_data_anal[0], &gps_data_rmc[l], 10);
}
gps_data_byte[0] = gps_data_anal[8];
gps_data_byte[1] = gps_data_anal[9];
gps_data_byte[2] = gps_data_anal[18];
gps_data_byte[3] = gps_data_anal[19];
rmc_flag = 0;
}
if(mySerial.available()&&(command_flag == 0))
{
command_code[j] = mySerial.read();
mySerial.print(command_code[j]);
j = j + 1;
if(j == 2)
{
mySerial.print("AddressWHR");
command_flag = 1;
j = 0;
}
}
if(command_flag == 1)
{
if(memcmp(command, command_code, 2))
{
mySerial.print("AddressFLT");
for(k = 0; k < 20; k++)mySerial.print(gps_data_anal[k]);
mySerial.print("CRC");
mySerial.print("AddressLCT");
for(l = 0; l < 4; l++)mySerial.print(gps_data_byte[l]);
mySerial.print("CRC");
}
command_flag = 0;
}
}

最后

以上就是踏实发卡为你收集整理的基于Arduino的GPS数据解析程序这篇博客讲了我利用arduino来解析和转发原始nema 0813数据的思想和实现方法。因为arduino比较简单,无法实现串口数据接收中断,所以都写在主循环里面了。不知道代码存在何种缺陷和漏洞,欢迎大家批评指正。GPS软件要求的全部内容,希望文章能够帮你解决基于Arduino的GPS数据解析程序这篇博客讲了我利用arduino来解析和转发原始nema 0813数据的思想和实现方法。因为arduino比较简单,无法实现串口数据接收中断,所以都写在主循环里面了。不知道代码存在何种缺陷和漏洞,欢迎大家批评指正。GPS软件要求所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部