NetBurner 3.5.0
PDF Version
 
nbtime.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5#include <servlets.h>
6#include <config_obj.h>
7#include <nbstring.h>
8#include <nettimer.h>
49#include <time.h>
50
51#ifndef _NB_TIME_H
52#define _NB_TIME_H
53
54#ifdef __cplusplus
55extern "C"
56{
57#endif /* __cplusplus */
58
59 time_t time(time_t *pt);
60#ifdef __cplusplus
61};
62#endif /* __cplusplus */
63
73time_t set_time(time_t time_to_set, uint32_t fraction=0);
74
86time_t timegm(struct tm *bts);
87
88#ifdef NB_NET_TYPES_H
89
100BOOL SetNTPTime(IPADDR ntpserver);
101
113BOOL SetTimeNTPFromPool(bool debug = FALSE);
114
126time_t GetNTPTime(IPADDR NTP_server_ip, uint32_t * pFraction=0);
127
128
129#define TWELVE_HOURS_SECS (12*3600)
130#define ONE_DAY_SECS (14*3600)
131
154class NtpClientServlet: public servlet, public config_obj, public TimeOutElement
155{
156
157config_string m_ServerAddress;
158config_int m_interval;
159ConfigEndMarker; // No new data members below this line
160OS_FLAGS NTPFlag;
161NBString m_server; //Name of server
162time_t last_update; //time of last valid update in system Secs
163time_t last_attempt; //time of last update in system Secs
164uint32_t m_TickSent; //Transmit time
165servlet_list * m_pWhoToReJoin;
166
167int m_fd; //fd to hold DNS Requests and UDP send/rx
168int cur_state; //State variable
169
170
171//Servlet virtual functions
172 virtual int AddToSelectSet(fd_set &rd_set, fd_set &wr_set, fd_set &er_set);
173 virtual void ProcessSelectResult(fd_set &rd_set, fd_set &wr_set, fd_set &er_set);
174//Timeout element virtual function
175 virtual void TimeElementEvent();
176
177public:
185 NtpClientServlet(const char* NTP_Server="pool.ntp.org",uint32_t update_interval_sec=TWELVE_HOURS_SECS);
186
187
197 NtpClientServlet(servlet_list * List_To_Join, const char* NTP_Server="pool.ntp.org",uint32_t update_interval_sec=TWELVE_HOURS_SECS);
198
208 bool TimeIsValid();
209
219bool TimeIsCurrent();
220
231 bool RefreshNow(uint32_t ticks_to_wait);
232
242 bool WaitForValid(uint32_t ticks_to_wait);
243
251 inline time_t GetSecsSinceUpdate() {return Secs-last_update; }
252};
253
254
255
256
257
258#endif /* NB_NET_TYPES_H */
259
260/*
261 * Legacy function calls.
262 */
263// int IOBoardRTCSetSystemFromRTCTime(void);
264// int IOBoardRTCSetRTCfromSystemTime(void);
265
266/*
267 * Set the local time zone by using the TZ environment variable.
268 * Use one of the following for the U.S.:
269 *
270 * tzsetchar( "EST5EDT4,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Eastern
271 * tzsetchar( "CST6CDT5,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Central
272 * tzsetchar( "MST7MDT6,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Mountain
273 * tzsetchar( "MST7" ); Arizona
274 * tzsetchar( "PST8PDT7,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Pacific
275 * tzsetchar( "AKST9AKDT8,M3.2.0/02:00:00,M11.1.0/02:00:00" ); Alaska
276 * tzsetchar( "HST10" ); Hawaii
277 *
278 * Effective 2007, the U.S. starts daylight savings time on the second Sunday of
279 * March at 2:00 AM and ends on the first Sunday of November at 2:00 AM. The
280 * starting and ending date/times for daylight savings time can be omitted from
281 * the string since these rules are used by default.
282 */
283
307void tzsetchar(const char *tzenv);
308
309#endif /* _NB_TIME_H */
310
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
Signed 32-bit Integer Configuration Variable.
Definition config_obj.h:649
Base class used to create configuration objects.
Definition config_obj.h:277
String Configuration Variable.
Definition config_obj.h:1055
Configuration object header file.
void tzsetchar(const char *tzenv)
Set the system local time.
time_t timegm(struct tm *bts)
Returns the value of type time_t that represents the GMT time described by the tm structure pointed b...
time_t set_time(time_t time_to_set, uint32_t fraction=0)
Set the system time to the value passed in the time_t parameter.
NetBurner String Class.
OSFlags enables a function or task to pend on multiple flags or events.
Definition nbrtos.h:1262