add Prepare and Destroy

This commit is contained in:
Thomas Kunze 2019-06-29 10:30:58 +02:00
parent b405bff672
commit a585bf2bb7
3 changed files with 54 additions and 7 deletions

View File

@ -6,6 +6,37 @@ project(knx)
add_subdirectory(pybind11)
pybind11_add_module(knx ../src/knx/address_table_object.cpp ../src/knx/apdu.cpp ../src/knx/application_layer.cpp ../src/knx/application_program_object.cpp ../src/knx/association_table_object.cpp ../src/knx/bau.cpp ../src/knx/bau07B0.cpp ../src/knx/bau57B0.cpp ../src/knx/bau_systemB.cpp ../src/knx/bits.cpp ../src/knx/cemi_frame.cpp ../src/knx/datapoint_types.cpp ../src/knx/data_link_layer.cpp ../src/knx/device_object.cpp ../src/knx/group_object.cpp ../src/knx/group_object_table_object.cpp ../src/knx/interface_object.cpp ../src/knx/ip_data_link_layer.cpp ../src/knx/ip_parameter_object.cpp ../src/knx/memory.cpp ../src/knx/network_layer.cpp ../src/knx/npdu.cpp ../src/knx/platform.cpp ../src/knx/table_object.cpp ../src/knx/tpdu.cpp ../src/knx/tpuart_data_link_layer.cpp ../src/knx/transport_layer.cpp ../src/linux_platform.cpp knxmodule.cpp)
pybind11_add_module(knx
knxmodule.cpp
../src/knx/address_table_object.cpp
../src/knx/apdu.cpp
../src/knx/application_layer.cpp
../src/knx/application_program_object.cpp
../src/knx/association_table_object.cpp
../src/knx/bau.cpp
../src/knx/bau07B0.cpp
../src/knx/bau57B0.cpp
../src/knx/bau_systemB.cpp
../src/knx/bits.cpp
../src/knx/cemi_frame.cpp
../src/knx/data_link_layer.cpp
../src/knx/device_object.cpp
../src/knx/group_object.cpp
../src/knx/group_object_table_object.cpp
../src/knx/interface_object.cpp
../src/knx/ip_data_link_layer.cpp
../src/knx/ip_parameter_object.cpp
../src/knx/memory.cpp
../src/knx/network_layer.cpp
../src/knx/npdu.cpp
../src/knx/table_object.cpp
../src/knx/tpdu.cpp
../src/knx/tpuart_data_link_layer.cpp
../src/knx/transport_layer.cpp
../src/knx/platform.cpp
../src/linux_platform.cpp
../src/knx_facade.cpp
../src/knx/dptconvert.cpp
../src/knx/knx_value.cpp
../src/knx/dpt.cpp)
include_directories(../src pybind11/include)

View File

@ -12,7 +12,7 @@
"ctestCommandArgs": "",
"inheritEnvironments": [ "linux_x64" ],
"wslPath": "${defaultWSLPath}",
"addressSanitizerEnabled": true,
"addressSanitizerEnabled": false,
"addressSanitizerRuntimeFlags": "detect_leaks=0",
"variables": []
}

View File

@ -1,6 +1,7 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl_bind.h>
#include <pybind11/functional.h>
#include <pybind11/stl.h>
namespace py = pybind11;
@ -11,6 +12,7 @@ namespace py = pybind11;
#include <thread>
#include <stdint.h>
#include <vector>
#include <algorithm>
#include "linux_platform.h"
#include "knx/bau57B0.h"
@ -31,10 +33,22 @@ static void loop()
}
static std::thread workerThread;
static std::vector<const char*> argv;
static void Prepare(int argc, char** argv)
struct StdStringCStrFunctor
{
platform = new LinuxPlatform(argc, argv);
const char* operator() (const std::string& str) { return str.c_str(); }
};
static void Prepare(std::vector<std::string> args)
{
//for(int i = 0; i < args.size(); i++)
// printf("%s\n", args[i].c_str());
argv = std::vector<const char*>(args.size());
std::transform(args.begin(), args.end(), argv.begin(), StdStringCStrFunctor());
platform = new LinuxPlatform(argv.size(), const_cast<char**>(argv.data()));
bau = new Bau57B0(*platform);
}
@ -109,7 +123,9 @@ PYBIND11_MODULE(knx, m)
py::bind_vector<std::vector<GroupObject>>(m, "GroupObjectList");
m.def("Start", &Start, "Start knx handling thread.");
m.def("Stop", &Start, "Stop knx handling thread.");
m.def("Stop", &Stop, "Stop knx handling thread.");
m.def("Prepare", &Prepare, "Allocated needed objects.");
m.def("Destroy", &Destroy, "Free object allocated by Prepare.");
m.def("ProgramMode", (bool(*)())&ProgramMode, "get programing mode active.");
m.def("ProgramMode", (bool(*)(bool))&ProgramMode, "Activate / deactivate programing mode.");
m.def("Configured", (bool(*)())&Configured, "get configured status.");
@ -152,4 +168,4 @@ PYBIND11_MODULE(knx, m)
go.objectWritten();
})
.def("callBack", (void(GroupObject::*)(GroupObjectUpdatedHandler))&GroupObject::callback);
}
}