Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: WNCInterface_M2Xdemo ATT_WNCInterface_Info WNCInterface_HTTP_example Public_IoT_M2X_Cellular_Demo
Fork of M2XStreamClient by
TimeService.h
- Committer:
- citrusbyte
- Date:
- 2016-01-02
- Revision:
- 21:6878944d2ce2
- Parent:
- 16:7903152de19f
File content as of revision 21:6878944d2ce2:
#ifndef TimeService_h
#define TimeService_h
class M2XStreamClient;
// A ISO8601 timestamp generation service for M2X.
// It uses the Time API provided by the M2X server to initialize
// clock, then uses millis() function provided by Arduino to calculate
// time advancements so as to reduce API query times.
//
// Right now, this service only works with 32-bit timestamp, meaning that
// this service won't work after 03:14:07 UTC on 19 January 2038. However,
// a similar service that uses 64-bit timestamp can be implemented following
// the logic here.
class TimeService {
public:
TimeService(M2XStreamClient* client);
// Initialize the time service. Notice the TimeService instance is only
// working after calling this function successfully.
int init();
// Reset the internal recorded time by calling M2X Time API again. Normally,
// you don't need to call this manually. TimeService will handle Arduino clock
// overflow automatically
int reset();
// Fills ISO8601 formatted timestamp into the buffer provided. +length+ should
// contains the maximum supported length of the buffer when calling. For now,
// the buffer should be able to store 25 characters for a full ISO8601 formatted
// timestamp, otherwise, an error will be returned.
int getTimestamp(char* buffer, int* length);
private:
M2XStreamClient* _client;
int32_t _server_timestamp;
uint32_t _local_last_milli;
Timer _timer;
};
#endif /* TimeService_h */
