Added error checking for polling
parent
2b34c82382
commit
92368f70a5
|
|
@ -178,8 +178,7 @@ bool icsneo_enableMessagePolling(const neodevice_t* device) {
|
||||||
if(!icsneo_isValidNeoDevice(device))
|
if(!icsneo_isValidNeoDevice(device))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
device->device->enableMessagePolling();
|
return device->device->enableMessagePolling();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool icsneo_disableMessagePolling(const neodevice_t* device) {
|
bool icsneo_disableMessagePolling(const neodevice_t* device) {
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,12 @@ static constexpr const char* ERROR_REQUIRED_PARAMETER_NULL = "A required paramet
|
||||||
static constexpr const char* ERROR_BUFFER_INSUFFICIENT = "The provided buffer was insufficient. No data was written.";
|
static constexpr const char* ERROR_BUFFER_INSUFFICIENT = "The provided buffer was insufficient. No data was written.";
|
||||||
static constexpr const char* ERROR_OUTPUT_TRUNCATED = "The output was too large for the provided buffer and has been truncated.";
|
static constexpr const char* ERROR_OUTPUT_TRUNCATED = "The output was too large for the provided buffer and has been truncated.";
|
||||||
static constexpr const char* ERROR_PARAMETER_OUT_OF_RANGE = "A parameter was out of range.";
|
static constexpr const char* ERROR_PARAMETER_OUT_OF_RANGE = "A parameter was out of range.";
|
||||||
static constexpr const char* ERROR_DEVICE_CURRENTLY_OPEN = "The device is currently open. Perhaps a different device state was required.";
|
static constexpr const char* ERROR_DEVICE_CURRENTLY_OPEN = "The device is currently open. Perhaps a different device state is required.";
|
||||||
static constexpr const char* ERROR_DEVICE_CURRENTLY_CLOSED = "The device is currently closed. Perhaps a different device state was required.";
|
static constexpr const char* ERROR_DEVICE_CURRENTLY_CLOSED = "The device is currently closed. Perhaps a different device state is required.";
|
||||||
static constexpr const char* ERROR_DEVICE_CURRENTLY_ONLINE = "The device is currently online. Perhaps a different device state was required.";
|
static constexpr const char* ERROR_DEVICE_CURRENTLY_ONLINE = "The device is currently online. Perhaps a different device state is required.";
|
||||||
static constexpr const char* ERROR_DEVICE_CURRENTLY_OFFLINE = "The device is currently offline. Perhaps a different device state was required.";
|
static constexpr const char* ERROR_DEVICE_CURRENTLY_OFFLINE = "The device is currently offline. Perhaps a different device state is required.";
|
||||||
static constexpr const char* ERROR_DEVICE_NOT_POLLING = "The device is not currently polling for messages.";
|
static constexpr const char* ERROR_DEVICE_CURRENTLY_POLLING = "The device is currently polling for messages. Perhaps a different device state is required.";
|
||||||
|
static constexpr const char* ERROR_DEVICE_NOT_CURRENTLY_POLLING = "The device is not currently polling for messages. Perhaps a different device state is required.";
|
||||||
static constexpr const char* ERROR_UNSUPPORTED_TX_NETWORK = "Message network is not a supported TX network.";
|
static constexpr const char* ERROR_UNSUPPORTED_TX_NETWORK = "Message network is not a supported TX network.";
|
||||||
static constexpr const char* ERROR_MESSAGE_MAX_LENGTH_EXCEEDED = "The message was too long.";
|
static constexpr const char* ERROR_MESSAGE_MAX_LENGTH_EXCEEDED = "The message was too long.";
|
||||||
|
|
||||||
|
|
@ -114,8 +115,10 @@ const char* APIError::DescriptionForType(ErrorType type) {
|
||||||
return ERROR_DEVICE_CURRENTLY_ONLINE;
|
return ERROR_DEVICE_CURRENTLY_ONLINE;
|
||||||
case DeviceCurrentlyOffline:
|
case DeviceCurrentlyOffline:
|
||||||
return ERROR_DEVICE_CURRENTLY_OFFLINE;
|
return ERROR_DEVICE_CURRENTLY_OFFLINE;
|
||||||
case DeviceNotPolling:
|
case DeviceCurrentlyPolling:
|
||||||
return ERROR_DEVICE_NOT_POLLING;
|
return ERROR_DEVICE_CURRENTLY_POLLING;
|
||||||
|
case DeviceNotCurrentlyPolling:
|
||||||
|
return ERROR_DEVICE_NOT_CURRENTLY_POLLING;
|
||||||
case UnsupportedTXNetwork:
|
case UnsupportedTXNetwork:
|
||||||
return ERROR_UNSUPPORTED_TX_NETWORK;
|
return ERROR_UNSUPPORTED_TX_NETWORK;
|
||||||
case MessageMaxLengthExceeded:
|
case MessageMaxLengthExceeded:
|
||||||
|
|
@ -205,7 +208,8 @@ APIError::Severity APIError::SeverityForType(ErrorType type) {
|
||||||
case DeviceCurrentlyClosed:
|
case DeviceCurrentlyClosed:
|
||||||
case DeviceCurrentlyOnline:
|
case DeviceCurrentlyOnline:
|
||||||
case DeviceCurrentlyOffline:
|
case DeviceCurrentlyOffline:
|
||||||
case DeviceNotPolling:
|
case DeviceCurrentlyPolling:
|
||||||
|
case DeviceNotCurrentlyPolling:
|
||||||
// Device Warnings
|
// Device Warnings
|
||||||
case PollingMessageOverflow:
|
case PollingMessageOverflow:
|
||||||
case DeviceFirmwareOutOfDate:
|
case DeviceFirmwareOutOfDate:
|
||||||
|
|
|
||||||
|
|
@ -77,20 +77,23 @@ std::string Device::describe() const {
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::enableMessagePolling() {
|
bool Device::enableMessagePolling() {
|
||||||
if(isMessagePollingEnabled()) // We are already polling
|
if(isMessagePollingEnabled()) {// We are already polling
|
||||||
return;
|
err(APIError::DeviceCurrentlyPolling);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
messagePollingCallbackID = com->addMessageCallback(MessageCallback([this](std::shared_ptr<Message> message) {
|
messagePollingCallbackID = com->addMessageCallback(MessageCallback([this](std::shared_ptr<Message> message) {
|
||||||
pollingContainer.enqueue(message);
|
pollingContainer.enqueue(message);
|
||||||
enforcePollingMessageLimit();
|
enforcePollingMessageLimit();
|
||||||
}));
|
}));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::disableMessagePolling() {
|
bool Device::disableMessagePolling() {
|
||||||
if(!isMessagePollingEnabled())
|
if(!isMessagePollingEnabled()) {
|
||||||
return true; // Not currently polling
|
err(APIError::DeviceNotCurrentlyPolling);
|
||||||
|
return false; // Not currently polling
|
||||||
|
}
|
||||||
auto ret = com->removeMessageCallback(messagePollingCallbackID);
|
auto ret = com->removeMessageCallback(messagePollingCallbackID);
|
||||||
getMessages(); // Flush any messages still in the container
|
getMessages(); // Flush any messages still in the container
|
||||||
messagePollingCallbackID = 0;
|
messagePollingCallbackID = 0;
|
||||||
|
|
@ -126,7 +129,7 @@ bool Device::getMessages(std::vector<std::shared_ptr<Message>>& container, size_
|
||||||
|
|
||||||
// not currently polling, throw error
|
// not currently polling, throw error
|
||||||
if(!isMessagePollingEnabled()) {
|
if(!isMessagePollingEnabled()) {
|
||||||
err(APIError::DeviceNotPolling);
|
err(APIError::DeviceNotCurrentlyPolling);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,10 @@ public:
|
||||||
DeviceCurrentlyClosed = 0x1006,
|
DeviceCurrentlyClosed = 0x1006,
|
||||||
DeviceCurrentlyOnline = 0x1007,
|
DeviceCurrentlyOnline = 0x1007,
|
||||||
DeviceCurrentlyOffline = 0x1008,
|
DeviceCurrentlyOffline = 0x1008,
|
||||||
DeviceNotPolling = 0x1009,
|
DeviceCurrentlyPolling = 0x1009,
|
||||||
UnsupportedTXNetwork = 0x1010,
|
DeviceNotCurrentlyPolling = 0x1010,
|
||||||
MessageMaxLengthExceeded = 0x1011,
|
UnsupportedTXNetwork = 0x1011,
|
||||||
|
MessageMaxLengthExceeded = 0x1012,
|
||||||
|
|
||||||
// Device Errors
|
// Device Errors
|
||||||
PollingMessageOverflow = 0x2000,
|
PollingMessageOverflow = 0x2000,
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ public:
|
||||||
virtual bool goOffline();
|
virtual bool goOffline();
|
||||||
|
|
||||||
// Message polling related functions
|
// Message polling related functions
|
||||||
void enableMessagePolling();
|
bool enableMessagePolling();
|
||||||
bool disableMessagePolling();
|
bool disableMessagePolling();
|
||||||
bool isMessagePollingEnabled() { return messagePollingCallbackID != 0; };
|
bool isMessagePollingEnabled() { return messagePollingCallbackID != 0; };
|
||||||
std::vector<std::shared_ptr<Message>> getMessages();
|
std::vector<std::shared_ptr<Message>> getMessages();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue