@@ -99,7 +99,7 @@ static time_t const EPOCH = 0;
99
99
* CTOR/DTOR
100
100
**************************************************************************************/
101
101
102
- TimeService::TimeService ()
102
+ TimeServiceClass::TimeServiceClass ()
103
103
: _con_hdl(nullptr )
104
104
, _is_rtc_configured(false )
105
105
, _is_tz_configured(false )
@@ -116,7 +116,7 @@ TimeService::TimeService()
116
116
* PUBLIC MEMBER FUNCTIONS
117
117
**************************************************************************************/
118
118
119
- void TimeService ::begin (ConnectionHandler * con_hdl)
119
+ void TimeServiceClass ::begin (ConnectionHandler * con_hdl)
120
120
{
121
121
_con_hdl = con_hdl;
122
122
initRTC ();
@@ -125,7 +125,7 @@ void TimeService::begin(ConnectionHandler * con_hdl)
125
125
#endif
126
126
}
127
127
128
- unsigned long TimeService ::getTime ()
128
+ unsigned long TimeServiceClass ::getTime ()
129
129
{
130
130
/* Check if it's time to sync */
131
131
unsigned long const current_tick = millis ();
@@ -139,12 +139,12 @@ unsigned long TimeService::getTime()
139
139
return isTimeValid (utc) ? utc : EPOCH_AT_COMPILE_TIME;
140
140
}
141
141
142
- void TimeService ::setTime (unsigned long time)
142
+ void TimeServiceClass ::setTime (unsigned long time)
143
143
{
144
144
setRTC (time );
145
145
}
146
146
147
- bool TimeService ::sync ()
147
+ bool TimeServiceClass ::sync ()
148
148
{
149
149
_is_rtc_configured = false ;
150
150
@@ -170,29 +170,29 @@ bool TimeService::sync()
170
170
return _is_rtc_configured;
171
171
}
172
172
173
- void TimeService ::setSyncInterval (unsigned long seconds)
173
+ void TimeServiceClass ::setSyncInterval (unsigned long seconds)
174
174
{
175
175
_sync_interval_ms = seconds * 1000 ;
176
176
}
177
177
178
- void TimeService ::setSyncFunction (syncTimeFunctionPtr sync_func)
178
+ void TimeServiceClass ::setSyncFunction (syncTimeFunctionPtr sync_func)
179
179
{
180
180
if (sync_func) {
181
181
_sync_func = sync_func;
182
182
}
183
183
}
184
184
185
- void TimeService ::setTimeZoneData (long offset, unsigned long dst_until)
185
+ void TimeServiceClass ::setTimeZoneData (long offset, unsigned long dst_until)
186
186
{
187
187
if (_timezone_offset != offset || _timezone_dst_until != dst_until) {
188
- DEBUG_DEBUG (" TimeService ::%s offset: %d dst_unitl %ul" , __FUNCTION__, offset, dst_until);
188
+ DEBUG_DEBUG (" TimeServiceClass ::%s offset: %d dst_unitl %ul" , __FUNCTION__, offset, dst_until);
189
189
_timezone_offset = offset;
190
190
_timezone_dst_until = dst_until;
191
191
_is_tz_configured = true ;
192
192
}
193
193
}
194
194
195
- unsigned long TimeService ::getLocalTime ()
195
+ unsigned long TimeServiceClass ::getLocalTime ()
196
196
{
197
197
unsigned long utc = getTime ();
198
198
if (_is_tz_configured) {
@@ -202,7 +202,7 @@ unsigned long TimeService::getLocalTime()
202
202
}
203
203
}
204
204
205
- unsigned long TimeService ::getTimeFromString (const String& input)
205
+ unsigned long TimeServiceClass ::getTimeFromString (const String& input)
206
206
{
207
207
struct tm t =
208
208
{
@@ -224,29 +224,29 @@ unsigned long TimeService::getTimeFromString(const String& input)
224
224
static const int expected_parameters = 6 ;
225
225
226
226
if (input == nullptr || input.length () != expected_length) {
227
- DEBUG_ERROR (" TimeService ::%s invalid input length" , __FUNCTION__);
227
+ DEBUG_ERROR (" TimeServiceClass ::%s invalid input length" , __FUNCTION__);
228
228
return 0 ;
229
229
}
230
230
231
231
int scanned_parameters = sscanf (input.c_str (), " %d %s %d %d:%d:%d" , &year, s_month, &day, &hour, &min, &sec);
232
232
233
233
if (scanned_parameters != expected_parameters) {
234
- DEBUG_ERROR (" TimeService ::%s invalid input parameters number" , __FUNCTION__);
234
+ DEBUG_ERROR (" TimeServiceClass ::%s invalid input parameters number" , __FUNCTION__);
235
235
return 0 ;
236
236
}
237
237
238
238
char * s_month_position = strstr (month_names, s_month);
239
239
240
240
if (s_month_position == nullptr || strlen (s_month) != 3 ) {
241
- DEBUG_ERROR (" TimeService ::%s invalid month name, use %s" , __FUNCTION__, month_names);
241
+ DEBUG_ERROR (" TimeServiceClass ::%s invalid month name, use %s" , __FUNCTION__, month_names);
242
242
return 0 ;
243
243
}
244
244
245
245
month = (s_month_position - month_names) / 3 ;
246
246
247
247
if (month < 0 || month > 11 || day < 1 || day > 31 || year < 1900 || hour < 0 ||
248
248
hour > 24 || min < 0 || min > 60 || sec < 0 || sec > 60 ) {
249
- DEBUG_ERROR (" TimeService ::%s invalid date values" , __FUNCTION__);
249
+ DEBUG_ERROR (" TimeServiceClass ::%s invalid date values" , __FUNCTION__);
250
250
return 0 ;
251
251
}
252
252
@@ -265,7 +265,7 @@ unsigned long TimeService::getTimeFromString(const String& input)
265
265
**************************************************************************************/
266
266
267
267
#ifdef HAS_TCP
268
- bool TimeService ::connected ()
268
+ bool TimeServiceClass ::connected ()
269
269
{
270
270
if (_con_hdl == nullptr ) {
271
271
return false ;
@@ -274,7 +274,7 @@ bool TimeService::connected()
274
274
}
275
275
}
276
276
277
- unsigned long TimeService ::getRemoteTime ()
277
+ unsigned long TimeServiceClass ::getRemoteTime ()
278
278
{
279
279
if (connected ()) {
280
280
/* At first try to see if a valid time can be obtained
@@ -307,12 +307,12 @@ unsigned long TimeService::getRemoteTime()
307
307
308
308
#endif /* HAS_TCP */
309
309
310
- bool TimeService ::isTimeValid (unsigned long const time)
310
+ bool TimeServiceClass ::isTimeValid (unsigned long const time)
311
311
{
312
312
return (time > EPOCH_AT_COMPILE_TIME);
313
313
}
314
314
315
- void TimeService ::initRTC ()
315
+ void TimeServiceClass ::initRTC ()
316
316
{
317
317
#if defined (ARDUINO_ARCH_SAMD)
318
318
samd_initRTC ();
@@ -329,7 +329,7 @@ void TimeService::initRTC()
329
329
#endif
330
330
}
331
331
332
- void TimeService ::setRTC (unsigned long time)
332
+ void TimeServiceClass ::setRTC (unsigned long time)
333
333
{
334
334
#if defined (ARDUINO_ARCH_SAMD)
335
335
samd_setRTC (time );
@@ -346,7 +346,7 @@ void TimeService::setRTC(unsigned long time)
346
346
#endif
347
347
}
348
348
349
- unsigned long TimeService ::getRTC ()
349
+ unsigned long TimeServiceClass ::getRTC ()
350
350
{
351
351
#if defined (ARDUINO_ARCH_SAMD)
352
352
return samd_getRTC ();
@@ -483,7 +483,8 @@ unsigned long esp8266_getRTC()
483
483
}
484
484
#endif
485
485
486
- TimeService & ArduinoIoTCloudTimeService () {
487
- static TimeService _timeService_instance;
488
- return _timeService_instance;
489
- }
486
+ /* *****************************************************************************
487
+ * EXTERN DEFINITION
488
+ ******************************************************************************/
489
+
490
+ TimeServiceClass TimeService;
0 commit comments