Standardized int-returning functions in icsneoc library to return -1 on failure. Updated icsneolegacy accordingly, and added headers for message callback functionality in c

checksum-failure-logging
EricLiu2000 2019-07-29 16:08:54 -04:00
parent 54b98ec9b4
commit 5a98bac8a6
3 changed files with 51 additions and 15 deletions

View File

@ -229,7 +229,7 @@ bool icsneo_getMessages(const neodevice_t* device, neomessage_t* messages, size_
size_t icsneo_getPollingMessageLimit(const neodevice_t* device) {
if(!icsneo_isValidNeoDevice(device))
return 0;
return -1;
return device->device->getPollingMessageLimit();
}
@ -242,6 +242,16 @@ bool icsneo_setPollingMessageLimit(const neodevice_t* device, size_t newLimit) {
return true;
}
int icsneo_addMessageCallback(const neodevice_t* device, void (*callback) (neomessage_t*)) {
if(!icsneo_isValidNeoDevice(device))
return -1;
}
bool icsneo_removeMessageCallback(const neodevice_t* device, int id) {
if(!icsneo_isValidNeoDevice(device))
return false;
}
bool icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLength) {
// TAG String copy function
if(maxLength == nullptr) {
@ -326,9 +336,9 @@ bool icsneo_settingsApplyDefaultsTemporary(const neodevice_t* device) {
return device->device->settings->applyDefaults(true);
}
size_t icsneo_settingsReadStructure(const neodevice_t* device, void* structure, size_t structureSize) {
int icsneo_settingsReadStructure(const neodevice_t* device, void* structure, size_t structureSize) {
if(!icsneo_isValidNeoDevice(device))
return 0;
return -1;
size_t readSize = device->device->settings->getSize();
if(structure == nullptr) // Structure size request
@ -343,7 +353,7 @@ size_t icsneo_settingsReadStructure(const neodevice_t* device, void* structure,
const void* deviceStructure = device->device->settings->getRawStructurePointer();
if(deviceStructure == nullptr) {
EventManager::GetInstance().add(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error);
return 0;
return -1;
}
memcpy(structure, deviceStructure, readSize);

View File

@ -292,7 +292,9 @@ int icsneoGetFireSettings(void* hObject, SFireSettings* pSettings, int iNumBytes
if(!icsneoValidateHObject(hObject))
return false;
neodevice_t* device = (neodevice_t*)hObject;
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
if(icsneo_settingsReadStructure(device, pSettings, iNumBytes) == -1)
return 0;
else return 1;
}
int icsneoSetFireSettings(void* hObject, SFireSettings* pSettings, int iNumBytes, int bSaveToEEPROM) {
@ -308,7 +310,9 @@ int icsneoGetVCAN3Settings(void* hObject, SVCAN3Settings* pSettings, int iNumByt
if(!icsneoValidateHObject(hObject))
return false;
neodevice_t* device = (neodevice_t*)hObject;
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
if(icsneo_settingsReadStructure(device, pSettings, iNumBytes) == -1)
return 0;
else return 1;
}
int icsneoSetVCAN3Settings(void* hObject, SVCAN3Settings* pSettings, int iNumBytes, int bSaveToEEPROM) {
@ -324,7 +328,9 @@ int icsneoGetFire2Settings(void* hObject, SFire2Settings* pSettings, int iNumByt
if(!icsneoValidateHObject(hObject))
return false;
neodevice_t* device = (neodevice_t*)hObject;
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
if(icsneo_settingsReadStructure(device, pSettings, iNumBytes) == -1)
return 0;
else return 1;
}
int icsneoSetFire2Settings(void* hObject, SFire2Settings* pSettings, int iNumBytes, int bSaveToEEPROM) {
@ -340,7 +346,9 @@ int icsneoGetVCANRFSettings(void* hObject, SVCANRFSettings* pSettings, int iNumB
if(!icsneoValidateHObject(hObject))
return false;
neodevice_t* device = (neodevice_t*)hObject;
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
if(icsneo_settingsReadStructure(device, pSettings, iNumBytes) == -1)
return 0;
else return 1;
}
int icsneoSetVCANRFSettings(void* hObject, SVCANRFSettings* pSettings, int iNumBytes, int bSaveToEEPROM) {
@ -356,7 +364,9 @@ int icsneoGetVCAN412Settings(void* hObject, SVCAN412Settings* pSettings, int iNu
if(!icsneoValidateHObject(hObject))
return false;
neodevice_t* device = (neodevice_t*)hObject;
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
if(icsneo_settingsReadStructure(device, pSettings, iNumBytes) == -1)
return 0;
else return 1;
}
int icsneoSetVCAN412Settings(void* hObject, SVCAN412Settings* pSettings, int iNumBytes, int bSaveToEEPROM) {
@ -372,7 +382,9 @@ int icsneoGetRADGalaxySettings(void* hObject, SRADGalaxySettings* pSettings, int
if(!icsneoValidateHObject(hObject))
return false;
neodevice_t* device = (neodevice_t*)hObject;
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
if(icsneo_settingsReadStructure(device, pSettings, iNumBytes) == -1)
return 0;
else return 1;
}
int icsneoSetRADGalaxySettings(void* hObject, SRADGalaxySettings* pSettings, int iNumBytes, int bSaveToEEPROM) {
@ -388,7 +400,9 @@ int icsneoGetRADStar2Settings(void* hObject, SRADStar2Settings* pSettings, int i
if(!icsneoValidateHObject(hObject))
return false;
neodevice_t* device = (neodevice_t*)hObject;
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
if(icsneo_settingsReadStructure(device, pSettings, iNumBytes) == -1)
return 0;
else return 1;
}
int icsneoSetRADStar2Settings(void* hObject, SRADStar2Settings* pSettings, int iNumBytes, int bSaveToEEPROM) {

View File

@ -265,7 +265,7 @@ extern bool DLLExport icsneo_getMessages(const neodevice_t* device, neomessage_t
/**
* \brief Get the maximum number of messages which will be held in the API managed buffer for the specified hardware.
* \param[in] device A pointer to the neodevice_t structure specifying the device to operate on.
* \returns Number of messages.
* \returns Number of messages, or -1 if device is invalid.
*
* See icsneo_enableMessagePolling() for more information about the message polling system.
*/
@ -284,6 +284,10 @@ extern size_t DLLExport icsneo_getPollingMessageLimit(const neodevice_t* device)
*/
extern bool DLLExport icsneo_setPollingMessageLimit(const neodevice_t* device, size_t newLimit);
extern int DLLExport icsneo_addMessageCallback(const neodevice_t* device, void (*callback) (neomessage_t*));
extern bool DLLExport icsneo_removeMessageCallback(const neodevice_t* device, int id);
/**
* \brief Get the friendly product name for a specified device.
* \param[in] device A pointer to the neodevice_t structure specifying the device to operate on.
@ -390,7 +394,7 @@ extern bool DLLExport icsneo_settingsApplyDefaultsTemporary(const neodevice_t* d
* \param[in] device A pointer to the neodevice_t structure specifying the device to operate on.
* \param[out] structure A pointer to a device settings structure for the current device.
* \param[in] structureSize The size of the current device settings structure in bytes.
* \returns Number of bytes written to structure
* \returns Number of bytes written to structure, or -1 if the operation failed.
*
* See icsneo_settingsApply() for further information about applying settings. See icsneo_settingsApplyDefaults() for further information about applying default settings.
*
@ -399,7 +403,7 @@ extern bool DLLExport icsneo_settingsApplyDefaultsTemporary(const neodevice_t* d
* If possible, use functions specific to the operation you want to acomplish (such as icsneo_setBaudrate()) instead of modifying the structure directly.
* This allows the client application to work with other hardware.
*/
extern size_t DLLExport icsneo_settingsReadStructure(const neodevice_t* device, void* structure, size_t structureSize);
extern int DLLExport icsneo_settingsReadStructure(const neodevice_t* device, void* structure, size_t structureSize);
/**
* \brief Apply a provided settings structure for a specified device.
@ -739,6 +743,12 @@ fn_icsneo_getPollingMessageLimit icsneo_getPollingMessageLimit;
typedef bool(*fn_icsneo_setPollingMessageLimit)(const neodevice_t* device, size_t newLimit);
fn_icsneo_setPollingMessageLimit icsneo_setPollingMessageLimit;
typedef int(*fn_icsneo_addMessageCallback)(const neodevice_t* device, void (*callback) (neomessage_t*);
fn_icsneo_addMessageCallback icsneo_addMessageCallback;
typedef bool(*fn_icsneo_removeMessageCallback)(const neodevice_t* device, int id);
fn_icsneo_removeMessageCallback icsneo_removeMessageCallback;
typedef bool(*fn_icsneo_getProductName)(const neodevice_t* device, char* str, size_t* maxLength);
fn_icsneo_getProductName icsneo_getProductName;
@ -757,7 +767,7 @@ fn_icsneo_settingsApplyDefaults icsneo_settingsApplyDefaults;
typedef bool(*fn_icsneo_settingsApplyDefaultsTemporary)(const neodevice_t* device);
fn_icsneo_settingsApplyDefaultsTemporary icsneo_settingsApplyDefaultsTemporary;
typedef size_t(*fn_icsneo_settingsReadStructure)(const neodevice_t* device, void* structure, size_t structureSize);
typedef int(*fn_icsneo_settingsReadStructure)(const neodevice_t* device, void* structure, size_t structureSize);
fn_icsneo_settingsReadStructure icsneo_settingsReadStructure;
typedef bool(*fn_icsneo_settingsApplyStructure)(const neodevice_t* device, const void* structure, size_t structureSize);
@ -845,6 +855,8 @@ int icsneo_init() {
ICSNEO_IMPORTASSERT(icsneo_getMessages);
ICSNEO_IMPORTASSERT(icsneo_getPollingMessageLimit);
ICSNEO_IMPORTASSERT(icsneo_setPollingMessageLimit);
ICSNEO_IMPORTASSERT(icsneo_addMessageCallback);
ICSNEO_IMPORTASSERT(icsneo_removeMessageCallback);
ICSNEO_IMPORTASSERT(icsneo_getProductName);
ICSNEO_IMPORTASSERT(icsneo_settingsRefresh);
ICSNEO_IMPORTASSERT(icsneo_settingsApply);