#ifdef USE_FASTRTPS #include "modulecomm_impl_tcp.h" #include #include #include #include #include namespace iv { namespace modulecomm { static QMutex gmodulecomm_dds_Mutex; static int createcount = 0; } } void modulecomm_impl_tcp::callbackTopic(const char * strdata,const unsigned int nSize,const unsigned int index, QDateTime * dt,const char * strmemname) { if(mbFunPlus) { mFun(strdata,nSize,index,dt,strmemname); } else { (*mpCall)(strdata,nSize,index,dt,strmemname); } } int modulecomm_impl_tcp::GetTempConfPath(char *strpath) { char strtmppath[256]; QDateTime dt = QDateTime::currentDateTime(); snprintf(strtmppath,256,"/tmp/adc_modulecomm_conf_%04d%02d%02d%02d%02d.ini",dt.date().year(), dt.date().month(),dt.date().day(),dt.time().hour(),dt.time().minute()); QFile xFile; xFile.setFileName(strtmppath); char strtem[256]; char strdata[10000]; snprintf(strdata,10000,""); if(!xFile.exists()) { if(xFile.open(QIODevice::ReadWrite)) { snprintf(strtem,256,"[common]\n");strncat(strdata,strtem,10000); snprintf(strtem,256,"DCPSDefaultDiscovery=TheRTPSConfig\n");strncat(strdata,strtem,10000); #ifdef dds_use_shm snprintf(strtem,256,"DCPSGlobalTransportConfig=myconfig\n");strncat(strdata,strtem,10000); snprintf(strtem,256,"[config/myconfig]\n");strncat(strdata,strtem,10000); snprintf(strtem,256,"transports=share\n");strncat(strdata,strtem,10000); snprintf(strtem,256,"[transport/share]\n");strncat(strdata,strtem,10000); snprintf(strtem,256,"transport_type=shmem\n");strncat(strdata,strtem,10000); snprintf(strtem,256,"pool_size=100000000\n");strncat(strdata,strtem,10000); #endif snprintf(strtem,256,"[rtps_discovery/TheRTPSConfig]\n");strncat(strdata,strtem,10000); snprintf(strtem,256,"ResendPeriod=5\n");strncat(strdata,strtem,10000); xFile.write(strdata,strnlen(strdata,10000)); xFile.close(); } } strncpy(strpath,strtmppath,255); return 0; } modulecomm_impl_tcp::modulecomm_impl_tcp(const char * strcommname,int ntype,const unsigned short nport ,const char * strip ) { strncpy(mstrtopic,strcommname,255); iv::modulecomm::gmodulecomm_dds_Mutex.lock(); if(ntype == type_recv) { mpSub = new TopicsSubscriber(); mpSub->init(strcommname,strip,nport,1); // std::this_thread::sleep_for(std::chrono::milliseconds(10)); mnType = type_recv; } else { mpPub = new TopicsPublisher(); mpPub->init(strcommname,nport,1); // std::this_thread::sleep_for(std::chrono::milliseconds(10)); mnType = type_send; } iv::modulecomm::createcount++; std::cout<<"count is "<setReceivedTopicFunction(topicFunction); return 0; } int modulecomm_impl_tcp::listenmsg(SMCallBack pCall) { if(mnType == type_send) { std::cout<<"send not listen."<setReceivedTopicFunction(topicFunction); return 0; } void modulecomm_impl_tcp::writemsg(const char *str, int nlen) { if(mnType == type_recv) { std::cout<<"recv not send."<senddata(str,nlen); } #endif