<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32通過(guò)GPRS與服務(wù)器建立TCP連接

          STM32通過(guò)GPRS與服務(wù)器建立TCP連接

          作者: 時(shí)間:2016-11-26 來(lái)源:網(wǎng)絡(luò) 收藏
          u16 USART3_CGREG_Cnt;

          u8 USART3_Task_Cnt;

          本文引用地址:http://www.ex-cimer.com/article/201611/321911.htm

          //task_GPRS為GPRS處理任務(wù),每50ms~200ms調(diào)用一次

          void task_GPRS()
          {
          switch(USART3_Task_Cnt)
          {
          case 0:
          // SendUartStr("case0",1);
          if(GprsState.bits.Timeout == true)
          {
          GprsState.Flag =0x00000000;
          {
          GPIO_InitTypeDef GPIO_InitStructure;

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_Init(GPIOC, &GPIO_InitStructure);
          //GPIO_SetBits(GPIOC, GPIO_Pin_9);
          GPIO_ResetBits(GPIOC, GPIO_Pin_9);
          SetGprsTime(3000);
          USART3_Task_Cnt = 1;
          }
          }
          break;
          case 1:
          // SendUartStr("case1",1);
          if(GprsState.bits.Timeout == true)
          {
          GPIO_InitTypeDef GPIO_InitStructure;

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_Init(GPIOC, &GPIO_InitStructure);
          GPIO_SetBits(GPIOC, GPIO_Pin_9);
          //GPIO_ResetBits(GPIOC, GPIO_Pin_9);
          SetGprsTime(1000);
          USART3_Task_Cnt = 2;
          }
          break;
          case 2:
          // SendUartStr("case2",1);
          if(GprsState.bits.Timeout == true)
          {
          GPIO_InitTypeDef GPIO_InitStructure;

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_Init(GPIOC, &GPIO_InitStructure);
          GPIO_SetBits(GPIOC, GPIO_Pin_8);
          //GPIO_ResetBits(GPIOC, GPIO_Pin_8);
          SetGprsTime(50);
          USART3_Task_Cnt = 3;
          }
          break;
          case 3:
          // SendUartStr("case3",1);
          if(GprsState.bits.Timeout == true)
          {
          GPIO_InitTypeDef GPIO_InitStructure;

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_Init(GPIOC, &GPIO_InitStructure);
          //GPIO_SetBits(GPIOC, GPIO_Pin_8);
          GPIO_ResetBits(GPIOC, GPIO_Pin_8);
          SetGprsTime(3000);
          USART3_Task_Cnt = 4;
          }
          break;
          case 4:
          if(GprsState.bits.Timeout == true)
          {
          // SendUartStr("AT+IPR=9600",3);
          // Delay(500);
          SendUartStr("AT+CREG=1",3);
          USART3_Task_Cnt = 5;
          SetGprsTime(4000);
          }
          break;
          case 5:
          if(GprsState.bits.Timeout == true)
          {
          SendUartStr("AT+CGREG=1",3);
          // USART3_Task_Cnt = 6;
          USART3_Task_Cnt = 7;
          USART3_CGREG_Cnt = 4000;
          SetGprsTime(1000);
          }
          break;
          case 6:
          // if(GprsState.bits.Timeout == true)
          // {
          // SendUartStr("AT+CREG?",3);
          // SendUartStr("AT+CGREG=1",3);
          // SendUartStr("AT+CGREG?",3);
          // if(GprsState.bits.AT_CGREG_OK == true)
          // {
          // USART3_Task_Cnt = 7;
          // SetGprsTime(5000);
          // }
          // else
          // {
          // USART3_CGREG_Cnt--;
          // if(USART3_CGREG_Cnt == 0)
          // {
          // USART3_Task_Cnt = 0;
          // }
          // }
          // }
          USART3_Task_Cnt = 7;
          break;
          case 7:
          if(GprsState.bits.Timeout == true)
          {
          SendUartStr("AT^SICS=0,conType,GPRS0",3);
          USART3_Task_Cnt = 8;
          SetGprsTime(100);
          }
          break;
          case 8:
          if(GprsState.bits.Timeout == true)
          {
          // SendUartStr("AT^SICS=0,user,gprs",3);
          USART3_Task_Cnt = 9;
          SetGprsTime(100);
          }
          break;
          case 9:
          if(GprsState.bits.Timeout == true)
          {
          // SendUartStr("AT^SICS=0,passwd,gprs",3);
          USART3_Task_Cnt = 10;
          SetGprsTime(100);
          }
          break;
          case 10:
          if(GprsState.bits.Timeout == true)
          {
          SendUartStr("AT^SICS=0,apn,"cmnet"",3);
          USART3_Task_Cnt = 11;
          SetGprsTime(100);
          }
          break;
          case 11:
          if(GprsState.bits.Timeout == true)
          {
          SendUartStr("AT^SISS=1,ConID,0",3);
          USART3_Task_Cnt = 12;
          SetGprsTime(100);
          }
          break;
          case 12:
          if(GprsState.bits.Timeout == true)
          {
          SendUartStr("AT^SISS=1,srvType,socket",3);
          USART3_Task_Cnt = 13;
          SetGprsTime(200);
          }
          break;
          case 13:
          if(GprsState.bits.Timeout == true)
          {
          SendUartStr("AT^SISS=1,address,"socktcp://118.244.164.188:7777"",3);
          USART3_Task_Cnt = 14;
          SetGprsTime(600);
          }
          break;
          case 14:
          if(GprsState.bits.Timeout == true)
          {
          SendUartStr("AT^SISO=1",3);
          USART3_Task_Cnt = 15;
          SetGprsTime(5000);
          GprsState.bits.Connect_Send_OK = false;
          }
          break;
          case 15:
          if(GprsState.bits.Connect_Send_OK == true)
          {
          GprsState.bits.Connect_Send_OK = false;
          USART3_Task_Cnt = 16;
          SendUartStr("Connect_OK!",1);
          }
          if(GprsState.bits.Timeout == true)
          {
          SendUartStr("AT^SISC=1",3);
          // USART3_Task_Cnt = 0;
          USART3_Task_Cnt = 7;
          SetGprsTime(3000);
          }
          break;
          case 16:
          // SendUartStr("AT^SISW=1,12",3);
          if(GprsState.bits.Timeout == true)
          {
          if(GPRSDataBuf.WaitSend == !0)
          {
          SendUartStr("AT^SISW=1,",3);
          SendUartByte((GPRSDataBuf.length)/10+0x30,3);
          SendUartByte((GPRSDataBuf.length)+0x30,3);
          SendUartStr("",3);
          USART3_Task_Cnt = 17;
          SetGprsTime(50);
          }
          }
          break;
          case 17:
          if(GprsState.bits.Timeout == true)
          {
          if(GPRSDataBuf.WaitSend == !0)
          {
          SendUartStr((char*)GPRSDataBuf.buf,3);
          SendUartStr("",3);
          USART3_Task_Cnt = 18;
          SetGprsTime(5000);
          }
          }
          break;
          case 18:
          if(GprsState.bits.Timeout == true)
          {
          // USART3_Task_Cnt = 0;
          SendUartStr("AT^SISC=1",3);
          USART3_Task_Cnt = 7;
          SetGprsTime(1000);
          }
          if(GprsState.bits.Connect_Send_OK == true)
          {
          GprsState.bits.Connect_Send_OK = false;
          GPRSDataBuf.SendOK = !0;
          GPRSDataBuf.WaitSend = 0;
          USART3_Task_Cnt = 16;
          SetGprsTime(1000);//發(fā)送間隔時(shí)間
          }
          break;
          case 19:

          break;

          default:
          break;
          }
          }



          關(guān)鍵詞: STM32GPRS服務(wù)器TCP連

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();