Added icsneo_isMessagePollingEnabled(), removed polling check from transmitting, and disabled error reporting on device destruction

checksum-failure-logging
EricLiu2000 2019-06-14 15:13:22 -04:00
parent a608d21304
commit 28fc98c475
4 changed files with 28 additions and 12 deletions

View File

@ -189,6 +189,13 @@ bool icsneo_disableMessagePolling(const neodevice_t* device) {
return device->device->disableMessagePolling(); return device->device->disableMessagePolling();
} }
bool icsneo_isMessagePollingEnabled(const neodevice_t* device) {
if(!icsneo_isValidNeoDevice(device))
return false;
return device->device->isMessagePollingEnabled();
}
bool icsneo_getMessages(const neodevice_t* device, neomessage_t* messages, size_t* items, uint64_t timeout) { bool icsneo_getMessages(const neodevice_t* device, neomessage_t* messages, size_t* items, uint64_t timeout) {
if(!icsneo_isValidNeoDevice(device)) if(!icsneo_isValidNeoDevice(device))
return false; return false;

View File

@ -78,7 +78,7 @@ std::string Device::describe() const {
} }
void Device::enableMessagePolling() { void Device::enableMessagePolling() {
if(messagePollingCallbackID != 0) // We are already polling if(isMessagePollingEnabled()) // We are already polling
return; return;
messagePollingCallbackID = com->addMessageCallback(MessageCallback([this](std::shared_ptr<Message> message) { messagePollingCallbackID = com->addMessageCallback(MessageCallback([this](std::shared_ptr<Message> message) {
@ -88,7 +88,7 @@ void Device::enableMessagePolling() {
} }
bool Device::disableMessagePolling() { bool Device::disableMessagePolling() {
if(messagePollingCallbackID == 0) if(!isMessagePollingEnabled())
return true; // Not currently polling return true; // Not currently polling
auto ret = com->removeMessageCallback(messagePollingCallbackID); auto ret = com->removeMessageCallback(messagePollingCallbackID);
@ -118,7 +118,7 @@ bool Device::getMessages(std::vector<std::shared_ptr<Message>>& container, size_
} }
// not currently polling, throw error // not currently polling, throw error
if(messagePollingCallbackID == 0) { if(!isMessagePollingEnabled()) {
err(APIError::DeviceNotPolling); err(APIError::DeviceNotPolling);
return false; return false;
} }
@ -215,9 +215,10 @@ bool Device::goOnline() {
return false; return false;
ledState = LEDState::Online; ledState = LEDState::Online;
updateLEDState();
online = true; online = true;
updateLEDState();
return true; return true;
} }
@ -226,9 +227,10 @@ bool Device::goOffline() {
return false; return false;
ledState = (latestResetStatus && latestResetStatus->cmRunning) ? LEDState::CoreMiniRunning : LEDState::Offline; ledState = (latestResetStatus && latestResetStatus->cmRunning) ? LEDState::CoreMiniRunning : LEDState::Offline;
updateLEDState(); updateLEDState();
online = false; online = false;
return true; return true;
} }
@ -246,12 +248,6 @@ bool Device::transmit(std::shared_ptr<Message> message) {
return false; return false;
} }
// not currently polling, throw error
if(messagePollingCallbackID == 0) {
err(APIError::DeviceNotPolling);
return false;
}
if(!isSupportedTXNetwork(message->network)) { if(!isSupportedTXNetwork(message->network)) {
err(APIError::UnsupportedTXNetwork); err(APIError::UnsupportedTXNetwork);
return false; return false;

View File

@ -21,6 +21,7 @@ namespace icsneo {
class Device { class Device {
public: public:
virtual ~Device() { virtual ~Device() {
destructing = true;
disableMessagePolling(); disableMessagePolling();
close(); close();
} }
@ -51,6 +52,7 @@ public:
// Message polling related functions // Message polling related functions
void enableMessagePolling(); void enableMessagePolling();
bool disableMessagePolling(); bool disableMessagePolling();
bool isMessagePollingEnabled() { return messagePollingCallbackID != 0; };
std::vector<std::shared_ptr<Message>> getMessages(); std::vector<std::shared_ptr<Message>> getMessages();
bool getMessages(std::vector<std::shared_ptr<Message>>& container, size_t limit = 0, std::chrono::milliseconds timeout = std::chrono::milliseconds(0)); bool getMessages(std::vector<std::shared_ptr<Message>>& container, size_t limit = 0, std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
size_t getCurrentMessageCount() { return pollingContainer.size_approx(); } size_t getCurrentMessageCount() { return pollingContainer.size_approx(); }
@ -114,7 +116,10 @@ protected:
} }
virtual device_errorhandler_t makeErrorHandler() { virtual device_errorhandler_t makeErrorHandler() {
return [this](APIError::ErrorType type) { ErrorManager::GetInstance().add(type, this); }; return [this](APIError::ErrorType type) {
if(!destructing)
ErrorManager::GetInstance().add(type, this);
};
} }
template<typename Transport> template<typename Transport>
@ -169,6 +174,8 @@ private:
size_t pollingMessageLimit = 20000; size_t pollingMessageLimit = 20000;
moodycamel::BlockingConcurrentQueue<std::shared_ptr<Message>> pollingContainer; moodycamel::BlockingConcurrentQueue<std::shared_ptr<Message>> pollingContainer;
void enforcePollingMessageLimit(); void enforcePollingMessageLimit();
bool destructing = false;
}; };
} }

View File

@ -195,6 +195,8 @@ extern bool DLLExport icsneo_enableMessagePolling(const neodevice_t* device);
*/ */
extern bool DLLExport icsneo_disableMessagePolling(const neodevice_t* device); extern bool DLLExport icsneo_disableMessagePolling(const neodevice_t* device);
extern bool DLLExport icsneo_isMessagePollingEnabled(const neodevice_t* device);
/** /**
* \brief Read out messages which have been recieved * \brief Read out messages which have been recieved
* \param[in] device A pointer to the neodevice_t structure specifying the device to operate on. * \param[in] device A pointer to the neodevice_t structure specifying the device to operate on.
@ -696,6 +698,9 @@ fn_icsneo_enableMessagePolling icsneo_enableMessagePolling;
typedef bool(*fn_icsneo_disableMessagePolling)(const neodevice_t* device); typedef bool(*fn_icsneo_disableMessagePolling)(const neodevice_t* device);
fn_icsneo_disableMessagePolling icsneo_disableMessagePolling; fn_icsneo_disableMessagePolling icsneo_disableMessagePolling;
typedef bool(*fn_icsneo_isMessagePollingEnabled)(const neodevice_t* device);
fn_icsneo_isMessagePollingEnabled icsneo_isMessagePollingEnabled;
typedef bool(*fn_icsneo_getMessages)(const neodevice_t* device, neomessage_t* messages, size_t* items, uint64_t timeout); typedef bool(*fn_icsneo_getMessages)(const neodevice_t* device, neomessage_t* messages, size_t* items, uint64_t timeout);
fn_icsneo_getMessages icsneo_getMessages; fn_icsneo_getMessages icsneo_getMessages;
@ -804,6 +809,7 @@ int icsneo_init() {
ICSNEO_IMPORTASSERT(icsneo_isOnline); ICSNEO_IMPORTASSERT(icsneo_isOnline);
ICSNEO_IMPORTASSERT(icsneo_enableMessagePolling); ICSNEO_IMPORTASSERT(icsneo_enableMessagePolling);
ICSNEO_IMPORTASSERT(icsneo_disableMessagePolling); ICSNEO_IMPORTASSERT(icsneo_disableMessagePolling);
ICSNEO_IMPORTASSERT(icsneo_isMessagePollingEnabled);
ICSNEO_IMPORTASSERT(icsneo_getMessages); ICSNEO_IMPORTASSERT(icsneo_getMessages);
ICSNEO_IMPORTASSERT(icsneo_getPollingMessageLimit); ICSNEO_IMPORTASSERT(icsneo_getPollingMessageLimit);
ICSNEO_IMPORTASSERT(icsneo_setPollingMessageLimit); ICSNEO_IMPORTASSERT(icsneo_setPollingMessageLimit);