![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Cubic Hand project for EECS 249A course.
Dependencies: MMA8451Q TSI cc3000_hostdriver_mbedsocket NVIC_set_all_priorities mbed Multi_WS2811
Diff: GloveWifi.cpp
- Revision:
- 19:e751d075e2e6
- Parent:
- 15:b48ac00af0b8
- Child:
- 26:42ae7eed0b68
--- a/GloveWifi.cpp Mon Dec 08 18:56:42 2014 +0000 +++ b/GloveWifi.cpp Mon Dec 08 23:54:33 2014 +0000 @@ -12,7 +12,8 @@ #define ECHO_SERVER_PORT 2000 #define MMA8451_I2C_ADDRESS (0x1d<<1) -GloveWifi::GloveWifi() +GloveWifi::GloveWifi(): +DropCount(0) { } @@ -60,8 +61,8 @@ printf("Unable to connect to (%s) on port (%d) \r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); wait(1); } - socket->set_blocking(true); printf("Connected!\r\n"); + socket->set_blocking(false, 10); } @@ -82,14 +83,29 @@ printf("Unable to connect to (%s) on port (%d) \r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); wait(1); } - socket->set_blocking(true); + socket->set_blocking(false, 10); printf("Reconnected!\r\n"); } -uint8_t GloveWifi::GetDataFromBuffer(uint8_t * buf, uint16_t size) +int GloveWifi::GetDataFromBuffer(char * buf, int size) { //printf("Buffer Size: %d\r\n", wifi->_simple_link.get_transmit_error()); - return socket->receive((char *)buf, size); + int numR = 0; + numR = socket->receive((char *)buf, size); + if(numR == -1) + { + DropCount++; + }else + { + DropCount = 0; + } + if(DropCount > 200) + { + printf("!\r\n"); + Reconnect(); + DropCount = 0; + } + return numR; } uint8_t GloveWifi::SendDataToGlove(uint8_t * buf, uint16_t size)