diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 02f0eb2..5677822 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -40,6 +40,9 @@ pybind11_add_module(icsneopy icsneopy/communication/message/livedatamessage.cpp icsneopy/communication/message/callback/messagecallback.cpp icsneopy/communication/message/filter/messagefilter.cpp + icsneopy/communication/message/filter/main51messagefilter.cpp + icsneopy/communication/message/main51message.cpp + icsneopy/communication/command.cpp icsneopy/core/macseccfg.cpp icsneopy/flexray/flexray.cpp icsneopy/disk/diskdriver.cpp diff --git a/bindings/python/icsneopy/communication/command.cpp b/bindings/python/icsneopy/communication/command.cpp new file mode 100644 index 0000000..963ebd7 --- /dev/null +++ b/bindings/python/icsneopy/communication/command.cpp @@ -0,0 +1,40 @@ +#include +#include + +#include "icsneo/communication/command.h" + +namespace icsneo { + +void init_command(pybind11::module_& m) { + pybind11::native_enum(m, "Command", "enum.IntEnum") + .value("Main51RxBufferOverflow", Command::Main51RxBufferOverflow) + .value("Main51StartCmd", Command::Main51StartCmd) + .value("Main51TxFifoOverflow", Command::Main51TxFifoOverflow) + .value("Main51BulkInNoData", Command::Main51BulkInNoData) + .value("Main51SetModeComplete", Command::Main51SetModeComplete) + .value("Main51ReadEeprom", Command::Main51ReadEeprom) + .value("Main51CmdDone", Command::Main51CmdDone) + .value("Main51ErrStatus", Command::Main51ErrStatus) + .value("Main51ReadSectorBuff", Command::Main51ReadSectorBuff) + .value("Main51WriteSectorBuff", Command::Main51WriteSectorBuff) + .value("Main51MmcProcessDone", Command::Main51MmcProcessDone) + .value("Main51ReInitDone", Command::Main51ReInitDone) + .value("EnableNetworkCommunication", Command::EnableNetworkCommunication) + .value("EnableNetworkCommunicationEx", Command::EnableNetworkCommunicationEx) + .value("KeepAlive", Command::KeepAlive) + .value("RequestSerialNumber", Command::RequestSerialNumber) + .value("GetMainVersion", Command::GetMainVersion) + .value("SetSettings", Command::SetSettings) + .value("SaveSettings", Command::SaveSettings) + .value("SetDefaultSettings", Command::SetDefaultSettings) + .value("ReadSettings", Command::ReadSettings) + .value("ScriptStatus", Command::ScriptStatus) + .value("WiVICommand", Command::WiVICommand) + .value("Extended", Command::Extended) + .value("ExtendedData", Command::ExtendedData) + .value("FlexRayControl", Command::FlexRayControl) + .value("CoreMiniPreload", Command::CoreMiniPreload) + .finalize(); +} + +} // namespace icsneo diff --git a/bindings/python/icsneopy/communication/message/filter/main51messagefilter.cpp b/bindings/python/icsneopy/communication/message/filter/main51messagefilter.cpp new file mode 100644 index 0000000..7a36de3 --- /dev/null +++ b/bindings/python/icsneopy/communication/message/filter/main51messagefilter.cpp @@ -0,0 +1,13 @@ +#include + +#include "icsneo/communication/message/filter/main51messagefilter.h" + +namespace icsneo { + +void init_main51messagefilter(pybind11::module_& m) { + pybind11::classh(m, "Main51MessageFilter") + .def(pybind11::init<>()) + .def(pybind11::init()); +} + +} // namespace icsneo diff --git a/bindings/python/icsneopy/communication/message/main51message.cpp b/bindings/python/icsneopy/communication/message/main51message.cpp new file mode 100644 index 0000000..4653086 --- /dev/null +++ b/bindings/python/icsneopy/communication/message/main51message.cpp @@ -0,0 +1,13 @@ +#include + +#include "icsneo/communication/message/main51message.h" + +namespace icsneo { + +void init_main51message(pybind11::module_& m) { + pybind11::classh(m, "Main51Message") + .def(pybind11::init<>()) + .def_readonly("command", &Main51Message::command); +} + +} // namespace icsneo diff --git a/bindings/python/icsneopy/icsneocpp.cpp b/bindings/python/icsneopy/icsneocpp.cpp index d92402e..24eddfe 100644 --- a/bindings/python/icsneopy/icsneocpp.cpp +++ b/bindings/python/icsneopy/icsneocpp.cpp @@ -32,7 +32,10 @@ void init_deviceextension(pybind11::module_&); void init_chipid(pybind11::module_&); void init_versionreport(pybind11::module_&); void init_device(pybind11::module_&); +void init_command(pybind11::module_&); +void init_main51message(pybind11::module_&); void init_messagefilter(pybind11::module_&); +void init_main51messagefilter(pybind11::module_&); void init_messagecallback(pybind11::module_&); void init_version(pybind11::module_&); void init_flexray(pybind11::module_& m); @@ -69,7 +72,10 @@ PYBIND11_MODULE(icsneopy, m) { init_scriptstatusmessage(m); init_spimessage(m); init_livedatamessage(m); + init_command(m); + init_main51message(m); init_messagefilter(m); + init_main51messagefilter(m); init_messagecallback(m); init_diskdriver(m); init_diskdetails(m); diff --git a/examples/python/main51/main51_filter.py b/examples/python/main51/main51_filter.py new file mode 100644 index 0000000..cfd0960 --- /dev/null +++ b/examples/python/main51/main51_filter.py @@ -0,0 +1,45 @@ +import icsneopy +import time + +# +# Main51 messages are device-originated notifications from the firmware's Main51 processor. +# This example filters for RX buffer overflow and TX FIFO overflow events. +# +def main51_filter(): + devices = icsneopy.find_all_devices() + + if len(devices) == 0: + print("no devices found") + return False + + device = devices[0] + print(f"selected {device}") + + def on_main51(message): + if not isinstance(message, icsneopy.Main51Message): + return + if message.command == icsneopy.Command.Main51RxBufferOverflow: + print("RX buffer overflow") + elif message.command == icsneopy.Command.Main51TxFifoOverflow: + print("TX FIFO overflow") + else: + print(f"Main51 command: {message.command}") + + filter = icsneopy.Main51MessageFilter() + callback = icsneopy.MessageCallback(on_main51, filter) + device.add_message_callback(callback) + + if not device.open(): + print("unable to open device") + return False + + if not device.go_online(): + print("unable to go online") + return False + + time.sleep(5) + + return True + +if __name__ == "__main__": + main51_filter()