[修改]11号线信号机联锁通信bug

This commit is contained in:
thesai 2024-10-21 14:47:58 +08:00
parent c6fe82c7e6
commit 7ee68a4ae8
3 changed files with 79 additions and 83 deletions

View File

@ -11,7 +11,6 @@ const ( //不知道对不对,问也不回,先瞎写吧
)
const (
SignalAspect_No = 0x99 //灭灯,这个值目前未知,先用一个应该没被使用的值占位
SignalAspect_H = 0x01 //红灯
SignalAspect_L = 0x04 //绿灯
SignalAspect_U = 0x02 //黄灯

View File

@ -9,7 +9,7 @@ import (
)
func TestFromInterlockFrame_Decode(t *testing.T) {
str := "58bea4c65e0e583f5bdedc310800450000c9d0770000801100003d0b0a0d3d0b7814413c40d800b5fcfd8200a63c0363010003000400000500000900000200040000080000020004aaaa0008aaaa0000000f000d06000e01000f060010060021060023060011060012060026060027010013060014010022060024060025060010001300001400001500001600001700001800001900001a00002c00002d00002e00002f00003000003100003200003300000000000004000daaaa000eaaaa000faaaa0010aaaa00000000000000000000000058f24545"
str := "58bea4c65e0e583f5bdedc310800450000c949950000801100003d0b0a0d3d0b7814413c40d800b5fcfd8200a63c0363010003000400000500000900000200040000080000020004aaaa0008aaaa0000000f000d01000e01000f060010060021060023010011060012060026060027010013060014010022060024060025010010001300001400001500001600001700001800001900001a00002c00002d00002e00002f00003000003100003200003300000000000004000daaaa000eaaaa000faaaa0010aaaa0000000000000000000000007a91cfc2"
data, err := hex.DecodeString(str)
if err != nil {
t.Fatal(err)
@ -112,7 +112,7 @@ func TestFromInterlockFrame_Decode(t *testing.T) {
}
func TestToInterlockFrame_Decode(t *testing.T) {
str := "583f5bdedc3158bea4c65e0e080045000172b52c4000401188173d0b78143d0b0a0d40d8413c015ebe7f83014f63013c0200030004010005010009020006000202eeaaaaaa000302eeaaaaaa000402eeaaaaaa000602eeaaaaaa000702eeaaaaaa000802eeaaaaaa00060002aaaa0003aaaa0004aaaa0006aaaa0007aaaa0008aaaa0000001b000800000900000a00000b00000c00000d06000e01000f06001006001106001206001306001401001c00001d00001e00001f00002000002106002206002306002406002506002606002701002800002b00001e000b00000c00000d00000e00000f00001000001100001200001300001400001500001600001700001800001900001a00002600002700002800002900002a00002b00002c00002d00002e00002f0000300000310000320000330000000000000c0005aaaa0006aaaa0007aaaa0008aaaa0009aaaa000aaaaa000baaaa000caaaa000daaaa000eaaaa000faaaa0010aaaa00000100000000000000000000000000000000328ef0af"
str := "583f5bdedc315871778a9d89080045000172f6950000801146ae3d0b78143d0b0a0d40d8413c015ef35583014f63013c0200030004010005010009010006000202eeaaaaaa000302eeaaaaaa000402eeaaaaaa000602eeaaaaaa000702eeaaaaaa000802eeaaaaaa00060002aa000003aa000004aa000006aa000007aa000008aa000000001b000806000901000a06000b06000c06000d06000e01000f06001006001106001206001306001401001c01001d06001e01001f06002006002106002206002306002406002506002606002701002801002b01001e000b00000c00000d00000e00000f00001000001100001200001300001400001500001600001700001800001900001a00002600002700002800002900002a00002b00002c00002d00002e00002f0000300000310000320000330000000000000c0005aaff0006aaff0007aaff0008aaff0009aaff000aaaff000baaff000caaff000daaff000eaaff000faaff0010aa0400000100000000000000000000000000000000a0313220"
data, err := hex.DecodeString(str)
if err != nil {
t.Fatal(err)

View File

@ -203,9 +203,6 @@ func (s *serviceContext) handleDriveMsg(data []byte) {
if entry.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机
signal2XH1 := component.Signal2XH1ElectronicType.Get(entry)
switch cmd.Cmd {
case SignalAspect_No:
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_LXJ).Id, false)
case SignalAspect_H:
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_DDJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_LXJ).Id, false)
@ -213,16 +210,12 @@ func (s *serviceContext) handleDriveMsg(data []byte) {
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_DDJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_LXJ).Id, true)
default:
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_LXJ).Id, false)
}
} else if entry.HasComponent(component.Signal3XH1ElectronicType) { // 3XH1信号机
signal3XH1 := component.Signal3XH1ElectronicType.Get(entry)
switch cmd.Cmd {
case SignalAspect_No:
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_ZXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_YXJ).Id, false)
case SignalAspect_H:
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_DDJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_LXJ).Id, false)
@ -244,15 +237,14 @@ func (s *serviceContext) handleDriveMsg(data []byte) {
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_ZXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_YXJ).Id, true)
default:
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_ZXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_YXJ).Id, false)
}
} else if entry.HasComponent(component.Signal3XH2ElectronicType) { // 3XH2信号机
signal3XH2 := component.Signal3XH2ElectronicType.Get(entry)
switch cmd.Cmd {
case SignalAspect_No:
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_YXJ).Id, false)
case SignalAspect_H:
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_DDJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_LXJ).Id, false)
@ -266,15 +258,13 @@ func (s *serviceContext) handleDriveMsg(data []byte) {
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_YXJ).Id, true)
default:
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_YXJ).Id, false)
}
} else if entry.HasComponent(component.Signal3XH3ElectronicType) { // 3XH3信号机
signal3XH3 := component.Signal3XH3ElectronicType.Get(entry)
switch cmd.Cmd {
case SignalAspect_No:
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_YXJ).Id, false)
case SignalAspect_H:
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_DDJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_LXJ).Id, false)
@ -288,15 +278,13 @@ func (s *serviceContext) handleDriveMsg(data []byte) {
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_YXJ).Id, true)
default:
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_YXJ).Id, false)
}
} else if entry.HasComponent(component.Signal3XH4ElectronicType) { // 3XH4信号机
signal3XH4 := component.Signal3XH4ElectronicType.Get(entry)
switch cmd.Cmd {
case SignalAspect_No:
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_ZXJ).Id, false)
case SignalAspect_H:
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_DDJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_LXJ).Id, false)
@ -310,24 +298,29 @@ func (s *serviceContext) handleDriveMsg(data []byte) {
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_LXJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_ZXJ).Id, false)
default:
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_DDJ).Id, true)
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_LXJ).Id, false)
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_ZXJ).Id, false)
}
} else {
logger().Error(fmt.Sprintf("信号机[%s]的型号未知", uid))
}
}
{ //采集状态赋值
signalAspectMap := make(map[uint16]byte)
for _, cmd := range frame.SignalData.CmdList {
signalAspectMap[cmd.Id] = cmd.Cmd
}
for _, interlockFrame := range s.toInterlockFrames {
for _, state := range interlockFrame.SignalStates {
state.State = signalAspectMap[state.Id]
}
}
}
//{ //采集状态赋值
// signalAspectMap := make(map[uint16]byte)
// for _, cmd := range frame.SignalData.CmdList {
// signalAspectMap[cmd.Id] = cmd.Cmd
// }
// for _, interlockFrame := range s.toInterlockFrames {
// for _, state := range interlockFrame.SignalStates {
// b := signalAspectMap[state.Id]
// if b != 0 {
// state.State = b
// }
// }
// }
//}
for _, cmd := range frame.AxleSectionData.CmdList {
if cmd.Cmd == 0x80 {
uid := s.deviceTable.AxleSectionMap[cmd.Id].uid
@ -667,50 +660,54 @@ func (s *serviceContext) collectDeviceState() {
state.State = GetStateByte(!component.BitStateType.Get(relay).Val)
state.PlState = GetStateByte(component.BitStateType.Get(pla).Val)
}
////信号机
//for _, state := range frame.SignalStates {
// row := s.deviceTable.SignalMap[state.Id]
// entry := wd.EntityMap[row.uid]
// lights := component.SignalLightsType.Get(entry)
// isL := false
// isH := false
// isU := false
// isA := false
// isB := false
// for _, light := range lights.Lights {
// switch {
// case light.HasComponent(component.LdTag):
// isL = component.BitStateType.Get(light).Val
// case light.HasComponent(component.HdTag):
// isH = component.BitStateType.Get(light).Val
// case light.HasComponent(component.UdTag):
// isU = component.BitStateType.Get(light).Val
// case light.HasComponent(component.BdTag):
// isB = component.BitStateType.Get(light).Val
// case light.HasComponent(component.AdTag):
// isA = component.BitStateType.Get(light).Val
// }
// }
// var stateByte byte
// if isH && isU {
// stateByte = 0x03
// } else {
// switch {
// case isL:
// stateByte = 0x04
// case isH:
// stateByte = 0x01
// case isU:
// stateByte = 0x02
// case isB:
// stateByte = 0x08
// case isA:
// stateByte = 0x09
// }
// }
//
// state.State = stateByte
//}
//信号机
for _, state := range frame.SignalStates {
row := s.deviceTable.SignalMap[state.Id]
entry := wd.EntityMap[row.uid]
if entry == nil {
continue
}
lights := component.SignalLightsType.Get(entry)
isL := false
isH := false
isU := false
isA := false
isB := false
for _, light := range lights.Lights {
switch {
case light.HasComponent(component.LdTag):
isL = component.BitStateType.Get(light).Val
case light.HasComponent(component.HdTag):
isH = component.BitStateType.Get(light).Val
case light.HasComponent(component.UdTag):
isU = component.BitStateType.Get(light).Val
case light.HasComponent(component.BdTag):
isB = component.BitStateType.Get(light).Val
case light.HasComponent(component.AdTag):
isA = component.BitStateType.Get(light).Val
}
}
var stateByte byte
if isH && isU {
stateByte = 0x03
} else {
switch {
case isL:
stateByte = 0x04
case isH:
stateByte = 0x01
case isU:
stateByte = 0x02
case isB:
stateByte = 0x08
case isA:
stateByte = 0x09
default:
stateByte = 0x06
}
}
state.State = stateByte
}
//计轴区段
for _, state := range frame.AxleSectionStates {
row := s.deviceTable.AxleSectionMap[state.Id]