123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167 |
- #include <atomic>
- #include <string>
- #include "../common/comm.h"
- #include "api.h"
- #include "../common/iobuffer.h"
- #include "../common/sensor_socket.h"
- #include "../common/peer_connection.h"
- #include "VideoRenderer.h"
- #include "../thirdparty/jsoncpp/include/json/json.h"
- #include "protocol.pb.h"
- #include "imu_sensor.h"
- #include "Rtk.h"
- #include "message_queue.h"
- #include <fstream>
- #include <iostream>
- #include <cstring>
- #include "hmacsha256.h"
- #include <linux/usbdevice_fs.h>
- #include <sys/ioctl.h>
- #include <sys/statfs.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/vfs.h>
- #include <dirent.h>
- #include <sys/stat.h>
-
- CMessageQueue::CMessageQueue():Head(nullptr),Tail(nullptr)
- {
- _peerId=-1;
- btimeStopedCar = false;
- File_fd = NULL;
- _Version = 1;
- }
- CMessageQueue::~CMessageQueue()
- {
- }
- void renableUSB(const char* file)
- {
- printf("Resetting USB device %s\n", file);
- int fd = open(file, O_WRONLY);
- if (fd < 0) {
- char text[256];
- perror(text);
- printf("Error opening output file %s", text);
- return;
- }
- int rc = ioctl(fd, USBDEVFS_RESET, 0);
- if (rc < 0) {
- perror("Error in ioctl");
- return;
- }
- printf("Reset successful\n");
- close(fd);
- }
- void CMessageQueue::Create()
- {
-
- Json::Value root;
- Json::Reader jsonReader;
- std::ifstream ifile("./config.json");
- std::string serverip;
- int32_t _hostPort;
- int32_t _remotePort;
- _curTick=0;
- bStopedCar=false;
- if(jsonReader.parse(ifile,root))
- {
- std::cout<<"enter config json"<<std::endl;
- _serial=root["serial"].asString();
-
- int32_t _Rtkport=root["rtk_port"].asInt();
- int32_t _Rtkhost=root["rtk_host"].asInt();
- std::string _Rtkip=root["rtk_ip"].asString();
- std::cout<<"Rtk ip:"<< _Rtkip <<std::endl;
- _Rtk = std::make_unique<SensorSocket<CRtkSensor>>(this, _Rtkip, _Rtkport, _Rtkhost);
-
- _Version = root["Version"].asInt();
- if(_Version)
- {
- std::string can_port_radar = root["can_bus_radar"].asString();
- _CanBusRadar = std::make_unique<SensorCanBus<CCanRadarSensor>>(this, can_port_radar);
-
- }
- else
- {
-
- int32_t _radarport=root["radar_port"].asInt();
- int32_t _radarhost=root["radar_host"].asInt();
- std::string _radarip=root["radar_ip"].asString();
- std::cout<<"radar ip:"<<_radarip<<std::endl;
- _RadarIp = std::make_unique<SensorSocket<CRadarSensor>>(this,_radarip,_radarport,_radarhost);
-
- }
-
-
- if(_Version)
- {
- std::string can_port = root["can_bus_vehicle"].asString();
- _CanBusVehicle = std::make_unique<SensorCanBus<CCanBusSensor>>(this, can_port);
-
- }
- else
- {
- _PcanBusVehicle = std::make_unique<SensorPeakCan<CPcanSensor>>(this);
-
- }
-
- _UdpMinPort=root["udp_min_port"].asInt();
- _UdpMaxPort=root["udp_max_port"].asInt();
-
-
-
-
- std::string serverUrl = root["MqttserverUrl"].asString();
- std::string userName = root["Esn"].asString();
- std::string password = root["EsnPass"].asString();
- std::string clientId = "";
- bool _Hm256 = false;
- unsigned char Source[128];
- time_t rawtime;
- struct tm* info;
- char buffer[80];
- time(&rawtime);
- info = localtime(&rawtime);
- uint8_t secret[32] = { 0 };
-
-
- sprintf((char*)secret, "%d%.2d%.2d", info->tm_year + 1900, info->tm_mon + 1, info->tm_mday);
- memset(Source, 0, 128);
- sprintf((char*)Source, "%s_0_0_%s", userName.c_str(), secret);
- clientId.clear();
- clientId.append((const char*)Source);
- if (password.length() && _Hm256)
- {
- uint8_t outdata[128] = { 0 };
- uint8_t md[SHA256_DIGESTLEN] = { 0 };
- int len1 = strlen((char*)secret);
- int len2 = strlen((char*)password.c_str());
- HMAC_SHA256_CTX hmac;
- hmac_sha256_init(&hmac, secret, len1);
- hmac_sha256_update(&hmac, (const uint8_t*)password.c_str(), len2);
- hmac_sha256_final(&hmac, md);
- memcpy(outdata, md, SHA256_DIGESTLEN);
- password.clear();
- password.append((const char*)outdata);
-
- }
-
- _Mqtt_ZR = std::make_unique<SensorMQTT<CMqttSensor>>(this, serverUrl, userName, password, clientId);
- std::string DataServerUrl = root["DataServerUrl"].asString();
- std::string DatauserName = root["DataEsn"].asString();
- std::string Datapassword = root["DataEsnPass"].asString();
- std::string DataclientId = root["DataClientId"].asString();
- _Mqtt_SE = std::make_unique<SensorMQTT<CDataMqttSensor>>(this, DataServerUrl, DatauserName, Datapassword, DataclientId);
-
-
-
-
-
-
- serverip=root["ip"].asString();
- _hostPort=root["TcpHostPort"].asInt();
- _remotePort=root["TcpRemotePort"].asInt();
- _name=root["name"].asString();
- const Json::Value arrayObj=root["camerainfo"];
- int32_t count=arrayObj.size();
- for(int32_t i=0;i<count;i++)
- {
- LocalCameraInfo info;
- const Json::Value& value=arrayObj[i];
- info.index=value["index"].asInt();
- info.label=value["label"].asString();
- _cameraArray.push_back(info);
- }
- for(int i=0;i<_cameraArray.size();i++)
- {
- _peerArray.push_back({nullptr});
- }
-
- }
- else{
- std::string error=jsonReader.getFormattedErrorMessages();
- std::cout<<error<<std::endl;
- }
- _client=std::make_unique<SocketClient>(this);
- _client->Start(serverip.c_str(),_remotePort,_hostPort);
-
-
-
-
-
-
-
-
-
-
-
-
- std::this_thread::yield();
-
- }
- void CMessageQueue::EnQueue(CIOBuffer* pBuffer)
- {
- bool bNullBuffer=false;
- std::unique_lock <std::mutex> lck(_lock);
- if(Head==nullptr)
- {
- Head=Tail=pBuffer;
- bNullBuffer=true;
- }
- else{
- Tail->NextBuf=pBuffer;
- Tail=Tail->NextBuf;
- }
- pBuffer->NextBuf=nullptr;
- if(bNullBuffer)
- {
-
-
- _cv.notify_all();
- }
- }
- void CMessageQueue::Process()
- {
- CIOBuffer * ptr=nullptr;
- {
- std::unique_lock <std::mutex> lck(_lock);
-
- while(Head==nullptr&&_cv.wait_for(lck,std::chrono::seconds(1))==std::cv_status::timeout)
- {
- CheckSignal();
-
-
-
- }
-
- }
- while(Head!=nullptr)
- {
- ptr=Head;
- Head=Head->NextBuf;
- if(ptr!=nullptr)
- {
- Message* message=reinterpret_cast<Message *>(ptr->Buffer);
- switch (message->cmd)
- {
- case MessageType::ReqVideo:
- OnNotifyReq((int32_t)message->param_l);
- break;
- case MessageType::RepVideo:
- OnNotifyRep((int32_t)message->param_l);
- break;
- case MessageType::Connected:
- OnNotifyConnected((bool)message->param_l);
- break;
- case MessageType::Leave:
- OnNotifyLeave();
- break;
- case MessageType::AsyncMessage:
- OnNotifyMessage();
- break;
- case MessageType::StopSensor:
- OnNotifyStopSensor();
- break;
- case MessageType::Ping:
- OnNotifyPing(message->param_l);
- break;
- }
- ptr->Release();
- }
- }
- }
- void CMessageQueue::SetTick(long long tick)
- {
- _curTick=tick;
- }
- void CMessageQueue::OnNotifyConnected(bool bRet)
- {
- if(bRet)
- {
-
- _client->WriteAddRobot(_serial,_name,static_cast<int32_t>(EgoType::Car));
- _updatethread.start(_client.get());
-
- }
- else
- {
- if(_peerId!=-1)
- {
- OnVideoLeave(_peerId,EgoType::User);
- _peerId=-1;
- }
-
- _updatethread.stop();
- }
- }
-
-
-
-
- void CMessageQueue::OnNotifyReq(int32_t index)
- {
-
- if(_peerId==-1) return;
- if(index==0)
- {
- mrsWebrtcCreateFactory(true);
- _curTick=0;
- bStopedCar=false;
- _Rtk->Start();
- if(_Version)
- {
- _CanBusVehicle->Start();
- _CanBusRadar->Start();
- }
- else
- {
- _PcanBusVehicle->Start();
- _RadarIp->Start();
- }
-
- _Mqtt_ZR->Start();
- _Mqtt_SE->Start();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
- _peerArray[index]=std::make_unique<CPeerConnection>(static_cast<ChannelType>(index),_client.get());
-
-
- _client->WriteVideoRep(_peerId, RemoNet::VideoDesc::OK, index);
- }
- void CMessageQueue::OnNotifyRep(int32_t index)
- {
- _peerArray[index]=std::make_unique<CPeerConnection>(static_cast<ChannelType>(index), _client.get());
-
-
- InitPeerConnection(_peerId,index);
- _peerArray[index]->CreateOffer();
-
- }
- void CMessageQueue::InitPeerConnection(int32_t peer,int32_t index)
- {
-
-
- _peerArray[index]->Initialize(peer,index,_UdpMinPort,_UdpMaxPort);
- _peerArray[index]->AddDataChannel(true, false);
-
- _peerArray[index]->AddLocalVideoTrack(static_cast<RenderPosition>(index),_cameraArray[index].index);
-
-
- if(index==RenderPosition::BACK)
- {
- void * front=_peerArray[RenderPosition::FRONT]->GetCurrentCtx();
- while(front==nullptr)
- {
- std::cout<<"front==nullptr"<<std::endl;
- std::this_thread::sleep_for(std::chrono::microseconds(50));
- front=_peerArray[RenderPosition::FRONT]->GetCurrentCtx();
- }
- void * back=_peerArray[RenderPosition::BACK]->GetCurrentCtx();
- while (back==nullptr)
- {
- std::cout<<"back==nullptr"<<std::endl;
- std::this_thread::sleep_for(std::chrono::microseconds(50));
- back=_peerArray[RenderPosition::BACK]->GetCurrentCtx();
- }
- _peerArray[RenderPosition::FRONT]->SetOtherCtx(back);
- _peerArray[RenderPosition::BACK]->SetOtherCtx(front);
- }
-
-
-
-
-
- if(index==RenderPosition::FRONT)
- _peerArray[index]->AddLocalAudioTrack();
- }
-
- void CMessageQueue::OnAdd(bool bRet)
- {
- }
- void CMessageQueue::OnConnected(bool bRet)
- {
-
- CIOBuffer * pBuffer=CIOBuffer::Alloc();
- Message* message=reinterpret_cast<Message *>(pBuffer->Buffer);
- message->cmd=MessageType::Connected;
- message->param_l=bRet;
- EnQueue(pBuffer);
-
- }
-
- void CMessageQueue::OnVideoLeave(int32_t peer,EgoType type)
- {
- {
- CIOBuffer * pBuffer=CIOBuffer::Alloc();
- Message* message=reinterpret_cast<Message *>(pBuffer->Buffer);
- message->cmd=MessageType::StopSensor;
- EnQueue(pBuffer);
- }
- {
- CIOBuffer * pBuffer=CIOBuffer::Alloc();
- Message* message=reinterpret_cast<Message *>(pBuffer->Buffer);
- message->cmd=MessageType::Leave;
-
- EnQueue(pBuffer);
- }
- }
- #ifdef WIN32
- void CMessageQueue::OnVideoRep(int32_t index,RemoNet::VideoDesc desc)
- {
- if (desc == RemoNet::VideoDesc::OK)
- {
- assert(_peerId!=-1);
- CIOBuffer * pBuffer=CIOBuffer::Alloc();
- Message* message=reinterpret_cast<Message *>(pBuffer->Buffer);
- message->cmd=MessageType::ReqVideo;
- message->param_l=index;
-
- EnQueue(pBuffer);
- }
- }
- #else
- void CMessageQueue::OnVideoReq(int32_t video,int32_t peer)
- {
-
- _peerId=peer;
- CIOBuffer * pBuffer=CIOBuffer::Alloc();
- Message* message=reinterpret_cast<Message *>(pBuffer->Buffer);
- message->cmd=MessageType::ReqVideo;
- message->param_l=video;
-
- EnQueue(pBuffer);
-
- }
- #endif
- void CMessageQueue::OnNotifyLeave()
- {
-
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
-
- for (size_t i = 0; i < _peerArray.size(); i++)
- {
- if(_peerArray[i]!=nullptr)
- {
- _peerArray[i]->Close();
- _peerArray[i].reset();
- }
-
- }
- _peerId=-1;
-
- }
- void CMessageQueue::OnNotifyStopSensor()
- {
- _curTick=0;
- if(_Version)
- {
- std::cout<<"_CanBusVehicle Stop"<<std::endl;
- _CanBusVehicle->Stop();
- std::cout<<"_CanBusRadar Stop"<<std::endl;
- _CanBusRadar->Stop();
- }
- else
- {
- std::cout<<"_PcanBusVehicle Stop"<<std::endl;
- _PcanBusVehicle->Stop();
- std::cout<<"_RadarIp Stop"<<std::endl;
- _RadarIp->Stop();
- }
- std::cout << "RTK Stop" << std::endl;
- _Rtk->Stop();
- std::cout<<"mqtt Stop"<<std::endl;
- _Mqtt_ZR->Stop();
- std::cout<<"data mqtt Stop"<<std::endl;
- _Mqtt_SE->Stop();
-
-
-
-
-
-
- RemoNet::StopAck Rep;
-
- CIOBuffer Buffer;
- MessageHead Head;
- Head.Command = RemoNet::CC_StopACK;
- Head.Length = Rep.ByteSizeLong();
- Head.Serialize(Buffer.Buffer);
- auto ptr = Buffer.Buffer + MessageHead::Size();
- Rep.SerializeToArray(ptr, Head.Length);
- Buffer.Length = Head.Length + MessageHead::Size();
- _peerArray[RenderPosition::FRONT]->SendData(Buffer);
- }
- void CMessageQueue::OnVideoOffer(int32_t index,const char* type, const char* sdp)
- {
-
- InitPeerConnection(_peerId,index);
-
- _peerArray[index]->SetRemoteDescription(type,sdp);
- _peerArray[index]->CreateAnswer();
-
- }
- void CMessageQueue::OnVideoAnswer(int32_t index, const char* type, const char* sdp)
- {
-
-
- _peerArray[index]->SetRemoteDescription(type,sdp);
-
- }
- void CMessageQueue::OnVideoCandidate(int32_t index,const char* candidate,
- int32_t sdp_mline_index,
- const char* sdp_mid)
- {
-
- _peerArray[index]->AddIceCandidate(candidate,sdp_mline_index,sdp_mid);
-
- }
- void CMessageQueue::OnMessageFrameNotify(ChannelType type,int16_t cmd,int16_t length,const void * data)
- {
-
-
- if(cmd==RemoNet::CC_Text)
- {
- RemoNet::TestTextReq Req;
-
- Req.ParseFromArray(data,length);
- std::cout<<Req.text()<<std::endl;
- CIOBuffer * pBuffer=CIOBuffer::Alloc();
- Message* message=reinterpret_cast<Message *>(pBuffer->Buffer);
- message->cmd=MessageType::AsyncMessage;
- EnQueue(pBuffer);
-
- }
- else if(cmd==RemoNet::CC_Switch)
- {
- RemoNet::CCSwitch Req;
- Req.ParseFromArray(data,length);
- bool front=Req.front();
- _peerArray[RenderPosition::FRONT]->SwitchCapture(front);
- }
- else if(cmd==RemoNet::CC_Ping)
- {
- RemoNet::CCPing Req;
- Req.ParseFromArray(data,length);
- CIOBuffer * pBuffer=CIOBuffer::Alloc();
- Message* message=reinterpret_cast<Message *>(pBuffer->Buffer);
- message->cmd=MessageType::Ping;
- message->param_l=Req.tick();
- EnQueue(pBuffer);
- }
- else if(cmd==RemoNet::CC_SensorStop)
- {
- CIOBuffer * pBuffer=CIOBuffer::Alloc();
- Message* message=reinterpret_cast<Message *>(pBuffer->Buffer);
- message->cmd=MessageType::StopSensor;
- EnQueue(pBuffer);
- }
- else if (cmd == RemoNet::CC_CANMSG)
- {
- _source = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- _curTick = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
-
- RemoNet::CCCanMsg Req;
- Req.ParseFromArray(data, length);
- cannet_frame* frames = (cannet_frame*)alloca(sizeof(cannet_frame) * Req.frams_size());
- for (int32_t i = 0; i < Req.frams_size(); i++)
- {
- auto& frame = Req.frams(i);
- frames[i].canid = frame.canid();
- frames[i].dlc = frame.dlc();
- memcpy(frames[i].data, frame.data().data(), frame.dlc());
- }
-
- if(_Version)
- _CanBusVehicle->Get()->OnMessage(frames, Req.frams_size());
- else
- _PcanBusVehicle->Get()->OnMessage(frames, Req.frams_size());
- }
- }
- void CMessageQueue::StopCar()
- {
- std::cout<<"Stop Car"<<std::endl;
- if(_Version)
- _CanBusVehicle->Get()->Emergency();
- else
- _PcanBusVehicle->Get()->Emergency();
- }
-
- void CMessageQueue::OnNotifyMessage()
- {
- RemoNet::TestTextReq Req;
- Req.set_text("ewqewqewqe");
- CIOBuffer Buffer;
- MessageHead Head;
- Head.Command = RemoNet::CC_Text;
- Head.Length = Req.ByteSizeLong();
- Head.Serialize(Buffer.Buffer);
- auto ptr = Buffer.Buffer + MessageHead::Size();
- Req.SerializeToArray(ptr, Head.Length);
- Buffer.Length = Head.Length + MessageHead::Size();
- _peerArray[RenderPosition::FRONT]->SendData(Buffer);
-
- }
- void CMessageQueue::OnNotifyPing(int64_t value)
- {
- RemoNet::CCPing Rep;
- Rep.set_tick(value);
- CIOBuffer Buffer;
- MessageHead Head;
- Head.Command = RemoNet::CC_Ping;
- Head.Length = Rep.ByteSizeLong();
- Head.Serialize(Buffer.Buffer);
- auto ptr = Buffer.Buffer + MessageHead::Size();
- Rep.SerializeToArray(ptr, Head.Length);
- Buffer.Length = Head.Length + MessageHead::Size();
-
- if( _peerArray[RenderPosition::FRONT]!=nullptr && _peerArray[RenderPosition::FRONT]->bReadyChannel)
- _peerArray[RenderPosition::FRONT]->SendData(Buffer);
- }
- void CMessageQueue::CheckSignal()
- {
-
- if(!bStopedCar)
- {
- long long tick=std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- if(_curTick!=0&&tick-_curTick > 3)
- {
- StopCar();
- bStopedCar=true;
- std::cout<<"_curTick!=0&&tick-_curTick > 3" << std::endl;
- _curStopTick = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- btimeStopedCar = true;
- _curTick = 0;
- }
- }
-
- }
- void CMessageQueue::WriteIMUData(ImuData* data)
- {
-
- MessageHead Head;
- CIOBuffer Buffer;
-
- RemoNet::IMuMessage Req;
-
- Req.set_rx(data->ry);
- Req.set_ry(data->rx);
-
-
- Head.Command=RemoNet::CC_IMU;
- Head.Length=Req.ByteSizeLong();
- Head.Serialize(Buffer.Buffer);
- auto ptr = Buffer.Buffer + MessageHead::Size();
- Req.SerializeToArray(ptr, Head.Length);
- Buffer.Length = Head.Length + MessageHead::Size();
-
- if( _peerArray[ChannelType::CHANNEL_IMU]!=nullptr)
- _peerArray[ChannelType::CHANNEL_IMU]->SendData(Buffer);
-
- }
- void CMessageQueue::WritePacket(ChannelType type, CIOBuffer & pBuffer)
- {
- if( _peerArray[type]!=nullptr)
- _peerArray[type]->SendData(pBuffer);
- }
- void CMessageQueue::WriteRadarData(RadarData& data)
- {
- MessageHead Head;
- CIOBuffer Buffer;
- RemoNet::CCRadarMessage Req;
- Req.set_radar0(data.r0);
- Req.set_radar1(data.r1);
- Req.set_radar2(data.r2);
- Req.set_radar3(data.r3);
- Req.set_radar4(data.r4);
- Req.set_radar5(data.r5);
- Req.set_radar6(data.r6);
- Req.set_radar7(data.r7);
-
- Head.Command = RemoNet::CC_Radar;
- Head.Length=Req.ByteSizeLong();
- Head.Serialize(Buffer.Buffer);
- auto ptr = Buffer.Buffer + MessageHead::Size();
- Req.SerializeToArray(ptr, Head.Length);
- Buffer.Length = Head.Length + MessageHead::Size();
- if( _peerArray[ChannelType::CHANNEL_RADAR]!=nullptr)
- _peerArray[ChannelType::CHANNEL_RADAR]->SendData(Buffer);
-
- }
- void CMessageQueue::WriteRobotStatus(int32_t ,int32_t )
- {
-
- }
- #ifdef LIDAR_SENSOR
- void CMessageQueue::WriteLidarPoint(const PointCloudMsg<PointXYZI>& msg,ChannelType side)
- {
- RemoNet::LidarPoint pt;
- pt.set_is_left(side==ChannelType::CHANNEL_LEFT_LIDAR);
- pt.set_frame_id(msg.frame_id);
- pt.set_height(msg.height);
- pt.set_width(msg.width);
- pt.set_is_dense(msg.is_dense);
- pt.set_seq(msg.seq);
- pt.set_timestamp(msg.timestamp);
- for(int i=0;i<msg.point_cloud_ptr->size();i++)
- {
- pt.add_data((*msg.point_cloud_ptr)[i].x);
- pt.add_data((*msg.point_cloud_ptr)[i].y);
- pt.add_data((*msg.point_cloud_ptr)[i].z);
- pt.add_data((*msg.point_cloud_ptr)[i].intensity);
- }
- MessageHead Head;
- CIOBuffer Buffer;
- Head.Command=RemoNet::CC_LIDARDATA;
- Head.Length=pt.ByteSizeLong();
- Head.Serialize(Buffer.Buffer);
- auto ptr = Buffer.Buffer + MessageHead::Size();
- pt.SerializeToArray(ptr, Head.Length);
- Buffer.Length = Head.Length + MessageHead::Size();
-
- if( _peerArray[side]!=nullptr)
- _peerArray[side]->SendData(&Buffer);
- }
- #endif
- void CMessageQueue::SwitchCamera(bool front)
- {
- _peerArray[RenderPosition::FRONT]->SwitchCapture(front);
- _peerArray[RenderPosition::BACK]->SwitchCapture(front);
- }
- void CMessageQueue::SendZGJStatus(int status)
- {
- _Rtk->Get()->Send_ZGJ_status(status);
- }
- void CMessageQueue::SendVehicleStatus(vehicle_status can_status)
- {
-
- if (CDataMqttSensor::_run)
- {
- time_t rawtime;
- struct tm* info;
- time(&rawtime);
- info = localtime(&rawtime);
- char secret[64] = { 0 };
- sprintf((char*)secret, "%d-%.2d-%.2d %.2d:%.2d:%.2d", info->tm_year + 1900, info->tm_mon + 1, info->tm_mday,info->tm_hour,info->tm_min,info->tm_sec);
- printf("%s\r\n",secret);
-
-
-
-
-
- Json::Value root;
- Json::Value Source;
- Json::FastWriter writer;
- std::string SendTime;
-
-
-
-
-
- Source["1"] = can_status.fire_status;
- Source["2"] = can_status.remote_forward;
- Source["3"] = can_status.remote_backward;
- Source["4"] = can_status.Brake;
- Source["5"] = can_status.Park;
- Source["6"] = can_status.Outrigger_status;
- Source["7"] = can_status.Turn_angle;
- Source["8"] = can_status.Left_turn;
- Source["9"] = can_status.Right_turn;
- Source["10"] = can_status.Raised;
- Source["11"] = can_status.Decrease;
- Source["12"] = can_status.Stretch;
- Source["13"] = can_status.Bulls_decline;
- Source["14"] = can_status.Material;
- Source["15"] = can_status.Discharge;
- Source["16"] = can_status.zhua;
- Source["17"] = can_status.fang;
- Source["18"] = can_status.Shell_rotation_left;
- Source["19"] = can_status.Shell_rotation_right;
- Source["19"] = can_status.Cabin;
- Source["20"] = can_status.Cab;
- Source["21"] = can_status.Working_signal;
- Source["22"] = can_status.Turn_left_signal;
- Source["23"] = can_status.Turn_right_signal;
- Source["24"] = can_status.Warning_Light;
- Source["25"] = can_status.Trumpet;
- Source["26"] = can_status.Security_lock;
- Source["27"] = can_status.Urget_stop;
- Source["28"] = can_status.Vehicle_id;
- Source["29"] = SendTime.assign(secret,strlen(secret));;
- Json::StyledWriter sw;
-
- if (!DataMqtt_SendDate)
- {
- DataMqtt_curTick = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- DataMqtt_SendDate = true;
- }
- else
- {
- long long tick = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- if (DataMqtt_curTick != 0 && tick - DataMqtt_curTick > 10000)
- {
- if (CDataMqttSensor::_run && (CDataMqttSensor::m_mqttClient != NULL))
- CDataMqttSensor::sendMessage((char*)sw.write(Source).c_str(), 0, (char*)"bg/log");
- DataMqtt_SendDate = false;
- }
- }
- }
- }
|