Data_VehicleSpeed.c 8.87 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"
6
#include "GUI.h"
hu's avatar
hu committed
7
#include "kwp2000_service.h"
hu's avatar
hu committed
8

hu's avatar
hu committed
9
static uint32_t SPEED_RADIO = 637u;
hu's avatar
hu committed
10 11 12

uint16_t Vehicle_ACT_Speed;
uint16_t Vehicle_DISP_Speed;
hu's avatar
hu committed
13 14 15 16 17
uint8_t  VehicleSpeedValid;
uint8_t  Vehicle_CurSeg;
uint8_t  DataOverSpeed;
uint8_t  DataOverSpeedK_Line;
uint32_t SPEED_PPK;
18 19 20 21 22

_ACCSUBSPEED   AccSubSpeed;
uint16_t       Speed_Old  ;
uint16_t       GslYblSpeedTime  ;

hu's avatar
hu committed
23
volatile uint32_t VehFreBuf[VehFreNum];
hu's avatar
hu committed
24 25 26

void Speed_KL30_Init(void)
{
hu's avatar
hu committed
27
    uint8_t i = 0u;
hu's avatar
hu committed
28 29 30
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
hu's avatar
hu committed
31 32 33
    DataOverSpeedK_Line = 0u;

    for (i = 0; i < VehFreNum; i++)
hu's avatar
hu committed
34
    {
hu's avatar
hu committed
35
        VehFreBuf[i] = 0u;
hu's avatar
hu committed
36 37
    }
}
hu's avatar
hu committed
38

hu's avatar
hu committed
39 40
void Speed_KL15_ON_Init(void)
{
hu's avatar
hu committed
41
    uint8_t i = 0u;
hu's avatar
hu committed
42 43 44 45
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
hu's avatar
hu committed
46 47 48 49 50 51
    DataOverSpeedK_Line = 0u;

    SPEED_PPK = 15925u;

    Veh_Fre_Init(SPEED_PPK);
    for (i = 0; i < VehFreNum; i++)
hu's avatar
hu committed
52
    {
hu's avatar
hu committed
53
        VehFreBuf[i] = 0u;
hu's avatar
hu committed
54
    }
55 56 57

    Speed_Old = 0u;
    GslYblSpeedTime = 0u;
hu's avatar
hu committed
58
}
hu's avatar
hu committed
59

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

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

hu's avatar
hu committed
76 77 78 79 80 81 82 83 84 85
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
86
    static uint8_t i = 0u;
87
    uint32_t VehValTmp = 0u;
hu's avatar
hu committed
88
    uint32_t VehValDisp = 0u;
hu's avatar
hu committed
89
    uint16_t VehValCup = 0u;
90
    uint32_t PPK = 0u;
hu's avatar
hu committed
91
    uint16_t  DataOverSpeedValue ;
hu's avatar
hu committed
92

hu's avatar
hu committed
93
    COMMON_PowerStatus_t IG_Sta;
hu's avatar
hu committed
94

hu's avatar
hu committed
95
    IG_Sta = Common_Get_IG_Sts_Valid();
hu's avatar
hu committed
96

hu's avatar
hu committed
97
    if ( IG_Sta == COMMON_POWER_ON)
hu's avatar
hu committed
98
    {
hu's avatar
hu committed
99 100 101
        /**/
        DataOverSpeedValue = K_Line_Set.K_Line_LID44;
        DataOverSpeedValue *= 10u;
hu's avatar
hu committed
102

hu's avatar
hu committed
103 104 105 106 107 108
        PPK = Get_Speed_PPK();

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

hu's avatar
hu committed
110 111
        i++;
        if (i > VehFreNum)
hu's avatar
hu committed
112
        {
hu's avatar
hu committed
113 114
            Fre_SortShort(VehFreBuf, VehFreNum);
            i = 0u;
hu's avatar
hu committed
115
        }
hu's avatar
hu committed
116
        VehValCup = (uint16_t) VehFreBuf[1u];
hu's avatar
hu committed
117 118

        if (VehValCup > 2250)
hu's avatar
hu committed
119
        {
hu's avatar
hu committed
120 121
            VehicleSpeedValid = 0u;

hu's avatar
hu committed
122 123 124 125
            Vehicle_ACT_Speed = 0u;
        }
        else
        {
hu's avatar
hu committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139
            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
140
        }
hu's avatar
hu committed
141

hu's avatar
hu committed
142 143 144
        //传入表头  计算放大系数
        VehValDisp = VehSpeedAmplification((uint16_t)Vehicle_ACT_Speed);
        SetGaugesPara(VehGauges, (uint16_t)VehValDisp);
hu's avatar
hu committed
145

hu's avatar
hu committed
146 147 148
        //获得显示格和显示车速
        Vehicle_CurSeg = GetGaugesCurrentPos(VehGauges);
        Vehicle_DISP_Speed = VehValDisp;//GetVehDisVal(Vehicle_CurSeg, &GaugesInfo_Init_Table[VehGauges]);
hu's avatar
hu committed
149

hu's avatar
hu committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163

        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
164 165 166
    }
    else
    {
hu's avatar
hu committed
167
        i = 0u;
hu's avatar
hu committed
168 169 170 171 172 173
    }
}

/*-------------------------------------------------------------------------
 * Function Name  : Set_Speed_PPK
 * Description    : 设置PPK值,初始化 或需要改变时调用
hu's avatar
hu committed
174
 * Input          :
hu's avatar
hu committed
175 176 177 178 179 180
 * Output         : None
 * Return         : None
 * onther         : PPK = 频率 * 3600 / 车速
 --------------------------------------------------------------------------*/
void Set_Speed_PPK(uint32_t PPK)
{
hu's avatar
hu committed
181
    SPEED_PPK = PPK;
hu's avatar
hu committed
182 183 184 185 186 187 188 189 190 191 192
}
/*-------------------------------------------------------------------------
 * 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
193
    SPEED_RADIO = Ratio;
hu's avatar
hu committed
194 195 196
}
/*-------------------------------------------------------------------------
 * Function Name  : Get_Speed_PPK
hu's avatar
hu committed
197
 * Description    :
hu's avatar
hu committed
198 199 200
 * Input          : None
 * Output         : None
 * Return         : 10倍PPK值
hu's avatar
hu committed
201
 * onther         :
hu's avatar
hu committed
202 203 204
 --------------------------------------------------------------------------*/
uint32_t Get_Speed_PPK(void)
{
hu's avatar
hu committed
205
    uint32_t u32Result = 0u;
hu's avatar
hu committed
206 207
    u32Result = SPEED_PPK;
    return u32Result;
hu's avatar
hu committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
}

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
232
    return Vehicle_CurSeg;
hu's avatar
hu committed
233 234 235 236 237 238 239 240 241 242 243
}
/*-------------------------------------------------------------------------
 * 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
244
    return VehicleSpeedValid;
hu's avatar
hu committed
245
}
hu's avatar
hu committed
246 247 248 249 250 251 252 253 254 255 256

/******************************************************************************
  函数名:Data_Acc_Speed_Processing
  功  能: 加速度计算
  参  数: 无
  返回值:无
 ******************************************************************************/
void Data_Acc_Speed_Processing(void)
{
    uint16_t Speed_New = 0;
    uint16_t AccSpeed  = 0;
257
    Speed_New = Common_Get_Act_V_Speed_Valid();
hu's avatar
hu committed
258

259 260
    AccSubSpeed.ACCSpeed_Time++;
    if (AccSubSpeed.ACCSpeed_Time >= 10)
hu's avatar
hu committed
261
    {
262
        AccSubSpeed.ACCSpeed_Time = 0;
hu's avatar
hu committed
263 264 265 266 267 268 269
        if (Speed_Old <= Speed_New)
        {
            AccSpeed      = Speed_New - Speed_Old;
            Speed_Old     = Speed_New ;

            if (AccSpeed > User_App.User_JADD)
            {
270
                AccSubSpeed.AccSpeed_Flag = 1 ;
hu's avatar
hu committed
271 272 273
            }
            else
            {
274
                AccSubSpeed.AccSpeed_Flag = 0 ;
hu's avatar
hu committed
275
            }
276
            AccSubSpeed.SubSpeed_Flag = 0 ;
hu's avatar
hu committed
277 278 279 280 281 282 283
        }
        else
        {
            AccSpeed      = Speed_Old - Speed_New;
            Speed_Old     = Speed_New ;
            if (AccSpeed > User_App.User_JSUB)
            {
284
                AccSubSpeed.SubSpeed_Flag = 1 ;
hu's avatar
hu committed
285 286 287
            }
            else
            {
288
                AccSubSpeed.SubSpeed_Flag = 0 ;
hu's avatar
hu committed
289
            }
290
            AccSubSpeed.AccSpeed_Flag = 0 ;
hu's avatar
hu committed
291 292 293 294 295 296 297 298 299 300 301 302 303
        }
    }
}
/******************************************************************************
  函数名:Data_GsLYbL_Speed_Processing
  功  能: 高速路, 一般路判断
  参  数: 无
  返回值:无
 ******************************************************************************/
void Data_GsLYbL_Speed_Processing(void)
{
    uint16_t User_Gsl = 0;
    uint16_t User_Ybl = 0;
304 305 306
    uint16_t Veh_Speed = 0u;

    Veh_Speed = Common_Get_Act_V_Speed_Valid();
hu's avatar
hu committed
307 308 309 310

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

311
    if ( Veh_Speed >= 600 )
hu's avatar
hu committed
312 313 314 315
    {
        if (GslYblSpeedTime <= 6000 )
            GslYblSpeedTime++;
    }
316
    else if ( Veh_Speed <= 590 )
hu's avatar
hu committed
317 318 319 320 321 322
    {
        GslYblSpeedTime = 0;
    }

    if (GslYblSpeedTime >= 6000)
    {
323
        AccSubSpeed.GslYbl_Flag = 1;
hu's avatar
hu committed
324 325 326
    }
    else
    {
327
        AccSubSpeed.GslYbl_Flag = 0;
hu's avatar
hu committed
328 329
    }

330
    if (AccSubSpeed.GslYbl_Flag == 1)
hu's avatar
hu committed
331
    {
332
        if (Veh_Speed > User_Gsl)
hu's avatar
hu committed
333
        {
334
            AccSubSpeed.GslSpeed_Flag = 1;
hu's avatar
hu committed
335
        }
336
        else if (Veh_Speed <= (User_Gsl - 10))
hu's avatar
hu committed
337
        {
338
            AccSubSpeed.GslSpeed_Flag = 0;
hu's avatar
hu committed
339 340 341 342
        }
    }
    else
    {
343
        if (Veh_Speed > User_Ybl)
hu's avatar
hu committed
344
        {
345
            AccSubSpeed.GslSpeed_Flag = 1;
hu's avatar
hu committed
346
        }
347
        else if (Veh_Speed <= (User_Ybl - 10))
hu's avatar
hu committed
348
        {
349
            AccSubSpeed.GslSpeed_Flag = 0;
hu's avatar
hu committed
350
        }
hu's avatar
hu committed
351

hu's avatar
hu committed
352
    }
hu's avatar
hu committed
353 354 355 356 357 358 359 360 361 362 363 364 365
}
//15925
//5096
void Drive_Info_Speed1_Plus_Conversion(void)
{
    uint32_t Veh_Frequenc = 0u;

    Veh_Frequenc = Cal_Veh_Frequency();
    Veh_Frequenc *= 10u;
    TimerB_PWM_Channel_Fre_Set(TIMERB_2_CH10, Veh_Frequenc, 500u);/*车速1 25*/

    Veh_Frequenc = Veh_Frequenc * 5096 / 15925;
    TimerB_PWM_Channel_Fre_Set(TIMERB_2_CH13, Veh_Frequenc, 500u);/*车速2 8*/
hu's avatar
hu committed
366
}