QT笔记:通过GPRS获取网络时间
1.ARM开发板通过向GPRS模块写指令获取网络时间:
/*连接阿里云时间同步服务器,用以获取时间*/
while(!gprs_send_cmd("AT\n","OK",1,1000));//同步波特率
while(!gprs_send_cmd("AT+CGATT?\n","+CGATT: 1",1,1000)); //查看网络附着状态
while(!gprs_send_cmd("AT+SAPBR=3,1,CONTYPE,GPRS\n","OK",1,100));//开启场景
while(!gprs_send_cmd("AT+SAPBR=3,1,APN,CMNET\n","OK",1,500));//设置APN为移动
while(!gprs_send_cmd("AT+SAPBR=1,1\n","OK",1,200));
while(!gprs_send_cmd("AT+SAPBR=2,1\n","OK",1,600));
while(!gprs_send_cmd("AT+CNTP=ntp1.aliyun.com,32\n","OK",1,200));//阿里云时间同步服务器
while(!gprs_send_cmd("AT+CNTP\n","+CNTP: 1",1,2000));
while(!gprs_send_cmd("AT+CCLK?\n","+CCLK:",1,2000));//获取时间信息
GPRS返回的时间格式:04/01/01,00:02:56+00
下面要对它进行解析
2.解析网络时间格式,并送给系统时钟:
/*************时间格式转换********************/
void hardware_cmd::data_process()//时间转换
{
bool ok;
QStringList str2;
int
来源:CSDN
作者:徐腾腾不加班
链接:https://blog.csdn.net/qq_33033059/article/details/89677699