Midnight Sun Firmware
Loading...
Searching...
No Matches
NetworkTimeProtocolHelpers

Network time protocol helper library. More...

Classes

struct  NTPTime
 Structure representing NTP time format with seconds and fractional seconds. More...
 
struct  NTPPacket
 Structure representing an NTP packet. More...
 

Macros

#define NTP_VERSION   4U
 NTP version being used.
 
#define NTP_LEAP_INDICATOR_OFFSET   6U
 Offset for the Leap Indicator in the flags field of the NTP packet.
 
#define NTP_VERSION_OFFSET   3U
 Offset for the NTP version in the flags field of the NTP packet.
 
#define NTP_MODE_OFFSET   0U
 Offset for the NTP mode in the flags field of the NTP packet.
 
#define NTP_POLL_TO_SECONDS(poll)   (1U << poll)
 Macro to convert NTP poll interval to seconds. More...
 

Enumerations

enum  NTPMode {
  NTP_RESERVED_MODE , NTP_ACTIVE_MODE , NTP_PASSIVE_MODE , NTP_CLIENT_MODE ,
  NTP_SERVER_MODE , NTP_BROADCAST_MODE , NTP_CONTROL_MODE , NUM_NTP_MODES
}
 Enumeration for the NTP modes. More...
 
enum  NTPLeapIndicator { NTP_LI_NONE , NTP_LI_LAST_MINUTE_OF_THE_DAY_61_S , NTP_LI_LAST_MINUTE_OF_THE_DAY_59_S , NTP_LI_NOSYNC }
 Enumeration for the Leap Indicator values. More...
 

Functions

time_t ntpToUnixTime (NTPTime ntpTime)
 Converts an NTP time to Unix time. More...
 
uint32_t unixToNTPTime (time_t unixTime)
 Converts a Unix time to NTP time. More...
 
void convertNTPTimestamp (NTPTime &timestamp)
 Converts an NTP timestamp to its human-readable representation. More...
 
void dumpNTPPacketData (const NTPPacket packet)
 Dumps the data of an NTP packet for debugging purposes. More...
 

Variables

static constexpr uint32_t NTP_UNIX_EPOCH_DIFF = 2208988800UL
 Difference between the NTP epoch (1900-01-01) and the Unix epoch (1970-01-01) in seconds.
 

Detailed Description

Network time protocol helper library.

Macro Definition Documentation

◆ NTP_POLL_TO_SECONDS

#define NTP_POLL_TO_SECONDS (   poll)    (1U << poll)

Macro to convert NTP poll interval to seconds.

Parameters
pollThe poll interval exponent

Enumeration Type Documentation

◆ NTPLeapIndicator

Enumeration for the Leap Indicator values.

Enumerator
NTP_LI_NONE 

No leap second adjustment

NTP_LI_LAST_MINUTE_OF_THE_DAY_61_S 

Last minute of the day has 61 seconds

NTP_LI_LAST_MINUTE_OF_THE_DAY_59_S 

Last minute of the day has 59 seconds

NTP_LI_NOSYNC 

Clock is not synchronized

◆ NTPMode

enum NTPMode

Enumeration for the NTP modes.

Enumerator
NTP_RESERVED_MODE 

Reserved mode (not used)

NTP_ACTIVE_MODE 

Symmetric active mode

NTP_PASSIVE_MODE 

Symmetric passive mode

NTP_CLIENT_MODE 

Client mode

NTP_SERVER_MODE 

Server mode

NTP_BROADCAST_MODE 

Broadcast mode

NTP_CONTROL_MODE 

Control mode

NUM_NTP_MODES 

Number of modes

Function Documentation

◆ convertNTPTimestamp()

void convertNTPTimestamp ( NTPTime timestamp)

Converts an NTP timestamp to its human-readable representation.

Parameters
timestampThe NTP timestamp to be converted

◆ dumpNTPPacketData()

void dumpNTPPacketData ( const NTPPacket  packet)

Dumps the data of an NTP packet for debugging purposes.

Parameters
packetThe NTP packet to be dumped

◆ ntpToUnixTime()

time_t ntpToUnixTime ( NTPTime  ntpTime)

Converts an NTP time to Unix time.

Parameters
ntpTimeThe NTP time to be converted
Returns
The corresponding Unix time

◆ unixToNTPTime()

uint32_t unixToNTPTime ( time_t  unixTime)

Converts a Unix time to NTP time.

Parameters
unixTimeThe Unix time to be converted
Returns
The corresponding NTP time in seconds since the NTP epoch