/** * @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; }
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; }
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; }