Data_VehicleSpeed.c 8.46 KB
Newer Older
hu's avatar
hu committed
1
#include "Data_VehicleSpeed.h"
hu's avatar
hu committed
2
#include "TimerB.h"
hu's avatar
hu committed
3 4
#include "Gauges.h"
#include "GaugesInterface.h"
hu's avatar
hu committed
5
#include "Common_Interface.h"
hu's avatar
hu committed
6

hu's avatar
hu committed
7
static uint32_t SPEED_RADIO = 637u;
hu's avatar
hu committed
8 9 10

uint16_t Vehicle_ACT_Speed;
uint16_t Vehicle_DISP_Speed;
hu's avatar
hu committed
11 12 13 14 15 16
uint8_t  VehicleSpeedValid;
uint8_t  Vehicle_CurSeg;
uint8_t  DataOverSpeed;
uint8_t  DataOverSpeedK_Line;
uint32_t SPEED_PPK;
volatile uint32_t VehFreBuf[VehFreNum];
hu's avatar
hu committed
17 18 19

void Speed_KL30_Init(void)
{
hu's avatar
hu committed
20
    uint8_t i = 0u;
hu's avatar
hu committed
21 22 23
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
hu's avatar
hu committed
24 25 26
    DataOverSpeedK_Line = 0u;

    for (i = 0; i < VehFreNum; i++)
hu's avatar
hu committed
27
    {
hu's avatar
hu committed
28
        VehFreBuf[i] = 0u;
hu's avatar
hu committed
29 30
    }
}
hu's avatar
hu committed
31

hu's avatar
hu committed
32 33
void Speed_KL15_ON_Init(void)
{
hu's avatar
hu committed
34
    uint8_t i = 0u;
hu's avatar
hu committed
35 36 37 38
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
hu's avatar
hu committed
39 40 41 42 43 44
    DataOverSpeedK_Line = 0u;

    SPEED_PPK = 15925u;

    Veh_Fre_Init(SPEED_PPK);
    for (i = 0; i < VehFreNum; i++)
hu's avatar
hu committed
45
    {
hu's avatar
hu committed
46
        VehFreBuf[i] = 0u;
hu's avatar
hu committed
47 48
    }
}
hu's avatar
hu committed
49

hu's avatar
hu committed
50 51 52 53 54 55 56
void Speed_KL15_OFF_Init(void)
{
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
}
hu's avatar
hu committed
57

hu's avatar
hu committed
58 59 60 61 62 63 64
void Speed_Wakeup_Init(void)
{
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
}
hu's avatar
hu committed
65

hu's avatar
hu committed
66 67 68 69 70 71 72 73 74 75
void Speed_Sleep_Init(void)
{
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
}

void Speed_Processing_Service(void)
{
hu's avatar
hu committed
76
    static uint8_t i = 0u;
77
    uint32_t VehValTmp = 0u;
hu's avatar
hu committed
78
    uint32_t VehValDisp = 0u;
hu's avatar
hu committed
79
    uint16_t VehValCup = 0u;
80
    uint32_t PPK = 0u;
hu's avatar
hu committed
81
    uint16_t  DataOverSpeedValue ;
hu's avatar
hu committed
82

hu's avatar
hu committed
83
    COMMON_PowerStatus_t IG_Sta;
hu's avatar
hu committed
84

hu's avatar
hu committed
85
    IG_Sta = Common_Get_IG_Sts_Valid();
hu's avatar
hu committed
86

hu's avatar
hu committed
87
    if ( IG_Sta == COMMON_POWER_ON)
hu's avatar
hu committed
88
    {
hu's avatar
hu committed
89 90 91
        /**/
        DataOverSpeedValue = K_Line_Set.K_Line_LID44;
        DataOverSpeedValue *= 10u;
hu's avatar
hu committed
92

hu's avatar
hu committed
93 94 95 96 97 98
        PPK = Get_Speed_PPK();

        VehValTmp = Cal_Veh_Frequency();
        VehValTmp *= 36000u;
        VehValTmp /= PPK;
        VehFreBuf[i] = VehValTmp;
hu's avatar
hu committed
99

hu's avatar
hu committed
100 101
        i++;
        if (i > VehFreNum)
hu's avatar
hu committed
102
        {
hu's avatar
hu committed
103 104
            Fre_SortShort(VehFreBuf, VehFreNum);
            i = 0u;
hu's avatar
hu committed
105
        }
hu's avatar
hu committed
106 107 108
        VehValCup = (uint16_t) VehFreBuf[1u];

        if (VehValCup > 2250)
hu's avatar
hu committed
109
        {
hu's avatar
hu committed
110 111
            VehicleSpeedValid = 0u;

hu's avatar
hu committed
112 113 114 115
            Vehicle_ACT_Speed = 0u;
        }
        else
        {
hu's avatar
hu committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129
            VehicleSpeedValid = 1u;

            if (VehValCup >= 1400u)
            {
                Vehicle_ACT_Speed = 1400u;
            }
            else  if (VehValCup <= 40u)
            {
                Vehicle_ACT_Speed = 0u;
            }
            else
            {
                Vehicle_ACT_Speed = VehValCup;
            }
hu's avatar
hu committed
130
        }
hu's avatar
hu committed
131

hu's avatar
hu committed
132 133 134
        //传入表头  计算放大系数
        VehValDisp = VehSpeedAmplification((uint16_t)Vehicle_ACT_Speed);
        SetGaugesPara(VehGauges, (uint16_t)VehValDisp);
hu's avatar
hu committed
135

hu's avatar
hu committed
136 137 138
        //获得显示格和显示车速
        Vehicle_CurSeg = GetGaugesCurrentPos(VehGauges);
        Vehicle_DISP_Speed = VehValDisp;//GetVehDisVal(Vehicle_CurSeg, &GaugesInfo_Init_Table[VehGauges]);
hu's avatar
hu committed
139

hu's avatar
hu committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153

        if (K_Line_Set.K_Line_LID44 != 0xFF)
        {
            if (DataOverSpeedK_Line)
            {
                if (Vehicle_DISP_Speed <= DataOverSpeedValue)
                    DataOverSpeedK_Line = 0;
            }
            else
            {
                if (Vehicle_DISP_Speed >= (DataOverSpeedValue + 20))
                    DataOverSpeedK_Line = 1;
            }
        }
hu's avatar
hu committed
154 155 156
    }
    else
    {
hu's avatar
hu committed
157
        i = 0u;
hu's avatar
hu committed
158 159 160 161 162 163
    }
}

/*-------------------------------------------------------------------------
 * Function Name  : Set_Speed_PPK
 * Description    : 设置PPK值,初始化 或需要改变时调用
hu's avatar
hu committed
164
 * Input          :
hu's avatar
hu committed
165 166 167 168 169 170
 * Output         : None
 * Return         : None
 * onther         : PPK = 频率 * 3600 / 车速
 --------------------------------------------------------------------------*/
void Set_Speed_PPK(uint32_t PPK)
{
hu's avatar
hu committed
171
    SPEED_PPK = PPK;
hu's avatar
hu committed
172 173 174 175 176 177 178 179 180 181 182
}
/*-------------------------------------------------------------------------
 * Function Name  : Set_Speed_PPK
 * Description    : 设置速比值,初始化 或需要改变时调用
 * Input          : 速比
 * Output         : None
 * Return         : None
 * onther         : 速比 = PPK / 脉冲
 --------------------------------------------------------------------------*/
void Set_Speed_Ratio(uint32_t Ratio)
{
hu's avatar
hu committed
183
    SPEED_RADIO = Ratio;
hu's avatar
hu committed
184 185 186
}
/*-------------------------------------------------------------------------
 * Function Name  : Get_Speed_PPK
hu's avatar
hu committed
187
 * Description    :
hu's avatar
hu committed
188 189 190
 * Input          : None
 * Output         : None
 * Return         : 10倍PPK值
hu's avatar
hu committed
191
 * onther         :
hu's avatar
hu committed
192 193 194
 --------------------------------------------------------------------------*/
uint32_t Get_Speed_PPK(void)
{
hu's avatar
hu committed
195
    uint32_t u32Result = 0u;
hu's avatar
hu committed
196 197
    u32Result = SPEED_PPK;
    return u32Result;
hu's avatar
hu committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
}

uint16_t Speed_Get_ActualValue(void)
{
    uint16_t u16Result = 0u;
    u16Result = Vehicle_ACT_Speed;
    return u16Result;
}
uint16_t Speed_Get_Display_Value(void)
{
    uint16_t u16Result = 0u;
    u16Result = Vehicle_DISP_Speed;
    return u16Result;
}
/*-------------------------------------------------------------------------
 * Function Name  : Speed_Get_CurSeg
 * Description    : 车速当前格
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 应用于断码
 --------------------------------------------------------------------------*/
uint8_t Speed_Get_CurSeg(void)
{
hu's avatar
hu committed
222
    return Vehicle_CurSeg;
hu's avatar
hu committed
223 224 225 226 227 228 229 230 231 232 233
}
/*-------------------------------------------------------------------------
 * Function Name  : Speed_Get_Valid
 * Description    : 车速有效?
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
uint8_t Speed_Get_Valid(void)
{
hu's avatar
hu committed
234
    return VehicleSpeedValid;
hu's avatar
hu committed
235
}
hu's avatar
hu committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343

/******************************************************************************
  函数名:Data_Acc_Speed_Processing
  功  能: 加速度计算
  参  数: 无
  返回值:无
 ******************************************************************************/
void Data_Acc_Speed_Processing(void)
{
#if 0
    uint16_t Speed_New = 0;
    uint16_t AccSpeed  = 0;
    Speed_New = DATA_VEHICLE_SPEED_DISPLAYING;

    AccSubSpeed.Sig.ACCSpeed_Time++;
    if (AccSubSpeed.Sig.ACCSpeed_Time >= 10)
    {
        AccSubSpeed.Sig.ACCSpeed_Time = 0;
        if (Speed_Old <= Speed_New)
        {
            AccSpeed      = Speed_New - Speed_Old;
            Speed_Old     = Speed_New ;

            if (AccSpeed > User_App.User_JADD)
            {
                AccSubSpeed.Sig.AccSpeed_Flag = 1 ;
            }
            else
            {
                AccSubSpeed.Sig.AccSpeed_Flag = 0 ;
            }
            AccSubSpeed.Sig.SubSpeed_Flag = 0 ;
        }
        else
        {
            AccSpeed      = Speed_Old - Speed_New;
            Speed_Old     = Speed_New ;
            if (AccSpeed > User_App.User_JSUB)
            {
                AccSubSpeed.Sig.SubSpeed_Flag = 1 ;
            }
            else
            {
                AccSubSpeed.Sig.SubSpeed_Flag = 0 ;
            }
            AccSubSpeed.Sig.AccSpeed_Flag = 0 ;
        }
    }
#endif
}
/******************************************************************************
  函数名:Data_GsLYbL_Speed_Processing
  功  能: 高速路, 一般路判断
  参  数: 无
  返回值:无
 ******************************************************************************/
void Data_GsLYbL_Speed_Processing(void)
{
#if 0
    uint16_t User_Gsl = 0;
    uint16_t User_Ybl = 0;

    User_Gsl = (uint16_t)User_App.User_Gsl * 10 ;
    User_Ybl = (uint16_t)User_App.User_Ybl * 10 ;

    if ( DATA_VEHICLE_SPEED_DISPLAYING >= 600 )
    {
        if (GslYblSpeedTime <= 6000 )
            GslYblSpeedTime++;
    }
    else if ( DATA_VEHICLE_SPEED_DISPLAYING <= 590 )
    {
        GslYblSpeedTime = 0;
    }

    if (GslYblSpeedTime >= 6000)
    {
        AccSubSpeed.Sig.GslYbl_Flag = 1;
    }
    else
    {
        AccSubSpeed.Sig.GslYbl_Flag = 0;
    }

    if (AccSubSpeed.Sig.GslYbl_Flag == 1)
    {
        if (DATA_VEHICLE_SPEED_DISPLAYING > User_Gsl)
        {
            AccSubSpeed.Sig.GslSpeed_Flag = 1;
        }
        else if (DATA_VEHICLE_SPEED_DISPLAYING <= (User_Gsl - 10))
        {
            AccSubSpeed.Sig.GslSpeed_Flag = 0;
        }
    }
    else
    {
        if (DATA_VEHICLE_SPEED_DISPLAYING > User_Ybl)
        {
            AccSubSpeed.Sig.GslSpeed_Flag = 1;
        }
        else if (DATA_VEHICLE_SPEED_DISPLAYING <= (User_Ybl - 10))
        {
            AccSubSpeed.Sig.GslSpeed_Flag = 0;
        }
    }
#endif
}