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 Vincent Wochnik

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ReportThread.cpp Source File

ReportThread.cpp

00001 #include "ReportThread.h"
00002 #include "logging.h"
00003 
00004 static const char *fmt2 = "111,%ld,%s\r\n";
00005 
00006 void ReportThread::threadFunc()
00007 {
00008     while (true) {
00009         dict.clear();
00010         osEvent e = ipool.get();
00011         if (e.status == osEventMail) {
00012             Operation *op = (Operation*)e.value.p;
00013             dict.set(op->identifier, op->state);
00014             ipool.free(op);
00015             while (!dict.full()) {
00016                 osEvent e = ipool.get(200);
00017                 if (e.status == osEventMail) {
00018                     op = (Operation*)e.value.p;
00019                     dict.set(op->identifier, op->state);
00020                     ipool.free(op);
00021                 } else {
00022                     break;
00023                 }
00024             }
00025             int l = 0;
00026             for (unsigned short i = 0; i < dict.size(); ++i) {
00027                 const long id = dict[i].identifier;
00028                 const OperationState state = dict[i].state;
00029                 l += snprintf(buf2+l, sizeof(buf2)-l, fmt2, id, strOperationState(state));
00030             }
00031             l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2);
00032             for (unsigned i = 0; i < 3; ++i) {
00033                 sock.setBlocking(3000);
00034                 int l2 = sock.sendOnly(buf, l);
00035                 if (l2 < 0) {
00036                     aError("Report: op state\n");
00037                     Thread::wait(3000);
00038                 } else {
00039                     break;
00040                 }
00041             }
00042         }
00043     }
00044 }