2023-10-23 18:01:48 +08:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
2024-01-22 15:56:40 +08:00
|
|
|
"fmt"
|
2024-07-31 17:08:54 +08:00
|
|
|
"joylink.club/bj-rtsts-server/sys_error"
|
2024-01-22 15:56:40 +08:00
|
|
|
"unsafe"
|
2023-12-14 13:04:48 +08:00
|
|
|
|
2024-01-11 10:24:56 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/data_proto"
|
2023-11-01 11:08:26 +08:00
|
|
|
"joylink.club/bj-rtsts-server/dto/request_proto"
|
2024-01-22 15:56:40 +08:00
|
|
|
appcomponent "joylink.club/bj-rtsts-server/ts/simulation/app_component"
|
|
|
|
"joylink.club/ecs"
|
2023-11-01 11:08:26 +08:00
|
|
|
"joylink.club/rtsssimulation/fi"
|
2023-10-23 18:01:48 +08:00
|
|
|
)
|
|
|
|
|
2024-01-22 15:56:40 +08:00
|
|
|
// 处理区段操作
|
|
|
|
func HandleSectionOperation(simulation *VerifySimulation, req *request_proto.SectionOperationReq) error {
|
|
|
|
uid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.Section{})
|
|
|
|
// 区段操作
|
2023-11-01 11:08:26 +08:00
|
|
|
switch req.Operation {
|
|
|
|
case request_proto.Section_SetFaultOcc:
|
2024-08-28 11:32:27 +08:00
|
|
|
return fi.PhysicalSectionFaultOccDrive(simulation.World, uid, true)
|
2024-01-22 15:56:40 +08:00
|
|
|
case request_proto.Section_SetParams:
|
2024-07-31 17:08:54 +08:00
|
|
|
err := setSectionParam(simulation.World, uid, req.Param)
|
2024-01-22 15:56:40 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-07-31 17:08:54 +08:00
|
|
|
if req.Param.MockDrst {
|
2024-08-28 11:32:27 +08:00
|
|
|
state, err := fi.PhysicalSectionDrstDrive(simulation.World, uid)
|
2024-07-31 17:08:54 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if state.Rjo {
|
|
|
|
return sys_error.New("运营原因拒绝复位")
|
|
|
|
}
|
|
|
|
}
|
2024-01-22 15:56:40 +08:00
|
|
|
if req.Param.MockPdrst {
|
2024-08-28 11:32:27 +08:00
|
|
|
state, err := fi.PhysicalSectionPdrstDrive(simulation.World, uid)
|
2024-07-31 17:08:54 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if state.Rjo {
|
|
|
|
return sys_error.New("运营原因拒绝预复位")
|
|
|
|
}
|
2024-01-22 15:56:40 +08:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("未知的区段操作:%s", req.Operation)
|
2023-11-01 11:08:26 +08:00
|
|
|
}
|
2023-10-24 10:19:51 +08:00
|
|
|
}
|
2024-01-22 15:56:40 +08:00
|
|
|
|
|
|
|
func setSectionParam(world ecs.World, uid string, sectionParam *request_proto.SectionParam) error {
|
|
|
|
return handleEntityState(world, uid, func(e *ecs.Entry) error {
|
|
|
|
e.AddComponent(appcomponent.SectionParamType, unsafe.Pointer(sectionParam))
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// func ChangeAxleSectionState(simulation *VerifySimulation, req *dto.AxleSectionOperationReqDto) error {
|
|
|
|
// sectionUid := QueryUidByMidAndComId(req.MapId, req.DeviceId, &data_proto.Section{})
|
|
|
|
// slog.Debug("操作计轴区段", "axleSectionUid", sectionUid)
|
|
|
|
// if req.TrainIn {
|
|
|
|
// return fi.AxleSectionTrainDrive(simulation.World, sectionUid, true)
|
|
|
|
// }
|
|
|
|
// if req.TrainOut {
|
|
|
|
// return fi.AxleSectionTrainDrive(simulation.World, sectionUid, false)
|
|
|
|
// }
|
|
|
|
// switch req.Operation {
|
|
|
|
// case request_proto.Section_CancelDrst:
|
2024-08-28 11:32:27 +08:00
|
|
|
// return fi.PhysicalSectionDrstDrive(simulation.World, sectionUid, false)
|
2024-01-22 15:56:40 +08:00
|
|
|
// case request_proto.Section_SetDrst:
|
2024-08-28 11:32:27 +08:00
|
|
|
// return fi.PhysicalSectionDrstDrive(simulation.World, sectionUid, true)
|
2024-01-22 15:56:40 +08:00
|
|
|
// case request_proto.Section_CancelPdrst:
|
2024-08-28 11:32:27 +08:00
|
|
|
// return fi.PhysicalSectionPdrstDrive(simulation.World, sectionUid, false)
|
2024-01-22 15:56:40 +08:00
|
|
|
// case request_proto.Section_SetPdrst:
|
2024-08-28 11:32:27 +08:00
|
|
|
// return fi.PhysicalSectionPdrstDrive(simulation.World, sectionUid, true)
|
2024-01-22 15:56:40 +08:00
|
|
|
// case request_proto.Section_CancelFaultOcc:
|
2024-08-28 11:32:27 +08:00
|
|
|
// return fi.PhysicalSectionFaultOccDrive(simulation.World, sectionUid, false)
|
2024-01-22 15:56:40 +08:00
|
|
|
// case request_proto.Section_SetFaultOcc:
|
2024-08-28 11:32:27 +08:00
|
|
|
// return fi.PhysicalSectionFaultOccDrive(simulation.World, sectionUid, true)
|
2024-01-22 15:56:40 +08:00
|
|
|
// }
|
|
|
|
// return nil
|
|
|
|
// }
|