rts-sim-testing-service/ts/simulation/wayside/memory/wayside_memory_turnout.go
walker 340d1371d2 道岔添加强制操作
添加应答器编解码器部分代码
2023-10-31 11:22:50 +08:00

75 lines
2.4 KiB
Go

package memory
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/component_proto"
"joylink.club/rtsssimulation/entity"
"joylink.club/rtsssimulation/fi"
"joylink.club/bj-rtsts-server/dto/request_proto"
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
"joylink.club/bj-rtsts-server/ts/protos/state"
)
// 处理道岔操作
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:
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_SB)
case request_proto.Turnout_SetJC:
fi.SetTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
case request_proto.Turnout_CancelJC:
fi.CancelTurnoutFault(simulation.World, uid, component_proto.Turnout_JC)
case request_proto.Turnout_ForceDw:
fi.ForceTurnoutDw(simulation.World, uid)
case request_proto.Turnout_ForceFw:
fi.ForceTurnoutFw(simulation.World, uid)
case request_proto.Turnout_CancelForce:
fi.CancelTurnoutForce(simulation.World, uid)
default:
panic(fmt.Sprintf("未知的道岔操作:%s", req.Operation))
}
}
// 获取全部的道岔状态,动力学使用
func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
var switchArr []*state.SwitchState
turnoutList := sim.Repo.TurnoutList()
for _, o := range turnoutList {
s := handlerTurnoutState(sim.World, o.Id())
if s == nil {
continue
}
s.Id = sim.GetComIdByUid(o.Id())
switchArr = append(switchArr, s)
}
return switchArr
}
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) {
return nil
}
pos := component.TurnoutPositionType.Get(entry)
return &state.SwitchState{Normal: pos.Db, Reverse: pos.Fb, Dw: pos.Dw, Fw: pos.Fw}
}