完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
试过直接用if(S2==0)放在void sendDataToServer()后面判断按键的方法不行 #include "main.h" #include "uart.h" #include "LCD1602.h" #include #include #include #include //常量 #define Success 1U #define Failure 0U //定义变量 unsigned long time_Cont = 0; //定时器计数器 _SaveData Save_Data; ***it s2=P2^2; code char TCPServer[] = "120.79.207.145"; //TCP服务器地址 code char Port[] = "80"; //端口 code char Port2[] = "8000"; //端口2 char flagConnect = 0; //**************************************************** //主函数 //**************************************************** void main() { unsigned char i = 0; Uart_Init(); delay_ms(10); Init_LCD1602(); LCD1602_write_com(0x80); LCD1602_write_word("Welcome to "); LCD1602_write_com(0x80+0x40); LCD1602_write_word(" Rescue system"); clrStruct(); //清空缓存数组 if (sendCommand("ATrn", "OKrn", 3000, 10) == Success); else errorLog(); delay_ms(10); if (sendCommand("AT+CPIN?rn", "READY", 1000, 10) == Success); else errorLog(); delay_ms(10); if (sendCommand("AT+CREG?rn", ",1", 1000, 10) == Success); else { delay_ms(10); if (sendCommand("AT+CREG?rn", ",5", 1000, 10) == Success); else errorLog(); } if (sendCommand("AT+QGNSSC?rn", "+QGNSSC: 1", 1000, 1) == Success); else if (sendCommand("AT+QGNSSC=1rn", "OKrn", 100, 10) == Success); else errorLog(); if (sendCommand("AT+QICLOSErn", "rn", 5000, 10) == Success); else errorLog(); delay_ms(100); if (sendCommand("AT+QIDEACTrn", "rn", 5000, 10) == Success); else errorLog(); while(1) { if (sendCommand("AT+QGNSSRD="NMEA/RMC"rn", "OKrn", 2000, 10) == Success); else errorLog(); Save_Data.isGetData = true; memset(Save_Data.GPS_Buffer, 0, 120); //清空 memcpy(Save_Data.GPS_Buffer, Rec_Buf, point1); parseGpsBuffer(); printGpsBuffer(); delay_ms(4000); } } void sendDataToServer() { xdata char send_buf[100] = {0}; memset(send_buf, 0, 100); //清空 if(s2==0) { if(flagConnect == 0) { flagConnect = 1; strcpy(send_buf, "AT+QIOPEN="TCP",""); strcat(send_buf, TCPServer); strcat(send_buf, "",""); strcat(send_buf, Port2); strcat(send_buf, ""rn"); if (sendCommand(send_buf, "CONNECT OK", 10000, 5) == Success); else errorLog(); delay_ms(100); } //发送数据 if (sendCommand("AT+QISENDrn", ">", 3000, 5) == Success); else errorLog(); delay_ms(1000); memset(send_buf, 0, 100); //清空 {sprintf(send_buf,"%s N,%s E ID01 SOSrn", Save_Data.latitude,Save_Data.longitude );} Init_LCD1602(); LCD1602_write_com(0x80); LCD1602_write_word("Message has "); LCD1602_write_com(0x80+0x40); LCD1602_write_word(" been sent "); if (sendCommand(send_buf, send_buf, 3000, 1) == Success); else errorLog(); delay_ms(10); SendData(0x1a);//发送数据 } else { if(flagConnect == 0) { flagConnect = 1; strcpy(send_buf, "AT+QIOPEN="TCP",""); strcat(send_buf, TCPServer); strcat(send_buf, "",""); strcat(send_buf, Port); strcat(send_buf, ""rn"); if (sendCommand(send_buf, "CONNECT OK", 10000, 5) == Success); else errorLog(); delay_ms(100); } //发送数据 if (sendCommand("AT+QISENDrn", ">", 3000, 5) == Success); else errorLog(); delay_ms(1000); memset(send_buf, 0, 100); //清空 {sprintf(send_buf,"%s N,%s E ID01rn", Save_Data.latitude,Save_Data.longitude); } if (sendCommand(send_buf, send_buf, 3000, 1) == Success); else errorLog(); delay_ms(10); SendData(0x1a);}//发送数据 // if (sendCommand("AT+QICLOSErn", "OKrn", 5000, 10) == Success); // else errorLog(); // delay_ms(100); // // if (sendCommand("AT+QIDEACTrn", "OKrn", 5000, 10) == Success); // else errorLog(); } |
|
相关推荐
1个回答
|
|
void errorLog() { while (1) { if (sendCommand("ATrn", "OKrn", 100, 10) == Success) { soft_reset(); } delay_ms(200); } } void soft_reset(void) //制造重启命令 { ((void (code *) (void)) 0x0000) (); } unsigned int sendCommand(char *Command, char *Response, unsigned long Timeout, unsigned char Retry) { unsigned char n; CLR_Buf(); for (n = 0; n < Retry; n++) { SendString(Command); //发送GPRS指令 Time_Cont = 0; while (Time_Cont < Timeout) { delay_ms(100); Time_Cont += 100; if (strstr(Rec_Buf, Response) != NULL) { return Success; } } Time_Cont = 0; } CLR_Buf(); return Failure; } void parseGpsBuffer() { char *subString; char *subStringNext; char i = 0; if (Save_Data.isGetData) { Save_Data.isGetData = false; // SendString("**************rn"); // SendString(Save_Data.GPS_Buffer); for (i = 0 ; i <= 6 ; i++) { if (i == 0) { if ((subString = strstr(Save_Data.GPS_Buffer, ",")) == NULL) errorLog(); //解析错误 } 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; case 3: memset(Save_Data.latitude, 0, latitude_Length); memcpy(Save_Data.latitude, subString, subStringNext - subString);break; //获取纬度信息 case 4: memset(Save_Data.N_S, 0, N_S_Length); memcpy(Save_Data.N_S, subString, subStringNext - subString);break; //获取N/S case 5: memset(Save_Data.longitude, 0, longitude_Length); memcpy(Save_Data.longitude, subString, subStringNext - subString);break; //获取经度信息 case 6: memset(Save_Data.E_W, 0, E_W_Length); 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(); //解析错误 } } } } } void printGpsBuffer() { if (Save_Data.isParseData) { Save_Data.isParseData = false; // SendString("Save_Data.UTCTime = "); // SendString(Save_Data.UTCTime); // SendString("rn"); if(Save_Data.isUsefull) { // Save_Data.isUsefull = false; // SendString("Save_Data.latitude = "); // SendString(Save_Data.latitude); // SendString("rn"); // // // SendString("Save_Data.N_S = "); // SendString(Save_Data.N_S); // SendString("rn"); // // SendString("Save_Data.longitude = "); // SendString(Save_Data.longitude); // SendString("rn"); // // SendString("Save_Data.E_W = "); // SendString(Save_Data.E_W); // SendString("rn"); LCD1602_write_com(0x80); LCD1602_write_word(Save_Data.latitude); LCD1602_write_data(' '); LCD1602_write_word(Save_Data.N_S); LCD1602_write_word(" "); LCD1602_write_com(0x80+0x40); LCD1602_write_word(Save_Data.longitude); LCD1602_write_data(' '); LCD1602_write_word(Save_Data.E_W); LCD1602_write_word(" "); sendDataToServer(); } else { // SendString("GPS DATA is not usefull!rn"); LCD1602_write_com(0x80); LCD1602_write_word("GPS DATA is "); LCD1602_write_com(0x80+0x40); LCD1602_write_word(" not usefull "); } } } void clrStruct() { Save_Data.isGetData = false; Save_Data.isParseData = false; Save_Data.isUsefull = false; memset(Save_Data.GPS_Buffer, 0, GPS_Buffer_Length); //清空 // memset(Save_Data.UTCTime, 0, UTCTime_Length); memset(Save_Data.latitude, 0, latitude_Length); memset(Save_Data.N_S, 0, N_S_Length); memset(Save_Data.longitude, 0, longitude_Length); memset(Save_Data.E_W, 0, E_W_Length); } //**************************************************** //MS延时函数 //**************************************************** void delay_ms(unsigned int n) { unsigned int i,j; for(i=0;i } |
|
|
|
只有小组成员才能发言,加入小组>>
物联网工程师必备:怎么选择不同的无线连接技术,本指南帮你忙!
3270 浏览 1 评论
【DFRobot TinkerNode NB-IoT 物联网开发板试用连载】WIFI功能测试
3919 浏览 0 评论
【DFRobot TinkerNode NB-IoT 物联网开发板试用连载】Arduino的替代SublimeText3+STino
3427 浏览 0 评论
使用端口扩展器轻松高效地向IIoT端点添加具有成本效益的子节点
3979 浏览 1 评论
20652 浏览 11 评论
模组有时候复位重启后输出日志为“REBOOT_CAUSE_SECURITY_PMU_POWER_ON_RESET”的原因?
764浏览 2评论
949浏览 2评论
974浏览 1评论
1092浏览 1评论
368浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-2 23:21 , Processed in 1.155517 second(s), Total 82, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号