【修改IBP灯归属逻辑】

This commit is contained in:
weizhihong 2023-10-20 15:52:50 +08:00
parent 1ca573c054
commit 7c539309a4
2 changed files with 36 additions and 61 deletions

View File

@ -13,16 +13,16 @@ import (
func ChangeIBPButtonState(sim *VerifySimulation, mapId int32, stationId, btnCode string, pressDown bool) { func ChangeIBPButtonState(sim *VerifySimulation, mapId int32, stationId, btnCode string, pressDown bool) {
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{}) stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
if pressDown { if pressDown {
fi.PressDownButton(sim.World, stationUid+"_"+btnCode) fi.PressDownButton(sim.World, stationUid+"_button_"+btnCode)
} else { } else {
fi.PressUpButton(sim.World, stationUid+"_"+btnCode) fi.PressUpButton(sim.World, stationUid+"_button_"+btnCode)
} }
} }
// 操作IBP按钮 // 操作IBP按钮
func ChangeIBPKeyState(sim *VerifySimulation, mapId int32, stationId, keyCode string, gear int32) { func ChangeIBPKeyState(sim *VerifySimulation, mapId int32, stationId, keyCode string, gear int32) {
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{}) stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
fi.SwitchKeyGear(sim.World, stationUid+"_"+keyCode, gear) fi.SwitchKeyGear(sim.World, stationUid+"_key_"+keyCode, gear)
} }
// 获取仿真车站按钮状态,前端推送 // 获取仿真车站按钮状态,前端推送
@ -36,7 +36,7 @@ func GetMapAllIBPState(sim *VerifySimulation, mapId int32, stationId, ibpMapCode
stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{}) stationUid := QueryUidByMidAndComId(mapId, stationId, &graphicData.Station{})
ibpStorage := getStorageIBPMapData(ibpMapCode) ibpStorage := getStorageIBPMapData(ibpMapCode)
for _, data := range ibpStorage.IbpButtons { // 按钮 for _, data := range ibpStorage.IbpButtons { // 按钮
entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_"+data.Code) entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_button_"+data.Code)
if !ok { if !ok {
continue continue
} }
@ -45,7 +45,7 @@ func GetMapAllIBPState(sim *VerifySimulation, mapId int32, stationId, ibpMapCode
} }
} }
for _, data := range ibpStorage.IbpAlarms { // 报警器 for _, data := range ibpStorage.IbpAlarms { // 报警器
entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_"+data.Code) entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_alarm_"+data.Code)
if !ok { if !ok {
continue continue
} }
@ -57,7 +57,7 @@ func GetMapAllIBPState(sim *VerifySimulation, mapId int32, stationId, ibpMapCode
} }
} }
for _, data := range ibpStorage.IbpLights { // 指示灯 for _, data := range ibpStorage.IbpLights { // 指示灯
entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_"+data.Code) entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_light_"+data.Code)
if !ok { if !ok {
continue continue
} }
@ -69,7 +69,7 @@ func GetMapAllIBPState(sim *VerifySimulation, mapId int32, stationId, ibpMapCode
} }
} }
for _, data := range ibpStorage.IbpKeys { // 钥匙 for _, data := range ibpStorage.IbpKeys { // 钥匙
entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_"+data.Code) entry, ok := entity.GetEntityByUid(sim.World, stationUid+"_key_"+data.Code)
if !ok { if !ok {
continue continue
} }

View File

@ -113,9 +113,6 @@ func CreateSimulation(projectId int32, mapIds []int32) (*VerifySimulation, error
} }
repo = newRepo repo = newRepo
} }
// 目前用本地构建状态
worldMemory := NewWaysideMemory()
initWorldDeviceState(worldMemory.Status, repo)
// 构建所有UID映射关系 // 构建所有UID映射关系
allUidMap := buildRepositoryAllUidsMap(mapIds, repo) allUidMap := buildRepositoryAllUidsMap(mapIds, repo)
//创建仿真 //创建仿真
@ -125,7 +122,7 @@ func CreateSimulation(projectId int32, mapIds []int32) (*VerifySimulation, error
verifySimulation := &VerifySimulation{ verifySimulation := &VerifySimulation{
MapIds: mapIds, MapIds: mapIds,
ProjectId: projectId, ProjectId: projectId,
Memory: worldMemory, Memory: NewWaysideMemory(),
Repo: repo, Repo: repo,
World: w, World: w,
WorldId: w.Id(), WorldId: w.Id(),
@ -823,7 +820,7 @@ func handlerIBPDeviceToStation(station *proto.Station, repo *proto.Repository, i
buttonType = proto.Button_Reset_Press buttonType = proto.Button_Reset_Press
} }
b := &proto.Button{ b := &proto.Button{
Id: station.Id + "_" + data.Code, Id: station.Id + "_button_" + data.Code,
Code: data.Code, Code: data.Code,
ButtonType: buttonType, ButtonType: buttonType,
HasLight: data.HasLight, HasLight: data.HasLight,
@ -836,7 +833,7 @@ func handlerIBPDeviceToStation(station *proto.Station, repo *proto.Repository, i
} }
for _, data := range storage.IbpKeys { // 钥匙 for _, data := range storage.IbpKeys { // 钥匙
b := &proto.Key{ b := &proto.Key{
Id: station.Id + "_" + data.Code, Id: station.Id + "_key_" + data.Code,
Code: data.Code, Code: data.Code,
Gear: 2, Gear: 2,
} }
@ -848,7 +845,7 @@ func handlerIBPDeviceToStation(station *proto.Station, repo *proto.Repository, i
} }
for _, data := range storage.IbpAlarms { // 报警器 for _, data := range storage.IbpAlarms { // 报警器
b := &proto.Alarm{ b := &proto.Alarm{
Id: station.Id + "_" + data.Code, Id: station.Id + "_alarm_" + data.Code,
Code: data.Code, Code: data.Code,
} }
deviceMap[data.Common.Id] = &proto.ElectronicComponent{ deviceMap[data.Common.Id] = &proto.ElectronicComponent{
@ -857,22 +854,37 @@ func handlerIBPDeviceToStation(station *proto.Station, repo *proto.Repository, i
} }
repo.Alarms = append(repo.Alarms, b) repo.Alarms = append(repo.Alarms, b)
} }
for _, data := range storage.IbpLights { // 指示灯 empGroup := &proto.ElectronicGroup{Code: "EMP"}
spksGroup := &proto.ElectronicGroup{Code: "SPKS"}
for _, data := range storage.IbpLights { // 指示灯,
b := &proto.Light{ b := &proto.Light{
Id: station.Id + "_" + data.Code, Id: station.Id + "_light_" + data.Code,
Code: data.Code, Code: data.Code,
Aspect: converIbpLightAspect(data.Color),
} }
deviceMap[data.Common.Id] = &proto.ElectronicComponent{ repo.Lights = append(repo.Lights, b)
// 存入组合类型的
c := &proto.ElectronicComponent{
Id: b.Id, Id: b.Id,
DeviceType: proto.DeviceType_DeviceType_Light, DeviceType: proto.DeviceType_DeviceType_Light,
} }
repo.Lights = append(repo.Lights, b) switch data.Code {
case "X紧急关闭", "S紧急关闭":
empGroup.Components = append(empGroup.Components, c)
case "启用状态_SPKS1", "启用状态_SPKS3", "启用状态_SPKS2", "启用状态_SPKS4":
spksGroup.Components = append(spksGroup.Components, c)
}
} }
// 组信息 for _, data := range storage.IbpRelatedDevices { // 组信息
for _, data := range storage.IbpRelatedDevices {
for _, c := range data.Combinationtypes { for _, c := range data.Combinationtypes {
group := &proto.ElectronicGroup{Code: c.Code} var group *proto.ElectronicGroup
switch c.Code {
case "EMP":
group = empGroup
case "SPKS":
group = spksGroup
default:
continue
}
for _, d := range c.RefDevices { for _, d := range c.RefDevices {
deviceType, ok := deviceMap[d] deviceType, ok := deviceMap[d]
if !ok { if !ok {
@ -881,25 +893,9 @@ func handlerIBPDeviceToStation(station *proto.Station, repo *proto.Repository, i
} }
group.Components = append(group.Components, deviceType) group.Components = append(group.Components, deviceType)
} }
station.ElectronicGroup = append(station.ElectronicGroup, group)
} }
} }
} station.ElectronicGroup = append(station.ElectronicGroup, empGroup, spksGroup)
// 将IBP的灯颜色转换成repo灯颜色
func converIbpLightAspect(color graphicData.IbpLight_IbpLightColor) proto.Light_LightAspect {
switch color {
case graphicData.IbpLight_white:
return proto.Light_B
case graphicData.IbpLight_red:
return proto.Light_H
case graphicData.IbpLight_green:
return proto.Light_L
case graphicData.IbpLight_blue:
return proto.Light_A
default:
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "未知的灯颜色类型" + color.String()})
}
} }
func converCheckPointUid(data *proto.CheckPoint, uidsMap *stationUidStructure) *proto.CheckPoint { func converCheckPointUid(data *proto.CheckPoint, uidsMap *stationUidStructure) *proto.CheckPoint {
@ -1073,27 +1069,6 @@ func findTurnoutIds(axleCountingMap map[string]*graphicData.AxleCounting, axleId
return turnoutIds return turnoutIds
} }
func initWorldDeviceState(status *VerifyStatus, repo *repository.Repository) {
// initWorldTurnoutState(status, repo)
// initWorldPhysicalSectionState(status, repo)
}
// 初始化道岔状态
func initWorldTurnoutState(status *VerifyStatus, repo *repository.Repository) {
for _, turnout := range repo.TurnoutList() {
id := turnout.Identity.Id()
status.SwitchStateMap.Store(id, &state.SwitchState{Id: id, Normal: true, Reverse: false})
}
}
// 初始化物理区段状态
func initWorldPhysicalSectionState(status *VerifyStatus, repo *repository.Repository) {
for _, section := range repo.PhysicalSectionList() {
id := section.Identity.Id()
status.PhysicalSectionStateMap.Store(id, &state.SectionState{Id: id, Occupied: false, Type: state.SectionType_Physic})
}
}
func convertToProtoSignalModel(gSmt graphicData.Signal_Model) proto.Signal_Model { func convertToProtoSignalModel(gSmt graphicData.Signal_Model) proto.Signal_Model {
switch gSmt { switch gSmt {
case graphicData.Signal_HLU: case graphicData.Signal_HLU: