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;
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;
case icsneo_error_set_settings_failure:
error = "Setting settings failed";
break;
// 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;
}
/*
Type getType() const noexcept { return Type(eventStruct.eventNumber); }
Severity getSeverity() const noexcept { return Severity(eventStruct.severity); }
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
EventTimePoint getTimestamp() const noexcept { return timepoint; }
void downgradeFromError() noexcept;
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;
}
bool isForDevice(const Device* forDevice) const noexcept { return forDevice == device; }
bool isForDevice(std::string serial) const noexcept;
// 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;
friend std::ostream& operator<<(std::ostream& os, const APIEvent& event) {
os << event.describe();
return os;
}
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;
}
static const char* DescriptionForType(Type type);
*/
return icsneo_error_success;
}

View File

@ -82,6 +82,10 @@ 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,
// Error setting settings
icsneo_error_set_settings_failure
} _icsneo_error_t;
/** @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);
/*
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 +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);
/** @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
}
#endif