ARM mbed M2X API Client: The ARM mbed client library is used to send/receive data to/from AT&T's M2X service from mbed LPC1768 microcontrollers.
Dependents: m2x-demo-all M2X_MTS_ACCEL_DEMO M2X_MTS_Accel M2X_K64F_ACCEL ... more
TimeService.h@16:7903152de19f, 2015-12-28 (annotated)
- Committer:
- citrusbyte
- Date:
- Mon Dec 28 12:48:19 2015 +0000
- Revision:
- 16:7903152de19f
Add TimeService implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
citrusbyte | 16:7903152de19f | 1 | #ifndef TimeService_h |
citrusbyte | 16:7903152de19f | 2 | #define TimeService_h |
citrusbyte | 16:7903152de19f | 3 | |
citrusbyte | 16:7903152de19f | 4 | class M2XStreamClient; |
citrusbyte | 16:7903152de19f | 5 | |
citrusbyte | 16:7903152de19f | 6 | // A ISO8601 timestamp generation service for M2X. |
citrusbyte | 16:7903152de19f | 7 | // It uses the Time API provided by the M2X server to initialize |
citrusbyte | 16:7903152de19f | 8 | // clock, then uses millis() function provided by Arduino to calculate |
citrusbyte | 16:7903152de19f | 9 | // time advancements so as to reduce API query times. |
citrusbyte | 16:7903152de19f | 10 | // |
citrusbyte | 16:7903152de19f | 11 | // Right now, this service only works with 32-bit timestamp, meaning that |
citrusbyte | 16:7903152de19f | 12 | // this service won't work after 03:14:07 UTC on 19 January 2038. However, |
citrusbyte | 16:7903152de19f | 13 | // a similar service that uses 64-bit timestamp can be implemented following |
citrusbyte | 16:7903152de19f | 14 | // the logic here. |
citrusbyte | 16:7903152de19f | 15 | class TimeService { |
citrusbyte | 16:7903152de19f | 16 | public: |
citrusbyte | 16:7903152de19f | 17 | TimeService(M2XStreamClient* client); |
citrusbyte | 16:7903152de19f | 18 | |
citrusbyte | 16:7903152de19f | 19 | // Initialize the time service. Notice the TimeService instance is only |
citrusbyte | 16:7903152de19f | 20 | // working after calling this function successfully. |
citrusbyte | 16:7903152de19f | 21 | int init(); |
citrusbyte | 16:7903152de19f | 22 | |
citrusbyte | 16:7903152de19f | 23 | // Reset the internal recorded time by calling M2X Time API again. Normally, |
citrusbyte | 16:7903152de19f | 24 | // you don't need to call this manually. TimeService will handle Arduino clock |
citrusbyte | 16:7903152de19f | 25 | // overflow automatically |
citrusbyte | 16:7903152de19f | 26 | int reset(); |
citrusbyte | 16:7903152de19f | 27 | |
citrusbyte | 16:7903152de19f | 28 | // Fills ISO8601 formatted timestamp into the buffer provided. +length+ should |
citrusbyte | 16:7903152de19f | 29 | // contains the maximum supported length of the buffer when calling. For now, |
citrusbyte | 16:7903152de19f | 30 | // the buffer should be able to store 25 characters for a full ISO8601 formatted |
citrusbyte | 16:7903152de19f | 31 | // timestamp, otherwise, an error will be returned. |
citrusbyte | 16:7903152de19f | 32 | int getTimestamp(char* buffer, int* length); |
citrusbyte | 16:7903152de19f | 33 | private: |
citrusbyte | 16:7903152de19f | 34 | M2XStreamClient* _client; |
citrusbyte | 16:7903152de19f | 35 | int32_t _server_timestamp; |
citrusbyte | 16:7903152de19f | 36 | uint32_t _local_last_milli; |
citrusbyte | 16:7903152de19f | 37 | Timer _timer; |
citrusbyte | 16:7903152de19f | 38 | }; |
citrusbyte | 16:7903152de19f | 39 | |
citrusbyte | 16:7903152de19f | 40 | #endif /* TimeService_h */ |