Can_App.c 5.11 KB
Newer Older
李俭双's avatar
李俭双 committed
1
#include "Can_App.h"
2
#include "Components.h"
3
#include "Application.h"
李俭双's avatar
李俭双 committed
4

陈家乐's avatar
陈家乐 committed
5
uint16_t CAN_TX_Count = 0;
6
uint16_t AliveCountTimer = 0;
陈家乐's avatar
陈家乐 committed
7 8 9 10
extern uint8_t Tpms_TX_Flag;
void CAN_TX_Count_Init(void)
{
    CAN_TX_Count = 0;
11
    AliveCountTimer = 0;
陈家乐's avatar
陈家乐 committed
12
}
13
void Can_Set_Buff_220(canlib_uint8_t CopyData[])
李俭双's avatar
李俭双 committed
14
{
15
    CANMsg220Union *p220;
李俭双's avatar
李俭双 committed
16
    uint8_t i = 0;
17 18 19 20 21 22

    p220 = (CANMsg220Union *)CopyData;
    if ( p220 != ( void * )0 )
    {
        for ( i = 0u; i < 8u; i++ )
        {
23
            p220->Msg [ i ] = 0x0u;
24
        }
25 26

        p220 -> Sig.TCS_TX = Get_Dis_Tcs_Val();
27 28 29 30 31 32 33 34 35 36 37
        p220 -> Sig.AliveCounter = AliveCountTimer;
        p220 -> Sig.CheckSum = (Get_Dis_Tcs_Val() == 1) ? 8 : 0;
    }

    if(AliveCountTimer < 7)
    {
        AliveCountTimer++;
    }
    else
    {
        AliveCountTimer = 0;
38
    }
39
    
40 41 42 43 44
}
void Can_Set_Buff_6EE(canlib_uint8_t CopyData[])
{
    CANMsg6EEUnion *p6EE;
    uint8_t i = 0;
45
    uint16_t Vspeed_tx = 0;
46
    uint32_t ODO_tx = Data_ODO_Read();    
47
    Vspeed_tx = Get_DispVechileSpeed_TX()/10;
48
    p6EE = (CANMsg6EEUnion *)CopyData;
李俭双's avatar
李俭双 committed
49
    
50 51 52 53
    if ( p6EE != ( void * )0 )
    {
        for ( i = 0u; i < 8u; i++ )
        {
54
            p6EE->Msg [ i ] = 0x0u;
55
        }
56 57 58 59 60 61 62 63 64 65 66 67
        p6EE -> Sig.ODO_TX_H        = (ODO_tx >> 16) & 0xFF ;
        p6EE -> Sig.ODO_TX_M        = (ODO_tx >> 8) & 0xFF ;
        p6EE -> Sig.ODO_TX_L        = ODO_tx & 0xFF ;
        if(Get_Fuel_RES() > 255)
        {
            p6EE -> Sig.Fuel_Res_TX  = 0xFF ; 
        }
        else
        {
            p6EE -> Sig.Fuel_Res_TX  = Get_Fuel_RES() ; 
        }
       
68
    } 
69 70
    //p6EE -> Sig.Vsppe_H3_TX     = (Vspeed_tx >> 8) & 0x7u ;
    //p6EE -> Sig.Vsppe_L8_TX     = Vspeed_tx & 0xFF ;
71
    
72 73 74 75 76 77 78 79 80 81 82
   // p6EE -> Sig.Uint_TX         = Get_Dis_KM_Unit() ;
   // p6EE -> Sig.Coolant_Seg_TX  = GET_DataCoolantTempSegDisp() ;
    //if (GET_DataCollantTempWarnflg() == 2)
    //{
    //    p6EE -> Sig.Coolant_Warn_TX = 1;
    //}
    //else
    //{
    //    p6EE -> Sig.Coolant_Warn_TX = 0;
    //}
    //p6EE -> Sig.Fuel_Seg_TX  = Get_CurFuelSetp() ;
83
    
84
    
85 86 87 88 89
}
void Can_Set_Buff_6EF(canlib_uint8_t CopyData[])
{
    CANMsg6EFUnion *p6EF;
    uint8_t i = 0;
90
    uint16_t Espeed_tx = 0;
91
    uint16_t TripA_tx = 0;
92
    Espeed_tx = Get_ActualEngineSpeed()/100;
93
    TripA_tx  = Data_Read_Trip(EM_TRIP_A);
94 95
    p6EF = (CANMsg6EFUnion *)CopyData;
    if ( p6EF != ( void * )0 )
李俭双's avatar
李俭双 committed
96
    {
97 98
        for ( i = 0u; i < 8u; i++ )
        {
99
            p6EF->Msg [ i ] = 0x0u;
100
        }
101 102
        p6EF -> Sig.TripA_H    = (TripA_tx >> 8) & 0xFF;
        p6EF -> Sig.TripA_L    = TripA_tx  & 0xFF;
李俭双's avatar
李俭双 committed
103
    }
104
    //p6EF -> Sig.Espeed_TX  = Espeed_tx;
105
    
李俭双's avatar
李俭双 committed
106
    //p6EF -> Sig.Coolant_TX = GET_DataCoolantTempValueDisp() + 40;
107 108 109 110 111 112 113 114
}
void Can_Set_Buff_450(canlib_uint8_t CopyData[])
{
    CANMsg450Union *p450;
    uint8_t i = 0;

    p450 = (CANMsg450Union *)CopyData;
    if ( p450 != ( void * )0 )
李俭双's avatar
李俭双 committed
115
    {
116 117
        for ( i = 0u; i < 8u; i++ )
        {
118
            p450->Msg [ i ] = 0x0u;
119
        }
120 121 122 123 124 125 126
        if(MenuData.TPMS_Front_Learn == 0)
        {
            p450 -> Sig.Front_Pressure_TX_H  = 0;
            p450 -> Sig.Front_Pressure_TX_L  = 0;
        }
        else
        {
陈家乐's avatar
陈家乐 committed
127 128
            p450 -> Sig.Front_Pressure_TX_H  = ((Get_Front_TPMS_TX() + 146) >> 8) & 0xFF;
            p450 -> Sig.Front_Pressure_TX_L  = (Get_Front_TPMS_TX() + 146) & 0xFF;
129 130 131 132 133 134 135 136
        }
        if(MenuData.TPMS_Rear_Learn == 0)
        {
            p450 -> Sig.Rear_Pressure_TX_H   = 0;
            p450 -> Sig.Rear_Pressure_TX_L   = 0;
        }
        else
        {
陈家乐's avatar
陈家乐 committed
137 138
            p450 -> Sig.Rear_Pressure_TX_H   = ((Get_Rear_TPMS_TX() + 146) >> 8) & 0xFF;
            p450 -> Sig.Rear_Pressure_TX_L   = (Get_Rear_TPMS_TX() + 146) & 0xFF;
139 140
        }
        
李俭双's avatar
李俭双 committed
141
    }
142
    
李俭双's avatar
李俭双 committed
143
}
陈家乐's avatar
陈家乐 committed
144

145 146 147 148 149 150 151 152 153 154
void Can_Set_Buff_580(canlib_uint8_t CopyData[])
{
    CANMsg580Union *p580;
    uint8_t i = 0;

    p580 = (CANMsg580Union *)CopyData;
    if ( p580 != ( void * )0 )
    {
        for ( i = 0u; i < 8u; i++ )
        {
155
            p580->Msg [ i ] = 0x0u;
156
        }
157 158 159

        if(Get_Tpms_TX_Flag() == 1)
        {
160
            if(++CAN_TX_Count > 3)
161 162 163 164
            {
                Tpms_TX_Flag = 0;
                CAN_TX_Count = 0;
            }
165 166 167 168 169 170 171 172
            p580 -> Sig.TPMS_LEARN_CND_BYTE0 = 0x31;
            p580 -> Sig.TPMS_LEARN_CND_BYTE1 = 0x01;
            p580 -> Sig.TPMS_LEARN_CND_BYTE2 = 0x59;
            p580 -> Sig.TPMS_LEARN_CND_BYTE3 = 0x08;
            p580 -> Sig.TPMS_LEARN_CND_BYTE4 = 0x00;
        }
        else if(Get_Tpms_TX_Flag() == 2)
        {
173
            if(++CAN_TX_Count > 3)
174 175 176 177
            {
                Tpms_TX_Flag = 0;
                CAN_TX_Count = 0;
            }
178 179 180 181 182 183 184 185
            p580 -> Sig.TPMS_LEARN_CND_BYTE0 = 0x31;
            p580 -> Sig.TPMS_LEARN_CND_BYTE1 = 0x01;
            p580 -> Sig.TPMS_LEARN_CND_BYTE2 = 0x59;
            p580 -> Sig.TPMS_LEARN_CND_BYTE3 = 0x08;
            p580 -> Sig.TPMS_LEARN_CND_BYTE4 = 0x01;
        }
        else
        {
186
            CAN_TX_Count = 0;
187 188 189 190 191
            //p580 -> Sig.TPMS_LEARN_CND_BYTE0 = 0x0;
            //p580 -> Sig.TPMS_LEARN_CND_BYTE1 = 0x0;
            //p580 -> Sig.TPMS_LEARN_CND_BYTE2 = 0x0;
            //p580 -> Sig.TPMS_LEARN_CND_BYTE3 = 0x0;
            //p580 -> Sig.TPMS_LEARN_CND_BYTE4 = 0x02;
192
        }
193
    }
194
    
195 196

}
197

198