【解决道岔转换报空指针问题】
This commit is contained in:
parent
125dab8a46
commit
95599bfae3
@ -216,7 +216,7 @@ func dynamicsRun(verifySimulation *memory.VerifySimulation) {
|
||||
stateSlice := memory.GetAllTurnoutState(verifySimulation)
|
||||
var turnoutInfoSlice []*dynamics.TurnoutInfo
|
||||
for _, sta := range stateSlice {
|
||||
code64, err := strconv.ParseUint(verifySimulation.GetComIdByUid(sta.Id), 10, 16)
|
||||
code64, err := strconv.ParseUint(sta.Id, 10, 16)
|
||||
if err != nil {
|
||||
zap.S().Error("id转uint16报错", err)
|
||||
}
|
||||
|
@ -36,11 +36,13 @@ func ChangeTurnoutState(simulation *VerifySimulation, status *state.SwitchState,
|
||||
}
|
||||
|
||||
// 获取全部的道岔状态,动力学使用
|
||||
func GetAllTurnoutState(simulation *VerifySimulation) []*state.SwitchState {
|
||||
allSwitchMap := &simulation.Memory.Status.SwitchStateMap
|
||||
func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
|
||||
allSwitchMap := &sim.Memory.Status.SwitchStateMap
|
||||
var switchArr []*state.SwitchState
|
||||
allSwitchMap.Range(func(_, v any) bool {
|
||||
switchArr = append(switchArr, v.(*state.SwitchState))
|
||||
o := v.(*state.SwitchState)
|
||||
sendObj := &state.SwitchState{Id: sim.GetComIdByUid(o.Id), Normal: o.Normal, Reverse: o.Reverse}
|
||||
switchArr = append(switchArr, sendObj)
|
||||
return true
|
||||
})
|
||||
return switchArr
|
||||
@ -49,17 +51,17 @@ func GetAllTurnoutState(simulation *VerifySimulation) []*state.SwitchState {
|
||||
// 获取仿真地图的道岔状态,前端推送
|
||||
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))
|
||||
switchArr := make([]*state.SwitchState, len(uidMap))
|
||||
for _, u := range uidMap {
|
||||
uidToIndex[u.Uid] = u.Index
|
||||
}
|
||||
var switchArr []*state.SwitchState
|
||||
allSwitchMap.Range(func(_, v any) bool {
|
||||
v, ok := allSwitchMap.Load(u.Uid)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
o := v.(*state.SwitchState)
|
||||
sendObj := &state.SwitchState{Id: strconv.Itoa(int(uidToIndex[o.Id])), Normal: o.Normal, Reverse: o.Reverse}
|
||||
sendObj := &state.SwitchState{Id: strconv.Itoa(int(u.Index)), Normal: o.Normal, Reverse: o.Reverse}
|
||||
switchArr = append(switchArr, sendObj)
|
||||
return true
|
||||
})
|
||||
}
|
||||
return switchArr
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user