rts-sim-testing-service/ts/simulation/wayside/memory/train_tcc_graphic.go

178 lines
6.4 KiB
Go
Raw Normal View History

2024-04-09 10:40:18 +08:00
package memory
import (
"joylink.club/bj-rtsts-server/dto/data_proto"
2024-08-22 13:12:03 +08:00
"joylink.club/bj-rtsts-server/dto/request_proto"
2024-04-09 10:40:18 +08:00
"joylink.club/bj-rtsts-server/dto/state_proto"
"joylink.club/bj-rtsts-server/third_party/message"
)
2024-05-08 10:00:53 +08:00
const (
SKQYS1 = "SKQYS1" //驾驶端1
SKQYS2 = "SKQYS2" //驾驶端2
JJZD = "JJZD" //紧急停车
QHFXKZ = "QHFXKZ" //驾驶方向
QYSB = "QYSB" //牵引制动手柄
2024-08-29 16:09:07 +08:00
ATOQD = "ATOQD" //ato 启动
2024-07-11 14:58:34 +08:00
2024-08-29 16:09:07 +08:00
ATPQCKG = "ATPQCKG" //ATP切除开关
KZM = "KZM" //开左门按钮
GZM = "GZM" //关左门按钮
GYM = "GYM" //关右门按钮
KYM = "KYM" //开右门
ZAWTGJC = "ZAWTGJC" //障碍物/脱轨检测
ZDZGZ = "ZDZGZ" //制动重故障
ATPSD = "ATPSD" //ATP上电按钮
MSQR = "MSQR" //模式确认
ZF = "ZF"
QZMYX = "QZMYX" //强制门允许
MSJJ = "MSJJ" //模式降级
MSSJ = "MSSJ" // 模式升级
HX = "HX" //唤醒按钮
JX = "JX" //检修按钮
XM = "XM" //休眠按钮
LIGHT_JJZD = JJZD
LIGHT_QQY = "QQY" //切牵引指示灯
LIGHT_JSSJH = "JSSJH" // 驾驶室激活
LIGHT_TFZDHJ = "TFZDHJ" //停放制动缓解
LIGHT_QYYX = "QYYX" // 牵引有效
LIGHT_ZDYX = "ZDYX" //制动有效
LIGHT_TFZDSJ = "TFZDSJ" //停放制动施加
LIGHT_CYZD = "CYZD" //常用制动
LIGHT_ZDGL = "ZDGL" //制动隔离
LIGHT_LSXH = "LSXH" //零速信号
LIGHT_ZMYX = "ZMYX" //左门允许
LIGHT_YMYX = "YMYX" //右门允许
LIGHT_ZFZSD = "ZFZSD" //折返指示灯
LIGHT_BDATPKC = "BDATPKC" //本段atp控车
LIGHT_ATOFCZSD = "ATOFCZSD" //ato发车指示灯
LIGHT_ATO_OPEN_LEFT_DOOR = "ATOKZM" //ato 开左门
LIGHT_ATO_OPEN_RIGHT_DOOR = "ATOKYM" //ato 开右门
LIGHT_ATO_CLOSE_LEFT_DOOR = "ATOGZM" //ato 关左门
LIGHT_ATO_CLOSE_RIGHT_DOOR = "ATOGYM" //ato 关右门
2024-05-08 10:00:53 +08:00
)
2024-04-09 10:40:18 +08:00
// 获取列车控制图形数据
func findTrainTccGraphicData(vs *VerifySimulation) *data_proto.TccGraphicStorage {
var tccGI *data_proto.TccGraphicStorage
for _, id := range vs.MapIds {
if QueryGiType(id) == data_proto.PictureType_TrainControlCab {
tccGI = QueryGiData[*data_proto.TccGraphicStorage](id)
break
}
}
return tccGI
}
func findTrainTccGraphicDataButtons(tccG *data_proto.TccGraphicStorage) []*data_proto.TccButton {
return tccG.TccButtons
}
func findTrainTccGraphicDataKeys(tccG *data_proto.TccGraphicStorage) []*data_proto.TccKey {
return tccG.TccKeys
}
func findTrainTccGraphicDataHandlers(tccG *data_proto.TccGraphicStorage) []*data_proto.TccHandle {
return tccG.TccHandles
}
2024-07-04 14:47:24 +08:00
func findTrainTccGraphicDataButtonByCode(tccG *data_proto.TccGraphicStorage, deviceCode string) (*data_proto.TccButton, bool) {
for _, d := range findTrainTccGraphicDataButtons(tccG) {
if d.Code == deviceCode {
return d, true
}
}
return nil, false
}
2024-04-09 10:40:18 +08:00
func findTrainTccGraphicDataButton(tccG *data_proto.TccGraphicStorage, id uint32) (*data_proto.TccButton, bool) {
for _, d := range findTrainTccGraphicDataButtons(tccG) {
if d.Common.Id == id {
return d, true
}
}
return nil, false
}
func findTrainTccGraphicDataKey(tccG *data_proto.TccGraphicStorage, id uint32) (*data_proto.TccKey, bool) {
for _, d := range findTrainTccGraphicDataKeys(tccG) {
if d.Common.Id == id {
return d, true
}
}
return nil, false
}
func findTrainTccGraphicDataHandler(tccG *data_proto.TccGraphicStorage, id uint32) (*data_proto.TccHandle, bool) {
for _, d := range findTrainTccGraphicDataHandlers(tccG) {
if d.Common.Id == id {
return d, true
}
}
return nil, false
}
func initTrainVobc(trainLoad int64, trainIsUp bool, maxBrake float32) (*state_proto.TrainVobcState, uint32) {
brake := trainBraking(int32(trainLoad), 100, maxBrake) / 1000 * 10
vobc := &state_proto.TrainVobcState{TrainLoad: trainLoad, BrakingStatus: true, BrakeForce: brake, DirectionForward: true,
2024-08-27 11:58:08 +08:00
AllDoorClose: true, ObstacleCheckBtn: true, RightDoorCloseCommand: true, LeftDoorCloseCommand: true, BrakeHeavyFault: true, AtpCutSwitch: true,
2024-08-22 13:12:03 +08:00
ConfirmBtn: true, AtpPowerOnBtn: true, DoorModeMM: true,
2024-07-11 14:58:34 +08:00
}
2024-05-20 15:21:22 +08:00
var trainActDir uint32 = 0
if trainIsUp {
trainActDir = 1
} else {
trainActDir = 2
}
return vobc, trainActDir
}
2024-04-09 10:40:18 +08:00
// 初始化列车控制数据
func initTrainTcc(vs *VerifySimulation) *state_proto.TrainControlState {
2024-04-09 10:40:18 +08:00
var tccGI *data_proto.TccGraphicStorage
for _, id := range vs.MapIds {
if QueryGiType(id) == data_proto.PictureType_TrainControlCab {
tccGI = QueryGiData[*data_proto.TccGraphicStorage](id)
break
}
}
tcc := &state_proto.TrainControlState{}
2024-04-09 10:40:18 +08:00
if tccGI != nil {
2024-07-04 17:39:56 +08:00
tcc.LightMaps = make(map[string]*state_proto.TrainControlState_ControlLight)
for _, light := range tccGI.TccLights {
tcc.LightMaps[light.Code] = &state_proto.TrainControlState_ControlLight{Id: light.Common.Id, Val: light.InitialState}
}
btns := make(map[string]*state_proto.TrainControlState_ControlButton, 0)
2024-04-09 10:40:18 +08:00
for _, b := range tccGI.TccButtons {
2024-07-04 14:47:24 +08:00
btn := &state_proto.TrainControlState_ControlButton{Id: b.Common.Id, Passed: false}
2024-07-11 14:58:34 +08:00
switch b.Code {
2024-08-27 11:58:08 +08:00
case ATPQCKG, ZAWTGJC, ZDZGZ, ATPSD, MSQR:
2024-07-11 14:58:34 +08:00
btn.Passed = true
2024-04-09 10:40:18 +08:00
}
btns[b.Code] = btn
2024-04-09 10:40:18 +08:00
}
2024-07-04 14:47:24 +08:00
tcc.Buttons = btns
2024-04-09 10:40:18 +08:00
for _, b := range tccGI.TccHandles {
2024-05-08 10:00:53 +08:00
if b.Code == QYSB {
tcc.PushHandler = &state_proto.TrainControlState_PushHandler{Id: b.Common.Id, Val: -100}
2024-04-09 10:40:18 +08:00
}
}
ds := make([]*state_proto.TrainControlState_DriverKeySwitch, 0)
2024-08-22 13:12:03 +08:00
tcc.SwitchKeyMap = make(map[string]*state_proto.TrainControlState_SwitchKeyChange, 0)
2024-04-09 10:40:18 +08:00
for _, b := range tccGI.TccKeys {
if b.GetType() == data_proto.TccKey_driverControllerActivationClint {
2024-04-13 09:40:25 +08:00
val := false
2024-07-11 14:58:34 +08:00
/* if b.Code == SKQYS1 && runDir {
val = true
} else if b.Code == SKQYS2 && !runDir {
val = true
}*/
2024-04-13 09:40:25 +08:00
ds = append(ds, &state_proto.TrainControlState_DriverKeySwitch{Id: b.Common.Id, Val: val})
2024-04-09 10:40:18 +08:00
} else if b.GetType() == data_proto.TccKey_frontAndRearDirectionalControl {
2024-08-22 13:12:03 +08:00
tcc.SwitchKeyMap[b.Code] = &state_proto.TrainControlState_SwitchKeyChange{Id: b.Common.Id, Val: uint32(message.IsTrue(true))}
} else if b.GetType() == data_proto.TccKey_trainDoorMode {
tcc.SwitchKeyMap[b.Code] = &state_proto.TrainControlState_SwitchKeyChange{Id: b.Common.Id, Val: uint32(request_proto.TrainControl_KL_END.Number())}
2024-04-09 10:40:18 +08:00
}
}
tcc.DriverKey = ds
}
return tcc
}