RTC C++
Namespaces | |
dpyRtc | |
Deepsy Rtc namespace that includes the different enums, structs or method signatures that should be used. | |
Classes | |
class | Rtc |
Allows to interact with a RTC Service. More... | |
Detailed Description
A quick overview of basic RTC API capabilities and examples is given.
If you find RTC API useful and would like to know more details, please check out further sections of the RTC API documentation or contact the Deepsy platform team.
Examples
-
Creating a RTC object
#include <dpy/rtcApi.h>RTC service;
-
Set synchronism time period in seconds
An example on how to set synchronism time is provided:#include <dpy/rtcApi.h>#include <iostream>void result_handler(boost::system::error_code ec){if (ec.value()) {std::cout << "Error : " << ec.message() << std::endl;} else {std::cout << "Synchronous operation performed successfully" << std::endl;}}int main(){Rtc rtc;std::uint32_t period = 100;rtc.asyncSetSyncTime(period, result_handler);return 0;} -
Set maximum time in seconds allowed to RTC to be drifted from UTC valid time
An example on how to set maximum time in seconds is provided:#include <dpy/rtcApi.h>#include <iostream>void result_handler(boost::system::error_code ec){if (ec.value()) {std::cout << "Error : " << ec.message() << std::endl;} else {std::cout << "Synchronous operation performed successfully" << std::endl;}}int main(){Rtc rtc;std::uint32_t period = 15;rtc.asyncSetDiffTime(period, result_handler);return 0;} -
Get RTC configuration parameters
In order to get RTC configuration parameters, dpyRtc::ParamConfig struct must be attended. An example is provided:#include <dpy/rtcApi.h>#include <iostream>void config_values_handler(boost::system::error_code error_code, dpyRtc::ParamConfig & params_struct){if (error_code.value() != 0) {std::cout << "Error : " << error_code.message() << std::endl;} else {std::cout << "Maximum time allowed to be drifted from UTC valid time: " << params_struct.max_diff_time_seconds << "s" << std::endl;}}int main(){Rtc rtc;rtc.asyncGetConfigValues(config_values_handler);return 0;} -
Add a Date Source and remove it from RTC service
#include <dpy/rtcApi.h>#include <iostream>int main(){Rtc rtc;boost::system::error_code ec;std::string source_name = "gnss1";dpyRtc::DateSources source;source.Type = dpyRtc::DateSourceType::GNSS;source.Priority = 2;source.URI = "127.0.0.1";source.LocalTime = false;ec = rtc.addNewSourceDate(source_name, source);if (ec.value() == 0) {std::cout << "Source added successfully" << std::endl;ec = rtc.deleteSourceDate(source_name);if (ec.value() == 0) {std::cout << "Source removed successfully" << std::endl;} else {std::cout << "Could not perform Date Source operation. Error = " << ec.value() << ", " << ec.message().c_str() << std::endl;}} else {std::cout << "Could not perform Date Source operation. Error = " << ec.value() << ", " << ec.message().c_str() << std::endl;}} -
Get date time from RTC service
#include <dpy/rtcApi.h>#include <iostream>{if (ec.value()) {std::cout << "Error : " << ec.message() << std::endl;} else {std::cout << "Synchronous operation performed successfully" << std::endl;std::cout << "Current date and time: " << date_and_time.tm_hour << ":" << date_and_time.tm_min << ":" << date_and_time.tm_sec << " " << date_and_time.tm_mday << "/" << date_and_time.tm_mon << "/" << date_and_time.tm_year << std::endl;}}int main(){Rtc rtc;rtc.asyncGetDateTime(static_cast<dpyRtc::time_and_date_handler> (result_handler));return 0;}