#include #include #include #include #include #include #include #include #include #include #include "lidarmerge.h" #include "modulecomm.h" #include "ivversion.h" QMutex gMutex; static qint64 glasttime = 0; static std::vector gvectorlidar; static char gstroutmemname[255]; static void * gpaout; void dec_yaml(const char * stryamlpath) { YAML::Node config; try { config = YAML::LoadFile(stryamlpath); } catch(YAML::BadFile e) { qDebug("load error."); return; } int i; int nlidarsize; std::vector veclidarname; if(config["lidar"]) { qDebug("have lidar size is %d",config["lidar"].size()); nlidarsize = config["lidar"].size(); for(i=0;i(); veclidarname.push_back(strname); } } else { return; } if(nlidarsize <1)return; std::string strmemname; std::string stroffset_x; std::string stroffset_y; std::string stroffset_z; for(i=0;i(); stroffset_x = config[veclidarname[i].data()]["offset"]["x"].as(); stroffset_y = config[veclidarname[i].data()]["offset"]["y"].as(); stroffset_z = config[veclidarname[i].data()]["offset"]["z"].as(); iv::lidar_data xlidardata; xlidardata.foff_x = atof(stroffset_x.data()); xlidardata.foff_y = atof(stroffset_y.data()); xlidardata.foff_z = atof(stroffset_z.data()); strncpy(xlidardata.strmemname,strmemname.data(),255); gvectorlidar.push_back(xlidardata); qDebug("name is %s ",strmemname.data()); } } } if(config["output"]) { strncpy(gstroutmemname,config["output"].as().data(),255); } else { strncpy(gstroutmemname,"lidar_pc",255); } return; } void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) { if(nSize <=16)return; unsigned int * pHeadSize = (unsigned int *)strdata; if(*pHeadSize > nSize) { std::cout<<"ListenPointCloud data is small headsize ="<<*pHeadSize<<" data size is"<::Ptr point_cloud( new pcl::PointCloud()); int nNameSize; nNameSize = *pHeadSize - 4-4-8; char * strName = new char[nNameSize+1];strName[nNameSize] = 0; memcpy(strName,(char *)((char *)strdata +4),nNameSize); point_cloud->header.frame_id = strName; memcpy(&point_cloud->header.seq,(char *)strdata+4+nNameSize,4); memcpy(&point_cloud->header.stamp,(char *)strdata+4+nNameSize+4,8); int nPCount = (nSize - *pHeadSize)/sizeof(pcl::PointXYZI); int i; pcl::PointXYZI * p; p = (pcl::PointXYZI *)((char *)strdata + *pHeadSize); for(i=0;ix; xp.y = p->y; xp.z = p->z; xp.intensity = p->intensity; point_cloud->push_back(xp); p++; // std::cout<<" x is "<::Ptr point_cloud,void * pa) { char * strOut = new char[4+sizeof(point_cloud->header.frame_id.size()) + 4+8+point_cloud->width * sizeof(pcl::PointXYZI)]; int * pHeadSize = (int *)strOut; *pHeadSize = 4 + point_cloud->header.frame_id.size()+4+8; memcpy(strOut+4,point_cloud->header.frame_id.c_str(),point_cloud->header.frame_id.size()); pcl::uint32_t * pu32 = (pcl::uint32_t *)(strOut+4+sizeof(point_cloud->header.frame_id.size())); *pu32 = point_cloud->header.seq; memcpy(strOut+4+sizeof(point_cloud->header.frame_id.size()) + 4,&point_cloud->header.stamp,8); pcl::PointXYZI * p; p = (pcl::PointXYZI *)(strOut +4+sizeof(point_cloud->header.frame_id.size()) + 4+8 ); memcpy(p,point_cloud->points.data(),point_cloud->width * sizeof(pcl::PointXYZI)); iv::modulecomm::ModuleSendMsg(pa,strOut,4+sizeof(point_cloud->header.frame_id.size()) + 4+8+point_cloud->width * sizeof(pcl::PointXYZI)); delete strOut; } void merge() { int i; std::vector xvectorlidar; pcl::PointCloud::Ptr point_cloud( new pcl::PointCloud()); gMutex.lock(); xvectorlidar = gvectorlidar; for(i=0;i150) ||(bNOtAllOK == false)) { merge(); qDebug("time is %ld",glasttime); glasttime = QDateTime::currentMSecsSinceEpoch(); } } } int main(int argc, char *argv[]) { showversion("driver_lidar_merge"); QCoreApplication a(argc, argv); dec_yaml("driver_lidar_merge.yaml"); void * pa; int i; for(i=0;i