|
@@ -4,6 +4,7 @@
|
|
|
|
|
|
extern setupConfig_t setupConfig;
|
|
|
extern iv::msgunit shmSonar;
|
|
|
+extern uint64_t gTime_ms;
|
|
|
|
|
|
CANRecv_Consumer::CANRecv_Consumer(CAN_Producer_Consumer *pBuf)
|
|
|
{
|
|
@@ -13,6 +14,8 @@ CANRecv_Consumer::CANRecv_Consumer(CAN_Producer_Consumer *pBuf)
|
|
|
|
|
|
objDist.fill(DIST_ERROR,NUM_OF_SENSOR_MAX);
|
|
|
sensorStatus.fill(false,NUM_OF_SENSOR_MAX);
|
|
|
+ objDist_Send.fill(DIST_ERROR,NUM_OF_SENSOR_MAX);
|
|
|
+ sensorStatus_Send.fill(false,NUM_OF_SENSOR_MAX);
|
|
|
}
|
|
|
|
|
|
CANRecv_Consumer::~CANRecv_Consumer()
|
|
@@ -48,6 +51,8 @@ void CANRecv_Consumer::run()
|
|
|
{
|
|
|
iv::can::canraw tempCANRaw;
|
|
|
uint8_t tempSensorID = 0;
|
|
|
+ uint32_t tempLastResult = DIST_ERROR;
|
|
|
+ uint16_t tempDist;
|
|
|
decodeTimer.start();
|
|
|
|
|
|
while (!QThread::isInterruptionRequested())
|
|
@@ -55,12 +60,26 @@ void CANRecv_Consumer::run()
|
|
|
tempCANRaw.CopyFrom(pBuffer->Consume_Element(1));
|
|
|
if(decodeEnableFlag == true)
|
|
|
{
|
|
|
- if(decodeTimer.elapsed() >= 25)
|
|
|
+ if(decodeTimer.elapsed() >= 50)
|
|
|
{
|
|
|
decodeEnableFlag = false;
|
|
|
objDist[decodeSensorID] = DIST_ERROR;
|
|
|
sensorStatus[decodeSensorID] = false;
|
|
|
tempSensorID = decodeSensorID + 1;
|
|
|
+
|
|
|
+ if(tempSensorID >= NUM_OF_SENSOR_MAX)
|
|
|
+ {
|
|
|
+ sonarSend_Lock.lock();
|
|
|
+ tempLastResult = objDist_Send[0];
|
|
|
+ sonarSend_Lock.unlock();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sonarSend_Lock.lock();
|
|
|
+ tempLastResult = objDist_Send[tempSensorID];
|
|
|
+ sonarSend_Lock.unlock();
|
|
|
+ }
|
|
|
+
|
|
|
if(tempSensorID >= NUM_OF_SENSOR_MAX)
|
|
|
{
|
|
|
//copy and send
|
|
@@ -76,21 +95,41 @@ void CANRecv_Consumer::run()
|
|
|
sensorStatus.fill(false,NUM_OF_SENSOR_MAX);
|
|
|
tempSensorID = 0;
|
|
|
}
|
|
|
- emit Enable_Ask(true,tempSensorID);
|
|
|
+ if(tempLastResult <= 2000)
|
|
|
+ emit Enable_Ask(true,tempSensorID,2);
|
|
|
+ else if(tempLastResult <= 3800)
|
|
|
+ emit Enable_Ask(true,tempSensorID,1);
|
|
|
+ else
|
|
|
+ emit Enable_Ask(true,tempSensorID,0);
|
|
|
decodeTimer.restart();
|
|
|
+ gTime_ms = QDateTime::currentMSecsSinceEpoch();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this->Trans_From_CANRaw(tempCANRaw);
|
|
|
if(CAN_ID == setupConfig.sonarCAN_ID && CAN_DLC == 2)
|
|
|
{
|
|
|
- uint16_t tempDist = (CAN_data[0] << 8) | CAN_data[1];
|
|
|
- if(tempDist <= 0x1493 && tempDist >= 0x88)
|
|
|
+ tempDist = (CAN_data[0] << 8) | CAN_data[1];
|
|
|
+ if(tempDist <= 0x1650 && tempDist >= 0xD0)
|
|
|
{
|
|
|
decodeEnableFlag = false;
|
|
|
objDist[decodeSensorID] = tempDist;
|
|
|
sensorStatus[decodeSensorID] = true;
|
|
|
tempSensorID = decodeSensorID + 1;
|
|
|
+
|
|
|
+ if(tempSensorID >= NUM_OF_SENSOR_MAX)
|
|
|
+ {
|
|
|
+ sonarSend_Lock.lock();
|
|
|
+ tempLastResult = objDist_Send[0];
|
|
|
+ sonarSend_Lock.unlock();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sonarSend_Lock.lock();
|
|
|
+ tempLastResult = objDist_Send[tempSensorID];
|
|
|
+ sonarSend_Lock.unlock();
|
|
|
+ }
|
|
|
+
|
|
|
if(tempSensorID >= NUM_OF_SENSOR_MAX)
|
|
|
{
|
|
|
//copy and send
|
|
@@ -106,8 +145,14 @@ void CANRecv_Consumer::run()
|
|
|
sensorStatus.fill(false,NUM_OF_SENSOR_MAX);
|
|
|
tempSensorID = 0;
|
|
|
}
|
|
|
- emit Enable_Ask(true,tempSensorID);
|
|
|
+ if(tempLastResult <= 2000)
|
|
|
+ emit Enable_Ask(true,tempSensorID,2);
|
|
|
+ else if(tempLastResult <= 3800)
|
|
|
+ emit Enable_Ask(true,tempSensorID,1);
|
|
|
+ else
|
|
|
+ emit Enable_Ask(true,tempSensorID,0);
|
|
|
decodeTimer.restart();
|
|
|
+ gTime_ms = QDateTime::currentMSecsSinceEpoch();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -125,6 +170,9 @@ void CANRecv_Consumer::Enable_DecodeResult_Slot(bool enableFlag,uint8_t sensorID
|
|
|
void CANRecv_Consumer::UltrasonicData_Ready_Slot(void)
|
|
|
{
|
|
|
iv::ultrasonic::ultrasonic xmsg;
|
|
|
+ uint64_t tempLastTime = QDateTime::currentMSecsSinceEpoch();
|
|
|
+ std::cout<<"interval time is "<<tempLastTime - gLastTime<<std::endl;
|
|
|
+ gLastTime = tempLastTime;
|
|
|
sonarSend_Lock.lock();
|
|
|
xmsg.set_sigobjdist_flside(objDist_Send[0]);
|
|
|
xmsg.set_sigobjdist_flcorner(objDist_Send[1]);
|