added rtc functions
parent
b44bf07d1b
commit
dee031710f
|
|
@ -41,22 +41,25 @@ ICSNEO_API icsneo_error_t icsneo_error_code(icsneo_error_t error_code, const cha
|
|||
std::string error;
|
||||
switch (error_code) {
|
||||
case icsneo_error_success:
|
||||
error = "success";
|
||||
error = "Success";
|
||||
break;
|
||||
case icsneo_error_invalid_parameters:
|
||||
error = "invalid parameters";
|
||||
error = "Invalid function parameters";
|
||||
break;
|
||||
case icsneo_error_open_failed:
|
||||
error = "open failed";
|
||||
error = "Open failed";
|
||||
break;
|
||||
case icsneo_error_go_online_failed:
|
||||
error = "go online failed";
|
||||
error = "Going online failed";
|
||||
break;
|
||||
case icsneo_error_enable_message_polling_failed:
|
||||
error = "enable message polling failed";
|
||||
error = "Enable message polling failed";
|
||||
break;
|
||||
case icsneo_error_sync_rtc_failed:
|
||||
error = "sync RTC failed";
|
||||
error = "Syncronizing RTC failed";
|
||||
break;
|
||||
case icsneo_error_rtc_failure:
|
||||
error = "RTC failure";
|
||||
break;
|
||||
// Don't default, let the compiler warn us if we forget to handle an error code
|
||||
}
|
||||
|
|
@ -621,6 +624,30 @@ ICSNEO_API icsneo_error_t icsneo_event_get_description(icsneo_event_t* event, co
|
|||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
ICSNEO_API icsneo_error_t icsneo_device_get_rtc(icsneo_device_t* device, int64_t* unix_epoch) {
|
||||
if (!device || !unix_epoch) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
if (auto rtc_time = device->device->getRTC(); rtc_time != std::nullopt) {
|
||||
*unix_epoch = std::chrono::duration_cast<std::chrono::seconds>(rtc_time->time_since_epoch()).count();
|
||||
} else {
|
||||
*unix_epoch = 0;
|
||||
return icsneo_error_rtc_failure;
|
||||
}
|
||||
return icsneo_error_success;
|
||||
}
|
||||
ICSNEO_API icsneo_error_t icsneo_device_set_rtc(icsneo_device_t* device, int64_t* unix_epoch) {
|
||||
if (!device || !unix_epoch) {
|
||||
return icsneo_error_invalid_parameters;
|
||||
}
|
||||
// TODO: Check if device is valid
|
||||
if (!device->device->setRTC(std::chrono::system_clock::time_point(std::chrono::seconds(*unix_epoch)))) {
|
||||
return icsneo_error_sync_rtc_failed;
|
||||
}
|
||||
return icsneo_error_success;
|
||||
}
|
||||
|
||||
/*
|
||||
Type getType() const noexcept { return Type(eventStruct.eventNumber); }
|
||||
Severity getSeverity() const noexcept { return Severity(eventStruct.severity); }
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ typedef enum _icsneo_error_t {
|
|||
icsneo_error_get_messages_failed,
|
||||
// Generic invalid type error
|
||||
icsneo_error_invalid_type,
|
||||
// Generic RTC error code
|
||||
icsneo_error_rtc_failure,
|
||||
} _icsneo_error_t;
|
||||
|
||||
/** @brief Integer representation of _icsneo_error_t enum.
|
||||
|
|
@ -408,17 +410,6 @@ ICSNEO_API icsneo_error_t icsneo_can_message_baudrate_switch(icsneo_device_t* de
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_can_message_error_state_indicator(icsneo_device_t* device, icsneo_message_t* message, bool* value);
|
||||
|
||||
|
||||
/*
|
||||
uint32_t arbid;
|
||||
uint8_t dlcOnWire;
|
||||
bool isRemote = false; // Not allowed if CAN FD
|
||||
bool isExtended = false;
|
||||
bool isCANFD = false;
|
||||
bool baudrateSwitch = false; // CAN FD only
|
||||
bool errorStateIndicator = false; // CAN FD only
|
||||
*/
|
||||
|
||||
/** @brief Get the global events not specifically related to a device.
|
||||
*
|
||||
* @param[out] icsneo_event_t** events Pointer to an array of icsneo_event_t to copy the events into.
|
||||
|
|
@ -450,6 +441,24 @@ ICSNEO_API icsneo_error_t icsneo_device_get_events(icsneo_device_t* device, icsn
|
|||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_event_get_description(icsneo_event_t* event, const char* value, uint32_t* value_length);
|
||||
|
||||
/** @brief Get the RTC (Real time clock) of a device.
|
||||
*
|
||||
* @param[in] icsneo_device_t device The device to get the RTC of.
|
||||
* @param[out] int64_t* unix_epoch Pointer to an int64_t to copy the RTC into.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_device_get_rtc(icsneo_device_t* device, int64_t* unix_epoch);
|
||||
|
||||
/** @brief Set the RTC (Real time clock) of a device.
|
||||
*
|
||||
* @param[in] icsneo_device_t device The device to get the RTC of.
|
||||
* @param[in] int64_t* unix_epoch int64_t to copy the RTC into.
|
||||
*
|
||||
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
|
||||
*/
|
||||
ICSNEO_API icsneo_error_t icsneo_device_set_rtc(icsneo_device_t* device, int64_t* unix_epoch);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue