Can_App.c 6.56 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
    uint8_t u8TCSVal = 0;
    u8TCSVal = Get_Dis_Tcs_Val();
19 20 21 22 23 24

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

28
        p220 -> Sig.TCS_TX = u8TCSVal;
29
        p220 -> Sig.AliveCounter = AliveCountTimer;
30
        p220 -> Sig.CheckSum = (u8TCSVal == 1) ? 8 : 0;
31 32
    }

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

112 113 114
    uint16_t u16FrontTpmsValue = Get_Front_TPMS_TX();
    uint16_t u16RearTpmsValue = Get_Rear_TPMS_TX();    

115 116
    p450 = (CANMsg450Union *)CopyData;
    if ( p450 != ( void * )0 )
李俭双's avatar
李俭双 committed
117
    {
118 119
        for ( i = 0u; i < 8u; i++ )
        {
120
            p450->Msg [ i ] = 0x0u;
121
        }
122
        if(Get_Front_TPMS_Sig_Vaild() == 0\
123 124 125
            || Get_TPMS_Front_Learn() != 2 
            || CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x373_Msg_Count) == CAN_SIG_LOST\
            || Get_Front_TPMS_ID_Vaild() == 0)
126 127 128 129 130 131
        {
            p450 -> Sig.Front_Pressure_TX_H  = 0;
            p450 -> Sig.Front_Pressure_TX_L  = 0;
        }
        else
        {
132
            if((u16FrontTpmsValue + 146) <= 1000U)
133
            {
134
                u16FrontTpms = (u16FrontTpmsValue + 146);
135 136 137 138 139 140 141
            }
            else
            {
                u16FrontTpms = 1000U;
            }
            p450 -> Sig.Front_Pressure_TX_H  = ( u16FrontTpms >> 8) & 0xFF;
            p450 -> Sig.Front_Pressure_TX_L  = ( u16FrontTpms) & 0xFF;
142
        }
143
        if(Get_Rear_TPMS_Sig_Vaild() == 0\
144 145 146
            || Get_TPMS_Rear_Learn() != 2 
            || CAN_MSG_Status(&CAN_CH0_CanMsgOp, CAN_CH0_ID_CAN_0x373_Msg_Count) == CAN_SIG_LOST\
            || Get_Rear_TPMS_ID_Vaild() == 0)
147 148 149 150 151 152
        {
            p450 -> Sig.Rear_Pressure_TX_H   = 0;
            p450 -> Sig.Rear_Pressure_TX_L   = 0;
        }
        else
        {
153
            if((u16RearTpmsValue + 146) <= 1000U)
154
            {
155
                u16RearTpms = (u16RearTpmsValue + 146);
156 157 158 159 160 161 162
            }
            else
            {
                u16RearTpms = 1000U;
            }
            p450 -> Sig.Rear_Pressure_TX_H   = (u16RearTpms >> 8) & 0xFF;
            p450 -> Sig.Rear_Pressure_TX_L   = (u16RearTpms) & 0xFF;
163 164
        }
        
李俭双's avatar
李俭双 committed
165
    }
166
    
李俭双's avatar
李俭双 committed
167
}
168
//uint8_t Can_580Send_flag = 0;
169 170 171 172
void Can_Set_Buff_580(canlib_uint8_t CopyData[])
{
    CANMsg580Union *p580;
    uint8_t i = 0;
173
    uint8_t u8TpmsFlag = Get_Tpms_TX_Flag() ;
174 175 176 177 178
    p580 = (CANMsg580Union *)CopyData;
    if ( p580 != ( void * )0 )
    {
        for ( i = 0u; i < 8u; i++ )
        {
179
            p580->Msg [ i ] = 0x0u;
180
        }
181

182
        if(u8TpmsFlag == 1)
183
        {
184 185 186 187 188 189 190
            //Can_580Send_flag = 1;
            //if(CAN_TX_Count++ > 2)
            //{
            //    Tpms_TX_Flag = 0;
            //    CAN_TX_Count = 0;
            //    //Can_580Send_flag = 0;
            //}
191 192 193 194 195
            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;
196 197 198 199 200
            //if(Can_580Send_flag == 0)
            //{
            //    Can_580Send_flag = 1;
            //    CAN_TX_Count++;
            //}
201
        }
202
        else if(u8TpmsFlag == 2)
203
        {
204 205 206 207 208 209 210
            //Can_580Send_flag = 1;
            //if(CAN_TX_Count++ > 2)
            //{
            //    Tpms_TX_Flag = 0;
            //    CAN_TX_Count = 0;
            //    //Can_580Send_flag = 0;
            //}
211 212 213 214 215
            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;
216 217 218 219 220
            //if(Can_580Send_flag == 0)
            //{
            //    Can_580Send_flag = 1;
            //    CAN_TX_Count++;
            //}
221 222 223
        }
        else
        {
224 225
            //Can_580Send_flag = 0;
            //CAN_TX_Count = 0;
226 227 228 229 230
            //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;
231
        }
232
    }
233
    
234 235

}
236

237