Data_Fuel_User.c 6.34 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7
#include "Data_Fuel_User.h"
#include "FuelConfig.h"
#include "Common_Interface.h"
#include "RTE_ADC.h"
#include "GPIO.h"
#include "Services_ODO_User.h"

hu's avatar
hu committed
8 9
static uint16_t Fuel_CurSeg;
static uint16_t Fuel_CyrStep;
hu's avatar
hu committed
10 11 12

/*-------------------------------------------------------------------------
 * Function Name  : Fuel_User_KL30_Init
hu's avatar
hu committed
13
 * Description    :
hu's avatar
hu committed
14 15 16 17 18 19 20
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
void Fuel_User_KL30_Init(void)
{
hu's avatar
hu committed
21 22 23
    Fuel_CurSeg = 0u;
    Fuel_CyrStep = 0u;

hu's avatar
hu committed
24 25
    FuelStruct FuelInitPara;
    AFC_INIT AFCInit;
hu's avatar
hu committed
26 27 28 29
    uint32_t ODO_Value = 0u;

    ODO_Value = Data_ODO_Read();

hu's avatar
hu committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    FuelInitPara.FuelShortCircuitR = FUEL_R_MIN_VAL;
    FuelInitPara.FuelOpenCircuitR = FUEL_R_MAX_VAL;

    FuelInitPara.DisplayZoneBoundary[0] = DISPLAY_BOUNDARY_ES;  // 1500
    FuelInitPara.DisplayZoneBoundary[1] = DISPLAY_BOUNDARY_1;   // 1500
    FuelInitPara.DisplayZoneBoundary[2] = DISPLAY_BOUNDARY_2;   // 1373
    FuelInitPara.DisplayZoneBoundary[3] = DISPLAY_BOUNDARY_3;   // 1191
    FuelInitPara.DisplayZoneBoundary[4] = DISPLAY_BOUNDARY_4;   // 1009
    FuelInitPara.DisplayZoneBoundary[5] = DISPLAY_BOUNDARY_5;   // 848
    FuelInitPara.DisplayZoneBoundary[6] = DISPLAY_BOUNDARY_6;   // 697
    FuelInitPara.DisplayZoneBoundary[7] = DISPLAY_BOUNDARY_7;   // 545
    FuelInitPara.DisplayZoneBoundary[8] = DISPLAY_BOUNDARY_8;   // 436
    FuelInitPara.DisplayZoneBoundary[9] = DISPLAY_BOUNDARY_9;   // 345
    FuelInitPara.DisplayZoneBoundary[10] = DISPLAY_BOUNDARY_10; // 254
    FuelInitPara.DisplayZoneBoundary[11] = DISPLAY_BOUNDARY_11; // 188
    FuelInitPara.DisplayZoneBoundary[12] = DISPLAY_BOUNDARY_12; // 132
    FuelInitPara.DisplayZoneBoundary[13] = DISPLAY_BOUNDARY_13; //  40
    FuelInitPara.DisplayZoneBoundary[14] = DISPLAY_BOUNDARY_FS; //  30

    AFCInit.CalcAFCMaxNum = 100;      /*50公里或者100公里已更新*/
    AFCInit.AFCMin = 30;              /*油耗最小值十倍*/
    AFCInit.AFCMax = 300;             /*油耗最大值*/
    AFCInit.AFCPreinstall = 80;       /*油耗初始值*/
    AFCInit.CurODO = ODO_Value * 100; /*总共里数100倍*/
    AFCInit.MaxDRMileage = 69900;     /*续航里程最大值*/
hu's avatar
hu committed
55 56 57 58

    InitFuelParamter(&FuelInitPara);
    InitAFC(&AFCInit);

hu's avatar
hu committed
59
    /*----燃油上涨为下降的0.6----*/
hu's avatar
hu committed
60 61 62 63 64 65 66
    SetIgnOffRefuelThreshold(6);

    SetPowerDnStep(0);

    SetFuelSensorRecoverGroupCnt(10);
    SetFuelSensorOpenCircuitGroupCnt(120);
    SetFuelSensorShortCircuitGroupCnt(120);
hu's avatar
hu committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
}
void Fuel_User_KL15_ON_Init(void)
{
}

void Fuel_User_KL15_OFF_Init(void)
{
}
void Fuel_User_Wakeup_Init(void)
{
}
void Fuel_User_Sleep_Init(void)
{
}
/*-------------------------------------------------------------------------
 * Function Name  : Fuel_User_KL15_ON_Processing_Service
hu's avatar
hu committed
83
 * Description    :
hu's avatar
hu committed
84 85 86 87 88 89 90
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 10Ms调用
 --------------------------------------------------------------------------*/
void Fuel_User_KL15_ON_Processing_Service(void)
{
hu's avatar
hu committed
91 92 93 94 95 96 97 98 99 100
    AFC_PARA AFCPara;
    uint8_t FuelR_Valid = 0u;
    uint8_t Vspeed_Valid = 0u;
    uint8_t Espeed_Valid = 0u;
    uint8_t FuelMode = 0u;
    uint8_t Step = 0u;
    uint16_t FuelR = 0u;
    uint16_t Vspeed = 0u;
    uint16_t Espeed = 0u;
    uint16_t FuelResistanceV = 0u;
hu's avatar
hu committed
101
    uint32_t ODO_Value = 0u;
hu's avatar
hu committed
102

hu's avatar
hu committed
103 104 105 106
    FuelR_Valid = RTE_Read_FUEL_R_Valid();
    Vspeed_Valid = Common_Get_Act_V_Speed_Valid();
    Espeed_Valid = Common_Get_Act_E_Speed_Valid();

hu's avatar
hu committed
107
    if ((Common_Get_IG_Sts() == COMMON_POWER_ON) && (Common_Get_IG_Sts_Valid() == COMMON_Valid))
hu's avatar
hu committed
108
    {
hu's avatar
hu committed
109
        if (FuelR_Valid)
hu's avatar
hu committed
110
        {
hu's avatar
hu committed
111 112 113 114 115 116
            FuelR = RTE_Read_FUEL_R();
        }
        else
        {
            FuelR = 0;
        }
hu's avatar
hu committed
117

hu's avatar
hu committed
118 119 120 121 122 123 124 125
        if (Vspeed_Valid)
        {
            Vspeed = Common_Get_Act_V_Speed();
        }
        else
        {
            Vspeed = 0;
        }
hu's avatar
hu committed
126

hu's avatar
hu committed
127 128 129 130 131 132 133 134
        if (Espeed_Valid)
        {
            Espeed = Common_Get_Act_E_Speed();
        }
        else
        {
            Espeed = 0;
        }
hu's avatar
hu committed
135

hu's avatar
hu committed
136 137
        SetPowerSt(1);
        AFCTimerCall();
hu's avatar
hu committed
138

hu's avatar
hu committed
139
        ODO_Value = Data_ODO_Read();
hu's avatar
hu committed
140

hu's avatar
hu committed
141 142 143 144
        AFCPara.CurODO = ODO_Value * 100u;
        AFCPara.FuleConsume = 0u;
        AFCPara.RPM = Espeed;
        AFCPara.Speed = (Vspeed / 10u);
hu's avatar
hu committed
145

hu's avatar
hu committed
146 147
        SetAFCPara((AFC_PARA *)&AFCPara);
        FuelFSM(FuelR); /*新版增加系数*/
hu's avatar
hu committed
148

hu's avatar
hu committed
149 150
        FuelResistanceV = GetFuelResistance(); /*燃油电阻获取*/

hu's avatar
hu committed
151
        FuelMode = GetFuelSensorState(); /*燃油状态获取*/
hu's avatar
hu committed
152

hu's avatar
hu committed
153 154
        if (FuelMode == FuelSensorNormal)
        {
hu's avatar
hu committed
155
            Fuel_CurSeg = (uint16_t)GetFuelSeg();   /*段*/
hu's avatar
hu committed
156 157 158 159 160 161 162
            Fuel_CyrStep = (uint16_t)GetFuelStep(); /*步*/
        }
        else
        {
            Fuel_CurSeg = 0u;
            Fuel_CyrStep = 0u;
        }
hu's avatar
hu committed
163
    }
hu's avatar
hu committed
164 165 166
}
/*-------------------------------------------------------------------------
 * Function Name  : Fuel_User_KL15_OFF_Processing_Service
hu's avatar
hu committed
167
 * Description    :
hu's avatar
hu committed
168 169 170 171 172 173 174
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 嵌入到100Ms中断中
 --------------------------------------------------------------------------*/
void Fuel_User_KL15_OFF_Processing_Service(void)
{
hu's avatar
hu committed
175
    uint8_t i;
hu's avatar
hu committed
176 177
    uint8_t FuelR_Valid = 0;
    uint16_t FuelR = 0;
hu's avatar
hu committed
178 179 180 181 182

    FuelR_Valid = RTE_Read_FUEL_R_Valid();
    FuelR = RTE_Read_FUEL_R();

    if (Common_Get_IG_Sts_Valid() == COMMON_Valid)
hu's avatar
hu committed
183
    {
hu's avatar
hu committed
184
        if (Common_Get_IG_Sts() == COMMON_POWER_OFF)
hu's avatar
hu committed
185
        {
hu's avatar
hu committed
186 187 188 189 190 191 192 193
            SetPowerSt(0);
            for (i = 0; i < 10; i++)
            {
                AFCTimerCall();
            }
            FuelFSM(FuelR);
        }
    }
hu's avatar
hu committed
194
}
hu's avatar
hu committed
195

hu's avatar
hu committed
196 197 198 199 200 201
/*-------------------------------------------------------------------------
 * Function Name  : Fuel_Get_CurSeg
 * Description    : 燃油当前格
 * Input          : None
 * Output         : None
 * Return         : None
hu's avatar
hu committed
202
 * onther         :
hu's avatar
hu committed
203 204 205
 --------------------------------------------------------------------------*/
uint8_t Fuel_Get_CurSeg(void)
{
hu's avatar
hu committed
206
    return Fuel_CurSeg;
hu's avatar
hu committed
207
}
hu's avatar
hu committed
208

hu's avatar
hu committed
209
/*返回燃油库电阻值*/
hu's avatar
hu committed
210 211
uint16_t Fuel_Get_Res(void)
{
hu's avatar
hu committed
212
    return GetFuelResistance();
hu's avatar
hu committed
213
}
hu's avatar
hu committed
214

hu's avatar
hu committed
215 216
uint16_t Fuel_Get_Step(void)
{
hu's avatar
hu committed
217 218 219 220
    uint16_t FuelStep = 0u;

    FuelStep = GetFuelStep();

hu's avatar
hu committed
221
    return FuelStep;
hu's avatar
hu committed
222
}