car_sim.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include <stdint.h>
  2. #include "api/video/video_frame.h"
  3. #include "../common/comm.h"
  4. #include "Protocol.pb.h"
  5. #include "car_sim.h"
  6. #include "EgoClient.h"
  7. CCarSim::CCarSim(CEgoClient* car) :_car(car)
  8. {
  9. }
  10. void CCarSim::Start()
  11. {
  12. }
  13. void CCarSim::Stop()
  14. {
  15. }
  16. void CCarSim::OnPeerMessage(int16_t cmd, int16_t length, const void* data)
  17. {
  18. switch (cmd)
  19. {
  20. case RemoNet::CC_Ping:
  21. {
  22. RemoNet::CCPing Req;
  23. Req.ParseFromArray(data, length);
  24. int64_t tick = GetTickCount64();
  25. int32_t diff = tick - Req.tick();
  26. double temp = Req.temp();
  27. _car->OnPingValue(diff,temp);
  28. }
  29. break;
  30. case RemoNet::CC_StopACK:
  31. {
  32. _car->OnStopAck();
  33. }
  34. case RemoNet::CC_STATE:
  35. {
  36. RemoNet::State msg;
  37. msg.ParseFromArray(data, length);
  38. /*
  39. RemoNet::CCCanMsg msg;
  40. msg.ParseFromArray(data, length);
  41. int32_t count = msg.frams_size();
  42. std::vector<cannet_frame> vec;
  43. for (int32_t i = 0; i < count; i++)
  44. {
  45. const RemoNet::can_net_frame& frame = msg.frams(i);
  46. if (frame.canid() == 0x189)
  47. {
  48. cannet_frame node;
  49. node.canid = frame.canid();
  50. node.dlc = frame.dlc();
  51. memcpy(node.data, frame.data().data(), node.dlc);
  52. }
  53. switch (_car->GetCurrentPage())
  54. {
  55. case PageProp::WorkPage1:
  56. {
  57. switch (frame.canid())
  58. {
  59. case 0x1F0:case 0x2F0:case 0x3F0:case 0x4F0:case 0x1F1:case 0x1F2:case 0x2F1:
  60. case 0x2F2:
  61. {
  62. cannet_frame node;
  63. node.canid = frame.canid();
  64. node.dlc = frame.dlc();
  65. memcpy(node.data, frame.data().data(), node.dlc);
  66. vec.push_back(node);
  67. }
  68. break;
  69. }
  70. }
  71. break;
  72. case PageProp::WorkPage2:
  73. {
  74. switch (frame.canid())
  75. {
  76. case 0x3F2:
  77. case 0x4F2:
  78. {
  79. cannet_frame node;
  80. node.canid = frame.canid();
  81. node.dlc = frame.dlc();
  82. memcpy(node.data, frame.data().data(), node.dlc);
  83. vec.push_back(node);
  84. }
  85. break;
  86. }
  87. }
  88. break;
  89. case PageProp::CalibrationPage:
  90. {
  91. switch (frame.canid())
  92. {
  93. case 0x2F6:case 0x3F6:case 0x4F6:
  94. case 0x1F9:case 0x2F9:case 0x4F9:
  95. case 0x380 + 0x81: //0x401
  96. {
  97. cannet_frame node;
  98. node.canid = frame.canid();
  99. node.dlc = frame.dlc();
  100. memcpy(node.data, frame.data().data(), node.dlc);
  101. vec.push_back(node);
  102. }
  103. break;
  104. }
  105. }
  106. break;
  107. case PageProp::EngineParameterPage:
  108. {
  109. switch (frame.canid())
  110. {
  111. case 0x1F3: case 0x2F3:case 0x3F3:case 0x4F3:
  112. case 0x1F4:case 0x2F4:case 0x3F4: case 0x4F4:
  113. case 0x1F5:
  114. {
  115. cannet_frame node;
  116. node.canid = frame.canid();
  117. node.dlc = frame.dlc();
  118. memcpy(node.data, frame.data().data(), node.dlc);
  119. vec.push_back(node);
  120. }
  121. break;
  122. }
  123. }
  124. break;
  125. case PageProp::WarningPage:
  126. {
  127. switch (frame.canid())
  128. {
  129. case 0x1F6:
  130. {
  131. cannet_frame node;
  132. node.canid = frame.canid();
  133. node.dlc = frame.dlc();
  134. memcpy(node.data, frame.data().data(), node.dlc);
  135. vec.push_back(node);
  136. }
  137. break;
  138. }
  139. }
  140. break;
  141. }
  142. }
  143. */
  144. FeedData data;
  145. data.brake_pressure = msg.brake_pressure();
  146. data.engine_rpm = msg.engine_rpm();
  147. data.engine_pressure = msg.engine_pressure();
  148. //data.gear = msg.gear();
  149. data.gearbox_oil_pressure = msg.gearbox_oil_pressure();
  150. data.gearbox_oil_temp = msg.gearbox_oil_temp();
  151. data.speed = msg.speed();
  152. data.work_pressure = msg.work_pressure();
  153. data.cold_water = msg.cold_water();
  154. data.steer_angle = msg.steer_angle();
  155. data.left_lock_status = msg.left_lock();
  156. data.right_lock_status = msg.right_lock();
  157. _car->OnFeedPage(data);
  158. }
  159. break;
  160. case RemoNet::CC_NDTPOS:
  161. {
  162. RemoNet::NDTPos Req;
  163. Req.ParseFromArray(data, length);
  164. Position pos;
  165. pos.x = Req.x();
  166. pos.y = Req.y();
  167. pos.z = Req.z();
  168. pos.rx = Req.rx();
  169. pos.ry = Req.ry();
  170. pos.rz = Req.rz();
  171. pos.rw = Req.rw();
  172. _car->OnNDTPos(&pos);
  173. }
  174. break;
  175. }
  176. }