Official reference client implementation for Cumulocity SmartREST on u-blox C027.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: operation/PollingThread.cpp
- Revision:
- 96:5dfdc8568e9f
- Parent:
- 95:010b0f7a0a1a
- Child:
- 97:ea056f6be2e8
--- a/operation/PollingThread.cpp Wed Apr 22 11:22:25 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -#include <stdio.h> -#include <ctype.h> -#include "PollingThread.h" -#include "lex.h" -#include "logging.h" - -bool PollingThread::handshake() -{ - int l = snprintf(buf2, SMARRESTBODY_SIZE, "%s", "80\r\n"); - l = snprintf(buf, SMARTREST_SIZE, getSmartRestFmt(), uri, l, buf2); - l = sock.sendAndReceive(buf, l, SMARTREST_SIZE); - if (l < 0) - return false; - size_t i = 0; - for (const char* p = skipHTTPHeader(buf); isalnum(*p); ++p, ++i) { - bayeuxId[i] = *p; - } - bayeuxId[i] = '\0'; - return bayeuxId[0]; -} - -bool PollingThread::subscribe() -{ - int l = snprintf(buf2, SMARRESTBODY_SIZE, "81,%s,/%s\r\n", bayeuxId, chn); - l = snprintf(buf, SMARTREST_SIZE, getSmartRestFmt(), uri, l, buf2); - l = sock.sendAndReceive(buf, l, SMARTREST_SIZE); - return l>=0; -} - -bool PollingThread::connect() -{ - int l = snprintf(buf2, SMARRESTBODY_SIZE, "83,%s\r\n", bayeuxId); - l = snprintf(buf, SMARTREST_SIZE, getSmartRestFmt(), uri, l, buf2); - l = sock.sendAndReceive(buf, l, SMARTREST_SIZE); - return l>=0; -} - -void PollingThread::threadFunc() -{ - uint8_t state = 1; - aInfo("Polling thread: %p\n", Thread::gettid()); - while (true) { - switch (state) { - case 1: if (!handshake()) { - aCritical("Poll: handshake fail!\n"); - break; - } - case 2: if(!subscribe()) { - aCritical("Poll: subscribe fail!\n"); - state = 1; - break; - } - case 3: if(!connect()) { - aCritical("Poll: connect fail!\n"); - state = 1; - break; - } - default: parser.handleControlMessage(buf); - if (parser.getBayeuxAdvice() == BA_HANDSHAKE) - state = 1; - else - state = 3; - } - } -} \ No newline at end of file