2024-04-09 10:40:18 +08:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2024-05-08 10:00:53 +08:00
|
|
|
const (
|
|
|
|
SKQYS1 = "SKQYS1" //驾驶端1
|
|
|
|
SKQYS2 = "SKQYS2" //驾驶端2
|
|
|
|
JJZD = "JJZD" //紧急停车
|
|
|
|
QHFXKZ = "QHFXKZ" //驾驶方向
|
|
|
|
QYSB = "QYSB" //牵引制动手柄
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 初始化列车控制数据
|
2024-05-08 10:00:53 +08:00
|
|
|
func initTrainTcc(vs *VerifySimulation, runDir bool) *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{}
|
|
|
|
if tccGI != nil {
|
|
|
|
for _, b := range tccGI.TccButtons {
|
2024-05-08 10:00:53 +08:00
|
|
|
if b.Code == JJZD {
|
2024-04-09 10:40:18 +08:00
|
|
|
tcc.Ebutton = &state_proto.TrainControlState_EmergentButton{Id: b.Common.Id, Passed: false}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, b := range tccGI.TccHandles {
|
2024-05-08 10:00:53 +08:00
|
|
|
if b.Code == QYSB {
|
2024-04-09 10:40:18 +08:00
|
|
|
tcc.PushHandler = &state_proto.TrainControlState_PushHandler{Id: b.Common.Id, Val: 0}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ds := make([]*state_proto.TrainControlState_DriverKeySwitch, 0)
|
|
|
|
for _, b := range tccGI.TccKeys {
|
|
|
|
if b.GetType() == data_proto.TccKey_driverControllerActivationClint {
|
2024-04-13 09:40:25 +08:00
|
|
|
val := false
|
2024-05-08 10:00:53 +08:00
|
|
|
if b.Code == SKQYS1 && runDir {
|
|
|
|
val = true
|
|
|
|
} else if b.Code == SKQYS2 && !runDir {
|
2024-04-13 09:40:25 +08:00
|
|
|
val = true
|
|
|
|
}
|
|
|
|
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-05-07 15:09:08 +08:00
|
|
|
tcc.DirKey = &state_proto.TrainControlState_DirectionKeySwitch{Id: b.Common.Id, Val: uint32(message.IsTrue(true))}
|
2024-04-09 10:40:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tcc.DriverKey = ds
|
|
|
|
}
|
|
|
|
return tcc
|
|
|
|
}
|