#include #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 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; } }