【提出第三方、world启动代码、修改运行环境列表返回结果】

This commit is contained in:
weizhihong 2023-10-26 18:00:17 +08:00
parent 4c9e9bfe35
commit b6534bc554
5 changed files with 75 additions and 68 deletions

View File

@ -21,7 +21,7 @@ func PageProjectRunConfigQuery(query *dto.PageProjectRunConfigReqDto) *dto.PageD
if err != nil { if err != nil {
panic(sys_error.New("查询失败,数据库错误请联系运维人员", err)) panic(sys_error.New("查询失败,数据库错误请联系运维人员", err))
} }
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records} return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: dto.ConvertToRunConfigFromSlice(records)}
} }
// 查询项目运行环境列表 // 查询项目运行环境列表

View File

@ -205,8 +205,7 @@ func (d *dynamics) initDynamics() {
// 动力学运行所需数据 // 动力学运行所需数据
func (d *dynamics) initDynamicsRunRepository() error { func (d *dynamics) initDynamicsRunRepository() error {
// 动力学接口调用 // 动力学接口调用
lineBaseInfo := d.manager.GetDynamicsRunRepository() err := d.requestStartSimulation(d.manager.GetDynamicsRunRepository())
err := d.requestStartSimulation(lineBaseInfo)
if err != nil { if err != nil {
return err return err
} }

View File

@ -15,7 +15,7 @@ import (
// 联锁代理通信接口 // 联锁代理通信接口
type InterlockMessageManager interface { type InterlockMessageManager interface {
CollectRelayInfo() *message.InterlockSendMsgPkg CollectRelayInfo() []*message.InterlockSendMsgPkg
HandleDriverInfo(b []byte) HandleDriverInfo(b []byte)
GetInterlockRunConfig() *config.InterlockConfig GetInterlockRunConfig() *config.InterlockConfig
} }
@ -78,10 +78,11 @@ func (i *interlockProxy) Start(manager InterlockMessageManager) {
i.collectInfoTaskCancel = cancle i.collectInfoTaskCancel = cancle
} }
const ( // 采集电路状态发送间隔,单位ms
// 采集电路状态发送间隔,单位ms const InterlockMessageSendInterval = 50
InterlockMessageSendInterval = 50
) // 序列号
var serialNumber uint8
// 定时发送采集电路状态任务 // 定时发送采集电路状态任务
func (i *interlockProxy) collectInfoStateTask(ctx context.Context) { func (i *interlockProxy) collectInfoStateTask(ctx context.Context) {
@ -98,7 +99,11 @@ func (i *interlockProxy) collectInfoStateTask(ctx context.Context) {
default: default:
} }
collectInfoStates := i.manager.CollectRelayInfo() collectInfoStates := i.manager.CollectRelayInfo()
i.sendCollectUdpClient.SendMsg(collectInfoStates) for _, state := range collectInfoStates {
serialNumber++
state.Header.SerialNumber = serialNumber
i.sendCollectUdpClient.SendMsg(state)
}
time.Sleep(time.Millisecond * InterlockMessageSendInterval) time.Sleep(time.Millisecond * InterlockMessageSendInterval)
} }
} }

View File

@ -5,20 +5,16 @@ import (
"fmt" "fmt"
"log/slog" "log/slog"
"math" "math"
"runtime"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
rtss_simulation "joylink.club/rtsssimulation"
"joylink.club/bj-rtsts-server/config" "joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/sys_error" "joylink.club/bj-rtsts-server/sys_error"
"joylink.club/bj-rtsts-server/third_party/dynamics" "joylink.club/bj-rtsts-server/third_party/dynamics"
"joylink.club/bj-rtsts-server/third_party/interlock"
"joylink.club/bj-rtsts-server/third_party/message" "joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/semi_physical_train" "joylink.club/bj-rtsts-server/third_party/semi_physical_train"
"joylink.club/bj-rtsts-server/ts/protos/graphicData" "joylink.club/bj-rtsts-server/ts/protos/graphicData"
@ -109,16 +105,6 @@ func CreateSimulation(projectId int32, mapIds []int32, runConfig string) (*Verif
if err != nil { if err != nil {
return nil, err return nil, err
} }
// 创建world
err = verifySimulation.initWorld()
if err != nil {
return nil, err
}
// 运行第三方服务
err = verifySimulation.runThirdParty()
if err != nil {
return nil, err
}
return verifySimulation, nil return verifySimulation, nil
} }
@ -416,7 +402,7 @@ func (s *VerifySimulation) GetInterlockRunConfig() *config.InterlockConfig {
} }
// 采集联锁中的继电器消息 // 采集联锁中的继电器消息
func (s *VerifySimulation) CollectRelayInfo() *message.InterlockSendMsgPkg { func (s *VerifySimulation) CollectRelayInfo() []*message.InterlockSendMsgPkg {
msg := &message.InterlockSendMsgPkg{} msg := &message.InterlockSendMsgPkg{}
relayArr := make([]string, 256) relayArr := make([]string, 256)
for index, id := range relayArr { for index, id := range relayArr {
@ -427,7 +413,7 @@ func (s *VerifySimulation) CollectRelayInfo() *message.InterlockSendMsgPkg {
} }
} }
return msg return []*message.InterlockSendMsgPkg{}
} }
// 初始化仿真运行配置 // 初始化仿真运行配置
@ -473,48 +459,6 @@ func (s *VerifySimulation) initRepository() error {
return nil return nil
} }
// 创建world
func (s *VerifySimulation) initWorld() error {
//创建仿真
w, err := rtss_simulation.NewSimulation(s.Repo)
if err != nil {
return sys_error.New("仿真创建失败", err)
}
s.World = w
// 保证World关闭
runtime.SetFinalizer(s, func(verifySimulation *VerifySimulation) {
slog.Info("---关闭仿真World---")
verifySimulation.World.Close()
})
return nil
}
// 运行仿真第三方模块
func (s *VerifySimulation) runThirdParty() error {
// 动力学启动
err := dynamics.Default().Start(s)
if err != nil {
return err
}
// 半实物启动
semi_physical_train.Default().Start(s)
// 联锁启动
interlock.Default().Start(s)
return nil
}
// 停止仿真
func (s *VerifySimulation) StopSimulation() {
// 停止ecs world
s.World.Close()
// 停止动力学接口功能
dynamics.Default().Stop()
// 停止半实物
semi_physical_train.Default().Stop()
// 联锁启动
interlock.Default().Stop()
}
func buildProtoRepository(mapIds []int32) (*proto.Repository, error) { func buildProtoRepository(mapIds []int32) (*proto.Repository, error) {
repo := &proto.Repository{} repo := &proto.Repository{}
var exceptStationGiMapIds []int32 var exceptStationGiMapIds []int32

View File

@ -1,15 +1,21 @@
package ts package ts
import ( import (
"log/slog"
"runtime"
"strconv" "strconv"
"sync" "sync"
"joylink.club/bj-rtsts-server/config" "joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/message_server" "joylink.club/bj-rtsts-server/message_server"
"joylink.club/bj-rtsts-server/sys_error" "joylink.club/bj-rtsts-server/sys_error"
"joylink.club/bj-rtsts-server/third_party/dynamics"
"joylink.club/bj-rtsts-server/third_party/interlock"
"joylink.club/bj-rtsts-server/third_party/semi_physical_train"
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory" "joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
rtss_simulation "joylink.club/rtsssimulation"
) )
// 仿真存储集合 // 仿真存储集合
@ -38,6 +44,16 @@ func CreateSimulation(projectId int32, mapIds []int32, runConfig string) (string
return "", err return "", err
} }
verifySimulation.SimulationId = simulationId verifySimulation.SimulationId = simulationId
// world构建
err = initWorld(verifySimulation)
if err != nil {
return "", err
}
// 第三方服务处理
err = runThirdParty(verifySimulation)
if err != nil {
return "", err
}
simulationMap.Store(simulationId, verifySimulation) simulationMap.Store(simulationId, verifySimulation)
// 全部成功,启动仿真 // 全部成功,启动仿真
verifySimulation.World.StartUp() verifySimulation.World.StartUp()
@ -55,8 +71,51 @@ func DestroySimulation(simulationId string) {
} }
simulationMap.Delete(simulationId) simulationMap.Delete(simulationId)
simulationInfo := s.(*memory.VerifySimulation) simulationInfo := s.(*memory.VerifySimulation)
// 停止ecs world
simulationInfo.World.Close()
// 停止第三方
stopThirdParty(simulationInfo)
message_server.Close(simulationInfo) message_server.Close(simulationInfo)
simulationInfo.StopSimulation() }
// 创建world
func initWorld(s *memory.VerifySimulation) error {
//创建仿真
w, err := rtss_simulation.NewSimulation(s.Repo)
if err != nil {
return sys_error.New("仿真创建失败", err)
}
s.World = w
// 保证World关闭
runtime.SetFinalizer(s, func(verifySimulation *memory.VerifySimulation) {
slog.Info("---关闭仿真World---")
verifySimulation.World.Close()
})
return nil
}
// 运行仿真第三方模块
func runThirdParty(s *memory.VerifySimulation) error {
// 动力学启动
err := dynamics.Default().Start(s)
if err != nil {
return err
}
// 半实物启动
semi_physical_train.Default().Start(s)
// 联锁启动
interlock.Default().Start(s)
return nil
}
// 停止仿真
func stopThirdParty(s *memory.VerifySimulation) {
// 停止动力学接口功能
dynamics.Default().Stop()
// 停止半实物
semi_physical_train.Default().Stop()
// 联锁启动
interlock.Default().Stop()
} }
func createSimulationId(projectId int32) string { func createSimulationId(projectId int32) string {