added icsneo_device_load_default_settings

David Rebbe 2024-12-04 23:18:26 -05:00
parent dee031710f
commit 875bf45421
2 changed files with 23 additions and 20 deletions

View File

@ -61,6 +61,9 @@ ICSNEO_API icsneo_error_t icsneo_error_code(icsneo_error_t error_code, const cha
case icsneo_error_rtc_failure: case icsneo_error_rtc_failure:
error = "RTC failure"; error = "RTC failure";
break; 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 // Don't default, let the compiler warn us if we forget to handle an error code
} }
// Find the minimum length of the error string and set value_length // Find the minimum length of the error string and set value_length
@ -648,24 +651,14 @@ ICSNEO_API icsneo_error_t icsneo_device_set_rtc(icsneo_device_t* device, int64_t
return icsneo_error_success; return icsneo_error_success;
} }
/* ICSNEO_API icsneo_error_t icsneo_device_load_default_settings(icsneo_device_t* device, bool save) {
Type getType() const noexcept { return Type(eventStruct.eventNumber); } if (!device) {
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 (!device->device->settings->applyDefaults(!save)) {
return icsneo_error_set_settings_failure;
void downgradeFromError() noexcept; }
bool isForDevice(const Device* forDevice) const noexcept { return forDevice == device; } return icsneo_error_success;
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;
}
static const char* DescriptionForType(Type type);
*/

View File

@ -84,6 +84,8 @@ typedef enum _icsneo_error_t {
icsneo_error_invalid_type, icsneo_error_invalid_type,
// Generic RTC error code // Generic RTC error code
icsneo_error_rtc_failure, 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.
@ -459,6 +461,14 @@ ICSNEO_API icsneo_error_t icsneo_device_get_rtc(icsneo_device_t* device, int64_t
*/ */
ICSNEO_API icsneo_error_t icsneo_device_set_rtc(icsneo_device_t* device, int64_t* unix_epoch); 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