【获取服务通道名称】

This commit is contained in:
weizhihong 2023-08-31 14:06:53 +08:00
parent 805dd2381d
commit 1a4145bd5d
7 changed files with 159 additions and 21 deletions

View File

@ -13,6 +13,7 @@ import (
"joylink.club/bj-rtsts-server/ats/verify/protos/state" "joylink.club/bj-rtsts-server/ats/verify/protos/state"
"joylink.club/bj-rtsts-server/ats/verify/simulation" "joylink.club/bj-rtsts-server/ats/verify/simulation"
"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/config"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
apiproto "joylink.club/bj-rtsts-server/grpcproto" apiproto "joylink.club/bj-rtsts-server/grpcproto"
"joylink.club/bj-rtsts-server/middleware" "joylink.club/bj-rtsts-server/middleware"
@ -30,6 +31,7 @@ func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
authed.POST("/train/add", addTrain) authed.POST("/train/add", addTrain)
authed.POST("/train/remove", removeTrain) authed.POST("/train/remove", removeTrain)
authed.POST("/switch/operation", switchOperation) authed.POST("/switch/operation", switchOperation)
authed.GET("/getDataChannelName", getDataChannelName)
// 初始化地图信息 // 初始化地图信息
initPublishMapInfo() initPublishMapInfo()
@ -303,6 +305,25 @@ func switchOperation(c *gin.Context) {
c.JSON(http.StatusOK, "ok") c.JSON(http.StatusOK, "ok")
} }
// 获取仿真信息更新通道名称
//
// @Summary 获取仿真信息更新通道名称
//
// @Security JwtAuth
//
// @Description 获取仿真信息更新通道名称
// @Tags ATS测试仿真Api
// @Accept json
// @Produce json
// @Param Authorization header string true "JWT Token"
//
// @Success 200 {object} string
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/simulation/getDataChannelName [get]
func getDataChannelName(c *gin.Context) {
c.JSON(http.StatusOK, config.SimulationId_prefix+apiproto.MemoryChangeServerSuffix)
}
// 获取仿真设备数据并返回 // 获取仿真设备数据并返回
func checkDeviceDataAndReturn(simId string) *memory.VerifySimulation { func checkDeviceDataAndReturn(simId string) *memory.VerifySimulation {
deviceMemory := simulation.FindSimulation(simId) deviceMemory := simulation.FindSimulation(simId)

View File

@ -2,8 +2,6 @@ package simulation
import ( import (
"encoding/binary" "encoding/binary"
"net"
"strings"
"fmt" "fmt"
"net/http" "net/http"
@ -20,23 +18,6 @@ import (
"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(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
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() {
// vobc 发来的列车信息 // vobc 发来的列车信息
vobc.RegisterTrainInfoHandler(func(info []byte) { vobc.RegisterTrainInfoHandler(func(info []byte) {
@ -123,7 +104,7 @@ func DestroySimulation(simulationId string) {
// 创建时生成仿真Id // 创建时生成仿真Id
func createSimulationId(mapId int32) string { func createSimulationId(mapId int32) string {
// 当前服务器IP + 端口 + 地图 // 当前服务器IP + 端口 + 地图
return simulationId_prefix + "_" + strconv.Itoa(config.Config.Server.Port) + "_" + strconv.Itoa(int(mapId)) return config.SimulationId_prefix + "_" + strconv.Itoa(config.Config.Server.Port) + "_" + strconv.Itoa(int(mapId))
} }
// 获取仿真列表 // 获取仿真列表

View File

@ -3,9 +3,12 @@ package config
import ( import (
"flag" "flag"
"fmt" "fmt"
"net"
"os" "os"
"strings"
"github.com/spf13/viper" "github.com/spf13/viper"
"joylink.club/bj-rtsts-server/dto"
) )
type AppConfig struct { type AppConfig struct {
@ -59,6 +62,23 @@ type vobc struct {
var Config AppConfig var Config AppConfig
var SimulationId_prefix = (func() string {
ip := "127.0.0.1"
addrList, err := net.InterfaceAddrs()
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
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]
})()
// 获取配置文件名称,从运行flag参数config中获取若未提供使用默认'dev' // 获取配置文件名称,从运行flag参数config中获取若未提供使用默认'dev'
func getConfigName() string { func getConfigName() string {
configName := "" configName := ""

View File

@ -2818,6 +2818,49 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/simulation/getDataChannelName": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "获取仿真信息更新通道名称",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "获取仿真信息更新通道名称",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/list": { "/api/v1/simulation/list": {
"get": { "get": {
"security": [ "security": [

View File

@ -2811,6 +2811,49 @@
} }
} }
}, },
"/api/v1/simulation/getDataChannelName": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "获取仿真信息更新通道名称",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "获取仿真信息更新通道名称",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/list": { "/api/v1/simulation/list": {
"get": { "get": {
"security": [ "security": [

View File

@ -2207,6 +2207,33 @@ paths:
summary: ATS仿真销毁 summary: ATS仿真销毁
tags: tags:
- ATS测试仿真Api - ATS测试仿真Api
/api/v1/simulation/getDataChannelName:
get:
consumes:
- application/json
description: 获取仿真信息更新通道名称
parameters:
- description: JWT Token
in: header
name: Authorization
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
type: string
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 获取仿真信息更新通道名称
tags:
- ATS测试仿真Api
/api/v1/simulation/list: /api/v1/simulation/list:
get: get:
consumes: consumes:

View File

@ -6,16 +6,19 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"joylink.club/bj-rtsts-server/ats/verify/protos/state" "joylink.club/bj-rtsts-server/ats/verify/protos/state"
"joylink.club/bj-rtsts-server/ats/verify/simulation" "joylink.club/bj-rtsts-server/ats/verify/simulation"
"joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
) )
var MemoryChangeServerSuffix = "serve-data"
type MemoryChangeServer struct { type MemoryChangeServer struct {
SimulationMap map[string]*state.SimulationStatus SimulationMap map[string]*state.SimulationStatus
} }
// 返回通道格式 // 返回通道格式
func (t *MemoryChangeServer) getChannelName() string { func (t *MemoryChangeServer) getChannelName() string {
return "memory-data-change" return config.SimulationId_prefix + MemoryChangeServerSuffix
} }
// 消息运行间隔 // 消息运行间隔