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
operation/ReportThread.h@109:2ec12f10ebf4, 2015-05-13 (annotated)
- Committer:
- xinlei
- Date:
- Wed May 13 13:54:17 2015 +0000
- Revision:
- 109:2ec12f10ebf4
- Parent:
- 106:c61f0d62b625
- Child:
- 116:4eb3c7e945cf
ReportThread now merges pending state before report.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xinlei | 94:61d44636f020 | 1 | #ifndef REPORTTHREAD_H |
xinlei | 94:61d44636f020 | 2 | #define REPORTTHREAD_H |
xinlei | 94:61d44636f020 | 3 | #include "Operation.h" |
xinlei | 94:61d44636f020 | 4 | #include "SmartRestConf.h" |
xinlei | 109:2ec12f10ebf4 | 5 | #include "SmartRestSocket.h" |
xinlei | 109:2ec12f10ebf4 | 6 | #define OPERATION_DICT_SIZE 10 |
xinlei | 109:2ec12f10ebf4 | 7 | |
xinlei | 109:2ec12f10ebf4 | 8 | class OperationDict |
xinlei | 109:2ec12f10ebf4 | 9 | { |
xinlei | 109:2ec12f10ebf4 | 10 | public: |
xinlei | 109:2ec12f10ebf4 | 11 | OperationDict(): count(0) {} |
xinlei | 109:2ec12f10ebf4 | 12 | const Operation& operator [](unsigned short i) const { return opl[i]; } |
xinlei | 109:2ec12f10ebf4 | 13 | Operation *set(long id, OperationState state) { |
xinlei | 109:2ec12f10ebf4 | 14 | unsigned short i = 0; |
xinlei | 109:2ec12f10ebf4 | 15 | for (; i < count; ++i) { |
xinlei | 109:2ec12f10ebf4 | 16 | if (opl[i].identifier == id) |
xinlei | 109:2ec12f10ebf4 | 17 | break; |
xinlei | 109:2ec12f10ebf4 | 18 | } |
xinlei | 109:2ec12f10ebf4 | 19 | if (i < count) { |
xinlei | 109:2ec12f10ebf4 | 20 | opl[i].identifier = id; |
xinlei | 109:2ec12f10ebf4 | 21 | opl[i].state = state; |
xinlei | 109:2ec12f10ebf4 | 22 | return &opl[i]; |
xinlei | 109:2ec12f10ebf4 | 23 | } else if (count < OPERATION_DICT_SIZE) { |
xinlei | 109:2ec12f10ebf4 | 24 | opl[i].identifier = id; |
xinlei | 109:2ec12f10ebf4 | 25 | opl[i].state = state; |
xinlei | 109:2ec12f10ebf4 | 26 | ++count; |
xinlei | 109:2ec12f10ebf4 | 27 | return &opl[i]; |
xinlei | 109:2ec12f10ebf4 | 28 | } else |
xinlei | 109:2ec12f10ebf4 | 29 | return NULL; |
xinlei | 109:2ec12f10ebf4 | 30 | |
xinlei | 109:2ec12f10ebf4 | 31 | } |
xinlei | 109:2ec12f10ebf4 | 32 | void clear() { count = 0; } |
xinlei | 109:2ec12f10ebf4 | 33 | bool full() const { return count >= OPERATION_DICT_SIZE; } |
xinlei | 109:2ec12f10ebf4 | 34 | unsigned short size() const { return count; } |
xinlei | 109:2ec12f10ebf4 | 35 | virtual ~OperationDict() {} |
xinlei | 109:2ec12f10ebf4 | 36 | private: |
xinlei | 109:2ec12f10ebf4 | 37 | unsigned short count; |
xinlei | 109:2ec12f10ebf4 | 38 | Operation opl[OPERATION_DICT_SIZE]; |
xinlei | 109:2ec12f10ebf4 | 39 | }; |
xinlei | 94:61d44636f020 | 40 | |
xinlei | 94:61d44636f020 | 41 | class ReportThread |
xinlei | 94:61d44636f020 | 42 | { |
xinlei | 94:61d44636f020 | 43 | public: |
xinlei | 109:2ec12f10ebf4 | 44 | ReportThread(OperationPool& pool) : ipool(pool), dict(), sock(), |
xinlei | 94:61d44636f020 | 45 | thread(ReportThread::threadWrapper, this) { |
xinlei | 94:61d44636f020 | 46 | strncpy(uri, "/s", sizeof(uri)); |
xinlei | 94:61d44636f020 | 47 | } |
xinlei | 101:dbcd3bc51758 | 48 | virtual ~ReportThread() { } |
xinlei | 94:61d44636f020 | 49 | void threadFunc(); |
xinlei | 94:61d44636f020 | 50 | static void threadWrapper(const void *p) { ((ReportThread*)p)->threadFunc(); } |
xinlei | 94:61d44636f020 | 51 | private: |
xinlei | 94:61d44636f020 | 52 | char uri[4]; |
xinlei | 94:61d44636f020 | 53 | OperationPool& ipool; |
xinlei | 109:2ec12f10ebf4 | 54 | OperationDict dict; |
xinlei | 94:61d44636f020 | 55 | char buf[SMARTREST_SIZE]; |
xinlei | 106:c61f0d62b625 | 56 | char buf2[SMARTREST_BODY_SIZE]; |
xinlei | 94:61d44636f020 | 57 | SmartRestSocket sock; |
xinlei | 94:61d44636f020 | 58 | Thread thread; |
xinlei | 94:61d44636f020 | 59 | }; |
xinlei | 94:61d44636f020 | 60 | |
xinlei | 94:61d44636f020 | 61 | #endif /* REPORTTHREAD_H */ |