From 619a20664569b7cd4312c363211ed1c9525e04a3 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 1 Aug 2023 14:54:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=BF=E7=9C=9F=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E3=80=81=E7=BB=93=E6=9E=84=E4=BD=93=E6=94=B9=E5=8A=A8=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/simulation.go | 37 +++---- ats/verify/simulation/simulation_manage.go | 60 ++++++---- .../wayside/memory/wayside_memory.go | 103 ++++-------------- .../wayside/memory/wayside_memory_helper,.go | 11 -- .../memory/wayside_memory_initializer.go | 29 ++--- .../wayside/memory/wayside_memory_map.go | 99 +++++++++++++++++ .../memory/wayside_memory_section_mapper.go | 11 -- .../memory/wayside_memory_train_runtime.go | 11 -- .../memory/wayside_memory_variation.go | 11 -- .../wayside/memory/wayside_path_layer.go | 11 -- .../wayside/memory/wayside_simulation.go | 24 ++++ .../wayside/runtime/wayside_runtime.go | 34 ------ .../simulation/wayside/verify_memory.go | 33 ------ grpcproto/simulation_server.go | 30 ++--- 14 files changed, 224 insertions(+), 280 deletions(-) delete mode 100644 ats/verify/simulation/wayside/memory/wayside_memory_helper,.go create mode 100644 ats/verify/simulation/wayside/memory/wayside_memory_map.go delete mode 100644 ats/verify/simulation/wayside/memory/wayside_memory_section_mapper.go delete mode 100644 ats/verify/simulation/wayside/memory/wayside_memory_train_runtime.go delete mode 100644 ats/verify/simulation/wayside/memory/wayside_memory_variation.go delete mode 100644 ats/verify/simulation/wayside/memory/wayside_path_layer.go create mode 100644 ats/verify/simulation/wayside/memory/wayside_simulation.go delete mode 100644 ats/verify/simulation/wayside/runtime/wayside_runtime.go delete mode 100644 ats/verify/simulation/wayside/verify_memory.go diff --git a/api/simulation.go b/api/simulation.go index 38a2e54..febc2df 100644 --- a/api/simulation.go +++ b/api/simulation.go @@ -4,7 +4,6 @@ import ( "fmt" "net/http" "strconv" - "strings" jwt "github.com/appleboy/gin-jwt/v2" "github.com/gin-gonic/gin" @@ -13,10 +12,9 @@ import ( "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" "joylink.club/bj-rtsts-server/ats/verify/protos/state" "joylink.club/bj-rtsts-server/ats/verify/simulation" - "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside" + "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory" "joylink.club/bj-rtsts-server/dto" apiproto "joylink.club/bj-rtsts-server/grpcproto" - "joylink.club/bj-rtsts-server/service" ) func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { @@ -57,8 +55,7 @@ func create(c *gin.Context) { rsp := dto.SimulationCreateRspDto{ MapId: req.MapId, } - mapData := service.QueryRtssGraphicStorage(req.MapId) - rsp.SimulationId = simulation.CreateSimulation(int(req.MapId), mapData) + rsp.SimulationId = simulation.CreateSimulation(req.MapId) c.JSON(http.StatusOK, &rsp) } @@ -101,16 +98,8 @@ func destroy(c *gin.Context) { // @Router /api/v1/simulation/list [get] func findAllSimulations(c *gin.Context) { zap.S().Debug("ATS测试仿真-获取ATS测试系统所有仿真实例的基本信息,请求") - simArr := [...]dto.SimulationInfoRepDto{} - i := 0 - for v := range simulation.SimulationMap { - simArr[i] = dto.SimulationInfoRepDto{ - SimulationId: v, - MapId: strings.Split(v, "_")[0], - } - } //TODO 后续调用 - c.JSON(http.StatusOK, simArr) + c.JSON(http.StatusOK, simulation.ListAllSimulations()) } // ATS测试仿真地图数据校验 @@ -165,14 +154,15 @@ func addTrain(c *gin.Context) { } zap.S().Debug("ATS测试仿真-添加列车,请求:", req) deviceMemory := checkDeviceDataAndReturn(req.SimulationId) - trainMap := deviceMemory.Status.TrainStateMap + trainMap := &deviceMemory.Memory.Status.TrainStateMap // 获取列车ID i := 1 for { - if trainMap[strconv.Itoa(i)] == nil { - break - } else { + _, ok := trainMap.Load(strconv.Itoa(i)) + if ok { i++ + } else { + break } } id := strconv.Itoa(i) @@ -182,7 +172,7 @@ func addTrain(c *gin.Context) { HeadLinkOffset: req.HeadLinkOffset, Up: req.Up, } - trainMap[id] = rsp + trainMap.Store(id, rsp) c.JSON(http.StatusOK, &rsp) } @@ -209,7 +199,7 @@ func removeTrain(c *gin.Context) { } zap.S().Debug("ATS测试仿真-移除列车,请求:", rt) deviceMemory := checkDeviceDataAndReturn(rt.SimulationId) - delete(deviceMemory.Status.TrainStateMap, rt.TrainId) + deviceMemory.Memory.Status.TrainStateMap.Delete(rt.TrainId) //TODO 后续调用列车删除操作 c.JSON(http.StatusOK, "ok") } @@ -236,17 +226,18 @@ func switchOperation(c *gin.Context) { panic(err) } deviceMemory := checkDeviceDataAndReturn(req.SimulationId) - switchInfo := deviceMemory.Status.SwitchStateMap[req.SwitchIndex] - if switchInfo == nil { + s, ok := deviceMemory.Memory.Status.SwitchStateMap.Load(req.SwitchIndex) + if !ok { panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("仿真[%s]中索引为[%s]的道岔不存在", req.SimulationId, req.SwitchIndex)}) } + switchInfo := s.(*state.SwitchState) switchInfo.Normal = req.TurnNormal switchInfo.Reverse = req.TurnReverse c.JSON(http.StatusOK, "ok") } // 获取仿真设备数据并返回 -func checkDeviceDataAndReturn(simId string) *wayside.VerifyMemory { +func checkDeviceDataAndReturn(simId string) *memory.VerifySimulation { deviceMemory := simulation.FindSimulation(simId) if deviceMemory == nil { panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("仿真[%s]不存在", simId)}) diff --git a/ats/verify/simulation/simulation_manage.go b/ats/verify/simulation/simulation_manage.go index 4b7e9ae..4533bbc 100644 --- a/ats/verify/simulation/simulation_manage.go +++ b/ats/verify/simulation/simulation_manage.go @@ -2,47 +2,65 @@ package simulation import ( "strconv" + "sync" - "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" - "joylink.club/bj-rtsts-server/ats/verify/protos/state" - "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside" + "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory" + "joylink.club/bj-rtsts-server/dto" ) // 仿真存储集合 -var SimulationMap = make(map[string]*wayside.VerifyMemory) - -// 仿真子id生成器 -var SimulationSubId = 0 +var simulationMap sync.Map // 创建仿真对象 -func CreateSimulation(mapId int, mapData *graphicData.RtssGraphicStorage) string { +func CreateSimulation(mapId int32) string { simulationId := createSimulationId(mapId) - verifyMemory := &wayside.VerifyMemory{ - Status: &wayside.VerifyStatus{ - SwitchStateMap: make(map[string]*state.SwitchState), - }, + _, e := simulationMap.Load(simulationId) + if !e { + verifySimulation := memory.CreateSimulation(mapId, simulationId) + simulationMap.Store(simulationId, verifySimulation) } - SimulationMap[simulationId] = verifyMemory return simulationId } // 删除仿真对象 func DestroySimulation(simulationId string) { - delete(SimulationMap, simulationId) + simulationMap.Delete(simulationId) } // 创建时生成仿真Id -func createSimulationId(mapId int) string { - SimulationSubId++ - return strconv.Itoa(mapId) + "_" + strconv.Itoa(SimulationSubId) +func createSimulationId(mapId int32) string { + return strconv.Itoa(int(mapId)) } // 获取仿真列表 -func ListAllSimulations() []*wayside.VerifyMemory { - return nil +func ListAllSimulations() []*dto.SimulationInfoRepDto { + simArr := []*dto.SimulationInfoRepDto{} + simulationMap.Range(func(k, v any) bool { + s := v.(*memory.VerifySimulation) + simArr = append(simArr, &dto.SimulationInfoRepDto{ + SimulationId: s.SimulationId, + MapId: strconv.Itoa(int(s.MapId)), + }) + return true + }) + return simArr } // 根据仿真id查找仿真实例 -func FindSimulation(simulationId string) *wayside.VerifyMemory { - return SimulationMap[simulationId] +func FindSimulation(simulationId string) *memory.VerifySimulation { + m, e := simulationMap.Load(simulationId) + if e { + return m.(*memory.VerifySimulation) + } + return nil +} + +// 获取普通仿真数组 +func GetSimulationArr() []*memory.VerifySimulation { + result := []*memory.VerifySimulation{} + simulationMap.Range(func(k, v any) bool { + result = append(result, v.(*memory.VerifySimulation)) + return true + }) + return result } diff --git a/ats/verify/simulation/wayside/memory/wayside_memory.go b/ats/verify/simulation/wayside/memory/wayside_memory.go index c8399a1..aa77b8c 100644 --- a/ats/verify/simulation/wayside/memory/wayside_memory.go +++ b/ats/verify/simulation/wayside/memory/wayside_memory.go @@ -2,107 +2,52 @@ package memory import ( "sync" - - "joylink.club/bj-rtsts-server/ats/verify/protos/state" - "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/face" ) -// 轨旁仿真模型结构 -type VerifyStructure struct { - //计轴检测点设备模型集合,key为索引编号 - AxlePointDeviceModelMap map[string]face.AxlePointDeviceModeller - //道岔设备模型集合,key为索引编号 - SwitchDeviceModelMap map[string]face.SwitchDeviceModeller - //由端点确定的link模型集合,key为索引编号 - LinkSectionModelMap map[string]face.LinkSectionModeller - //计轴区段模型集合,key为索引编号 - AxleSectionModelMap map[string]face.AxleSectionModeller - //物理区段模型集合,key为索引编号 - PhysicalSectionModelMap map[string]face.PhysicalSectionModeller - //逻辑区段模型集合,key为索引编号 - LogicalSectionModelMap map[string]face.LogicalSectionModeller - //信号机模型集合,key为索引编号 - SignalDeviceModelMap map[string]face.SignalDeviceModeller -} - -func (me *VerifyStructure) create() *VerifyStructure { - me.AxlePointDeviceModelMap = make(map[string]face.AxlePointDeviceModeller) - me.SwitchDeviceModelMap = make(map[string]face.SwitchDeviceModeller) - me.LinkSectionModelMap = make(map[string]face.LinkSectionModeller) - me.AxleSectionModelMap = make(map[string]face.AxleSectionModeller) - me.PhysicalSectionModelMap = make(map[string]face.PhysicalSectionModeller) - me.LogicalSectionModelMap = make(map[string]face.LogicalSectionModeller) - me.SignalDeviceModelMap = make(map[string]face.SignalDeviceModeller) - return me -} - /////////////////////////////////////////////////////////////////////////// // 轨旁仿真模型状态 type VerifyStatus struct { - //道岔状态,key为道岔id即索引 - SwitchStateMap map[string]*state.SwitchState - //轨道状态,key为轨道id即索引 - LinkStateMap map[string]*state.LinkState - //列车状态,key为列车id即索引 - TrainStateMap map[string]*state.TrainState - //计轴区段状态,key为计轴区段的id即索引 - AxleSectionStateMap map[string]*state.SectionState - //物理区段状态,key为物理区段id即索引 - PhysicalSectionStateMap map[string]*state.SectionState - //逻辑区段状态,key为逻辑区段id即索引 - LogicSectionStateMap map[string]*state.SectionState - //信号机状态,key为信号机id,即索引 - SignalStateMap map[string]*state.SignalState + //道岔状态,key为道岔id即索引 state.SwitchState + SwitchStateMap sync.Map + //轨道状态,key为轨道id即索引 state.LinkState + LinkStateMap sync.Map + //列车状态,key为列车id即索引 state.TrainState + TrainStateMap sync.Map + //计轴区段状态,key为计轴区段的id即索引 state.SectionState + AxleSectionStateMap sync.Map + //物理区段状态,key为物理区段id即索引 state.SectionState + PhysicalSectionStateMap sync.Map + //逻辑区段状态,key为逻辑区段id即索引 state.SectionState + LogicSectionStateMap sync.Map + //信号机状态,key为信号机id,即索引 state.SignalState + SignalStateMap sync.Map } -func (me *VerifyStatus) create() *VerifyStatus { - me.SwitchStateMap = make(map[string]*state.SwitchState) - me.LinkStateMap = make(map[string]*state.LinkState) - me.TrainStateMap = make(map[string]*state.TrainState) - me.AxleSectionStateMap = make(map[string]*state.SectionState) - me.PhysicalSectionStateMap = make(map[string]*state.SectionState) - me.LogicSectionStateMap = make(map[string]*state.SectionState) - me.SignalStateMap = make(map[string]*state.SignalState) - return me +// 轨旁仿真模型状态(变更) +type ChangeVerifyStatus struct { + VerifyStatus + //删除的列车ID列表 + RemoveTrainId []string } ////////////////////////////////////////////////////////////////////////// // 轨旁仿真内存模型 type WaysideMemory struct { - //固定关系数据:轨旁仿真模型结构 - Structure *VerifyStructure - //可变状态数据:轨旁仿真模型状态 + //可变状态数据:轨旁仿真模型状态(全量数据) Status *VerifyStatus + // 要变更的状态:用户操作过的状态记录在这里,增量推送次数据 + ChangeStatus *ChangeVerifyStatus //状态保护锁 rwLock *sync.RWMutex - //对数据的操作管理实现:对内存模型初始化的初始化器 - Initializer *WaysideMemoryInitializer - //对数据的操作管理实现:对内存模型的列车运行时数据操作的更新器 - TrainRuntime *WaysideMemoryTrainRuntime - //对数据的操作管理实现:工具 - Helper *WaysideMemoryHelper - //对数据的操作管理实现:计算当前时刻与上一时刻状态的变化量,用于前端页面增量更新 - Variation *WaysideMemoryVariation - //对数据的操作管理实现:实现设备到区段的映射 - SectionMapper *WaysideMemorySectionMapper - //端点和轨道构成的路径层 - PathLayer *WaysidePathLayer } // 初始化轨旁仿真内存模型 func (memory *WaysideMemory) Create() *WaysideMemory { - memory.Structure = new(VerifyStructure).create() - memory.Status = new(VerifyStatus).create() + memory.Status = new(VerifyStatus) + memory.ChangeStatus = &ChangeVerifyStatus{} memory.rwLock = new(sync.RWMutex) - //初始化数据操作管理器 - memory.Initializer = new(WaysideMemoryInitializer).Create(memory) - memory.TrainRuntime = new(WaysideMemoryTrainRuntime).Create(memory) - memory.Helper = new(WaysideMemoryHelper).Create(memory) - memory.Variation = new(WaysideMemoryVariation).Create(memory) - memory.SectionMapper = new(WaysideMemorySectionMapper).Create(memory) - memory.PathLayer = new(WaysidePathLayer).Create(memory) return memory } diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_helper,.go b/ats/verify/simulation/wayside/memory/wayside_memory_helper,.go deleted file mode 100644 index 969af41..0000000 --- a/ats/verify/simulation/wayside/memory/wayside_memory_helper,.go +++ /dev/null @@ -1,11 +0,0 @@ -package memory - -//工具 -type WaysideMemoryHelper struct { - memory *WaysideMemory -} - -func (me *WaysideMemoryHelper) Create(memory *WaysideMemory) *WaysideMemoryHelper { - me.memory = memory - return me -} diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_initializer.go b/ats/verify/simulation/wayside/memory/wayside_memory_initializer.go index 971a135..cd02096 100644 --- a/ats/verify/simulation/wayside/memory/wayside_memory_initializer.go +++ b/ats/verify/simulation/wayside/memory/wayside_memory_initializer.go @@ -1,35 +1,24 @@ package memory import ( - "fmt" - - "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" "joylink.club/bj-rtsts-server/ats/verify/protos/state" ) // 根据地图数据来初始VerifyMemoryModel,包括对地图数据的校验,构建设备间固定关系, // 初始化设备状态。 -type WaysideMemoryInitializer struct { - memory *WaysideMemory -} - -func (me *WaysideMemoryInitializer) Create(memory *WaysideMemory) *WaysideMemoryInitializer { - me.memory = memory - return me -} // 从地图数据构建仿真内存模型 -func (me *WaysideMemoryInitializer) InitFromMap(proto *graphicData.RtssGraphicStorage) { - me.initFromMapForTest(proto) +func InitFromMap(status *VerifyStatus, mapInfo *VerifyStructure) { + initFromMapForTest(status, mapInfo) } // 暂时测试用 -func (me *WaysideMemoryInitializer) initFromMapForTest(proto *graphicData.RtssGraphicStorage) { - for _, turnout := range proto.Turnouts { - var swtichState *state.SwitchState = new(state.SwitchState) - swtichState.Id = fmt.Sprintf("%d", turnout.Index) - swtichState.Normal = true - swtichState.Reverse = false - me.memory.Status.SwitchStateMap[swtichState.Id] = swtichState +func initFromMapForTest(status *VerifyStatus, mapInfo *VerifyStructure) { + for _, turnout := range mapInfo.SwitchDeviceModelMap { + status.LinkStateMap.Store(turnout.GetIndex(), &state.SwitchState{ + Id: turnout.GetIndex(), + Normal: true, + Reverse: false, + }) } } diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_map.go b/ats/verify/simulation/wayside/memory/wayside_memory_map.go new file mode 100644 index 0000000..0906639 --- /dev/null +++ b/ats/verify/simulation/wayside/memory/wayside_memory_map.go @@ -0,0 +1,99 @@ +package memory + +import ( + "fmt" + "strconv" + "sync" + + "google.golang.org/protobuf/proto" + "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" + "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/face" + "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/model/device" + "joylink.club/bj-rtsts-server/db/model" + "joylink.club/bj-rtsts-server/service" +) + +// 仿真存储集合 +var graphicDataMap sync.Map + +// 轨旁仿真模型结构 +type VerifyStructure struct { + //计轴检测点设备模型集合,key为索引编号 + AxlePointDeviceModelMap map[string]face.AxlePointDeviceModeller + //道岔设备模型集合,key为索引编号 + SwitchDeviceModelMap map[string]face.SwitchDeviceModeller + //由端点确定的link模型集合,key为索引编号 + LinkSectionModelMap map[string]face.LinkSectionModeller + //计轴区段模型集合,key为索引编号 + AxleSectionModelMap map[string]face.AxleSectionModeller + //物理区段模型集合,key为索引编号 + PhysicalSectionModelMap map[string]face.PhysicalSectionModeller + //逻辑区段模型集合,key为索引编号 + LogicalSectionModelMap map[string]face.LogicalSectionModeller + //信号机模型集合,key为索引编号 + SignalDeviceModelMap map[string]face.SignalDeviceModeller +} + +// 创建一个地图数据模型结构数据 +func NewVerifyStructure() *VerifyStructure { + return &VerifyStructure{ + AxlePointDeviceModelMap: make(map[string]face.AxlePointDeviceModeller), + SwitchDeviceModelMap: make(map[string]face.SwitchDeviceModeller), + LinkSectionModelMap: make(map[string]face.LinkSectionModeller), + AxleSectionModelMap: make(map[string]face.AxleSectionModeller), + PhysicalSectionModelMap: make(map[string]face.PhysicalSectionModeller), + LogicalSectionModelMap: make(map[string]face.LogicalSectionModeller), + SignalDeviceModelMap: make(map[string]face.SignalDeviceModeller), + } +} + +// 将发布的地图数据放入内存中 +func PublishMapVerifyStructure(graphic model.PublishedGi) *VerifyStructure { + verifyStructure := NewVerifyStructure() + graphicStorage := &graphicData.RtssGraphicStorage{} + proto.Unmarshal(graphic.Proto, graphicStorage) + // 初始化道岔信息 + initGraphicTurnout(graphicStorage.Turnouts, verifyStructure) + // 初始化计轴信息 + // 初始化link信息 + // 初始化物理区段信息 + // 初始化逻辑区段信息 + // 初始化计轴区段信息 + // 初始化信号机信息 + graphicDataMap.Store(graphic.ID, verifyStructure) + return verifyStructure +} + +// 移除内存中的地图信息 +func DeleteMapVerifyStructure(mapId int32) { + graphicDataMap.Delete(mapId) +} + +// 获取内存中的地图信息 +func QueryMapVerifyStructure(mapId int32) *VerifyStructure { + d, ok := graphicDataMap.Load(mapId) + if ok { + return d.(*VerifyStructure) + } + publishdata, err := service.GetPublishedGiById(int(mapId)) + if err != nil { + panic(err) + } + if publishdata != nil { + return PublishMapVerifyStructure(*publishdata) + } + panic(fmt.Sprintf("地图【id:%d】不存在", mapId)) +} + +// 初始化道岔信息 +func initGraphicTurnout(turnouts []*graphicData.Turnout, data *VerifyStructure) { + for _, t := range turnouts { + id := strconv.Itoa(int(t.Index)) + data.SwitchDeviceModelMap[id] = &device.SwitchDeviceModel{ + DeviceModel: face.DeviceModel{ + GraphicId: t.Common.Id, + Index: id, + }, + } + } +} diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_section_mapper.go b/ats/verify/simulation/wayside/memory/wayside_memory_section_mapper.go deleted file mode 100644 index 23f1469..0000000 --- a/ats/verify/simulation/wayside/memory/wayside_memory_section_mapper.go +++ /dev/null @@ -1,11 +0,0 @@ -package memory - -//实现设备到区段的映射 -type WaysideMemorySectionMapper struct { - memory *WaysideMemory -} - -func (me *WaysideMemorySectionMapper) Create(memory *WaysideMemory) *WaysideMemorySectionMapper { - me.memory = memory - return me -} diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_train_runtime.go b/ats/verify/simulation/wayside/memory/wayside_memory_train_runtime.go deleted file mode 100644 index d687ee4..0000000 --- a/ats/verify/simulation/wayside/memory/wayside_memory_train_runtime.go +++ /dev/null @@ -1,11 +0,0 @@ -package memory - -//对内存模型的列车运行时数据操作的更新器 -type WaysideMemoryTrainRuntime struct { - memory *WaysideMemory -} - -func (tr *WaysideMemoryTrainRuntime) Create(memory *WaysideMemory) *WaysideMemoryTrainRuntime { - tr.memory = memory - return tr -} diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_variation.go b/ats/verify/simulation/wayside/memory/wayside_memory_variation.go deleted file mode 100644 index 4e64f6f..0000000 --- a/ats/verify/simulation/wayside/memory/wayside_memory_variation.go +++ /dev/null @@ -1,11 +0,0 @@ -package memory - -//计算当前时刻与上一时刻状态的变化量,用于前端页面增量更新 -type WaysideMemoryVariation struct { - memory *WaysideMemory -} - -func (me *WaysideMemoryVariation) Create(memory *WaysideMemory) *WaysideMemoryVariation { - me.memory = memory - return me -} diff --git a/ats/verify/simulation/wayside/memory/wayside_path_layer.go b/ats/verify/simulation/wayside/memory/wayside_path_layer.go deleted file mode 100644 index fa535fb..0000000 --- a/ats/verify/simulation/wayside/memory/wayside_path_layer.go +++ /dev/null @@ -1,11 +0,0 @@ -package memory - -//端点和轨道构成的路径层 -type WaysidePathLayer struct { - memory *WaysideMemory -} - -func (me *WaysidePathLayer) Create(memory *WaysideMemory) *WaysidePathLayer { - me.memory = memory - return me -} diff --git a/ats/verify/simulation/wayside/memory/wayside_simulation.go b/ats/verify/simulation/wayside/memory/wayside_simulation.go new file mode 100644 index 0000000..985d367 --- /dev/null +++ b/ats/verify/simulation/wayside/memory/wayside_simulation.go @@ -0,0 +1,24 @@ +package memory + +// 轨旁仿真定义 +type VerifySimulation struct { + //地图id + MapId int32 + //仿真id + SimulationId string + //仿真内存数据 + Memory *WaysideMemory +} + +// 创建仿真对象 +func CreateSimulation(mapId int32, simulationId string) *VerifySimulation { + m := &WaysideMemory{} + verifySimulation := &VerifySimulation{ + MapId: mapId, + SimulationId: simulationId, + Memory: m.Create(), + } + // 初始化构地图设备状态 + InitFromMap(verifySimulation.Memory.Status, QueryMapVerifyStructure(mapId)) + return verifySimulation +} diff --git a/ats/verify/simulation/wayside/runtime/wayside_runtime.go b/ats/verify/simulation/wayside/runtime/wayside_runtime.go deleted file mode 100644 index 8a60c01..0000000 --- a/ats/verify/simulation/wayside/runtime/wayside_runtime.go +++ /dev/null @@ -1,34 +0,0 @@ -package runtime - -import ( - "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" - "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory" -) - -// 轨旁仿真定义 -type VerifySimulation struct { - //地图id - MapId int32 - //仿真id - SimulationId string - //仿真内存数据 - Memory *memory.WaysideMemory -} - -// 创建仿真 -func CreateSimulation(mapId int32, simulationId string) *VerifySimulation { - sim := new(VerifySimulation) - sim.MapId = mapId - sim.SimulationId = simulationId - return sim -} - -// 启动仿真 -func (me *VerifySimulation) Start(proto *graphicData.RtssGraphicStorage) { - me.Memory.Initializer.InitFromMap(proto) -} - -// 关闭仿真 -func (me *VerifySimulation) Shutdown() { - -} diff --git a/ats/verify/simulation/wayside/verify_memory.go b/ats/verify/simulation/wayside/verify_memory.go deleted file mode 100644 index b8c15a8..0000000 --- a/ats/verify/simulation/wayside/verify_memory.go +++ /dev/null @@ -1,33 +0,0 @@ -package wayside - -import "joylink.club/bj-rtsts-server/ats/verify/protos/state" - -//轨旁仿真模型结构 -type VerifyStructure struct { -} - -//轨旁仿真模型状态 -type VerifyStatus struct { - //道岔状态,key为道岔id即索引 - SwitchStateMap map[string]*state.SwitchState - //轨道状态,key为轨道id即索引 - LinkStateMap map[string]*state.LinkState - //列车状态,key为列车id即索引 - TrainStateMap map[string]*state.TrainState - //计轴区段状态,key为计轴区段的id即索引 - AxleSectionStateMap map[string]*state.SectionState - //物理区段状态,key为物理区段id即索引 - PhysicalSectionStateMap map[string]*state.SectionState - //逻辑区段状态,key为逻辑区段id即索引 - LogicSectionStateMap map[string]*state.SectionState - //信号机状态,key为信号机id,即索引 - SignalStateMap map[string]*state.SignalState -} - -//轨旁仿真内存模型 -type VerifyMemory struct { - //固定关系数据:轨旁仿真模型结构 - Structure *VerifyStructure - //可变状态数据:轨旁仿真模型状态 - Status *VerifyStatus -} diff --git a/grpcproto/simulation_server.go b/grpcproto/simulation_server.go index fc28408..eac871d 100644 --- a/grpcproto/simulation_server.go +++ b/grpcproto/simulation_server.go @@ -1,14 +1,13 @@ package apiproto import ( - "strconv" "strings" "time" "github.com/golang/protobuf/proto" "joylink.club/bj-rtsts-server/ats/verify/protos/state" "joylink.club/bj-rtsts-server/ats/verify/simulation" - "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside" + "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory" ) type SimulationServer struct{} @@ -33,15 +32,19 @@ func (t *SimulationServer) allMsgData(params map[string]string) []byte { if simulation == nil { return nil } - return []byte(generateTestState(simulation).String()) + data, err := proto.Marshal(generateTestState(simulation)) + if err != nil { + panic(err) + } + return data } // 定时发送数据 func (t *SimulationServer) onTick() []TopicMsg { - msgArr := make([]TopicMsg, len(simulation.SimulationMap)) - i := 0 - for k, v := range simulation.SimulationMap { - channelName := handlerChannelName(k, t.getChannelName()) + simArr := simulation.GetSimulationArr() + msgArr := make([]TopicMsg, len(simArr)) + for i, v := range simArr { + channelName := handlerChannelName(v.SimulationId, t.getChannelName()) b, err := proto.Marshal(generateTestState(v)) if err != nil { panic(err) @@ -50,7 +53,6 @@ func (t *SimulationServer) onTick() []TopicMsg { channalName: channelName, data: b, } - i++ } return msgArr } @@ -61,8 +63,8 @@ func handlerChannelName(sid string, format string) string { } // 生成道岔测试状态数据 -func generateTestState(v *wayside.VerifyMemory) *state.PushedDevicesStatus { - switchMap := v.Status.SwitchStateMap +func generateTestState(v *memory.VerifySimulation) *state.PushedDevicesStatus { + /*switchMap := v.Status.SwitchStateMap switchArr := make([]*state.SwitchState, 9) if len(switchMap) == 0 { for i := 0; i < 9; i++ { @@ -79,11 +81,9 @@ func generateTestState(v *wayside.VerifyMemory) *state.PushedDevicesStatus { switchArr[i] = v i++ } - } + }*/ return &state.PushedDevicesStatus{ - All: true, - AllStatus: &state.AllDevicesStatus{ - SwitchState: switchArr, - }, + All: true, + AllStatus: &state.AllDevicesStatus{}, } }