Пример #1
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;
}
/**
*  @brief  Create Tcp client connection
*
*  @param  Server IP (string)
*  @param  Server Port (string)
*  @param  Function pointer to data handler function
*
*  @return Connection id
*/
uint8_t GS_API_CreateTcpClientConnection(char* serverIp, char* serverPort, 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_TcpClientStart((int8_t*) serverIp, (int8_t*) serverPort)))
     {
    	  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;
}