mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Major improvements to the settings API
* Allow the raw structure to be manipulated from C and Legacy APIs * Structure is now split between what's on the device and what's on the client so changes will not be visible from read methods until apply() * Allow devices to connect which have slightly different firmware versions than the settings structure
This commit is contained in:
@@ -338,6 +338,76 @@ 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) {
|
||||
if(!icsneo_isValidNeoDevice(device)) {
|
||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t readSize = device->device->settings->getSize();
|
||||
if(structure == nullptr) // Structure size request
|
||||
return readSize;
|
||||
if(readSize > structureSize) {
|
||||
// Client application has a smaller structure than we do
|
||||
// It is probably built against an older version of the API
|
||||
ErrorManager::GetInstance().add(APIError::OutputTruncated);
|
||||
readSize = structureSize;
|
||||
}
|
||||
|
||||
const void* deviceStructure = device->device->settings->getRawStructurePointer();
|
||||
if(deviceStructure == nullptr) {
|
||||
ErrorManager::GetInstance().add(APIError::SettingsNotAvailable);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(structure, deviceStructure, readSize);
|
||||
|
||||
if(readSize < structureSize) // Client application is attempting to read more than we have
|
||||
memset((uint8_t*)structure + readSize, 0, structureSize - readSize);
|
||||
|
||||
return readSize;
|
||||
}
|
||||
|
||||
// Not exported
|
||||
static bool icsneo_settingsWriteStructure(const neodevice_t* device, const void* structure, size_t structureSize) {
|
||||
if(!icsneo_isValidNeoDevice(device)) {
|
||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(structure == nullptr) {
|
||||
ErrorManager::GetInstance().add(APIError::RequiredParameterNull);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t writeSize = device->device->settings->getSize();
|
||||
if(writeSize < structureSize) {
|
||||
ErrorManager::GetInstance().add(APIError::OutputTruncated);
|
||||
structureSize = writeSize;
|
||||
}
|
||||
|
||||
void* deviceStructure = device->device->settings->getMutableRawStructurePointer();
|
||||
if(deviceStructure == nullptr) {
|
||||
ErrorManager::GetInstance().add(APIError::SettingsNotAvailable);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(deviceStructure, structure, structureSize);
|
||||
|
||||
// If writeSize > structureSize that means that the user has given us a smaller structure
|
||||
// This is okay, we will keep the end of the structure intact
|
||||
// TODO Flag an error
|
||||
return true;
|
||||
}
|
||||
|
||||
bool icsneo_settingsApplyStructure(const neodevice_t* device, const void* structure, size_t structureSize) {
|
||||
return icsneo_settingsWriteStructure(device, structure, structureSize) && icsneo_settingsApply(device);
|
||||
}
|
||||
|
||||
bool icsneo_settingsApplyStructureTemporary(const neodevice_t* device, const void* structure, size_t structureSize) {
|
||||
return icsneo_settingsWriteStructure(device, structure, structureSize) && icsneo_settingsApplyTemporary(device);
|
||||
}
|
||||
|
||||
int64_t icsneo_getBaudrate(const neodevice_t* device, uint16_t netid) {
|
||||
if(!icsneo_isValidNeoDevice(device)) {
|
||||
ErrorManager::GetInstance().add(APIError::InvalidNeoDevice);
|
||||
|
||||
@@ -177,88 +177,132 @@ void icsneoSetISO15765RxParameters(void* hObject, int lNetwork, int lEnable, spy
|
||||
|
||||
//Device Functions
|
||||
int icsneoGetConfiguration(void* hObject, unsigned char* pData, int* lNumBytes) {
|
||||
// TODO Implement
|
||||
// 2G devices are not supported in the new API
|
||||
return false;
|
||||
}
|
||||
|
||||
int icsneoSendConfiguration(void* hObject, unsigned char* pData, int lNumBytes) {
|
||||
// TODO Implement
|
||||
// 2G devices are not supported in the new API
|
||||
return false;
|
||||
}
|
||||
|
||||
int icsneoGetFireSettings(void* hObject, SFireSettings* pSettings, int iNumBytes) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoSetFireSettings(void* hObject, SFireSettings* pSettings, int iNumBytes, int bSaveToEEPROM) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
if(bSaveToEEPROM)
|
||||
return icsneo_settingsApplyStructure(device, pSettings, iNumBytes);
|
||||
return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoGetVCAN3Settings(void* hObject, SVCAN3Settings* pSettings, int iNumBytes) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoSetVCAN3Settings(void* hObject, SVCAN3Settings* pSettings, int iNumBytes, int bSaveToEEPROM) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
if(bSaveToEEPROM)
|
||||
return icsneo_settingsApplyStructure(device, pSettings, iNumBytes);
|
||||
return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoGetFire2Settings(void* hObject, SFire2Settings* pSettings, int iNumBytes) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoSetFire2Settings(void* hObject, SFire2Settings* pSettings, int iNumBytes, int bSaveToEEPROM) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
if(bSaveToEEPROM)
|
||||
return icsneo_settingsApplyStructure(device, pSettings, iNumBytes);
|
||||
return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoGetVCANRFSettings(void* hObject, SVCANRFSettings* pSettings, int iNumBytes) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoSetVCANRFSettings(void* hObject, SVCANRFSettings* pSettings, int iNumBytes, int bSaveToEEPROM) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
if(bSaveToEEPROM)
|
||||
return icsneo_settingsApplyStructure(device, pSettings, iNumBytes);
|
||||
return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoGetVCAN412Settings(void* hObject, SVCAN412Settings* pSettings, int iNumBytes) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoSetVCAN412Settings(void* hObject, SVCAN412Settings* pSettings, int iNumBytes, int bSaveToEEPROM) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
if(bSaveToEEPROM)
|
||||
return icsneo_settingsApplyStructure(device, pSettings, iNumBytes);
|
||||
return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoGetRADGalaxySettings(void* hObject, SRADGalaxySettings* pSettings, int iNumBytes) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoSetRADGalaxySettings(void* hObject, SRADGalaxySettings* pSettings, int iNumBytes, int bSaveToEEPROM) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
if(bSaveToEEPROM)
|
||||
return icsneo_settingsApplyStructure(device, pSettings, iNumBytes);
|
||||
return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoGetRADStar2Settings(void* hObject, SRADStar2Settings* pSettings, int iNumBytes) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
return !!icsneo_settingsReadStructure(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoSetRADStar2Settings(void* hObject, SRADStar2Settings* pSettings, int iNumBytes, int bSaveToEEPROM) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
if(bSaveToEEPROM)
|
||||
return icsneo_settingsApplyStructure(device, pSettings, iNumBytes);
|
||||
return icsneo_settingsApplyStructureTemporary(device, pSettings, iNumBytes);
|
||||
}
|
||||
|
||||
int icsneoSetBitRate(void* hObject, int BitRate, int NetworkID) {
|
||||
// TODO Implement
|
||||
return false;
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
return icsneo_setBaudrate(device, (uint16_t)NetworkID, BitRate);
|
||||
}
|
||||
|
||||
int icsneoGetDeviceParameters(void* hObject, char* pParameter, char* pValues, short ValuesLength) {
|
||||
@@ -327,7 +371,7 @@ int icsneoGetDLLVersion(void) {
|
||||
|
||||
int icsneoGetSerialNumber(void* hObject, unsigned int*iSerialNumber) {
|
||||
if(!icsneoValidateHObject(hObject))
|
||||
return false;
|
||||
return false;
|
||||
neodevice_t* device = (neodevice_t*)hObject;
|
||||
*iSerialNumber = icsneo_serialStringToNum(device->serial);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user