rts-sim-testing-service/ts/simulation/wayside/memory/wayside_memory_ibp.go

60 lines
2.0 KiB
Go
Raw Normal View History

2023-10-18 13:53:17 +08:00
package memory
import (
2023-12-07 10:17:48 +08:00
"fmt"
2023-10-26 17:16:07 +08:00
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
2023-10-18 13:53:17 +08:00
"joylink.club/rtsssimulation/fi"
)
// 操作IBP按钮
2023-12-14 13:04:48 +08:00
func ChangeIBPButtonState(sim *VerifySimulation, mapId int32, stationId, btnId uint32, pressDown bool) error {
2023-12-07 10:17:48 +08:00
uidMap, err := getIbpUidByMapIdAndStationId(mapId, stationId)
if err != nil {
return err
}
if uidMap.IbpButtonIds[btnId] == nil {
2023-12-14 13:04:48 +08:00
return fmt.Errorf("车站【%d】按钮【%d】UID不存在", stationId, btnId)
2023-12-07 10:17:48 +08:00
}
2023-10-20 13:50:22 +08:00
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
2023-10-18 13:53:17 +08:00
if pressDown {
2023-12-07 10:17:48 +08:00
return fi.PressDownButton(sim.World, stationUid+"_"+uidMap.IbpButtonIds[btnId].Uid)
2023-10-18 13:53:17 +08:00
} else {
2023-12-07 10:17:48 +08:00
return fi.PressUpButton(sim.World, stationUid+"_"+uidMap.IbpButtonIds[btnId].Uid)
2023-10-18 13:53:17 +08:00
}
}
2023-10-20 13:50:22 +08:00
// 操作IBP按钮
2023-12-14 13:04:48 +08:00
func ChangeIBPKeyState(sim *VerifySimulation, mapId int32, stationId, keyId uint32, gear int32) error {
2023-12-07 10:17:48 +08:00
uidMap, err := getIbpUidByMapIdAndStationId(mapId, stationId)
if err != nil {
return err
}
if uidMap.IbpKeyIds[keyId] == nil {
2023-12-14 13:04:48 +08:00
return fmt.Errorf("车站【%d】钥匙【%d】UID不存在", stationId, keyId)
2023-12-07 10:17:48 +08:00
}
2023-10-20 13:50:22 +08:00
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
2023-12-07 10:17:48 +08:00
return fi.SwitchKeyGear(sim.World, stationUid+"_"+uidMap.IbpKeyIds[keyId].Uid, gear)
}
// 根据平面布置图ID、列车ID获取IbpUid信息
2023-12-14 13:04:48 +08:00
func getIbpUidByMapIdAndStationId(mapId int32, stationId uint32) (*IBPUidStructure, error) {
2023-12-07 10:17:48 +08:00
giData := QueryGiData[*graphicData.RtssGraphicStorage](mapId)
var station *graphicData.Station
for _, s := range giData.Stations {
if GetMapElementId(s.Common) == stationId {
2023-12-07 10:17:48 +08:00
station = s
break
}
}
if station == nil {
2023-12-14 13:04:48 +08:00
return nil, fmt.Errorf("地图【%d】车站【%d】不存在", mapId, stationId)
2023-12-07 10:17:48 +08:00
}
if station.RefIbpMapCode == "" {
return nil, fmt.Errorf("车站【%s】未关联IBP地图", station.StationName)
}
ibpMapId, _ := QueryGiDataByName[*graphicData.IBPGraphicStorage](station.RefIbpMapCode)
return QueryUidStructure[*IBPUidStructure](ibpMapId), nil
2023-10-20 13:50:22 +08:00
}