This commit is contained in:
xzb 2023-11-22 11:21:17 +08:00
parent bfaf00aeda
commit a267f071cb
2 changed files with 19 additions and 2 deletions

View File

@ -1,6 +1,10 @@
package message package message
import "log/slog" import (
"fmt"
"log/slog"
"strings"
)
//应答器传输模块BTM与车载ATP通信协议定义 //应答器传输模块BTM与车载ATP通信协议定义
@ -72,6 +76,19 @@ func NewAtpRequestFrame(sn byte) *AtpRequestFrame {
FId: *NewCanFrameId(CAN_ADDR_REQ_BTM, CAN_ADDR_REQ_ATP, CAN_FRAME_ATP_REQ, sn), FId: *NewCanFrameId(CAN_ADDR_REQ_BTM, CAN_ADDR_REQ_ATP, CAN_FRAME_ATP_REQ, sn),
} }
} }
func (f *AtpRequestFrame) String() string {
sb := strings.Builder{}
sb.WriteString(fmt.Sprintf("AtpRequestFrame ID1 = 0x%0x, ID2 = 0x%0x, ID3 = 0x%0x, ID4 = 0x%0x,",
f.FId.ID1, f.FId.ID2, f.FId.ID3, f.FId.ID4))
sb.WriteString(fmt.Sprintf("PowerAmplifierTurnOn = %t", f.PowerAmplifierTurnOn))
sb.WriteString(fmt.Sprintf(",PowerAmplifierControlledByAtp = %t", f.PowerAmplifierControlledByAtp))
sb.WriteString(fmt.Sprintf(",ResendRequest = %d", f.ResendRequest))
sb.WriteString(fmt.Sprintf(",Speed = %d", f.Speed))
sb.WriteString(fmt.Sprintf(",Time = %d", f.Time))
sb.WriteString(fmt.Sprintf(",Crc16 = %d", f.Crc16))
sb.WriteString(fmt.Sprintf(",Crc16CheckOk = %t", f.Crc16CheckOk))
return sb.String()
}
func (f *AtpRequestFrame) Decode(cf *CanetFrame) bool { func (f *AtpRequestFrame) Decode(cf *CanetFrame) bool {
f.FId = cf.CanId f.FId = cf.CanId
// //

View File

@ -62,7 +62,7 @@ func (p *CanetFrame) Decode(buf []byte) {
} }
func (p *CanetFrame) String() string { func (p *CanetFrame) String() string {
sb := strings.Builder{} sb := strings.Builder{}
sb.WriteString(fmt.Sprintf("FF = %t, RTR = %t, CanLen = %d, ID1 = 0x%0x, ID2 = 0x%0x, ID3 = 0x%0x, ID4 = 0x%0x,", p.FF, p.RTR, p.CanLen, sb.WriteString(fmt.Sprintf("CanetFrame FF = %t, RTR = %t, CanLen = %d, ID1 = 0x%0x, ID2 = 0x%0x, ID3 = 0x%0x, ID4 = 0x%0x,", p.FF, p.RTR, p.CanLen,
p.CanId.ID1, p.CanId.ID2, p.CanId.ID3, p.CanId.ID4)) p.CanId.ID1, p.CanId.ID2, p.CanId.ID3, p.CanId.ID4))
sb.WriteString("CanData = ") sb.WriteString("CanData = ")
for _, d := range p.CanData { for _, d := range p.CanData {