|
include "string.h"
#include "delay.h"
#include "uart.h"
#include "timer0.h"
#include "SIMxxx.h"
sbit P10=P1^0; //用于提示程序进行到哪里
sbit P11=P1^1; //用于提示程序进行到哪里
sbit RUNING_LED=P1^2; //程序中控制的LED灯
unsigned char xdata Display_GPGGA_Buffer[68]={0}; //用于储存GPGGA的数据
unsigned int k=0,qian_a=0,hou_a=0,qian_b=0,hou_b=0,qian_c=0,hou_c=0; //存储前后逗号的位置序号的变量
bit qian_OK=0; //已找出前面的逗号的标志变量
//bit First_Share_OK=0; //已开始LCD显示的标志变量
bit jiajian=1; //进行加或减的标志变量
//bit Page = 0;
bit Flag_Calc_GPGGA_OK = 0; //GPGGA完整有效的数据已收到的标志变量
//u8 NUM[][10]={"0030","0031","0032","0033","0034","0035","0036","0037","0038","0039"};//数字编码
//char a[10]={0,1,2,3,4,5,6,7,8,9};
//int x;
/************* 外部函数和变量声明*****************/
/*******************************************************************************
* 函数名 : main
* 描述 : 主函数
* 输入 :
* 输出 :
* 返回 :
* 注意 :
*******************************************************************************/
void main(void)
{
unsigned char i = 0;
u8 res;
Uart1Init();
Timer0Init();
EA=1; //开总中断
res=1;
P10=0;P11=0;
while(res)
{
res=sim900a_work_test();
}
res=1;
while(res)
{
res=sim900a_enmessage_mode_out();
}
P10=1;
res=1;
Delay_ms(10);
clrStruct();
while(1)
{
parseGpsBuffer();
if(Flag_Rec_Message==1)
{
Flag_Rec_Message=0;
res=SIM_HANDLE_MESSAGE_CMD();
if (
Flag_Calc_GPGGA_OK == 1
&& RX_Buffer[1] == 'G'
&& RX_Buffer[3] == 'G'
&& RX_Buffer[4] == 'G'
&& RX_Buffer[5] == 'A'
&& (RX_Buffer[28] == 'N'|| RX_Buffer[28] == 'S')
&& (RX_Buffer[41] == 'E'|| RX_Buffer[41] == 'W')
) //确认是否收到"GPGGA"这一帧完整有效的数据
if(res)
{
if(res==1)
{
RUNING_LED=1;
// if(res==1)
// {
// for(x=0;x<10;x++)
// {
// a[x]=NUM[x];
// }
// }
res=sim900a_send_chmessage("00310037003600380039003200380039003000310039","4F60597D00680065006C006C006F");
}
else if(res==2)
{
RUNING_LED=0;
// if(res==2)
// {
// for(x=0;x<10;x++)
// {
// a[x]=NUM[x];
// }
// }
res=sim900a_send_chmessage("00310037003600380039003200380039003000310039","4F60597D00680065006C006C006F");
}
}
}
}
}
void errorLog(int num)
{
while (1)
{
UartPrintf("ERROR");
UartPrintASCII(num+0x30);
UartPrintf("\r\n");
}
}
void parseGpsBuffer()
{
char *subString;
char *subStringNext;
char i = 0;
if (Save_Data.isGetData)
{
Save_Data.isGetData = false;
UartPrintf("**************\r\n");
UartPrintf(Save_Data.GPS_Buffer);
for (i = 0 ; i <= 6 ; i++)
{
if (i == 0)
{
if ((subString = strstr(Save_Data.GPS_Buffer, ",")) == NULL)
errorLog(1); //解析错误
}
else
{
subString++;
if ((subStringNext = strstr(subString, ",")) != NULL)
{
char usefullBuffer[2];
switch(i)
{
case 1:memcpy(Save_Data.UTCTime, subString, subStringNext - subString);break; //获取UTC时间
case 2:memcpy(usefullBuffer, subString, subStringNext - subString);break; //获取UTC时间
case 3:memcpy(Save_Data.latitude, subString, subStringNext - subString);break; //获取纬度信息
case 4:memcpy(Save_Data.N_S, subString, subStringNext - subString);break; //获取N/S
case 5:memcpy(Save_Data.longitude, subString, subStringNext - subString);break; //获取经度信息
case 6:memcpy(Save_Data.E_W, subString, subStringNext - subString);break; //获取E/W
default:break;
}
subString = subStringNext;
Save_Data.isParseData = true;
if(usefullBuffer[0] == 'A')
Save_Data.isUsefull = true;
else if(usefullBuffer[0] == 'V')
Save_Data.isUsefull = false;
}
else
{
errorLog(2); //解析错误
}
}
}
}
}
void printGpsBuffer()
{
if (Save_Data.isParseData)
{
Save_Data.isParseData = false;
UartPrintf("Save_Data.UTCTime = ");
UartPrintf(Save_Data.UTCTime);
UartPrintf("\r\n");
if(Save_Data.isUsefull)
{
Save_Data.isUsefull = false;
UartPrintf("Save_Data.latitude = ");
UartPrintf(Save_Data.latitude);
UartPrintf("\r\n");
UartPrintf("Save_Data.N_S = ");
UartPrintf(Save_Data.N_S);
UartPrintf("\r\n");
UartPrintf("Save_Data.longitude = ");
UartPrintf(Save_Data.longitude);
UartPrintf("\r\n");
UartPrintf("Save_Data.E_W = ");
UartPrintf(Save_Data.E_W);
UartPrintf("\r\n");
}
else
{
UartPrintf("GPS DATA is not usefull!\r\n");
}
}
}
|
评分
-
查看全部评分
|