【增加站场图上SPKS状态】

This commit is contained in:
weizhihong 2023-11-02 16:37:57 +08:00
parent 8598553359
commit 58b81b1d13
2 changed files with 44 additions and 0 deletions

View File

@ -65,6 +65,10 @@ func (ms *SfpMs) OnTick() ([]*ms_api.TopicMsg, error) {
if err != nil {
return nil, err
}
spksStates, err := ms.collectSpksStates()
if err != nil {
return nil, err
}
ststes := &state.PushedDevicesStatus{
All: true,
AllStatus: &state.AllDevicesStatus{
@ -74,6 +78,7 @@ func (ms *SfpMs) OnTick() ([]*ms_api.TopicMsg, error) {
ButtonState: buttonStates,
PsdState: psdStates,
SectionState: sectionStates,
KeyState: spksStates,
},
}
b, err := proto.Marshal(ststes)
@ -261,3 +266,19 @@ func (ms *SfpMs) collectTurnoutStates() ([]*state.SwitchState, error) {
}
return switchArr, nil
}
// 人员防护开关状态
func (ms *SfpMs) collectSpksStates() ([]*state.KeyState, error) {
uidsMap := memory.QueryUidStructure[*memory.StationUidStructure](ms.mapId)
var states []*state.KeyState
for _, u := range uidsMap.SpksSwitchIds { // 钥匙
entry, ok := entity.GetEntityByUid(ms.vs.World, u.Uid)
if !ok {
return nil, fmt.Errorf("ibp钥匙实体不存在: World id=%d, uid=%s", ms.vs.World.Id(), u.Uid)
}
if entry.HasComponent(component.KeyTag) {
states = append(states, &state.KeyState{Id: u.CommonId, Gear: component.GearStateType.Get(entry).Val})
}
}
return states, nil
}

View File

@ -32,6 +32,7 @@ type StationUidStructure struct {
PlatformIds map[string]*elementIdStructure
PsdIds map[string]*elementIdStructure
GateBoxIds map[string]*elementIdStructure
SpksSwitchIds map[string]*elementIdStructure
}
type RelayUidStructure struct {
@ -79,6 +80,7 @@ func initStationUid(data *graphicData.RtssGraphicStorage) *StationUidStructure {
PlatformIds: make(map[string]*elementIdStructure, len(data.Platforms)),
PsdIds: make(map[string]*elementIdStructure, len(data.ScreenDoors)),
GateBoxIds: make(map[string]*elementIdStructure, len(data.GateBoxs)),
SpksSwitchIds: make(map[string]*elementIdStructure, len(data.SpksSwitchs)),
}
city, lineId, _ := getUIdPrefix(data.UniqueIdPrefix)
// 初始化计轴信息
@ -197,6 +199,25 @@ func initStationUid(data *graphicData.RtssGraphicStorage) *StationUidStructure {
Uid: GenerateElementUid(city, lineId, []string{stationId}, box.Code),
}
}
// SPKS人员防护
for _, spk := range data.SpksSwitchs {
if spk.RefStand == "" {
continue
}
platform := platformMap[spk.RefStand]
if platform == nil {
continue
}
station := gus.StationIds[platform.RefStationId]
if station == nil {
continue
}
gus.SpksSwitchIds[spk.Common.Id] = &elementIdStructure{
CommonId: spk.Common.Id,
Code: spk.Code,
Uid: station.Uid + "_key_" + spk.Code,
}
}
return gus
}
@ -327,6 +348,8 @@ func getUidMapByType(uidData any, m interface{}) map[string]*elementIdStructure
return (uidData.(*StationUidStructure)).ButtonIds
case *graphicData.Station:
return (uidData.(*StationUidStructure)).StationIds
case *graphicData.SpksSwitch:
return (uidData.(*StationUidStructure)).SpksSwitchIds
default:
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "类型未映射字段"})
}