From c5bce795c62f50d11d47eb5a1e0a6363cb0826e5 Mon Sep 17 00:00:00 2001 From: Jonathan Schwartz Date: Tue, 29 Jul 2025 17:15:18 +0000 Subject: [PATCH] Device: Add MessageFilter to enableMessagePolling() --- .gitignore | 1 + bindings/python/icsneopy/device/device.cpp | 2 +- device/device.cpp | 12 +++++++++--- include/icsneo/device/device.h | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 0c58819..b40c9db 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ third-party/concurrentqueue/tests examples/csharp/bin examples/csharp/obj test/system +.env diff --git a/bindings/python/icsneopy/device/device.cpp b/bindings/python/icsneopy/device/device.cpp index 423ec28..97d58b5 100644 --- a/bindings/python/icsneopy/device/device.cpp +++ b/bindings/python/icsneopy/device/device.cpp @@ -17,7 +17,7 @@ void init_device(pybind11::module_& m) { .def("close", &Device::close, pybind11::call_guard()) .def("describe", &Device::describe) .def("disable_message_polling", &Device::disableMessagePolling, pybind11::call_guard()) - .def("enable_message_polling", &Device::enableMessagePolling, pybind11::call_guard()) + .def("enable_message_polling", &Device::enableMessagePolling, pybind11::arg("filter") = std::nullopt, pybind11::call_guard()) .def("get_current_message_count", &Device::getCurrentMessageCount) .def("get_digital_io", &Device::getDigitalIO, pybind11::arg("type"), pybind11::arg("number"), pybind11::call_guard()) .def("get_gptp_status", &Device::getGPTPStatus, pybind11::arg("timeout") = std::chrono::milliseconds(100), pybind11::call_guard()) diff --git a/device/device.cpp b/device/device.cpp index edc4607..ac6dd87 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -105,15 +105,21 @@ std::string Device::describe() const { return ss.str(); } -bool Device::enableMessagePolling() { +bool Device::enableMessagePolling(std::optional filter) { if(isMessagePollingEnabled()) {// We are already polling report(APIEvent::Type::DeviceCurrentlyPolling, APIEvent::Severity::Error); return false; } - messagePollingCallbackID = com->addMessageCallback(std::make_shared([this](std::shared_ptr message) { + if(!filter.has_value()) { + // If no filter is provided, use a default that includes all messages + filter.emplace(MessageFilter()); + filter->includeInternalInAny = true; + } + auto callback = std::make_shared(*filter, [this](std::shared_ptr message) { pollingContainer.enqueue(message); enforcePollingMessageLimit(); - })); + }); + messagePollingCallbackID = com->addMessageCallback(callback); return true; } diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index 96cd334..e0c033c 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -206,7 +206,7 @@ public: // Message polling related functions - bool enableMessagePolling(); + bool enableMessagePolling(std::optional filter = std::nullopt); bool disableMessagePolling(); bool isMessagePollingEnabled() { return messagePollingCallbackID != 0; }; std::pair>, bool> getMessages();