|
@@ -0,0 +1,202 @@
|
|
|
+#include "cansend_producer.h"
|
|
|
+
|
|
|
+#include "math.h"
|
|
|
+
|
|
|
+#include "decode_cfg.h"
|
|
|
+extern setupConfig_t setupConfig;
|
|
|
+
|
|
|
+extern uint8_t chassisShift;
|
|
|
+extern double chassisVelocity;
|
|
|
+extern QMutex chassisDataLock;
|
|
|
+
|
|
|
+extern double GPSIMUVelocity; // m/s
|
|
|
+extern double GPSIMUYawRate; // deg/s
|
|
|
+extern QMutex GPSIMUDataLock;
|
|
|
+
|
|
|
+CANSend_Producer::CANSend_Producer(CAN_Producer_Consumer *pBuf)
|
|
|
+{
|
|
|
+ pBuffer = pBuf;
|
|
|
+}
|
|
|
+
|
|
|
+CANSend_Producer::~CANSend_Producer()
|
|
|
+{
|
|
|
+ requestInterruption();
|
|
|
+ while(this->isFinished() == false);
|
|
|
+}
|
|
|
+
|
|
|
+uint32_t CANSend_Producer::Trans_to_CANRaw(iv::can::canraw &xraw)
|
|
|
+{
|
|
|
+ xraw.set_id(CAN_ID);
|
|
|
+ xraw.set_bext(CAN_IDE);
|
|
|
+ xraw.set_bremote(CAN_RTR);
|
|
|
+ xraw.set_len(CAN_DLC);
|
|
|
+ xraw.set_data(CAN_data,CAN_DLC);
|
|
|
+ xraw.set_rectime(QDateTime::currentMSecsSinceEpoch());
|
|
|
+}
|
|
|
+
|
|
|
+void CANSend_Producer::run()
|
|
|
+{
|
|
|
+ QTime xTime;
|
|
|
+ xTime.start();
|
|
|
+
|
|
|
+ SpeedInformation_ch0_t SpeedInformation_ch0;
|
|
|
+ YawRateInformation_ch0_t YawRateInformation_ch0;
|
|
|
+
|
|
|
+ SpeedInformation_ch1_t SpeedInformation_ch1;
|
|
|
+ YawRateInformation_ch1_t YawRateInformation_ch1;
|
|
|
+
|
|
|
+ SpeedInformation_ch2_t SpeedInformation_ch2;
|
|
|
+ YawRateInformation_ch2_t YawRateInformation_ch2;
|
|
|
+
|
|
|
+ SpeedInformation_ch3_t SpeedInformation_ch3;
|
|
|
+ YawRateInformation_ch3_t YawRateInformation_ch3;
|
|
|
+
|
|
|
+ SpeedInformation_ch4_t SpeedInformation_ch4;
|
|
|
+ YawRateInformation_ch4_t YawRateInformation_ch4;
|
|
|
+
|
|
|
+ SpeedInformation_ch5_t SpeedInformation_ch5;
|
|
|
+ YawRateInformation_ch5_t YawRateInformation_ch5;
|
|
|
+
|
|
|
+ SpeedInformation_ch6_t SpeedInformation_ch6;
|
|
|
+ YawRateInformation_ch6_t YawRateInformation_ch6;
|
|
|
+
|
|
|
+ SpeedInformation_ch7_t SpeedInformation_ch7;
|
|
|
+ YawRateInformation_ch7_t YawRateInformation_ch7;
|
|
|
+
|
|
|
+ iv::can::canraw xraw;
|
|
|
+
|
|
|
+ int lastTime = xTime.elapsed();
|
|
|
+ uint64_t interval = 20; //interval time should more than 10 ms
|
|
|
+
|
|
|
+ while (!QThread::isInterruptionRequested())
|
|
|
+ {
|
|
|
+ if(abs(xTime.elapsed() - lastTime)>=interval)
|
|
|
+ {
|
|
|
+ //update timer
|
|
|
+ lastTime = xTime.elapsed();
|
|
|
+
|
|
|
+ chassisDataLock.lock();
|
|
|
+ chasShift = chassisShift; //1P 2R 3N 4D
|
|
|
+ chasVelocity = chassisVelocity;
|
|
|
+ chassisDataLock.unlock();
|
|
|
+
|
|
|
+ GPSIMUDataLock.lock();
|
|
|
+ gpsVelocity = GPSIMUVelocity;
|
|
|
+ gpsYawRate = GPSIMUYawRate;
|
|
|
+ GPSIMUDataLock.unlock();
|
|
|
+
|
|
|
+ if(chasShift == 4)
|
|
|
+ speedDirection = 1; //0 stand 1 forward 2 reverse 3 reserved
|
|
|
+ else if(chasShift == 2)
|
|
|
+ speedDirection = 2;
|
|
|
+ else
|
|
|
+ speedDirection = 0;
|
|
|
+
|
|
|
+ if(fabs(chasVelocity - gpsVelocity) > 1.5)
|
|
|
+ speedFinal = gpsVelocity;
|
|
|
+ else
|
|
|
+ speedFinal = chasVelocity;
|
|
|
+
|
|
|
+ switch (setupConfig.radarID) {
|
|
|
+ case 0:
|
|
|
+ SpeedInformation_ch0.RadarDevice_SpeedDirection = speedDirection;
|
|
|
+ SpeedInformation_ch0.RadarDevice_Speed_phys = speedFinal;
|
|
|
+ CAN_ID = Pack_SpeedInformation_ch0_ARS408_can_database_ch0(&SpeedInformation_ch0,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+
|
|
|
+ YawRateInformation_ch0.RadarDevice_YawRate_phys = gpsYawRate;
|
|
|
+ CAN_ID = Pack_YawRateInformation_ch0_ARS408_can_database_ch0(&YawRateInformation_ch0,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ SpeedInformation_ch1.RadarDevice_SpeedDirection = speedDirection;
|
|
|
+ SpeedInformation_ch1.RadarDevice_Speed_phys = speedFinal;
|
|
|
+ CAN_ID = Pack_SpeedInformation_ch1_ARS408_can_database_ch1(&SpeedInformation_ch1,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+
|
|
|
+ YawRateInformation_ch1.RadarDevice_YawRate_phys = gpsYawRate;
|
|
|
+ CAN_ID = Pack_YawRateInformation_ch1_ARS408_can_database_ch1(&YawRateInformation_ch1,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ SpeedInformation_ch2.RadarDevice_SpeedDirection = speedDirection;
|
|
|
+ SpeedInformation_ch2.RadarDevice_Speed_phys = speedFinal;
|
|
|
+ CAN_ID = Pack_SpeedInformation_ch2_ARS408_can_database_ch2(&SpeedInformation_ch2,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+
|
|
|
+ YawRateInformation_ch2.RadarDevice_YawRate_phys = gpsYawRate;
|
|
|
+ CAN_ID = Pack_YawRateInformation_ch2_ARS408_can_database_ch2(&YawRateInformation_ch2,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ SpeedInformation_ch3.RadarDevice_SpeedDirection = speedDirection;
|
|
|
+ SpeedInformation_ch3.RadarDevice_Speed_phys = speedFinal;
|
|
|
+ CAN_ID = Pack_SpeedInformation_ch3_ARS408_can_database_ch3(&SpeedInformation_ch3,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+
|
|
|
+ YawRateInformation_ch3.RadarDevice_YawRate_phys = gpsYawRate;
|
|
|
+ CAN_ID = Pack_YawRateInformation_ch3_ARS408_can_database_ch3(&YawRateInformation_ch3,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ SpeedInformation_ch4.RadarDevice_SpeedDirection = speedDirection;
|
|
|
+ SpeedInformation_ch4.RadarDevice_Speed_phys = speedFinal;
|
|
|
+ CAN_ID = Pack_SpeedInformation_ch4_ARS408_can_database_ch4(&SpeedInformation_ch4,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+
|
|
|
+ YawRateInformation_ch4.RadarDevice_YawRate_phys = gpsYawRate;
|
|
|
+ CAN_ID = Pack_YawRateInformation_ch4_ARS408_can_database_ch4(&YawRateInformation_ch4,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ SpeedInformation_ch5.RadarDevice_SpeedDirection = speedDirection;
|
|
|
+ SpeedInformation_ch5.RadarDevice_Speed_phys = speedFinal;
|
|
|
+ CAN_ID = Pack_SpeedInformation_ch5_ARS408_can_database_ch5(&SpeedInformation_ch5,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+
|
|
|
+ YawRateInformation_ch5.RadarDevice_YawRate_phys = gpsYawRate;
|
|
|
+ CAN_ID = Pack_YawRateInformation_ch5_ARS408_can_database_ch5(&YawRateInformation_ch5,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ SpeedInformation_ch6.RadarDevice_SpeedDirection = speedDirection;
|
|
|
+ SpeedInformation_ch6.RadarDevice_Speed_phys = speedFinal;
|
|
|
+ CAN_ID = Pack_SpeedInformation_ch6_ARS408_can_database_ch6(&SpeedInformation_ch6,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+
|
|
|
+ YawRateInformation_ch6.RadarDevice_YawRate_phys = gpsYawRate;
|
|
|
+ CAN_ID = Pack_YawRateInformation_ch6_ARS408_can_database_ch6(&YawRateInformation_ch6,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ SpeedInformation_ch7.RadarDevice_SpeedDirection = speedDirection;
|
|
|
+ SpeedInformation_ch7.RadarDevice_Speed_phys = speedFinal;
|
|
|
+ CAN_ID = Pack_SpeedInformation_ch7_ARS408_can_database_ch7(&SpeedInformation_ch7,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+
|
|
|
+ YawRateInformation_ch7.RadarDevice_YawRate_phys = gpsYawRate;
|
|
|
+ CAN_ID = Pack_YawRateInformation_ch7_ARS408_can_database_ch7(&YawRateInformation_ch7,CAN_data,&CAN_DLC,&CAN_IDE);
|
|
|
+ this->Trans_to_CANRaw(xraw);
|
|
|
+ pBuffer->Produce_Element(xraw);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|