실시간 시계 및 달력
More...
#include <RTCCalendar.hpp>
|
| void | getDateTime (struct tm &t) |
| | 현재 로컬 시간을 가져옵니다.
|
| time_t | getDateTime () |
| | 현재 로컬 시간을 가져옵니다.
|
| void | getUTC (struct tm &t) |
| | 현재 UTC 시간을 가져옵니다.
|
| time_t | getUTC () |
| | 현재 UTC 시간을 가져옵니다.
|
| void | setDateTime (struct tm &t) |
| | 현재 로컬 시간을 설정합니다.
|
| void | setDateTime (time_t t) |
| | 현재 로컬 시간을 설정합니다.
|
| void | setUTC (struct tm &t) |
| | 현재 UTC 시간을 설정합니다.
|
| void | setUTC (time_t t) |
| | 현재 UTC 시간을 설정합니다.
|
| void | setDateTimeAlarm (struct tm &t) |
| | 현재 로컬 시간을 기준으로 알람을 설정합니다.
|
| void | setDateTimeAlarm (time_t t) |
| | 현재 로컬 시간을 기준으로 알람을 설정합니다.
|
| error_t | setTimeAlarm (uint8_t hour, uint8_t min, uint8_t sec=0) |
| | 현재 로컬 시간을 기준으로 알람을 설정합니다.
|
| void | onDateTimeAlarm (void(*func)()) |
| | 알람 발생시 호출될 콜백함수를 지정합니다.
|
| void | setTimeDiff (int16_t diffMinutes) |
| | UTC와 로컬 시간과의 차이를 분 단위로 지정합니다.
|
| int16_t | getTimeDiff () |
| | UTC와 로컬 시간과의 차이를 반환합니다.
|
| virtual void | getTimeSinceBoot (struct timeval *tv)=0 |
| | 보드 부팅 이후부터 현재까지의 경과 시간을 구합니다.
|
|
virtual void | signalAlarm () |
|
|
virtual void | getUTCFromHardware (uint16_t *year, uint8_t *month, uint8_t *day, uint8_t *hour, uint8_t *min, uint8_t *sec, uint32_t *subsec=NULL)=0 |
|
virtual void | setUTCToHardware (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec, int32_t subsec=0)=0 |
|
virtual void | setUTCAlarmToHardware (uint8_t hour, uint8_t min, uint8_t sec)=0 |
실시간 시계 및 달력
RTCCalendar 는 실시간 시계, 달력, 및 알람 기능을 위해 사용됩니다. 사용자 응용이 이해하기 쉬운 struct tm, 및 time_t를 사용하여 하드웨어에 현재 시간 및 알람 시간을 설정할 수 있습니다. 또한 하드웨어 시간을 struct tm, 또는 time_t로 변환하여 사용할 수 있습니다.
RTCCalendar 를 상속받은 시스템은 시스템 시간을 유지합니다. 시스템 시간은 setDateTime(), setUTC(), 또는 settimeofday() 등을 통해서 설정됩니다. 설정된 시스템 시간은 getDateTime(), getUTC(), 또는 gettimeofday() 등을 통해서 조회할 수 있습니다. 시스템 시간은 전원이 유지되는 한, reboot() 을 통한 소프트웨어 리셋에 상관없이 유지됩니다. MCU 종류별 시스템 시간의 초기화 및 유지는 다음과 같습니다.
◆ getDateTime() [1/2]
| time_t RTCCalendar::getDateTime |
( |
| ) |
|
현재 로컬 시간을 가져옵니다.
- Returns
- Unix epoch 형태의 현재 로컬 시간
다음과 같이 사용합니다.
static const char *weekday[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
static void printTask(void *args) {
Serial.write("0123456789\r\n");
printf(
"[%lu usec] Timer works!\n",
micros());
struct tm t;
System.getDateTime(t);
struct timeval now;
gettimeofday(&now, NULL);
printf(
"Now: %u-%u-%u %s %02u:%02u:%02u (%lu.%06ld)\n",
t.tm_year + 1900,
t.tm_mon + 1,
t.tm_mday,
weekday[t.tm_wday],
t.tm_hour,
t.tm_min,
t.tm_sec,
(uint32_t) now.tv_sec,
now.tv_usec
);
printf("Supply voltage: %ld mV\n", System.getSupplyVoltage());
}
◆ getDateTime() [2/2]
| void RTCCalendar::getDateTime |
( |
struct tm & | t | ) |
|
현재 로컬 시간을 가져옵니다.
- Parameters
-
다음과 같이 사용합니다.
static const char *weekday[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
static void printTask(void *args) {
Serial.write("0123456789\r\n");
printf(
"[%lu usec] Timer works!\n",
micros());
struct tm t;
System.getDateTime(t);
struct timeval now;
gettimeofday(&now, NULL);
printf(
"Now: %u-%u-%u %s %02u:%02u:%02u (%lu.%06ld)\n",
t.tm_year + 1900,
t.tm_mon + 1,
t.tm_mday,
weekday[t.tm_wday],
t.tm_hour,
t.tm_min,
t.tm_sec,
(uint32_t) now.tv_sec,
now.tv_usec
);
printf("Supply voltage: %ld mV\n", System.getSupplyVoltage());
}
◆ getTimeDiff()
| int16_t RTCCalendar::getTimeDiff |
( |
| ) |
|
UTC와 로컬 시간과의 차이를 반환합니다.
- Returns
- UTC와 로컬 시간과의 차이 (단위: 분)
◆ getTimeSinceBoot()
| virtual void RTCCalendar::getTimeSinceBoot |
( |
struct timeval * | tv | ) |
|
|
pure virtual |
보드 부팅 이후부터 현재까지의 경과 시간을 구합니다.
- Parameters
-
| tv[out] | 경과 시간이 반환될 timeval 포인터 |
Implemented in McuATSAMD21, McuATSAMR21, McuESP32, McuMSP430x5, McuNRF51, McuSTM32F0xx, McuSTM32F4xx, McuSTM32L0xx, McuSTM32L1xx, McuSTM32L4xx, and McuSTM32WLxx.
◆ getUTC() [1/2]
| time_t RTCCalendar::getUTC |
( |
| ) |
|
현재 UTC 시간을 가져옵니다.
- Returns
- Unix epoch 형태의 현재 UTC 시간
◆ getUTC() [2/2]
| void RTCCalendar::getUTC |
( |
struct tm & | t | ) |
|
현재 UTC 시간을 가져옵니다.
- Parameters
-
◆ onDateTimeAlarm()
| void RTCCalendar::onDateTimeAlarm |
( |
void(* | func )() | ) |
|
알람 발생시 호출될 콜백함수를 지정합니다.
- Parameters
-
◆ setDateTime() [1/2]
| void RTCCalendar::setDateTime |
( |
struct tm & | t | ) |
|
현재 로컬 시간을 설정합니다.
- Parameters
-
| [in] | t | 설정할 현재 로컬 시간이 저장된 구조체 |
◆ setDateTime() [2/2]
| void RTCCalendar::setDateTime |
( |
time_t | t | ) |
|
현재 로컬 시간을 설정합니다.
- Parameters
-
| [in] | t | 설정할 현재 로컬 시간 (Unix epoch) |
◆ setDateTimeAlarm() [1/2]
| void RTCCalendar::setDateTimeAlarm |
( |
struct tm & | t | ) |
|
현재 로컬 시간을 기준으로 알람을 설정합니다.
- Parameters
-
◆ setDateTimeAlarm() [2/2]
| void RTCCalendar::setDateTimeAlarm |
( |
time_t | t | ) |
|
현재 로컬 시간을 기준으로 알람을 설정합니다.
- Parameters
-
◆ setTimeAlarm()
| error_t RTCCalendar::setTimeAlarm |
( |
uint8_t | hour, |
|
|
uint8_t | min, |
|
|
uint8_t | sec = 0 ) |
현재 로컬 시간을 기준으로 알람을 설정합니다.
- Parameters
-
| [in] | hour | 알람을 설정할 시 (hour, 범위: 0~23) |
| [in] | min | 알람을 설정할 분 (minute, 범위: 0~59) |
| [in] | sec | 알람을 설정할 초 (second, 범위: 0~59) |
- Note
- 초 단위는 하드웨어에 따라 지원하지 않을 수 있습니다.
◆ setTimeDiff()
| void RTCCalendar::setTimeDiff |
( |
int16_t | diffMinutes | ) |
|
UTC와 로컬 시간과의 차이를 분 단위로 지정합니다.
- Parameters
-
| [in] | diffMinutes | UTC와 로컬 시간과의 차이 (단위: 분) |
예를 들어, 한국 표준 시를(Korean Standard Time: GMT+09:00) 로컬 시간으로 사용하기 위해서는 diffMinutes 를 540 (9 * 60) 분으로 지정합니다. 이 차이를 설정하지 않으면 UTC와 로컬 시간의 차이는 0입니다. 즉, UTC로 동작하게 됩니다.
System.setTimeDiff(9 * 60);
◆ setUTC() [1/2]
| void RTCCalendar::setUTC |
( |
struct tm & | t | ) |
|
현재 UTC 시간을 설정합니다.
- Parameters
-
| [in] | t | 설정할 현재 UTC 시간이 저장된 구조체 |
◆ setUTC() [2/2]
| void RTCCalendar::setUTC |
( |
time_t | t | ) |
|
현재 UTC 시간을 설정합니다.
- Parameters
-
| [in] | t | 설정할 현재 UTC 시간 (Unix epoch) |
The documentation for this class was generated from the following file: