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

83 lines
2.8 KiB
Go
Raw Normal View History

2023-10-23 18:01:48 +08:00
package memory
import (
2024-01-22 15:56:40 +08:00
"fmt"
"joylink.club/bj-rtsts-server/sys_error"
2024-01-22 15:56:40 +08:00
"unsafe"
2023-12-14 13:04:48 +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:
return fi.PhysicalSectionFaultOccDrive(simulation.World, uid, true)
2024-01-22 15:56:40 +08:00
case request_proto.Section_SetParams:
err := setSectionParam(simulation.World, uid, req.Param)
2024-01-22 15:56:40 +08:00
if err != nil {
return err
}
if req.Param.MockDrst {
state, err := fi.PhysicalSectionDrstDrive(simulation.World, uid)
if err != nil {
return err
}
if state.Rjo {
return sys_error.New("运营原因拒绝复位")
}
}
2024-01-22 15:56:40 +08:00
if req.Param.MockPdrst {
state, err := fi.PhysicalSectionPdrstDrive(simulation.World, uid)
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:
// return fi.PhysicalSectionDrstDrive(simulation.World, sectionUid, false)
2024-01-22 15:56:40 +08:00
// case request_proto.Section_SetDrst:
// return fi.PhysicalSectionDrstDrive(simulation.World, sectionUid, true)
2024-01-22 15:56:40 +08:00
// case request_proto.Section_CancelPdrst:
// return fi.PhysicalSectionPdrstDrive(simulation.World, sectionUid, false)
2024-01-22 15:56:40 +08:00
// case request_proto.Section_SetPdrst:
// return fi.PhysicalSectionPdrstDrive(simulation.World, sectionUid, true)
2024-01-22 15:56:40 +08:00
// case request_proto.Section_CancelFaultOcc:
// return fi.PhysicalSectionFaultOccDrive(simulation.World, sectionUid, false)
2024-01-22 15:56:40 +08:00
// case request_proto.Section_SetFaultOcc:
// return fi.PhysicalSectionFaultOccDrive(simulation.World, sectionUid, true)
2024-01-22 15:56:40 +08:00
// }
// return nil
// }