mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
new: implemented can.obd2 builtin parser
This commit is contained in:
parent
cf6fba6151
commit
c3999d6bb5
11 changed files with 520 additions and 52 deletions
25
modules/can/can_obd2_pid_response.go
Normal file
25
modules/can/can_obd2_pid_response.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package can
|
||||
|
||||
import (
|
||||
"go.einride.tech/can"
|
||||
)
|
||||
|
||||
func (msg *OBD2Message) ParseResponse(frame can.Frame) bool {
|
||||
msgSize := frame.Data[0]
|
||||
// validate data size
|
||||
if msgSize > 7 {
|
||||
// fmt.Printf("invalid response size %d\n", msgSize)
|
||||
return false
|
||||
}
|
||||
|
||||
svcID := frame.Data[1] - 0x40
|
||||
|
||||
msg.Type = OBD2MessageTypeResponse
|
||||
msg.ECU = uint8(uint16(frame.ID) - uint16(OBD2ECUResponseMinID))
|
||||
msg.Size = msgSize - 3
|
||||
msg.Service = OBD2Service(svcID)
|
||||
msg.PID = lookupPID(svcID, []uint8{frame.Data[2]})
|
||||
msg.Data = frame.Data[3 : 3+msg.Size]
|
||||
|
||||
return true
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue