rts-sim-testing-service/ts/simulation/wayside/memory/wayside_memory_section.go
2023-10-26 17:16:07 +08:00

58 lines
1.8 KiB
Go

package memory
import (
"log/slog"
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/dto/request_proto"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/bj-rtsts-server/ts/protos/state"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/fi"
)
func GetMapAllSectionState(sim *VerifySimulation, mapId int32) []*state.SectionState {
uidMap := QueryMapUidMapByType(mapId, &graphicData.Section{})
var sectionArr []*state.SectionState
for _, u := range uidMap {
s := handlerSectionState(sim.World, u.Uid)
if s == nil {
continue
}
s.Id = u.CommonId
sectionArr = append(sectionArr, s)
}
return sectionArr
}
func handlerSectionState(w ecs.World, uid string) *state.SectionState {
entry, ok := entity.GetEntityByUid(w, uid)
if !ok {
//fmt.Printf("id=%s的信号机不存在", uid)
return nil
}
if entry.HasComponent(component.AxleSectionTag) { //计轴区段
sectionState := &state.SectionState{}
axleState := component.AxleSectionStateType.Get(entry)
sectionState.Occupied = axleState.Occ
sectionState.Type = state.SectionType_Axle
return sectionState
}
return nil
}
func ChangeAxleSectionState(simulation *VerifySimulation, req *dto.AxleSectionOperationReqDto) {
sectionUid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &graphicData.Section{})
slog.Debug("操作计轴区段", "axleSectionUid", sectionUid)
switch req.Operation {
case request_proto.Section_Drst:
fi.DriveAxleSectionDrst(simulation.World, sectionUid, req.Reset)
case request_proto.Section_Pdrst:
fi.DriveAxleSectionPdrst(simulation.World, sectionUid, req.Reset)
case request_proto.Section_TrainIn:
fi.DriveAxleSectionTrainIn(simulation.World, sectionUid)
case request_proto.Section_TrainOut:
fi.DriveAxleSectionTrainOut(simulation.World, sectionUid)
}
}