Compare commits

..

2 Commits

Author SHA1 Message Date
David Rebbe 875bf45421 added icsneo_device_load_default_settings 2024-12-04 23:18:26 -05:00
David Rebbe dee031710f added rtc functions 2024-12-04 23:08:49 -05:00
2 changed files with 75 additions and 36 deletions

View File

@ -41,22 +41,28 @@ ICSNEO_API icsneo_error_t icsneo_error_code(icsneo_error_t error_code, const cha
std::string error; std::string error;
switch (error_code) { switch (error_code) {
case icsneo_error_success: case icsneo_error_success:
error = "success"; error = "Success";
break; break;
case icsneo_error_invalid_parameters: case icsneo_error_invalid_parameters:
error = "invalid parameters"; error = "Invalid function parameters";
break; break;
case icsneo_error_open_failed: case icsneo_error_open_failed:
error = "open failed"; error = "Open failed";
break; break;
case icsneo_error_go_online_failed: case icsneo_error_go_online_failed:
error = "go online failed"; error = "Going online failed";
break; break;
case icsneo_error_enable_message_polling_failed: case icsneo_error_enable_message_polling_failed:
error = "enable message polling failed"; error = "Enable message polling failed";
break; break;
case icsneo_error_sync_rtc_failed: case icsneo_error_sync_rtc_failed:
error = "sync RTC failed"; error = "Syncronizing RTC failed";
break;
case icsneo_error_rtc_failure:
error = "RTC failure";
break;
case icsneo_error_set_settings_failure:
error = "Setting settings failed";
break; break;
// Don't default, let the compiler warn us if we forget to handle an error code // Don't default, let the compiler warn us if we forget to handle an error code
} }
@ -621,24 +627,38 @@ ICSNEO_API icsneo_error_t icsneo_event_get_description(icsneo_event_t* event, co
return icsneo_error_success; return icsneo_error_success;
} }
/* ICSNEO_API icsneo_error_t icsneo_device_get_rtc(icsneo_device_t* device, int64_t* unix_epoch) {
Type getType() const noexcept { return Type(eventStruct.eventNumber); } if (!device || !unix_epoch) {
Severity getSeverity() const noexcept { return Severity(eventStruct.severity); } return icsneo_error_invalid_parameters;
std::string getDescription() const noexcept { return std::string(eventStruct.description); } }
const Device* getDevice() const noexcept { return device; } // Will return nullptr if this is an API-wide event // TODO: Check if device is valid
EventTimePoint getTimestamp() const noexcept { return timepoint; } 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();
void downgradeFromError() noexcept; } else {
*unix_epoch = 0;
bool isForDevice(const Device* forDevice) const noexcept { return forDevice == device; } return icsneo_error_rtc_failure;
bool isForDevice(std::string serial) const noexcept; }
return icsneo_error_success;
// As opposed to getDescription, this will also add text such as "neoVI FIRE 2 CY2468 Error: " to fully describe the problem }
std::string describe() const noexcept; ICSNEO_API icsneo_error_t icsneo_device_set_rtc(icsneo_device_t* device, int64_t* unix_epoch) {
friend std::ostream& operator<<(std::ostream& os, const APIEvent& event) { if (!device || !unix_epoch) {
os << event.describe(); return icsneo_error_invalid_parameters;
return os; }
// 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;
} }
static const char* DescriptionForType(Type type); ICSNEO_API icsneo_error_t icsneo_device_load_default_settings(icsneo_device_t* device, bool save) {
*/ if (!device) {
return icsneo_error_invalid_parameters;
}
// TODO: Check if device is valid
if (!device->device->settings->applyDefaults(!save)) {
return icsneo_error_set_settings_failure;
}
return icsneo_error_success;
}

View File

@ -82,6 +82,10 @@ typedef enum _icsneo_error_t {
icsneo_error_get_messages_failed, icsneo_error_get_messages_failed,
// Generic invalid type error // Generic invalid type error
icsneo_error_invalid_type, icsneo_error_invalid_type,
// Generic RTC error code
icsneo_error_rtc_failure,
// Error setting settings
icsneo_error_set_settings_failure
} _icsneo_error_t; } _icsneo_error_t;
/** @brief Integer representation of _icsneo_error_t enum. /** @brief Integer representation of _icsneo_error_t enum.
@ -408,17 +412,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); 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. /** @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. * @param[out] icsneo_event_t** events Pointer to an array of icsneo_event_t to copy the events into.
@ -450,6 +443,32 @@ 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); 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);
/** @brief Load the default settings for a device
*
* @param[in] icsneo_device_t device The device to load the settings for.
* @param[in] bool save True to make the settings permanent, false settings will be reverted on next boot.
*
* @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise.
*/
ICSNEO_API icsneo_error_t icsneo_device_load_default_settings(icsneo_device_t* device, bool save);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif