示例#1
0
void GS_API_CheckForData(void){
     uint8_t rxData;

     /* Read one byte at a time - Use non-blocking call */
     while (GS_HAL_recv(&rxData, 1, 0)) {
          /* Process the received data */
          switch(AtLib_ReceiveDataProcess(rxData)){
          case HOST_APP_MSG_ID_TCP_SERVER_CLIENT_CONNECTION:
          {
               uint8_t cidServerStr[] = " ";
               uint8_t cidClientStr[] = " ";
               uint8_t cidServer = GS_API_INVALID_CID;
               uint8_t cidClient = GS_API_INVALID_CID;

               if(AtLib_ParseTcpServerClientConnection((char *)cidServerStr, (char *)cidClientStr, tcpServerClientIp, tcpServerClientPort)){
                    cidServer = gs_api_parseCidStr(cidServerStr);
                    cidClient = gs_api_parseCidStr(cidClientStr);
                    gs_api_setCidDataHandler(cidClient, gs_api_getCidDataHandler(cidServer));
               }
               GS_API_Printf("TCP Server Client Connection %d, %d, %s, %s\r\n", cidServer, cidClient, tcpServerClientIp, tcpServerClientPort);
          }
          break;

          case HOST_APP_MSG_ID_RESPONSE_TIMEOUT:
          case HOST_APP_MSG_ID_NONE:
               // Do nothing
               break;

          default:
               break;
          }
     }
}
/**
*  @brief  Create Tcp Server Connection
*
*  @param  Host port (string)
*  @param  Function pointer to data handler function
*
*  @return Connection id
*/
uint8_t GS_API_CreateTcpServerConnection(char* port, GS_API_DataHandler cidDataHandler){
     uint8_t cidStr[] = " ";
     uint16_t cid = GS_API_INVALID_CID;
 	 unsigned int response_timeout_temp;

   	 response_timeout_temp = GS_Api_GetResponseTimeoutHandle();
 	 GS_Api_SetResponseTimeoutHandle(TIMEOUT_RESPONSE_INTERVAL_HIGH);

     if(!gs_api_handle_cmd_resp(AtLibGs_TcpServer_Start((int8_t*)port)))
     {
    	  GS_Api_SetResponseTimeoutHandle(response_timeout_temp);
          return cid;
     }

     if(AtLib_ParseTcpServerStartResponse(cidStr)){
          // need to convert from ASCII to numeric
          cid = gs_api_parseCidStr(cidStr);
          if(cid != GS_API_INVALID_CID){
               cidDataHandlers[cid] = cidDataHandler;
          }
     }

     GS_Api_SetResponseTimeoutHandle(response_timeout_temp);
     return cid;
}
/**
*  @brief  Parse cid in DISCONNECT response
*
*  Should be called when DISCONNECT message is caught.
*  Parses response and returns cid.
*
*  @return Connection id
*/
uint8_t GS_Api_ParseDisconnectCid(){
	uint8_t cidStr[] = " ";
	uint8_t cid = GS_API_INVALID_CID;

    if(AtLib_ParseTcpServerStartResponse(cidStr))
    {
         // need to convert from ASCII to numeric
         cid = gs_api_parseCidStr(cidStr);
    }
    return cid;
}
示例#4
0
uint8_t GS_API_CreateUdpClientConnection(char* serverIp, char* serverPort, char* localPort, GS_API_DataHandler cidDataHandler){
     uint8_t cidStr[] = " ";
     uint16_t cid = GS_API_INVALID_CID;

     if(!gs_api_handle_cmd_resp(AtLibGs_UdpClientStart((int8_t*) serverIp, (int8_t*) serverPort, (int8_t*) localPort)))
          return cid;

     if(AtLib_ParseUdpServerStartResponse(cidStr)){
          // need to convert from ASCII to numeric
          cid = gs_api_parseCidStr(cidStr);
          if(cid != GS_API_INVALID_CID){
               cidDataHandlers[cid] = cidDataHandler;
          }
     }

     return cid;
}
示例#5
0
uint8_t GS_API_CreateTcpServerConnection(char* port, GS_API_DataHandler cidDataHandler){
     uint8_t cidStr[] = " ";
     uint16_t cid = GS_API_INVALID_CID;

     if(!gs_api_handle_cmd_resp(AtLibGs_TcpServer_Start((int8_t*)port))) {
          return cid;
	}
   
     if(AtLib_ParseTcpServerStartResponse(cidStr)){
          // need to convert from ASCII to numeric
          cid = gs_api_parseCidStr(cidStr);
          if(cid != GS_API_INVALID_CID){
               cidDataHandlers[cid] = cidDataHandler;
         }
     }
  
     return cid;
}
示例#6
0
uint8_t GS_API_CreateTcpClientConnection(char* serverIp, char* serverPort, GS_API_DataHandler cidDataHandler){
     uint8_t cidStr[] = " ";
     uint16_t cid = GS_API_INVALID_CID;

     if(!gs_api_handle_cmd_resp(AtLibGs_TcpClientStart((int8_t*) serverIp, (int8_t*) serverPort))) {
	  printf("ERROR: WIFI TCP CLIENT SETUP ERROR.\n");
          return cid;
	}

     if(AtLib_ParseTcpServerStartResponse(cidStr)){
          // need to convert from ASCII to numeric
          cid = gs_api_parseCidStr(cidStr);
          if(cid != GS_API_INVALID_CID){
               cidDataHandlers[cid] = cidDataHandler;
          }
     }

     return cid;
}