From ef4ba6a7e195e7573ede0b4f62aaa5fc4d09f2e4 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Fri, 17 Nov 2023 17:10:15 +0800 Subject: [PATCH 1/2] balise btm --- third_party/message/can_btm_time_sync_rsp.go | 97 ++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 third_party/message/can_btm_time_sync_rsp.go diff --git a/third_party/message/can_btm_time_sync_rsp.go b/third_party/message/can_btm_time_sync_rsp.go new file mode 100644 index 0000000..77afddd --- /dev/null +++ b/third_party/message/can_btm_time_sync_rsp.go @@ -0,0 +1,97 @@ +package message + +// BtmTimeSyncCheckFrame BTM发往ATP的时间校验帧 +type BtmTimeSyncCheckFrame struct { + //帧ID + FId CanFrameId + //T2时刻 + //当收到某一流水号的ATP查询帧后,BTM将记录接收到该查询帧的时间值做为T2时刻。 + T2 uint32 + //T3时刻 + //BTM将在T3时刻发送回复帧给ATP,并保持流水号与ATP查询帧一致。 + T3 uint32 +} + +func NewBtmTimeSyncCheckFrame(sn byte) *BtmTimeSyncCheckFrame { + return &BtmTimeSyncCheckFrame{ + FId: *NewCanFrameId(CAN_ADDR_RSP_ATP, CAN_ADDR_RSP_BTM, CAN_FRAME_TIME_SYNC_RSP, sn), + } +} +func (f *BtmTimeSyncCheckFrame) Decode(reader CanBitsReader) bool { + // + if !f.FId.Decode(reader) { + return false + } + //T2 + t21, t21Ok := reader.ReadByte() + if !t21Ok { + return false + } + t22, t22Ok := reader.ReadByte() + if !t22Ok { + return false + } + t23, t23Ok := reader.ReadByte() + if !t23Ok { + return false + } + t24, t24Ok := reader.ReadByte() + if !t24Ok { + return false + } + f.T2 = 0 + f.T2 |= uint32(t21) << 24 + f.T2 |= uint32(t22) << 16 + f.T2 |= uint32(t23) << 8 + f.T2 |= uint32(t24) + //T3 + t31, t31Ok := reader.ReadByte() + if !t31Ok { + return false + } + t32, t32Ok := reader.ReadByte() + if !t32Ok { + return false + } + t33, t33Ok := reader.ReadByte() + if !t33Ok { + return false + } + t34, t34Ok := reader.ReadByte() + if !t34Ok { + return false + } + f.T3 = 0 + f.T3 |= uint32(t31) << 24 + f.T3 |= uint32(t32) << 16 + f.T3 |= uint32(t33) << 8 + f.T3 |= uint32(t34) + // + return true +} +func (f *BtmTimeSyncCheckFrame) Encode() CanBusData { + writer := NewCanBitsWriter(12) + f.FId.Encode(writer) + // + timeByteMsk := uint32(0x00_00_00_ff) + //t2 + t21 := byte((f.T2 >> 24) & timeByteMsk) + t22 := byte((f.T2 >> 16) & timeByteMsk) + t23 := byte((f.T2 >> 8) & timeByteMsk) + t24 := byte(f.T2 & timeByteMsk) + writer.AddByte(t21) + writer.AddByte(t22) + writer.AddByte(t23) + writer.AddByte(t24) + //t3 + t31 := byte((f.T3 >> 24) & timeByteMsk) + t32 := byte((f.T3 >> 16) & timeByteMsk) + t33 := byte((f.T3 >> 8) & timeByteMsk) + t34 := byte(f.T3 & timeByteMsk) + writer.AddByte(t31) + writer.AddByte(t32) + writer.AddByte(t33) + writer.AddByte(t34) + // + return writer.(CanBusData) +} From 268e93ca88b736ca0ec0e87c56896c261c380a18 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Fri, 17 Nov 2023 18:00:53 +0800 Subject: [PATCH 2/2] balise btm --- third_party/message/can_btm_data.go | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 third_party/message/can_btm_data.go diff --git a/third_party/message/can_btm_data.go b/third_party/message/can_btm_data.go new file mode 100644 index 0000000..d4f1854 --- /dev/null +++ b/third_party/message/can_btm_data.go @@ -0,0 +1,46 @@ +package message + +//数据帧(0x80+扩展类型),一个CAN帧只能存储8个字节,对于一个应答器报文,分片到多个CAN数据帧中 + +// BtmDataMessageFrame 数据帧-应答器报文 +// offset = [0x00,0x0c] 共13个即可用于存储应答器报文的共104个字节 +type BtmDataMessageFrame struct { + //帧ID + FId CanFrameId + //8字节,应答器报文片段 + Message []byte +} + +// BtmDataMessageTimeAFrame 数据帧-时间戳A +// offset = 0x0d +type BtmDataMessageTimeAFrame struct { + //帧ID + FId CanFrameId + //时间戳A + TimeA uint32 + //CRC + Crc32A uint32 +} + +// BtmDataMessageTimeBFrame 数据帧-时间戳B +// offset = 0x0e +type BtmDataMessageTimeBFrame struct { + //帧ID + FId CanFrameId + //时间戳B + TimeB uint32 + //CRC + Crc32B uint32 +} + +// BtmDataMessageEndFrame 数据帧-结束 +// offset = 0x7f +type BtmDataMessageEndFrame struct { + //帧ID + FId CanFrameId + //TK time B + TkB uint32 + //CRC32C校验包含对状态应答帧与数据帧的总校验,总共为8×17-4=132字节,4-即Crc32C + //1个状态应答帧 + 13个BtmDataMessageFrame + 1个BtmDataMessageTimeAFrame + 1个BtmDataMessageTimeBFrame + 1个BtmDataMessageEndFrame + Crc32C uint32 +}