【修改获取道岔状态信息】
This commit is contained in:
parent
8ec370bd8c
commit
f41a4e0eb9
@ -2,7 +2,6 @@ package simulation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -27,7 +26,6 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
// vobc 发来的列车信息
|
// vobc 发来的列车信息
|
||||||
vobc.RegisterTrainInfoHandler(func(info []byte) {
|
vobc.RegisterTrainInfoHandler(func(info []byte) {
|
||||||
zap.S().Info("接收到vobc发送的列车消息", hex.EncodeToString(info))
|
|
||||||
memory.UdpUpdateTime.VobcTime = time.Now().UnixMilli()
|
memory.UdpUpdateTime.VobcTime = time.Now().UnixMilli()
|
||||||
for _, simulation := range GetSimulationArr() {
|
for _, simulation := range GetSimulationArr() {
|
||||||
simulation.Memory.Status.TrainStateMap.Range(func(_, value any) bool {
|
simulation.Memory.Status.TrainStateMap.Range(func(_, value any) bool {
|
||||||
@ -41,11 +39,9 @@ func init() {
|
|||||||
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
||||||
}
|
}
|
||||||
trainInfo := decoderVobcTrainState(info)
|
trainInfo := decoderVobcTrainState(info)
|
||||||
zap.S().Info("解析后vobc列车消息", trainInfo)
|
|
||||||
d := append(info, uint8(trainId))
|
d := append(info, uint8(trainId))
|
||||||
// 发送给动力学
|
// 发送给动力学
|
||||||
dynamics.SendDynamicsTrainMsg(d)
|
dynamics.SendDynamicsTrainMsg(d)
|
||||||
zap.S().Info("发送后:", hex.EncodeToString(d))
|
|
||||||
// 存放至列车中
|
// 存放至列车中
|
||||||
train.VobcState = trainInfo
|
train.VobcState = trainInfo
|
||||||
return true
|
return true
|
||||||
@ -62,7 +58,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
trainState := sta.(*state.TrainState)
|
trainState := sta.(*state.TrainState)
|
||||||
// 给半实物仿真发送速度
|
// 给半实物仿真发送速度
|
||||||
zap.S().Infof("发送到vobc发送的速度%d, %d \n", info.Speed, math.Abs(float64(info.Speed*36)))
|
|
||||||
vobc.SendTrainSpeedTask(math.Abs(float64(info.Speed * 36)))
|
vobc.SendTrainSpeedTask(math.Abs(float64(info.Speed * 36)))
|
||||||
// 更新列车状态
|
// 更新列车状态
|
||||||
memory.UpdateTrainState(simulation, convert(info, trainState, simulation))
|
memory.UpdateTrainState(simulation, convert(info, trainState, simulation))
|
||||||
|
@ -27,8 +27,8 @@ func ChangeTurnoutState(simulation *VerifySimulation, status *state.SwitchState,
|
|||||||
// 获取全部的道岔状态,动力学使用
|
// 获取全部的道岔状态,动力学使用
|
||||||
func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
|
func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
|
||||||
turnoutList := sim.Repo.TurnoutList()
|
turnoutList := sim.Repo.TurnoutList()
|
||||||
switchArr := make([]*state.SwitchState, len(turnoutList))
|
var switchArr []*state.SwitchState
|
||||||
for i, o := range turnoutList {
|
for _, o := range turnoutList {
|
||||||
p := entities.GetState(sim.WorldId, o.Id())
|
p := entities.GetState(sim.WorldId, o.Id())
|
||||||
sendObj := &state.SwitchState{Id: sim.GetComIdByUid(o.Id())}
|
sendObj := &state.SwitchState{Id: sim.GetComIdByUid(o.Id())}
|
||||||
switch p {
|
switch p {
|
||||||
@ -37,9 +37,8 @@ func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
|
|||||||
case entities.F:
|
case entities.F:
|
||||||
sendObj.Reverse = true
|
sendObj.Reverse = true
|
||||||
default:
|
default:
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
switchArr[i] = sendObj
|
switchArr = append(switchArr, sendObj)
|
||||||
}
|
}
|
||||||
return switchArr
|
return switchArr
|
||||||
}
|
}
|
||||||
@ -48,8 +47,7 @@ func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
|
|||||||
func GetMapAllTurnoutState(sim *VerifySimulation, mapId int32) []*state.SwitchState {
|
func GetMapAllTurnoutState(sim *VerifySimulation, mapId int32) []*state.SwitchState {
|
||||||
// 获取本地图下的道岔信息
|
// 获取本地图下的道岔信息
|
||||||
uidMap := QueryMapUidMapByType(mapId, &graphicData.Turnout{})
|
uidMap := QueryMapUidMapByType(mapId, &graphicData.Turnout{})
|
||||||
switchArr := make([]*state.SwitchState, len(uidMap))
|
var switchArr []*state.SwitchState
|
||||||
i := 0
|
|
||||||
for _, u := range uidMap {
|
for _, u := range uidMap {
|
||||||
p := entities.GetState(sim.WorldId, u.Uid)
|
p := entities.GetState(sim.WorldId, u.Uid)
|
||||||
sendObj := &state.SwitchState{Id: strconv.Itoa(int(u.Index))}
|
sendObj := &state.SwitchState{Id: strconv.Itoa(int(u.Index))}
|
||||||
@ -61,8 +59,7 @@ func GetMapAllTurnoutState(sim *VerifySimulation, mapId int32) []*state.SwitchSt
|
|||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switchArr[i] = sendObj
|
switchArr = append(switchArr, sendObj)
|
||||||
i++
|
|
||||||
}
|
}
|
||||||
return switchArr
|
return switchArr
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ type Slope struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Curve struct {
|
type Curve struct {
|
||||||
int
|
|
||||||
ID int32 `json:"id"`
|
ID int32 `json:"id"`
|
||||||
StartLinkId int32 `json:"startLinkId"`
|
StartLinkId int32 `json:"startLinkId"`
|
||||||
StartLinkOffset int32 `json:"startLinkOffset"`
|
StartLinkOffset int32 `json:"startLinkOffset"`
|
||||||
|
@ -63,8 +63,6 @@ type udpServer struct {
|
|||||||
eng gnet.Engine
|
eng gnet.Engine
|
||||||
addr string
|
addr string
|
||||||
multicore bool
|
multicore bool
|
||||||
|
|
||||||
eventHandlers []gnet.EventHandler
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *udpServer) OnBoot(eng gnet.Engine) gnet.Action {
|
func (server *udpServer) OnBoot(eng gnet.Engine) gnet.Action {
|
||||||
@ -192,7 +190,16 @@ func runSendTurnoutStateTask(tiFunc TurnoutInfoFunc) error {
|
|||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
fmt.Println("Recovered from panic:", r)
|
fmt.Println("Recovered from panic:", r)
|
||||||
}
|
}
|
||||||
|
// 重新运行
|
||||||
|
doDynamicsTurnoutUDPRun()
|
||||||
}()
|
}()
|
||||||
|
// 动力学UDP逻辑运行
|
||||||
|
doDynamicsTurnoutUDPRun()
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func doDynamicsTurnoutUDPRun() {
|
||||||
tick := time.Tick(50 * time.Millisecond)
|
tick := time.Tick(50 * time.Millisecond)
|
||||||
for range tick {
|
for range tick {
|
||||||
if turnoutInfoFunc == nil {
|
if turnoutInfoFunc == nil {
|
||||||
@ -209,8 +216,6 @@ func runSendTurnoutStateTask(tiFunc TurnoutInfoFunc) error {
|
|||||||
}
|
}
|
||||||
turnoutLifeSignal++
|
turnoutLifeSignal++
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析动力学的列车信息
|
// 解析动力学的列车信息
|
||||||
|
@ -41,8 +41,6 @@ func PublishMsg(channalName string, data []byte) {
|
|||||||
if resp.GetError() != nil {
|
if resp.GetError() != nil {
|
||||||
respError := resp.GetError()
|
respError := resp.GetError()
|
||||||
zap.S().Errorf("Publish msg[%s] error %d(%s)\n", channalName, respError.Code, respError.Message)
|
zap.S().Errorf("Publish msg[%s] error %d(%s)\n", channalName, respError.Code, respError.Message)
|
||||||
} else {
|
|
||||||
zap.S().Debugf("[%s] Successfully published", channalName)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,26 @@ var serverMap = make(map[string]*IMsgServer)
|
|||||||
// 消息服务退出通道
|
// 消息服务退出通道
|
||||||
var serverExitChannelMap = make(map[string]chan bool)
|
var serverExitChannelMap = make(map[string]chan bool)
|
||||||
|
|
||||||
|
// 服务运行
|
||||||
|
func doServerRun(tick *time.Ticker, server IMsgServer, exitChannel chan bool) {
|
||||||
|
// 循环推送信息
|
||||||
|
for {
|
||||||
|
<-tick.C
|
||||||
|
topicMsgs := server.onTick()
|
||||||
|
if len(topicMsgs) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, msg := range topicMsgs {
|
||||||
|
PublishMsg(msg.channalName, msg.data)
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case <-exitChannel:
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 注册服务
|
// 注册服务
|
||||||
func RegisterMsgServer(server IMsgServer) {
|
func RegisterMsgServer(server IMsgServer) {
|
||||||
if client == nil {
|
if client == nil {
|
||||||
@ -51,24 +71,11 @@ func RegisterMsgServer(server IMsgServer) {
|
|||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
zap.S().Debug("定时器发生错误,%v\n", r)
|
zap.S().Debug("定时器发生错误,%v\n", r)
|
||||||
}
|
}
|
||||||
|
// 重新启动,防止服务卡死
|
||||||
|
doServerRun(tick, server, exitChannel)
|
||||||
}()
|
}()
|
||||||
// 循环推送信息
|
// 循环推送信息
|
||||||
for {
|
doServerRun(tick, server, exitChannel)
|
||||||
<-tick.C
|
|
||||||
topicMsgs := server.onTick()
|
|
||||||
if len(topicMsgs) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, msg := range topicMsgs {
|
|
||||||
PublishMsg(msg.channalName, msg.data)
|
|
||||||
}
|
|
||||||
select {
|
|
||||||
case <-exitChannel:
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 59c2b04ebe1a5c1c499282004604bc6c25342ec1
|
Subproject commit 5fec9755b06bdb566e77092063676883e0bb6344
|
Loading…
Reference in New Issue
Block a user