|
@@ -1,5 +1,4 @@
|
|
|
#include "can_bus.h"
|
|
|
-#include "vehicle.h"
|
|
|
#include <thread>
|
|
|
#include "message_queue.h"
|
|
|
#include <math.h>
|
|
@@ -216,7 +215,104 @@ void CCanBusSensor::Notify(struct can_frame *date)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void CCanBusSensor::order(cannet_frame* frames){
|
|
|
+
|
|
|
+ cannet_frame& frame = frames[0];
|
|
|
+ Sendframe[0].can_id = 0x421;
|
|
|
+ Sendframe[0].can_dlc = frame.dlc;
|
|
|
+
|
|
|
+ memcpy(Sendframe[0].data,order_on,frame.dlc);
|
|
|
+ order_flag = true;
|
|
|
+
|
|
|
+ if(!order_flag){
|
|
|
+ cout<<"order_flag: false"<<endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void CCanBusSensor::toggleLamp(cannet_frame* frames){
|
|
|
+
|
|
|
+ cannet_frame& frame = frames[0];
|
|
|
+ Sendframe[0].can_id = 0x121;
|
|
|
+ Sendframe[0].can_dlc = frame.dlc;
|
|
|
+
|
|
|
+ switch (frame.data[0])
|
|
|
+ {
|
|
|
+ case 0x00:
|
|
|
+ memcpy(Sendframe[0].data,headlamp_off,frame.dlc);
|
|
|
+ std::cout<<"前车灯关,后车灯关 "<<std::endl;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x10:
|
|
|
+ memcpy(Sendframe[0].data,headlamp_on,frame.dlc);
|
|
|
+ std::cout<<"前车灯开,后车灯关 "<<std::endl;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 0x08:
|
|
|
+ memcpy(Sendframe[0].data,taillamp_on,frame.dlc);
|
|
|
+ std::cout<<"前车灯关,后车灯开 "<<std::endl;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CCanBusSensor::car_stop(cannet_frame* frames){
|
|
|
+
|
|
|
+ cannet_frame& frame = frames[0];
|
|
|
+ Sendframe[0].can_id = 0x111;
|
|
|
+ Sendframe[0].can_dlc = frame.dlc;
|
|
|
+
|
|
|
+ if(frame.data[2]==0x00){
|
|
|
+ memcpy(Sendframe[0].data,stop,frame.dlc);
|
|
|
+
|
|
|
+ stop_flag = true;
|
|
|
+ if(stop_flag){
|
|
|
+ std::cout<<"stop_flag: true"<<std::endl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void CCanBusSensor::move_run(cannet_frame* frames){
|
|
|
+
|
|
|
+ cannet_frame& frame = frames[0];
|
|
|
+ int32_t canid = frame.canid;
|
|
|
+
|
|
|
+ Sendframe[0].can_id = 0x111;
|
|
|
+ Sendframe[0].can_dlc = frame.dlc;
|
|
|
+
|
|
|
+ if(frame.data[4]>0x02 && frame.data[4]<=0x7F){
|
|
|
+ Sendframe[0].data = move_forward;
|
|
|
+ run_flag = true;
|
|
|
+ }
|
|
|
+ else if(frame.data[5]>0x02 && frame.data[5]<=0x7F){
|
|
|
+ memcpy(Sendframe[0].data,stop,frame.dlc);
|
|
|
+ run_flag = true;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void CCanBusSensor::move_rot(cannet_frame* frames){
|
|
|
+
|
|
|
+ cannet_frame& frame = frames[0];
|
|
|
+ int32_t canid = frame.canid;
|
|
|
+
|
|
|
+ Sendframe[1].can_id = 0x111;
|
|
|
+ Sendframe[1].can_dlc = frame.dlc;
|
|
|
+
|
|
|
+ if(frame.data[0] != 0x01){
|
|
|
+ memcpy(Sendframe[0].data,move_rotation,frame.dlc);
|
|
|
+ rot_flag = true;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
void CCanBusSensor::OnMessage(cannet_frame* frames, int32_t count)
|
|
|
{
|
|
@@ -232,26 +328,80 @@ void CCanBusSensor::OnMessage(cannet_frame* frames, int32_t count)
|
|
|
switch (canid)
|
|
|
{
|
|
|
case 0x181:
|
|
|
- Sendframe[0].can_id = 0x121;
|
|
|
+
|
|
|
Sendframe[0].can_dlc = frame.dlc;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ CCanBusSensor::order(&frame);
|
|
|
+ CCanBusSensor::toggleLamp(&frame);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- memcpy(Sendframe[0].data,order_on,sizeof(order_on));
|
|
|
- memcpy(Sendframe[0].data,headlamp_on,sizeof(headlamp_on));
|
|
|
|
|
|
- if(frame.data[0]==0x10)
|
|
|
- memcpy(Sendframe[0].data,headlamp_on,sizeof(headlamp_on));
|
|
|
- else
|
|
|
- memcpy(Sendframe[0].data,headlamp_off,sizeof(headlamp_off));
|
|
|
|
|
|
-
|
|
|
break;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
case 0x182:
|
|
|
Sendframe[1].can_id = 0x182;
|
|
|
Sendframe[1].can_dlc = frame.dlc;
|