Device: Add MessageFilter to enableMessagePolling()
parent
1e5e714f5b
commit
c5bce795c6
|
|
@ -15,3 +15,4 @@ third-party/concurrentqueue/tests
|
||||||
examples/csharp/bin
|
examples/csharp/bin
|
||||||
examples/csharp/obj
|
examples/csharp/obj
|
||||||
test/system
|
test/system
|
||||||
|
.env
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ void init_device(pybind11::module_& m) {
|
||||||
.def("close", &Device::close, pybind11::call_guard<pybind11::gil_scoped_release>())
|
.def("close", &Device::close, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||||
.def("describe", &Device::describe)
|
.def("describe", &Device::describe)
|
||||||
.def("disable_message_polling", &Device::disableMessagePolling, pybind11::call_guard<pybind11::gil_scoped_release>())
|
.def("disable_message_polling", &Device::disableMessagePolling, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||||
.def("enable_message_polling", &Device::enableMessagePolling, pybind11::call_guard<pybind11::gil_scoped_release>())
|
.def("enable_message_polling", &Device::enableMessagePolling, pybind11::arg("filter") = std::nullopt, pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||||
.def("get_current_message_count", &Device::getCurrentMessageCount)
|
.def("get_current_message_count", &Device::getCurrentMessageCount)
|
||||||
.def("get_digital_io", &Device::getDigitalIO, pybind11::arg("type"), pybind11::arg("number"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
.def("get_digital_io", &Device::getDigitalIO, pybind11::arg("type"), pybind11::arg("number"), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||||
.def("get_gptp_status", &Device::getGPTPStatus, pybind11::arg("timeout") = std::chrono::milliseconds(100), pybind11::call_guard<pybind11::gil_scoped_release>())
|
.def("get_gptp_status", &Device::getGPTPStatus, pybind11::arg("timeout") = std::chrono::milliseconds(100), pybind11::call_guard<pybind11::gil_scoped_release>())
|
||||||
|
|
|
||||||
|
|
@ -105,15 +105,21 @@ std::string Device::describe() const {
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::enableMessagePolling() {
|
bool Device::enableMessagePolling(std::optional<MessageFilter> filter) {
|
||||||
if(isMessagePollingEnabled()) {// We are already polling
|
if(isMessagePollingEnabled()) {// We are already polling
|
||||||
report(APIEvent::Type::DeviceCurrentlyPolling, APIEvent::Severity::Error);
|
report(APIEvent::Type::DeviceCurrentlyPolling, APIEvent::Severity::Error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
messagePollingCallbackID = com->addMessageCallback(std::make_shared<MessageCallback>([this](std::shared_ptr<Message> 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<MessageCallback>(*filter, [this](std::shared_ptr<Message> message) {
|
||||||
pollingContainer.enqueue(message);
|
pollingContainer.enqueue(message);
|
||||||
enforcePollingMessageLimit();
|
enforcePollingMessageLimit();
|
||||||
}));
|
});
|
||||||
|
messagePollingCallbackID = com->addMessageCallback(callback);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ public:
|
||||||
// Message polling related functions
|
// Message polling related functions
|
||||||
|
|
||||||
|
|
||||||
bool enableMessagePolling();
|
bool enableMessagePolling(std::optional<MessageFilter> filter = std::nullopt);
|
||||||
bool disableMessagePolling();
|
bool disableMessagePolling();
|
||||||
bool isMessagePollingEnabled() { return messagePollingCallbackID != 0; };
|
bool isMessagePollingEnabled() { return messagePollingCallbackID != 0; };
|
||||||
std::pair<std::vector<std::shared_ptr<Message>>, bool> getMessages();
|
std::pair<std::vector<std::shared_ptr<Message>>, bool> getMessages();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue