Host library for controlling a WiConnect enabled Wi-Fi module.
Dependents: wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more
Diff: internal/wiconnect/ProcessCommand.cpp
- Revision:
- 17:7268f365676b
- Parent:
- 16:7f1d6d359787
- Child:
- 21:17bb3eddcbae
diff -r 7f1d6d359787 -r 7268f365676b internal/wiconnect/ProcessCommand.cpp --- a/internal/wiconnect/ProcessCommand.cpp Wed Aug 13 04:41:04 2014 -0700 +++ b/internal/wiconnect/ProcessCommand.cpp Sat Aug 23 05:39:17 2014 -0700 @@ -240,7 +240,15 @@ RESET_CMD_HEADER(header); } else - { + { + if(packetLen > 0) + { + if(packetLen == 1 || packetLen == 2) + { + return WICONNECT_CMD_RESPONSE_ERROR; + } + packetLen -= 2; + } if((int)packetLen > context->responseBufferLen) { DEBUG_ERROR("Packet larger than response buffer: %d > %d", packetLen, context->responseBufferLen); @@ -294,7 +302,16 @@ } else if(context->bytesToRead == 0) { - *context->responseBufferPtr = 0; + *context->responseBufferPtr = 0; + + // read the trailing \r\n + char trailingCRLF[2]; + const int bytesReceived = serial.read(trailingCRLF, 2, 100); + // FIXME there's a potenital weakness where the trailing \r\n isn't ready to be recieved + if(bytesReceived != 2) + { + return WICONNECT_TIMEOUT; + } } }