#include #include #include #include #include #include #include #include #include #include #include "modulecomm.h" using namespace boost::python; namespace py = boost::python; namespace np = boost::python::numpy; // 回调函数类型 boost::signals2::signal mySignal; py::object mpfunc; void onSignal(int value) { std::cout << "Member function slot called with value: " << value << std::endl; // mpfunc(39); } // 假设我们有一个简单的C++函数,它返回一个整数 class ModuleCommPython { private: std::thread * mpthread; std::string mstrmemname; void * mpa = nullptr; std::shared_ptr mpdata_ptr; int mnRecvdatasize = 0; bool mbUpdate = false; int64_t mnRecvTime = 0; bool mbRun = true; std::mutex * mpmutex; public: ModuleCommPython(){ mpa = nullptr; // mpthread = new std::thread(&ModuleCommPython::threadcallback,this); mpmutex = new std::mutex(); std::cout<<"create trhead."<join(); std::cout<<" complete ModuleCommPython"<join(); std::cout<<" complete ModuleCommPython"<(data); iv::modulecomm::ModuleSendMsg(mpa,data_ptr,ndatasize); return 0; } int RecvData(np::ndarray& arr,int ndatasize, np::ndarray& nRealSize,np::ndarray& ndRecvTime) { int nRtn = 0; if(mbUpdate == false) { return nRtn; //no data recv } mpmutex->lock(); if(ndatasize < mnRecvdatasize) { void* data = nRealSize.get_data(); int* data_ptr = static_cast(data); data_ptr[0] = mnRecvdatasize; nRtn = -1; } else { void* data = arr.get_data(); char* data_ptr = static_cast(data); memcpy(data_ptr,mpdata_ptr.get(),mnRecvdatasize); int64_t nRecvTime = std::chrono::system_clock::now().time_since_epoch().count(); void* datatime = ndRecvTime.get_data(); int64_t* datatime_ptr = static_cast(datatime); ndRecvTime[0] = nRecvTime; nRtn = mnRecvdatasize; mbUpdate = false; } mpmutex->unlock(); return nRtn; } void UpdateRecv(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) { (void)index; (void)dt; (void)strmemname; // std::cout<<"recv data."<lock(); mpdata_ptr = std::shared_ptr(new char[nSize]); memcpy(mpdata_ptr.get(),strdata,nSize); mnRecvdatasize = nSize; mbUpdate = true; mpmutex->unlock(); } int Add(np::ndarray& arr) { int nsize = 0; std::cout<<"enter add."<(arr.attr("shape")) << std::endl; // std::cout << "Data type: "<< py::extract(arr.attr("dtype")) << std::endl; // 获取数组的维度 const np::dtype& dtype = arr.get_dtype(); const Py_intptr_t* shape = arr.get_shape(); int ndims = arr.get_nd(); nsize = ndims; // 获取指向数据的指针 void* data = arr.get_data(); std::cout<<" size: "<()) { unsigned char * data_ptr = static_cast(data); for (Py_intptr_t i = 0; i < 5; ++i) { std::cout << (int)(data_ptr[i]) << " "<("ModuleCommPython") .def("Add", &ModuleCommPython::Add) .def("SetCall",&ModuleCommPython::SetCall) .def("TestCall",&ModuleCommPython::TestCall) .def("SendData",&ModuleCommPython::SendData) .def("RecvData",&ModuleCommPython::RecvData) .def("RegisterSend",&ModuleCommPython::RegisterSend) .def("RegisterRecv",&ModuleCommPython::RegisterRecv) .def("teststring",&ModuleCommPython::teststring) ; def("get_ca_object", &get_ca_object); }