【修改仿真ID生成规则】
【消息增加发送区段状态】
This commit is contained in:
parent
21f4f81972
commit
845a8b2f33
@ -1,16 +1,37 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"joylink.club/bj-rtsts-server/dynamics"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
|
||||
"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() {
|
||||
dynamics.RegisterTrainInfoHandler(func(info *dynamics.TrainInfo) {
|
||||
for _, simulation := range GetSimulationArr() {
|
||||
@ -94,7 +115,8 @@ func DestroySimulation(simulationId string) {
|
||||
|
||||
// 创建时生成仿真Id
|
||||
func createSimulationId(mapId int32) string {
|
||||
return strconv.Itoa(int(mapId))
|
||||
// 当前服务器IP + 端口 + 地图
|
||||
return simulationId_prefix + "_" + strconv.Itoa(config.Config.Server.Port) + "_" + strconv.Itoa(int(mapId))
|
||||
}
|
||||
|
||||
// 获取仿真列表
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -83,11 +83,7 @@ func GetAllTrainState(simulation *VerifySimulation) []*state.TrainState {
|
||||
allTrainMap := &simulation.Memory.Status.TrainStateMap
|
||||
var trainArr []*state.TrainState
|
||||
allTrainMap.Range(func(k, v any) bool {
|
||||
d := v.(*state.TrainState)
|
||||
if d.Show { // 只推送显示的车信息
|
||||
c := proto.Clone(d).(*state.TrainState)
|
||||
trainArr = append(trainArr, c)
|
||||
}
|
||||
trainArr = append(trainArr, v.(*state.TrainState))
|
||||
return true
|
||||
})
|
||||
return trainArr
|
||||
|
@ -30,12 +30,7 @@ func GetAllTurnoutState(simulation *VerifySimulation) []*state.SwitchState {
|
||||
allSwitchMap := &simulation.Memory.Status.SwitchStateMap
|
||||
var switchArr []*state.SwitchState
|
||||
allSwitchMap.Range(func(k, v any) bool {
|
||||
d := v.(*state.SwitchState)
|
||||
switchArr = append(switchArr, &state.SwitchState{
|
||||
Id: d.Id,
|
||||
Normal: d.Normal,
|
||||
Reverse: d.Reverse,
|
||||
})
|
||||
switchArr = append(switchArr, v.(*state.SwitchState))
|
||||
return true
|
||||
})
|
||||
return switchArr
|
||||
|
@ -32,8 +32,9 @@ func (s *VerifySimulation) GetAllState() *state.PushedDevicesStatus {
|
||||
return &state.PushedDevicesStatus{
|
||||
All: true,
|
||||
AllStatus: &state.AllDevicesStatus{
|
||||
SwitchState: GetAllTurnoutState(s),
|
||||
TrainState: GetAllTrainState(s),
|
||||
SwitchState: GetAllTurnoutState(s),
|
||||
TrainState: GetAllTrainState(s),
|
||||
SectionState: append(GetAllAxleSectionState(s), GetAllPhysicalSectionState(s)...),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user