mbgtools-lx
4.2.8
|
Go to the source code of this file.
Data Structures | |
struct | TIMEOUT |
Typedefs | |
typedef char | DAYS_OF_MONTH_TABLE[2][12] |
A table with the days of month. More... | |
Functions | |
static __mbg_inline uint32_t | bin_frac_16_to_dec_frac (uint16_t bin, uint32_t scale) |
Convert a 16 bit binary fraction to a scaled decimal. More... | |
static __mbg_inline uint32_t | bin_frac_32_to_dec_frac (uint32_t bin, uint32_t scale) |
Convert a 32 bit binary fraction to a scaled decimal. More... | |
static __mbg_inline uint16_t | dec_frac_to_bin_frac_16 (uint32_t dec, uint32_t scale) |
static __mbg_inline uint32_t | dec_frac_to_bin_frac_32 (uint32_t dec, uint32_t scale) |
static __mbg_inline uint32_t | frac_sec_from_bin (uint32_t b, uint32_t scale) |
Convert a binary fraction to a scaled decimal. More... | |
static __mbg_inline double | dfrac_sec_from_bin (uint32_t b) |
Convert a binary fraction to "double" fractions. More... | |
void | set_timeout (TIMEOUT *t, clock_t clk, clock_t interval) |
Set a timeout object to specified interval. More... | |
void | stretch_timeout (TIMEOUT *t, clock_t interval) |
Stretch a timeout specified in given timeout object. More... | |
bit | check_timeout (TIMEOUT *t, clock_t clk) |
Check if a timeout object has expired. More... | |
int | err_tm (const TM_GPS *tm) |
Check if a TM_GPS structure contains a valid date and time. More... | |
TM_GPS * | clear_time (TM_GPS *tm) |
Set the time in a TM_GPS structure to 00:00:00.000. More... | |
TM_GPS * | wsec_to_tm (long wsec, TM_GPS *tm) |
Convert second-of-week to day-of-week and time-of-day. More... | |
long | tm_to_wsec (const TM_GPS *tm) |
Compute second-of-week from day-of-week and time-of-day. More... | |
int | is_leap_year (int y) |
Check if a specific year is a leap year. More... | |
int | day_of_year (int day, int month, int year) |
Compute the day-of-year from a given date. More... | |
void | date_of_year (int year, int day_num, TM_GPS *tm) |
Compute a date from a given year and day-of-year. More... | |
int | day_of_week (int day, int month, int year) |
Compute day-of-week from a given date. More... | |
int | days_to_years (long *day_num, int year) |
Update a year number by a number of days, accounting for leap years. More... | |
long | n_days (ushort mday, ushort month, ushort year) |
Compute number of days after Jan 1, 0000 for a given date. More... | |
int | sprint_time (char *s, const TM_GPS *tm) |
Print time with hours, minutes, seconds to a string. More... | |
int | sprint_short_time (char *s, const TM_GPS *tm) |
Print time with hours, minutes to a string. More... | |
int | sprint_date (char *s, const TM_GPS *tm) |
Print date to a string. More... | |
int | sprint_day_date (char *s, const TM_GPS *tm) |
Print day-of-week and date to a string. More... | |
int | sprint_tm (char *s, const TM_GPS *tm) |
Print day-of-week, date and time to a string. More... | |
void | sscan_time (const char *s, TM_GPS *tm) |
Extract a time from a string. More... | |
void | sscan_date (char *s, TM_GPS *tm) |
Extract a date from a string. More... | |
Variables | |
TM_GPS | dhms |
TM_GPS | datum |
const char * | short_time_fmt |
const char * | time_fmt |
const char * | long_time_fmt |
const char * | date_fmt |
const char * | day_date_fmt |
const char * | day_name_eng [] |
const char * | day_name_ger [] |
const TM_GPS | init_tm |
DAYS_OF_MONTH_TABLE | days_of_month |
#define _get_days_of_month | ( | _y, | |
_m | |||
) | days_of_month[ _is_leap_year( _y ) ][_m] |
#define _is_leap_year | ( | _y | ) | ( ( ( ( (_y) % 4 ) == 0 ) && ( ( (_y) % 100 ) != 0 ) ) || ( ( (_y) % 400 ) == 0 ) ) |
#define _n_days | ( | _s | ) | n_days( (_s)->mday, (_s)->month, (_s)->year ) |
#define bin_frac_16_to_msec | ( | _bin | ) | bin_frac_16_to_dec_frac( (_bin), 1000L ) |
#define bin_frac_16_to_nsec | ( | _bin | ) | bin_frac_16_to_dec_frac( (_bin), 1000000000L ) |
#define bin_frac_16_to_usec | ( | _bin | ) | bin_frac_16_to_dec_frac( (_bin), 1000000L ) |
#define bin_frac_32_to_msec | ( | _bin | ) | bin_frac_32_to_dec_frac( (_bin), 1000L ) |
Definition at line 476 of file mbgtime.h.
Referenced by snprint_ntp_tstamp_to_iso_ms().
#define bin_frac_32_to_nsec | ( | _bin | ) | bin_frac_32_to_dec_frac( (_bin), 1000000000L ) |
Definition at line 478 of file mbgtime.h.
Referenced by snprint_ntp_tstamp_to_iso_ns().
#define bin_frac_32_to_usec | ( | _bin | ) | bin_frac_32_to_dec_frac( (_bin), 1000000L ) |
Definition at line 477 of file mbgtime.h.
Referenced by snprint_ntp_tstamp_to_iso_us().
#define DAYS_OF_MONTH_TABLE_INIT |
An initializer for a DAYS_OF_MONTH_TABLE.
#define GPS_SEC_BIAS 315964800UL |
GPS epoch bias from ordinary time_t epoch.
The Unix time_t epoch is usually 1970-01-01 00:00 whereas the GPS epoch is 1980-01-06 00:00, so the difference is 10 years, plus 2 days due to leap years (1972 and 1976), plus the difference of the day-of-month (6 - 1), so:
time_t t = ( gps_week * SECS_PER_WEEK ) + sec_of_week + GPS_SEC_BIAS
Definition at line 130 of file mbgtime.h.
Referenced by show_utc_info().
#define HNS_PER_MIN ( HNS_PER_SEC * SECS_PER_MIN ) |
#define HNS_PER_MS 10000L |
Definition at line 272 of file mbgtime.h.
Referenced by mbg_delta_sys_time_ms().
#define HNS_PER_SEC 10000000L |
Definition at line 268 of file mbgtime.h.
Referenced by mbg_get_sys_uptime(), mbg_sleep_sec(), and snprint_gmtime_error().
#define MBG_FRAC32_CONVERSION_TYPE int64_t |
Data type used for intermediate results on 32 bit multiplications.
We need 64 bits for intermediate integer results to avoid a range overflow from 32 x 32 bit multiplications. On systems which don't support 64 bit types we use the "double" type as a workaround.
Definition at line 392 of file mbgtime.h.
Referenced by bin_frac_16_to_dec_frac(), bin_frac_32_to_dec_frac(), dec_frac_to_bin_frac_16(), and dec_frac_to_bin_frac_32().
#define MBG_FRAC32_UNITS_PER_SEC ( (MBG_FRAC32_CONVERSION_TYPE) 4294967296.0 ) |
Constant used to convert e.g. PCPS_TIME_STAMP::frac values.
Max value of PCPS_TIME_STAMP::frac + 1, used for scaling
Definition at line 400 of file mbgtime.h.
Referenced by bin_frac_32_to_dec_frac(), dec_frac_to_bin_frac_32(), delta_timestamps(), dfrac_sec_from_bin(), mbg_chk_time_info(), mbg_chk_tstamp64_leap_sec(), mbg_get_default_cycles_frequency_from_dev(), mbg_set_current_process_affinity_to_cpu(), and show_ucap_event().
#define MINS_PER_DAY ( MINS_PER_HOUR * HOURS_PER_DAY ) |
#define MINS_PER_HOUR 60 |
Definition at line 236 of file mbgtime.h.
Referenced by set_new_ref_offs(), show_signal(), snprint_hours_mins(), and snprint_utc_offs().
#define MSEC_PER_DAY ( MSEC_PER_SEC * SECS_PER_DAY ) |
#define MSEC_PER_HOUR ( MSEC_PER_SEC * SECS_PER_HOUR ) |
#define MSEC_PER_MIN ( MSEC_PER_SEC * SECS_PER_MIN ) |
#define MSEC_PER_SEC 1000L |
Definition at line 252 of file mbgtime.h.
Referenced by snprint_time_t_to_iso_ms().
#define msec_to_bin_frac_16 | ( | _msec | ) | dec_frac_to_bin_frac_16( (_msec), 1000L ) |
#define msec_to_bin_frac_32 | ( | _msec | ) | dec_frac_to_bin_frac_32( (_msec), 1000L ) |
#define MSEC_TO_NSEC_MULTIPLIER ( NSEC_PER_SEC / MSEC_PER_SEC ) |
#define MSEC_TO_USEC_MULTIPLIER ( USEC_PER_SEC / MSEC_PER_SEC ) |
#define NSEC_PER_SEC 1000000000L |
Definition at line 264 of file mbgtime.h.
Referenced by delta_timespec_d_s(), delta_timespec_ll_ns(), do_set_system_time_from_pcps_hr_time(), mbg_chk_time_info(), normalize_nano_time_64(), nsec_to_ntp_frac(), ntp_frac_to_nsec(), ntp_tstamp_to_nanotime_64(), set_system_time_from_pcps_time(), snprint_gmtime_error(), snprint_time_t_to_iso_ns(), and swap_tstamp().
#define nsec_to_bin_frac_16 | ( | _nsec | ) | dec_frac_to_bin_frac_16( (_nsec), 1000000000L ) |
#define nsec_to_bin_frac_32 | ( | _nsec | ) | dec_frac_to_bin_frac_32( (_nsec), 1000000000L ) |
#define NTP_FRAC_PER_SEC (uint64_t) 4294967296.0 |
Definition at line 145 of file mbgtime.h.
Referenced by nsec_to_ntp_frac(), ntp_frac_to_nsec(), and ntp_tstamp_to_double().
#define NTP_SEC_BIAS 2208988800UL |
NTP epoch bias from ordinary time_t epoch.
The Unix time_t epoch is usually 1970-01-01 00:00 whereas the NTP epoch is 1900-01-01 00:00, so the difference is a constant number of seconds:
time_t t = ntp_time - NTP_SEC_BIAS
Definition at line 142 of file mbgtime.h.
Referenced by ntp_tstamp_to_nanotime_64(), ntp_tstamp_to_timespec(), snprint_ntp_tstamp_to_iso_ms(), snprint_ntp_tstamp_to_iso_ns(), snprint_ntp_tstamp_to_iso_us(), and timespec_to_ntp_tstamp().
#define SEC100S_PER_DAY ( SEC100S_PER_SEC * SECS_PER_DAY ) |
#define SEC100S_PER_HOUR ( SEC100S_PER_SEC * SECS_PER_HOUR ) |
#define SEC100S_PER_MIN ( SEC100S_PER_SEC * SECS_PER_MIN ) |
#define SECS_PER_DAY 86400L |
Definition at line 243 of file mbgtime.h.
Referenced by show_utc_info().
#define SECS_PER_HOUR 3600 |
Definition at line 242 of file mbgtime.h.
Referenced by get_tz_name(), pcps_tz_name(), set_system_time_from_pcps_time(), snprint_time_t_to_iso(), and snprint_utc_offs().
#define SECS_PER_WEEK 604800L |
Definition at line 244 of file mbgtime.h.
Referenced by show_utc_info().
#define USEC_PER_SEC 1000000L |
Definition at line 260 of file mbgtime.h.
Referenced by snprint_time_t_to_iso_us().
#define usec_to_bin_frac_16 | ( | _usec | ) | dec_frac_to_bin_frac_16( (_usec), 1000000L ) |
#define usec_to_bin_frac_32 | ( | _usec | ) | dec_frac_to_bin_frac_32( (_usec), 1000000L ) |
typedef char DAYS_OF_MONTH_TABLE[2][12] |
A table with the days of month.
First row is for standard years, second row is for leap years.
|
static |
Convert a 16 bit binary fraction to a scaled decimal.
[in] | bin | The binary fraction |
[in] | scale | The scale factor |
Definition at line 417 of file mbgtime.h.
References MBG_FRAC32_CONVERSION_TYPE.
|
static |
Convert a 32 bit binary fraction to a scaled decimal.
[in] | bin | The binary fraction |
[in] | scale | The scale factor |
Definition at line 439 of file mbgtime.h.
References MBG_FRAC32_CONVERSION_TYPE, and MBG_FRAC32_UNITS_PER_SEC.
Referenced by do_set_system_time_from_pcps_hr_time(), frac_sec_from_bin(), mbg_snprint_hr_tstamp(), mbg_str_pcps_hr_time_frac(), ntp_tstamp_to_nanotime_64(), and swap_tstamp().
Check if a timeout object has expired.
[in] | t | The timeout object |
[in] | clk | The current time, in clock_t ticks |
Referenced by dfrac_sec_from_bin().
Set the time in a TM_GPS structure to 00:00:00.000.
[in,out] | tm | The date/time structure to be set |
Referenced by dfrac_sec_from_bin().
void date_of_year | ( | int | year, |
int | day_num, | ||
TM_GPS * | tm | ||
) |
Compute a date from a given year and day-of-year.
[in] | year | The full year number |
[in] | day_num | Number of days from the beginning of that year, may be negative |
[out] | tm | Address of a TM_GPS structure which takes the computed results |
Referenced by dfrac_sec_from_bin().
int day_of_week | ( | int | day, |
int | month, | ||
int | year | ||
) |
Compute day-of-week from a given date.
[in] | day | The day-of-month |
[in] | month | The month |
[in] | year | The full year number |
Referenced by dfrac_sec_from_bin().
int day_of_year | ( | int | day, |
int | month, | ||
int | year | ||
) |
Compute the day-of-year from a given date.
[in] | day | The day-of-month |
[in] | month | The month |
[in] | year | The full year number |
Referenced by dfrac_sec_from_bin().
int days_to_years | ( | long * | day_num, |
int | year | ||
) |
Update a year number by a number of days, accounting for leap years.
[in] | day_num | The number of days to evaluate |
[in] | year | The year number to start with |
Referenced by dfrac_sec_from_bin().
|
static |
Definition at line 458 of file mbgtime.h.
References MBG_FRAC32_CONVERSION_TYPE.
|
static |
Definition at line 466 of file mbgtime.h.
References MBG_FRAC32_CONVERSION_TYPE, and MBG_FRAC32_UNITS_PER_SEC.
|
static |
Convert a binary fraction to "double" fractions.
Convert a binary fraction (e.g. of a second, as in PCPS_TIME_STAMP::frac) to a "double" with the units of seconds.
E.g. a 0xFFFFFFFF fraction yields 0.9999999999....
[in] | b | The binary fraction |
Definition at line 534 of file mbgtime.h.
References check_timeout(), clear_time(), date_of_year(), day_of_week(), day_of_year(), days_to_years(), err_tm(), is_leap_year(), MBG_FRAC32_UNITS_PER_SEC, n_days(), set_timeout(), sprint_date(), sprint_day_date(), sprint_short_time(), sprint_time(), sprint_tm(), sscan_date(), sscan_time(), stretch_timeout(), tm_to_wsec(), and wsec_to_tm().
Referenced by get_htc_delta().
int err_tm | ( | const TM_GPS * | tm | ) |
Check if a TM_GPS structure contains a valid date and time.
[in] | tm | The date/time structure to be checked |
Referenced by dfrac_sec_from_bin().
|
static |
Convert a binary fraction to a scaled decimal.
Convert a binary fraction (e.g. of a second, as in PCPS_TIME_STAMP::frac) to a decimal fraction, using a specified scale factor.
[in] | b | The binary fraction |
[in] | scale | The scale factor |
Definition at line 509 of file mbgtime.h.
References bin_frac_32_to_dec_frac().
int is_leap_year | ( | int | y | ) |
Check if a specific year is a leap year.
[in] | y | The full year number |
Referenced by dfrac_sec_from_bin().
Compute number of days after Jan 1, 0000 for a given date.
[in] | mday | The day-of-month |
[in] | month | The month |
[in] | year | The full year number |
Referenced by dfrac_sec_from_bin().
void set_timeout | ( | TIMEOUT * | t, |
clock_t | clk, | ||
clock_t | interval | ||
) |
Set a timeout object to specified interval.
[out] | t | The timeout object |
[in] | clk | The current time, in clock_t ticks |
[in] | interval | The interval until expiration, in clock_t ticks |
Referenced by dfrac_sec_from_bin().
int sprint_date | ( | char * | s, |
const TM_GPS * | tm | ||
) |
Print date to a string.
[out] | s | Address of a string buffer to be filled |
[in] | tm | Address of a TM_GPS structure providing date and time |
Referenced by dfrac_sec_from_bin().
int sprint_day_date | ( | char * | s, |
const TM_GPS * | tm | ||
) |
Print day-of-week and date to a string.
[out] | s | Address of a string buffer to be filled |
[in] | tm | Address of a TM_GPS structure providing date and time |
Referenced by dfrac_sec_from_bin().
int sprint_short_time | ( | char * | s, |
const TM_GPS * | tm | ||
) |
Print time with hours, minutes to a string.
[out] | s | Address of a string buffer to be filled |
[in] | tm | Address of a TM_GPS structure providing date and time |
Referenced by dfrac_sec_from_bin().
int sprint_time | ( | char * | s, |
const TM_GPS * | tm | ||
) |
Print time with hours, minutes, seconds to a string.
[out] | s | Address of a string buffer to be filled |
[in] | tm | Address of a TM_GPS structure providing date and time |
Referenced by dfrac_sec_from_bin().
int sprint_tm | ( | char * | s, |
const TM_GPS * | tm | ||
) |
Print day-of-week, date and time to a string.
[out] | s | Address of a string buffer to be filled |
[in] | tm | Address of a TM_GPS structure providing date and time |
Referenced by dfrac_sec_from_bin().
void sscan_date | ( | char * | s, |
TM_GPS * | tm | ||
) |
Extract a date from a string.
[in] | s | A date string in format dd.mm. or dd.mm.yyyy |
[out] | tm | Address of a TM_GPS structure which takes the extracted date |
Referenced by dfrac_sec_from_bin().
void sscan_time | ( | const char * | s, |
TM_GPS * | tm | ||
) |
Extract a time from a string.
[in] | s | A time string in format hh:mm:ss |
[out] | tm | Address of a TM_GPS structure which takes the extracted time |
Referenced by dfrac_sec_from_bin().
void stretch_timeout | ( | TIMEOUT * | t, |
clock_t | interval | ||
) |
Stretch a timeout specified in given timeout object.
[in,out] | t | The timeout object |
[in] | interval | The interval until expiration, in clock_t ticks |
Referenced by dfrac_sec_from_bin().
long tm_to_wsec | ( | const TM_GPS * | tm | ) |
Compute second-of-week from day-of-week and time-of-day.
[in] | tm | Address of a TM_GPS structure providing day-of-week and time-of-day |
Referenced by dfrac_sec_from_bin().
Convert second-of-week to day-of-week and time-of-day.
[in] | wsec | The second-of-week number to be converted |
[out] | tm | Address of a TM_GPS structure which takes the computed results |
Referenced by dfrac_sec_from_bin().
const char* date_fmt |
TM_GPS datum |
const char* day_date_fmt |
const char* day_name_eng[] |
const char* day_name_ger[] |
DAYS_OF_MONTH_TABLE days_of_month |
TM_GPS dhms |
const TM_GPS init_tm |
const char* long_time_fmt |
const char* short_time_fmt |
const char* time_fmt |