Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::BroadcastTimeDefs Struct Reference

Static constants and helper functions for Broadcast Time Protocol. More...

#include <BroadcastTimeDefs.hxx>

Public Types

enum  EventType {
  REPORT_TIME = 0 , REPORT_DATE , REPORT_YEAR , REPORT_RATE ,
  SET_TIME , SET_DATE , SET_YEAR , SET_RATE ,
  QUERY , STOP , START , DATE_ROLLOVER ,
  UNDEFINED
}
 Type of event. More...
 
enum  {
  EVENT_ID_MASK = 0xFFFFFFFFFFFF0000 , EVENT_SUFFIX_MASK = 0x000000000000FFFF , EVENT_TYPE_MASK = 0x000000000000F000 , EVENT_HOURS_MASK = 0x0000000000001F00 ,
  EVENT_MINUTES_MASK = 0x00000000000000FF , EVENT_MONTH_MASK = 0x0000000000000F00 , EVENT_DAY_MASK = 0x00000000000000FF , EVENT_YEAR_MASK = 0x0000000000000FFF ,
  EVENT_RATE_MASK = 0x0000000000000FFF , EVENT_HOURS_SHIFT = 8 , EVENT_MINUTES_SHIFT = 0 , EVENT_MONTH_SHIFT = 8 ,
  EVENT_DAY_SHIFT = 0 , EVENT_YEAR_SHIFT = 0 , EVENT_RATE_SHIFT = 0 , TIME_EVENT_BASE_SUFFIX = 0x0000 ,
  DATE_EVENT_BASE_SUFFIX = 0x2000 , YEAR_EVENT_BASE_SUFFIX = 0x3000 , RATE_EVENT_BASE_SUFFIX = 0x4000 , QUERY_EVENT_SUFFIX = 0xF000 ,
  STOP_EVENT_SUFFIX = 0xF001 , START_EVENT_SUFFIX = 0xF002 , DATE_ROLLOVER_EVENT_SUFFIX = 0xF003 , EVENT_SET_SUFFIX_MASK = 0x8000
}
 
enum  {
  SUNDAY = 0 , MONDAY , TUESDAY , WEDNESDAY ,
  THURSDAY , FRIDAY , SATURDAY
}
 

Static Public Member Functions

static EventType get_event_type (uint16_t suffix)
 Get the EventTuype from the event suffix number.
 
static bool valid_time (uint16_t suffix)
 Validate that this is a supported time event.
 
static bool valid_date (uint16_t suffix)
 Validate that this is a supported date event.
 
static int event_to_min (uint64_t event)
 Get the minutes from the event.
 
static int event_to_hour (uint64_t event)
 Get the hour from the event.
 
static int event_to_day (uint64_t event)
 Get the day from the event.
 
static int event_to_month (uint64_t event)
 Get the month from the event.
 
static int event_to_year (uint64_t event)
 Get the year from the event.
 
static int16_t event_to_rate (uint64_t event)
 Get the rate from the event.
 
static uint64_t time_to_event (uint64_t event_base, int hours, int minutes)
 Build an event from hours and minutes.
 
static uint64_t date_to_event (uint64_t event_base, int month, int day)
 Build an event from month and day.
 
static uint64_t year_to_event (uint64_t event_base, int year)
 Build an event from year.
 
static uint64_t rate_to_event (uint64_t event_base, int16_t rate)
 Build an event from rate.
 
static std::string time_to_string (int hour, int min)
 Convert time in integer hours/minutes to a string ("hh:mm").
 
static std::string rate_quarters_to_string (int16_t rate)
 Convert rate in integer rate quarters to a string (float).
 
static std::string date_to_string (int year, int month, int day)
 Converts a date to a string "Mmm dd, yyyy".
 
static bool string_to_time (const std::string &stime, int *hour, int *min)
 Convert a string (hh:mm) to hour and minute component integers.
 
static int16_t string_to_rate_quarters (const std::string &srate)
 Convert a string (float) to rate quarters.
 
static bool string_to_date (const std::string &sdate, int *year, int *month, int *day)
 Converts a (user-provided) string "Mmm dd, yyyy" to date.
 
static bool canonicalize_time_string (std::string *stime)
 Verifies that a user-provided string parses as time, and canonicalizes the string format.
 
static bool canonicalize_rate_string (std::string *srate)
 Verifies that a user-provided string parses as rate quarters, and canonicalizes the string format.
 
static bool canonicalize_date_string (std::string *sdate)
 Verifies that a user-provided string parses as date, and canonicalizes the string format.
 

Static Public Attributes

static constexpr NodeID DEFAULT_FAST_CLOCK_ID = 0x010100000100ULL
 Unique identifier for the Default Fast Clock.
 
static constexpr NodeID DEFAULT_REALTIME_CLOCK_ID = 0x010100000101ULL
 Unique identifier for the Default Real-Time Clock.
 
static constexpr NodeID ALTERNATE_CLOCK_1_ID = 0x010100000102ULL
 Unique identifier for Alternate Clock 1.
 
static constexpr NodeID ALTERNATE_CLOCK_2_ID = 0x010100000103ULL
 Unique identifier for Alternate Clock 2.
 

Detailed Description

Static constants and helper functions for Broadcast Time Protocol.

Definition at line 47 of file BroadcastTimeDefs.hxx.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
EVENT_ID_MASK 

Unique ID mask.

EVENT_SUFFIX_MASK 

suffix mask

EVENT_TYPE_MASK 

type mask

EVENT_HOURS_MASK 

hours mask

EVENT_MINUTES_MASK 

minutes mask

EVENT_MONTH_MASK 

month mask

EVENT_DAY_MASK 

day mask

EVENT_YEAR_MASK 

rate mask

EVENT_RATE_MASK 

rate mask

EVENT_HOURS_SHIFT 

hours mask

EVENT_MINUTES_SHIFT 

minutes mask

EVENT_MONTH_SHIFT 

month mask

EVENT_DAY_SHIFT 

day mask

EVENT_YEAR_SHIFT 

year mask

EVENT_RATE_SHIFT 

rate mask

TIME_EVENT_BASE_SUFFIX 

time event base suffix

DATE_EVENT_BASE_SUFFIX 

date event base suffix

YEAR_EVENT_BASE_SUFFIX 

year event base suffix

RATE_EVENT_BASE_SUFFIX 

rate event base suffix

QUERY_EVENT_SUFFIX 

query event suffix value

STOP_EVENT_SUFFIX 

stop clock event suffix value

START_EVENT_SUFFIX 

start clock event suffix value

DATE_ROLLOVER_EVENT_SUFFIX 

rollover the date suffix value

EVENT_SET_SUFFIX_MASK 

suffix max for setting a property

Definition at line 79 of file BroadcastTimeDefs.hxx.

◆ anonymous enum

anonymous enum
Enumerator
SUNDAY 

Day of the week value Sunday.

MONDAY 

Day of the week value Monday.

TUESDAY 

Day of the week value Tuesday.

WEDNESDAY 

Day of the week value Wednesday.

THURSDAY 

Day of the week value Thursday.

FRIDAY 

Day of the week value Friday.

SATURDAY 

Day of the week value Saturday.

Definition at line 110 of file BroadcastTimeDefs.hxx.

◆ EventType

Type of event.

Enumerator
REPORT_TIME 

report time event

REPORT_DATE 

report date event

REPORT_YEAR 

report year event

REPORT_RATE 

report rate event

SET_TIME 

set time event

SET_DATE 

set date event

SET_YEAR 

set year event

SET_RATE 

set rate event

QUERY 

query event

STOP 

stop clock event

START 

start clock event

DATE_ROLLOVER 

date rollover event

UNDEFINED 

undefined event

Definition at line 62 of file BroadcastTimeDefs.hxx.

Member Function Documentation

◆ canonicalize_date_string()

bool openlcb::BroadcastTimeDefs::canonicalize_date_string ( std::string *  sdate)
static

Verifies that a user-provided string parses as date, and canonicalizes the string format.

Parse errors get turned into "Jan 1, 1970".

Parameters
sdateinput-output argument. Input is user-provided date in "Mmm dd, yyyy" format, output is the canonicalized date.
Returns
true if the string has changed during canonicalization.

Definition at line 241 of file BroadcastTimeDefs.cxx.

◆ canonicalize_rate_string()

bool openlcb::BroadcastTimeDefs::canonicalize_rate_string ( std::string *  srate)
static

Verifies that a user-provided string parses as rate quarters, and canonicalizes the string format.

Parse errors get turned into "0.00".

Parameters
srateinput-output argument. Input is user-provided rate, output is the canonicalized rate.
Returns
true if the string has changed during canonicalization.

Definition at line 229 of file BroadcastTimeDefs.cxx.

◆ canonicalize_time_string()

bool openlcb::BroadcastTimeDefs::canonicalize_time_string ( std::string *  stime)
static

Verifies that a user-provided string parses as time, and canonicalizes the string format.

Parse errors get turned into "00:00".

Parameters
stimeinput-output argument. Input is the user-provided time (hh:mm), output is the canonicalized time.
Returns
true if the string has changed during canonicalization.

Definition at line 254 of file BroadcastTimeDefs.cxx.

◆ date_to_event()

static uint64_t openlcb::BroadcastTimeDefs::date_to_event ( uint64_t  event_base,
int  month,
int  day 
)
inlinestatic

Build an event from month and day.

Parameters
event_basebase event ID of the event pool
monthmonth (1 to 12)
dayday of month (1 to 31)
Returns
resulting event ID

Definition at line 304 of file BroadcastTimeDefs.hxx.

◆ date_to_string()

std::string openlcb::BroadcastTimeDefs::date_to_string ( int  year,
int  month,
int  day 
)
static

Converts a date to a string "Mmm dd, yyyy".

Parameters
year0 to 4095
month1 to 12 (warning! struct tm has 0 to 11)
day1 to 31

Definition at line 117 of file BroadcastTimeDefs.cxx.

◆ event_to_day()

static int openlcb::BroadcastTimeDefs::event_to_day ( uint64_t  event)
inlinestatic

Get the day from the event.

To save logic, the event is assumed to be of type REPORT_DATE.

Returns
-1 on error, else day

Definition at line 231 of file BroadcastTimeDefs.hxx.

◆ event_to_hour()

static int openlcb::BroadcastTimeDefs::event_to_hour ( uint64_t  event)
inlinestatic

Get the hour from the event.

To save logic, the event is assumed to be of type REPORT_TIME.

Returns
-1 on error, else hour

Definition at line 218 of file BroadcastTimeDefs.hxx.

◆ event_to_min()

static int openlcb::BroadcastTimeDefs::event_to_min ( uint64_t  event)
inlinestatic

Get the minutes from the event.

To save logic, the event is assumed to be of type REPORT_TIME.

Returns
-1 on error, else minute

Definition at line 205 of file BroadcastTimeDefs.hxx.

◆ event_to_month()

static int openlcb::BroadcastTimeDefs::event_to_month ( uint64_t  event)
inlinestatic

Get the month from the event.

To save logic, the event is assumed to be of type REPORT_DATE.

Returns
-1 on error, else month (January = 1)

Definition at line 244 of file BroadcastTimeDefs.hxx.

◆ event_to_rate()

static int16_t openlcb::BroadcastTimeDefs::event_to_rate ( uint64_t  event)
inlinestatic

Get the rate from the event.

To save logic, the event is assumed to be of type REPORT_RATE.

Returns
signed 12-bit rate value.

Definition at line 265 of file BroadcastTimeDefs.hxx.

◆ event_to_year()

static int openlcb::BroadcastTimeDefs::event_to_year ( uint64_t  event)
inlinestatic

Get the year from the event.

To save logic, the event is assumed to be of type REPORT_YEAR.

Returns
years past 0AD

Definition at line 257 of file BroadcastTimeDefs.hxx.

◆ get_event_type()

static EventType openlcb::BroadcastTimeDefs::get_event_type ( uint16_t  suffix)
inlinestatic

Get the EventTuype from the event suffix number.

Parameters
suffix16-bit event suffix
Returns
the EventType

Definition at line 124 of file BroadcastTimeDefs.hxx.

◆ rate_quarters_to_string()

std::string openlcb::BroadcastTimeDefs::rate_quarters_to_string ( int16_t  rate)
static

Convert rate in integer rate quarters to a string (float).

Parameters
raterate in the form of rate quarters
Returns
rate represented in the form of a string (float)

Definition at line 82 of file BroadcastTimeDefs.cxx.

◆ rate_to_event()

static uint64_t openlcb::BroadcastTimeDefs::rate_to_event ( uint64_t  event_base,
int16_t  rate 
)
inlinestatic

Build an event from rate.

Parameters
event_basebase event ID of the event pool
year(0AD to 4095AD)
Returns
resulting event ID

Definition at line 328 of file BroadcastTimeDefs.hxx.

◆ string_to_date()

bool openlcb::BroadcastTimeDefs::string_to_date ( const std::string &  sdate,
int *  year,
int *  month,
int *  day 
)
static

Converts a (user-provided) string "Mmm dd, yyyy" to date.

Verifies that the values are in range for OpenLCB and for a real date.

Parameters
sdatethe input string in "Mmm dd, yyyy" format.
yearwill be filled in with the year (0 to 4095)
monthwill be filled in with the month (1 to 12) (warning! struct tm has 0 to 11)
daywill be filled in with the day (1 to 31)
Returns
true on success, false on parse error. Note that it is not fully specified what is a parse error; certain errors will be corrected (e.g. feb 30, 2001 will be fixed to march 2).

Definition at line 189 of file BroadcastTimeDefs.cxx.

◆ string_to_rate_quarters()

int16_t openlcb::BroadcastTimeDefs::string_to_rate_quarters ( const std::string &  srate)
static

Convert a string (float) to rate quarters.

Parameters
sraterate in the form of a string float
Returns
Rate in the form of an int16_t in rate quarters. If a conversion error occurs, then the returned value will be 0, which is at least a valid rate.

Definition at line 160 of file BroadcastTimeDefs.cxx.

◆ string_to_time()

bool openlcb::BroadcastTimeDefs::string_to_time ( const std::string &  stime,
int *  hour,
int *  min 
)
static

Convert a string (hh:mm) to hour and minute component integers.

Parameters
stimetime in the form of a string
hourresulting hour integer (0 to 23)
minresulting minute integer (0 to 59)
Returns
true on success, else false on fault

Definition at line 137 of file BroadcastTimeDefs.cxx.

◆ time_to_event()

static uint64_t openlcb::BroadcastTimeDefs::time_to_event ( uint64_t  event_base,
int  hours,
int  minutes 
)
inlinestatic

Build an event from hours and minutes.

Parameters
event_basebase event ID of the event pool
hourshours (0 to 23)
minutesminutes (0 to 59)
Returns
resulting event ID

Definition at line 290 of file BroadcastTimeDefs.hxx.

◆ time_to_string()

std::string openlcb::BroadcastTimeDefs::time_to_string ( int  hour,
int  min 
)
static

Convert time in integer hours/minutes to a string ("hh:mm").

Parameters
hourhours in integer form (0 to 23)
minminutes in integer form (0 to 59)
Returns
time represented in the form of a string ("hh:mm")

Definition at line 54 of file BroadcastTimeDefs.cxx.

◆ valid_date()

static bool openlcb::BroadcastTimeDefs::valid_date ( uint16_t  suffix)
inlinestatic

Validate that this is a supported date event.

Assume that the four most significant bits have been seperately validated.

Returns
true of valid, else false

Definition at line 194 of file BroadcastTimeDefs.hxx.

◆ valid_time()

static bool openlcb::BroadcastTimeDefs::valid_time ( uint16_t  suffix)
inlinestatic

Validate that this is a supported time event.

Assume that the four most significant bits have been seperately validated.

Returns
true of valid, else false

Definition at line 185 of file BroadcastTimeDefs.hxx.

◆ year_to_event()

static uint64_t openlcb::BroadcastTimeDefs::year_to_event ( uint64_t  event_base,
int  year 
)
inlinestatic

Build an event from year.

Parameters
event_basebase event ID of the event pool
year(0AD to 4095AD)
Returns
resulting event ID

Definition at line 317 of file BroadcastTimeDefs.hxx.

Member Data Documentation

◆ ALTERNATE_CLOCK_1_ID

constexpr NodeID openlcb::BroadcastTimeDefs::ALTERNATE_CLOCK_1_ID = 0x010100000102ULL
staticconstexpr

Unique identifier for Alternate Clock 1.

Definition at line 56 of file BroadcastTimeDefs.hxx.

◆ ALTERNATE_CLOCK_2_ID

constexpr NodeID openlcb::BroadcastTimeDefs::ALTERNATE_CLOCK_2_ID = 0x010100000103ULL
staticconstexpr

Unique identifier for Alternate Clock 2.

Definition at line 59 of file BroadcastTimeDefs.hxx.

◆ DEFAULT_FAST_CLOCK_ID

constexpr NodeID openlcb::BroadcastTimeDefs::DEFAULT_FAST_CLOCK_ID = 0x010100000100ULL
staticconstexpr

Unique identifier for the Default Fast Clock.

Definition at line 50 of file BroadcastTimeDefs.hxx.

◆ DEFAULT_REALTIME_CLOCK_ID

constexpr NodeID openlcb::BroadcastTimeDefs::DEFAULT_REALTIME_CLOCK_ID = 0x010100000101ULL
staticconstexpr

Unique identifier for the Default Real-Time Clock.

Definition at line 53 of file BroadcastTimeDefs.hxx.


The documentation for this struct was generated from the following files: