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

#define VEH_FILTER_LEN    7

hu's avatar
hu committed
8
static struct
hu's avatar
hu committed
9 10 11
{
    uint8_t Count ;
    uint16_t Data[VEH_FILTER_LEN] ;
hu's avatar
hu committed
12
} VehcleFilter;
hu's avatar
hu committed
13

hu's avatar
hu committed
14 15
static uint32_t SPEED_PPK = 159246ul ;
static uint32_t SPEED_RADIO = 637 ;
hu's avatar
hu committed
16 17 18 19 20 21

uint16_t Vehicle_ACT_Speed;
uint16_t Vehicle_DISP_Speed;
uint8_t VehicleSpeedValid;
uint8_t Vehicle_CurSeg ;

hu's avatar
hu committed
22
static uint16_t Cal_VehSpeed(uint16_t Fre, uint8_t Len);
hu's avatar
hu committed
23 24 25 26 27 28 29 30 31

void Speed_KL30_Init(void)
{
    uint8_t i ;
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
    VehcleFilter.Count = 0 ;
hu's avatar
hu committed
32
    for (i = 0 ; i < VEH_FILTER_LEN ; i ++)
hu's avatar
hu committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46
    {
        VehcleFilter.Data[ i ] = 0 ;
    }

    Set_Speed_PPK(159246ul);
}
void Speed_KL15_ON_Init(void)
{
    uint8_t i ;
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
    VehcleFilter.Count = 0 ;
hu's avatar
hu committed
47
    for (i = 0 ; i < VEH_FILTER_LEN ; i ++)
hu's avatar
hu committed
48 49 50 51
    {
        VehcleFilter.Data[ i ] = 0 ;
    }

hu's avatar
hu committed
52
    Veh_Fre_Init(Get_Speed_PPK() / 10);
hu's avatar
hu committed
53 54 55 56 57 58 59 60 61
}
void Speed_KL15_OFF_Init(void)
{
    uint8_t i ;
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
    VehcleFilter.Count = 0 ;
hu's avatar
hu committed
62
    for (i = 0 ; i < VEH_FILTER_LEN ; i ++)
hu's avatar
hu committed
63 64 65 66 67 68 69 70 71 72 73
    {
        VehcleFilter.Data[ i ] = 0 ;
    }
}
void Speed_Wakeup_Init(void)
{
    uint8_t i ;
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
hu's avatar
hu committed
74
    for (i = 0 ; i < VEH_FILTER_LEN ; i ++)
hu's avatar
hu committed
75 76 77 78 79 80 81 82 83 84 85
    {
        VehcleFilter.Data[ i ] = 0 ;
    }
}
void Speed_Sleep_Init(void)
{
    uint8_t i ;
    Vehicle_ACT_Speed = 0u;
    Vehicle_DISP_Speed = 0u;
    VehicleSpeedValid = 0u;
    Vehicle_CurSeg = 0u;
hu's avatar
hu committed
86
    for (i = 0 ; i < VEH_FILTER_LEN ; i ++)
hu's avatar
hu committed
87 88 89 90 91 92 93 94 95 96 97 98
    {
        VehcleFilter.Data[ i ] = 0 ;
    }
}

void Speed_Processing_Service(void)
{
    uint32_t VehValTmp ;
    uint32_t PPK = Get_Speed_PPK();
    //if(Get_Veh_Fre_Event())
    //{
    //    VehValTmp = Cal_VehSpeed(Get_Veh_Fre(),VEH_FILTER_LEN) ;
hu's avatar
hu committed
99

hu's avatar
hu committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    //    VehValTmp *= 3600 ;
    //    VehValTmp *= 10 ;
    //    VehValTmp *= 10 ;
    //    VehValTmp /= PPK ;

    //    Vehicle_ACT_Speed = VehValTmp ;
    //}

    VehValTmp = Cal_Veh_Frequency();

    VehValTmp *= 3600 ;
    VehValTmp *= 10 ;
    VehValTmp *= 10 ;
    VehValTmp /= PPK ;

hu's avatar
hu committed
115

hu's avatar
hu committed
116 117 118 119 120

    //VehValTmp = Cal_Veh_Frequency();
    //VehValTmp *= 3600 ;
    //VehValTmp *= 10 ;
    //VehValTmp /= PPK ;
hu's avatar
hu committed
121 122

    if (VehValTmp > 2250)
hu's avatar
hu committed
123 124 125 126 127 128 129 130 131
    {
        VehValTmp = 0 ;
        VehicleSpeedValid = 0 ;
    }
    else
    {
        VehicleSpeedValid = 1 ;
    }
    Vehicle_ACT_Speed = VehValTmp ;
hu's avatar
hu committed
132

hu's avatar
hu committed
133 134 135 136 137 138
//传入表头
    VehValTmp = VehSpeedAmplification((uint16_t)VehValTmp);
    SetGaugesPara(VehGauges, (uint16_t)VehValTmp);

//获得显示格和显示车速
    Vehicle_CurSeg = GetGaugesCurrentPos(VehGauges);
hu's avatar
hu committed
139
    Vehicle_DISP_Speed = GetVehDisVal(Vehicle_CurSeg, &GaugesInfo_Init_Table[VehGauges]);
hu's avatar
hu committed
140 141 142 143


}

hu's avatar
hu committed
144
static uint16_t Cal_VehSpeed(uint16_t Fre, uint8_t Len)
hu's avatar
hu committed
145 146
{
    static uint16_t u16Result = 0 ;
hu's avatar
hu committed
147
    if (Fre > 2000)
hu's avatar
hu committed
148
    {
hu's avatar
hu committed
149
        //do nothing
hu's avatar
hu committed
150 151 152
    }
    else
    {
hu's avatar
hu committed
153
        if (VehcleFilter.Count < Len)
hu's avatar
hu committed
154 155 156 157 158
        {
            VehcleFilter.Data[VehcleFilter.Count] = Fre ;
            VehcleFilter.Count ++ ;
        }
        else
hu's avatar
hu committed
159
        {
hu's avatar
hu committed
160
            VehcleFilter.Count = 0 ;
hu's avatar
hu committed
161
            App_SortNByte(VehcleFilter.Data, Len);
hu's avatar
hu committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183

            u16Result = VehcleFilter.Data[2] ;
            u16Result += VehcleFilter.Data[3] ;
            u16Result += VehcleFilter.Data[3] ;
            u16Result += VehcleFilter.Data[4] ;
            u16Result /= 4 ;
        }
    }

    return u16Result ;
}

/*-------------------------------------------------------------------------
 * Function Name  : Set_Speed_PPK
 * Description    : 设置PPK值,初始化 或需要改变时调用
 * Input          : 10倍的PPK
 * Output         : None
 * Return         : None
 * onther         : PPK = 频率 * 3600 / 车速
 --------------------------------------------------------------------------*/
void Set_Speed_PPK(uint32_t PPK)
{
hu's avatar
hu committed
184
    SPEED_PPK = PPK ;
hu's avatar
hu committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
}
/*-------------------------------------------------------------------------
 * Function Name  : Set_Speed_PPK
 * Description    : 设置速比值,初始化 或需要改变时调用
 * Input          : 速比
 * Output         : None
 * Return         : None
 * onther         : 速比 = PPK / 脉冲
 --------------------------------------------------------------------------*/
void Set_Speed_Ratio(uint32_t Ratio)
{
    SPEED_RADIO = Ratio ;
}
/*-------------------------------------------------------------------------
 * Function Name  : Get_Speed_PPK
hu's avatar
hu committed
200
 * Description    :
hu's avatar
hu committed
201 202 203
 * Input          : None
 * Output         : None
 * Return         : 10倍PPK值
hu's avatar
hu committed
204
 * onther         :
hu's avatar
hu committed
205 206 207
 --------------------------------------------------------------------------*/
uint32_t Get_Speed_PPK(void)
{
hu's avatar
hu committed
208 209 210
    uint32_t u32Result = 0u;
    u32Result = SPEED_PPK ;
    return u32Result ;
hu's avatar
hu committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
}

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)
{
    return Vehicle_CurSeg ;
}
/*-------------------------------------------------------------------------
 * Function Name  : Speed_Get_Valid
 * Description    : 车速有效?
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
uint8_t Speed_Get_Valid(void)
{
    return VehicleSpeedValid ;
}