diff --git a/third_party/message/can_atp_req.go b/third_party/message/can_atp_req.go index 6c3ba5e..a46c4df 100644 --- a/third_party/message/can_atp_req.go +++ b/third_party/message/can_atp_req.go @@ -90,8 +90,10 @@ type AtpRequestFrame struct { Speed uint16 //当前ATP系统时间,1=1ms Time uint32 - //crc 校验 + //crc 校验码,从数据流中接收到的 Crc16 uint16 + //解码时CRC16校验结果,true-校验通过 + Crc16CheckOk bool } // NewAtpRequestFrame 创建ATP查询帧 @@ -179,9 +181,9 @@ func (f *AtpRequestFrame) Decode(bits CanBitsReader) bool { return false } //crc校验 - if f.Crc16 != crc16 { + f.Crc16CheckOk = f.Crc16 == crc16 + if !f.Crc16CheckOk { slog.Debug("解码AtpRequestFrame,CRC16校验未通过!!") - return false } // return true diff --git a/third_party/message/can_btm_status_rsp.go b/third_party/message/can_btm_status_rsp.go new file mode 100644 index 0000000..ffef805 --- /dev/null +++ b/third_party/message/can_btm_status_rsp.go @@ -0,0 +1,154 @@ +package message + +// BtmStatusRspFrame BTM发往ATP的状态应答帧 +type BtmStatusRspFrame struct { + //帧ID + FId CanFrameId + //数据流水号,0~255变化,每次加一 + Dsn byte + //应答器计数(每过一个应答器加一,在同一个应答器内不变) + BaliseCounter byte + //报文计数器(每解出一个报文加一) + MessageCounter byte + //功率放大器状态,true-1 turn on ;false-0 turn off + PowerAmplifierOn bool + //ATP查询帧CRC16校验结果,true-1校验失败,false-0校验通过 + AtpReqCrcCheckWrong bool + //功率放大器故障,true-1故障,false-0正常 + PowerAmplifierFailure bool + //天线故障,true-1故障,false-0正常 + AntennaFault bool + //BTM detailed code + DetailedCode byte + //有具体报文内容时TK A时刻填充为CD信号上升沿时刻,报文全零时TK A时刻填充为CD信号下降沿时刻。 + TkTimeA uint32 +} + +func NewBtmStatusRspFrame(sn byte) *BtmStatusRspFrame { + return &BtmStatusRspFrame{ + FId: *NewCanFrameId(CAN_ADDR_RSP_ATP, CAN_ADDR_RSP_BTM, CAN_FRAME_STATUS_RSP, sn), + } +} +func (f *BtmStatusRspFrame) Decode(reader CanBitsReader) bool { + if !f.FId.Decode(reader) { + return false + } + //数据流水号 + if d, ok := reader.ReadByte(); ok { + f.Dsn = d + } else { + return false + } + //应答器计数 + if d, ok := reader.ReadByte(); ok { + f.BaliseCounter = d + } else { + return false + } + //报文计数器 + if d, ok := reader.ReadByte(); ok { + f.MessageCounter = d + } else { + return false + } + //功率放大器状态 + if d, ok := reader.ReadBits(1); ok { + f.PowerAmplifierOn = 1 == d + } else { + return false + } + //ATP查询帧CRC16校验结果 + if d, ok := reader.ReadBits(1); ok { + f.AtpReqCrcCheckWrong = 1 == d + } else { + return false + } + //功率放大器故障 + if d, ok := reader.ReadBits(1); ok { + f.PowerAmplifierFailure = 1 == d + } else { + return false + } + //天线故障 + if d, ok := reader.ReadBits(1); ok { + f.AntennaFault = 1 == d + } else { + return false + } + //BTM detailed code + if d, ok := reader.ReadBits(4); ok { + f.DetailedCode = d + } else { + return false + } + //tk time a + tk1, tk1Ok := reader.ReadByte() + if !tk1Ok { + return false + } + tk2, tk2Ok := reader.ReadByte() + if !tk2Ok { + return false + } + tk3, tk3Ok := reader.ReadByte() + if !tk3Ok { + return false + } + tk4, tk4Ok := reader.ReadByte() + if !tk4Ok { + return false + } + f.TkTimeA = 0 + f.TkTimeA |= uint32(tk1) << 24 + f.TkTimeA |= uint32(tk2) << 16 + f.TkTimeA |= uint32(tk3) << 8 + f.TkTimeA |= uint32(tk4) + // + return true +} +func (f *BtmStatusRspFrame) Encode() CanBusData { + writer := NewCanBitsWriter(12) + // + f.FId.Encode(writer) + writer.AddByte(f.Dsn) + writer.AddByte(f.BaliseCounter) + writer.AddByte(f.MessageCounter) + // + if f.PowerAmplifierOn { + writer.AddBits(1, 1) + } else { + writer.AddBits(0, 1) + } + // + if f.AtpReqCrcCheckWrong { + writer.AddBits(1, 1) + } else { + writer.AddBits(0, 1) + } + // + if f.PowerAmplifierFailure { + writer.AddBits(1, 1) + } else { + writer.AddBits(0, 1) + } + // + if f.AntennaFault { + writer.AddBits(1, 1) + } else { + writer.AddBits(0, 1) + } + // + writer.AddBits(f.DetailedCode, 4) + //tk time a + tkMsk := uint32(0x00_00_00_ff) + tk1 := byte((f.TkTimeA >> 24) & tkMsk) + tk2 := byte((f.TkTimeA >> 16) & tkMsk) + tk3 := byte((f.TkTimeA >> 8) & tkMsk) + tk4 := byte(f.TkTimeA & tkMsk) + writer.AddByte(tk1) + writer.AddByte(tk2) + writer.AddByte(tk3) + writer.AddByte(tk4) + // + return writer.(CanBusData) +}