Make a blank settings interface if one does not exist because segfaulting is bad
parent
6456d4e261
commit
8044488bed
|
|
@ -216,9 +216,6 @@ bool icsneo_settingsRefresh(const neodevice_t* device) {
|
|||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
if(!device->device->settings) // Settings are not available for this device
|
||||
return false;
|
||||
|
||||
return device->device->settings->refresh();
|
||||
}
|
||||
|
||||
|
|
@ -226,9 +223,6 @@ bool icsneo_settingsApply(const neodevice_t* device) {
|
|||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
if(!device->device->settings) // Settings are not available for this device
|
||||
return false;
|
||||
|
||||
return device->device->settings->apply();
|
||||
}
|
||||
|
||||
|
|
@ -236,9 +230,6 @@ bool icsneo_settingsApplyTemporary(const neodevice_t* device) {
|
|||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
if(!device->device->settings) // Settings are not available for this device
|
||||
return false;
|
||||
|
||||
return device->device->settings->apply(true);
|
||||
}
|
||||
|
||||
|
|
@ -246,9 +237,6 @@ bool icsneo_settingsApplyDefaults(const neodevice_t* device) {
|
|||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
if(!device->device->settings) // Settings are not available for this device
|
||||
return false;
|
||||
|
||||
return device->device->settings->applyDefaults();
|
||||
}
|
||||
|
||||
|
|
@ -256,9 +244,6 @@ bool icsneo_settingsApplyDefaultsTemporary(const neodevice_t* device) {
|
|||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
if(!device->device->settings) // Settings are not available for this device
|
||||
return false;
|
||||
|
||||
return device->device->settings->applyDefaults(true);
|
||||
}
|
||||
|
||||
|
|
@ -266,9 +251,6 @@ bool icsneo_setBaudrate(const neodevice_t* device, uint16_t netid, uint32_t newB
|
|||
if(!icsneo_isValidNeoDevice(device))
|
||||
return false;
|
||||
|
||||
if(!device->device->settings) // Settings are not available for this device
|
||||
return false;
|
||||
|
||||
return device->device->settings->setBaudrateFor(netid, newBaudrate);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -145,10 +145,10 @@ bool Device::open() {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool settingsNecessary = bool(settings); // Check if the shared_ptr exists
|
||||
bool settingsNecessary = !settings->disabled;
|
||||
if(settingsNecessary) {
|
||||
settings->refresh();
|
||||
if(!settings || !settings->ok())
|
||||
if(!settings->ok())
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ uint16_t IDeviceSettings::CalculateGSChecksum(const std::vector<uint8_t>& settin
|
|||
}
|
||||
|
||||
bool IDeviceSettings::refresh(bool ignoreChecksum) {
|
||||
if(disabled)
|
||||
return false;
|
||||
|
||||
std::vector<uint8_t> rxSettings;
|
||||
bool ret = com->getSettingsSync(rxSettings);
|
||||
if(!ret)
|
||||
|
|
@ -86,7 +89,7 @@ bool IDeviceSettings::refresh(bool ignoreChecksum) {
|
|||
}
|
||||
|
||||
bool IDeviceSettings::apply(bool temporary) {
|
||||
if(readonly)
|
||||
if(disabled || readonly)
|
||||
return false;
|
||||
|
||||
std::vector<uint8_t> bytestream;
|
||||
|
|
@ -135,7 +138,7 @@ bool IDeviceSettings::apply(bool temporary) {
|
|||
}
|
||||
|
||||
bool IDeviceSettings::applyDefaults(bool temporary) {
|
||||
if(readonly)
|
||||
if(disabled || readonly)
|
||||
return false;
|
||||
|
||||
com->sendCommand(Command::SetDefaultSettings);
|
||||
|
|
@ -178,7 +181,7 @@ bool IDeviceSettings::applyDefaults(bool temporary) {
|
|||
}
|
||||
|
||||
bool IDeviceSettings::setBaudrateFor(Network net, uint32_t baudrate) {
|
||||
if(readonly)
|
||||
if(disabled || readonly)
|
||||
return false;
|
||||
|
||||
switch(net.getType()) {
|
||||
|
|
@ -201,7 +204,7 @@ bool IDeviceSettings::setBaudrateFor(Network net, uint32_t baudrate) {
|
|||
}
|
||||
|
||||
template<typename T> bool IDeviceSettings::setStructure(const T& newStructure) {
|
||||
if(readonly)
|
||||
if(disabled || readonly)
|
||||
return false;
|
||||
|
||||
if(sizeof(T) != structSize)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ public:
|
|||
Device(neodevice_t neodevice = { 0 }) {
|
||||
data = neodevice;
|
||||
data.device = this;
|
||||
settings = std::unique_ptr<IDeviceSettings>(new IDeviceSettings(nullptr));
|
||||
}
|
||||
virtual ~Device() {
|
||||
disableMessagePolling();
|
||||
|
|
|
|||
|
|
@ -281,9 +281,13 @@ public:
|
|||
static constexpr uint16_t GS_VERSION = 5;
|
||||
static uint16_t CalculateGSChecksum(const std::vector<uint8_t>& settings);
|
||||
|
||||
// Parameter createInoperableSettings exists because it is serving as a warning that you probably don't want to do this
|
||||
typedef void* warn_t;
|
||||
IDeviceSettings(warn_t createInoperableSettings) : disabled(true), readonly(true), structSize(0) { (void)createInoperableSettings; }
|
||||
|
||||
IDeviceSettings(std::shared_ptr<Communication> com, size_t size) : com(com), structSize(size) {}
|
||||
virtual ~IDeviceSettings() {}
|
||||
bool ok() { return settingsLoaded; }
|
||||
bool ok() { return !disabled && settingsLoaded; }
|
||||
|
||||
bool refresh(bool ignoreChecksum = false); // Get from device
|
||||
|
||||
|
|
@ -303,6 +307,7 @@ public:
|
|||
|
||||
uint8_t getEnumValueForBaudrate(uint32_t baudrate);
|
||||
|
||||
bool disabled = false;
|
||||
bool readonly = false;
|
||||
protected:
|
||||
std::shared_ptr<Communication> com;
|
||||
|
|
|
|||
Loading…
Reference in New Issue