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

69 lines
2.2 KiB
Go
Raw Normal View History

package memory
import (
2023-09-28 18:24:36 +08:00
"fmt"
2023-10-07 10:57:16 +08:00
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
2023-10-13 17:43:48 +08:00
"joylink.club/rtsssimulation/component/component_proto"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/fi"
2023-09-22 18:10:46 +08:00
2023-10-13 17:43:48 +08:00
"joylink.club/bj-rtsts-server/dto/request_proto"
2023-10-26 17:16:07 +08:00
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/bj-rtsts-server/ts/protos/state"
)
2023-10-13 17:43:48 +08:00
// 处理道岔操作
func HandleTurnoutOperation(simulation *VerifySimulation, req *request_proto.TurnoutOperationReq) {
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &graphicData.Turnout{})
switch req.Operation {
case request_proto.Turnout_DC:
fi.DriveTurnoutDCOn(simulation.World, uid)
case request_proto.Turnout_CancelDC:
fi.DriveTurnoutDCOff(simulation.World, uid)
case request_proto.Turnout_FC:
fi.DriveTurnoutFCOn(simulation.World, uid)
case request_proto.Turnout_CancelFC:
fi.DriveTurnoutFCOff(simulation.World, uid)
case request_proto.Turnout_SetSB:
fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
case request_proto.Turnout_CancelSB:
2023-10-16 11:28:09 +08:00
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
2023-10-13 17:43:48 +08:00
case request_proto.Turnout_SetJC:
fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
case request_proto.Turnout_CancelJC:
2023-10-16 11:28:09 +08:00
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
2023-10-13 17:43:48 +08:00
default:
panic(fmt.Sprintf("未知的道岔操作:%s", req.Operation))
}
}
2023-09-22 18:10:46 +08:00
// 获取全部的道岔状态,动力学使用
func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
2023-09-26 16:38:14 +08:00
var switchArr []*state.SwitchState
2023-09-27 14:15:11 +08:00
turnoutList := sim.Repo.TurnoutList()
2023-09-26 16:38:14 +08:00
for _, o := range turnoutList {
2023-10-07 10:57:16 +08:00
s := handlerTurnoutState(sim.World, o.Id())
if s == nil {
continue
}
s.Id = sim.GetComIdByUid(o.Id())
switchArr = append(switchArr, s)
2023-09-26 14:12:26 +08:00
}
return switchArr
}
2023-10-07 10:57:16 +08:00
func handlerTurnoutState(w ecs.World, uid string) *state.SwitchState {
entry, ok := entity.GetEntityByUid(w, uid)
if !ok {
fmt.Printf("id=%s的道岔不存在", uid)
return nil
}
if !entry.HasComponent(component.TurnoutPositionType) {
2023-10-07 10:57:16 +08:00
return nil
}
pos := component.TurnoutPositionType.Get(entry)
return &state.SwitchState{Normal: pos.Db, Reverse: pos.Fb, Dw: pos.Dw, Fw: pos.Fw}
2023-10-07 10:57:16 +08:00
}