动力学列车数据配置
This commit is contained in:
parent
72374630de
commit
8f54503ab3
|
@ -212,12 +212,13 @@ func configTrain(c *gin.Context) {
|
|||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param Authorization header string true "JWT Token"
|
||||
// @Param AddTrainReqDto body dto.AddTrainReqDto true "ATS测试仿真-添加列车"
|
||||
// @Param AddTrainReqDto body dto.AddTrainReqDtoNew true "ATS测试仿真-添加列车"
|
||||
// @Success 200 {object} dto.AddTrainRspDto
|
||||
// @Failure 500 {object} dto.ErrorDto
|
||||
// @Router /api/v1/simulation/train/add [post]
|
||||
func addTrain(c *gin.Context) {
|
||||
req := dto.AddTrainReqDto{}
|
||||
//req := dto.AddTrainReqDto{}
|
||||
req := dto.AddTrainReqDtoNew{}
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
panic(sys_error.New("添加列车失败,请求参数异常", err))
|
||||
}
|
||||
|
@ -234,8 +235,39 @@ func addTrain(c *gin.Context) {
|
|||
RunDirection: req.RunDirection,
|
||||
TrainLength: req.TrainLength,
|
||||
WheelDiameter: req.WheelDiameter,
|
||||
/*TrainDynamicConfig: &state_proto.TrainDynamicConfig{
|
||||
//int32 mass=1;
|
||||
//基本阻力参数A
|
||||
BaseResistanceParamA: req.ConfigTrain.BaseResistanceParamA,
|
||||
// 基本阻力参数B
|
||||
BaseResistanceParamB: req.ConfigTrain.BaseResistanceParamB,
|
||||
// 基本阻力参数C
|
||||
BaseResistanceParamC: req.ConfigTrain.BaseResistanceParamC,
|
||||
//曲线阻力参数R1
|
||||
CurveResistanceParamR1: req.ConfigTrain.CurveResistanceParamR1,
|
||||
// 曲线阻力参数R2
|
||||
CurveResistanceParamR2: req.ConfigTrain.CurveResistanceParamR2,
|
||||
// 曲线阻力参数R3
|
||||
CurveResistanceParamR3: req.ConfigTrain.CurveResistanceParamR3,
|
||||
// 曲线阻力参数R4
|
||||
CurveResistanceParamR4: req.ConfigTrain.CurveResistanceParamR4,
|
||||
//旋转质量参数
|
||||
RevolvingMassParam: req.ConfigTrain.RevolvingMassParam,
|
||||
//是否跳跃
|
||||
Jump: req.ConfigTrain.Jump,
|
||||
//打滑(%)
|
||||
Slip: req.ConfigTrain.Slip,
|
||||
//前溜/后溜(mm)(正数前溜,负数后溜)
|
||||
Slide: req.ConfigTrain.Slide,
|
||||
//过标/欠标(mm)(正数过标,负数欠标)
|
||||
StopSign: req.ConfigTrain.StopSign,
|
||||
//车径
|
||||
//WheelDiameter: req.ConfigTrain.WheelDiameter,
|
||||
TrainEndsA: memory.DtoTrainEndsToStateProto(req.ConfigTrain.TrainEndsA),
|
||||
TrainEndsB: memory.DtoTrainEndsToStateProto(req.ConfigTrain.TrainEndsB),
|
||||
},*/
|
||||
}
|
||||
memory.AddTrainState(simulation, rsp, req.MapId)
|
||||
memory.AddTrainStateNew(simulation, rsp, req.ConfigTrain, req.MapId)
|
||||
c.JSON(http.StatusOK, &rsp)
|
||||
}
|
||||
|
||||
|
|
46
docs/docs.go
46
docs/docs.go
|
@ -4165,7 +4165,7 @@ const docTemplate = `{
|
|||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.AddTrainReqDto"
|
||||
"$ref": "#/definitions/dto.AddTrainReqDtoNew"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -5003,9 +5003,17 @@ const docTemplate = `{
|
|||
"PictureType_TrainData"
|
||||
]
|
||||
},
|
||||
"dto.AddTrainReqDto": {
|
||||
"dto.AddTrainReqDtoNew": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ConfigTrain": {
|
||||
"description": "列车数据配置",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.ConfigTrainData"
|
||||
}
|
||||
]
|
||||
},
|
||||
"devicePort": {
|
||||
"description": "道岔端口",
|
||||
"type": "string"
|
||||
|
@ -5043,7 +5051,6 @@ const docTemplate = `{
|
|||
"type": "boolean"
|
||||
},
|
||||
"wheelDiameter": {
|
||||
"description": "列车轮径",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
|
@ -5232,7 +5239,7 @@ const docTemplate = `{
|
|||
]
|
||||
},
|
||||
"baseResistanceParamA": {
|
||||
"description": "基本阻力参数A",
|
||||
"description": "Mass int32 ` + "`" + `json:\"mass\" form:\"mass\"` + "`" + ` // 列车的质量(100=1ton)",
|
||||
"type": "number"
|
||||
},
|
||||
"baseResistanceParamB": {
|
||||
|
@ -5263,14 +5270,6 @@ const docTemplate = `{
|
|||
"description": "是否跳跃",
|
||||
"type": "boolean"
|
||||
},
|
||||
"length": {
|
||||
"description": "列车的长度(cm)",
|
||||
"type": "integer"
|
||||
},
|
||||
"mass": {
|
||||
"description": "列车的质量(100=1ton)",
|
||||
"type": "integer"
|
||||
},
|
||||
"revolvingMassParam": {
|
||||
"description": "旋转质量参数",
|
||||
"type": "number"
|
||||
|
@ -5286,10 +5285,6 @@ const docTemplate = `{
|
|||
"stopSign": {
|
||||
"description": "过标/欠标(mm)(正数过标,负数欠标)",
|
||||
"type": "integer"
|
||||
},
|
||||
"wheelDiameter": {
|
||||
"description": "轮径(mm)",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -5308,12 +5303,13 @@ const docTemplate = `{
|
|||
"description": "雷达是否有效",
|
||||
"type": "boolean"
|
||||
},
|
||||
"speedSensorEnable": {
|
||||
"speedSensorEnableA": {
|
||||
"description": "2端速度传感器是否有效",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "boolean"
|
||||
}
|
||||
"type": "boolean"
|
||||
},
|
||||
"speedSensorEnableB": {
|
||||
"description": "2端速度传感器是否有效",
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -5327,8 +5323,16 @@ const docTemplate = `{
|
|||
"configData": {
|
||||
"$ref": "#/definitions/dto.ConfigTrainData"
|
||||
},
|
||||
"length": {
|
||||
"description": "列车的长度(cm)",
|
||||
"type": "integer"
|
||||
},
|
||||
"simulationId": {
|
||||
"type": "string"
|
||||
},
|
||||
"wheelDiameter": {
|
||||
"description": "轮径(mm)",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -4159,7 +4159,7 @@
|
|||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.AddTrainReqDto"
|
||||
"$ref": "#/definitions/dto.AddTrainReqDtoNew"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -4997,9 +4997,17 @@
|
|||
"PictureType_TrainData"
|
||||
]
|
||||
},
|
||||
"dto.AddTrainReqDto": {
|
||||
"dto.AddTrainReqDtoNew": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ConfigTrain": {
|
||||
"description": "列车数据配置",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.ConfigTrainData"
|
||||
}
|
||||
]
|
||||
},
|
||||
"devicePort": {
|
||||
"description": "道岔端口",
|
||||
"type": "string"
|
||||
|
@ -5037,7 +5045,6 @@
|
|||
"type": "boolean"
|
||||
},
|
||||
"wheelDiameter": {
|
||||
"description": "列车轮径",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
|
@ -5226,7 +5233,7 @@
|
|||
]
|
||||
},
|
||||
"baseResistanceParamA": {
|
||||
"description": "基本阻力参数A",
|
||||
"description": "Mass int32 `json:\"mass\" form:\"mass\"` // 列车的质量(100=1ton)",
|
||||
"type": "number"
|
||||
},
|
||||
"baseResistanceParamB": {
|
||||
|
@ -5257,14 +5264,6 @@
|
|||
"description": "是否跳跃",
|
||||
"type": "boolean"
|
||||
},
|
||||
"length": {
|
||||
"description": "列车的长度(cm)",
|
||||
"type": "integer"
|
||||
},
|
||||
"mass": {
|
||||
"description": "列车的质量(100=1ton)",
|
||||
"type": "integer"
|
||||
},
|
||||
"revolvingMassParam": {
|
||||
"description": "旋转质量参数",
|
||||
"type": "number"
|
||||
|
@ -5280,10 +5279,6 @@
|
|||
"stopSign": {
|
||||
"description": "过标/欠标(mm)(正数过标,负数欠标)",
|
||||
"type": "integer"
|
||||
},
|
||||
"wheelDiameter": {
|
||||
"description": "轮径(mm)",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -5302,12 +5297,13 @@
|
|||
"description": "雷达是否有效",
|
||||
"type": "boolean"
|
||||
},
|
||||
"speedSensorEnable": {
|
||||
"speedSensorEnableA": {
|
||||
"description": "2端速度传感器是否有效",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "boolean"
|
||||
}
|
||||
"type": "boolean"
|
||||
},
|
||||
"speedSensorEnableB": {
|
||||
"description": "2端速度传感器是否有效",
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -5321,8 +5317,16 @@
|
|||
"configData": {
|
||||
"$ref": "#/definitions/dto.ConfigTrainData"
|
||||
},
|
||||
"length": {
|
||||
"description": "列车的长度(cm)",
|
||||
"type": "integer"
|
||||
},
|
||||
"simulationId": {
|
||||
"type": "string"
|
||||
},
|
||||
"wheelDiameter": {
|
||||
"description": "轮径(mm)",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -35,8 +35,12 @@ definitions:
|
|||
- PictureType_RelayCabinetLayout
|
||||
- PictureType_IBP
|
||||
- PictureType_TrainData
|
||||
dto.AddTrainReqDto:
|
||||
dto.AddTrainReqDtoNew:
|
||||
properties:
|
||||
ConfigTrain:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.ConfigTrainData'
|
||||
description: 列车数据配置
|
||||
devicePort:
|
||||
description: 道岔端口
|
||||
type: string
|
||||
|
@ -65,7 +69,6 @@ definitions:
|
|||
description: 列车方向,true-上行,false-下行
|
||||
type: boolean
|
||||
wheelDiameter:
|
||||
description: 列车轮径
|
||||
type: integer
|
||||
type: object
|
||||
dto.AddTrainRspDto:
|
||||
|
@ -189,7 +192,8 @@ definitions:
|
|||
- $ref: '#/definitions/dto.ConfigTrainEnds'
|
||||
description: 车辆B端
|
||||
baseResistanceParamA:
|
||||
description: 基本阻力参数A
|
||||
description: Mass int32 `json:"mass" form:"mass"` //
|
||||
列车的质量(100=1ton)
|
||||
type: number
|
||||
baseResistanceParamB:
|
||||
description: 基本阻力参数B
|
||||
|
@ -212,12 +216,6 @@ definitions:
|
|||
jump:
|
||||
description: 是否跳跃
|
||||
type: boolean
|
||||
length:
|
||||
description: 列车的长度(cm)
|
||||
type: integer
|
||||
mass:
|
||||
description: 列车的质量(100=1ton)
|
||||
type: integer
|
||||
revolvingMassParam:
|
||||
description: 旋转质量参数
|
||||
type: number
|
||||
|
@ -230,9 +228,6 @@ definitions:
|
|||
stopSign:
|
||||
description: 过标/欠标(mm)(正数过标,负数欠标)
|
||||
type: integer
|
||||
wheelDiameter:
|
||||
description: 轮径(mm)
|
||||
type: integer
|
||||
type: object
|
||||
dto.ConfigTrainEnds:
|
||||
properties:
|
||||
|
@ -245,11 +240,12 @@ definitions:
|
|||
radarEnable:
|
||||
description: 雷达是否有效
|
||||
type: boolean
|
||||
speedSensorEnable:
|
||||
speedSensorEnableA:
|
||||
description: 2端速度传感器是否有效
|
||||
items:
|
||||
type: boolean
|
||||
type: array
|
||||
type: boolean
|
||||
speedSensorEnableB:
|
||||
description: 2端速度传感器是否有效
|
||||
type: boolean
|
||||
type: object
|
||||
dto.ConfigTrainReqDto:
|
||||
properties:
|
||||
|
@ -258,8 +254,14 @@ definitions:
|
|||
type: integer
|
||||
configData:
|
||||
$ref: '#/definitions/dto.ConfigTrainData'
|
||||
length:
|
||||
description: 列车的长度(cm)
|
||||
type: integer
|
||||
simulationId:
|
||||
type: string
|
||||
wheelDiameter:
|
||||
description: 轮径(mm)
|
||||
type: integer
|
||||
type: object
|
||||
dto.ErrorDto:
|
||||
properties:
|
||||
|
@ -3607,7 +3609,7 @@ paths:
|
|||
name: AddTrainReqDto
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/dto.AddTrainReqDto'
|
||||
$ref: '#/definitions/dto.AddTrainReqDtoNew'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
|
|
@ -55,24 +55,48 @@ type AddTrainReqDto struct {
|
|||
// 列车轮径
|
||||
WheelDiameter int32 `json:"wheelDiameter" from:"wheelDiameter"`
|
||||
}
|
||||
type AddTrainReqDtoNew struct {
|
||||
//仿真id
|
||||
SimulationId string `json:"simulationId" form:"simulationId"`
|
||||
//列车方向,true-上行,false-下行
|
||||
RunDirection bool `json:"up" form:"up"`
|
||||
//车头所在link的索引
|
||||
HeadLinkId string `json:"headLinkId" form:"headLinkId"`
|
||||
//车头所在link内的偏移量,单位为mm
|
||||
HeadLinkOffset int64 `json:"headLinkOffset" form:"headLinkOffset"`
|
||||
//物理区段、道岔ID
|
||||
Id uint32 `json:"id" form:"id"`
|
||||
//道岔端口
|
||||
DevicePort string `json:"devicePort" form:"devicePort"`
|
||||
//车头所在link内的偏移量,单位为mm
|
||||
HeadOffset int64 `json:"headOffset" form:"headOffset"`
|
||||
//列车长度
|
||||
TrainLength int64 `json:"trainLength" from:"trainLength"`
|
||||
// 场景ID
|
||||
MapId int32 `json:"mapId" from:"mapId"`
|
||||
WheelDiameter int32 `json:"wheelDiameter" from:"wheelDiameter"`
|
||||
// 列车数据配置
|
||||
ConfigTrain ConfigTrainData `json:"ConfigTrain" from:"mapId"`
|
||||
}
|
||||
|
||||
// 为反正列车修改对应的测试配置
|
||||
type ConfigTrainReqDto struct {
|
||||
SimulationId string `json:"simulationId" form:"simulationId"`
|
||||
// 列车Id
|
||||
TrainId int `json:"TrainId" form:"TrainId"`
|
||||
ConfigData ConfigTrainData
|
||||
TrainId int `json:"TrainId" form:"TrainId"`
|
||||
Length int64 `json:"length"` // 列车的长度(cm)
|
||||
ConfigData ConfigTrainData
|
||||
WheelDiameter int32 `json:"wheelDiameter"` // 轮径(mm)
|
||||
}
|
||||
type ConfigTrainEnds struct {
|
||||
SpeedSensorEnable []bool `json:"speedSensorEnable"` // 2端速度传感器是否有效
|
||||
RadarEnable bool `json:"radarEnable"` // 雷达是否有效
|
||||
RadarCheckSpeed float32 `json:"radarCheckSpeed"` // 雷达测速数值
|
||||
RadarCheckTime int32 `json:"radarCheckTime"` // 雷达检测时间(秒)
|
||||
SpeedSensorEnableA bool `json:"speedSensorEnableA"` // 2端速度传感器是否有效
|
||||
SpeedSensorEnableB bool `json:"speedSensorEnableB"` // 2端速度传感器是否有效
|
||||
RadarEnable bool `json:"radarEnable"` // 雷达是否有效
|
||||
RadarCheckSpeed float32 `json:"radarCheckSpeed"` // 雷达测速数值
|
||||
RadarCheckTime int32 `json:"radarCheckTime"` // 雷达检测时间(秒)
|
||||
}
|
||||
type ConfigTrainData struct {
|
||||
//
|
||||
Mass int32 `json:"mass" form:"mass"` // 列车的质量(100=1ton)
|
||||
Length int64 `json:"length"` // 列车的长度(cm)
|
||||
//Mass int32 `json:"mass" form:"mass"` // 列车的质量(100=1ton)
|
||||
BaseResistanceParamA float32 `json:"baseResistanceParamA"` // 基本阻力参数A
|
||||
BaseResistanceParamB float32 `json:"baseResistanceParamB"` // 基本阻力参数B
|
||||
BaseResistanceParamC float32 `json:"baseResistanceParamC"` // 基本阻力参数C
|
||||
|
@ -85,7 +109,6 @@ type ConfigTrainData struct {
|
|||
Slip float32 `json:"slip"` // 打滑(%)
|
||||
Slide int32 `json:"slide"` // 前溜/后溜(mm)(正数前溜,负数后溜)
|
||||
StopSign int32 `json:"stopSign"` // 过标/欠标(mm)(正数过标,负数欠标)
|
||||
WheelDiameter int32 `json:"wheelDiameter"` // 轮径(mm)
|
||||
TrainEndsA ConfigTrainEnds `json:"TrainEndsA"` // 车辆A端
|
||||
TrainEndsB ConfigTrainEnds `json:"TrainEndsB"` // 车辆B端
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -5,9 +5,10 @@ type InitTrainInfo struct {
|
|||
LinkIndex uint16 `json:"linkIndex"`
|
||||
LinkOffset uint32 `json:"linkOffset"`
|
||||
//单位0.1km/h
|
||||
Speed uint16 `json:"speed"`
|
||||
Up bool `json:"up"`
|
||||
TrainLength uint32 `json:"trainLength"`
|
||||
Speed uint16 `json:"speed"`
|
||||
Up bool `json:"up"`
|
||||
//TrainLength uint32 `json:"trainLength"`
|
||||
TrainOperationConfig *TrainOperationConfig `json:"TrainOperationConfig"`
|
||||
}
|
||||
|
||||
// 移除列车请求参数
|
||||
|
@ -51,8 +52,8 @@ type Curve struct {
|
|||
Curvature int32 `json:"curvature"`
|
||||
}
|
||||
type TrainOperationConfig struct {
|
||||
TrainIndex int `json:"trainIndex"`
|
||||
Mass int `json:"mass" form:"mass"` //列车的质量(100=1ton)
|
||||
TrainIndex int `json:"trainIndex"`
|
||||
//Mass int `json:"mass" form:"mass"` //列车的质量(100=1ton)
|
||||
Length int `json:"列车的长度(cm)"`
|
||||
BaseResistanceParamA float32 `json:"基本阻力参数A"`
|
||||
BaseResistanceParamB float32 `json:"基本阻力参数B"`
|
||||
|
@ -66,7 +67,7 @@ type TrainOperationConfig struct {
|
|||
Slip float32 `json:"打滑(%)"`
|
||||
Slide int `json:"前溜/后溜(mm)(正数前溜,负数后溜)"`
|
||||
StopSign int `json:"过标/欠标(mm)(正数过标,负数欠标)"`
|
||||
WheelDiameter int `json:"轮径(mm)"`
|
||||
//WheelDiameter int `json:"轮径(mm)"`
|
||||
//RadarSpeed float32 `json:"雷达速度差值(m/s)"`
|
||||
//RadarDuration int `json:"雷达速度差值持续时间(ms)"`
|
||||
//RadarIsValid bool `json:"雷达是否失效"`
|
||||
|
|
|
@ -19,8 +19,105 @@ import (
|
|||
"joylink.club/bj-rtsts-server/dto/state_proto"
|
||||
)
|
||||
|
||||
func DtoTrainEndsToStateProto(ends dto.ConfigTrainEnds) *state_proto.TrainEndsState {
|
||||
return &state_proto.TrainEndsState{SpeedSensorEnableA: ends.SpeedSensorEnableA, SpeedSensorEnableB: ends.SpeedSensorEnableB,
|
||||
RadarEnable: ends.RadarEnable, RadarCheckSpeed: ends.RadarCheckSpeed, RadarCheckTime: ends.RadarCheckTime}
|
||||
}
|
||||
func CreateMsgTrainConfig(trainId int, trainLen int64, configTrainData dto.ConfigTrainData) *message.TrainOperationConfig {
|
||||
return &message.TrainOperationConfig{TrainIndex: trainId, Length: int(trainLen),
|
||||
BaseResistanceParamA: configTrainData.BaseResistanceParamA, BaseResistanceParamB: configTrainData.BaseResistanceParamB,
|
||||
BaseResistanceParamC: configTrainData.BaseResistanceParamC, CurveResistanceParamR1: configTrainData.CurveResistanceParamR1,
|
||||
CurveResistanceParamR2: configTrainData.CurveResistanceParamR2, CurveResistanceParamR3: configTrainData.CurveResistanceParamR3,
|
||||
CurveResistanceParamR4: configTrainData.CurveResistanceParamR4, RevolvingMassParam: configTrainData.RevolvingMassParam,
|
||||
Jump: configTrainData.Jump, Slip: configTrainData.Slip, Slide: int(configTrainData.Slide),
|
||||
StopSign: int(configTrainData.StopSign)}
|
||||
}
|
||||
|
||||
// 增加列车状态
|
||||
func AddTrainState(vs *VerifySimulation, status *state_proto.TrainState, mapId int32) *state_proto.TrainState {
|
||||
func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, configTrainData dto.ConfigTrainData, mapId int32) *state_proto.TrainState {
|
||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||
_, ok := allTrainMap.Load(status.Id)
|
||||
if ok {
|
||||
panic(fmt.Sprintf("列车【%s】已存在", status.Id))
|
||||
}
|
||||
// 显示状态
|
||||
status.Show = true
|
||||
//向动力学发送初始化请求
|
||||
trainIndex, _ := strconv.ParseUint(status.Id, 10, 16)
|
||||
slog.Debug("添加列车", "trainIndex", trainIndex, "HeadDeviceId", status.HeadDeviceId, "HeadOffset", status.HeadOffset)
|
||||
// 映射link、偏移量、运行方向
|
||||
var uid string
|
||||
if status.DevicePort == "" {
|
||||
uid = QueryUidByMidAndComId(mapId, status.HeadDeviceId, &data_proto.Section{})
|
||||
} else {
|
||||
uid = QueryUidByMidAndComId(mapId, status.HeadDeviceId, &data_proto.Turnout{})
|
||||
}
|
||||
// 车头所在link、link上的偏移
|
||||
linkId, loffset := QueryLinkAndOffsetByDevice(vs.Repo, uid, status.DevicePort, status.HeadOffset)
|
||||
// link上的运行方向、设备上的运行方向
|
||||
up, pointTo := QueryUpAndABByDevice(vs.Repo, uid, status.DevicePort, status.RunDirection)
|
||||
// 车头所在公里标
|
||||
kilometer := CalcTrainKilometer(vs.Repo, uid, status.DevicePort, status.RunDirection, status.HeadOffset)
|
||||
// 车尾相对车头link的偏移量
|
||||
calctailOffset := calcTrailTailOffset(loffset, status.TrainLength, up)
|
||||
// 车尾位置
|
||||
tailLink, _, _, tailLOffset, _, _, e1 := CalcInitializeLink(vs, linkId, calctailOffset, up)
|
||||
if e1 != nil {
|
||||
panic(sys_error.New("添加列车失败,列车车尾占用位置计算出错", e1))
|
||||
}
|
||||
status.Up = up
|
||||
status.PointTo = pointTo
|
||||
status.TrainKilometer = kilometer.Value
|
||||
status.DynamicState = &state_proto.TrainDynamicState{
|
||||
HeadLinkId: linkId,
|
||||
HeadLinkOffset: loffset,
|
||||
TailLinkId: tailLink,
|
||||
TailLinkOffset: tailLOffset,
|
||||
RunningUp: up,
|
||||
}
|
||||
/* status.TrainDynamicConfig = &state_proto.TrainDynamicConfig{
|
||||
BaseResistanceParamA: configTrainData.BaseResistanceParamA, BaseResistanceParamB: configTrainData.BaseResistanceParamB,
|
||||
BaseResistanceParamC: configTrainData.BaseResistanceParamC, CurveResistanceParamR1: configTrainData.CurveResistanceParamR1,
|
||||
CurveResistanceParamR2: configTrainData.CurveResistanceParamR2, CurveResistanceParamR3: configTrainData.CurveResistanceParamR3,
|
||||
CurveResistanceParamR4: configTrainData.CurveResistanceParamR4, RevolvingMassParam: configTrainData.RevolvingMassParam,
|
||||
Jump: configTrainData.Jump, Slip: configTrainData.Slip,
|
||||
Slide: configTrainData.Slide, StopSign: configTrainData.StopSign,
|
||||
TrainEndsA: DtoTrainEndsToStateProto(configTrainData.TrainEndsA),
|
||||
TrainEndsB: DtoTrainEndsToStateProto(configTrainData.TrainEndsB)}*/
|
||||
//初始化列车参数状态
|
||||
createOrUpdateStateDynamicConfig(status, configTrainData)
|
||||
status.VobcState = &state_proto.TrainVobcState{}
|
||||
slog.Debug("列车初始化", "trainIndex", trainIndex, "linkId", linkId, "loffset", loffset)
|
||||
linkIdInt, _ := strconv.Atoi(linkId)
|
||||
err := dynamics.Default().RequestAddTrain(&message.InitTrainInfo{
|
||||
TrainIndex: uint16(trainIndex),
|
||||
LinkIndex: uint16(linkIdInt),
|
||||
LinkOffset: uint32(loffset),
|
||||
Speed: uint16(math.Round(float64(status.Speed * 10))),
|
||||
Up: status.Up,
|
||||
TrainOperationConfig: CreateMsgTrainConfig(int(trainIndex), status.TrainLength, configTrainData),
|
||||
})
|
||||
if err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DynamicsError, Message: err.Error()})
|
||||
}
|
||||
// world中加车
|
||||
fi.AddTrainToWorld(vs.World, status.Id)
|
||||
fi.UpdateTrainPositionFromDynamics(vs.World, fi.TrainPositionInfo{
|
||||
TrainId: status.Id,
|
||||
Up: status.Up,
|
||||
Len: uint32(status.TrainLength),
|
||||
HeadLink: linkId,
|
||||
HeadLinkOffset: uint32(loffset),
|
||||
TailLink: tailLink,
|
||||
TailLinkOffset: uint32(tailLOffset),
|
||||
})
|
||||
// 将信息合并到当前设备状态中
|
||||
allTrainMap.Store(status.Id, status)
|
||||
return status
|
||||
}
|
||||
|
||||
// 增加列车状态
|
||||
/*func AddTrainState(vs *VerifySimulation, status *state_proto.TrainState, mapId int32) *state_proto.TrainState {
|
||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||
_, ok := allTrainMap.Load(status.Id)
|
||||
if ok {
|
||||
|
@ -89,8 +186,40 @@ func AddTrainState(vs *VerifySimulation, status *state_proto.TrainState, mapId i
|
|||
// 将信息合并到当前设备状态中
|
||||
allTrainMap.Store(status.Id, status)
|
||||
return status
|
||||
}*/
|
||||
|
||||
func createOrUpdateStateDynamicConfig(trainState *state_proto.TrainState, configTrainData dto.ConfigTrainData) {
|
||||
if trainState.TrainDynamicConfig == nil {
|
||||
trainState.TrainDynamicConfig = &state_proto.TrainDynamicConfig{}
|
||||
}
|
||||
trainState.TrainDynamicConfig.BaseResistanceParamA = configTrainData.BaseResistanceParamA
|
||||
trainState.TrainDynamicConfig.BaseResistanceParamB = configTrainData.BaseResistanceParamB
|
||||
trainState.TrainDynamicConfig.BaseResistanceParamC = configTrainData.BaseResistanceParamC
|
||||
trainState.TrainDynamicConfig.CurveResistanceParamR1 = configTrainData.CurveResistanceParamR1
|
||||
trainState.TrainDynamicConfig.CurveResistanceParamR2 = configTrainData.CurveResistanceParamR2
|
||||
trainState.TrainDynamicConfig.CurveResistanceParamR3 = configTrainData.CurveResistanceParamR3
|
||||
trainState.TrainDynamicConfig.CurveResistanceParamR4 = configTrainData.CurveResistanceParamR4
|
||||
trainState.TrainDynamicConfig.Jump = configTrainData.Jump
|
||||
trainState.TrainDynamicConfig.Slip = configTrainData.Slip
|
||||
trainState.TrainDynamicConfig.Slide = configTrainData.Slide
|
||||
trainState.TrainDynamicConfig.StopSign = configTrainData.StopSign
|
||||
copyTrainEnds(trainState.TrainDynamicConfig, "TrainEndsA", configTrainData.TrainEndsA)
|
||||
copyTrainEnds(trainState.TrainDynamicConfig, "TrainEndsB", configTrainData.TrainEndsB)
|
||||
}
|
||||
|
||||
func copyTrainEnds(trainState *state_proto.TrainDynamicConfig, fieldName string, configData dto.ConfigTrainEnds) {
|
||||
fieldVal := reflect.ValueOf(trainState).Elem().FieldByName(fieldName)
|
||||
endsVal := fieldVal.Interface().(*state_proto.TrainEndsState)
|
||||
if endsVal == nil {
|
||||
endsVal = &state_proto.TrainEndsState{}
|
||||
fieldVal.Set(reflect.ValueOf(endsVal))
|
||||
}
|
||||
endsVal.SpeedSensorEnableA = configData.SpeedSensorEnableA
|
||||
endsVal.SpeedSensorEnableA = configData.SpeedSensorEnableB
|
||||
endsVal.RadarEnable = configData.RadarEnable
|
||||
endsVal.RadarCheckSpeed = configData.RadarCheckSpeed
|
||||
endsVal.RadarCheckTime = configData.RadarCheckTime
|
||||
}
|
||||
func UpdateConfigTrain(vs *VerifySimulation, ct *dto.ConfigTrainReqDto) {
|
||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||
data, ok := allTrainMap.Load(strconv.Itoa(ct.TrainId))
|
||||
|
@ -101,52 +230,31 @@ func UpdateConfigTrain(vs *VerifySimulation, ct *dto.ConfigTrainReqDto) {
|
|||
if !ok {
|
||||
panic(sys_error.New(fmt.Sprintf("列车参数修改断言:列车【%s】不存在", ct.TrainId)))
|
||||
}
|
||||
if trainState.DynamicState.TrainDynamicConfig == nil {
|
||||
trainState.DynamicState.TrainDynamicConfig = &state_proto.TrainDynamicConfig{}
|
||||
}
|
||||
trainState.DynamicState.TrainDynamicConfig.BaseResistanceParamA = ct.ConfigData.BaseResistanceParamA
|
||||
trainState.DynamicState.TrainDynamicConfig.BaseResistanceParamB = ct.ConfigData.BaseResistanceParamB
|
||||
trainState.DynamicState.TrainDynamicConfig.BaseResistanceParamC = ct.ConfigData.BaseResistanceParamC
|
||||
trainState.DynamicState.TrainDynamicConfig.CurveResistanceParamR1 = ct.ConfigData.CurveResistanceParamR1
|
||||
trainState.DynamicState.TrainDynamicConfig.CurveResistanceParamR2 = ct.ConfigData.CurveResistanceParamR2
|
||||
trainState.DynamicState.TrainDynamicConfig.CurveResistanceParamR3 = ct.ConfigData.CurveResistanceParamR3
|
||||
trainState.DynamicState.TrainDynamicConfig.CurveResistanceParamR4 = ct.ConfigData.CurveResistanceParamR4
|
||||
trainState.TrainLength = ct.ConfigData.Length
|
||||
trainState.DynamicState.TrainDynamicConfig.Mass = ct.ConfigData.Mass
|
||||
trainState.DynamicState.TrainDynamicConfig.Jump = ct.ConfigData.Jump
|
||||
trainState.DynamicState.TrainDynamicConfig.Slip = ct.ConfigData.Slip
|
||||
trainState.DynamicState.TrainDynamicConfig.Slide = ct.ConfigData.Slide
|
||||
trainState.DynamicState.TrainDynamicConfig.StopSign = ct.ConfigData.StopSign
|
||||
createOrUpdateStateDynamicConfig(trainState, ct.ConfigData)
|
||||
/* if trainState.TrainDynamicConfig == nil {
|
||||
trainState.TrainDynamicConfig = &state_proto.TrainDynamicConfig{}
|
||||
}*/
|
||||
/*trainState.TrainDynamicConfig.BaseResistanceParamA = ct.ConfigData.BaseResistanceParamA
|
||||
trainState.TrainDynamicConfig.BaseResistanceParamB = ct.ConfigData.BaseResistanceParamB
|
||||
trainState.TrainDynamicConfig.BaseResistanceParamC = ct.ConfigData.BaseResistanceParamC
|
||||
trainState.TrainDynamicConfig.CurveResistanceParamR1 = ct.ConfigData.CurveResistanceParamR1
|
||||
trainState.TrainDynamicConfig.CurveResistanceParamR2 = ct.ConfigData.CurveResistanceParamR2
|
||||
trainState.TrainDynamicConfig.CurveResistanceParamR3 = ct.ConfigData.CurveResistanceParamR3
|
||||
trainState.TrainDynamicConfig.CurveResistanceParamR4 = ct.ConfigData.CurveResistanceParamR4
|
||||
trainState.TrainDynamicConfig.Jump = ct.ConfigData.Jump
|
||||
trainState.TrainDynamicConfig.Slip = ct.ConfigData.Slip
|
||||
trainState.TrainDynamicConfig.Slide = ct.ConfigData.Slide
|
||||
trainState.TrainDynamicConfig.StopSign = ct.ConfigData.StopSign*/
|
||||
trainState.TrainLength = ct.Length
|
||||
|
||||
trainState.WheelDiameter = ct.ConfigData.WheelDiameter
|
||||
copyTrainEnds(trainState.DynamicState.TrainDynamicConfig, "TrainEndsA", ct.ConfigData.TrainEndsA)
|
||||
copyTrainEnds(trainState.DynamicState.TrainDynamicConfig, "TrainEndsB", ct.ConfigData.TrainEndsB)
|
||||
trainState.WheelDiameter = ct.WheelDiameter
|
||||
//copyTrainEnds(trainState.TrainDynamicConfig, "TrainEndsA", ct.ConfigData.TrainEndsA)
|
||||
//copyTrainEnds(trainState.TrainDynamicConfig, "TrainEndsB", ct.ConfigData.TrainEndsB)
|
||||
//requestDynamicConfig(ct)
|
||||
}
|
||||
|
||||
func copyTrainEnds(trainState *state_proto.TrainDynamicConfig, fieldName string, configData dto.ConfigTrainEnds) {
|
||||
fieldVal := reflect.ValueOf(trainState).Elem().FieldByName(fieldName)
|
||||
endsVal := fieldVal.Interface().(*state_proto.TrainEndsState)
|
||||
if endsVal == nil {
|
||||
endsVal = &state_proto.TrainEndsState{}
|
||||
fieldVal.Set(reflect.ValueOf(endsVal))
|
||||
//endsVal := fieldVal.Interface().(*state_proto.TrainEndsState)
|
||||
}
|
||||
endsVal.SpeedSensorEnable = configData.SpeedSensorEnable
|
||||
endsVal.RadarEnable = configData.RadarEnable
|
||||
endsVal.RadarCheckSpeed = configData.RadarCheckSpeed
|
||||
endsVal.RadarCheckTime = configData.RadarCheckTime
|
||||
}
|
||||
|
||||
func requestDynamicConfig(ct *dto.ConfigTrainReqDto) {
|
||||
cd := ct.ConfigData
|
||||
msg := &message.TrainOperationConfig{TrainIndex: ct.TrainId, Mass: int(cd.Mass), Length: int(cd.Length),
|
||||
BaseResistanceParamA: cd.BaseResistanceParamA, BaseResistanceParamB: cd.BaseResistanceParamB,
|
||||
BaseResistanceParamC: cd.BaseResistanceParamC, CurveResistanceParamR1: cd.CurveResistanceParamR1,
|
||||
CurveResistanceParamR2: cd.CurveResistanceParamR2, CurveResistanceParamR3: cd.CurveResistanceParamR3,
|
||||
CurveResistanceParamR4: cd.CurveResistanceParamR4, RevolvingMassParam: cd.RevolvingMassParam,
|
||||
Jump: cd.Jump, Slip: cd.Slip, Slide: int(cd.Slide),
|
||||
StopSign: int(cd.StopSign), WheelDiameter: int(cd.WheelDiameter)}
|
||||
msg := CreateMsgTrainConfig(ct.TrainId, ct.Length, ct.ConfigData)
|
||||
err2 := dynamics.Default().TrainOperationConfig(msg)
|
||||
err := err2
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue