动力学列车数据配置

This commit is contained in:
tiger_zhou 2024-01-17 15:53:14 +08:00
parent 72374630de
commit 8f54503ab3
8 changed files with 786 additions and 606 deletions

View File

@ -212,12 +212,13 @@ func configTrain(c *gin.Context) {
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param Authorization header string true "JWT Token" // @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 // @Success 200 {object} dto.AddTrainRspDto
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/simulation/train/add [post] // @Router /api/v1/simulation/train/add [post]
func addTrain(c *gin.Context) { func addTrain(c *gin.Context) {
req := dto.AddTrainReqDto{} //req := dto.AddTrainReqDto{}
req := dto.AddTrainReqDtoNew{}
if err := c.ShouldBind(&req); err != nil { if err := c.ShouldBind(&req); err != nil {
panic(sys_error.New("添加列车失败,请求参数异常", err)) panic(sys_error.New("添加列车失败,请求参数异常", err))
} }
@ -234,8 +235,39 @@ func addTrain(c *gin.Context) {
RunDirection: req.RunDirection, RunDirection: req.RunDirection,
TrainLength: req.TrainLength, TrainLength: req.TrainLength,
WheelDiameter: req.WheelDiameter, 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) c.JSON(http.StatusOK, &rsp)
} }

View File

@ -4165,7 +4165,7 @@ const docTemplate = `{
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.AddTrainReqDto" "$ref": "#/definitions/dto.AddTrainReqDtoNew"
} }
} }
], ],
@ -5003,9 +5003,17 @@ const docTemplate = `{
"PictureType_TrainData" "PictureType_TrainData"
] ]
}, },
"dto.AddTrainReqDto": { "dto.AddTrainReqDtoNew": {
"type": "object", "type": "object",
"properties": { "properties": {
"ConfigTrain": {
"description": "列车数据配置",
"allOf": [
{
"$ref": "#/definitions/dto.ConfigTrainData"
}
]
},
"devicePort": { "devicePort": {
"description": "道岔端口", "description": "道岔端口",
"type": "string" "type": "string"
@ -5043,7 +5051,6 @@ const docTemplate = `{
"type": "boolean" "type": "boolean"
}, },
"wheelDiameter": { "wheelDiameter": {
"description": "列车轮径",
"type": "integer" "type": "integer"
} }
} }
@ -5232,7 +5239,7 @@ const docTemplate = `{
] ]
}, },
"baseResistanceParamA": { "baseResistanceParamA": {
"description": "基本阻力参数A", "description": "Mass int32 ` + "`" + `json:\"mass\" form:\"mass\"` + "`" + ` // 列车的质量100=1ton",
"type": "number" "type": "number"
}, },
"baseResistanceParamB": { "baseResistanceParamB": {
@ -5263,14 +5270,6 @@ const docTemplate = `{
"description": "是否跳跃", "description": "是否跳跃",
"type": "boolean" "type": "boolean"
}, },
"length": {
"description": "列车的长度cm",
"type": "integer"
},
"mass": {
"description": "列车的质量100=1ton",
"type": "integer"
},
"revolvingMassParam": { "revolvingMassParam": {
"description": "旋转质量参数", "description": "旋转质量参数",
"type": "number" "type": "number"
@ -5286,10 +5285,6 @@ const docTemplate = `{
"stopSign": { "stopSign": {
"description": "过标/欠标mm正数过标负数欠标", "description": "过标/欠标mm正数过标负数欠标",
"type": "integer" "type": "integer"
},
"wheelDiameter": {
"description": "轮径mm",
"type": "integer"
} }
} }
}, },
@ -5308,12 +5303,13 @@ const docTemplate = `{
"description": "雷达是否有效", "description": "雷达是否有效",
"type": "boolean" "type": "boolean"
}, },
"speedSensorEnable": { "speedSensorEnableA": {
"description": "2端速度传感器是否有效", "description": "2端速度传感器是否有效",
"type": "array", "type": "boolean"
"items": { },
"type": "boolean" "speedSensorEnableB": {
} "description": "2端速度传感器是否有效",
"type": "boolean"
} }
} }
}, },
@ -5327,8 +5323,16 @@ const docTemplate = `{
"configData": { "configData": {
"$ref": "#/definitions/dto.ConfigTrainData" "$ref": "#/definitions/dto.ConfigTrainData"
}, },
"length": {
"description": "列车的长度cm",
"type": "integer"
},
"simulationId": { "simulationId": {
"type": "string" "type": "string"
},
"wheelDiameter": {
"description": "轮径mm",
"type": "integer"
} }
} }
}, },

View File

@ -4159,7 +4159,7 @@
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.AddTrainReqDto" "$ref": "#/definitions/dto.AddTrainReqDtoNew"
} }
} }
], ],
@ -4997,9 +4997,17 @@
"PictureType_TrainData" "PictureType_TrainData"
] ]
}, },
"dto.AddTrainReqDto": { "dto.AddTrainReqDtoNew": {
"type": "object", "type": "object",
"properties": { "properties": {
"ConfigTrain": {
"description": "列车数据配置",
"allOf": [
{
"$ref": "#/definitions/dto.ConfigTrainData"
}
]
},
"devicePort": { "devicePort": {
"description": "道岔端口", "description": "道岔端口",
"type": "string" "type": "string"
@ -5037,7 +5045,6 @@
"type": "boolean" "type": "boolean"
}, },
"wheelDiameter": { "wheelDiameter": {
"description": "列车轮径",
"type": "integer" "type": "integer"
} }
} }
@ -5226,7 +5233,7 @@
] ]
}, },
"baseResistanceParamA": { "baseResistanceParamA": {
"description": "基本阻力参数A", "description": "Mass int32 `json:\"mass\" form:\"mass\"` // 列车的质量100=1ton",
"type": "number" "type": "number"
}, },
"baseResistanceParamB": { "baseResistanceParamB": {
@ -5257,14 +5264,6 @@
"description": "是否跳跃", "description": "是否跳跃",
"type": "boolean" "type": "boolean"
}, },
"length": {
"description": "列车的长度cm",
"type": "integer"
},
"mass": {
"description": "列车的质量100=1ton",
"type": "integer"
},
"revolvingMassParam": { "revolvingMassParam": {
"description": "旋转质量参数", "description": "旋转质量参数",
"type": "number" "type": "number"
@ -5280,10 +5279,6 @@
"stopSign": { "stopSign": {
"description": "过标/欠标mm正数过标负数欠标", "description": "过标/欠标mm正数过标负数欠标",
"type": "integer" "type": "integer"
},
"wheelDiameter": {
"description": "轮径mm",
"type": "integer"
} }
} }
}, },
@ -5302,12 +5297,13 @@
"description": "雷达是否有效", "description": "雷达是否有效",
"type": "boolean" "type": "boolean"
}, },
"speedSensorEnable": { "speedSensorEnableA": {
"description": "2端速度传感器是否有效", "description": "2端速度传感器是否有效",
"type": "array", "type": "boolean"
"items": { },
"type": "boolean" "speedSensorEnableB": {
} "description": "2端速度传感器是否有效",
"type": "boolean"
} }
} }
}, },
@ -5321,8 +5317,16 @@
"configData": { "configData": {
"$ref": "#/definitions/dto.ConfigTrainData" "$ref": "#/definitions/dto.ConfigTrainData"
}, },
"length": {
"description": "列车的长度cm",
"type": "integer"
},
"simulationId": { "simulationId": {
"type": "string" "type": "string"
},
"wheelDiameter": {
"description": "轮径mm",
"type": "integer"
} }
} }
}, },

View File

@ -35,8 +35,12 @@ definitions:
- PictureType_RelayCabinetLayout - PictureType_RelayCabinetLayout
- PictureType_IBP - PictureType_IBP
- PictureType_TrainData - PictureType_TrainData
dto.AddTrainReqDto: dto.AddTrainReqDtoNew:
properties: properties:
ConfigTrain:
allOf:
- $ref: '#/definitions/dto.ConfigTrainData'
description: 列车数据配置
devicePort: devicePort:
description: 道岔端口 description: 道岔端口
type: string type: string
@ -65,7 +69,6 @@ definitions:
description: 列车方向,true-上行false-下行 description: 列车方向,true-上行false-下行
type: boolean type: boolean
wheelDiameter: wheelDiameter:
description: 列车轮径
type: integer type: integer
type: object type: object
dto.AddTrainRspDto: dto.AddTrainRspDto:
@ -189,7 +192,8 @@ definitions:
- $ref: '#/definitions/dto.ConfigTrainEnds' - $ref: '#/definitions/dto.ConfigTrainEnds'
description: 车辆B端 description: 车辆B端
baseResistanceParamA: baseResistanceParamA:
description: 基本阻力参数A description: Mass int32 `json:"mass" form:"mass"` //
列车的质量100=1ton
type: number type: number
baseResistanceParamB: baseResistanceParamB:
description: 基本阻力参数B description: 基本阻力参数B
@ -212,12 +216,6 @@ definitions:
jump: jump:
description: 是否跳跃 description: 是否跳跃
type: boolean type: boolean
length:
description: 列车的长度cm
type: integer
mass:
description: 列车的质量100=1ton
type: integer
revolvingMassParam: revolvingMassParam:
description: 旋转质量参数 description: 旋转质量参数
type: number type: number
@ -230,9 +228,6 @@ definitions:
stopSign: stopSign:
description: 过标/欠标mm正数过标负数欠标 description: 过标/欠标mm正数过标负数欠标
type: integer type: integer
wheelDiameter:
description: 轮径mm
type: integer
type: object type: object
dto.ConfigTrainEnds: dto.ConfigTrainEnds:
properties: properties:
@ -245,11 +240,12 @@ definitions:
radarEnable: radarEnable:
description: 雷达是否有效 description: 雷达是否有效
type: boolean type: boolean
speedSensorEnable: speedSensorEnableA:
description: 2端速度传感器是否有效 description: 2端速度传感器是否有效
items: type: boolean
type: boolean speedSensorEnableB:
type: array description: 2端速度传感器是否有效
type: boolean
type: object type: object
dto.ConfigTrainReqDto: dto.ConfigTrainReqDto:
properties: properties:
@ -258,8 +254,14 @@ definitions:
type: integer type: integer
configData: configData:
$ref: '#/definitions/dto.ConfigTrainData' $ref: '#/definitions/dto.ConfigTrainData'
length:
description: 列车的长度cm
type: integer
simulationId: simulationId:
type: string type: string
wheelDiameter:
description: 轮径mm
type: integer
type: object type: object
dto.ErrorDto: dto.ErrorDto:
properties: properties:
@ -3607,7 +3609,7 @@ paths:
name: AddTrainReqDto name: AddTrainReqDto
required: true required: true
schema: schema:
$ref: '#/definitions/dto.AddTrainReqDto' $ref: '#/definitions/dto.AddTrainReqDtoNew'
produces: produces:
- application/json - application/json
responses: responses:

View File

@ -55,24 +55,48 @@ type AddTrainReqDto struct {
// 列车轮径 // 列车轮径
WheelDiameter int32 `json:"wheelDiameter" from:"wheelDiameter"` 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 { type ConfigTrainReqDto struct {
SimulationId string `json:"simulationId" form:"simulationId"` SimulationId string `json:"simulationId" form:"simulationId"`
// 列车Id // 列车Id
TrainId int `json:"TrainId" form:"TrainId"` TrainId int `json:"TrainId" form:"TrainId"`
ConfigData ConfigTrainData Length int64 `json:"length"` // 列车的长度cm
ConfigData ConfigTrainData
WheelDiameter int32 `json:"wheelDiameter"` // 轮径mm
} }
type ConfigTrainEnds struct { type ConfigTrainEnds struct {
SpeedSensorEnable []bool `json:"speedSensorEnable"` // 2端速度传感器是否有效 SpeedSensorEnableA bool `json:"speedSensorEnableA"` // 2端速度传感器是否有效
RadarEnable bool `json:"radarEnable"` // 雷达是否有效 SpeedSensorEnableB bool `json:"speedSensorEnableB"` // 2端速度传感器是否有效
RadarCheckSpeed float32 `json:"radarCheckSpeed"` // 雷达测速数值 RadarEnable bool `json:"radarEnable"` // 雷达是否有效
RadarCheckTime int32 `json:"radarCheckTime"` // 雷达检测时间(秒) RadarCheckSpeed float32 `json:"radarCheckSpeed"` // 雷达测速数值
RadarCheckTime int32 `json:"radarCheckTime"` // 雷达检测时间(秒)
} }
type ConfigTrainData struct { type ConfigTrainData struct {
// //Mass int32 `json:"mass" form:"mass"` // 列车的质量100=1ton
Mass int32 `json:"mass" form:"mass"` // 列车的质量100=1ton
Length int64 `json:"length"` // 列车的长度cm
BaseResistanceParamA float32 `json:"baseResistanceParamA"` // 基本阻力参数A BaseResistanceParamA float32 `json:"baseResistanceParamA"` // 基本阻力参数A
BaseResistanceParamB float32 `json:"baseResistanceParamB"` // 基本阻力参数B BaseResistanceParamB float32 `json:"baseResistanceParamB"` // 基本阻力参数B
BaseResistanceParamC float32 `json:"baseResistanceParamC"` // 基本阻力参数C BaseResistanceParamC float32 `json:"baseResistanceParamC"` // 基本阻力参数C
@ -85,7 +109,6 @@ type ConfigTrainData struct {
Slip float32 `json:"slip"` // 打滑(% Slip float32 `json:"slip"` // 打滑(%
Slide int32 `json:"slide"` // 前溜/后溜mm正数前溜负数后溜 Slide int32 `json:"slide"` // 前溜/后溜mm正数前溜负数后溜
StopSign int32 `json:"stopSign"` // 过标/欠标mm正数过标负数欠标 StopSign int32 `json:"stopSign"` // 过标/欠标mm正数过标负数欠标
WheelDiameter int32 `json:"wheelDiameter"` // 轮径mm
TrainEndsA ConfigTrainEnds `json:"TrainEndsA"` // 车辆A端 TrainEndsA ConfigTrainEnds `json:"TrainEndsA"` // 车辆A端
TrainEndsB ConfigTrainEnds `json:"TrainEndsB"` // 车辆B端 TrainEndsB ConfigTrainEnds `json:"TrainEndsB"` // 车辆B端
} }

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,10 @@ type InitTrainInfo struct {
LinkIndex uint16 `json:"linkIndex"` LinkIndex uint16 `json:"linkIndex"`
LinkOffset uint32 `json:"linkOffset"` LinkOffset uint32 `json:"linkOffset"`
//单位0.1km/h //单位0.1km/h
Speed uint16 `json:"speed"` Speed uint16 `json:"speed"`
Up bool `json:"up"` Up bool `json:"up"`
TrainLength uint32 `json:"trainLength"` //TrainLength uint32 `json:"trainLength"`
TrainOperationConfig *TrainOperationConfig `json:"TrainOperationConfig"`
} }
// 移除列车请求参数 // 移除列车请求参数
@ -51,8 +52,8 @@ type Curve struct {
Curvature int32 `json:"curvature"` Curvature int32 `json:"curvature"`
} }
type TrainOperationConfig struct { type TrainOperationConfig struct {
TrainIndex int `json:"trainIndex"` TrainIndex int `json:"trainIndex"`
Mass int `json:"mass" form:"mass"` //列车的质量100=1ton //Mass int `json:"mass" form:"mass"` //列车的质量100=1ton
Length int `json:"列车的长度cm"` Length int `json:"列车的长度cm"`
BaseResistanceParamA float32 `json:"基本阻力参数A"` BaseResistanceParamA float32 `json:"基本阻力参数A"`
BaseResistanceParamB float32 `json:"基本阻力参数B"` BaseResistanceParamB float32 `json:"基本阻力参数B"`
@ -66,7 +67,7 @@ type TrainOperationConfig struct {
Slip float32 `json:"打滑(%"` Slip float32 `json:"打滑(%"`
Slide int `json:"前溜/后溜mm正数前溜负数后溜"` Slide int `json:"前溜/后溜mm正数前溜负数后溜"`
StopSign int `json:"过标/欠标mm正数过标负数欠标"` StopSign int `json:"过标/欠标mm正数过标负数欠标"`
WheelDiameter int `json:"轮径mm"` //WheelDiameter int `json:"轮径mm"`
//RadarSpeed float32 `json:"雷达速度差值m/s"` //RadarSpeed float32 `json:"雷达速度差值m/s"`
//RadarDuration int `json:"雷达速度差值持续时间ms"` //RadarDuration int `json:"雷达速度差值持续时间ms"`
//RadarIsValid bool `json:"雷达是否失效"` //RadarIsValid bool `json:"雷达是否失效"`

View File

@ -19,8 +19,105 @@ import (
"joylink.club/bj-rtsts-server/dto/state_proto" "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 allTrainMap := &vs.Memory.Status.TrainStateMap
_, ok := allTrainMap.Load(status.Id) _, ok := allTrainMap.Load(status.Id)
if ok { if ok {
@ -89,8 +186,40 @@ func AddTrainState(vs *VerifySimulation, status *state_proto.TrainState, mapId i
// 将信息合并到当前设备状态中 // 将信息合并到当前设备状态中
allTrainMap.Store(status.Id, status) allTrainMap.Store(status.Id, status)
return 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) { func UpdateConfigTrain(vs *VerifySimulation, ct *dto.ConfigTrainReqDto) {
allTrainMap := &vs.Memory.Status.TrainStateMap allTrainMap := &vs.Memory.Status.TrainStateMap
data, ok := allTrainMap.Load(strconv.Itoa(ct.TrainId)) data, ok := allTrainMap.Load(strconv.Itoa(ct.TrainId))
@ -101,52 +230,31 @@ func UpdateConfigTrain(vs *VerifySimulation, ct *dto.ConfigTrainReqDto) {
if !ok { if !ok {
panic(sys_error.New(fmt.Sprintf("列车参数修改断言:列车【%s】不存在", ct.TrainId))) panic(sys_error.New(fmt.Sprintf("列车参数修改断言:列车【%s】不存在", ct.TrainId)))
} }
if trainState.DynamicState.TrainDynamicConfig == nil { createOrUpdateStateDynamicConfig(trainState, ct.ConfigData)
trainState.DynamicState.TrainDynamicConfig = &state_proto.TrainDynamicConfig{} /* if trainState.TrainDynamicConfig == nil {
} trainState.TrainDynamicConfig = &state_proto.TrainDynamicConfig{}
trainState.DynamicState.TrainDynamicConfig.BaseResistanceParamA = ct.ConfigData.BaseResistanceParamA }*/
trainState.DynamicState.TrainDynamicConfig.BaseResistanceParamB = ct.ConfigData.BaseResistanceParamB /*trainState.TrainDynamicConfig.BaseResistanceParamA = ct.ConfigData.BaseResistanceParamA
trainState.DynamicState.TrainDynamicConfig.BaseResistanceParamC = ct.ConfigData.BaseResistanceParamC trainState.TrainDynamicConfig.BaseResistanceParamB = ct.ConfigData.BaseResistanceParamB
trainState.DynamicState.TrainDynamicConfig.CurveResistanceParamR1 = ct.ConfigData.CurveResistanceParamR1 trainState.TrainDynamicConfig.BaseResistanceParamC = ct.ConfigData.BaseResistanceParamC
trainState.DynamicState.TrainDynamicConfig.CurveResistanceParamR2 = ct.ConfigData.CurveResistanceParamR2 trainState.TrainDynamicConfig.CurveResistanceParamR1 = ct.ConfigData.CurveResistanceParamR1
trainState.DynamicState.TrainDynamicConfig.CurveResistanceParamR3 = ct.ConfigData.CurveResistanceParamR3 trainState.TrainDynamicConfig.CurveResistanceParamR2 = ct.ConfigData.CurveResistanceParamR2
trainState.DynamicState.TrainDynamicConfig.CurveResistanceParamR4 = ct.ConfigData.CurveResistanceParamR4 trainState.TrainDynamicConfig.CurveResistanceParamR3 = ct.ConfigData.CurveResistanceParamR3
trainState.TrainLength = ct.ConfigData.Length trainState.TrainDynamicConfig.CurveResistanceParamR4 = ct.ConfigData.CurveResistanceParamR4
trainState.DynamicState.TrainDynamicConfig.Mass = ct.ConfigData.Mass trainState.TrainDynamicConfig.Jump = ct.ConfigData.Jump
trainState.DynamicState.TrainDynamicConfig.Jump = ct.ConfigData.Jump trainState.TrainDynamicConfig.Slip = ct.ConfigData.Slip
trainState.DynamicState.TrainDynamicConfig.Slip = ct.ConfigData.Slip trainState.TrainDynamicConfig.Slide = ct.ConfigData.Slide
trainState.DynamicState.TrainDynamicConfig.Slide = ct.ConfigData.Slide trainState.TrainDynamicConfig.StopSign = ct.ConfigData.StopSign*/
trainState.DynamicState.TrainDynamicConfig.StopSign = ct.ConfigData.StopSign trainState.TrainLength = ct.Length
trainState.WheelDiameter = ct.ConfigData.WheelDiameter trainState.WheelDiameter = ct.WheelDiameter
copyTrainEnds(trainState.DynamicState.TrainDynamicConfig, "TrainEndsA", ct.ConfigData.TrainEndsA) //copyTrainEnds(trainState.TrainDynamicConfig, "TrainEndsA", ct.ConfigData.TrainEndsA)
copyTrainEnds(trainState.DynamicState.TrainDynamicConfig, "TrainEndsB", ct.ConfigData.TrainEndsB) //copyTrainEnds(trainState.TrainDynamicConfig, "TrainEndsB", ct.ConfigData.TrainEndsB)
//requestDynamicConfig(ct) //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) { func requestDynamicConfig(ct *dto.ConfigTrainReqDto) {
cd := ct.ConfigData msg := CreateMsgTrainConfig(ct.TrainId, ct.Length, 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)}
err2 := dynamics.Default().TrainOperationConfig(msg) err2 := dynamics.Default().TrainOperationConfig(msg)
err := err2 err := err2
if err != nil { if err != nil {