【修改发送道岔逻辑】
This commit is contained in:
parent
e6921ad33d
commit
88fbd2abce
@ -1,36 +1,41 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
|
||||
"joylink.club/bj-rtsts-server/dto"
|
||||
)
|
||||
|
||||
// 道岔相关道岔操作方法
|
||||
func ChangeTurnoutState(simulation *VerifySimulation, status *state.SwitchState, mapId int32) {
|
||||
|
||||
/*
|
||||
index, err := strconv.Atoi(status.Id)
|
||||
if err != nil {
|
||||
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "参数转换出错"})
|
||||
}
|
||||
uid := GetDeviceUidByIndex(mapId, int32(index), &graphicData.Turnout{})
|
||||
fmt.Printf("修改道岔【UID:%s】\n", uid)
|
||||
allSwitchMap := &simulation.Memory.Status.SwitchStateMap
|
||||
d, ok := allSwitchMap.Load(status.Id)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("道岔【%s】不存在", status.Id))
|
||||
}
|
||||
cur := d.(*state.SwitchState)
|
||||
if !proto.Equal(cur, status) { // 如果信息发送了变化
|
||||
// 将信息合并到当前设备状态中
|
||||
cur.Normal = status.Normal
|
||||
cur.Reverse = status.Reverse
|
||||
// 将变更信息放入变更状态队列中
|
||||
simulation.Memory.ChangeStatus.SwitchStateMap.Store(status.Id, proto.Clone(cur))
|
||||
}
|
||||
*/
|
||||
index, err := strconv.Atoi(status.Id)
|
||||
if err != nil {
|
||||
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "参数转换出错"})
|
||||
}
|
||||
uid := QueryUidByMidAndIndex(mapId, int32(index), &graphicData.Turnout{})
|
||||
log.Default().Printf("修改道岔【UID:%s】\n", uid)
|
||||
allSwitchMap := &simulation.Memory.Status.SwitchStateMap
|
||||
d, ok := allSwitchMap.Load(uid)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("道岔【UID:%s】不存在", uid))
|
||||
}
|
||||
status.Id = uid
|
||||
cur := d.(*state.SwitchState)
|
||||
if !proto.Equal(cur, status) { // 如果信息发送了变化
|
||||
// 将信息合并到当前设备状态中
|
||||
cur.Normal = status.Normal
|
||||
cur.Reverse = status.Reverse
|
||||
// 将变更信息放入变更状态队列中
|
||||
simulation.Memory.ChangeStatus.SwitchStateMap.Store(status.Id, proto.Clone(cur))
|
||||
}
|
||||
}
|
||||
|
||||
// 获取全部的道岔状态
|
||||
// 获取全部的道岔状态,动力学使用
|
||||
func GetAllTurnoutState(simulation *VerifySimulation) []*state.SwitchState {
|
||||
allSwitchMap := &simulation.Memory.Status.SwitchStateMap
|
||||
var switchArr []*state.SwitchState
|
||||
@ -41,8 +46,20 @@ func GetAllTurnoutState(simulation *VerifySimulation) []*state.SwitchState {
|
||||
return switchArr
|
||||
}
|
||||
|
||||
// 获取仿真地图的道岔状态
|
||||
// 获取仿真地图的道岔状态,前端推送
|
||||
func GetMapAllTurnoutState(simulation *VerifySimulation, mapId int32) []*state.SwitchState {
|
||||
allSwitchMap := &simulation.Memory.Status.SwitchStateMap
|
||||
uidMap := QueryMapUidMapByType(mapId, &graphicData.Turnout{})
|
||||
uidToIndex := make(map[string]int32, len(uidMap))
|
||||
for _, u := range uidMap {
|
||||
uidToIndex[u.Uid] = u.Index
|
||||
}
|
||||
var switchArr []*state.SwitchState
|
||||
allSwitchMap.Range(func(_, v any) bool {
|
||||
o := v.(*state.SwitchState)
|
||||
sendObj := &state.SwitchState{Id: strconv.Itoa(int(uidToIndex[o.Id])), Normal: o.Normal, Reverse: o.Reverse}
|
||||
switchArr = append(switchArr, sendObj)
|
||||
return true
|
||||
})
|
||||
return switchArr
|
||||
}
|
||||
|
@ -90,16 +90,6 @@ func CreateSimulation(projectId int32, mapIds []int32) (*VerifySimulation, error
|
||||
repoVersion := "0.1"
|
||||
repo := repository.FindRepository(repoId, repoVersion)
|
||||
if repo == nil {
|
||||
//var storages []*graphicData.RtssGraphicStorage
|
||||
//var rmapIds []int32
|
||||
//for _, mapId := range mapIds {
|
||||
// storage := QueryGraphicStorage(mapId)
|
||||
// if storage == nil {
|
||||
// continue
|
||||
// }
|
||||
// storages = append(storages, storage)
|
||||
// rmapIds = append(rmapIds, mapId)
|
||||
//}
|
||||
protoRepo, err := buildProtoRepository(mapIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user