⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 at.lst

📁 基于STC51通过GPS自主定位导航FAT文件系统程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
             -***************
 438          //函数作用:分析AT消息
 439          //参数说明:无
 440          //注意事项:
 441          //返回说明:
 442          //********************************************************************************************************
             -***************
 443          static void at_parse_msg(void)
 444          {       
 445   1              at_msglist_t *list;
 446   1              
 447   1              //数据包列表中查找并且调用相应处理函数
 448   1              for(list=at_msglist;list->cmdstr!=NULL;list++)
 449   1              {               
 450   2                      //找到了以后 调用相应函数
 451   2                      if(str_comprise(at_receive_buffer,list->cmdstr))
 452   2                      {
 453   3                              list->callback();//调用相应函数
 454   3                              return;
 455   3                      }
 456   2              }
 457   1      }
 458          
 459          //********************************************************************************************************
             -***************
 460          //函数作用:处理AT回应数据包
 461          //参数说明:无
 462          //注意事项:
 463          //返回说明:无
 464          //********************************************************************************************************
             -***************
 465          static void ATAnalyse(void)
 466          {
 467   1              if(!at_get_msg())return;//接收消息
 468   1              
 469   1              //if(at_debug==1)//调试信息
 470   1              //{
 471   1              //      print_line(at_receive_buffer);
C51 COMPILER V7.20   AT                                                                    11/03/2007 17:08:50 PAGE 9   

 472   1              //}
 473   1              
 474   1              at_parse_msg();//分析消息
 475   1      }
 476          
 477          //*****************************************************************************************
 478          //函数作用:等待回应
 479          //参数说明:
 480          //注意事项:
 481          //返回说明:如果等到OK返回1
 482          //*****************************************************************************************
 483          static uchar at_wait_ack(uint wait_time, uchar ack_no)
 484          {       
 485   1              at_ack=0;
 486   1              while(!at_ack)//等返回
 487   1              {
 488   2                      mdelay(20);
 489   2                      ATAnalyse();
 490   2                      if(wait_time&0x01)LED_CTRL=!LED_CTRL;
 491   2                      if(--wait_time==0)break;//超时退出
 492   2              }
 493   1                      
 494   1              if(at_ack==ack_no)return 1;
 495   1              return 0;
 496   1      }
 497          
 498          //*****************************************************************************************
 499          //函数作用:等待ok
 500          //参数说明:
 501          //注意事项:
 502          //返回说明:如果等到OK返回1
 503          //*****************************************************************************************
 504          static uchar at_wait_ok(void)
 505          {
 506   1              return at_wait_ack(500,AT_ACK_OK);
 507   1      }
 508          
 509          //********************************************************************************************************
             -***************
 510          //函数作用:发送AT命令
 511          //参数说明:
 512          //注意事项:
 513          //返回说明:
 514          //********************************************************************************************************
             -***************
 515          static void at_send_command(uchar *command, uchar *param)
 516          {
 517   1              AT_SEND_STR(AT_CMD_HEAD);
 518   1              AT_SEND_STR(command);
 519   1              AT_SEND_STR(param);
 520   1              AT_SEND_STR(AT_CMD_END);
 521   1      }
 522          
 523          //********************************************************************************************************
             -***************
 524          //函数作用:发送AT命令并且等待OK
 525          //参数说明:
 526          //注意事项:
 527          //返回说明:如果等到ok 返回1
 528          //********************************************************************************************************
             -***************
 529          static uchar at_send_command_waitok(uchar *command, uchar *param)
C51 COMPILER V7.20   AT                                                                    11/03/2007 17:08:50 PAGE 10  

 530          {               
 531   1              at_send_command(command,param);
 532   1              return(at_wait_ok());
 533   1      }
 534          
 535          //*****************************************************************************************
 536          //函数作用:发送短信息
 537          //参数说明:
 538          //注意事项:
 539          //返回说明:
 540          //*****************************************************************************************
 541          uchar ATSendSMS(uchar *dest_no, uchar *content_buf, uchar data_coding)
 542          {
 543   1              uint length;
 544   1              uchar i;
 545   1              uchar MoveTemp;
 546   1              uchar temp_buf[16];
 547   1      
 548   1              if(at_reset)return 0;
 549   1              delay(1);//防止连续发送短信
 550   1              
 551   1              //发送头
 552   1              AT_SEND_STR(AT_CMD_HEAD);
 553   1              AT_SEND_STR(AT_CMD_SENDSMS);
 554   1              //发送PDU包长度
 555   1              length=str_length(dest_no);//对方号码长度
 556   1              if(length&0x01)length++;//修正奇偶
 557   1              length+=20;//其他字节固定长度
 558   1              if(data_coding==0x00)//英文
 559   1              {               
 560   2                      i=0;
 561   2                      while(content_buf[i]!=0)
 562   2                      {
 563   3                              MoveTemp=content_buf[i+1]<<(7-i%8);
 564   3                              MoveTemp+=(content_buf[i]>>i%8);
 565   3                              i++;
 566   3                              length+=2;
 567   3                              if(((i+1)%8)==0)if(content_buf[i])i++;
 568   3                      }
 569   2              }
 570   1              else if(data_coding==0x08)//中文
 571   1              {
 572   2                      length+=str_length(content_buf);
 573   2              }
 574   1              int_to_dec(temp_buf,(length>>1)-1);//转化为十进制 并且修正为字节长度 然后减1
 575   1              AT_SEND_STR(temp_buf);//发送
 576   1              
 577   1              AT_SEND_CHAR('\r');
 578   1              
 579   1              //等待 "> "
 580   1              mdelay(100);
 581   1              
 582   1              //状态报告码
 583   1              AT_SEND_STR("001100");
 584   1              //号码长度
 585   1              length=str_length(dest_no)+2;//号码长度+86的长度
 586   1              char_to_hex(temp_buf,length);//转化为hex字符串
 587   1              AT_SEND_STR(temp_buf);//发送
 588   1              //号码属性--国际号码
 589   1              AT_SEND_STR("91");//发送
 590   1              //号码内容 奇偶数修正-F 并且高低字节对调
 591   1              str_copy(temp_buf,"86");//国家代码--中国地区
C51 COMPILER V7.20   AT                                                                    11/03/2007 17:08:50 PAGE 11  

 592   1              str_cat(temp_buf,dest_no);//拷贝号码
 593   1              if(length&0x01)str_cat(temp_buf,"F");//修正奇偶
 594   1              swap_low4_and_high4(temp_buf,length);//高低字节对调
 595   1              AT_SEND_STR(temp_buf);//发送
 596   1              //PID
 597   1              AT_SEND_STR("00");
 598   1              //编码方式
 599   1              char_to_hex(temp_buf,data_coding);//转化为hex字符串
 600   1              AT_SEND_STR(temp_buf);//发送
 601   1              //有效期
 602   1              AT_SEND_STR("8F");//发送
 603   1              //内容长度
 604   1              length=str_length(content_buf);//计算内容缓冲区长度
 605   1              if(data_coding==0x08)length>>=1;//如果是中文把字符串长度转化字节长度--除以2
 606   1              char_to_hex(temp_buf,length);//转化为hex字符串
 607   1              AT_SEND_STR(temp_buf);//发送
 608   1              //真正的内容
 609   1              if(data_coding==0x00)//英文
 610   1              {               
 611   2                      uchar MoveTemp;
 612   2                      uchar i=0,j=0;
 613   2                      while(content_buf[i]!=0)
 614   2                      {
 615   3                              MoveTemp=content_buf[i+1]<<(7-i%8);
 616   3                              MoveTemp+=(content_buf[i]>>i%8);
 617   3                              Bcd2Char(temp_buf,MoveTemp);//转化为hex
 618   3                              AT_SEND_STR(temp_buf);//发送
 619   3                              i++;
 620   3                              j+=2;
 621   3                              if(((i+1)%8)==0)if(content_buf[i])i++;
 622   3                      }
 623   2              }
 624   1              else if(data_coding==0x08)//中文
 625   1              {
 626   2                      AT_SEND_STR(content_buf);//发送
 627   2              }
 628   1              
 629   1              //发送结束符
 630   1              AT_SEND_CHAR(0x1A);
 631   1              
 632   1              //等待发送成功
 633   1              if(!at_wait_ack(1000,AT_ACK_OK))goto error;
 634   1              return 1;
 635   1      
 636   1      error:
 637   1              at_reset=1;
 638   1              return 0;
 639   1      }
 640          
 641          //********************************************************************************************************
             -***************
 642          //函数作用:应答电话
 643          //参数说明:
 644          //注意事项:
 645          //返回说明:如果等到 返回1
 646          //********************************************************************************************************
             -***************
 647          uchar ATAnswer(void)
 648          {
 649   1              if(at_send_command_waitok(AT_CMD_ANSWER,""))
 650   1              {
 651   2                      ring=0;
C51 COMPILER V7.20   AT                                                                    11/03/2007 17:08:50 PAGE 12  

 652   2                      calling=1;
 653   2                      return 1;
 654   2              }
 655   1              return 0;
 656   1      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -