car_sim.cpp 3.8 KB

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