

#ifndef _DATA_PROCESSOR_H_
#define _DATA_PROCESSOR_H_

#include "Communication_Over_CAN.h"
#include "Non_volatile_Memorys.h"
#include "System_Status_Monitor.h"
#include "GUI.h"
#include "CAN_Communication_Matrix.h"
#include "Telltales.h"
#include "Menus.h"
/******************************************************************************
数据逼近方向
******************************************************************************/
#define   DATA_APPR_DIR_INC                 0x00
#define   DATA_APPR_DIR_DEC                 0x01


//extern uint16_t TireTEMP;
extern uint16_t TireTEMPL;
extern uint16_t TireTEMPR;
//extern uint16_t TirePLR;
extern uint16_t TirePL;
extern uint16_t TirePR;
/******************************************************************************
发动机转速
******************************************************************************/

/*** 全局变量 ***/
extern uint16_t DataESpeedActual;
extern uint16_t DataESpeedDisp;
extern uint8_t  DataESpeedValid;
extern uint8_t  Maintain_alarm;
#define  DATA_ENGINE_SPEED_ACTUAL           DataESpeedActual
#define  DATA_ENGINE_SPEED_DISPLAYING       DataESpeedDisp
#define  DATA_ENGINE_SPEED_VALID            DataESpeedValid
extern uint8_t IO_DISP_TEST_OFF_TIME;   //自检结束延时
/*** 参数设置 ***/
#define   DATA_ENGINE_RUNNING_THRESHOLD     400 //发动机运转阈值    
#define   DATA_ENGINE_STOP_THRESHOLD        300 //发动机停止阈值

#define   DATA_ESPEED_DAMPING_FACTOR        50   //阻尼系数
#define   DATA_ESPEED_INC_STEP              3   //速度增加时慢加速速度变化步长
#define   DATA_ESPEED_DEC_STEP              8   //方向改变时急减速速度变化步长
#define   DATA_ESPEED_APPR_SPEED_MIN        2   //最小逼近速度
#define   DATA_ESPEED_HYSTERESIS            40   //回差    

/*** 控制结构 ***/
typedef struct
{
  uint16_t  Timer;
  uint16_t  Backup;
  uint16_t  Buffer[5];
  uint8_t   Cnt;
  uint8_t   UseBackup;
} DataESpeedSamplerStruct;            //转速采样结构

typedef struct
{
  uint16_t  Speed;
  uint16_t  Delta;
  uint8_t   Dir;
} DataESPeedDampingStruct;            //转速阻尼结构

typedef struct
{
  uint16_t  ESpeedBackup;
  uint16_t  Timer;
  uint8_t   Mode;
} DataESpeedIdleStruct;               //怠速处理结构

/******************************************************************************
车速
******************************************************************************/

/*** 全局变量 ***/
extern uint16_t DataVSpeedActual;
extern uint16_t DataVSpeedDisp;
extern uint8_t  DataVSpeedValid;
extern uint8_t  DataOverSpeed;

#define  DATA_VEHICLE_SPEED_ACTUAL          DataVSpeedActual
#define  DATA_VEHICLE_SPEED_DISPLAYING      DataVSpeedDisp
#define  DATA_VEHICLE_SPEED_VALID           DataVSpeedValid
#define  DATA_OVER_SPEED_WARNING            DataOverSpeed

/*** 参数设置 ***/
#define   DATA_VEHICLE_RUNNING_THRESHOLD    25  //汽车行进阈值    
#define   DATA_VEHICLE_STOP_THRESHOLD       20  //汽车停止阈值

#define   DATA_VSPEED_DAMPING_FACTOR        4   //阻尼系数
#define   DATA_VSPEED_INC_STEP              3   //速度增加时慢加速速度变化步长
#define   DATA_VSPEED_DEC_STEP              8   //方向改变时急减速速度变化步长
#define   DATA_VSPEED_APPR_SPEED_MIN        2   //最小逼近速度
#define   DATA_VSPEED_HYSTERESIS            10   //回差 20201208解决定速巡航车速不稳问题

/*** 控制结构 ***/
typedef struct
{
  uint16_t  Timer;
  uint16_t  Backup;
  uint16_t  Buffer[3];
  uint8_t   Cnt;
  uint8_t   UseBackup;
} DataVSpeedSamplerStruct;            //车速采样结构

typedef struct
{
  uint16_t  Speed;
  uint16_t  Delta;
  uint8_t   Dir;
} DataVSPeedDampingStruct;            //车速阻尼结构

/******************************************************************************
水温
******************************************************************************/

/*** 全局变量 ***/
extern uint16_t DataCoolantTempSegDisp;
extern uint16_t DataCoolantTemp;
extern uint8_t DataCollantTempValid;
extern uint8_t DataHiCollantTempWarning;

#define  DATA_COOLANT_TEMP_SEG_DISPLAYING   DataCoolantTempSegDisp               
#define  DATA_COOLANT_TEMP_VALID            DataCollantTempValid                 
#define  DATA_COOLANT_TEMP                  DataCoolantTemp                      
#define  DATA_HI_COOLANT_TEMP_WARNING       DataHiCollantTempWarning             

/*** 状态定义 ***/
#define   DATA_COOLANT_TEMP_STATE_DELAY     0x00       //上电延时
#define   DATA_COOLANT_TEMP_STATE_INIT      0x01       //初始
#define   DATA_COOLANT_TEMP_STATE_FAST      0x02       //快速走
#define   DATA_COOLANT_TEMP_STATE_NORMAL    0x03       //正常模式
#define   DATA_COOLANT_TEMP_STATE_FAULT     0x04       //掉线

/*** 参数设置 ***/
#define   DATA_COOLANT_TEMP_WAIT_SEC        3     //多长时间更新一次
#define   DATA_COOLANT_TEMP_SEG_STEP_FAST   20    //快速走动时,每走一格间隔的时间,单位ms
#define   DATA_COOLANT_TEMP_SEG_STEP_SLOW   1500  //慢速走动时,每走一格间隔的时间,单位ms 

#define   DATA_COOLANT_TEMP_SEG_PER_GROUP   1      
#define   DATA_COOLANT_TEMP_TOTAL_GROUP     8     
#define   DATA_COOLANT_TEMP_TOTAL_SEG       (DATA_COOLANT_TEMP_SEG_PER_GROUP * DATA_COOLANT_TEMP_TOTAL_GROUP)   
#define   DATA_HI_COOLANT_TEMP_SEG          7       

/*** 控制结构 ***/
typedef struct
{
  uint16_t  Backup;
  uint16_t  LostTimer;
  uint16_t  Last;
  uint8_t   InvalidCnt;
  uint8_t   DstSeg;
  uint8_t   State;
  uint8_t   Wait;
  uint8_t   Prescaler;
  uint8_t   FastMode;
  uint8_t   OutputEnable;
  uint8_t   DispTimer;
} DataCoolantTempCalcStruct;

typedef struct
{
  uint16_t  Up[DATA_COOLANT_TEMP_TOTAL_GROUP + 1];
  uint16_t  Dn[DATA_COOLANT_TEMP_TOTAL_GROUP + 1];
} DataCoolantTempTableStruct;

/*** 水温表格 ***/                       
static const DataCoolantTempTableStruct DataCoolantTempTable14T =
{
  /*                                                   -------------------->                                */
  {           50,      59,      67,       75,       90,      98,      105,     111,    120},
  /* +--------+---------+---------+---------+---------+---------+---------+                                 */
  /* | 段码组 |         |    1    |    2    |    3    |    4    |    5    |                                 */
  /* +--------+---------+---------+---------+---------+---------+---------+                                 */
  {           50,      59,      67,       75,       90,      98,      105,     111,    120},
  /*                                                  <--------------------                                 */
};

/******************************************************************************
ADBLUE
******************************************************************************/

/*** 全局变量 ***/
extern uint16_t DataCoolantADblueSegDisp;
extern uint16_t DataCoolantADblue;
extern uint8_t DataCollantADblueValid;
extern uint8_t DataHiCollantADblueWarning;

#define  DATA_COOLANT_ADBLUE_SEG_DISPLAYING   DataCoolantADblueSegDisp               
#define  DATA_COOLANT_ADBLUE_VALID            DataCollantADblueValid                 
#define  DATA_COOLANT_ADBLUE                  DataCoolantADblue                      
#define  DATA_HI_COOLANT_ADBLUE_WARNING       DataHiCollantADblueWarning             

/*** 状态定义 ***/
#define   DATA_COOLANT_ADBLUE_STATE_DELAY     0x00     //上电延时
#define   DATA_COOLANT_ADBLUE_STATE_INIT      0x01     //初始
#define   DATA_COOLANT_ADBLUE_STATE_FAST      0x02     //快速走
#define   DATA_COOLANT_ADBLUE_STATE_NORMAL    0x03     //正常模式
#define   DATA_COOLANT_ADBLUE_STATE_FAULT     0x04     //掉线

/*** 参数设置 ***/
#define   DATA_COOLANT_ADBLUE_WAIT_SEC        3     //多长时间更新一次
#define   DATA_COOLANT_ADBLUE_SEG_STEP_FAST   20    //快速走动时,每走一格间隔的时间,单位ms
#define   DATA_COOLANT_ADBLUE_SEG_STEP_SLOW   1500  //慢速走动时,每走一格间隔的时间,单位ms 

#define   DATA_COOLANT_ADBLUE_SEG_PER_GROUP   1        
#define   DATA_COOLANT_ADBLUE_TOTAL_GROUP     13       
#define   DATA_COOLANT_ADBLUE_TOTAL_SEG       (DATA_COOLANT_ADBLUE_SEG_PER_GROUP * DATA_COOLANT_ADBLUE_TOTAL_GROUP)   
#define   DATA_HI_COOLANT_ADBLUE_SEG          120         

/*** 控制结构 ***/
typedef struct
{
  uint16_t  Backup;
  uint16_t  LostTimer;
  uint16_t  Last;
  uint8_t   InvalidCnt;
  uint8_t   DstSeg;
  uint8_t   State;
  uint8_t   Wait;
  uint8_t   Prescaler;
  uint8_t   FastMode;
  uint8_t   OutputEnable;
  uint8_t   DispTimer;
} DataCoolantADblueCalcStruct;

typedef struct
{
  uint16_t  Up[DATA_COOLANT_ADBLUE_TOTAL_GROUP + 1];
  uint16_t  Dn[DATA_COOLANT_ADBLUE_TOTAL_GROUP + 1];
} DataCoolantADblueTableStruct;

/*** 水温表格 ***/                       
static const DataCoolantADblueTableStruct DataCoolantADblueTable14T =
{
  /*                                                   -------------------->                                */
  {           50,      54,      58,      63,    68,      73,78,101,104,106,108,110,111,210},
  /* +--------+---------+---------+---------+---------+---------+---------+                                 */
  /* | 段码组 |         |    1    |    2    |    3    |    4    |    5    |                                 */
  /* +--------+---------+---------+---------+---------+---------+---------+                                 */
  {           50,      54,      58,      63,    68,      72,78,101,104,106,108,110,111,210},
  /*                                                  <--------------------                                 */
};
/******************************************************************************
机油压力
******************************************************************************/

/*** 全局变量 ***/
extern uint16_t DataCoolantOilSegDisp;
extern uint16_t DataCoolantOil;
extern uint8_t DataCollantOilValid;
extern uint8_t DataHiCollantOilWarning;

#define  DATA_COOLANT_OIL_SEG_DISPLAYING   DataCoolantOilSegDisp               
#define  DATA_COOLANT_OIL_VALID            DataCollantOilValid                 
#define  DATA_COOLANT_OIL                  DataCoolantOil                      
#define  DATA_HI_COOLANT_OIL_WARNING       DataHiCollantOilWarning             

/*** 状态定义 ***/
#define   DATA_COOLANT_OIL_STATE_DELAY     0x00       //上电延时
#define   DATA_COOLANT_OIL_STATE_INIT      0x01       //初始
#define   DATA_COOLANT_OIL_STATE_FAST      0x02       //快速走
#define   DATA_COOLANT_OIL_STATE_NORMAL    0x03       //正常模式
#define   DATA_COOLANT_OIL_STATE_FAULT     0x04       //掉线

/*** 参数设置 ***/
#define   DATA_COOLANT_OIL_WAIT_SEC        3     //多长时间更新一次
#define   DATA_COOLANT_OIL_SEG_STEP_FAST   20    //快速走动时,每走一格间隔的时间,单位ms
#define   DATA_COOLANT_OIL_SEG_STEP_SLOW   1500  //慢速走动时,每走一格间隔的时间,单位ms 

//#define   DATA_COOLANT_OIL_SEG_PER_GROUP   1      
//#define   DATA_COOLANT_OIL_TOTAL_GROUP     8     
//#define   DATA_COOLANT_OIL_TOTAL_SEG       (DATA_COOLANT_OIL_SEG_PER_GROUP * DATA_COOLANT_OIL_TOTAL_GROUP)   
//#define   DATA_HI_COOLANT_OIL_SEG          7       

/*** 控制结构 ***/
typedef struct
{
  uint16_t  Backup;
  uint16_t  LostTimer;
  uint16_t  Last;
  uint8_t   InvalidCnt;
  uint8_t   DstSeg;
  uint8_t   State;
  uint8_t   Wait;
  uint8_t   Prescaler;
  uint8_t   FastMode;
  uint8_t   OutputEnable;
  uint8_t   DispTimer;
} DataCoolantOilCalcStruct;


/******************************************************************************
AirO
******************************************************************************/
/*** 全局变量 ***/
extern uint16_t DataCoolantAirOSegDisp;
extern uint32_t DataCoolantAirO;
extern uint8_t  DataCollantAirOValid;
extern uint8_t  DataHiCollantAirOWarning;
extern uint8_t  FrontPress;
extern uint8_t  RearPress;
#define  DATA_COOLANT_GAS1_SEG_DISPLAYING   DataCoolantAirOSegDisp            
#define  DATA_COOLANT_GAS1_VALID            DataCoolantAirO            
#define  DATA_COOLANT_GAS1                  DataCollantAirOValid            
#define  DATA_LOW_COOLANT_GAS1_WARNING      DataHiCollantAirOWarning  

/*** 状态定义 ***/
#define   DATA_COOLANT_AirO_STATE_DELAY     0x00       //上电延时
#define   DATA_COOLANT_AirO_STATE_INIT      0x01       //初始
#define   DATA_COOLANT_AirO_STATE_FAST      0x02       //快速走
#define   DATA_COOLANT_AirO_STATE_NORMAL    0x03       //正常模式
#define   DATA_COOLANT_AirO_STATE_FAULT     0x04       //掉线

/*** 参数设置 ***/
#define   DATA_COOLANT_AirO_WAIT_SEC        3     //多长时间更新一次
#define   DATA_COOLANT_AirO_SEG_STEP_FAST   20    //快速走动时,每走一格间隔的时间,单位ms
#define   DATA_COOLANT_AirO_SEG_STEP_SLOW   1500  //慢速走动时,每走一格间隔的时间,单位ms 

#define   DATA_COOLANT_AirO_SEG_PER_GROUP   10       //一个小格走的微步数（电机是角度*12 断码是平均像素点）
#define   DATA_COOLANT_AirO_TOTAL_GROUP     5         //关键点个数（对应断码或者表盘关键点数个数）
#define   DATA_COOLANT_AirO_TOTAL_SEG       (DATA_COOLANT_AirO_SEG_PER_GROUP * DATA_COOLANT_AirO_TOTAL_GROUP)   
#define   DATA_HI_COOLANT_AirO_SEG          1180         //报警点

/******************************************************************************
AirT
******************************************************************************/
/*** 全局变量 ***/
extern uint16_t DataCoolantAirTSegDisp;
extern uint32_t DataCoolantAirT;
extern uint8_t  DataCollantAirTValid;
extern uint8_t  DataHiCollantAirTWarning;

#define  DATA_COOLANT_GAS2_SEG_DISPLAYING   DataCoolantAirTSegDisp         
#define  DATA_COOLANT_GAS2_VALID            DataCoolantAirT  
#define  DATA_COOLANT_GAS2                  DataCollantAirTValid       
#define  DATA_LOW_COOLANT_GAS2_WARNING      DataHiCollantAirTWarning

/*** 状态定义 ***/
#define   DATA_COOLANT_AirT_STATE_DELAY     0x00       //上电延时
#define   DATA_COOLANT_AirT_STATE_INIT      0x01       //初始
#define   DATA_COOLANT_AirT_STATE_FAST      0x02       //快速走
#define   DATA_COOLANT_AirT_STATE_NORMAL    0x03       //正常模式
#define   DATA_COOLANT_AirT_STATE_FAULT     0x04       //掉线

/*** 参数设置 ***/
#define   DATA_COOLANT_AirT_WAIT_SEC        3     //多长时间更新一次
#define   DATA_COOLANT_AirT_SEG_STEP_FAST   20    //快速走动时,每走一格间隔的时间,单位ms
#define   DATA_COOLANT_AirT_SEG_STEP_SLOW   1500  //慢速走动时,每走一格间隔的时间,单位ms 

#define   DATA_COOLANT_AirT_SEG_PER_GROUP   10       //一个小格走的微步数（电机是角度*12 断码是平均像素点）
#define   DATA_COOLANT_AirT_TOTAL_GROUP     5         //关键点个数（对应断码或者表盘关键点数个数）
#define   DATA_COOLANT_AirT_TOTAL_SEG       (DATA_COOLANT_AirT_SEG_PER_GROUP * DATA_COOLANT_AirT_TOTAL_GROUP)   
#define   DATA_HI_COOLANT_AirT_SEG          1180         //报警点

/******************************************************************************
燃油余量
******************************************************************************/

/*** 全局变量 ***/
extern uint8_t DataFuelSensorFault;
extern uint8_t DataFuelLevelLow;
extern uint8_t DataFuelLevelVolatile;
extern uint8_t DataFuelLevelSegDisp;
extern uint16_t DataFuelVolRemaining;
extern uint16_t DataFuelSensorRes;
extern uint16_t FuelConsumptionRate;
       
#define  DATA_FUEL_SENSOR_FAULT             DataFuelSensorFault
#define  DATA_FUEL_LEVEL_LOW                DataFuelLevelLow
#define  DATA_FUEL_LEVEL_VOLATILE           DataFuelLevelVolatile
#define  DATA_FUEL_LEVEL_SEG_DISPLAYING     DataFuelLevelSegDisp
#define  DATA_FUEL_VOLUME_REMAINING         DataFuelVolRemaining
#define  DATA_FUEL_SENSOR_RESISTANCE        DataFuelSensorRes

/*** 状态定义 ***/
#define   DATA_FUEL_STATE_STOP              0x00
#define   DATA_FUEL_STATE_DELAY             0x01
#define   DATA_FUEL_STATE_INIT              0x02
#define   DATA_FUEL_STATE_FAST              0x03
#define   DATA_FUEL_STATE_MID               0x04
#define   DATA_FUEL_STATE_SLOW              0x05
#define   DATA_FUEL_STATE_WAIT              0x06
#define   DATA_FUEL_STATE_REINIT            0x07
#define   DATA_FUEL_STATE_FAULT             0x08

/*** 参数设置 ***/
#define   DATA_FUEL_LEVEL_WAIT_SEC          3
#define   DATA_IGN_ON_REFUEL_ENABLE         1
#define   DATA_ENGINE_RUNNING_REFUEL_ENABLE 1
//#define   DATA_COOL_SENSOR_RES_MIN          100     //水温短路
//#define   DATA_COOL_SENSOR_RES_MAX          3500    //水温开路
#define   DATA_FUEL_SENSOR_RES_MIN          30
#define   DATA_FUEL_SENSOR_RES_MAX          1900
#define   DATA_FUEL_SENSOR_FAULT_DET_TIME   20000      //传感器失效检测时间(未失效 -> 失效),单位ms
#define   DATA_FUEL_SENSOR_FAULT_RECOV_TIME 20000      //传感器失效恢复时间(失效 -> 未失效),单位ms
//#define   DATA_COOL_SENSOR_FAULT_RECOV_TIME 20000      //水温传感器失效恢复时间(失效 -> 未失效),单位ms
#define   DATA_REFUEL_THRESHOLD             60         //加油阈值 (x0.1L)
#define   DATA_DEFUEL_THRESHOLD             120        //放油阈值 (x0.1L)
#define   DATA_FUEL_TANK_CAPACITY           600        //油箱容量 (x0.1L)

#define   DATA_FUEL_SAMPLE_CYCLE_FAST       1500       //快速采样周期,单位ms
#define   DATA_FUEL_SAMPLE_CYCLE_MID        2500       //中速采样周期,单位ms
#define   DATA_FUEL_SAMPLE_CYCLE_SLOW       120000     //慢速采样周期,单位ms

#define   DATA_FUEL_SAMPLE_POINT_MIN_FAST   12         //快速采样时,最小采样点数
#define   DATA_FUEL_SAMPLE_POINT_MIN_MID    20         //中速采样时,最小采样点数
#define   DATA_FUEL_SAMPLE_POINT_MIN_SLOW   1000       //慢速采样时,最小采样点数

#define   DATA_FUEL_DAMPING_FACTOR_RES      0.000003   //传感器电阻值阻尼系数

#define   DATA_FUEL_LEVEL_SEG_STEP          20         //每走一格间隔的时间,单位ms 
#define   DATA_FUEL_LEVEL_SEG_STEP_FORCE    800        //加油时最后一组每走一格强制间隔的时间,单位ms

#define   DATA_FUEL_RES_VOL_TABLE_COL       (sizeof(DataFuelResVolTable) / sizeof(DataFuelResVsVolStruct))
//#define   DATA_Cool_RES_VOL_TABLE_COL       (sizeof(DataCoolResVolTable) / sizeof(DataCoolResVsVolStruct))
#define   DATA_FUEL_LEVEL_SEG_PER_GROUP     1
//#define   DATA_COOL_LEVEL_SEG_PER_GROUP     1
#define   DATA_FUEL_LEVEL_TOTAL_GROUP       8
//#define   DATA_COOL_LEVEL_TOTAL_GROUP       8
#define   DATA_FUEL_LEVEL_TOTAL_SEG         (DATA_FUEL_LEVEL_SEG_PER_GROUP * DATA_FUEL_LEVEL_TOTAL_GROUP)
//#define   DATA_COOL_LEVEL_TOTAL_SEG         (DATA_COOL_LEVEL_SEG_PER_GROUP * DATA_COOL_LEVEL_TOTAL_GROUP)
#define   DATA_LOW_FUEL_SEG                 1

/*** 控制结构 ***/
typedef struct
{
  uint8_t   Init;
  uint8_t   State;
  uint8_t   Timer;
  uint8_t   Prescaler;
  uint8_t   Wait;
  uint8_t   VehicleRunning;
  uint8_t   EngineRunning;
  uint8_t   OutputEnable;
  uint8_t   LowFuelEnable;
  uint8_t   BackupValid;
  uint8_t   SegBackup;
  uint16_t  VolRef;
  uint16_t  VolBackup;
  uint16_t  ResBackup;
} DataFuelLevelStateStruct;

typedef struct
{
  uint8_t   Enable;
  uint8_t   Cnt;
  uint8_t   Valid;
  uint16_t  Timer;
  uint16_t  Buffer[5];
  uint16_t  Res;
} DataFuelSensorSamplerStruct;

typedef struct
{
  uint8_t   Enable;
  uint8_t   Update;
  uint8_t   Valid;
  uint16_t  Timer;
  uint16_t  SampleCycle;
  uint16_t  Cnt;
  uint16_t  SamplePointMin;
  uint32_t  Sum;
  uint16_t  Res;
  uint16_t  Vol;
} DataFuelSensorResCalcStruct;

typedef struct
{
  uint8_t   Enable;
  uint8_t   RefuelEnable;
  uint8_t   Busy;
  uint8_t   SlowMode;
  uint16_t  ResInput;
  uint16_t  Timer;
  uint16_t  Res;
  uint16_t  Vol;
  float     DampingRes;
} DataFuelSensorResDampingStruct;

typedef struct
{
  uint8_t   FastMode;
  uint8_t   DstSeg;
  uint16_t  ResDisp;
  uint16_t  Timer;
} DataFuelLevelDisplayStruct;

typedef struct
{
  uint16_t Res;
  uint16_t Vol;
} DataFuelResVsVolStruct;
typedef struct
{
  uint16_t Res;
  uint16_t Vol;
} DataCoolResVsVolStruct;

typedef struct
{
  uint16_t  Up[DATA_FUEL_LEVEL_TOTAL_GROUP + 1];
  uint16_t  Dn[DATA_FUEL_LEVEL_TOTAL_GROUP + 1];
} DataFuelLevelTableStruct;

/*** 阻值/燃油量对应表 ***/
static const DataFuelResVsVolStruct DataFuelResVolTable[] =
{
  /*=================================
     Res(x0.1 Ohm) |  Vol(x0.1 L)
  ---------------------------------*/
  {             30,            500,},
  {             80,            420,},
  {             70,            380,},
  {             50,            330,},
  {             130,           270,},
  {             910,           210,},
  {            1140,           150,},
  {            1350,           100,},
  {            2000,            50,},
  {            2830,            30,},
  /*===============================*/
};

/*** 燃油量表格 ***/
static const DataFuelLevelTableStruct DataFuelLevelTable =
{
  /*                                                  -------------------->                                 */
  {                   1110,     1050,      1000,      400,     350,      300,      200,      100,      50, },
  /* +--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+   */
  /* | 段码组 |         |    1    |    2    |    3    |    4    |    5    |    6    |    7    |    8    |   */
  /* +--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+   */
  {                   1000,     980,       900,       350,     300,      250,      170,      80,       30, },
  /*                                                  <--------------------                                 */
};

/******************************************************************************
断电计时
******************************************************************************/

/*** 全局变量 ***/
extern uint16_t DataIGNOffTimerSec;

#define  DATA_IGN_OFF_TIMER_SEC             DataIGNOffTimerSec

/*** 控制结构 ***/
typedef struct
{
  uint8_t   IGNStatus;
  uint16_t  RoCBackup;
} DataIGNOffTimingStruct;

/******************************************************************************
室外温度显示
******************************************************************************/

/*** 全局变量 ***/
extern uint8_t  DataAmbientTempDispMode;
extern uint8_t  DataAmbientTemp;
extern uint8_t  DataAmbientTempUnit;

#define  DATA_AMBIENT_TEMP_DISP_MODE        DataAmbientTempDispMode
#define  DATA_AMBIENT_TEMP                  DataAmbientTemp
#define  DATA_AMBIENT_TEMP_UNIT             DataAmbientTempUnit

extern uint8_t  DataoilTempDispMode;
extern uint8_t  DataoiltTemp;
extern uint8_t  DataoilTempUnit;

#define  DATA_oil_TEMP_DISP_MODE        DataoilTempDispMode
#define  DATA_oil_TEMP                  DataoiltTemp
#define  DATA_oil_TEMP_UNIT             DataoilTempUnit

/******************************************************************************
里程滚动计数器
******************************************************************************/

/*** 全局变量 ***/
extern uint16_t DataMileageRollingCounter;

#define  DATA_MILEAGE_ROLLING_COUNTER       DataMileageRollingCounter     //里程滚动计数器,单位m

/*** 控制结构 ***/
typedef struct
{
  uint16_t  mmRollingCounter;
  uint16_t  mmRoCBackup;
} DataMileageCalcStruct;

/******************************************************************************
总计里程
******************************************************************************/

/*** 全局变量 ***/
extern uint8_t  DataODOValid;

#define  DATA_ODO_VALID                     DataODOValid

/*** 控制结构 ***/
typedef struct
{
  uint8_t  UpdateDisable;
  uint16_t RoCBackup;
  uint32_t LastSaved;
} DataODOStruct;

/******************************************************************************
小计里程
******************************************************************************/

/*** 全局变量 ***/
extern uint16_t DataTrip;
extern uint16_t   DataTripA;
extern uint16_t   DataTripB;
extern uint8_t  DataTripUnit;
extern uint8_t  DataTripValid;

//extern uint16_t DataTripAFuelAve;
extern uint16_t DataTripASeatbelt;

#define  DATA_TRIP                          DataTrip
#define  DATA_TRIPA                          DataTripA
#define  DATA_TRIPB                          DataTripB
#define  DATA_TRIP_UNIT                     DataTripUnit
#define  DATA_TRIP_VALID                    DataTripValid

/*** 控制结构 ***/
typedef struct
{
  uint16_t  MileageA100m;
  uint16_t  MileageB100m;
  uint16_t  RoCBackup;
} DataTripStruct;

/******************************************************************************
行驶时间
******************************************************************************/

/*** 全局变量 ***/
extern uint8_t DataDrivingTimeHour;
extern uint8_t DataDrivingTimeMin;

#define  DATA_DRIVING_TIME_HOUR             DataDrivingTimeHour
#define  DATA_DRIVING_TIME_MIN              DataDrivingTimeMin

/*** 控制结构 ***/
typedef struct
{
  uint8_t   Init;
  uint8_t   Start;
  uint16_t  RoCBackup;
  uint16_t  Timer;
} DataDrivingTimeStruct;

/******************************************************************************
平均车速
******************************************************************************/

/*** 全局变量 ***/
extern uint8_t DataAvgSpeed;
extern uint8_t DataAvgSpeedValid;
extern uint16_t  DataDTE;
#define  DATA_AVG_SPEED                     DataAvgSpeed
#define  DATA_AVG_SPEED_VALID               DataAvgSpeedValid

/*** 参数设置 ***/
#define  DATA_AVG_SPEED_TOTAL_KM            50

/*** 控制结构 ***/
typedef struct
{
  uint16_t  MileageRoCBackup;
  uint16_t  TimeRoCBackup;
  uint16_t  Mileage[DATA_AVG_SPEED_TOTAL_KM];
  uint16_t  Time[DATA_AVG_SPEED_TOTAL_KM];
  uint16_t  MileageSample;
  uint16_t  TimeSample;
  uint8_t   Ptr;
  uint8_t   Cnt;
  uint8_t   UpdateTimer;
  uint8_t   Running;
} DataAvgSpeedStruct;


/****************************转速采样数据处理*********************************/
/******************************************************************************
全局变量
******************************************************************************/
//extern volatile uint8_t ESPWMDutyCycle;
//#define   ES_PWM_DUTY_CYCLE                 TimerCycle

/******************************************************************************
背光设置
******************************************************************************/
#define   ES_PWM_DUTY_CYCLE_FILTER          5    //接收到的占空比差大于此值认为是无效占空比
#define   ES_PWM_FILTER_MAX_CNT             10   //最大阻止接收次数
#define   ES_SAMPLE_POINT                   10   //10
#define   ES_PWM_DUTY_CYCLE_MAX             7000
#define   ES_PWM_DUTY_CYCLE_MIN             7
#define   ES_PWM_DUTY_CYCLE_HYSTERESIS      5    //回差
#define   ES_PWM_DUTY_CYCLE_APPR_FACTOR     8    //占空比逼近系数 
#define   ES_PWM_DUTY_CYCLE_APPR_SPEED      20   //占空比逼近周期,单位ms  

#define   ES_OFF_TIME_DOOR_OPEN_ONLY        150


/******************************************************************************
结构声明
******************************************************************************/
typedef struct
{
  uint8_t   Backup;
  uint16_t  Timer;
  uint16_t  HiLvTimer;
} ESPWMCaptureStruct;

typedef struct
{
  uint16_t   InitTimer;
  uint8_t    Backup;
  uint8_t    BackupCnt;
  uint16_t   Sample[ES_SAMPLE_POINT];
  uint16_t   Ptr;
  uint16_t   Cnt;
  uint8_t    Locked;
  uint16_t   Timer;
  uint16_t   Current;
} ESPWMFilterStruct;

/******************************************************************************
函数声明
******************************************************************************/

void Data_Power_On_Init(void);
void Data_IGN_On_Init(void);
void Data_Tpms_Proceser(void);

void Data_Engine_Speed_Processing_Service(void);
void Data_Vehicle_Speed_Processing_Service(void);
void Data_AirO_Level_Processing_Service(void);
void Data_AirT_Level_Processing_Service(void);
void Data_Coolant_Temp_Processing_Service(void);
void Data_Coolant_ADblue_Processing_Service(void);
void Data_Coolant_Oil_Processing_Service(void);
void Data_Drive_Info_Group1_Processing_Service(void);
void Data_Drive_Info_Group2_Processing_Service(void);
void Data_IGN_Off_Timing_Service(void);
void Data_ODO_Processing(void);
void Data_Trip_Processing(void);
void Data_Fuel_Consumption_Processing(void);
uint8_t Data_Get_Average_Fuel_Consumption(void);
void Data_Average_Fuel_Consumption_Reset(void);
void Data_DTE_Processing(void);
void Data_DTE_Init(void);
void Data_TPMS_Value_Processing(void);
void Data_Mileage_Rolling_Counter_Update_ISR(void);
void Data_Clear_TripA(void);
void Data_Clear_TripB(void);
void Data_ODO_Update_Disable(void);
#endif