mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
icsneolegacy: Implemented get() and set() RTC functions
This commit is contained in:
@@ -5,6 +5,10 @@
|
||||
|
||||
#include "icsneo/icsneocpp.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4996) // STL time functions
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
// Print version
|
||||
std::cout << "Running libicsneo " << icsneo::GetVersion() << std::endl;
|
||||
@@ -118,6 +122,36 @@ int main() {
|
||||
}
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
// Set the real time clock on the device using the system clock
|
||||
// First, let's see if we can get the time from the device (if it has an RTC)
|
||||
std::cout << "\n\tChecking and setting the RTC on the device" << std::endl;
|
||||
auto dTime = device->getRTC();
|
||||
if (dTime.has_value()) {
|
||||
std::time_t time = std::chrono::system_clock::to_time_t(dTime.value());
|
||||
const auto timeInfo = std::gmtime(&time);
|
||||
if(!timeInfo)
|
||||
return false;
|
||||
std::cout << "\t\tGetting current UTC time: " << std::put_time(timeInfo, "%Y-%m-%d %H:%M:%S") << std::endl;
|
||||
} else {
|
||||
std::cout << "\t\tTime not available" << std::endl;
|
||||
}
|
||||
|
||||
// Now, set the time using the system's clock so that we can check it again to ensure it's set
|
||||
auto now = std::chrono::system_clock::now();
|
||||
device->setRTC(now);
|
||||
std::cout << "\t\tTime is now set..." << std::endl;
|
||||
|
||||
// Get the time again after setting
|
||||
auto dTime2 = device->getRTC();
|
||||
if (dTime2.has_value()) {
|
||||
std::time_t time2 = std::chrono::system_clock::to_time_t(dTime2.value());
|
||||
const auto timeInfo2 = std::gmtime(&time2);
|
||||
if(!timeInfo2)
|
||||
return false;
|
||||
std::cout << "\t\tGetting current UTC time: " << std::put_time(timeInfo2, "%Y-%m-%d %H:%M:%S") << std::endl;
|
||||
} else {
|
||||
std::cout << "\t\tTime is not available" << std::endl;
|
||||
}
|
||||
// Now we can either register a handler (or multiple) for messages coming in
|
||||
// or we can enable message polling, and then call device->getMessages periodically
|
||||
|
||||
@@ -127,7 +161,7 @@ int main() {
|
||||
// Keep in mind that 20k messages comes quickly at high bus loads!
|
||||
|
||||
// We can transmit messages
|
||||
std::cout << "\tTransmitting an extended CAN FD frame... ";
|
||||
std::cout << "\n\tTransmitting an extended CAN FD frame... ";
|
||||
auto txMessage5 = std::make_shared<icsneo::CANMessage>();
|
||||
txMessage5->network = icsneo::Network::NetID::HSCAN;
|
||||
txMessage5->arbid = 0x1C5001C5;
|
||||
|
||||
Reference in New Issue
Block a user