void* DataUpdateThread(void*) { TCPClientConnect((char*)"192.168.1.141",1234); while(true) { if(runFlag == true) { // // Get some new data. // #if 0 static uint32_t iteration = 0; iteration++; for(uint32_t k=0; k<sizeof(data)-1; k++) { data[k] = data[k+1]; } if(iteration%5 == 0) { data[sizeof(data)-1] = rand(); } #else TCPRead( &data[0], sizeof(data) ); #endif } usleep(1000000/100); } }
/*** int TCPSocket::readStream(byte *rgbRead, size_t cbReadMax) ** ** Synopsis: ** Reads an array of bytes from the socket buffer (and removes the bytes from the socket) ** ** Parameters: ** rgbRead A pointer to a buffer to receive the bytes. ** ** cbReadMax The maximum size of rgbPeek ** ** pStatus A pointer to receive the status of the call, usually the connection status. ** ** Return Values: ** The actual number of bytes read. 0 is returned if no bytes were read or an error occured. ** ** Errors: ** No bytes to read, or a connection error. ** ** Notes: ** ** This call is safe to make without checking the connection status. ** */ size_t TCPSocket::readStream(byte *rgbRead, size_t cbReadMax) { size_t cbReady = 0; if( (cbReady = available()) > 0 ) { cbReady = cbReady < cbReadMax ? cbReady : cbReadMax; return(TCPRead(&_socket, rgbRead, cbReady, NULL)); } return(0); }
/*** int TCPSocket::readByte(void) ** ** Synopsis: ** Reads the next available byte out of the socket buffer (removing the byte from the socket) ** ** Parameters: ** ** pStatus A pointer to receive the status of the call, usually the connection status. ** ** Return Values: ** The actual byte, casted to an integer. -1 is returned if no byte was returned or an error occured. ** ** Errors: ** Nothing to read, or a connection error. ** ** Notes: ** ** This call is safe to make without checking the connection status. ** */ int TCPSocket::readByte(void) { byte bData = 0; // this will run the stack tasks if(available() > 0 && TCPRead(&_socket, &bData, 1, NULL) ) { return((int) bData); } return(-1); }
/** * Reads data form http socket * \param sock TCP_SOCKET to use. <I>Please, remember to use the "&" operator</I> * \param dataBuffer data buffer to fill * \param datalen amount of BYTEs to read * \return None */ void HTTPReadData(TCP_SOCKET* sock, char* dataBuffer, int datalen) { httpReadBuffer = dataBuffer; httpReadBufferCount = datalen; TCPRead(sock, httpReadBuffer, httpReadBufferCount); }
/** * Reads the specified number of characters from a FTP socket and puts them into the specified char array * \param ftpsockread - The handle of the socket to read (the handle returned by the command FTPClientOpen). * \param ftpreadch - The char array to fill with the read characters. * \param ftprlen - The number of characters to read. * \warning The length of the array must be AT LEAST = ftprlen+1, because at the end of the operation the array it's automatically NULL terminated (is added the '\0' character). * \return None. */ void FTPRead(TCP_SOCKET ftpsockread , char ftpreadch[] , int ftprlen) { TCPRead(ftpsockread , ftpreadch , ftprlen); }
BOOL XivelyPut(TCP_SOCKET MySocket, char* tmpString) { char resString[250]; BOOL result; int i; static ROM char GoodHTTPResponse[] = "{\"status\":200"; #if defined(STACK_USE_UART) UARTWrite(1,tmpString); #endif // Send the blob TCPWrite( MySocket, tmpString, (int)strlen(tmpString) ); #if defined(STACK_USE_UART) UARTWrite(1,"Data sent, Waiting response.\r\n"); #endif vTaskDelay(500); // Make sure there are enough chars to read i = 10; while (i>0 && (TCPRxLen(MySocket) < 16)) { //vTaskDelay( xDelay(500) ); vTaskDelay(500); i--; } if(i!=0) { // Get the response from the server TCPRead( MySocket, resString, 250 ); #if defined(STACK_USE_UART) UARTWrite(1,resString); UARTWrite(1,"\r\n"); #endif if (strstr( resString, GoodHTTPResponse) == NULL) { // We are in an error condition, so light up the Flyport led result = FALSE; #if defined(STACK_USE_UART) UARTWrite(1,"Request failed.\r\n"); #endif } else { #if defined(STACK_USE_UART) UARTWrite(1,"Request succeeded.\r\n"); #endif result = TRUE; } } else { #if defined(STACK_USE_UART) UARTWrite(1,"Server did not reply.\r\n"); #endif result = FALSE; } vTaskDelay(500); return result; }