1.发送IG_OFF要持续500毫秒,或者发完IG_OFF后不要再发送跟上下电有关的命令。
2.当没有什么请求时候要发送0x04就可以。
3.当接管的时候要发发送0x04或者别的上下电命令,但是不能不发,0x04代表没有任何上下电请求。如果在接管的时候不发任何上下电命令,车辆就会直接下电。
4.当时在调试上下电的时候,先手动上电,然后接管车辆,远程下电正常,如果在1min之内重新上电也正常,但是超过两分钟后上电就不管用,后来发现是底盘VCU休眠后vehicle就会把CAN的开关给关闭掉,导致can数据发送不出去,后来把接收到can休眠的函数里把can的开关给屏蔽掉,这样就不会在接收到vcu休眠的状态把CAN给关闭掉。
以下是上下电处理相关处理代码:
void * powerReqThread(void *arg)
{
print_log("%s id=%lu\r\n",__FUNCTION__,pthread_self());//获取当前线程ID
print_log("Into (%s)\r\n", __FUNCTION__);
struct timeval tv;
long long microsecond;
int pwReqCount = 0;
unsigned char *pw_req_cmd = (unsigned char*)malloc(sizeof(unsigned char) * CAN_MSG_MAX_LEN);
int num1=0,num2=0,num3=0,num4=0;
while(!gIsPwReqThreadExit)
{
pwReqCount=1;
if(mPowerCmd==IG_OFF)
{
for(num1=0;num1<6;num1++)
{
gettimeofday(&tv,NULL);
pw_req_cmd[0] = PW_REQ_ID & 0xFF;
pw_req_cmd[1] = (PW_REQ_ID >> 8) & 0xFF;
microsecond = ((long long)tv.tv_sec) * 1000000 + tv.tv_usec;
pw_req_cmd[2] = microsecond & 0xFF;
pw_req_cmd[3] = (microsecond >> 8) & 0xFF;
pw_req_cmd[4] = (microsecond >> 16) & 0xFF;
pw_req_cmd[5] = (microsecond >> 24) & 0xFF;
pw_req_cmd[6] = 0x00;
pw_req_cmd[7] = RESERVE;
pw_req_cmd[8] = RESERVE;
pw_req_cmd[9] = RESERVE;
pw_req_cmd[10] = RESERVE;
pw_req_cmd[11] = RESERVE;
pw_req_cmd[12] = FRAME_COUNTER(pwReqCount);
pw_req_cmd[13] = crc8VerifyFF(&pw_req_cmd[CAN_DATA_OFFSET], CRC_VERIFY_DATA_LEN);
CanOperateSwitch = CAN_SEND_ENABLE;
rdbWrite(ptr_rdb, pw_req_cmd, CAN_MSG_MAX_LEN); //给Vac主机发送上电命令 每隔50ms统计下上电命令是否改变然后发给VCA命令一次
print_log("CONTROLMODULES mPowerCmd=%d,sendPowerFrame=%d vcuPowerRelayState=%d\n",mPowerCmd,sendPowerFrame,vcuPowerRelayState);
usleep(500000); //min 500ms
}
mPowerCmd=CLEAR_POWER;
}
else if(mPowerCmd==IG_ON)
{
if(vcuPowerRelayState < IG_ON)
{
for(num2=0;num2<6;num2++)
{
gettimeofday(&tv,NULL);
pw_req_cmd[0] = PW_REQ_ID & 0xFF;
pw_req_cmd[1] = (PW_REQ_ID >> 8) & 0xFF;
microsecond = ((long long)tv.tv_sec) * 1000000 + tv.tv_usec;
pw_req_cmd[2] = microsecond & 0xFF;
pw_req_cmd[3] = (microsecond >> 8) & 0xFF;
pw_req_cmd[4] = (microsecond >> 16) & 0xFF;
pw_req_cmd[5] = (microsecond >> 24) & 0xFF;
pw_req_cmd[6] = 0x01;
pw_req_cmd[7] = RESERVE;
pw_req_cmd[8] = RESERVE;
pw_req_cmd[9] = RESERVE;
pw_req_cmd[10] = RESERVE;
pw_req_cmd[11] = RESERVE;
pw_req_cmd[12] = FRAME_COUNTER(pwReqCount);
pw_req_cmd[13] = crc8VerifyFF(&pw_req_cmd[CAN_DATA_OFFSET], CRC_VERIFY_DATA_LEN);
CanOperateSwitch = CAN_SEND_ENABLE;
rdbWrite(ptr_rdb, pw_req_cmd, CAN_MSG_MAX_LEN); //给Vac主机发送上电命令 每隔50ms统计下上电命令是否改变然后发给VCA命令一次
print_log("CONTROLMODULES mPowerCmd1=%d,sendPowerFrame=%d vcuPowerRelayState=%d \n",mPowerCmd,sendPowerFrame,vcuPowerRelayState);
usleep(20000);
}
}
else
{
print_log("CONTROLMODULES mPowerCmd==IG_ON vcuPowerRelayState=%d\n",vcuPowerRelayState);
}
mPowerCmd=CLEAR_POWER;
}
else if(mPowerCmd==POWER_ON)
{
if(vcuPowerRelayState < POWER_ON)
{
for(num3=0;num3<6;num3++)
{
gettimeofday(&tv,NULL);
pw_req_cmd[0] = PW_REQ_ID & 0xFF;
pw_req_cmd[1] = (PW_REQ_ID >> 8) & 0xFF;
microsecond = ((long long)tv.tv_sec) * 1000000 + tv.tv_usec;
pw_req_cmd[2] = microsecond & 0xFF;
pw_req_cmd[3] = (microsecond >> 8) & 0xFF;
pw_req_cmd[4] = (microsecond >> 16) & 0xFF;
pw_req_cmd[5] = (microsecond >> 24) & 0xFF;
pw_req_cmd[6] = 0x02;
pw_req_cmd[7] = RESERVE;
pw_req_cmd[8] = RESERVE;
pw_req_cmd[9] = RESERVE;
pw_req_cmd[10] = RESERVE;
pw_req_cmd[11] = RESERVE;
pw_req_cmd[12] = FRAME_COUNTER(pwReqCount);
pw_req_cmd[13] = crc8VerifyFF(&pw_req_cmd[CAN_DATA_OFFSET], CRC_VERIFY_DATA_LEN);
CanOperateSwitch = CAN_SEND_ENABLE;
rdbWrite(ptr_rdb, pw_req_cmd, CAN_MSG_MAX_LEN); //给Vac主机发送上电命令 每隔50ms统计下上电命令是否改变然后发给VCA命令一次
print_log("CONTROLMODULES mPowerCmd=%d,sendPowerFrame=%d vcuPowerRelayState=%d\n",mPowerCmd,sendPowerFrame,vcuPowerRelayState);
usleep(20000);
}
}
else
{
print_log("CONTROLMODULES mPowerCmd==POWER_ON vcuPowerRelayState=%d\n",vcuPowerRelayState);
}
mPowerCmd=CLEAR_POWER;
}
else if(mPowerCmd==AUTO_ON)
{
if(vcuPowerRelayState < AUTO_ON)
{
for(num4=0;num4<6;num4++)
{
gettimeofday(&tv,NULL);
pw_req_cmd[0] = PW_REQ_ID & 0xFF;
pw_req_cmd[1] = (PW_REQ_ID >> 8) & 0xFF;
microsecond = ((long long)tv.tv_sec) * 1000000 + tv.tv_usec;
pw_req_cmd[2] = microsecond & 0xFF;
pw_req_cmd[3] = (microsecond >> 8) & 0xFF;
pw_req_cmd[4] = (microsecond >> 16) & 0xFF;
pw_req_cmd[5] = (microsecond >> 24) & 0xFF;
pw_req_cmd[6] = 0x03;
pw_req_cmd[7] = RESERVE;
pw_req_cmd[8] = RESERVE;
pw_req_cmd[9] = RESERVE;
pw_req_cmd[10] = RESERVE;
pw_req_cmd[11] = RESERVE;
pw_req_cmd[12] = FRAME_COUNTER(pwReqCount);
pw_req_cmd[13] = crc8VerifyFF(&pw_req_cmd[CAN_DATA_OFFSET], CRC_VERIFY_DATA_LEN);
CanOperateSwitch = CAN_SEND_ENABLE;
rdbWrite(ptr_rdb, pw_req_cmd, CAN_MSG_MAX_LEN); //给Vac主机发送上电命令 每隔50ms统计下上电命令是否改变然后发给VCA命令一次
print_log("CONTROLMODULES mPowerCmd=%d,sendPowerFrame=%d vcuPowerRelayState=%d\n",mPowerCmd,sendPowerFrame,vcuPowerRelayState);
usleep(20000);
}
}
else
{
print_log("CONTROLMODULES mPowerCmd==AUTO_ON vcuPowerRelayState=%d\n",vcuPowerRelayState);
}
mPowerCmd=CLEAR_POWER;
}
else
{
gettimeofday(&tv,NULL);
pw_req_cmd[0] = PW_REQ_ID & 0xFF;
pw_req_cmd[1] = (PW_REQ_ID >> 8) & 0xFF;
microsecond = ((long long)tv.tv_sec) * 1000000 + tv.tv_usec;
pw_req_cmd[2] = microsecond & 0xFF;
pw_req_cmd[3] = (microsecond >> 8) & 0xFF;
pw_req_cmd[4] = (microsecond >> 16) & 0xFF;
pw_req_cmd[5] = (microsecond >> 24) & 0xFF;
pw_req_cmd[6] = 0x04;
pw_req_cmd[7] = RESERVE;
pw_req_cmd[8] = RESERVE;
pw_req_cmd[9] = RESERVE;
pw_req_cmd[10] = RESERVE;
pw_req_cmd[11] = RESERVE;
pw_req_cmd[12] = FRAME_COUNTER(pwReqCount);
pw_req_cmd[13] = crc8VerifyFF(&pw_req_cmd[CAN_DATA_OFFSET], CRC_VERIFY_DATA_LEN);
CanOperateSwitch = CAN_SEND_ENABLE;
rdbWrite(ptr_rdb, pw_req_cmd, CAN_MSG_MAX_LEN); //给Vac主机发送上电命令 每隔50ms统计下上电命令是否改变然后发给VCA命令一次
print_log("CONTROLMODULES mPowerCmdv else=%d,sendPowerFrame=%d vcuPowerRelayState=%d\n",mPowerCmd,sendPowerFrame,vcuPowerRelayState);
}
#if 0
pwReqCount += 1;
if(pwReqCount > 15)
pwReqCount = 0;
#endif
usleep(CAN_SEND_INTERVAL_50MS);
}
free(pw_req_cmd);
return 0;
}