@@ -242,14 +242,26 @@ START_TEST (test_autoset_pid_length)
242
242
arbitration_id : 0x100 ,
243
243
mode : 0x22 ,
244
244
has_pid : true,
245
- pid : 2 ,
245
+ pid : 0x1234 ,
246
246
no_frame_padding : true
247
247
};
248
248
diagnostic_request (& SHIMS , & request , response_received_handler );
249
249
250
250
ck_assert_int_eq (last_can_frame_sent_arb_id , request .arbitration_id );
251
251
ck_assert_int_eq (last_can_payload_sent [1 ], request .mode );
252
+ ck_assert_int_eq (last_can_payload_sent [2 ], (request .pid & 0xFF00 ) >> 8 );
253
+ ck_assert_int_eq (last_can_payload_sent [3 ], request .pid & 0xFF );
252
254
ck_assert_int_eq (last_can_payload_size , 4 );
255
+
256
+ request .arbitration_id = 0x101 ;
257
+ request .pid = 0x12 ;
258
+
259
+ diagnostic_request (& SHIMS , & request , response_received_handler );
260
+
261
+ ck_assert_int_eq (last_can_frame_sent_arb_id , request .arbitration_id );
262
+ ck_assert_int_eq (last_can_payload_sent [1 ], request .mode );
263
+ ck_assert_int_eq (last_can_payload_sent [2 ], request .pid );
264
+ ck_assert_int_eq (last_can_payload_size , 3 );
253
265
}
254
266
END_TEST
255
267
@@ -279,10 +291,10 @@ START_TEST (test_request_pid_enhanced)
279
291
{
280
292
uint16_t arb_id = 0x100 ;
281
293
DiagnosticRequestHandle handle = diagnostic_request_pid (& SHIMS ,
282
- DIAGNOSTIC_ENHANCED_PID , arb_id , 0x2 , response_received_handler );
294
+ DIAGNOSTIC_ENHANCED_PID , arb_id , 0x1234 , response_received_handler );
283
295
284
296
fail_if (last_response_was_received );
285
- const uint8_t can_data [] = {0x4 , 0x22 + 0x40 , 0x0 , 0x2 , 0x45 };
297
+ const uint8_t can_data [] = {0x4 , 0x22 + 0x40 , 0x12 , 0x34 , 0x45 };
286
298
diagnostic_receive_can_frame (& SHIMS , & handle , arb_id + 0x8 , can_data ,
287
299
sizeof (can_data ));
288
300
fail_unless (last_response_was_received );
@@ -291,7 +303,7 @@ START_TEST (test_request_pid_enhanced)
291
303
arb_id + 0x8 );
292
304
ck_assert_int_eq (last_response_received .mode , 0x22 );
293
305
fail_unless (last_response_received .has_pid );
294
- ck_assert_int_eq (last_response_received .pid , 0x2 );
306
+ ck_assert_int_eq (last_response_received .pid , 0x1234 );
295
307
ck_assert_int_eq (last_response_received .payload_length , 1 );
296
308
ck_assert_int_eq (last_response_received .payload [0 ], can_data [4 ]);
297
309
}
@@ -301,10 +313,10 @@ START_TEST (test_wrong_mode_response)
301
313
{
302
314
uint16_t arb_id = 0x100 ;
303
315
DiagnosticRequestHandle handle = diagnostic_request_pid (& SHIMS ,
304
- DIAGNOSTIC_ENHANCED_PID , arb_id , 0x2 , response_received_handler );
316
+ DIAGNOSTIC_ENHANCED_PID , arb_id , 0x1234 , response_received_handler );
305
317
306
318
fail_if (last_response_was_received );
307
- const uint8_t can_data [] = {0x4 , 0x1 + 0x40 , 0x0 , 0x2 , 0x45 };
319
+ const uint8_t can_data [] = {0x4 , 0x1 + 0x40 , 0x12 , 0x34 , 0x45 };
308
320
diagnostic_receive_can_frame (& SHIMS , & handle , arb_id + 0x8 , can_data ,
309
321
sizeof (can_data ));
310
322
fail_if (last_response_was_received );
@@ -316,7 +328,7 @@ START_TEST (test_missing_pid)
316
328
{
317
329
uint16_t arb_id = 0x100 ;
318
330
DiagnosticRequestHandle handle = diagnostic_request_pid (& SHIMS ,
319
- DIAGNOSTIC_ENHANCED_PID , arb_id , 0x2 , response_received_handler );
331
+ DIAGNOSTIC_ENHANCED_PID , arb_id , 0x1234 , response_received_handler );
320
332
321
333
fail_if (last_response_was_received );
322
334
const uint8_t can_data [] = {0x1 , 0x22 + 0x40 };
@@ -331,10 +343,10 @@ START_TEST (test_wrong_pid_response)
331
343
{
332
344
uint16_t arb_id = 0x100 ;
333
345
DiagnosticRequestHandle handle = diagnostic_request_pid (& SHIMS ,
334
- DIAGNOSTIC_ENHANCED_PID , arb_id , 0x2 , response_received_handler );
346
+ DIAGNOSTIC_ENHANCED_PID , arb_id , 0x1234 , response_received_handler );
335
347
336
348
fail_if (last_response_was_received );
337
- const uint8_t can_data [] = {0x4 , 0x22 + 0x40 , 0x0 , 0x3 , 0x45 };
349
+ const uint8_t can_data [] = {0x4 , 0x22 + 0x40 , 0x12 , 0x33 , 0x45 };
338
350
diagnostic_receive_can_frame (& SHIMS , & handle , arb_id + 0x8 , can_data ,
339
351
sizeof (can_data ));
340
352
fail_if (last_response_was_received );
@@ -346,23 +358,23 @@ START_TEST (test_wrong_pid_then_right_completes)
346
358
{
347
359
uint16_t arb_id = 0x100 ;
348
360
DiagnosticRequestHandle handle = diagnostic_request_pid (& SHIMS ,
349
- DIAGNOSTIC_ENHANCED_PID , arb_id , 0x2 , response_received_handler );
361
+ DIAGNOSTIC_ENHANCED_PID , arb_id , 0x1234 , response_received_handler );
350
362
351
363
fail_if (last_response_was_received );
352
- uint8_t can_data [] = {0x4 , 0x22 + 0x40 , 0x0 , 0x3 , 0x45 };
364
+ uint8_t can_data [] = {0x4 , 0x22 + 0x40 , 0x12 , 0x33 , 0x45 };
353
365
diagnostic_receive_can_frame (& SHIMS , & handle , arb_id + 0x8 , can_data ,
354
366
sizeof (can_data ));
355
367
fail_if (last_response_was_received );
356
368
fail_if (handle .completed );
357
369
358
- can_data [3 ] = 0x2 ;
370
+ can_data [3 ] = 0x34 ;
359
371
diagnostic_receive_can_frame (& SHIMS , & handle , arb_id + 0x8 , can_data ,
360
372
sizeof (can_data ));
361
373
fail_unless (last_response_was_received );
362
374
fail_unless (handle .completed );
363
375
fail_unless (handle .success );
364
376
fail_unless (last_response_received .success );
365
- ck_assert_int_eq (last_response_received .pid , 0x2 );
377
+ ck_assert_int_eq (last_response_received .pid , 0x1234 );
366
378
}
367
379
END_TEST
368
380
@@ -407,6 +419,65 @@ START_TEST (test_payload_to_integer)
407
419
}
408
420
END_TEST
409
421
422
+ START_TEST (test_response_multi_frame )
423
+ {
424
+ DiagnosticRequest request = {
425
+ arbitration_id : 0x100 ,
426
+ mode : OBD2_MODE_VEHICLE_INFORMATION ,
427
+ has_pid : true,
428
+ pid : 0x2
429
+ };
430
+ DiagnosticRequestHandle handle = diagnostic_request (& SHIMS , & request ,
431
+ response_received_handler );
432
+
433
+ const uint8_t can_data [] = {0x10 , 0x14 , 0x9 + 0x40 , 0x2 , 0x1 , 0x31 , 0x46 , 0x4d };
434
+ DiagnosticResponse response = diagnostic_receive_can_frame (& SHIMS , & handle ,
435
+ request .arbitration_id + 0x8 , can_data , sizeof (can_data ));
436
+
437
+ fail_unless (can_frame_was_sent );
438
+ fail_unless (!response .success );
439
+ fail_unless (!response .completed );
440
+ fail_unless (response .multi_frame );
441
+ ck_assert_int_eq (last_can_frame_sent_arb_id , request .arbitration_id );
442
+ ck_assert_int_eq (last_can_payload_sent [0 ], 0x30 );
443
+
444
+ const uint8_t can_data_1 [] = {0x21 , 0x43 , 0x55 , 0x39 , 0x4a , 0x39 , 0x34 , 0x48 };
445
+ response = diagnostic_receive_can_frame (& SHIMS , & handle ,
446
+ request .arbitration_id + 0x8 , can_data_1 , sizeof (can_data_1 ));
447
+ fail_unless (!response .success );
448
+ fail_unless (!response .completed );
449
+ fail_unless (response .multi_frame );
450
+
451
+ const uint8_t can_data_2 [] = {0x22 , 0x55 , 0x41 , 0x30 , 0x34 , 0x35 , 0x32 , 0x34 };
452
+ response = diagnostic_receive_can_frame (& SHIMS , & handle ,
453
+ request .arbitration_id + 0x8 , can_data_2 , sizeof (can_data_2 ));
454
+ fail_unless (response .success );
455
+ fail_unless (response .completed );
456
+ fail_unless (response .multi_frame );
457
+ ck_assert_int_eq (response .mode , OBD2_MODE_VEHICLE_INFORMATION );
458
+ ck_assert_int_eq (response .pid , 0x2 );
459
+ ck_assert_int_eq (response .payload_length , 18 );
460
+ ck_assert_int_eq (response .payload [0 ], 0x01 );
461
+ ck_assert_int_eq (response .payload [1 ], 0x31 );
462
+ ck_assert_int_eq (response .payload [2 ], 0x46 );
463
+ ck_assert_int_eq (response .payload [3 ], 0x4d );
464
+ ck_assert_int_eq (response .payload [4 ], 0x43 );
465
+ ck_assert_int_eq (response .payload [5 ], 0x55 );
466
+ ck_assert_int_eq (response .payload [6 ], 0x39 );
467
+ ck_assert_int_eq (response .payload [7 ], 0x4a );
468
+ ck_assert_int_eq (response .payload [8 ], 0x39 );
469
+ ck_assert_int_eq (response .payload [9 ], 0x34 );
470
+ ck_assert_int_eq (response .payload [10 ], 0x48 );
471
+ ck_assert_int_eq (response .payload [11 ], 0x55 );
472
+ ck_assert_int_eq (response .payload [12 ], 0x41 );
473
+ ck_assert_int_eq (response .payload [13 ], 0x30 );
474
+ ck_assert_int_eq (response .payload [14 ], 0x34 );
475
+ ck_assert_int_eq (response .payload [15 ], 0x35 );
476
+ ck_assert_int_eq (response .payload [16 ], 0x32 );
477
+ ck_assert_int_eq (response .payload [17 ], 0x34 );
478
+ }
479
+ END_TEST
480
+
410
481
Suite * testSuite (void ) {
411
482
Suite * s = suite_create ("uds" );
412
483
TCase * tc_core = tcase_create ("core" );
@@ -429,6 +500,7 @@ Suite* testSuite(void) {
429
500
tcase_add_test (tc_core , test_wrong_pid_then_right_completes );
430
501
tcase_add_test (tc_core , test_negative_response );
431
502
tcase_add_test (tc_core , test_payload_to_integer );
503
+ tcase_add_test (tc_core , test_response_multi_frame );
432
504
433
505
// TODO these are future work:
434
506
// TODO test request MIL
0 commit comments