@@ -462,5 +462,37 @@ describe('CAN Processor Unit Tests', () => {
462462 expect ( chargerCmd ?. messageName ) . toBe ( 'Charger_Command' ) ;
463463 expect ( chargerSts ?. messageName ) . toBe ( 'Charger_Status' ) ;
464464 } ) ;
465+
466+ it ( 'should handle IDs that already have the EFF bit set' , ( ) => {
467+ const CHARGER_CMD_DBC_ID = 2550588916 ; // 0x9806E5F4
468+ const data = [ 0x68 , 0x10 , 0x64 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ;
469+ const result = decodeCanMessage ( can , CHARGER_CMD_DBC_ID , data , 7000 ) ;
470+ expect ( result ) . not . toBeNull ( ) ;
471+ expect ( result ?. messageName ) . toBe ( 'Charger_Command' ) ;
472+ } ) ;
473+
474+ it ( 'should handle negative IDs (if bridge sends signed uint32)' , ( ) => {
475+ const CHARGER_CMD_SIGNED_ID = - 1744378380 ; // 0x9806E5F4 as signed 32-bit
476+ const data = [ 0x68 , 0x10 , 0x64 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ;
477+ const result = decodeCanMessage ( can , CHARGER_CMD_SIGNED_ID , data , 8000 ) ;
478+
479+ // With the new fallback, this should now be decoded correctly
480+ expect ( result ) . not . toBeNull ( ) ;
481+ expect ( result ?. messageName ) . toBe ( 'Charger_Command' ) ;
482+ } ) ;
483+
484+ it ( 'should handle small extended IDs using fallback' , ( ) => {
485+ // If we have an extended message with ID 0x123 in DBC,
486+ // but we send it as standard ID 0x123.
487+ // (Note: example.dbc doesn't have this, but we can simulate the logic)
488+ // For now, testing that EFF bit toggling works for known IDs.
489+ const CHARGER_CMD_WITHOUT_EFF = 0x1806E5F4 ; // Raw arbitration ID
490+ const data = [ 0x68 , 0x10 , 0x64 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ;
491+ const result = decodeCanMessage ( can , CHARGER_CMD_WITHOUT_EFF , data , 9000 ) ;
492+
493+ expect ( result ) . not . toBeNull ( ) ;
494+ expect ( result ?. messageName ) . toBe ( 'Charger_Command' ) ;
495+ expect ( result ?. canId ) . toBe ( 2550588916 ) ; // Should return the DBC ID
496+ } ) ;
465497 } ) ;
466498} ) ;
0 commit comments