@@ -730,6 +730,7 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
730730 msg -> id = 0xFFFFFFFFU ;
731731 msg -> sts = 1 ;
732732
733+ repeat :
733734 if (!can [handle ].mode .fdoe )
734735 rc = CAN_Read (can [handle ].board , & can_msg , & timestamp );
735736 else
@@ -786,6 +787,10 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
786787 can [handle ].counters .err ++ ;
787788 return CANERR_ERR_FRAME ; // error frame received
788789 }
790+ if ((can_msg .MSGTYPE & PCAN_MESSAGE_EXTENDED ) && can [handle ].mode .nxtd )
791+ goto repeat ; // refuse extended frames
792+ if ((can_msg .MSGTYPE & PCAN_MESSAGE_RTR ) && can [handle ].mode .nrtr )
793+ goto repeat ; // refuse remote frames
789794 msg -> id = (int32_t )can_msg .ID ;
790795 msg -> xtd = (can_msg .MSGTYPE & PCAN_MESSAGE_EXTENDED ) ? 1 : 0 ;
791796 msg -> rtr = (can_msg .MSGTYPE & PCAN_MESSAGE_RTR ) ? 1 : 0 ;
@@ -809,10 +814,15 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
809814 return CANERR_RX_EMPTY ; // receiver empty
810815 }
811816 if ((can_msg_fd .MSGTYPE & PCAN_MESSAGE_ERRFRAME )) {
817+ // TODO: encode status message (error frame)
812818 can [handle ].status .receiver_empty = 1 ;
813819 can [handle ].counters .err ++ ;
814820 return CANERR_ERR_FRAME ; // error frame received
815821 }
822+ if ((can_msg .MSGTYPE & PCAN_MESSAGE_EXTENDED ) && can [handle ].mode .nxtd )
823+ goto repeat ; // refuse extended frames
824+ if ((can_msg .MSGTYPE & PCAN_MESSAGE_RTR ) && can [handle ].mode .nrtr )
825+ goto repeat ; // refuse remote frames
816826 msg -> id = (int32_t )can_msg_fd .ID ;
817827 msg -> xtd = (can_msg_fd .MSGTYPE & PCAN_MESSAGE_EXTENDED ) ? 1 : 0 ;
818828 msg -> rtr = (can_msg_fd .MSGTYPE & PCAN_MESSAGE_RTR ) ? 1 : 0 ;
@@ -1075,8 +1085,8 @@ static TPCANStatus pcan_capability(TPCANHandle board, can_mode_t *capability)
10751085 capability -> nxtd = 1 ; // PCAN_ACCEPTANCE_FILTER_29BIT available since version 4.2.0
10761086 capability -> nrtr = 1 ; // PCAN_ALLOW_RTR_FRAMES available since version 4.2.0
10771087#else
1078- capability -> nxtd = 0 ; // This feature is not supported (TODO: acceptance filtering )
1079- capability -> nrtr = 0 ; // This feature is not supported (TODO: suppress RTR frames )
1088+ capability -> nxtd = 1 ; // Suppress XTD frames (software solution )
1089+ capability -> nrtr = 1 ; // Suppress RTR frames (software solution )
10801090#endif
10811091 capability -> err = 1 ; // PCAN_ALLOW_ERROR_FRAMES available since version 4.2.0
10821092 capability -> mon = 1 ; // PCAN_LISTEN_ONLY available since version 1.0.0
0 commit comments