maix::time
maix.time module
This is
maix::time
module of MaixCDK.
All of these elements are in namespacemaix::time
.For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!
Module
No module
Enum
Variable
Function
time
Get current time in s
item | description |
---|---|
return | current time in s, double type |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, e.g. before NTP: 10(s), after: 1718590639.5149617(s). If you want to calculate time interval, please use ticks_s(). |
C++ defination code:
double time()
time_ms
Get current time in ms
item | description |
---|---|
return | current time in ms, uint64_t type |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, e.g. before NTP: 10000(ms), after: 1718590639000(ms) If you want to calculate time interval, please use ticks_ms(). |
C++ defination code:
uint64_t time_ms()
time_s
Get current time in s
item | description |
---|---|
return | current time in s, uint64_t type |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, e.g. before NTP: 10(s), after: 1718590639(s) |
C++ defination code:
uint64_t time_s()
time_us
Get current time in us
item | description |
---|---|
return | current time in us, uint64_t type |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, e.g. before NTP: 10000000(us), after: 1718590639000000(s) If you want to calculate time interval, please use ticks_us(). |
C++ defination code:
uint64_t time_us()
time_diff
Calculate time difference in s.
item | description |
---|---|
param | last: last time now: current time, can be -1 if use current time |
return | time difference |
attention | If board have no RTC battery, when bootup and connect to network, system will automatically sync time by NTP, will cause time() have big change, and lead to big value. e.g. before NTP: 1(s), after: 1718590500(s) If you want to calculate time interval, please use ticks_diff(). |
C++ defination code:
double time_diff(double last, double now = -1)
ticks_s
Get current time in s since bootup
item | description |
---|---|
return | current time in s, double type |
C++ defination code:
double ticks_s()
ticks_ms
Get current time in ms since bootup
item | description |
---|---|
return | current time in ms, uint64_t type |
C++ defination code:
uint64_t ticks_ms()
ticks_us
Get current time in us since bootup
item | description |
---|---|
return | current time in us, uint64_t type |
C++ defination code:
uint64_t ticks_us()
ticks_diff
Calculate time difference in s.
item | description |
---|---|
param | last: last time now: current time, can be -1 if use current time |
return | time difference |
C++ defination code:
double ticks_diff(double last, double now = -1)
sleep
Sleep seconds
item | description |
---|---|
param | s: seconds, double type |
C++ defination code:
void sleep(double s)
sleep_ms
Sleep milliseconds
item | description |
---|---|
param | ms: milliseconds, uint64_t type |
C++ defination code:
void sleep_ms(uint64_t ms)
sleep_us
Sleep microseconds
item | description |
---|---|
param | us: microseconds, uint64_t type |
C++ defination code:
void sleep_us(uint64_t us)
fps
Calculate FPS since last call this method.\nAttention, this method is not multi thread safe, only call this method in one threads.\nIf you want to use in multi threads, please use time.FPS class.\nFPS is average value of recent n(buff_len) times, and you can call fps_set_buff_len(10) to change buffer length, default is 20.\nMultiple invoke this function will calculate fps between two invoke, and you can also call fps_start() fisrt to manually assign fps calulate start point.
item | description |
---|---|
return | float type, current fps since last call this method |
C++ defination code:
float fps()
fps_start
Manually set fps calculation start point, then you can call fps() function to calculate fps between fps_start() and fps().
C++ defination code:
void fps_start()
fps_set_buff_len
Set fps method buffer length, by default the buffer length is 10.
item | description |
---|---|
param | len: Buffer length to store recent fps value. |
C++ defination code:
void fps_set_buff_len(int len)
now
Get current UTC date and time
item | description |
---|---|
return | current date and time, DateTime type |
C++ defination code:
time::DateTime *now()
localtime
Get local time
item | description |
---|---|
return | local time, DateTime type |
C++ defination code:
time::DateTime *localtime()
strptime
DateTime from string
item | description |
---|---|
param | str: date time string format: date time format |
return | DateTime |
C++ defination code:
time::DateTime *strptime(const std::string &str, const std::string &format)
gmtime
timestamp to DateTime(time zone is UTC (value 0))
item | description |
---|---|
param | timestamp: double timestamp |
return | DateTime |
C++ defination code:
time::DateTime *gmtime(double timestamp)
timezone
Set or get timezone
item | description |
---|---|
param | timezone: string type, can be empty and default to empty, if empty, only return crrent timezone, a "region/city" string, e.g. Asia/Shanghai, Etc/UTC, you can get all by list_timezones function. |
return | string type, return current timezone setting. |
attention | when set new timezone, time setting not take effect in this process for some API, so you need to restart program. |
C++ defination code:
std::string timezone(const std::string &timezone = "")
timezone (overload 1)
Set or get timezone
item | description |
---|---|
param | region: string type, which region to set, can be empty means only get current, default empty. city: string type, which city to set, can be empty means only get current, default empty. |
return | list type, return current timezone setting, first is region, second is city. |
attention | when set new timezone, time setting not take effect in this process for some API, so you need to restart program. |
C++ defination code:
std::vector<std::string> timezone2(const std::string ®ion = "", const std::string &city = "")
list_timezones
List all timezone info
item | description |
---|---|
return | A dict with key are regions, and value are region's cities. |
C++ defination code:
std::map<std::string, std::vector<std::string>> list_timezones()
ntp_timetuple
Retrieves time from an NTP server\nThis function fetches the current time from the specified NTP server and port,\nreturning a tuple containing the time details.
item | description |
---|---|
param | host: The hostname or IP address of the NTP server. port: The port number of the NTP server. Use -1 for the default port 123. retry: The number of retry attempts. Must be at least 1. timeout_ms: The timeout duration in milliseconds. Must be non-negative. |
return | A list of 6 elements: [year, month, day, hour, minute, second] |
C++ defination code:
std::vector<int> ntp_timetuple(std::string host, int port=-1, uint8_t retry=3, int timeout_ms=0)
ntp_timetuple_with_config
Retrieves time from an NTP server using a configuration file\nThis function reads the configuration from a YAML file to fetch the current time\nfrom a list of specified NTP servers, returning a tuple containing the time details.
item | description |
---|---|
param | path: The path to the YAML configuration file, which should include: - Config: - retry: Number of retry attempts (must be at least 1) - total_timeout_ms: Total timeout duration in milliseconds (must be non-negative) - NtpServers: - host: Hostname or IP address of the NTP server - port: Port number of the NTP server (use 123 for default) Example YAML configuration: Config: - retry: 3 - total_timeout_ms: 10000 NtpServers: - host: "pool.ntp.org" port: 123 - host: "time.nist.gov" port: 123 - host: "time.windows.com" port: 123 |
return | A list of 6 elements: [year, month, day, hour, minute, second] |
C++ defination code:
std::vector<int> ntp_timetuple_with_config(std::string path)
ntp_sync_sys_time
Retrieves time from an NTP server and synchronizes the system time\nThis function fetches the current time from the specified NTP server and port,\nthen synchronizes the system time with the retrieved time.
item | description |
---|---|
param | host: The hostname or IP address of the NTP server. port: The port number of the NTP server. Use 123 for the default port. retry: The number of retry attempts. Must be at least 1. timeout_ms: The timeout duration in milliseconds. Must be non-negative. |
return | A list of 6 elements: [year, month, day, hour, minute, second] |
C++ defination code:
std::vector<int> ntp_sync_sys_time(std::string host, int port=-1, uint8_t retry=3, int timeout_ms=0)
ntp_sync_sys_time_with_config
Retrieves time from an NTP server using a configuration file and synchronizes the system time\nThis function reads the configuration from a YAML file to fetch the current time\nfrom a list of specified NTP servers, then synchronizes the system time with the retrieved time.
item | description |
---|---|
param | path: The path to the YAML configuration file, which should include: - Config: - retry: Number of retry attempts (must be at least 1) - total_timeout_ms: Total timeout duration in milliseconds (must be non-negative) - NtpServers: - host: Hostname or IP address of the NTP server - port: Port number of the NTP server (use 123 for default) Example YAML configuration: Config: - retry: 3 - total_timeout_ms: 10000 NtpServers: - host: "pool.ntp.org" port: 123 - host: "time.nist.gov" port: 123 - host: "time.windows.com" port: 123 |
return | A vector of integers containing the time details: [year, month, day, hour, minute, second] |
C++ defination code:
std::vector<int> ntp_sync_sys_time_with_config(std::string path)
Class
FPS
FPS class to use average filter to calculate FPS.
C++ defination code:
class FPS
FPS
FPS class constructor
item | description |
---|---|
type | func |
param | buff_len: Average buffer length, default 20, that is, fps() function will return the average fps in recent buff_len times fps. |
static | False |
C++ defination code:
FPS(int buff_len = 20)
start
Manually set fps calculation start point, then you can call fps() function to calculate fps between start() and fps().
item | description |
---|---|
type | func |
static | False |
C++ defination code:
void start()
fps
The same as end function.
item | description |
---|---|
type | func |
return | float type, current fps since last call this method |
static | False |
C++ defination code:
float fps()
fps (overload 1)
Calculate FPS since last call this method.\nFPS is average value of recent n(buff_len) times, and you can call fps_set_buff_len(10) to change buffer length, default is 20.\nMultiple invoke this function will calculate fps between two invoke, and you can also call fps_start() fisrt to manually assign fps calulate start point.
item | description |
---|---|
type | func |
return | float type, current fps since last call this method |
static | False |
C++ defination code:
inline float end()
set_buff_len
Set fps method buffer length, by default the buffer length is 10.
item | description |
---|---|
type | func |
param | len: Buffer length to store recent fps value. |
static | False |
C++ defination code:
void set_buff_len(int len)
DateTime
Date and time class
C++ defination code:
class DateTime
year
Year
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int year
month
Month, 1~12
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int month
day
Day
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int day
hour
Hour
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int hour
minute
Minute
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int minute
second
Second
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int second
microsecond
Microsecond
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int microsecond
yearday
Year day
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int yearday
weekday
Weekday, 0 is Monday, 6 is Sunday
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
int weekday
zone
Time zone
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
float zone
zone_name
Time zone name
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
std::string zone_name
DateTime
Constructor
item | description |
---|---|
type | func |
param | year: year month: month day: day hour: hour minute: minute second: second microsecond: microsecond yearday: year day weekday: weekday zone: time zone |
static | False |
C++ defination code:
DateTime(int year = 0, int month = 0, int day = 0, int hour = 0, int minute = 0, int second = 0, int microsecond = 0, int yearday = 0, int weekday = 0, int zone = 0)
strftime
Convert to string
item | description |
---|---|
type | func |
return | date time string |
static | False |
C++ defination code:
std::string strftime(const std::string &format)
timestamp
Convert to float timestamp
item | description |
---|---|
type | func |
return | float timestamp |
static | False |
C++ defination code:
double timestamp()