Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: operation/PollThread.cpp
- Revision:
- 134:c4009ecaf5c0
- Parent:
- 129:dc9e37d4bc05
--- a/operation/PollThread.cpp Fri Aug 07 12:55:27 2015 +0000 +++ b/operation/PollThread.cpp Mon Aug 10 14:18:05 2015 +0000 @@ -3,6 +3,7 @@ #include "PollThread.h" #include "logging.h" + bool PollThread::handshake() { int l = snprintf(buf2, sizeof(buf2), "%s", "80\r\n"); @@ -20,6 +21,7 @@ return bayeuxId[0]; } + bool PollThread::subscribe() { int l = snprintf(buf2, sizeof(buf2), "81,%s,%s\r\n", bayeuxId, chn); @@ -33,6 +35,7 @@ return *p == 0; } + bool PollThread::connect() { int l = snprintf(buf2, sizeof(buf2), "83,%s\r\n", bayeuxId); @@ -52,25 +55,20 @@ } // Avoid heartbeat message overflows the buffer l = 0; - for (unsigned short i = 0; i < 200; ++i) { + for (unsigned short i = 0; i < 300; ++i) { int l2 = sock.receive(buf+l, sizeof(buf)-l); - printf("l2: %d\n", l2); if (l2 > 0) { - printf("poll: %.*s\n", l2, buf+l); l += l2; - } else if (!sock.is_connected()) { - break; } else { - l = l2; break; } } - if (l >= 0) - buf[l] = 0; sock.close(); + buf[l] = 0; return l>0; } + void PollThread::threadFunc() { unsigned short state = 1; @@ -87,10 +85,9 @@ } case 3: if(!connect()) { aCritical("Poll: connect fail!\n"); - state = 1; break; } - default: parser.parse(buf); + parser.parse(buf); if (parser.getBayeuxAdvice() == BA_HANDSHAKE) state = 1; else