rts-sim-testing-service/ts/simulation/wayside/memory/train_tcc_graphic.go
2024-07-11 14:58:34 +08:00

146 lines
4.7 KiB
Go

package memory
import (
"joylink.club/bj-rtsts-server/dto/data_proto"
"joylink.club/bj-rtsts-server/dto/state_proto"
"joylink.club/bj-rtsts-server/third_party/message"
)
const (
SKQYS1 = "SKQYS1" //驾驶端1
SKQYS2 = "SKQYS2" //驾驶端2
JJZD = "JJZD" //紧急停车
QHFXKZ = "QHFXKZ" //驾驶方向
QYSB = "QYSB" //牵引制动手柄
ATPQCKG = "ATPQCKG" //ATP切除开关
KZM = "KZM" //开左门按钮
GZM = "GZM" //关左门按钮
GYM = "GYM" //关右门按钮
ZAWTGJC = "ZAWTGJC" //障碍物/脱轨检测
ZDZGZ = "ZDZGZ" //制动重故障
ATPSD = "ATPSD" //ATP上电按钮
MSQR = "MSQR" //模式确认
)
// 获取列车控制图形数据
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
}
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
}
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) (*state_proto.TrainVobcState, uint32) {
vobc := &state_proto.TrainVobcState{TrainLoad: int64(trainLoad), BrakingStatus: true, BrakeForce: 100, DirectionForward: true,
AllDoorClose: true, ObstacleCheckBtn: true, RightDoorCloseCommand: true, LeftDoorCloseCommand: true, BrakeHeavyFault: true, AtpCutSwitch: true,
ConfirmBtn: true, AtpPowerOnBtn: true,
}
var trainActDir uint32 = 0
if trainIsUp {
//vobc.Tc1Active = true
trainActDir = 1
} else {
//vobc.Tc2Active = true
trainActDir = 2
}
return vobc, trainActDir
}
// 初始化列车控制数据
func initTrainTcc(vs *VerifySimulation, runDir bool, breaking int32) *state_proto.TrainControlState {
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{}
if tccGI != nil {
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([]*state_proto.TrainControlState_ControlButton, 0)
for _, b := range tccGI.TccButtons {
btn := &state_proto.TrainControlState_ControlButton{Id: b.Common.Id, Passed: false}
switch b.Code {
case ATPQCKG, GZM, GYM, ZAWTGJC, ZDZGZ, ATPSD, MSQR:
btn.Passed = true
}
btns = append(btns, btn)
}
tcc.Buttons = btns
for _, b := range tccGI.TccHandles {
if b.Code == QYSB {
tcc.PushHandler = &state_proto.TrainControlState_PushHandler{Id: b.Common.Id, Val: -100}
}
}
ds := make([]*state_proto.TrainControlState_DriverKeySwitch, 0)
for _, b := range tccGI.TccKeys {
if b.GetType() == data_proto.TccKey_driverControllerActivationClint {
val := false
/* if b.Code == SKQYS1 && runDir {
val = true
} else if b.Code == SKQYS2 && !runDir {
val = true
}*/
ds = append(ds, &state_proto.TrainControlState_DriverKeySwitch{Id: b.Common.Id, Val: val})
} else if b.GetType() == data_proto.TccKey_frontAndRearDirectionalControl {
tcc.DirKey = &state_proto.TrainControlState_DirectionKeySwitch{Id: b.Common.Id, Val: uint32(message.IsTrue(true))}
}
}
tcc.DriverKey = ds
}
return tcc
}