|
@@ -1,9 +1,8 @@
|
|
#include "can_bus.h"
|
|
#include "can_bus.h"
|
|
#include <thread>
|
|
#include <thread>
|
|
#include "message_queue.h"
|
|
#include "message_queue.h"
|
|
-#include <math.h>
|
|
+
|
|
-#include <chrono>
|
|
+
|
|
-#include <algorithm>
|
|
|
|
|
|
|
|
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
|
|
#define GET_BIT(x, bit) ((x & (1 << bit)) >> bit)
|
|
|
|
|
|
@@ -226,89 +225,114 @@ void CCanBusSensor::order(cannet_frame* frame){
|
|
Sendframe[0].can_id = 0x421;
|
|
Sendframe[0].can_id = 0x421;
|
|
Sendframe[0].can_dlc = carframe.dlc;
|
|
Sendframe[0].can_dlc = carframe.dlc;
|
|
|
|
|
|
-
|
|
+ memcpy(Sendframe[0].data,order_on,carframe.dlc);
|
|
- std::copy(order_on,order_on+8,Sendframe[0].data);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+bool CCanBusSensor::car_stop(cannet_frame* frame){
|
|
|
|
+
|
|
|
|
+ cannet_frame& carframe = frame[0];
|
|
|
|
+
|
|
|
|
+ switch (carframe.data[2])
|
|
|
|
+ {
|
|
|
|
+ case 0x00:
|
|
|
|
+ *id_111 = *car_stop;
|
|
|
|
+ stop_flag = true;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ stop_flag = false;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return stop_flag;
|
|
|
|
+}
|
|
|
|
|
|
void CCanBusSensor::toggleLamp(cannet_frame* frame){
|
|
void CCanBusSensor::toggleLamp(cannet_frame* frame){
|
|
|
|
|
|
cannet_frame& carframe = frame[0];
|
|
cannet_frame& carframe = frame[0];
|
|
- Sendframe[1].can_id = 0x121;
|
|
+ Sendframe[2].can_id = 0x121;
|
|
- Sendframe[1].can_dlc = carframe.dlc;
|
|
+ Sendframe[2].can_dlc = carframe.dlc;
|
|
|
|
|
|
switch (carframe.data[0])
|
|
switch (carframe.data[0])
|
|
{
|
|
{
|
|
case 0x00:
|
|
case 0x00:
|
|
-
|
|
+ memcpy(Sendframe[2].data,headlamp_off,carframe.dlc);
|
|
- std::copy(headlamp_off,headlamp_off+8,Sendframe[1].data);
|
|
+
|
|
- std::cout<<"前车灯关,后车灯关 "<<std::endl;
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
case 0x10:
|
|
case 0x10:
|
|
-
|
|
+ memcpy(Sendframe[2].data,headlamp_on,carframe.dlc);
|
|
- std::copy(headlamp_on,headlamp_on+8,Sendframe[1].data);
|
|
+
|
|
- std::cout<<"前车灯开,后车灯关 "<<std::endl;
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
case 0x08:
|
|
case 0x08:
|
|
-
|
|
+ memcpy(Sendframe[2].data,taillamp_on,carframe.dlc);
|
|
- std::copy(taillamp_on,taillamp_on+8,Sendframe[1].data);
|
|
+
|
|
- std::cout<<"前车灯关,后车灯开 "<<std::endl;
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void CCanBusSensor::car_stop(cannet_frame* frame){
|
|
|
|
|
|
|
|
- cannet_frame& carframe = frame[0];
|
|
+int CCanBusSensor::gearselection(cannet_frame* frame){
|
|
- bool stop_flag = false;
|
|
+
|
|
|
|
+ cannet_frame& carframe = frame[0];
|
|
|
|
+ switch (carframe.data[5])
|
|
|
|
+ {
|
|
|
|
+ case 0x10:
|
|
|
|
+ return 1;
|
|
|
|
+ break;
|
|
|
|
|
|
- switch (carframe.data[2])
|
|
+ case 0x00:
|
|
- {
|
|
+ return 2;
|
|
- case 0x00:
|
|
+ break;
|
|
- Sendframe[2].can_id = 0x111;
|
|
+
|
|
- Sendframe[2].can_dlc = carframe.dlc;
|
|
+ case 0x40:
|
|
- stop_flag = true;
|
|
+ return 3;
|
|
- while(stop_flag){
|
|
+ break;
|
|
- memcpy(Sendframe[2].data,stop_on,carframe.dlc);
|
|
+ }
|
|
- std::cout<<"car stop!"<<std::endl;
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 0xFF:
|
|
|
|
- stop_flag = false;
|
|
|
|
- std::cout<<"car end stop..."<<std::endl;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void CCanBusSensor::gear_act(int gear){
|
|
|
|
+
|
|
|
|
+ switch (gear)
|
|
|
|
+ {
|
|
|
|
+ case 1:
|
|
|
|
+ id_633[0] =
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
|
|
void CCanBusSensor::move_run(cannet_frame* frame){
|
|
void CCanBusSensor::move_run(cannet_frame* frame){
|
|
|
|
|
|
cannet_frame& carframe = frame[0];
|
|
cannet_frame& carframe = frame[0];
|
|
|
|
|
|
-
|
|
+ switch (gearselection)
|
|
-
|
|
+ if(carframe.data[4]>0x02 && carframe.data[4]<=0x7F)
|
|
- if (static_cast<unsigned char>(carframe.data[4]) > 0x02 &&
|
|
|
|
- static_cast<unsigned char>(carframe.data[4]) <= 0x7F)
|
|
|
|
-
|
|
|
|
{
|
|
{
|
|
- Sendframe[3].can_id = 0x111;
|
|
+
|
|
- std::copy(move_forward,move_forward+8,Sendframe[3].data);
|
|
+
|
|
|
|
+
|
|
|
|
+ id_111[0] = 0x00;
|
|
|
|
+ id_111[1] = 0x96;
|
|
|
|
+
|
|
run_flag = true;
|
|
run_flag = true;
|
|
std::cout<<"油门前进"<<std::endl;
|
|
std::cout<<"油门前进"<<std::endl;
|
|
}
|
|
}
|
|
- else
|
|
+ else if(carframe.data[5]>0x02 && carframe.data[5]<=0x7F)
|
|
-
|
|
|
|
- if (static_cast<unsigned char>(carframe.data[5]) > 0x02 &&
|
|
|
|
- static_cast<unsigned char>(carframe.data[5]) <= 0x7F)
|
|
|
|
{
|
|
{
|
|
- Sendframe[4].can_id = 0x111;
|
|
+
|
|
- std::copy(move_backward,move_backward+8,Sendframe[4].data);
|
|
+
|
|
|
|
+
|
|
|
|
+ id_111[0] = 0x00;
|
|
|
|
+ id_111[1] = 0x00;
|
|
|
|
+
|
|
run_flag = true;
|
|
run_flag = true;
|
|
std::cout<<"刹车后退"<<std::endl;
|
|
std::cout<<"刹车后退"<<std::endl;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ else { id_111[0] = 0x00; id_111[1] = 0x00; }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -316,13 +340,34 @@ void CCanBusSensor::move_rot(cannet_frame* frame){
|
|
|
|
|
|
cannet_frame& carframe = frame[0];
|
|
cannet_frame& carframe = frame[0];
|
|
|
|
|
|
- Sendframe[5].can_id = 0x111;
|
|
+ switch(carframe.data[0])
|
|
- Sendframe[5].can_dlc = carframe.dlc;
|
|
+ {
|
|
|
|
+ case 0x01:
|
|
|
|
+
|
|
|
|
+ id_111[2] = 0x00;
|
|
|
|
+ id_111[3] = 0x00;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 0x04:
|
|
|
|
+
|
|
|
|
+ id_111[2] = 0x00;
|
|
|
|
+ id_111[3] = 0xc8;
|
|
|
|
+
|
|
|
|
+ rot_flag = true;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 0x10:
|
|
|
|
+
|
|
|
|
+ id_111[2] = 0xFF;
|
|
|
|
+ id_111[3] = 0x38;
|
|
|
|
+
|
|
|
|
+ rot_flag = true;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
|
|
- if(carframe.data[0] != 0x01){
|
|
|
|
- memcpy(Sendframe[5].data,move_rotation,carframe.dlc);
|
|
|
|
- rot_flag = true;
|
|
|
|
- cout<<"转弯"<<endl;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -330,115 +375,64 @@ void CCanBusSensor::move_rot(cannet_frame* frame){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
+
|
|
|
|
|
|
void CCanBusSensor::OnMessage(cannet_frame* frames, int32_t count)
|
|
void CCanBusSensor::OnMessage(cannet_frame* frames, int32_t count)
|
|
{
|
|
{
|
|
|
|
|
|
- for (int32_t i = 0; i < count; i++)
|
|
+ for (int32_t i = count; i > 0; i--)
|
|
{
|
|
{
|
|
cannet_frame& frame = frames[i];
|
|
cannet_frame& frame = frames[i];
|
|
|
|
|
|
int32_t canid = frame.canid;
|
|
int32_t canid = frame.canid;
|
|
|
|
|
|
|
|
|
|
-
|
|
+ CCanBusSensor::order(&frame);
|
|
switch (canid)
|
|
switch (canid)
|
|
{
|
|
{
|
|
case 0x181:
|
|
case 0x181:
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
+
|
|
CCanBusSensor::toggleLamp(&frame);
|
|
CCanBusSensor::toggleLamp(&frame);
|
|
- CCanBusSensor::order(&frame);
|
|
+ if(!CCanBusSensor::car_stop(&frame))
|
|
-
|
|
+ {
|
|
- CCanBusSensor::car_stop(&frame);
|
|
+
|
|
-
|
|
+ CCanBusSensor::move_run(&frame);
|
|
|
|
+ }
|
|
|
|
+
|
|
break;
|
|
break;
|
|
|
|
|
|
case 0x0CFDD633:
|
|
case 0x0CFDD633:
|
|
-
|
|
|
|
- CCanBusSensor::order(&frame);
|
|
|
|
- CCanBusSensor::move_rot(&frame);
|
|
|
|
-
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 0x182:
|
|
|
|
- Sendframe[1].can_id = 0x182;
|
|
|
|
- Sendframe[1].can_dlc = frame.dlc;
|
|
|
|
-
|
|
|
|
- memcpy(Sendframe[1].data, frame.data, frame.dlc);
|
|
|
|
-
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 0x183:
|
|
|
|
- Sendframe[2].can_id = 0x183;
|
|
|
|
- Sendframe[2].can_dlc = frame.dlc;
|
|
|
|
-
|
|
|
|
- Direction = make_int16(frame.data[3],frame.data[2]);
|
|
|
|
- _message->SendVehicleStatus(Direction,Hand_Throttle,Foot_Throttle,Brake);
|
|
|
|
-
|
|
|
|
- memcpy(Sendframe[2].data, frame.data, frame.dlc);
|
|
|
|
-
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- case 0x184:
|
|
|
|
|
|
|
|
- Sendframe[3].can_id = 0x184;
|
|
+ if(!CCanBusSensor::car_stop(&frame))
|
|
- Sendframe[3].can_dlc = frame.dlc;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- model = (frame.data[3] & 0x04) == 0x04 ? 1 : 0;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- _front_view = (frame.data[4] & 0x04) == 0x04 ? false: true;
|
|
|
|
- _message->SwitchCamera(_front_view);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if((frame.data[4] & 0x10) == 0x10 ? 1 : 0)
|
|
|
|
{
|
|
{
|
|
- _message->SendZGJStatus(1);
|
|
+
|
|
- std::cout << "SendZGJStatus" << std::endl;
|
|
+ int gear = CCanBusSensor::gearselection(&frame);
|
|
-
|
|
+ CCanBusSensor::gear_act(gear);
|
|
|
|
+ CCanBusSensor::move_rot(&frame);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
|
|
-
|
|
+ break;
|
|
- if((frame.data[4] & 0x20) == 0x20 ? 1 : 0)
|
|
|
|
- {
|
|
|
|
- _message->SendZGJStatus(2);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if(!_message->btimeStopedCar)
|
|
+
|
|
- {
|
|
+ default:
|
|
- memcpy(Sendframe[3].data, frame.data, frame.dlc);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- long long tick=std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
|
|
-
|
|
|
|
- if(tick-_message->_curStopTick > 500)
|
|
|
|
- {
|
|
|
|
- Emergency();
|
|
|
|
- _message->btimeStopedCar = false;
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
- if(tick-_message->_curStopTick < 500)
|
|
|
|
- Emergency();
|
|
|
|
- else
|
|
|
|
- _message->btimeStopedCar = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ Sendframe[3].can_id = 0x111;
|
|
|
|
+ Sendframe[3].can_dlc = frame.dlc;
|
|
|
|
+ memcpy(Sendframe[3].data,id_111,frame.dlc);
|
|
|
|
+ cout<<"id_111: "<<static_cast<int>(id_111[0])<<static_cast<int>(id_111[1])<<static_cast<int>(id_111[2])<<static_cast<int>(id_111[3])<<endl;
|
|
}
|
|
}
|
|
|
|
|
|
void CCanBusSensor::SendStatusToMSG()
|
|
void CCanBusSensor::SendStatusToMSG()
|