RTC C++

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. More...

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

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;
    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;
    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 << "Synchronism time period : " << params_struct.sync_time_seconds << "s" << std::endl;
    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";
    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>
    void result_handler(boost::system::error_code& ec, struct tm date_and_time)
    {
    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;
    return 0;
    }


bool LocalTime
Indicates if source is provided in local time or UTC time.
Definition: dateSourceTypes.h:33
Definition: dateSourceTypes.h:28
Parameters struct which contains the response received from the service.
Definition: rtcApi.h:24
void asyncGetDateTime(dpyRtc::time_and_date_handler handler)
Method to get date and time coming from RTC service.
boost::function< void(boost::system::error_code &ec, struct tm date_and_time)> time_and_date_handler
Handler for result function callback. This type of function is called when the status callback is don...
Definition: rtcApi.h:55
DateSourceType Type
Date Source Type.
Definition: dateSourceTypes.h:30
void asyncSetSyncTime(std::uint32_t time_s, dpyRtc::result_handler handler)
Method to set synchronism time period in seconds.
void asyncSetDiffTime(std::uint32_t time_s, dpyRtc::result_handler handler)
Method to set maximum time in seconds allowed to RTC to be drifted from UTC valid time.
std::uint32_t Priority
Priority of date source [1 - highest priority, 100 - lowest priority].
Definition: dateSourceTypes.h:31
void asyncGetConfigValues(dpyRtc::params_handler handler)
Method to get configuration parameters coming from RTC service.
boost::function< void(boost::system::error_code &ec)> result_handler
Handler for result function callback. This type of function is called when the status callback is don...
Definition: rtcApi.h:40
std::uint32_t sync_time_seconds
Synchronism time period in seconds.
Definition: rtcApi.h:26
boost::system::error_code addNewSourceDate(const std::string &source_name, const dpyRtc::DateSources &source)
Method used to add a date source.
boost::system::error_code deleteSourceDate(const std::string &source_name)
Delete a particular date source.
std::string URI
URL/IP address or file absolute path where date source is located (127.0.0.1 for localhost)
Definition: dateSourceTypes.h:32
std::uint32_t max_diff_time_seconds
Maximum time in seconds allowed to RTC to be drifted from UTC valid time.
Definition: rtcApi.h:27
Allows to interact with a RTC Service.
Definition: rtcApi.h:89