mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-09-22 00:48:40 +02:00
Bindings: Python: Add Main51MessageFilter support
This commit is contained in:
committed by
Kyle Schwarz
parent
bb892bfd9b
commit
8cd907250d
@@ -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
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/native_enum.h>
|
||||
|
||||
#include "icsneo/communication/command.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_command(pybind11::module_& m) {
|
||||
pybind11::native_enum<Command>(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
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
#include "icsneo/communication/message/filter/main51messagefilter.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_main51messagefilter(pybind11::module_& m) {
|
||||
pybind11::classh<Main51MessageFilter, MessageFilter>(m, "Main51MessageFilter")
|
||||
.def(pybind11::init<>())
|
||||
.def(pybind11::init<Command>());
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
#include "icsneo/communication/message/main51message.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
void init_main51message(pybind11::module_& m) {
|
||||
pybind11::classh<Main51Message, RawMessage>(m, "Main51Message")
|
||||
.def(pybind11::init<>())
|
||||
.def_readonly("command", &Main51Message::command);
|
||||
}
|
||||
|
||||
} // namespace icsneo
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user