2023-11-17 16:28:05 +08:00
|
|
|
|
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),
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-21 17:20:03 +08:00
|
|
|
|
func (f *BtmStatusRspFrame) Decode(cf *CanetFrame) bool {
|
|
|
|
|
f.FId = cf.CanId
|
|
|
|
|
//
|
|
|
|
|
reader := NewCanBitsReader(cf.CanData, 8)
|
2023-11-17 16:28:05 +08:00
|
|
|
|
//数据流水号
|
|
|
|
|
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
|
|
|
|
|
}
|
2023-11-21 17:20:03 +08:00
|
|
|
|
func (f *BtmStatusRspFrame) Encode() *CanetFrame {
|
|
|
|
|
cf := &CanetFrame{}
|
|
|
|
|
cf.CanId = f.FId
|
|
|
|
|
cf.CanLen = 8
|
|
|
|
|
cf.FF = true
|
|
|
|
|
cf.RTR = false
|
2023-11-17 16:28:05 +08:00
|
|
|
|
//
|
2023-11-21 17:20:03 +08:00
|
|
|
|
writer := NewCanBitsWriter(8)
|
2023-11-17 16:28:05 +08:00
|
|
|
|
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)
|
|
|
|
|
//
|
2023-11-21 17:20:03 +08:00
|
|
|
|
cf.CanData = writer.(CanBusData).GetData()
|
|
|
|
|
return cf
|
2023-11-17 16:28:05 +08:00
|
|
|
|
}
|