Commit 63eebee0 authored by 李俭双's avatar 李俭双

feat:增加车速数据处理

parent d20dd765
...@@ -168,10 +168,7 @@ uint32_t Common_GetSocTime(void) ...@@ -168,10 +168,7 @@ uint32_t Common_GetSocTime(void)
*/ */
uint32_t Data_Km_To_Mile(uint32_t Km) uint32_t Data_Km_To_Mile(uint32_t Km)
{ {
//Km *= 621; Km = (Km * 64u) / 103u;
//Km /= 1000;
Km *= 100;
Km /= 161;
return Km; return Km;
} }
/** /**
......
...@@ -69,108 +69,62 @@ void Data_Vehicle_Speed_Processing_Service(void) ...@@ -69,108 +69,62 @@ void Data_Vehicle_Speed_Processing_Service(void)
uint16_t Delta; uint16_t Delta;
uint32_t VSpeed; uint32_t VSpeed;
uint32_t VSpeedCal; uint32_t VSpeedCal;
//uint8_t ESC_VehicleSpeedvalid; uint8_t ESC_VehicleSpeedState;
uint32_t Vehicle_Speed; uint32_t Vehicle_Speed;
Vehicle_Speed = Get_CAN_CH0_ID_101_Sig_ECU_Vehicle_Speed( ); Vehicle_Speed = Get_CAN_CH0_ID_101_Sig_ECU_Vehicle_Speed( );
//ESC_VehicleSpeedvalid = Get_CAN_CH0_ID_330_Sig_ESC_Vehicle_speed_valid( ); ESC_VehicleSpeedState = Get_CAN_CH0_ID_101_Sig_ECU_Vehicle_Speed_State( );
// 第1步:获取实际车速值及车速有效性 // 第1步:获取实际车速值及车速有效性
if( Common_Get_IG_Sts( ) == COMMON_POWER_ON ) if( Common_Get_IG_Sts( ) == COMMON_POWER_ON )
{ {
if ((CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x101_Msg_Count) == CAN_SIG_LOST) || (Vehicle_Speed > 0XFF)) if (CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x101_Msg_Count) == CAN_SIG_LOST)
{
DataVSpeedValid = 0;
DataVSpeedActual = 0;
DataVSpeedSampler.Backup = 0;
}
else
{ {
/* 先判断掉线 */ if (ESC_VehicleSpeedState == 1)
if (CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x101_Msg_Count) == CAN_SIG_LOST)
{ {
DataVSpeedValid = 0; DataVSpeedValid = 0;
DataVSpeedActual = 0; DataVSpeedActual = 0;
DataVSpeedSampler.Backup = 0; DataVSpeedSampler.Backup = 0;
} }
#if 0 else
else if ( ESC_VehicleSpeedvalid == 1 )//发送can无效标志位
{ {
if ( DataVSpeedSampler.Timer1 <= 10 ) /* 10帧无效 */ if ( DataVSpeedValid == 0 )
{
if ( DataVSpeedValid )//判断车速是否有效,有效采集10次,车速等于上次值
{
DataVSpeedSampler.Timer1++;
DataVSpeedActual = DataVSpeedSampler.Backup;
}
else//无效,不采集,车速=0
{
DataVSpeedSampler.Timer1 = 10;
DataVSpeedActual = 0;
DataVSpeedSampler.Backup = 0;
}
}
else//不采集就,车速=0
{ {
DataVSpeedValid = 0; DataVSpeedValid = 1;
DataVSpeedActual = 0; VSpeed = Vehicle_Speed;
DataVSpeedSampler.Backup = 0; DataVSpeedActual = VSpeed * 10;
} }
} else
#endif
else /* 收到无效值 */
{
if ( DataVSpeedSampler.Timer <= 100 ) /* 100帧无效值 */
{ {
if ( DataVSpeedValid ) DataVSpeedSampler.Buffer [ DataVSpeedSampler.Cnt ] = Vehicle_Speed;
i = DataVSpeedSampler.Cnt;
while ( (i > 0) && (DataVSpeedSampler.Buffer [ i ] < DataVSpeedSampler.Buffer [ i - 1 ]) )
{ {
DataVSpeedSampler.Timer++; VSpeed = DataVSpeedSampler.Buffer [ i ];
DataVSpeedActual = DataVSpeedSampler.Backup; DataVSpeedSampler.Buffer [ i ] = DataVSpeedSampler.Buffer [ i - 1 ];
DataVSpeedSampler.Buffer [ i - 1 ] = VSpeed;
i--;
} }
else
DataVSpeedSampler.Cnt++;
if ( DataVSpeedSampler.Cnt >= 3 )
{ {
DataVSpeedSampler.Timer = 100; DataVSpeedSampler.Cnt = 0;
DataVSpeedActual = 0; VSpeed = DataVSpeedSampler.Buffer [ 1 ];
DataVSpeedSampler.Backup = 0; DataVSpeedActual = VSpeed * 10;
} }
DataVSpeedSampler.Timer = 0;
DataVSpeedSampler.Timer1 = 0;
DataVSpeedSampler.Backup = DataVSpeedActual;
DataVSpeedValid = 1;
} }
else // 接收到100帧无效值
{
DataVSpeedValid = 0;
DataVSpeedActual = 0;
DataVSpeedSampler.Backup = 0;
}
}
}
else //车速在线且有效
{
if ( DataVSpeedValid == 0 )
{
DataVSpeedValid = 1;
VSpeed = Vehicle_Speed;
// VSpeed *= 9;
// VSpeed >>= 4;
DataVSpeedActual = VSpeed * 10;
}
else
{
DataVSpeedSampler.Buffer [ DataVSpeedSampler.Cnt ] = Vehicle_Speed;
i = DataVSpeedSampler.Cnt;
while ( (i > 0) && (DataVSpeedSampler.Buffer [ i ] < DataVSpeedSampler.Buffer [ i - 1 ]) )
{
VSpeed = DataVSpeedSampler.Buffer [ i ];
DataVSpeedSampler.Buffer [ i ] = DataVSpeedSampler.Buffer [ i - 1 ];
DataVSpeedSampler.Buffer [ i - 1 ] = VSpeed;
i--;
}
DataVSpeedSampler.Cnt++;
if ( DataVSpeedSampler.Cnt >= 3 )
{
DataVSpeedSampler.Cnt = 0;
VSpeed = DataVSpeedSampler.Buffer [ 1 ];
//VSpeed *= 9;
//VSpeed >>= 4;
DataVSpeedActual = VSpeed * 10;
}
DataVSpeedSampler.Timer = 0;
DataVSpeedSampler.Timer1 = 0;
DataVSpeedSampler.Backup = DataVSpeedActual;
} }
} }
} }
...@@ -251,8 +205,8 @@ void Data_Vehicle_Speed_Processing_Service(void) ...@@ -251,8 +205,8 @@ void Data_Vehicle_Speed_Processing_Service(void)
else else
{ {
DataVSPeedDamping.Speed += Delta; DataVSPeedDamping.Speed += Delta;
if ( DataVSPeedDamping.Speed > 1200 ) if ( DataVSPeedDamping.Speed > 1990 )
DataVSPeedDamping.Speed = 1200; DataVSPeedDamping.Speed = 1990;
} }
} }
else // 显示值正在向实际值减小,则维持当前方向调节增加速度 else // 显示值正在向实际值减小,则维持当前方向调节增加速度
...@@ -300,8 +254,8 @@ void Data_Vehicle_Speed_Processing_Service(void) ...@@ -300,8 +254,8 @@ void Data_Vehicle_Speed_Processing_Service(void)
else else
{ {
DataVSPeedDamping.Speed += Delta; DataVSPeedDamping.Speed += Delta;
if ( DataVSPeedDamping.Speed > 1200 ) if ( DataVSPeedDamping.Speed > 1990 )
DataVSPeedDamping.Speed = 1200; DataVSPeedDamping.Speed = 1990;
} }
} }
else // 显示值当前是减小方向 else // 显示值当前是减小方向
...@@ -336,12 +290,14 @@ void Data_Vehicle_Speed_Processing_Service(void) ...@@ -336,12 +290,14 @@ void Data_Vehicle_Speed_Processing_Service(void)
if ( DataVSpeedValid ) if ( DataVSpeedValid )
{ {
VSpeedCal *= 108; VSpeedCal *= 107;
VSpeedCal /= 100; VSpeedCal /= 100;
if((VSpeedCal % 10) >= 5) VSpeedCal = VSpeedCal + 10;
if(VSpeedCal > 1990)
{ {
VSpeedCal += 5; /* 四舍五入 */ VSpeedCal = 1990;
} }
DataVSpeedDisp = ( uint16_t )VSpeedCal; DataVSpeedDisp = ( uint16_t )VSpeedCal;
} }
else else
...@@ -366,24 +322,21 @@ uint16_t Get_DispVechileSpeed(void) ...@@ -366,24 +322,21 @@ uint16_t Get_DispVechileSpeed(void)
uint16_t Vspeed = 0; uint16_t Vspeed = 0;
if(Get_Dis_KM_Unit() == 0) /* KM */ if(Get_Dis_KM_Unit() == 0) /* KM */
{ {
if ( DataVSpeedDisp >= 1200 ) if ( DataVSpeedDisp >= 1990 )
{ {
DataVSpeedDisp = 1200; DataVSpeedDisp = 1990;
} }
Vspeed = DataVSpeedDisp; Vspeed = DataVSpeedDisp;
} }
else //if (Get_Dis_KM_Unit() == 1) /* MILE */ else /* MILE */
{ {
Vspeed = Data_Km_To_Mile(DataVSpeedDisp); Vspeed = Data_Km_To_Mile(DataVSpeedDisp);
if ( Vspeed >= 750 ) if ( Vspeed >= 1230 )
{ {
Vspeed = 750; Vspeed = 1230;
} }
} }
// else
// {
// ;
// }
return Vspeed; return Vspeed;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment