1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#include "Individual_ECU_Comm.h"
#include "CAN_Communication_Matrix.h"
//---------------------------------------------------------
//仪表→“守护神”ECU的通信式样 wangboyu 2021年8月3日09:48:26
//---------------------------------------------------------
//344 - 7
//---------------------------------------------------------
static const DefaultCommCode[COMM_CODE_MAX_NUM] = {0x01,0x40,0x41,0x81,0x40,0xD1,0x7F};
//typedef struct
//{
// ID18FEAE17_TYPE Data_Type[ ID18FEAE17_TYPE_MAX ] ;
// uint32_t Data[ ID18FEAE17_TYPE_MAX ] ;
//}ReqDataStruct;
static struct
{
en_CommSta CacheReqCode ;
en_CommSta ReqCode ;
en_CommSta OldReqCode ;
en_CommSta RespCode ;
uint8_t ErrCount ;
uint8_t ErrSta ;
uint8_t RevEvent ;
//------------------
ID18FEAE17_TYPE Type ;
uint32_t Data[ID18FEAE17_TYPE_MAX] ;
uint32_t ReqData[ID18FEAE17_TYPE_MAX] ;
}CommVariable ;
static void Set_ECU_ResponseCode(en_CommSta Code);
static void Set_ECU_Data(ID18FEAE17_TYPE Type,uint32_t Data);
/*-------------------------------------------------------------------------
* Function Name : Individual_ECU_Comm_KL30_Init
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
void Individual_ECU_Comm_KL30_Init(void)
{
Set_Meter_RequestCode(METER_CODE_DATA_T_REQ,ID_TripA_AvrFuelCost,0) ;
CommVariable.ErrCount = 1 ;
CommVariable.ErrSta = 0 ;
CommVariable.RevEvent = 0 ;
}
void Individual_ECU_Comm_KL15_ON_Init(void)
{
}
void Individual_ECU_Comm_KL15_OFF_Init(void)
{
}
void Individual_ECU_Comm_Wakeup_Init(void)
{
}
void Individual_ECU_Comm_Sleep_Init(void)
{
}
/*-------------------------------------------------------------------------
* Function Name : Individual_ECU_Comm_Processing_Service
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
void Individual_ECU_Comm_Processing_Service(void)
{
if(CAN_MSG_Status(ID_CanMsg18EF1718_Msg_Count) == CAN_SIG_LOST)
{
CommVariable.RevEvent = 0 ;
CommVariable.ErrCount = 0 ;
CommVariable.ErrSta = 1 ;
}
else
{
if(CommVariable.RevEvent)
{
CommVariable.RevEvent = 0 ;
if(CommVariable.OldReqCode != CommVariable.ReqCode)
{
CommVariable.OldReqCode = CommVariable.ReqCode ;
CommVariable.ErrCount = 0 ;
}
switch(CommVariable.ReqCode)
{
case METER_CODE_DATA_T_REQ :
if(CommVariable.RespCode == ECU_CODE_DATA_T_Y_RESPONSE)
{
CommVariable.ErrCount = 0 ;
CommVariable.ErrSta = 0 ;
}
else
{
if(CommVariable.ErrCount < 10)
{
CommVariable.ErrCount ++ ;
CommVariable.ErrSta = 1 ;
}
else
{
CommVariable.ErrSta = 2 ;
}
}
break ;
case METER_CODE_DATA_CLR_REQ :
if(CommVariable.RespCode == ECU_CODE_DATA_CLR_Y_RESPONSE)
{
CommVariable.ErrCount = 0 ;
CommVariable.ErrSta = 0 ;
}
else
{
if(CommVariable.ErrCount < 10)
{
CommVariable.ErrCount ++ ;
CommVariable.ErrSta = 1 ;
}
else
{
CommVariable.ErrSta = 2 ;
}
}
break ;
case METER_CODE_DATA_W_REQ :
if(CommVariable.RespCode == ECU_CODE_DATA_W_Y_RESPONSE)
{
CommVariable.ErrCount = 0 ;
CommVariable.ErrSta = 0 ;
}
else
{
if(CommVariable.ErrCount < 10)
{
CommVariable.ErrCount ++ ;
CommVariable.ErrSta = 1 ;
}
else
{
CommVariable.ErrSta = 2 ;
}
}
break ;
default :
break ;
}
}
}
}
/*-------------------------------------------------------------------------
* Function Name : RevMsg_ID18EF1718_Cbk
* Description : 放在CAN接收中断中
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
void RevMsg_ID18EF1718_Cbk(void)
{
uint8_t i = 0 ;
uint32_t Data = 0 ;
ID18FEAE17_TYPE Type = 0 ;
CommVariable.RevEvent = 1 ;
if(Get_ID_18EF1718_Sig_Response_Code() == DefaultCommCode[ECU_CODE_DATA_T_Y_RESPONSE])
{
Set_ECU_ResponseCode(ECU_CODE_DATA_T_Y_RESPONSE) ;
}
else if(Get_ID_18EF1718_Sig_Response_Code() == DefaultCommCode[ECU_CODE_DATA_CLR_Y_RESPONSE])
{
Set_ECU_ResponseCode(ECU_CODE_DATA_CLR_Y_RESPONSE) ;
}
else if(Get_ID_18EF1718_Sig_Response_Code() == DefaultCommCode[ECU_CODE_DATA_W_Y_RESPONSE])
{
Set_ECU_ResponseCode(ECU_CODE_DATA_W_Y_RESPONSE) ;
}
else
{
Set_ECU_ResponseCode(ECU_CODE_DATA_N_RESPONSE) ;
}
Type = Get_ID_18EF1718_Sig_Data_Type();
Data = Get_ID_18EF1718_Sig_Date();
for(i = 0 ;i < ID18FEAE17_TYPE_MAX;i ++)
{
if(Type == IDAE17_TYTE_DATA[i])
{
break ;
}
}
Set_ECU_Data(i,Data);
}
/*-------------------------------------------------------------------------
* Function Name : Set_Meter_RequestCode
* Description : 应用发起- 清零或复位等事件
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
void Set_Meter_RequestCode(en_CommSta Code,ID18FEAE17_TYPE Type,uint32_t Data)
{
CommVariable.CacheReqCode = Code ;
if(Code != METER_CODE_DATA_T_REQ)
{
CommVariable.Type = Type ;
CommVariable.ReqData[ Type ] = Data ;
}
}
/*-------------------------------------------------------------------------
* Function Name : Meter_RequestCode_Update
* Description : 放在CAN发送中断的首行
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
void Meter_RequestCode_Update(void)
{
if(CommVariable.CacheReqCode != CommVariable.ReqCode)
{
CommVariable.ReqCode = CommVariable.CacheReqCode ;
}
}
/*-------------------------------------------------------------------------
* Function Name : Get_Meter_RequestID
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
en_CommSta Get_Meter_RequestID(void)
{
return CommVariable.ReqCode ;
}
/*-------------------------------------------------------------------------
* Function Name : Get_Meter_RequestCode
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
uint8_t Get_Meter_RequestCode(void)
{
return DefaultCommCode[ CommVariable.ReqCode ] ;
}
/*-------------------------------------------------------------------------
* Function Name : Get_Meter_RequestType
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
ID18FEAE17_TYPE Get_Meter_RequestType(void)
{
return CommVariable.Type ;
}
/*-------------------------------------------------------------------------
* Function Name : Get_Meter_RequestData
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
uint32_t Get_Meter_RequestData(ID18FEAE17_TYPE Type)
{
return CommVariable.ReqData[ Type ] ;
}
/*-------------------------------------------------------------------------
* Function Name : Set_ECU_ResponseCode
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
static void Set_ECU_ResponseCode(en_CommSta Code)
{
CommVariable.RespCode = Code ;
}
/*-------------------------------------------------------------------------
* Function Name : Get_ECU_ResponseCode
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
static uint8_t Get_ECU_ResponseCode(void)
{
return DefaultCommCode[ CommVariable.RespCode ] ;
}
/*-------------------------------------------------------------------------
* Function Name : Set_ECU_Data
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
static void Set_ECU_Data(ID18FEAE17_TYPE Type,uint32_t Data)
{
if(Type < ID18FEAE17_TYPE_MAX)
{
CommVariable.Data[Type] = Data ;
}
}
/*-------------------------------------------------------------------------
* Function Name : Get_ECU_Data
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
uint32_t Get_ECU_Data(ID18FEAE17_TYPE Type)
{
return CommVariable.Data[Type] ;
}
/*-------------------------------------------------------------------------
* Function Name : Get_ECU_RespErr
* Description : 错误计数器状态
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
uint8_t Get_ECU_RespErr(void)
{
return CommVariable.ErrSta ;
}
/*-------------------------------------------------------------------------
* Function Name : Get_ECU_RespSure
* Description : 得到肯定应答
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
uint8_t Get_ECU_RespSure(void)
{
uint8_t u8Result = 0 ;
if(CommVariable.ErrSta == 0)
{
u8Result = 1 ;
}
return u8Result ;
}