【修改仿真ID生成规则】

【消息增加发送区段状态】
This commit is contained in:
weizhihong 2023-08-03 10:41:43 +08:00
parent 21f4f81972
commit 845a8b2f33
6 changed files with 98 additions and 16 deletions

View File

@ -1,16 +1,37 @@
package simulation package simulation
import ( import (
"net"
"strconv"
"strings"
"sync"
"go.uber.org/zap" "go.uber.org/zap"
"joylink.club/bj-rtsts-server/ats/verify/protos/state" "joylink.club/bj-rtsts-server/ats/verify/protos/state"
"joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/dynamics" "joylink.club/bj-rtsts-server/dynamics"
"strconv"
"sync"
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory" "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
) )
var simulationId_prefix = (func() string {
ip := "127.0.0.1"
addrList, err := net.InterfaceAddrs()
if err != nil {
panic(err)
}
for _, address := range addrList {
if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
ip = ipNet.IP.String()
}
}
}
ipArr := strings.Split(ip, ".")
return ipArr[2] + "_" + ipArr[3]
})()
func init() { func init() {
dynamics.RegisterTrainInfoHandler(func(info *dynamics.TrainInfo) { dynamics.RegisterTrainInfoHandler(func(info *dynamics.TrainInfo) {
for _, simulation := range GetSimulationArr() { for _, simulation := range GetSimulationArr() {
@ -94,7 +115,8 @@ func DestroySimulation(simulationId string) {
// 创建时生成仿真Id // 创建时生成仿真Id
func createSimulationId(mapId int32) string { func createSimulationId(mapId int32) string {
return strconv.Itoa(int(mapId)) // 当前服务器IP + 端口 + 地图
return simulationId_prefix + "_" + strconv.Itoa(config.Config.Server.Port) + "_" + strconv.Itoa(int(mapId))
} }
// 获取仿真列表 // 获取仿真列表

View File

@ -0,0 +1,34 @@
package memory
import (
"fmt"
"github.com/golang/protobuf/proto"
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
)
// 计轴区段状态更新
func ChangeAxleSectionState(simulation *VerifySimulation, status *state.SectionState) {
allSectionMap := &simulation.Memory.Status.AxleSectionStateMap
d, ok := allSectionMap.Load(status.Id)
if !ok {
panic(fmt.Sprintf("计轴区段【%s】不存在", status.Id))
}
cur := d.(*state.SectionState)
if !proto.Equal(cur, status) { // 如果信息发送了变化
cur.Occupied = status.Occupied
// 将变更信息放入变更状态队列中
simulation.Memory.ChangeStatus.AxleSectionStateMap.Store(status.Id, proto.Clone(cur))
}
}
// 获取全部的计轴区段状态
func GetAllAxleSectionState(simulation *VerifySimulation) []*state.SectionState {
allSectionMap := &simulation.Memory.Status.AxleSectionStateMap
var sectionArr []*state.SectionState
allSectionMap.Range(func(k, v any) bool {
sectionArr = append(sectionArr, v.(*state.SectionState))
return true
})
return sectionArr
}

View File

@ -0,0 +1,34 @@
package memory
import (
"fmt"
"github.com/golang/protobuf/proto"
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
)
// 物理区段状态更新
func ChangePhysicalSectionState(simulation *VerifySimulation, status *state.SectionState) {
allSectionMap := &simulation.Memory.Status.PhysicalSectionStateMap
d, ok := allSectionMap.Load(status.Id)
if !ok {
panic(fmt.Sprintf("物理区段【%s】不存在", status.Id))
}
cur := d.(*state.SectionState)
if !proto.Equal(cur, status) { // 如果信息发送了变化
cur.Occupied = status.Occupied
// 将变更信息放入变更状态队列中
simulation.Memory.ChangeStatus.PhysicalSectionStateMap.Store(status.Id, proto.Clone(cur))
}
}
// 获取全部的物理区段状态
func GetAllPhysicalSectionState(simulation *VerifySimulation) []*state.SectionState {
allSectionMap := &simulation.Memory.Status.PhysicalSectionStateMap
var sectionArr []*state.SectionState
allSectionMap.Range(func(k, v any) bool {
sectionArr = append(sectionArr, v.(*state.SectionState))
return true
})
return sectionArr
}

View File

@ -83,11 +83,7 @@ func GetAllTrainState(simulation *VerifySimulation) []*state.TrainState {
allTrainMap := &simulation.Memory.Status.TrainStateMap allTrainMap := &simulation.Memory.Status.TrainStateMap
var trainArr []*state.TrainState var trainArr []*state.TrainState
allTrainMap.Range(func(k, v any) bool { allTrainMap.Range(func(k, v any) bool {
d := v.(*state.TrainState) trainArr = append(trainArr, v.(*state.TrainState))
if d.Show { // 只推送显示的车信息
c := proto.Clone(d).(*state.TrainState)
trainArr = append(trainArr, c)
}
return true return true
}) })
return trainArr return trainArr

View File

@ -30,12 +30,7 @@ func GetAllTurnoutState(simulation *VerifySimulation) []*state.SwitchState {
allSwitchMap := &simulation.Memory.Status.SwitchStateMap allSwitchMap := &simulation.Memory.Status.SwitchStateMap
var switchArr []*state.SwitchState var switchArr []*state.SwitchState
allSwitchMap.Range(func(k, v any) bool { allSwitchMap.Range(func(k, v any) bool {
d := v.(*state.SwitchState) switchArr = append(switchArr, v.(*state.SwitchState))
switchArr = append(switchArr, &state.SwitchState{
Id: d.Id,
Normal: d.Normal,
Reverse: d.Reverse,
})
return true return true
}) })
return switchArr return switchArr

View File

@ -32,8 +32,9 @@ func (s *VerifySimulation) GetAllState() *state.PushedDevicesStatus {
return &state.PushedDevicesStatus{ return &state.PushedDevicesStatus{
All: true, All: true,
AllStatus: &state.AllDevicesStatus{ AllStatus: &state.AllDevicesStatus{
SwitchState: GetAllTurnoutState(s), SwitchState: GetAllTurnoutState(s),
TrainState: GetAllTrainState(s), TrainState: GetAllTrainState(s),
SectionState: append(GetAllAxleSectionState(s), GetAllPhysicalSectionState(s)...),
}, },
} }
} }