123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #include <stdint.h>
- #include "api/video/video_frame.h"
- #include "../common/comm.h"
- #include "Protocol.pb.h"
- #include "car_sim.h"
- #include "EgoClient.h"
- CCarSim::CCarSim(CEgoClient* car) :_car(car)
- {
- }
- void CCarSim::Start()
- {
- }
- void CCarSim::Stop()
- {
-
- }
- void CCarSim::OnPeerMessage(int16_t cmd, int16_t length, const void* data)
- {
- switch (cmd)
- {
- case RemoNet::CC_Ping:
- {
- RemoNet::CCPing Req;
- Req.ParseFromArray(data, length);
- int64_t tick = GetTickCount64();
- int32_t diff = tick - Req.tick();
- double temp = Req.temp();
- _car->OnPingValue(diff,temp);
- }
- break;
- case RemoNet::CC_StopACK:
- {
- _car->OnStopAck();
- }
- case RemoNet::CC_STATE:
- {
- RemoNet::State msg;
- msg.ParseFromArray(data, length);
- /*
- RemoNet::CCCanMsg msg;
- msg.ParseFromArray(data, length);
- int32_t count = msg.frams_size();
- std::vector<cannet_frame> vec;
- for (int32_t i = 0; i < count; i++)
- {
- const RemoNet::can_net_frame& frame = msg.frams(i);
- if (frame.canid() == 0x189)
- {
- cannet_frame node;
- node.canid = frame.canid();
- node.dlc = frame.dlc();
- memcpy(node.data, frame.data().data(), node.dlc);
- }
- switch (_car->GetCurrentPage())
- {
- case PageProp::WorkPage1:
- {
- switch (frame.canid())
- {
- case 0x1F0:case 0x2F0:case 0x3F0:case 0x4F0:case 0x1F1:case 0x1F2:case 0x2F1:
- case 0x2F2:
- {
- cannet_frame node;
- node.canid = frame.canid();
- node.dlc = frame.dlc();
- memcpy(node.data, frame.data().data(), node.dlc);
- vec.push_back(node);
- }
- break;
- }
- }
- break;
- case PageProp::WorkPage2:
- {
- switch (frame.canid())
- {
- case 0x3F2:
- case 0x4F2:
- {
- cannet_frame node;
- node.canid = frame.canid();
- node.dlc = frame.dlc();
- memcpy(node.data, frame.data().data(), node.dlc);
- vec.push_back(node);
- }
- break;
- }
- }
- break;
- case PageProp::CalibrationPage:
- {
- switch (frame.canid())
- {
- case 0x2F6:case 0x3F6:case 0x4F6:
- case 0x1F9:case 0x2F9:case 0x4F9:
- case 0x380 + 0x81: //0x401
- {
- cannet_frame node;
- node.canid = frame.canid();
- node.dlc = frame.dlc();
- memcpy(node.data, frame.data().data(), node.dlc);
- vec.push_back(node);
- }
- break;
- }
- }
- break;
- case PageProp::EngineParameterPage:
- {
- switch (frame.canid())
- {
- case 0x1F3: case 0x2F3:case 0x3F3:case 0x4F3:
- case 0x1F4:case 0x2F4:case 0x3F4: case 0x4F4:
- case 0x1F5:
- {
- cannet_frame node;
- node.canid = frame.canid();
- node.dlc = frame.dlc();
- memcpy(node.data, frame.data().data(), node.dlc);
- vec.push_back(node);
- }
- break;
- }
- }
- break;
- case PageProp::WarningPage:
- {
- switch (frame.canid())
- {
- case 0x1F6:
- {
- cannet_frame node;
- node.canid = frame.canid();
- node.dlc = frame.dlc();
- memcpy(node.data, frame.data().data(), node.dlc);
- vec.push_back(node);
- }
- break;
- }
- }
- break;
- }
- }
- */
- FeedData data;
- data.brake_pressure = msg.brake_pressure();
- data.engine_rpm = msg.engine_rpm();
- data.engine_pressure = msg.engine_pressure();
- //data.gear = msg.gear();
- data.gearbox_oil_pressure = msg.gearbox_oil_pressure();
- data.gearbox_oil_temp = msg.gearbox_oil_temp();
- data.speed = msg.speed();
- data.work_pressure = msg.work_pressure();
- data.cold_water = msg.cold_water();
- data.steer_angle = msg.steer_angle();
- data.left_lock_status = msg.left_lock();
- data.right_lock_status = msg.right_lock();
- _car->OnFeedPage(data);
- }
- break;
- case RemoNet::CC_NDTPOS:
- {
- RemoNet::NDTPos Req;
- Req.ParseFromArray(data, length);
- Position pos;
- pos.x = Req.x();
- pos.y = Req.y();
- pos.z = Req.z();
- pos.rx = Req.rx();
- pos.ry = Req.ry();
- pos.rz = Req.rz();
- pos.rw = Req.rw();
- _car->OnNDTPos(&pos);
- }
- break;
- }
- }
-
|