github.com/blueinnovationsgroup/can-go@v0.0.0-20230518195432-d0567cda0028/pkg/socketcan/errorframe.go (about) 1 package socketcan 2 3 import ( 4 "encoding/hex" 5 "fmt" 6 ) 7 8 type ErrorFrame struct { 9 // Class is the error class 10 ErrorClass ErrorClass 11 // LostArbitrationBit contains the bit number when the error class is LostArbitration. 12 LostArbitrationBit uint8 13 // ControllerError contains error information when the error class is Controller. 14 ControllerError ControllerError 15 // ProtocolViolationError contains error information when the error class is Protocol. 16 ProtocolError ProtocolViolationError 17 // ProtocolViolationErrorLocation contains error location when the error class is Protocol. 18 ProtocolViolationErrorLocation ProtocolViolationErrorLocation 19 // TransceiverError contains error information when the error class is Transceiver. 20 TransceiverError TransceiverError 21 // ControllerSpecificInformation contains controller-specific additional error information. 22 ControllerSpecificInformation [3]byte 23 } 24 25 func (e *ErrorFrame) String() string { 26 switch e.ErrorClass { 27 case ErrorClassLostArbitration: 28 return fmt.Sprintf( 29 "%s in bit %d (%s)", 30 e.ErrorClass, 31 e.LostArbitrationBit, 32 hex.EncodeToString(e.ControllerSpecificInformation[:]), 33 ) 34 case ErrorClassController: 35 return fmt.Sprintf( 36 "%s: %s (%v)", 37 e.ErrorClass, 38 e.ControllerError, 39 hex.EncodeToString(e.ControllerSpecificInformation[:]), 40 ) 41 case ErrorClassProtocolViolation: 42 return fmt.Sprintf( 43 "%s: %s: location %s (%v)", 44 e.ErrorClass, 45 e.ProtocolError, 46 e.ProtocolViolationErrorLocation, 47 hex.EncodeToString(e.ControllerSpecificInformation[:]), 48 ) 49 case ErrorClassTransceiver: 50 return fmt.Sprintf( 51 "%s: %s (%v)", 52 e.ErrorClass, 53 e.TransceiverError, 54 hex.EncodeToString(e.ControllerSpecificInformation[:]), 55 ) 56 default: 57 return fmt.Sprintf( 58 "%s (%v)", 59 e.ErrorClass, 60 hex.EncodeToString(e.ControllerSpecificInformation[:]), 61 ) 62 } 63 }