mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Error system now functional in C and C++ APIs
This commit is contained in:
@@ -19,6 +19,8 @@ typedef struct {
|
||||
uint8_t reserved[16];
|
||||
} neoerror_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
@@ -68,16 +70,18 @@ public:
|
||||
Error = 0x30
|
||||
};
|
||||
|
||||
APIError() : errorStruct({}), device(nullptr) {}
|
||||
APIError(ErrorType error);
|
||||
APIError(ErrorType error, const Device* device);
|
||||
|
||||
const neoerror_t* getNeoError() const noexcept { return &errorStruct; }
|
||||
ErrorType getType() const noexcept { return ErrorType(errorStruct.errorNumber); }
|
||||
Severity getSeverity() const noexcept { return Severity(errorStruct.severity); }
|
||||
std::string getDescription() const noexcept { return std::string(errorStruct.description); }
|
||||
const Device* getDevice() const noexcept { return device; } // Will return nullptr if this is an API-wide error
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> getTimestamp() const noexcept { return timepoint; }
|
||||
|
||||
bool isForDevice(Device* forDevice) const noexcept { return forDevice == device; }
|
||||
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
|
||||
@@ -104,20 +108,22 @@ public:
|
||||
ErrorFilter() {} // Empty filter matches anything
|
||||
ErrorFilter(APIError::ErrorType error) : type(error) {}
|
||||
ErrorFilter(APIError::Severity severity) : severity(severity) {}
|
||||
ErrorFilter(Device* device, APIError::ErrorType error = APIError::Any) : type(error), matchOnDevicePtr(true), device(device) {}
|
||||
ErrorFilter(Device* device, APIError::Severity severity = APIError::Severity::Any) : severity(severity), matchOnDevicePtr(true), device(device) {}
|
||||
ErrorFilter(const Device* device, APIError::ErrorType error = APIError::Any) : type(error), matchOnDevicePtr(true), device(device) {}
|
||||
ErrorFilter(const Device* device, APIError::Severity severity) : severity(severity), matchOnDevicePtr(true), device(device) {}
|
||||
ErrorFilter(std::string serial, APIError::ErrorType error = APIError::Any) : type(error), serial(serial) {}
|
||||
ErrorFilter(std::string serial, APIError::Severity severity = APIError::Severity::Any) : severity(severity), serial(serial) {}
|
||||
ErrorFilter(std::string serial, APIError::Severity severity) : severity(severity), serial(serial) {}
|
||||
|
||||
bool match(const APIError& error) const noexcept;
|
||||
|
||||
APIError::Severity severity = APIError::Severity::Any;
|
||||
APIError::ErrorType type = APIError::Any;
|
||||
bool matchOnDevicePtr = false;
|
||||
Device* device = nullptr; // nullptr will match on "no device, generic API error"
|
||||
const Device* device = nullptr; // nullptr will match on "no device, generic API error"
|
||||
std::string serial; // Empty serial will match any, including no device. Not affected by matchOnDevicePtr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
}
|
||||
void get(std::vector<APIError>& errors, ErrorFilter filter, size_t max = 0) { get(errors, max, filter); }
|
||||
void get(std::vector<APIError>& errors, size_t max = 0, ErrorFilter filter = ErrorFilter());
|
||||
bool getOne(APIError& error, ErrorFilter filter = ErrorFilter());
|
||||
bool getLastError(APIError& error, ErrorFilter filter = ErrorFilter());
|
||||
|
||||
void add(APIError error) {
|
||||
std::lock_guard<std::mutex> lk(mutex);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "icsneo/platform/dynamiclib.h" // Dynamic library loading and exporting
|
||||
#include "icsneo/communication/network.h" // Network type and netID defines
|
||||
#include "icsneo/api/version.h" // For version info
|
||||
#include "icsneo/api/error.h" // For error info
|
||||
|
||||
#ifndef ICSNEOC_DYNAMICLOAD
|
||||
|
||||
@@ -68,6 +69,20 @@ extern bool DLLExport icsneo_describeDevice(const neodevice_t* device, char* str
|
||||
|
||||
extern neoversion_t DLLExport icsneo_getVersion(void);
|
||||
|
||||
extern bool DLLExport icsneo_getErrors(neoerror_t* errors, size_t* size);
|
||||
|
||||
extern bool DLLExport icsneo_getDeviceErrors(const neodevice_t* device, neoerror_t* errors, size_t* size);
|
||||
|
||||
extern bool DLLExport icsneo_getLastError(neoerror_t* error);
|
||||
|
||||
extern void DLLExport icsneo_discardAllErrors(void);
|
||||
|
||||
extern void DLLExport icsneo_discardDeviceErrors(const neodevice_t* device);
|
||||
|
||||
extern void DLLExport icsneo_setErrorLimit(size_t newLimit);
|
||||
|
||||
extern size_t DLLExport icsneo_getErrorLimit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
@@ -155,6 +170,27 @@ fn_icsneo_describeDevice icsneo_describeDevice;
|
||||
typedef neoversion_t(*fn_icsneo_getVersion)(void);
|
||||
fn_icsneo_getVersion icsneo_getVersion;
|
||||
|
||||
typedef bool(*fn_icsneo_getErrors)(neoerror_t* errors, size_t* size);
|
||||
fn_icsneo_getErrors icsneo_getErrors;
|
||||
|
||||
typedef bool(*fn_icsneo_getDeviceErrors)(const neodevice_t* device, neoerror_t* errors, size_t* size);
|
||||
fn_icsneo_getDeviceErrors icsneo_getDeviceErrors;
|
||||
|
||||
typedef bool(*fn_icsneo_getLastError)(neoerror_t* error);
|
||||
fn_icsneo_getLastError icsneo_getLastError;
|
||||
|
||||
typedef void(*fn_icsneo_discardAllErrors)(void);
|
||||
fn_icsneo_discardAllErrors icsneo_discardAllErrors;
|
||||
|
||||
typedef void(*fn_icsneo_discardDeviceErrors)(const neodevice_t* device);
|
||||
fn_icsneo_discardDeviceErrors icsneo_discardDeviceErrors;
|
||||
|
||||
typedef void(*fn_icsneo_setErrorLimit)(size_t newLimit);
|
||||
fn_icsneo_setErrorLimit icsneo_setErrorLimit;
|
||||
|
||||
typedef size_t(*fn_icsneo_getErrorLimit)(void);
|
||||
fn_icsneo_getErrorLimit icsneo_getErrorLimit;
|
||||
|
||||
#define ICSNEO_IMPORT(func) func = (fn_##func)icsneo_dynamicLibraryGetFunction(icsneo_libraryHandle, #func)
|
||||
#define ICSNEO_IMPORTASSERT(func) if((ICSNEO_IMPORT(func)) == NULL) return 3
|
||||
void* icsneo_libraryHandle = NULL;
|
||||
@@ -196,6 +232,13 @@ int icsneo_init() {
|
||||
ICSNEO_IMPORTASSERT(icsneo_transmitMessages);
|
||||
ICSNEO_IMPORTASSERT(icsneo_describeDevice);
|
||||
ICSNEO_IMPORTASSERT(icsneo_getVersion);
|
||||
ICSNEO_IMPORTASSERT(icsneo_getErrors);
|
||||
ICSNEO_IMPORTASSERT(icsneo_getDeviceErrors);
|
||||
ICSNEO_IMPORTASSERT(icsneo_getLastError);
|
||||
ICSNEO_IMPORTASSERT(icsneo_discardAllErrors);
|
||||
ICSNEO_IMPORTASSERT(icsneo_discardDeviceErrors);
|
||||
ICSNEO_IMPORTASSERT(icsneo_setErrorLimit);
|
||||
ICSNEO_IMPORTASSERT(icsneo_getErrorLimit);
|
||||
|
||||
icsneo_initialized = true;
|
||||
return 0;
|
||||
|
||||
@@ -6,11 +6,22 @@
|
||||
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/api/version.h"
|
||||
#include "icsneo/api/errormanager.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
std::vector<std::shared_ptr<Device>> FindAllDevices();
|
||||
|
||||
size_t ErrorCount(ErrorFilter filter = ErrorFilter());
|
||||
std::vector<APIError> GetErrors(ErrorFilter filter, size_t max = 0);
|
||||
std::vector<APIError> GetErrors(size_t max = 0, ErrorFilter filter = ErrorFilter());
|
||||
void GetErrors(std::vector<APIError>& errors, ErrorFilter filter, size_t max = 0);
|
||||
void GetErrors(std::vector<APIError>& errors, size_t max = 0, ErrorFilter filter = ErrorFilter());
|
||||
bool GetLastError(APIError& error, ErrorFilter filter = ErrorFilter());
|
||||
void DiscardErrors(ErrorFilter filter = ErrorFilter());
|
||||
void SetErrorLimit(size_t newLimit);
|
||||
size_t GetErrorLimit();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user