Bläddra i källkod

add moduelcommrust.pro for complile so for rust. add rustdecisiondemo, only begin.

yuchuli 11 månader sedan
förälder
incheckning
9621f37d67

+ 7 - 0
src/RUST/rustdecisiondemo/Cargo.lock

@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "rustdecisiondemo"
+version = "0.1.0"

+ 11 - 0
src/RUST/rustdecisiondemo/Cargo.toml

@@ -0,0 +1,11 @@
+[package]
+name = "rustdecisiondemo"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[build-dependencies]  
+
+# cc = "1.0"
+[dependencies]

+ 4 - 0
src/RUST/rustdecisiondemo/Readme.md

@@ -0,0 +1,4 @@
+在modulecomm目录编译modulecommrust生成libmodulecommrust.so文件拷贝到本目录。
+
+rust编译
+cargo rustc -- -L .   -lmodulecommrust

+ 6 - 0
src/RUST/rustdecisiondemo/src/build.rs

@@ -0,0 +1,6 @@
+fn main() {  
+
+    println!("hello build");
+
+
+}

+ 27 - 0
src/RUST/rustdecisiondemo/src/main.rs

@@ -0,0 +1,27 @@
+mod modulecommrust;  
+
+
+use std::os::raw::{c_char, c_uint};  
+// 定义Rust中的回调函数,与C/C++中的SMCallBack兼容  
+
+
+//extern "C" fn rust_sm_callback(strdata: *const c_char, nsize: c_uint, index: c_uint) {  
+//    println!("Callback received:  (size: {}, index: {})", nsize, index);  
+//} 
+
+fn main() {
+    println!("Hello, world!");
+
+    let strcommname = "test";  
+
+    let c_commname = std::ffi::CString::new(strcommname).unwrap();  
+    let nsize = 100;
+    let npaccount = 10;
+
+    let _pa = unsafe { modulecommrust::RegisterSendRUST(c_commname.as_ptr(), nsize, npaccount) };
+
+    unsafe { modulecommrust::UnregisterRUST(_pa) };
+
+//    let a = unsafe { modulecomm::create_rustt_instance() };  
+//    unsafe{modulecomm::destroy_rustt_instance(a)};
+}

+ 16 - 0
src/RUST/rustdecisiondemo/src/modulecommrust.rs

@@ -0,0 +1,16 @@
+use std::ffi::c_void;
+use std::os::raw::{c_char, c_uint};  
+
+#[link(name = "modulecommrust", kind = "dylib")]  
+extern "C" {  
+
+    pub fn RegisterSendRUST(strcommname: *const c_char, nsize: c_uint,npaccount: c_uint) -> *mut c_void; 
+
+ //   pub fn RegisterRecvRUST(strcommname: *const c_char, pCall: extern "C" fn(*const c_char, c_uint, c_uint)) -> *mut c_void;  
+
+    pub fn UnregisterRUST(instance: *mut c_void);  
+
+
+    // ... 其他函数的声明 ...  
+
+} 

+ 33 - 0
src/common/modulecomm/modulecommrust.cpp

@@ -0,0 +1,33 @@
+
+#include "modulecomm.h"
+#include "modulecommrust.h"
+
+void  ModuleSendMsgRUST(void * pHandle,const char * strdata,const unsigned int nDataLen)
+{
+    iv::modulecomm::ModuleSendMsg(pHandle,strdata,nDataLen);
+}
+
+void  UnregisterRUST(void * pHandle)
+{
+    iv::modulecomm::Unregister(pHandle);
+}
+
+void  PauseCommRUST(void * pHandle)
+{
+    iv::modulecomm::PauseComm(pHandle);
+}
+
+void  ContintuCommRUST(void * pHandle)
+{
+    iv::modulecomm::ContintuComm(pHandle);
+}
+
+void *  RegisterSendRUST(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount)
+{
+    return iv::modulecomm::RegisterSend(strcommname,nBufSize,nMsgBufCount);
+}
+
+void *  RegisterRecvRUST(const char * strcommname,SMCallBack pCall)
+{
+    return iv::modulecomm::RegisterRecv(strcommname,pCall);
+}

+ 15 - 0
src/common/modulecomm/modulecommrust.h

@@ -0,0 +1,15 @@
+
+
+extern "C" {
+
+
+void  ModuleSendMsgRUST(void * pHandle,const char * strdata,const unsigned int nDataLen);
+void  UnregisterRUST(void * pHandle);
+void  PauseCommRUST(void * pHandle);
+void  ContintuCommRUST(void * pHandle);
+
+void *  RegisterSendRUST(const char * strcommname,const unsigned int nBufSize,const unsigned int nMsgBufCount);
+void *  RegisterRecvRUST(const char * strcommname,SMCallBack pCall);
+
+
+}

+ 112 - 0
src/common/modulecomm/modulecommrust.pro

@@ -0,0 +1,112 @@
+QT -= gui
+
+#QT += dbus
+QT += xml
+
+
+TEMPLATE = lib
+DEFINES += MODULECOMM_LIBRARY
+
+unix:DEFINES += RUNSYSTEMTEST
+
+if(contains(DEFINES,RUNSYSTEMTEST)){
+unix:system("./../../../include/linuxsystemtest.sh ")
+}
+
+unix:include(./../../../include/systemdef.pri)
+win32: DEFINES += SYSTEM_WIN
+
+DEFINES += MODULECOMM_NO_FASTRTPS
+
+DEFINES += USE_GROUPUDP
+
+if(contains(DEFINES,USE_GROUPUDP)){
+QT += network
+} else {
+QT += dbus
+DEFINES += USEDBUS
+}
+
+QMAKE_CXXFLAGS +=  -g
+
+CONFIG += c++11
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+    modulecomm.cpp \
+    modulecomm_base.cpp \
+    modulecommrust.cpp
+
+HEADERS += \
+    ivmodulemsg_type.h \
+    modulecomm.h \
+    modulecomm_base.h \
+    ivstdcolorout.h \
+    modulecommrust.h
+
+CONFIG += plugin
+
+
+# Default rules for deployment.
+unix {
+    target.path = /usr/lib
+}
+!isEmpty(target.path): INSTALLS += target
+
+
+
+!include(./shm/modulecomm_shm.pri ) {
+    error( "Couldn't find the modulecomm_shm.pri file!" )
+}
+
+!include(./inter/modulecomm_inter.pri ) {
+    error( "Couldn't find the modulecomm_inter.pri file!" )
+}
+
+
+if(contains(DEFINES,MODULECOMM_NO_FASTRTPS)){
+DEFINES += NOT_USEFASTRTPS
+}else{
+
+if(contains(DEFINES,SYSTEM_AGX)){
+DEFINES += USE_FASTRTPS
+LIBS += -L$$PWD/../../../thirdpartylib/FastRTPS/lib/libarm64
+system("cd ./../../../thirdpartylib/FastRTPS/lib ; unzip -x -n libarm64.zip ; cd ../../../include ; echo $PWD")
+}
+
+if(contains(DEFINES,SYSTEM_UBUNTU1804)){
+DEFINES += USE_FASTRTPS
+LIBS += -L$$PWD/../../../thirdpartylib/FastRTPS/lib/libamd64
+system("cd ./../../../thirdpartylib/FastRTPS/lib ; unzip -x -n libamd64.zip ; cd ../../../include ; echo $PWD")
+}
+
+}
+
+
+
+if(contains(DEFINES,USE_FASTRTPS)){
+!include(./fastrtps/modulecomm_fastrtps.pri ) {
+    error( "Couldn't find the modulecomm_fastrtps.pri file!" )
+}
+}
+
+
+INCLUDEPATH += $$PWD/shm
+INCLUDEPATH += $$PWD/fastrtps
+INCLUDEPATH += $$PWD/inter
+
+
+if(contains(DEFINES,USE_FASTRTPS)){
+LIBS +=  -lfastcdr -lfastrtps
+}
+