[修改]设备状态proto消息中增加计轴区段状态,原“所有区段状态”改为物理区段状态“

This commit is contained in:
thesai 2024-08-12 15:18:52 +08:00
parent 272274a5c4
commit 016ce0e8bb
4 changed files with 72 additions and 28 deletions

@ -1 +1 @@
Subproject commit a5ebb6869d51969e5887f1dfceaffe8fcdc27312
Subproject commit 4a126b57ac6bb950d764851a27a5ddf4caad0b2a

View File

@ -239,12 +239,12 @@ func (t *ToInterlockFrame) encode() []byte {
//扣车数量0
data = binary.BigEndian.AppendUint16(data, 0)
//信号机状态
binary.BigEndian.AppendUint16(data, uint16(len(t.SignalStates)))
data = binary.BigEndian.AppendUint16(data, uint16(len(t.SignalStates)))
for _, state := range t.SignalStates {
data = state.encode(data)
}
//计轴区段
binary.BigEndian.AppendUint16(data, uint16(len(t.AxleSectionStates)))
data = binary.BigEndian.AppendUint16(data, uint16(len(t.AxleSectionStates)))
for _, state := range t.AxleSectionStates {
data = state.encode(data)
}
@ -259,6 +259,8 @@ func (t *ToInterlockFrame) encode() []byte {
}
//车库门数量0
data = binary.BigEndian.AppendUint16(data, 0)
//填充报文长度
binary.BigEndian.PutUint16(data[1:3], uint16(len(data)))
return data
}

View File

@ -3,7 +3,7 @@ package beijing11
// StationDeviceIndexTable 联锁站设备索引表
type StationDeviceIndexTable struct {
StationName string //地图数据中车站的Code属性
WaysideCode string //通信数据中的“轨旁编号”
InterlockCode uint16 //通信数据中的“联锁编号”
TurnoutMap map[uint16]*Row
PsdMap map[uint16]*Row
EsbMap map[uint16]*Row
@ -17,10 +17,10 @@ type StationDeviceIndexTable struct {
XcjMap map[uint16]*Row
}
func NewStationDeviceIndexTable() *StationDeviceIndexTable {
func NewStationDeviceIndexTable(stationName string, interlockCode uint16) *StationDeviceIndexTable {
return &StationDeviceIndexTable{
StationName: "",
WaysideCode: "",
StationName: stationName,
InterlockCode: interlockCode,
TurnoutMap: make(map[uint16]*Row),
PsdMap: make(map[uint16]*Row),
EsbMap: make(map[uint16]*Row),

View File

@ -25,6 +25,7 @@ var (
var (
mu = sync.Mutex{} //启动任务时使用,避免重复启动任务
serviceContextMap = make(map[string]*serviceContext) //每个集中站的服务上下文key-集中站code
waysideCode uint16 = 0x6301
)
type serviceContext struct {
@ -115,11 +116,29 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI
}
uids := memory.QueryUidStructure[*memory.StationUidStructure](mapId)
table := NewStationDeviceIndexTable()
var table *StationDeviceIndexTable
for _, station := range stationGi.Stations {
if station.StationName != stationCode {
continue
}
for _, lianSuoIndexData := range stationGi.LianSuoData.Stations {
if lianSuoIndexData.Id == station.Common.Id {
table = NewStationDeviceIndexTable(station.StationName, uint16(lianSuoIndexData.Index))
break
}
}
break
}
if table == nil {
panic(fmt.Sprintf("联锁配置车站[%s]在地图中没有对应的车站或联锁编号数据", stationCode))
}
//道岔
for _, data := range stationGi.LianSuoData.Switchs {
if data.Index <= 0 {
continue
}
for _, station := range uids.TurnoutIds[data.Id].CentralizedStations {
if station.Code == stationCode {
if station.StationName == stationCode {
table.TurnoutMap[uint16(data.Id)] = &Row{
commonId: data.Id,
uid: uids.TurnoutIds[data.Id].Uid,
@ -131,8 +150,11 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI
}
//屏蔽门
for _, data := range stationGi.LianSuoData.ScreenDoors {
if data.Index <= 0 {
continue
}
for _, station := range uids.PsdIds[data.Id].CentralizedStations {
if station.Code == stationCode {
if station.StationName == stationCode {
relateDeviceMap := make(map[string]string)
for _, mkx := range sim.Repo.MkxList() {
if mkx.Psd().Id() == uids.PsdIds[data.Id].Uid {
@ -152,8 +174,11 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI
}
//紧急停车
for _, data := range stationGi.LianSuoData.EsbButtons {
if data.Index <= 0 {
continue
}
for _, station := range uids.EsbIds[data.Id].CentralizedStations {
if station.Code == stationCode {
if station.StationName == stationCode {
table.EsbMap[uint16(data.Id)] = &Row{
commonId: data.Id,
uid: uids.EsbIds[data.Id].Uid,
@ -166,8 +191,11 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI
//扣车实际数据中数量为0
//信号机
for _, data := range stationGi.LianSuoData.Signals {
if data.Index <= 0 {
continue
}
for _, station := range uids.SignalIds[data.Id].CentralizedStations {
if station.Code == stationCode {
if station.StationName == stationCode {
table.SignalMap[uint16(data.Id)] = &Row{
commonId: data.Id,
uid: uids.SignalIds[data.Id].Uid,
@ -179,8 +207,14 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI
}
//计轴区段
for _, data := range stationGi.LianSuoData.Sections {
if data.Index <= 0 {
continue
}
if data.Index == 0 { //这是其它线的区段
continue
}
for _, station := range uids.PhysicalSectionIds[data.Id].CentralizedStations {
if station.Code == stationCode {
if station.StationName == stationCode {
table.AxleSectionMap[uint16(data.Id)] = &Row{
commonId: data.Id,
uid: uids.PhysicalSectionIds[data.Id].Uid,
@ -194,8 +228,11 @@ func makeTable(sim *memory.VerifySimulation, stationCode string) *StationDeviceI
//防淹门实际数据中数量为0
//人员防护
for _, data := range stationGi.LianSuoData.SpksSwitchs {
if data.Index <= 0 {
continue
}
for _, station := range uids.SpksIds[data.Id].CentralizedStations {
if station.Code == stationCode {
if station.StationName == stationCode {
table.SpksMap[uint16(data.Id)] = &Row{
commonId: data.Id,
uid: uids.SpksIds[data.Id].Uid,
@ -217,27 +254,32 @@ func (s *serviceContext) runCollectTask(ctx context.Context) {
defer func() {
if err := recover(); err != nil {
logger().Error("状态收集任务出错,记录后重启", "error", err, "stack", string(debug.Stack()))
s.runCollectTask(nil)
s.runCollectTask(ctx)
}
}()
}()
for range time.Tick(time.Duration(s.iConfig.Period) * time.Millisecond) {
select {
case <-ctx.Done():
return
default:
frame := s.collectDeviceState()
err := s.client.Send(frame.encode())
data := frame.encode()
err := s.client.Send(data)
if err != nil {
logger().Error("向联锁发送数据失败", "error", err)
} else {
logger().Info(fmt.Sprintf("向联锁发送数据:%x", data))
}
}
}
}()
}
func (s *serviceContext) collectDeviceState() *ToInterlockFrame {
wd := entity.GetWorldData(s.sim.World)
frame := &ToInterlockFrame{}
frame.WaysideCode = waysideCode
frame.InterlockCode = s.deviceTable.InterlockCode
//道岔
for _, row := range s.deviceTable.TurnoutMap {
entry := wd.EntityMap[row.uid]