can_bus.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. #include "can_bus.h"
  2. #include <thread>
  3. #include "message_queue.h"
  4. #define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
  5. int16_t make_int16(unsigned char h,unsigned char l)
  6. {
  7. int16_t hi=(int16_t)(h&0x00FF);
  8. int16_t low= (int16_t)(l&0x00FF);
  9. return (hi<<8)|low;
  10. }
  11. CCanBusSensor::CCanBusSensor(CMessageQueue* q) :_message(q)
  12. {
  13. _run = false;
  14. _front_view = true;
  15. for (int32_t i = 0; i < sizeof(Sendframe)/sizeof(can_frame); i++)
  16. memset(&Sendframe[i], 0, sizeof(can_frame));
  17. }
  18. void CCanBusSensor::SetCanBusSensor(SensorCanBus<CCanBusSensor>* can)
  19. {
  20. _canbus = can;
  21. halfautomatic = true;
  22. _message->_Feeddata.right_lock = 1;
  23. }
  24. void CCanBusSensor::CanSendProc()
  25. {
  26. while (_run)
  27. {
  28. /*
  29. volatile int64_t tick=std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  30. if(tick-_last_can_uptime < 400)
  31. {
  32. std::lock_guard<std::mutex> lg(_last_can_lock);
  33. for(int32_t i=0;i<sizeof(Sendframe)/sizeof(can_frame);i++)
  34. {
  35. if(Sendframe[i].can_id != 0)
  36. {
  37. if(_message->_Feeddata.left_lock)
  38. _canbus->Write(&Sendframe[i]);
  39. Sendframe[i].can_id = 0;
  40. }
  41. }
  42. }
  43. std::this_thread::sleep_for(std::chrono::milliseconds(20));
  44. */
  45. //std::lock_guard<std::mutex> lg(_last_can_lock);
  46. for(int32_t i=0;i<sizeof(Sendframe)/sizeof(can_frame);i++)
  47. {
  48. if(Sendframe[i].can_id != 0)
  49. {
  50. if(!_message->_Feeddata.right_lock)
  51. {
  52. _canbus->Write(&Sendframe[i]);
  53. //printf("%x\r\n",Sendframe[i].can_id);
  54. }
  55. Sendframe[i].can_id = 0;
  56. }
  57. }
  58. std::this_thread::sleep_for(std::chrono::milliseconds(5));
  59. }
  60. }
  61. void CCanBusSensor::Start()
  62. {
  63. /*
  64. struct can_frame Sendframe_Test;
  65. Sendframe_Test.data[0] = 0xB1;
  66. Sendframe_Test.data[1] = 0x10;
  67. Sendframe_Test.data[2] = 0xFF;
  68. Sendframe_Test.can_dlc = 3;
  69. Sendframe_Test.can_id = 0x601;
  70. int ret = write(_canbus->sockfd, &Sendframe_Test, sizeof(Sendframe_Test));
  71. if(sizeof(Sendframe_Test) != ret)
  72. std::cout << "CCanBusSensor write error" << std::endl;
  73. */
  74. _run = true;
  75. _can_thread = std::thread(&CCanBusSensor::CanSendProc, this);
  76. halfautomatic = true;
  77. Gear_position_Set = 0;
  78. Gear_position_now = 1;
  79. count = 0;
  80. _message->_Feeddata.right_lock = 1;
  81. }
  82. void CCanBusSensor::Run()
  83. {
  84. }
  85. void CCanBusSensor::Stop()
  86. {
  87. /*
  88. struct can_frame Sendframe_Test;
  89. Sendframe_Test.data[0] = 0xB1;
  90. Sendframe_Test.data[1] = 0x10;
  91. Sendframe_Test.data[2] = 0x00;
  92. Sendframe_Test.can_dlc = 3;
  93. Sendframe_Test.can_id = 0x601;
  94. int ret = write(_canbus->sockfd, &Sendframe_Test, sizeof(Sendframe_Test));
  95. if(sizeof(Sendframe) != ret)
  96. std::cout << "CCanBusSensor write error" << std::endl;
  97. */
  98. if (_run)
  99. {
  100. _run = false;
  101. _can_thread.join();
  102. }
  103. for (int32_t i = 0; i < sizeof(Sendframe)/sizeof(can_frame); i++)
  104. memset(&Sendframe[i], 0, sizeof(can_frame));
  105. halfautomatic = false;
  106. Gear_position_Set = 0;
  107. Gear_position_now = 1;
  108. count = 0;
  109. _message->_Feeddata.right_lock = 1;
  110. }
  111. void CCanBusSensor::GetGearCurrent(uint8_t data)
  112. {
  113. /*
  114. if((GET_BIT(data,4) == 1) && (GET_BIT(data,5) == 0) && (GET_BIT(data,6) == 0))
  115. Gear_position_now = 1;
  116. else if((GET_BIT(data,4) == 0) && (GET_BIT(data,5) == 1) && (GET_BIT(data,6) == 0))
  117. Gear_position_now = 2;
  118. else if((GET_BIT(data,4) == 1) && (GET_BIT(data,5) == 1) && (GET_BIT(data,6) == 0))
  119. Gear_position_now = 3;
  120. else if((GET_BIT(data,4) == 0) && (GET_BIT(data,5) == 0) && (GET_BIT(data,6) == 1))
  121. Gear_position_now = 4;
  122. else
  123. Gear_position_now = 0;
  124. */
  125. if((GET_BIT(data,0) == 1) && (GET_BIT(data,1) == 0))
  126. {
  127. Gear_direction = 'F';
  128. _message->_Feeddata.f_gear = 1;
  129. }
  130. else if((GET_BIT(data,0) == 0) && (GET_BIT(data,1) == 1))
  131. {
  132. Gear_direction = 'R';
  133. _message->_Feeddata.f_gear = 2;
  134. }
  135. else
  136. {
  137. Gear_direction = 'N';
  138. _message->_Feeddata.f_gear = 3;
  139. }
  140. if((GET_BIT(data,4) == 0) && (GET_BIT(data,5) == 1) && (GET_BIT(data,6) == 0))
  141. {
  142. Gear_position_now = 2;
  143. _message->_Feeddata.gear_1 = 2;
  144. }
  145. else if((GET_BIT(data,4) == 1) && (GET_BIT(data,5) == 1) && (GET_BIT(data,6) == 0))
  146. {
  147. Gear_position_now = 3;
  148. _message->_Feeddata.gear_1 = 3;
  149. }
  150. else if((GET_BIT(data,4) == 0) && (GET_BIT(data,5) == 0) && (GET_BIT(data,6) == 1))
  151. {
  152. Gear_position_now = 4;
  153. _message->_Feeddata.gear_1 = 4;
  154. }
  155. else
  156. {
  157. Gear_position_now = 1;
  158. _message->_Feeddata.gear_1 = 1;
  159. }
  160. }
  161. void CCanBusSensor::SetGear_FR_Current(uint8_t data,uint8_t type)//0,F,1,R
  162. {
  163. if(!type)//F
  164. {
  165. if((GET_BIT(data,3) == 1))//1
  166. Gear_position_Set = 1;
  167. if((GET_BIT(data,2) == 1))//2
  168. Gear_position_Set = 2;
  169. if((GET_BIT(data,1) == 1))//3
  170. Gear_position_Set = 3;
  171. if((GET_BIT(data,0) == 1))//4
  172. Gear_position_Set = 4;
  173. }
  174. else//R
  175. {
  176. if((GET_BIT(data,4) == 1))//1
  177. Gear_position_Set = 1;
  178. if((GET_BIT(data,5) == 1))//2
  179. Gear_position_Set = 2;
  180. if((GET_BIT(data,6) == 1))//3
  181. Gear_position_Set = 3;
  182. if((GET_BIT(data,7) == 1))//4
  183. Gear_position_Set = 4;
  184. }
  185. }
  186. void CCanBusSensor::Notify(struct can_frame *date)
  187. {
  188. //std::cout << std::hex << date->can_id << std::endl;
  189. //memcpy(&Sendframe[ii++],date,sizeof(can_frame));
  190. //_canbus->Write(&Sendframe[0]);
  191. if(_run)
  192. {
  193. switch (date->can_id)
  194. {
  195. case 0x8CFF2303:
  196. GetGearCurrent(date->data[0]);//变速箱挡位和FRN
  197. _message->_Feeddata.gearbox_oil_temp = (int32_t)(date->data[4] - 50);//变速箱油温
  198. //std::cout << _message->_Feeddata.gearbox_oil_temp << std::endl;
  199. break;
  200. case 0x98FEEE00:
  201. _message->_Feeddata.cold_water = (int32_t)(date->data[0] -40);//发动机水温
  202. //std::cout << _message->_Feeddata.cold_water << std::endl;
  203. break;
  204. case 0x98FEEF00:
  205. _message->_Feeddata.engine_pressure = (int32_t)(date->data[3] * 4);//发动机压力
  206. //std::cout << _message->_Feeddata.engine_pressure << std::endl;
  207. break;
  208. case 0x8CF00400:
  209. _message->_Feeddata.engine_rpm = make_int16(date->data[4],date->data[3]) / 8 ;//发动机转速
  210. //std::cout << _message->_Feeddata.engine_rpm << std::endl;
  211. count++;
  212. if( _message->btimeStopedCar && _message->_Feeddata.engine_rpm > 700)
  213. printf("----%d-----\r\n",count);
  214. /*count++;
  215. if((count > 10) && _message->btimeStopedCar && _message->_Feeddata.engine_rpm > 700)
  216. {
  217. NoEmergency();
  218. count = 0;
  219. }
  220. else if(count == 1000)
  221. count = 0;
  222. */
  223. break;
  224. case 0x98FEE500:
  225. {
  226. int16_t dh = make_int16(date->data[3],date->data[2]);
  227. int16_t dl = make_int16(date->data[1],date->data[0]);
  228. int32_t ddd = (((dh & 0x0000ffff) << 16) | (dl & 0x0000ffff));
  229. _message->_Feeddata.engine_time = ddd / 20;//发动机运行小时
  230. //std::cout << _message->_Feeddata.engine_time << std::endl;
  231. }
  232. break;
  233. case 0x180 + 0x71:
  234. _message->_Feeddata.brake_pressure = make_int16(date->data[5],date->data[4]);//制动压力(Kpa)
  235. //std::cout << _message->_Feeddata.brake_pressure << std::endl;
  236. break;
  237. case 0x180 + 0x74:
  238. _message->_Feeddata.gearbox_oil_pressure = (int32_t)(date->data[2]);//变速箱油压
  239. //std::cout << _message->_Feeddata.gearbox_oil_pressure << std::endl;
  240. break;
  241. case 0x180 + 0x76://报警信息页面
  242. memcpy(_message->_Feeddata.Error_Buff,date->data,date->can_dlc);
  243. //SendStatusToMSG();
  244. _message->SendVehicleStatue();
  245. break;
  246. case 0x280 + 0x72:
  247. _message->_Feeddata.fuel_level = make_int16(date->data[1],date->data[0]);//燃油油量(%)
  248. //std::cout << _message->_Feeddata.fuel_level << std::endl;
  249. break;
  250. case 0x380 + 0x72:
  251. _message->_Feeddata.lock_switch_l = ((date->data[3] & 0x02) == 0x02) ? 1 : 0;//锁钩到位开关左
  252. _message->_Feeddata.lock_switch_r = ((date->data[3] & 0x04) == 0x04) ? 1 : 0;//锁钩到位开关右
  253. _message->_Feeddata.tip_limit = ((date->data[2] & 0x20) == 0x20) ? 1 : 0;//倾翻限位
  254. //std::cout << _message->_Feeddata.lock_switch_l << " "<< _message->_Feeddata.lock_switch_r << " " << _message->_Feeddata.tip_limit <<std::endl;
  255. break;
  256. case 0x480 + 0x72:
  257. _message->_Feeddata.parking = ((date->data[0] & 0x02) == 0x02) ? 1 : 0;//驻车
  258. _message->_Feeddata.outgrigger_l = ((date->data[0] & 0x04) == 0x04) ? 1 : 0;//左支腿伸到位开关
  259. _message->_Feeddata.outgrigger_r = ((date->data[0] & 0x08) == 0x08) ? 1 : 0;//右支腿伸到位开关
  260. _message->_Feeddata.tip_pressure = ((date->data[0] & 0x20) == 0x20) ? 1 : 0;//倾翻压力开关
  261. _message->_Feeddata.turn_left = ((date->data[4] & 0x01) == 0x01) ? 1 : 0;//左转
  262. _message->_Feeddata.turn_right = ((date->data[4] & 0x02) == 0x02) ? 1 : 0;//右转
  263. //_message->_Feeddata.low_beam = ((date->data[4] & 0x04) == 0x04) ? 1 : 0;//近光灯
  264. //_message->_Feeddata.hight_beam = ((date->data[4] & 0x08) == 0x08) ? 1 : 0;//远光灯
  265. _message->_Feeddata.low_beam = ((date->data[4] & 0x08) == 0x08) ? 1 : 0;//近光灯
  266. _message->_Feeddata.hight_beam = ((date->data[4] & 0x04) == 0x04) ? 1 : 0;//远光灯
  267. _message->_Feeddata.front_work_lamp = ((date->data[4] & 0x10) == 0x10) ? 1 : 0;//前工作灯
  268. _message->_Feeddata.rear_work_lamp = ((date->data[4] & 0x20) == 0x20) ? 1 : 0;//后工作灯
  269. _message->_Feeddata.brake = ((date->data[6] & 0x01) == 0x01) ? 1 : 0;//刹车
  270. _message->_Feeddata.back_car = ((date->data[6] & 0x02) == 0x02) ? 1 : 0;//倒车
  271. _message->_Feeddata.left_lock = ((date->data[7] & 0x01) == 0x01) ? 1 : 0;//遥操模式
  272. _message->_Feeddata.right_lock = ((date->data[7] & 0x02) == 0x02) ? 1 : 0;//人工模式
  273. //printf("%d--%d\r\n",_message->_Feeddata.turn_left ,_message->_Feeddata.turn_right);
  274. //std::cout << _message->_Feeddata.left_lock << " " << _message->_Feeddata.right_lock << std::endl;
  275. break;
  276. case 0x480 + 0x74:
  277. _message->_Feeddata.system_vol = make_int16(date->data[1],date->data[0]);//系统电压
  278. _message->_Feeddata.cargo_weight = make_int16(date->data[3],date->data[2]);//渣包重量
  279. break;
  280. default:
  281. break;
  282. }
  283. }
  284. }
  285. void CCanBusSensor::OnMessage(cannet_busframe* frames, int32_t count)
  286. {
  287. //std::lock_guard<std::mutex> lg(_last_can_lock);
  288. _last_can_uptime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  289. for (int32_t i = 0; i < count; i++)
  290. {
  291. cannet_busframe& frame = frames[i];
  292. int32_t canid = frame.canid;
  293. //printf("%x\r\n",canid);
  294. switch (canid)
  295. {
  296. case 0x181:
  297. Sendframe[0].can_id = 0x186;
  298. Sendframe[0].can_dlc = frame.dlc;
  299. //切换前后摄像头
  300. //_front_view = (Sendframe[0].data[1] & 0x01) == 0x01 ? false: true;
  301. _front_view = (frame.data[1] & 0x01) == 0x01 ? false: true;
  302. //printf("%x\r\n",frame.data[1]);
  303. _message->SwitchCamera(_front_view);
  304. memcpy(Sendframe[0].data, frame.data, frame.dlc);
  305. //_canbus->Write(&Sendframe[0]);
  306. break;
  307. case 0x281:
  308. Sendframe[1].can_id = 0x286;
  309. Sendframe[1].can_dlc = frame.dlc;
  310. halfautomatic = (frame.data[1] & 0x20) == 0x20 ? false: true;//0手动,1自动
  311. if((frame.data[1] & 0x0f) != 0)//N档
  312. {
  313. if(halfautomatic)
  314. {
  315. Sendframe[1].data[0] = 0x00;
  316. Gear_position_Set = 1;
  317. }
  318. else
  319. Sendframe[1].data[0] = 0x10;
  320. }
  321. else
  322. {
  323. if((frame.data[0] & 0x0f) != 0)//F档
  324. {
  325. SetGear_FR_Current(frame.data[0],0);
  326. if(Gear_position_now != Gear_position_Set)
  327. {
  328. if(Gear_position_now < Gear_position_Set)//up
  329. {
  330. if(halfautomatic)
  331. Sendframe[1].data[0] = 0x05;
  332. else
  333. Sendframe[1].data[0] = 0x15;
  334. }
  335. else//down
  336. {
  337. if(halfautomatic)
  338. Sendframe[1].data[0] = 0x09;
  339. else
  340. Sendframe[1].data[0] = 0x19;
  341. }
  342. }
  343. else
  344. {
  345. if(halfautomatic)
  346. Sendframe[1].data[0] = 0x01;
  347. else
  348. Sendframe[1].data[0] = 0x11;
  349. }
  350. }
  351. if(((frame.data[0] & 0xf0) >> 4) != 0)//R档
  352. {
  353. SetGear_FR_Current(frame.data[0],1);
  354. if(Gear_position_now != Gear_position_Set)
  355. {
  356. if(Gear_position_now < Gear_position_Set)//up
  357. {
  358. if(halfautomatic)
  359. Sendframe[1].data[0] = 0x06;
  360. else
  361. Sendframe[1].data[0] = 0x16;
  362. }
  363. else//down
  364. {
  365. if(halfautomatic)
  366. Sendframe[1].data[0] = 0x0A;
  367. else
  368. Sendframe[1].data[0] = 0x1A;
  369. }
  370. }
  371. else
  372. {
  373. if(halfautomatic)
  374. Sendframe[1].data[0] = 0x02;
  375. else
  376. Sendframe[1].data[0] = 0x12;
  377. }
  378. }
  379. }
  380. if(((unsigned char)frame.data[7] == (unsigned char)0xff) && !_message->btimeStopedCar)
  381. {
  382. Emergency();
  383. std::cout<< "现在是急停"<<((unsigned char)frame.data[7] == (unsigned char)0xff)<<std::endl;
  384. }
  385. else if((frame.data[7] == 0x00) && _message->btimeStopedCar)
  386. {
  387. NoEmergency();
  388. std::cout<< "没有急停"<<((frame.data[7] == 0x00))<<std::endl;
  389. }
  390. /*
  391. if(!_message->btimeStopedCar && halfautomatic)
  392. {
  393. memcpy(Sendframe[1].data + 1, frame.data + 1, frame.dlc - 1);
  394. }
  395. else if(!_message->btimeStopedCar && !halfautomatic)
  396. {
  397. memcpy(Sendframe[1].data, frame.data, frame.dlc);
  398. }
  399. */
  400. if(!_message->btimeStopedCar)
  401. {
  402. memcpy(Sendframe[1].data + 1, frame.data + 1, frame.dlc - 1);
  403. }
  404. else
  405. {
  406. /*
  407. long long tick=std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  408. if(tick-_message->_curStopTick > 100)
  409. {
  410. _message->btimeStopedCar = false;
  411. NoEmergency();
  412. }
  413. else
  414. Emergency();*/
  415. }
  416. //_canbus->Write(&Sendframe[1]);
  417. break;
  418. case 0x381:
  419. Sendframe[2].can_id = 0x386;
  420. Sendframe[2].can_dlc = frame.dlc;
  421. memcpy(Sendframe[2].data, frame.data, frame.dlc);
  422. //_canbus->Write(&Sendframe[2]);
  423. break;
  424. case 0x481:
  425. Sendframe[3].can_id = 0x486;
  426. Sendframe[3].can_dlc = frame.dlc;
  427. memcpy(Sendframe[3].data, frame.data, frame.dlc);
  428. //_canbus->Write(&Sendframe[3]);
  429. break;
  430. case 0x1A0:
  431. //Sendframe[4].can_id = 0x306;
  432. //Sendframe[4].can_dlc = frame.dlc;
  433. //memcpy(Sendframe[4].data, frame.data, frame.dlc);
  434. _message->Senddirection(make_int16(frame.data[2],frame.data[3]));
  435. /*
  436. GL_CANTxData.Data[0]:=16#FF;
  437. GL_CANTxData.Data[1]:=16#00;
  438. GL_CANTxData.Data[2]:=FB_EXTRACT_B(HZ_remote, 1);
  439. GL_CANTxData.Data[3]:=FB_EXTRACT_B(HZ_remote, 0);
  440. GL_CANTxData.Data[4]:=FB_PACK(Turn_left_Remote,Emoto_TX_Remote,0,0,0,0,0,0);
  441. GL_CANTxData.Data[5]:=16#00;
  442. GL_CANTxData.Data[6]:=16#67;
  443. GL_CANTxData.Data[7]:=16#18;
  444. */
  445. break;
  446. }
  447. }
  448. }
  449. void CCanBusSensor::SendStatusToMSG()
  450. {
  451. RemoNet::State req;
  452. req.set_work_pressure(_message->_Feeddata.work_pressure);
  453. req.set_brake_pressure(_message->_Feeddata.brake_pressure);
  454. req.set_gearbox_oil_temp(_message->_Feeddata.gearbox_oil_temp);
  455. req.set_gearbox_oil_pressure(_message->_Feeddata.gearbox_oil_pressure);
  456. req.set_engine_rpm(_message->_Feeddata.engine_rpm);//发动机转速
  457. req.set_speed(_message->_Feeddata.speed);//不知道?---可能是后加的传感器---驱动轮增量编码器
  458. req.set_gear(_message->_Feeddata.gear);
  459. req.set_engine_pressure(_message->_Feeddata.engine_pressure);//发动机压力
  460. req.set_cold_water(_message->_Feeddata.cold_water);//冷却液温度-发动机水温
  461. req.set_steer_angle(_message->_Feeddata.steer_angle);//转向角度(原来金川是轮子的现在大冶用铰链位置) 铰接转向姿态编码器
  462. req.set_left_lock(_message->_Feeddata.left_lock);//遥操模式
  463. req.set_right_lock(_message->_Feeddata.right_lock);//人工模式
  464. req.set_engine_time(_message->_Feeddata.engine_time);//发动机运行小时
  465. req.set_wire_sensor_l(_message->_Feeddata.wire_sensor_l);//拉线传感器左侧
  466. req.set_wire_sensor_r(_message->_Feeddata.wire_sensor_r);//拉线传感器右侧
  467. req.set_fuel_level(_message->_Feeddata.fuel_level);//燃油油位
  468. req.set_lock_switch_l(_message->_Feeddata.lock_switch_l);//锁钩到位开关左
  469. req.set_lock_switch_r(_message->_Feeddata.lock_switch_r); //锁钩到位开关右
  470. req.set_tip_limit(_message->_Feeddata.tip_limit);//倾翻限位
  471. req.set_turn_left(_message->_Feeddata.turn_left);//左转
  472. req.set_turn_right(_message->_Feeddata.turn_right);//右转
  473. req.set_hight_beam(_message->_Feeddata.hight_beam);//远光灯
  474. req.set_low_beam(_message->_Feeddata.low_beam);//近光灯
  475. req.set_parking(_message->_Feeddata.parking);//驻车
  476. req.set_brake(_message->_Feeddata.brake);//刹车
  477. req.set_back_car(_message->_Feeddata.back_car);//倒车
  478. req.set_front_work_lamp(_message->_Feeddata.front_work_lamp);//前工作灯
  479. req.set_rear_work_lamp(_message->_Feeddata.rear_work_lamp);//后工作灯
  480. req.set_cargo_weight(_message->_Feeddata.cargo_weight);//渣包重量
  481. req.set_system_vol(_message->_Feeddata.system_vol);//系统电压
  482. req.set_error_buff((char *)_message->_Feeddata.Error_Buff,8);//报警信息
  483. req.set_f_gear(_message->_Feeddata.f_gear);//1F,2R,3N
  484. req.set_gear_1(_message->_Feeddata.gear_1);//1,2,3,4
  485. req.set_outgrigger_l(_message->_Feeddata.outgrigger_l);//左支腿伸到位开关
  486. req.set_outgrigger_r(_message->_Feeddata.outgrigger_r);//右支腿伸到位开关
  487. req.set_tip_pressure(_message->_Feeddata.tip_pressure);//倾翻压力开关
  488. MessageHead Head;
  489. CIOBuffer pBuffer;
  490. Head.Command = RemoNet::CC_STATE;
  491. Head.Length = req.ByteSizeLong();
  492. Head.Serialize(pBuffer.Buffer);
  493. auto ptr = pBuffer.Buffer + MessageHead::Size();
  494. req.SerializeToArray(ptr, Head.Length);
  495. pBuffer.Length = MessageHead::Size() + Head.Length;
  496. _message->WritePacket(ChannelType::CHANNEL_CAR, pBuffer);
  497. }
  498. void CCanBusSensor::Emergency()
  499. {
  500. /*
  501. Sendframe[1].can_id = 0x286;
  502. Sendframe[1].can_dlc = 8;
  503. Sendframe[1].data[7] = 0xFF;
  504. //_canbus->Write(&Sendframe[3]);
  505. */
  506. //std::cout << "stop" << std::endl;
  507. _message->btimeStopedCar = true;
  508. //_message->_curStopTick = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  509. _message->SendEmergency();
  510. }
  511. void CCanBusSensor::NoEmergency()
  512. {
  513. /*
  514. Sendframe[1].can_id = 0x286;
  515. Sendframe[1].can_dlc = 8;
  516. Sendframe[1].data[7] = 0xFF;
  517. //_canbus->Write(&Sendframe[3]);
  518. */
  519. //std::cout << "start" << std::endl;
  520. _message->btimeStopedCar = false;
  521. _message->SendNoEmergency();
  522. }