Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
thesai 2024-07-24 18:27:51 +08:00
commit 72ca826be2
19 changed files with 1452 additions and 1188 deletions

View File

@ -406,7 +406,6 @@ func controlTrain(c *gin.Context) {
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/simulation/train/remove/all [post] // @Router /api/v1/simulation/train/remove/all [post]
func removeAllTrain(c *gin.Context) { func removeAllTrain(c *gin.Context) {
rt := &dto.RemoveAllTrainRspDto{} rt := &dto.RemoveAllTrainRspDto{}
if err := c.ShouldBind(&rt); err != nil { if err := c.ShouldBind(&rt); err != nil {
panic(sys_error.New("移除所有列车失败,请求参数异常", err)) panic(sys_error.New("移除所有列车失败,请求参数异常", err))

View File

@ -160,10 +160,11 @@ type VehiclePCSimConfig2 struct {
} }
type VehiclePCSimConfig struct { type VehiclePCSimConfig struct {
TrainEnds bool `json:"trainEnds" description:"列车端点A?"` //TrainEnds bool `json:"trainEnds" description:"列车端点A?"`
Open bool `json:"open" description:"是否开启"` ConfigName string `json:"configName" description:"连接名称"`
PcSimIp string `json:"pcSimIp" description:"pc仿真平台通信ip"` Open bool `json:"open" description:"是否开启"`
PcSimPort uint32 `json:"pcSimPort" description:"pc仿真平台通信端口"` PcSimIp string `json:"pcSimIp" description:"pc仿真平台通信ip"`
PcSimPort uint32 `json:"pcSimPort" description:"pc仿真平台通信端口"`
//LocalTestingPort uint32 `json:"localTestingPort" description:"本地测试端口"` //LocalTestingPort uint32 `json:"localTestingPort" description:"本地测试端口"`
} }

View File

@ -40,6 +40,7 @@ type RunConfigSelectOption struct {
} }
type TrainConnTypeConfigDto struct { type TrainConnTypeConfigDto struct {
TypeName string `json:"typeName" form:"typeName"` // 连接名称; //连接名称
ConnType state_proto.TrainConnState_TrainConnType `json:"connType" form:"connType"` // NONE = 0 未知连接 ;VOBC = 1; //半实物PC_SIM = 2; //PC仿真 ConnType state_proto.TrainConnState_TrainConnType `json:"connType" form:"connType"` // NONE = 0 未知连接 ;VOBC = 1; //半实物PC_SIM = 2; //PC仿真
} }

View File

@ -152,6 +152,7 @@ type TrainConnThirdDto struct {
SimulationId string `json:"simulationId" form:"simulationId"` SimulationId string `json:"simulationId" form:"simulationId"`
Id string `json:"id" form:"id"` // 列车Id Id string `json:"id" form:"id"` // 列车Id
ConnType state_proto.TrainConnState_TrainConnType `json:"connType" form:"connType"` //连接类型 0=未连接;1=半实物;2= 车载仿真 ConnType state_proto.TrainConnState_TrainConnType `json:"connType" form:"connType"` //连接类型 0=未连接;1=半实物;2= 车载仿真
TypeName string `json:"typeName" form:"typeName"` //连接名称
} }
// 为仿真添加测试车请求 // 为仿真添加测试车请求

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,14 @@ import (
"time" "time"
) )
func lowPower(power bool) bool {
if power {
return false
} else {
return true
}
}
// 综合后备盘IBP消息服务 // 综合后备盘IBP消息服务
func NewTrainControlMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask { func NewTrainControlMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask {
return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]列车控制", mapId), func() error { return ms_api.NewScheduleTask(fmt.Sprintf("地图[%d]列车控制", mapId), func() error {
@ -18,12 +26,51 @@ func NewTrainControlMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask
trainId := fmt.Sprintf("%v", key) trainId := fmt.Sprintf("%v", key)
ts := value.(*state_proto.TrainState) ts := value.(*state_proto.TrainState)
ttcc := ts.Tcc ttcc := ts.Tcc
vobc := ts.VobcState
lights := make([]*state_proto.TrainControlState_ControlLight, 0) lights := make([]*state_proto.TrainControlState_ControlLight, 0)
for _, light := range ttcc.LightMaps { for lightKey, light := range ttcc.LightMaps {
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: light.Val}) switch lightKey {
} case memory.LIGHT_JJZD:
tcc := &state_proto.TrainControlStateMsg{Buttons: ttcc.Buttons, DriverKey: ttcc.DriverKey, DirKey: ttcc.DirKey, PushHandler: ttcc.PushHandler, Lights: lights} state := lowPower(vobc.LightEmergencyBrakingStatus)
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: state})
case memory.LIGHT_QQY:
state := lowPower(vobc.LightTractionSafetyCircuit)
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: state})
case memory.LIGHT_JSSJH:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.LightDriverActive})
case memory.LIGHT_TFZDHJ:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.StopNotAllBrake})
case memory.LIGHT_QYYX:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.TractionEffective})
case memory.LIGHT_ZDYX:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.BrakeEffective})
case memory.LIGHT_TFZDSJ:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.ParkingBrakeStatus})
case memory.LIGHT_CYZD:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.MostUseBrake})
case memory.LIGHT_ZDGL:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.BrakeQuarantine})
case memory.LIGHT_LSXH:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.NoSpeedSigle})
case memory.LIGHT_ZMYX:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.LeftDoorState})
case memory.LIGHT_YMYX:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.RightDoorState})
case memory.LIGHT_ZFZSD:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.TurnbackStatus})
case memory.LIGHT_BDATPKC:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: vobc.LocalAtpControl})
default:
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: light.Val})
}
}
buttons := make([]*state_proto.TrainControlState_ControlButton, 0)
for _, button := range ttcc.Buttons {
buttons = append(buttons, button)
}
tcc := &state_proto.TrainControlStateMsg{Buttons: buttons, DriverKey: ttcc.DriverKey, DirKey: ttcc.DirKey, PushHandler: ttcc.PushHandler, Lights: lights}
err := mqtt.GetMsgClient().PubTrainControlState(vs.SimulationId, trainId, tcc) err := mqtt.GetMsgClient().PubTrainControlState(vs.SimulationId, trainId, tcc)
if err != nil { if err != nil {
slog.Error("发送列车控制mqtt失败", err) slog.Error("发送列车控制mqtt失败", err)

@ -1 +1 @@
Subproject commit 4437185ee9fb654dc87cfa6d481e9744b1c43155 Subproject commit 2f5d8c3cfdf06ced1a0b0a50f47f9353c441e196

View File

@ -1,7 +1,10 @@
package service package service
import ( import (
"encoding/json"
"fmt" "fmt"
"joylink.club/bj-rtsts-server/config"
"strings"
"time" "time"
"joylink.club/bj-rtsts-server/db/dbquery" "joylink.club/bj-rtsts-server/db/dbquery"
@ -33,8 +36,31 @@ func ListProjectRunConfigQuery() []*dto.ProjectRunConfigDto {
return dto.ConvertToRunConfigFromSlice(records) return dto.ConvertToRunConfigFromSlice(records)
} }
func checkRunConfig(jsonConfigStr string) *sys_error.BusinessError {
var configMap config.ThirdPartyConfig
err := json.Unmarshal([]byte(jsonConfigStr), &configMap)
if err != nil {
return sys_error.New("运行环境序列化错误", err)
}
checkSameMap := make(map[string]bool)
for _, simConfig := range configMap.PcSimConfigs {
if simConfig.ConfigName == "" || len(strings.TrimSpace(simConfig.ConfigName)) == 0 {
return sys_error.New(fmt.Sprintf("车载运行配置名称不能为空 配置ip:%v,端口%v", simConfig.PcSimIp, simConfig.PcSimPort), err)
}
if checkSameMap[simConfig.ConfigName] {
return sys_error.New(fmt.Sprintf("车载运行配置重复的名称:%v", simConfig.ConfigName), err)
}
checkSameMap[simConfig.ConfigName] = true
}
return nil
}
// 创建项目运行环境 // 创建项目运行环境
func CreateProjectRunConfig(dd *dto.ProjectRunConfigReqDto) bool { func CreateProjectRunConfig(dd *dto.ProjectRunConfigReqDto) bool {
if checkErr := checkRunConfig(dd.ConfigContent); checkErr != nil {
panic(checkErr)
}
d := model.ProjectRunConfig{ d := model.ProjectRunConfig{
Name: dd.Name, Name: dd.Name,
Description: dd.Description, Description: dd.Description,
@ -42,6 +68,7 @@ func CreateProjectRunConfig(dd *dto.ProjectRunConfigReqDto) bool {
CreateTime: time.Now(), CreateTime: time.Now(),
UpdateTime: time.Now(), UpdateTime: time.Now(),
} }
err := dbquery.ProjectRunConfig.Save(&d) err := dbquery.ProjectRunConfig.Save(&d)
if err != nil { if err != nil {
panic(sys_error.New("保存失败,数据库错误请联系运维人员", err)) panic(sys_error.New("保存失败,数据库错误请联系运维人员", err))
@ -75,6 +102,9 @@ func QueryRunConfig(id int32) *dto.ProjectRunConfigDto {
// 更新项目运行环境 // 更新项目运行环境
func UpdateProjectRunConfig(id int32, dd *dto.ProjectRunConfigReqDto) bool { func UpdateProjectRunConfig(id int32, dd *dto.ProjectRunConfigReqDto) bool {
if checkErr := checkRunConfig(dd.ConfigContent); checkErr != nil {
panic(checkErr)
}
findOldQuery := dbquery.ProjectRunConfig findOldQuery := dbquery.ProjectRunConfig
oldD, err := findOldQuery.Where(findOldQuery.ID.Eq(id)).Debug().First() oldD, err := findOldQuery.Where(findOldQuery.ID.Eq(id)).Debug().First()
if oldD == nil || err != nil { if oldD == nil || err != nil {

View File

@ -93,10 +93,18 @@ func (d *dynamics) updateState(state tpapi.ThirdPartyApiServiceState) {
func (d *dynamics) State() tpapi.ThirdPartyApiServiceState { func (d *dynamics) State() tpapi.ThirdPartyApiServiceState {
return d.state return d.state
} }
func (d *dynamics) FindAppendApiService() []tpapi.ThirdPartyApiService {
return nil
}
func (d *dynamics) Name() string { func (d *dynamics) Name() string {
return Name return Name
} }
func (d *dynamics) TrueService() bool {
return true
}
func (d *dynamics) ServiceDesc() string {
return Name
}
// 解码列车信息并处理 // 解码列车信息并处理
func (d *dynamics) handleDynamicsTrainInfo(b []byte) { func (d *dynamics) handleDynamicsTrainInfo(b []byte) {

View File

@ -121,8 +121,6 @@ func AtpLowPowerByte(d byte) bool {
// 列车速度位置报告 // 列车速度位置报告
type TrainSpeedPlaceReportMsg struct { type TrainSpeedPlaceReportMsg struct {
//列车id
TrainId string
PulseCount1 uint32 PulseCount1 uint32
PulseCount2 uint32 PulseCount2 uint32
} }

View File

@ -51,7 +51,15 @@ func (s *semiPhysicalTrainImpl) State() tpapi.ThirdPartyApiServiceState {
func (s *semiPhysicalTrainImpl) Name() string { func (s *semiPhysicalTrainImpl) Name() string {
return Name return Name
} }
func (d *semiPhysicalTrainImpl) FindAppendApiService() []tpapi.ThirdPartyApiService {
return nil
}
func (d *semiPhysicalTrainImpl) TrueService() bool {
return true
}
func (d *semiPhysicalTrainImpl) ServiceDesc() string {
return Name
}
func (s *semiPhysicalTrainImpl) handleTrainControlMsg(b []byte) { func (s *semiPhysicalTrainImpl) handleTrainControlMsg(b []byte) {
s.udpDelayRecorder.RecordInterval() s.udpDelayRecorder.RecordInterval()
// slog.Debug(fmt.Sprintf("半实物列车控制消息近期消息间隔: %v", s.udpDelayRecorder.GetIntervals())) // slog.Debug(fmt.Sprintf("半实物列车控制消息近期消息间隔: %v", s.udpDelayRecorder.GetIntervals()))

View File

@ -40,24 +40,39 @@ func convertServiceName(name string) state_proto.SimulationThirdPartyApiService_
func GetRunningServiceStates() *state_proto.SimulationThirdPartyApiService { func GetRunningServiceStates() *state_proto.SimulationThirdPartyApiService {
ss := &state_proto.SimulationThirdPartyApiService{} ss := &state_proto.SimulationThirdPartyApiService{}
for _, tpas := range tpapiService { for _, tpas := range tpapiService {
t := convertServiceName(tpas.Name()) if tpas.TrueService() {
if t == state_proto.SimulationThirdPartyApiService_Undefined { collectServiceState(ss, tpas)
slog.Error("未知的第三方接口服务类型", "name", tpas.Name()) } else {
continue trueServices := tpas.FindAppendApiService()
} if trueServices != nil && len(trueServices) > 0 {
switch tpas.State() { for _, trueService := range trueServices {
case tpapi.ThirdPartyState_Normal: collectServiceState(ss, trueService)
ss.States = append(ss.States, &state_proto.SimulationThirdPartyApiServiceState{ }
Type: t, }
State: state_proto.SimulationThirdPartyApiService_Normal,
})
case tpapi.ThirdPartyState_Broken:
ss.States = append(ss.States, &state_proto.SimulationThirdPartyApiServiceState{
Type: t,
State: state_proto.SimulationThirdPartyApiService_Error,
})
} }
} }
return ss return ss
} }
func collectServiceState(ss *state_proto.SimulationThirdPartyApiService, service tpapi.ThirdPartyApiService) {
t := convertServiceName(service.Name())
if t == state_proto.SimulationThirdPartyApiService_Undefined {
slog.Error("未知的第三方接口服务类型", "name", service.Name())
return
}
switch service.State() {
case tpapi.ThirdPartyState_Normal:
ss.States = append(ss.States, &state_proto.SimulationThirdPartyApiServiceState{
Type: t,
ServiceName: service.ServiceDesc(),
State: state_proto.SimulationThirdPartyApiService_Normal,
})
case tpapi.ThirdPartyState_Broken:
ss.States = append(ss.States, &state_proto.SimulationThirdPartyApiServiceState{
Type: t,
ServiceName: service.ServiceDesc(),
State: state_proto.SimulationThirdPartyApiService_Error,
})
}
}

View File

@ -23,6 +23,11 @@ type ThirdPartyApiService interface {
Name() string Name() string
// 服务状态 // 服务状态
State() ThirdPartyApiServiceState State() ThirdPartyApiServiceState
FindAppendApiService() []ThirdPartyApiService
//是否真实服务如果为假就会调用FindAppendApiService方法
TrueService() bool
//服务描述
ServiceDesc() string
} }
// func NewThirdPartyApiService() ThirdPartyApiService { // func NewThirdPartyApiService() ThirdPartyApiService {

View File

@ -1,49 +1,75 @@
package train_pc_sim package train_pc_sim
import ( import (
"encoding/hex"
"fmt"
"joylink.club/bj-rtsts-server/dto/state_proto" "joylink.club/bj-rtsts-server/dto/state_proto"
"joylink.club/bj-rtsts-server/third_party/message" "joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/tcp" "joylink.club/bj-rtsts-server/third_party/tcp"
"joylink.club/bj-rtsts-server/third_party/tpapi"
"log/slog" "log/slog"
) )
type trainPcReciverData struct { type TrainPcReciverData struct {
clientKey string tpapi.ThirdPartyApiService
tcpClient *tcp.TcpClient clientKey string
pcSimManage TrainPcSimManage tcpClient *tcp.TcpClient
isSleep bool pcSimManage TrainPcSimManage
ebCheckIndex uint8 trainInit bool
ebCheckTime int64 state tpapi.ThirdPartyApiServiceState
speedPlace *message.TrainSpeedPlaceReportMsg
train *state_proto.TrainState
} }
func (rd *trainPcReciverData) receiverDataHandle(n int, data []byte) { func (rd *TrainPcReciverData) Name() string {
/*if !rd.isSleep { return Name
time.Sleep(time.Second * 5) }
rd.isSleep = true
}*/ // 服务状态
func (rd *TrainPcReciverData) State() tpapi.ThirdPartyApiServiceState {
return rd.state
}
func (d *TrainPcReciverData) updateState(state tpapi.ThirdPartyApiServiceState) {
d.state = state
}
func (d *TrainPcReciverData) readError(err error) {
slog.Error("连接车载pc仿真tcp服务断开", err)
d.updateState(tpapi.ThirdPartyState_Broken)
d.tcpClient = nil
}
func (d *TrainPcReciverData) ServiceDesc() string {
return d.clientKey
}
func (rd *TrainPcReciverData) receiverDataHandle(n int, data []byte) {
receiveData := data[:n] receiveData := data[:n]
hexSourceData := hex.EncodeToString(receiveData)
slog.Info(fmt.Sprintf("接受列车激活端:%v pc仿真接收数据%v", rd.clientKey, hexSourceData))
trainPcMsgs := message.TrainPcSimDecode(receiveData) trainPcMsgs := message.TrainPcSimDecode(receiveData)
connType := state_proto.TrainConnState_PC_SIM_A train := rd.train
if rd.clientKey == "B" { if train == nil {
connType = state_proto.TrainConnState_PC_SIM_B slog.Error("车载输出数字量未找到连接车载pc仿真的列车")
return
} }
if !train.ConnState.Conn {
slog.Error("车载输出数字量,,列车未连接车载pc仿真")
return
}
//hexSourceData := hex.EncodeToString(receiveData)
//slog.Info(fmt.Sprintf("接受列车激活端:%v pc仿真接收数据%v", rd.clientKey, hexSourceData))
for _, baseMsg := range trainPcMsgs { for _, baseMsg := range trainPcMsgs {
//slog.Info(fmt.Sprintf("pc仿真接收数据%v,类型:%X", hexSourceData, baseMsg.Type)) //slog.Info(fmt.Sprintf("pc仿真接收数据%v,类型:%X", hexSourceData, baseMsg.Type))
switch baseMsg.Type { switch baseMsg.Type {
//case RECIVE_TRAIN_CREATE_REMOVE: //case RECIVE_TRAIN_CREATE_REMOVE:
// pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0]) // pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0])
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR: case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR:
rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(connType, baseMsg.Data) initResult := rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(train, rd.trainInit, baseMsg.Data)
rd.trainInit = initResult
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK: case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK:
rd.pcSimManage.TrainPcSimDigitalReportHandle(connType, baseMsg.Data) rd.pcSimManage.TrainPcSimDigitalReportHandle(train, baseMsg.Data)
case message.RECIVE_TRAIN_QUERY_STATUS: case message.RECIVE_TRAIN_QUERY_STATUS:
rd.pcSimManage.TrainBtmQuery(connType, baseMsg.Data) rd.pcSimManage.TrainBtmQuery(train, baseMsg.Data)
case message.RECIVE_TRAIN_MOCK_DATA: case message.RECIVE_TRAIN_MOCK_DATA:
rd.pcSimManage.TrainPcSimMockInfo(connType, baseMsg.Data) rd.pcSimManage.TrainPcSimMockInfo(train, baseMsg.Data)
//case RECIVE_TRAIN_DOOR_MODE: //case RECIVE_TRAIN_DOOR_MODE:
// pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0]) // pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0])

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"joylink.club/bj-rtsts-server/config" "joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/dto/state_proto" "joylink.club/bj-rtsts-server/dto/state_proto"
"joylink.club/bj-rtsts-server/sys_error"
"joylink.club/bj-rtsts-server/third_party/message" "joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/tcp" "joylink.club/bj-rtsts-server/third_party/tcp"
"joylink.club/bj-rtsts-server/third_party/tpapi" "joylink.club/bj-rtsts-server/third_party/tpapi"
@ -38,15 +39,17 @@ type TrainPcSim interface {
SendBaliseData(train *state_proto.TrainState, msgType byte, data []byte) SendBaliseData(train *state_proto.TrainState, msgType byte, data []byte)
SendBaliseData2(train *state_proto.TrainState, msgType byte, data []string) SendBaliseData2(train *state_proto.TrainState, msgType byte, data []string)
//发布列车控制的相关事件 //发布列车控制的相关事件
PublishTrainControlEvent(train *state_proto.TrainState, events []TrainControlEvent) //PublishTrainControlEvent(train *state_proto.TrainState, events []TrainControlEvent)
SendTrainControlMsg(train *state_proto.TrainState, baseMessage []message.TrainPcSimBaseMessage) SendTrainControlMsg(train *state_proto.TrainState, baseMessage []message.TrainPcSimBaseMessage)
// CreateOrRemoveSpeedPLace 创建或删除速度位置信息 // CreateOrRemoveSpeedPLace 创建或删除速度位置信息
CreateOrRemoveSpeedPLace(train *state_proto.TrainState) //CreateOrRemoveSpeedPLace(train *state_proto.TrainState)
// CreateOrRemoveTrain 创建或删除列车 // CreateOrRemoveTrain 创建或删除列车
CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error
// TrainPluseCount 计算列车脉冲 // TrainPluseCount 计算列车脉冲
TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32)
ResetPluseCount(sta *state_proto.TrainState)
//FindAllThirdPartState() []tpapi.ThirdPartyApiService
} }
type TrainPcSimManage interface { type TrainPcSimManage interface {
@ -56,36 +59,25 @@ type TrainPcSimManage interface {
//获取列车模拟量数据 //获取列车模拟量数据
ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage
// TrainPcSimDigitalOutInfoHandle 4.4.1. 车载输出数字量信息报文内容 // TrainPcSimDigitalOutInfoHandle 4.4.1. 车载输出数字量信息报文内容
TrainPcSimDigitalOutInfoHandle(connType state_proto.TrainConnState_TrainConnType, data []byte) TrainPcSimDigitalOutInfoHandle(train *state_proto.TrainState, trainInit bool, data []byte) bool
// TrainPcSimDigitalReportHandle 4.4.2. 车载输出数字反馈量信息报文内容 // TrainPcSimDigitalReportHandle 4.4.2. 车载输出数字反馈量信息报文内容
TrainPcSimDigitalReportHandle(connType state_proto.TrainConnState_TrainConnType, data []byte) TrainPcSimDigitalReportHandle(train *state_proto.TrainState, data []byte)
FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState
// TrainPcSimMockInfo 门模式 // TrainPcSimMockInfo 门模式
//TrainDoorModeHandle(state byte) //TrainDoorModeHandle(state byte)
//处理列车pc仿真模拟量数据 //处理列车pc仿真模拟量数据
TrainPcSimMockInfo(connType state_proto.TrainConnState_TrainConnType, data []byte) TrainPcSimMockInfo(train *state_proto.TrainState, data []byte)
// TrainBtmQuery 处理列车btm查询 // TrainBtmQuery 处理列车btm查询
TrainBtmQuery(connType state_proto.TrainConnState_TrainConnType, data []byte) TrainBtmQuery(train *state_proto.TrainState, data []byte)
} }
type trainPcSimService struct {
const Name = "车载pc仿真" state tpapi.ThirdPartyApiServiceState
newPcSimclientMap map[string]*TrainPcReciverData
func FindTrainPcSimClientKey(t *state_proto.TrainState) string { cancleContext context.CancelFunc
if t.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_A { trainPcSimManage TrainPcSimManage
return "A" //speedPlace *message.TrainSpeedPlaceReportMsg
} else if t.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_B { //trainSpeedPlace map[string]*message.TrainSpeedPlaceReportMsg
return "B" configs []config.VehiclePCSimConfig
}
return ""
}
func (d *trainPcSimService) Name() string {
return Name
}
func (d *trainPcSimService) State() tpapi.ThirdPartyApiServiceState {
return d.state
}
func (d *trainPcSimService) updateState(state tpapi.ThirdPartyApiServiceState) {
d.state = state
} }
var ( var (
@ -101,14 +93,56 @@ func Default() TrainPcSim {
} }
return singleObj return singleObj
} }
const Name = "车载pc仿真"
func (d *trainPcSimService) Name() string {
return ""
}
func (d *trainPcSimService) State() tpapi.ThirdPartyApiServiceState {
return tpapi.ThirdPartyState_Closed
}
func (d *trainPcSimService) FindAppendApiService() []tpapi.ThirdPartyApiService {
return d.findAllThirdPartState()
}
func (d *trainPcSimService) TrueService() bool {
return false
}
func (d *trainPcSimService) ServiceDesc() string {
return Name
}
func FindTrainPcSimClientKey2(t *state_proto.TrainState) string {
return t.ConnState.TypeName
}
func (d *trainPcSimService) findTrainConn(sta *state_proto.TrainState) (*TrainPcReciverData, error) {
trainPcReciver := d.newPcSimclientMap[sta.ConnState.TypeName]
if trainPcReciver == nil {
return nil, fmt.Errorf("")
}
return trainPcReciver, nil
}
func (d *trainPcSimService) findAllThirdPartState() []tpapi.ThirdPartyApiService {
services := make([]tpapi.ThirdPartyApiService, 0)
for _, data := range d.newPcSimclientMap {
services = append(services, data)
}
return services
}
func pluseCountSpeed(wheelDiameter int32, speedMeter float32) uint32 { func pluseCountSpeed(wheelDiameter int32, speedMeter float32) uint32 {
s1 := speedMeter * 1000 s1 := speedMeter * 1000
pluseCountData := s1 * 200 / math.Pi / float32(wheelDiameter) pluseCountData := s1 * 200 / math.Pi / float32(wheelDiameter)
return uint32(pluseCountData) return uint32(pluseCountData)
} }
func (d *trainPcSimService) ResetPluseCount(sta *state_proto.TrainState) {
if sd, err := d.findTrainConn(sta); err == nil {
sd.speedPlace.PulseCount1 = 0
sd.speedPlace.PulseCount2 = 0
}
func (s *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) { }
func (d *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) {
defer initLock.Unlock() defer initLock.Unlock()
initLock.Lock() initLock.Lock()
if sta.TrainRunUp { if sta.TrainRunUp {
@ -128,33 +162,18 @@ func (s *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2,
} }
} }
func (s *trainPcSimService) TrainPluseCountReset(sta *state_proto.TrainState) { func (d *trainPcSimService) TrainPluseCountReset(sta *state_proto.TrainState) {
defer initLock.Unlock() defer initLock.Unlock()
initLock.Lock() initLock.Lock()
sta.PluseCount.PulseCount1 = 0 sta.PluseCount.PulseCount1 = 0
sta.PluseCount.PulseCount2 = 0 sta.PluseCount.PulseCount2 = 0
} }
type trainPcSimService struct {
state tpapi.ThirdPartyApiServiceState
newPcSimclientMap map[string]*trainPcReciverData
cancleContext context.CancelFunc
trainPcSimManage TrainPcSimManage
speedPlace *message.TrainSpeedPlaceReportMsg
configs []config.VehiclePCSimConfig
}
// 接受来自pc仿真的消息
func (d *trainPcSimService) readError(err error) {
slog.Error("连接车载pc仿真tcp服务断开", err)
d.updateState(tpapi.ThirdPartyState_Broken)
}
func (d *trainPcSimService) newCloseAllConn() { func (d *trainPcSimService) newCloseAllConn() {
trains := d.trainPcSimManage.GetConnTrain2() trains := d.trainPcSimManage.GetConnTrain2()
for _, train := range trains { for _, train := range trains {
d.CreateOrRemoveTrain(train, false) d.CreateOrRemoveTrain(train, false)
} }
} }
func (d *trainPcSimService) newCloseConn(clientKey string) { func (d *trainPcSimService) newCloseConn(clientKey string) {
@ -162,28 +181,22 @@ func (d *trainPcSimService) newCloseConn(clientKey string) {
if rd != nil { if rd != nil {
rd.tcpClient.Close() rd.tcpClient.Close()
rd.tcpClient = nil rd.tcpClient = nil
delete(d.newPcSimclientMap, clientKey) rd.train = nil
rd.speedPlace = nil
} }
} }
func (d *trainPcSimService) findConfig(tcChar string) (*config.VehiclePCSimConfig, error) { func (d *trainPcSimService) findConfig(configName string) (*config.VehiclePCSimConfig, error) {
configFlag := false
if tcChar == "A" {
configFlag = true
} else if tcChar == "B" {
configFlag = false
} else {
return nil, fmt.Errorf(fmt.Sprintf("未知车载pc连接标识:%v", tcChar))
}
for _, cfg := range d.configs { for _, cfg := range d.configs {
if cfg.Open && cfg.TrainEnds == configFlag { if cfg.Open && cfg.ConfigName == configName {
return &cfg, nil return &cfg, nil
} }
} }
return nil, fmt.Errorf("未找到对应的车载pc连接配置") return nil, fmt.Errorf("未找到对应的车载pc连接配置")
} }
func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
/*func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
go func() { go func() {
for { for {
@ -202,10 +215,9 @@ func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
d.newCloseConn(clientKey) d.newCloseConn(clientKey)
continue continue
} }
rd := d.newPcSimclientMap[clientKey] rd := d.newPcSimclientMap[clientKey]
if rd == nil { if rd == nil {
d.newPcSimclientMap[clientKey] = &trainPcReciverData{pcSimManage: d.trainPcSimManage, clientKey: clientKey, tcpClient: &tcp.TcpClient{}} d.newPcSimclientMap[clientKey] = &TrainPcReciverData{pcSimManage: d.trainPcSimManage, clientKey: clientKey, tcpClient: &tcp.TcpClient{}}
} }
if !rd.tcpClient.IsConning() { if !rd.tcpClient.IsConning() {
d.newCloseConn(clientKey) d.newCloseConn(clientKey)
@ -216,33 +228,42 @@ func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
time.Sleep(time.Second) time.Sleep(time.Second)
} }
}() }()
} }*/
func (d *trainPcSimService) initConn(clientKey string) { func (d *trainPcSimService) initConn(clientKey string) error {
rd := d.newPcSimclientMap[clientKey] rd := d.newPcSimclientMap[clientKey]
if rd != nil && rd.tcpClient != nil && rd.tcpClient.IsConning() { if rd != nil && rd.tcpClient != nil && rd.tcpClient.IsConning() {
rd.ebCheckIndex = 0 return nil
rd.isSleep = false } else {
return rd.trainInit = false
rd.tcpClient = nil
} }
rd = &trainPcReciverData{pcSimManage: d.trainPcSimManage, clientKey: clientKey, tcpClient: &tcp.TcpClient{}}
d.newPcSimclientMap[clientKey] = rd
cfg, _ := d.findConfig(clientKey)
addr := fmt.Sprintf("%v:%v", cfg.PcSimIp, cfg.PcSimPort)
client2, err := tcp.StartTcpClient(addr, rd.receiverDataHandle, d.readError) cfg, cfgErr := d.findConfig(clientKey)
if cfgErr != nil {
errMsg := fmt.Sprintf("没找到对应的配置信息 key:%v", clientKey)
slog.Error(errMsg, cfgErr.Error())
rd.updateState(tpapi.ThirdPartyState_Broken)
return sys_error.New(errMsg, cfgErr)
}
addr := fmt.Sprintf("%v:%v", cfg.PcSimIp, cfg.PcSimPort)
client2, err := tcp.StartTcpClient(addr, rd.receiverDataHandle, rd.readError)
if err != nil { if err != nil {
slog.Error(fmt.Sprintf("车载pc连接失败 clientKey:%v,error:%v", clientKey, err.Error())) connErrMsg := fmt.Sprintf("车载pc连接失败 clientKey:%v", clientKey)
d.updateState(tpapi.ThirdPartyState_Broken) slog.Error(connErrMsg, err.Error())
rd.updateState(tpapi.ThirdPartyState_Broken)
return sys_error.New(connErrMsg, err)
} else { } else {
rd.tcpClient = client2 rd.tcpClient = client2
} }
return nil
} }
func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) { func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
configs := pcSimManage.GetTrainPcSimConfig() configs := pcSimManage.GetTrainPcSimConfig()
d.newPcSimclientMap = make(map[string]*trainPcReciverData) d.newPcSimclientMap = make(map[string]*TrainPcReciverData)
if len(configs) <= 0 { if len(configs) <= 0 {
slog.Info("车载pc仿真配置未开启") slog.Info("车载pc仿真配置未开启")
return return
@ -251,44 +272,55 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
for _, c := range configs { for _, c := range configs {
if !c.Open { if !c.Open {
closedCount++ closedCount++
} else {
ck := c.ConfigName
pcReciver := &TrainPcReciverData{clientKey: ck, pcSimManage: pcSimManage}
pcReciver.updateState(tpapi.ThirdPartyState_Closed)
d.newPcSimclientMap[ck] = pcReciver
} }
} }
if closedCount == len(configs) { if closedCount == len(configs) {
slog.Error("车载pc仿真配置未开启") slog.Error("车载pc仿真配置未开启")
return return
} }
//third_party.AppendService(d.findAllThirdPartState())
d.configs = configs d.configs = configs
ctx, ctxFun := context.WithCancel(context.Background()) ctx, ctxFun := context.WithCancel(context.Background())
d.cancleContext = ctxFun d.cancleContext = ctxFun
d.trainPcSimManage = pcSimManage d.trainPcSimManage = pcSimManage
d.connTrainPcSim(ctx) //d.connTrainPcSim(ctx)
d.updateState(tpapi.ThirdPartyState_Normal)
go d.sendTrainLocationAndSpeedTask(ctx) go d.sendTrainLocationAndSpeedTask(ctx)
} }
func (d *trainPcSimService) Stop() { func (d *trainPcSimService) Stop() {
for _, data := range d.newPcSimclientMap {
d.updateState(tpapi.ThirdPartyState_Closed) data.updateState(tpapi.ThirdPartyState_Closed)
}
if d.cancleContext != nil { if d.cancleContext != nil {
d.cancleContext() d.cancleContext()
d.cancleContext = nil d.cancleContext = nil
} }
d.newCloseAllConn() d.newCloseAllConn()
} }
func (d *trainPcSimService) CreateOrRemoveSpeedPLace(train *state_proto.TrainState) {
if train.ConnState.Conn && (train.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_A || train.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_B) { /*
train.PluseCount = &state_proto.SensorSpeedPulseCount{} func (d *trainPcSimService) CreateOrRemoveSpeedPLace(train *state_proto.TrainState) {
d.speedPlace = &message.TrainSpeedPlaceReportMsg{TrainId: train.Id} if train.ConnState.Conn && (train.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_A || train.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_B) {
} else { train.PluseCount = &state_proto.SensorSpeedPulseCount{}
train.PluseCount = nil d.speedPlace = &message.TrainSpeedPlaceReportMsg{TrainId: train.Id}
d.speedPlace = nil } else {
train.PluseCount = nil
d.speedPlace = nil
}
} }
} */
func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error { func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error {
clientKey := FindTrainPcSimClientKey(train) clientKey := FindTrainPcSimClientKey2(train)
d.initConn(clientKey) err := d.initConn(clientKey)
if err != nil {
d.newCloseConn(clientKey)
return err
}
data := []byte{message.FLAG_CAMMAND_REMOVE_TRAIN} data := []byte{message.FLAG_CAMMAND_REMOVE_TRAIN}
if isCreate { if isCreate {
data[0] = message.FLAG_CAMMAND_CREATE_TRAIN data[0] = message.FLAG_CAMMAND_CREATE_TRAIN
@ -303,14 +335,19 @@ func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, i
if initTrainErr != nil { if initTrainErr != nil {
return initTrainErr return initTrainErr
} }
} }
return nil return nil
} }
func (d *trainPcSimService) initTrain(rd *trainPcReciverData, train *state_proto.TrainState, isCreate bool, trains *message.TrainPcSimBaseMessage) error { func (d *trainPcSimService) initTrain(rd *TrainPcReciverData, train *state_proto.TrainState, isCreate bool, trains *message.TrainPcSimBaseMessage) error {
msgs := make([]message.TrainPcSimBaseMessage, 0) msgs := make([]message.TrainPcSimBaseMessage, 0)
sendMsg := make([]byte, 0) sendMsg := make([]byte, 0)
if isCreate { if isCreate {
rd.speedPlace = &message.TrainSpeedPlaceReportMsg{}
train.PluseCount = &state_proto.SensorSpeedPulseCount{}
rd.train = train
tcc := train.Tcc
tcc.LineInitTimeStamp12 = 0
tcc.Line12ConnErr = false
tmpMsgs := d.trainPcSimManage.ObtainTrainDigitalMockData(train) tmpMsgs := d.trainPcSimManage.ObtainTrainDigitalMockData(train)
msgs = append(msgs, tmpMsgs...) msgs = append(msgs, tmpMsgs...)
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{0x00}, Type: message.RECIVE_TRAIN_DOOR_MODE}) //门模式 msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{0x00}, Type: message.RECIVE_TRAIN_DOOR_MODE}) //门模式
@ -331,7 +368,6 @@ func (d *trainPcSimService) initTrain(rd *trainPcReciverData, train *state_proto
sendMsg = append(sendMsg, data...) sendMsg = append(sendMsg, data...)
} }
sendMsg = append(sendMsg, trains.Encode()...) sendMsg = append(sendMsg, trains.Encode()...)
hexData := hex.EncodeToString(sendMsg) hexData := hex.EncodeToString(sendMsg)
slog.Info(fmt.Sprintf("发送列车初始化消息:%v", hexData)) slog.Info(fmt.Sprintf("发送列车初始化消息:%v", hexData))
rd.tcpClient.Send(sendMsg) rd.tcpClient.Send(sendMsg)
@ -348,21 +384,26 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
} }
trains := d.trainPcSimManage.GetConnTrain2() trains := d.trainPcSimManage.GetConnTrain2()
for _, train := range trains { for _, train := range trains {
if train.Tcc.Line12ConnErr {
d.updateState(tpapi.ThirdPartyState_Broken)
continue
}
if train.ConnState.Conn && train.PluseCount != nil { if train.ConnState.Conn && train.PluseCount != nil {
clientKey := FindTrainPcSimClientKey(train) trainClient, trainDataErr := d.findTrainConn(train)
rd := d.newPcSimclientMap[clientKey] if trainDataErr != nil {
slog.Error(fmt.Sprintf("pc仿真速度位置未找到对应的列车 id:%v", train.Id))
continue
}
connState := tpapi.ThirdPartyState_Normal
if train.Tcc.Line12ConnErr {
connState = tpapi.ThirdPartyState_Broken
}
trainClient.updateState(connState)
s1, s2 := train.PluseCount.PulseCount1, train.PluseCount.PulseCount2 s1, s2 := train.PluseCount.PulseCount1, train.PluseCount.PulseCount2
d.speedPlace.ParsePulseCount1(s1, s2) trainClient.speedPlace.ParsePulseCount1(s1, s2)
data := d.speedPlace.Encode(train.TrainRunUp, s1, s2) data := trainClient.speedPlace.Encode(train.TrainRunUp, s1, s2)
bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data} bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data}
d.TrainPluseCountReset(train) d.TrainPluseCountReset(train)
dataCode := bm.Encode() dataCode := bm.Encode()
//slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,s1: %v,s2: %v,c2: %v,c2: %v,发送数据:%v", train.Id, s1, s2, d.speedPlace.PulseCount1, d.speedPlace.PulseCount2, hex.EncodeToString(dataCode))) slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,s1: %v,s2: %v,c2: %v,c2: %v,发送数据:%v", train.Id, s1, s2, trainClient.speedPlace.PulseCount1, trainClient.speedPlace.PulseCount2, hex.EncodeToString(dataCode)))
err := rd.tcpClient.Send(dataCode) err := trainClient.tcpClient.Send(dataCode)
if err != nil { if err != nil {
slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode))) slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode)))
} }
@ -376,9 +417,14 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
// SendDriverActive Deprecated 发送驾驶激活 // SendDriverActive Deprecated 发送驾驶激活
func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) { func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
trainClient, trainDataErr := d.findTrainConn(train)
if trainDataErr != nil {
slog.Error(fmt.Sprintf("发送驾驶激活未找到对应的列车连接列车id%v", train.Id))
return
}
vobc := train.VobcState vobc := train.VobcState
clientKey := FindTrainPcSimClientKey(train)
rd := d.newPcSimclientMap[clientKey]
defulatBuf := make([]byte, 0) defulatBuf := make([]byte, 0)
msg := &message.TrainPcSimBaseMessage{Data: defulatBuf} msg := &message.TrainPcSimBaseMessage{Data: defulatBuf}
if train.TrainRunUp { if train.TrainRunUp {
@ -405,18 +451,22 @@ func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
msgs = append(msgs, msg.Encode()...) msgs = append(msgs, msg.Encode()...)
hexData := hex.EncodeToString(msgs) hexData := hex.EncodeToString(msgs)
slog.Info(fmt.Sprintf("发送驾驶激活列车id:%v,数据:%v", train.Id, hexData)) slog.Info(fmt.Sprintf("发送驾驶激活列车id:%v,数据:%v", train.Id, hexData))
err := rd.tcpClient.Send(msgs) err := trainClient.tcpClient.Send(msgs)
if err != nil { if err != nil {
slog.Error(fmt.Sprintf("发送驾驶激活失败列车id:%v,数据:%v,err:%v", train.Id, hexData, err.Error())) slog.Error(fmt.Sprintf("发送驾驶激活失败列车id:%v,数据:%v,err:%v", train.Id, hexData, err.Error()))
} }
} }
func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState) { func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState) {
trainClient, trainDataErr := d.findTrainConn(train)
if trainDataErr != nil {
slog.Error(fmt.Sprintf("发送列车牵引知道失败未找到对应的列车id:%v", train.Id))
return
}
tc := train.ConnState tc := train.ConnState
if tc.Conn { if tc.Conn {
vobc := train.VobcState vobc := train.VobcState
clientKey := FindTrainPcSimClientKey(train)
rd := d.newPcSimclientMap[clientKey]
msg := &message.TrainPcSimBaseMessage{} msg := &message.TrainPcSimBaseMessage{}
newTraction := vobc.TractionForce newTraction := vobc.TractionForce
@ -443,16 +493,20 @@ func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, t
msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD
} }
da := msg.Encode() da := msg.Encode()
slog.Info("发送列车手柄消息", "clientKey", clientKey, "msg", hex.EncodeToString(da)) slog.Info("发送列车手柄消息", "msg", hex.EncodeToString(da))
err := rd.tcpClient.Send(da) err := trainClient.tcpClient.Send(da)
//err := client.Send(da) //err := client.Send(da)
if err != nil { if err != nil {
slog.Error("发送列车手柄消息失败", "clientKey", clientKey, "msg", hex.EncodeToString(da)) slog.Error("发送列车手柄消息失败", "msg", hex.EncodeToString(da))
} }
} }
} }
func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, trainForward, trainBackward bool) { func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, trainForward, trainBackward bool) {
trainClient, trainDataErr := d.findTrainConn(train)
if trainDataErr != nil {
slog.Error(fmt.Sprintf("发送列车方向失败未找到列车连接trainId%s", train.Id))
return
}
baseMsgs := make([]*message.TrainPcSimBaseMessage, 0) baseMsgs := make([]*message.TrainPcSimBaseMessage, 0)
if !trainForward && !trainBackward { if !trainForward && !trainBackward {
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD}) baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD})
@ -462,13 +516,11 @@ func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, tr
} else if trainBackward { } else if trainBackward {
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_BACKWARD}) baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_BACKWARD})
} }
clientKey := FindTrainPcSimClientKey(train)
rd := d.newPcSimclientMap[clientKey]
for _, msg := range baseMsgs { for _, msg := range baseMsgs {
da := msg.Encode() da := msg.Encode()
slog.Info(fmt.Sprintf("发送列车方向列车:%v ,数据:%v", train.Id, hex.EncodeToString(da))) slog.Info(fmt.Sprintf("发送列车方向列车:%v ,数据:%v", train.Id, hex.EncodeToString(da)))
err := rd.tcpClient.Send(da) err := trainClient.tcpClient.Send(da)
if err != nil { if err != nil {
slog.Error(fmt.Sprintf("发送列车方向失败列车:%v ,数据:%v,err:%v", train.Id, hex.EncodeToString(da), err.Error())) slog.Error(fmt.Sprintf("发送列车方向失败列车:%v ,数据:%v,err:%v", train.Id, hex.EncodeToString(da), err.Error()))
@ -477,14 +529,18 @@ func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, tr
} }
func (d *trainPcSimService) SendBaliseData2(train *state_proto.TrainState, msgType byte, data []string) { func (d *trainPcSimService) SendBaliseData2(train *state_proto.TrainState, msgType byte, data []string) {
trainClient, trainDataErr := d.findTrainConn(train)
if trainDataErr != nil {
slog.Error(fmt.Sprintf("发送列车PC仿真应答器信息失败2未找到列车连接trainId%v", train.Id))
return
}
for _, hexData := range data { for _, hexData := range data {
dd, _ := hex.DecodeString(hexData) dd, _ := hex.DecodeString(hexData)
msg := &message.TrainPcSimBaseMessage{Type: msgType, Data: dd} msg := &message.TrainPcSimBaseMessage{Type: msgType, Data: dd}
clientKey := FindTrainPcSimClientKey(train)
rd := d.newPcSimclientMap[clientKey]
da := msg.Encode() da := msg.Encode()
//slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,数据类型:0x%X,数据:%v", msgType, hex.EncodeToString(da))) //slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,数据类型:0x%X,数据:%v", msgType, hex.EncodeToString(da)))
err := rd.tcpClient.Send(da) err := trainClient.tcpClient.Send(da)
if err != nil { if err != nil {
slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息失败,数据:%v", hex.EncodeToString(da))) slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息失败,数据:%v", hex.EncodeToString(da)))
} }
@ -492,25 +548,33 @@ func (d *trainPcSimService) SendBaliseData2(train *state_proto.TrainState, msgTy
} }
func (d *trainPcSimService) SendBaliseData(train *state_proto.TrainState, msgType byte, data []byte) { func (d *trainPcSimService) SendBaliseData(train *state_proto.TrainState, msgType byte, data []byte) {
trainClient, trainDataErr := d.findTrainConn(train)
if trainDataErr != nil {
slog.Error(fmt.Sprintf("发送列车PC仿真应答器信息失败未找到列车连接trainId%v", train.Id))
return
}
msg := &message.TrainPcSimBaseMessage{} msg := &message.TrainPcSimBaseMessage{}
msg.Type = msgType msg.Type = msgType
msg.Data = data msg.Data = data
clientKey := FindTrainPcSimClientKey(train)
rd := d.newPcSimclientMap[clientKey]
da := msg.Encode() da := msg.Encode()
//slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,无应答器:%v,数据:%v", msgType == message.RECIVE_TRAIN_BTM_NOT_DATA, hex.EncodeToString(da))) //slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,无应答器:%v,数据:%v", msgType == message.RECIVE_TRAIN_BTM_NOT_DATA, hex.EncodeToString(da)))
err := rd.tcpClient.Send(da) err := trainClient.tcpClient.Send(da)
if err != nil { if err != nil {
slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息失败,数据:%v", hex.EncodeToString(da))) slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息失败,数据:%v", hex.EncodeToString(da)))
} }
} }
func (d *trainPcSimService) PublishTrainControlEvent(train *state_proto.TrainState, events []TrainControlEvent) { /*func (d *trainPcSimService) PublishTrainControlEvent(train *state_proto.TrainState, events []TrainControlEvent) {
if len(events) <= 0 { if len(events) <= 0 {
return return
} }
clientKey := FindTrainPcSimClientKey(train) trainClient, trainDataErr := d.findTrainConn(train)
rd := d.newPcSimclientMap[clientKey] if trainDataErr != nil {
slog.Error("")
return
}
msgs := make([]byte, 0) msgs := make([]byte, 0)
for _, event := range events { for _, event := range events {
msg := &message.TrainPcSimBaseMessage{Type: event.Type, Data: event.Data} msg := &message.TrainPcSimBaseMessage{Type: event.Type, Data: event.Data}
@ -519,20 +583,24 @@ func (d *trainPcSimService) PublishTrainControlEvent(train *state_proto.TrainSta
} }
hexCode := hex.EncodeToString(msgs) hexCode := hex.EncodeToString(msgs)
slog.Info(fmt.Sprintf("列车数字量信息发送数据:%v", hexCode)) slog.Info(fmt.Sprintf("列车数字量信息发送数据:%v", hexCode))
err := rd.tcpClient.Send(msgs) err := trainClient.tcpClient.Send(msgs)
if err != nil { if err != nil {
slog.Error(fmt.Sprintf("列车数字量信息发送失败,数据:%v", hexCode)) slog.Error(fmt.Sprintf("列车数字量信息发送失败,数据:%v", hexCode))
} }
} }*/
func (d *trainPcSimService) SendTrainControlMsg(train *state_proto.TrainState, baseMessage []message.TrainPcSimBaseMessage) { func (d *trainPcSimService) SendTrainControlMsg(train *state_proto.TrainState, baseMessage []message.TrainPcSimBaseMessage) {
if len(baseMessage) <= 0 { if len(baseMessage) <= 0 {
return return
} }
clientKey := FindTrainPcSimClientKey(train) trainClient, trainDataErr := d.findTrainConn(train)
rd := d.newPcSimclientMap[clientKey] if trainDataErr != nil {
slog.Error(fmt.Sprintf("发送列车控制信息失败,无连接,列车Id:%v", train.Id))
return
}
for _, msg := range baseMessage { for _, msg := range baseMessage {
d.sendData(rd.tcpClient, msg.Encode()) d.sendData(trainClient.tcpClient, msg.Encode())
} }
} }

View File

@ -13,14 +13,36 @@ const (
QHFXKZ = "QHFXKZ" //驾驶方向 QHFXKZ = "QHFXKZ" //驾驶方向
QYSB = "QYSB" //牵引制动手柄 QYSB = "QYSB" //牵引制动手柄
ATPQCKG = "ATPQCKG" //ATP切除开关 ATPQCKG = "ATPQCKG" //ATP切除开关
KZM = "KZM" //开左门按钮 KZM = "KZM" //开左门按钮
GZM = "GZM" //关左门按钮 GZM = "GZM" //关左门按钮
GYM = "GYM" //关右门按钮 GYM = "GYM" //关右门按钮
ZAWTGJC = "ZAWTGJC" //障碍物/脱轨检测 KYM = "KYM" //开右门
ZDZGZ = "ZDZGZ" //制动重故障 ZAWTGJC = "ZAWTGJC" //障碍物/脱轨检测
ATPSD = "ATPSD" //ATP上电按钮 ZDZGZ = "ZDZGZ" //制动重故障
MSQR = "MSQR" //模式确认 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控车
) )
// 获取列车控制图形数据 // 获取列车控制图形数据
@ -103,21 +125,22 @@ func initTrainTcc(vs *VerifySimulation, runDir bool, breaking int32) *state_prot
} }
} }
tcc := &state_proto.TrainControlState{Line12ConnErr: false, InitCount: 0} tcc := &state_proto.TrainControlState{}
if tccGI != nil { if tccGI != nil {
tcc.LightMaps = make(map[string]*state_proto.TrainControlState_ControlLight) tcc.LightMaps = make(map[string]*state_proto.TrainControlState_ControlLight)
for _, light := range tccGI.TccLights { for _, light := range tccGI.TccLights {
tcc.LightMaps[light.Code] = &state_proto.TrainControlState_ControlLight{Id: light.Common.Id, Val: light.InitialState} tcc.LightMaps[light.Code] = &state_proto.TrainControlState_ControlLight{Id: light.Common.Id, Val: light.InitialState}
} }
btns := make([]*state_proto.TrainControlState_ControlButton, 0) btns := make(map[string]*state_proto.TrainControlState_ControlButton, 0)
for _, b := range tccGI.TccButtons { for _, b := range tccGI.TccButtons {
btn := &state_proto.TrainControlState_ControlButton{Id: b.Common.Id, Passed: false} btn := &state_proto.TrainControlState_ControlButton{Id: b.Common.Id, Passed: false}
switch b.Code { switch b.Code {
case ATPQCKG, GZM, GYM, ZAWTGJC, ZDZGZ, ATPSD, MSQR: case ATPQCKG, GZM, GYM, ZAWTGJC, ZDZGZ, ATPSD, MSQR:
btn.Passed = true btn.Passed = true
} }
btns = append(btns, btn) btns[b.Code] = btn
//btns = append(btns, btn)
} }
tcc.Buttons = btns tcc.Buttons = btns
for _, b := range tccGI.TccHandles { for _, b := range tccGI.TccHandles {

View File

@ -150,12 +150,11 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
//列车连接 半实物或车载pc仿真 //列车连接 半实物或车载pc仿真
allTrainMap.Range(func(k, v any) bool { allTrainMap.Range(func(k, v any) bool {
tmpTrain := v.(*state_proto.TrainState) tmpTrain := v.(*state_proto.TrainState)
if tmpTrain.ConnState.Conn { connState := tmpTrain.ConnState
if connState.Conn {
connTypeName := "半实物" connTypeName := "半实物"
if tmpTrain.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_A { if connState.ConnType == state_proto.TrainConnState_PC_SIM && connState.TypeName == ct.TypeName {
connTypeName = "车载pc仿真-A" connTypeName = fmt.Sprintf("车载pc仿真-%v", ct.TypeName)
} else if tmpTrain.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_B {
connTypeName = "车载pc仿真-B"
} }
panic(sys_error.New(fmt.Sprintf("列车[%s]已经连接 [%v],此列车无法连接", k, connTypeName))) panic(sys_error.New(fmt.Sprintf("列车[%s]已经连接 [%v],此列车无法连接", k, connTypeName)))
return false return false
@ -165,7 +164,8 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
} }
train.ConnState.Conn = true train.ConnState.Conn = true
train.ConnState.ConnType = ct.ConnType train.ConnState.ConnType = ct.ConnType
if ct.ConnType == state_proto.TrainConnState_PC_SIM_A || ct.ConnType == state_proto.TrainConnState_PC_SIM_B { train.ConnState.TypeName = ct.TypeName
if ct.ConnType == state_proto.TrainConnState_PC_SIM {
train.Tcc.LineInitTimeStamp12 = 0 train.Tcc.LineInitTimeStamp12 = 0
err := TrainPcSimConnOrRemoveHandle(train, true) err := TrainPcSimConnOrRemoveHandle(train, true)
if err != nil { if err != nil {
@ -180,6 +180,7 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
// 列车断开三方连接 // 列车断开三方连接
func TrainUnConn(vs *VerifySimulation, trainId string) { func TrainUnConn(vs *VerifySimulation, trainId string) {
allTrainMap := &vs.Memory.Status.TrainStateMap allTrainMap := &vs.Memory.Status.TrainStateMap
data, ok := allTrainMap.Load(trainId) data, ok := allTrainMap.Load(trainId)
if !ok { if !ok {
@ -190,8 +191,11 @@ func TrainUnConn(vs *VerifySimulation, trainId string) {
if err != nil { if err != nil {
panic(sys_error.New("未连接车载PC仿真无法断开连接")) panic(sys_error.New("未连接车载PC仿真无法断开连接"))
} }
train.ConnState.Conn = false defer func() {
train.ConnState.ConnType = state_proto.TrainConnState_NONE train.ConnState.Conn = false
train.ConnState.ConnType = state_proto.TrainConnState_NONE
train.ConnState.TypeName = ""
}()
} }
func createOrUpdateStateDynamicConfig(trainState *state_proto.TrainState, configTrainData dto.ConfigTrainData, trainEndsA dto.ConfigTrainEnds, func createOrUpdateStateDynamicConfig(trainState *state_proto.TrainState, configTrainData dto.ConfigTrainData, trainEndsA dto.ConfigTrainEnds,
trainEndsB dto.ConfigTrainEnds) { trainEndsB dto.ConfigTrainEnds) {
@ -438,12 +442,16 @@ func removeTrain(vs *VerifySimulation, trainId string, train *state_proto.TrainS
if err != nil { if err != nil {
return err return err
} }
if train.ConnState.Conn { thirdConn := train.ConnState
train.ConnState.Conn = false if thirdConn.Conn {
thirdConn.Conn = false
err = TrainPcSimConnOrRemoveHandle(train, false) err = TrainPcSimConnOrRemoveHandle(train, false)
if err != nil { if err != nil {
train.ConnState.Conn = true train.ConnState.Conn = true
return err return err
} else {
thirdConn.ConnType = state_proto.TrainConnState_NONE
thirdConn.TypeName = ""
} }
} }
if train.VobcState != nil { if train.VobcState != nil {
@ -454,7 +462,7 @@ func removeTrain(vs *VerifySimulation, trainId string, train *state_proto.TrainS
vobc.BrakeForce = DEFAULT_BRAKE_FORCE vobc.BrakeForce = DEFAULT_BRAKE_FORCE
} }
train.Show = false train.Show = false
train.ConnState.ConnType = state_proto.TrainConnState_NONE
return fi.RemoveTrainFromWorld(vs.World, trainId) return fi.RemoveTrainFromWorld(vs.World, trainId)
} }

View File

@ -532,16 +532,12 @@ func (s *VerifySimulation) CollectInterlockRelayInfo(code string) *message.Inter
func (s *VerifySimulation) FindTrainConnTypes() []dto.TrainConnTypeConfigDto { func (s *VerifySimulation) FindTrainConnTypes() []dto.TrainConnTypeConfigDto {
typeConfig := make([]dto.TrainConnTypeConfigDto, 0) typeConfig := make([]dto.TrainConnTypeConfigDto, 0)
if /*s.runConfig.Vobc.Open &&*/ s.runConfig.Vobc.Ip != "" { if /*s.runConfig.Vobc.Open &&*/ s.runConfig.Vobc.Ip != "" {
typeConfig = append(typeConfig, dto.TrainConnTypeConfigDto{ConnType: state_proto.TrainConnState_VOBC}) typeConfig = append(typeConfig, dto.TrainConnTypeConfigDto{TypeName: "半实物vobc", ConnType: state_proto.TrainConnState_VOBC})
} }
for _, pcSim := range s.runConfig.PcSimConfigs { for _, pcSim := range s.runConfig.PcSimConfigs {
dto := dto.TrainConnTypeConfigDto{ConnType: state_proto.TrainConnState_PC_SIM_A}
if !pcSim.TrainEnds { typeConfig = append(typeConfig, dto.TrainConnTypeConfigDto{TypeName: pcSim.ConfigName, ConnType: state_proto.TrainConnState_PC_SIM})
dd := &dto
dd.ConnType = state_proto.TrainConnState_PC_SIM_B
}
typeConfig = append(typeConfig, dto)
} }
/* if s.runConfig.PcSimConfig.Open { /* if s.runConfig.PcSimConfig.Open {
typeConfig = append(typeConfig, dto.TrainConnTypeConfigDto{ConnType: state_proto.TrainConnState_PC_SIM}) typeConfig = append(typeConfig, dto.TrainConnTypeConfigDto{ConnType: state_proto.TrainConnState_PC_SIM})

View File

@ -38,14 +38,15 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
sta := data.(*state_proto.TrainState) sta := data.(*state_proto.TrainState)
vobc := sta.VobcState vobc := sta.VobcState
tcc := sta.Tcc tcc := sta.Tcc
var tce []train_pc_sim.TrainControlEvent = nil
var baseMsg []message.TrainPcSimBaseMessage = nil
if ct.ControlType == request_proto.TrainControl_EMERGENT_BUTTON { if ct.ControlType == request_proto.TrainControl_EMERGENT_BUTTON {
tce = trainControlButton(vobc, tcc.Buttons, ct.DeviceId, ct.ControlButton.Active, tccGraphicData) baseMsg = trainControlButton(vobc, tcc.Buttons, ct.DeviceId, ct.ControlButton.Active, tccGraphicData)
} else if ct.ControlType == request_proto.TrainControl_DRIVER_KEY_SWITCH { } else if ct.ControlType == request_proto.TrainControl_DRIVER_KEY_SWITCH {
tce = trainControlDriverKey(sta, ct.DriverKey, ct.DeviceId, tccGraphicData) baseMsg = trainControlDriverKey(sta, ct.DriverKey, ct.DeviceId, tccGraphicData)
train_pc_sim.Default().SendDriverActive(sta) train_pc_sim.Default().SendDriverActive(sta)
} else if ct.ControlType == request_proto.TrainControl_DIRECTION_KEY_SWITCH { } else if ct.ControlType == request_proto.TrainControl_DIRECTION_KEY_SWITCH {
tce = trainControlDirKey(sta.DynamicState.Speed, vobc, tcc, ct.DirKey, ct.DeviceId, tccGraphicData) baseMsg = trainControlDirKey(sta.DynamicState.Speed, vobc, tcc, ct.DirKey, ct.DeviceId, tccGraphicData)
//此处先注释,根据现场调试情况 2024-4-16 //此处先注释,根据现场调试情况 2024-4-16
train_pc_sim.Default().SendTrainDirection(sta, sta.VobcState.DirectionForward, sta.VobcState.DirectionBackward) train_pc_sim.Default().SendTrainDirection(sta, sta.VobcState.DirectionForward, sta.VobcState.DirectionBackward)
} else if ct.ControlType == request_proto.TrainControl_HANDLER { } else if ct.ControlType == request_proto.TrainControl_HANDLER {
@ -55,13 +56,13 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
oldTraction := sta.VobcState.TractionForce oldTraction := sta.VobcState.TractionForce
oldBrakeForce := sta.VobcState.BrakeForce oldBrakeForce := sta.VobcState.BrakeForce
isTraction := ct.Handler.Val > 0 //是否制动 isTraction := ct.Handler.Val > 0 //是否制动
tce = trainControlHandle(vobc, tcc, ct.Handler, ct.DeviceId, tccGraphicData) baseMsg = trainControlHandle(vobc, tcc, ct.Handler, ct.DeviceId, tccGraphicData)
train_pc_sim.Default().SendHandleSwitch(oldTraction, oldBrakeForce, isTraction, sta) train_pc_sim.Default().SendHandleSwitch(oldTraction, oldBrakeForce, isTraction, sta)
} }
if vobc.DirectionForward && vobc.TractionForce == 0 { if vobc.DirectionForward && vobc.TractionForce == 0 {
tce = append(tce, train_pc_sim.TrainControlEvent{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DIR_ZERO_FORWARD, 1}}) baseMsg = append(baseMsg, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DIR_ZERO_FORWARD, 1}})
} else { } else {
tce = append(tce, train_pc_sim.TrainControlEvent{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DIR_ZERO_FORWARD, 0}}) baseMsg = append(baseMsg, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DIR_ZERO_FORWARD, 0}})
} }
if !vobc.DirectionForward && !vobc.DirectionBackward { if !vobc.DirectionForward && !vobc.DirectionBackward {
vobc.TractionStatus = false vobc.TractionStatus = false
@ -70,62 +71,56 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
if vobc.EmergencyBrakingStatus { if vobc.EmergencyBrakingStatus {
vobc.TractionForce = 0 vobc.TractionForce = 0
} }
if sta.ConnState.Conn && (sta.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_A || sta.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_B) && tce != nil { if sta.ConnState.Conn && (sta.ConnState.ConnType == state_proto.TrainConnState_PC_SIM) && baseMsg != nil {
train_pc_sim.Default().PublishTrainControlEvent(sta, tce) train_pc_sim.Default().SendTrainControlMsg(sta, baseMsg)
} }
} }
func findBtnFromTccByDeviceId(tcc []*state_proto.TrainControlState_ControlButton, deviceId uint32) (*state_proto.TrainControlState_ControlButton, bool) { func trainControlButton(vobc *state_proto.TrainVobcState, buttonMap map[string]*state_proto.TrainControlState_ControlButton, deviceId uint32, active bool, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
for _, tccBtn := range tcc {
if tccBtn.Id == deviceId {
return tccBtn, true
}
}
return nil, false
}
func trainControlButton(vobc *state_proto.TrainVobcState, tcc []*state_proto.TrainControlState_ControlButton, deviceId uint32, active bool, tccGraphic *data_proto.TccGraphicStorage) []train_pc_sim.TrainControlEvent {
if graphicBtn, ok := findTrainTccGraphicDataButton(tccGraphic, deviceId); ok { if graphicBtn, ok := findTrainTccGraphicDataButton(tccGraphic, deviceId); ok {
btn, btnOk := findBtnFromTccByDeviceId(tcc, deviceId) btn := buttonMap[graphicBtn.Code]
if btnOk == false { if btn == nil {
slog.Error("未找到对应的车载摁钮code:", graphicBtn.Code, "设备id:", deviceId) slog.Error("未找到对应的车载摁钮code:", graphicBtn.Code, "设备id:", deviceId)
return nil return nil
} }
switch graphicBtn.Code { switch graphicBtn.Code {
case "JJZD": // 紧急制动 case JJZD: // 紧急制动
return controlEBBtn(vobc, active, btn) return controlEBBtn(vobc, active, btn)
case "ATPQCKG": //atp切除 case ATPQCKG: //atp切除
return controlAtpBtn(vobc, active, btn) return controlAtpBtn(vobc, active, btn)
/* case "WBJJZDFK": //外部紧急制动反馈 /* case "WBJJZDFK": //外部紧急制动反馈
return controlOutEbReportBtn(vobc, active, btn)*/ return controlOutEbReportBtn(vobc, active, btn)*/
case "KZM": //开左门按钮 case KZM: //开左门按钮
return controlLeftDoorBtn(vobc, active, btn) return controlLeftDoorBtn(vobc, active, btn)
case "GZM": //关左门按钮 case GZM: //关左门按钮
return controlLeftDoorCloseBtn(vobc, active, btn) return controlLeftDoorCloseBtn(vobc, active, btn)
case "KYM": //开右门按钮 case KYM: //开右门按钮
return controlRightDoorBtn(vobc, active, btn) return controlRightDoorBtn(vobc, active, btn)
case "GYM": //关右门按钮 case GYM: //关右门按钮
return controlRightDoorCloseBtn(vobc, active, btn) return controlRightDoorCloseBtn(vobc, active, btn)
case "ZF": //折返按钮 case ZF: //折返按钮
return controlReverseBtn(vobc, active, btn) return controlReverseBtn(vobc, active, btn)
case "QZMYX": //强制门允许 case QZMYX: //强制门允许
return controlDoorAllowBtn(vobc, active, btn) return controlDoorAllowBtn(vobc, active, btn)
case "MSJJ": //模式降级按钮 case MSJJ: //模式降级按钮
return controlModeDownBtn(vobc, active, btn) return controlModeDownBtn(vobc, active, btn)
case "MSSJ": //模式升级按钮 case MSSJ: //模式升级按钮
return controlModeUpBtn(vobc, active, btn) return controlModeUpBtn(vobc, active, btn)
case "MSQR": //模式确认按钮 case MSQR: //模式确认按钮
return controlModeConfirmBtn(vobc, active, btn) return controlModeConfirmBtn(vobc, active, btn)
case "ZAWTGJC": //障碍物/脱轨检测 case ZAWTGJC: //障碍物/脱轨检测
return controlObstacleDetectionBtn(vobc, active, btn) return controlObstacleDetectionBtn(vobc, active, btn)
case "ZDZGZ": //制动重故障 case ZDZGZ: //制动重故障
return controlBrakeHeavyBtn(vobc, active, btn) return controlBrakeHeavyBtn(vobc, active, btn)
case "ATPSD": //ATP上电按钮 case ATPSD: //ATP上电按钮
return controlAtpPowerBtn(vobc, active, btn) return controlAtpPowerBtn(vobc, active, btn)
case "HX": //唤醒按钮 case HX: //唤醒按钮
return controlWakeUpBtn(vobc, active, btn) return controlWakeUpBtn(vobc, active, btn)
case "JX": //检修按钮 case JX: //检修按钮
return controlOverhaulBtn(vobc, active, btn) return controlOverhaulBtn(vobc, active, btn)
case "XM": //休眠按钮 case XM: //休眠按钮
return controlSleepBtn(vobc, active, btn) return controlSleepBtn(vobc, active, btn)
default: default:
return nil return nil
@ -136,7 +131,7 @@ func trainControlButton(vobc *state_proto.TrainVobcState, tcc []*state_proto.Tra
} }
// 应急摁钮 // 应急摁钮
func controlEBBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlEBBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
if !active { if !active {
return nil return nil
} }
@ -144,77 +139,70 @@ func controlEBBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_p
vobc.EmergencyBrakingStatus = true vobc.EmergencyBrakingStatus = true
vobc.TractionForce = 0 vobc.TractionForce = 0
vobc.BrakeForce = DEFAULT_BRAKE_FORCE vobc.BrakeForce = DEFAULT_BRAKE_FORCE
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, 0}}, {Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_BRAKE_STATE, 1}}} //紧急制动 return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, 0}}, {Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_BRAKE_STATE, 1}}}
} }
// atp 切除 // atp 切除
func controlAtpBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlAtpBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
vobc.AtpCutSwitch = active vobc.AtpCutSwitch = active
tccBtn.Passed = active tccBtn.Passed = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.ATP_CUT, status}}} //紧急制动 return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.ATP_CUT, status}}}
}
// 外部紧急制动反馈
func controlOutEbReportBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent {
var status byte = 0
if active {
status = 1
}
vobc.OuterEmergentBrakeReport = active
tccBtn.Passed = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, status}}} //紧急制动
} }
// 开左门按钮 // 开左门按钮
func controlLeftDoorBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlLeftDoorBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
vobc.LeftDoorOpenCommand = active vobc.LeftDoorOpenCommand = active
tccBtn.Passed = active tccBtn.Passed = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.LEFT_OPEN_DOOR, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.LEFT_OPEN_DOOR, status}}}
} }
// 关左门按钮 // 关左门按钮
func controlLeftDoorCloseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlLeftDoorCloseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
vobc.LeftDoorCloseCommand = active vobc.LeftDoorCloseCommand = active
tccBtn.Passed = active tccBtn.Passed = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.CLOSE_LEFT_DOOR, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.CLOSE_LEFT_DOOR, status}}}
} }
// 开右门 // 开右门
func controlRightDoorBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlRightDoorBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
vobc.RightDoorOpenCommand = active vobc.RightDoorOpenCommand = active
tccBtn.Passed = active tccBtn.Passed = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OPEN_RIGHT_DOOR, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OPEN_RIGHT_DOOR, status}}}
} }
// 关右门按钮 // 关右门按钮
func controlRightDoorCloseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlRightDoorCloseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
vobc.RightDoorCloseCommand = active vobc.RightDoorCloseCommand = active
tccBtn.Passed = active tccBtn.Passed = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.CLOSE_RIGHT_DOOR, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.CLOSE_RIGHT_DOOR, status}}}
} }
// 折返 // 折返
func controlReverseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlReverseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
@ -222,121 +210,126 @@ func controlReverseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *st
//vobc.RightDoorCloseCommand = active //vobc.RightDoorCloseCommand = active
vobc.TurnbackStatus = active vobc.TurnbackStatus = active
tccBtn.Passed = active tccBtn.Passed = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TURN_BACK, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TURN_BACK, status}}}
} }
// 强制门允许 // 强制门允许
func controlDoorAllowBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlDoorAllowBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.ForceDoorAllow = active vobc.ForceDoorAllow = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.FORCE_DOOR_ALLOW, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.FORCE_DOOR_ALLOW, status}}}
} }
// 模式降级按钮 // 模式降级按钮
func controlModeDownBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlModeDownBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.ModeLevelDownBtn = active vobc.ModeLevelDownBtn = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_MODE_DOWN, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_MODE_DOWN, status}}}
} }
// 模式升级按钮 // 模式升级按钮
func controlModeUpBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlModeUpBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.ModeLevelUpBtn = active vobc.ModeLevelUpBtn = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_MODE_UP, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_MODE_UP, status}}}
} }
// 模式确认按钮 // 模式确认按钮
func controlModeConfirmBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlModeConfirmBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.ConfirmBtn = active vobc.ConfirmBtn = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.CONFIRM, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.CONFIRM, status}}}
} }
// 障碍物/脱轨检测 // 障碍物/脱轨检测
func controlObstacleDetectionBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlObstacleDetectionBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.ObstacleCheckBtn = active vobc.ObstacleCheckBtn = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OBSTACLE_CHECK, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OBSTACLE_CHECK, status}}}
} }
// 制动重故障 // 制动重故障
func controlBrakeHeavyBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlBrakeHeavyBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.BrakeHeavyFault = active vobc.BrakeHeavyFault = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.BRAKE_HEAVY_FAULT, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.BRAKE_HEAVY_FAULT, status}}}
} }
// ATP上电按钮 // ATP上电按钮
func controlAtpPowerBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlAtpPowerBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.AtpPowerOnBtn = active vobc.AtpPowerOnBtn = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.ATP_POWER_ON, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.ATP_POWER_ON, status}}}
} }
// 唤醒按钮 // 唤醒按钮
func controlWakeUpBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlWakeUpBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.WakeUpBtn = active vobc.WakeUpBtn = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.WAKE_UP, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.WAKE_UP, status}}}
} }
// 检修按钮 // 检修按钮
func controlOverhaulBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlOverhaulBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.OverhaulBtn = active vobc.OverhaulBtn = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OVERHAUL, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OVERHAUL, status}}}
} }
// 休眠按钮 // 休眠按钮
func controlSleepBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []train_pc_sim.TrainControlEvent { func controlSleepBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_proto.TrainControlState_ControlButton) []message.TrainPcSimBaseMessage {
var status byte = 0 var status byte = 0
if active { if active {
status = 1 status = 1
} }
tccBtn.Passed = active tccBtn.Passed = active
vobc.SleepBtn = active vobc.SleepBtn = active
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.SLEEP, status}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.SLEEP, status}}}
} }
// 列车方向 // 列车方向
func trainControlDirKey(trainSpeed int32, vobc *state_proto.TrainVobcState, tcc *state_proto.TrainControlState, request *request_proto.TrainControl_DirectionKeySwitch, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []train_pc_sim.TrainControlEvent { func trainControlDirKey(trainSpeed int32, vobc *state_proto.TrainVobcState, tcc *state_proto.TrainControlState, request *request_proto.TrainControl_DirectionKeySwitch, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
_, find := findTrainTccGraphicDataKey(tccGraphic, deviceId) _, find := findTrainTccGraphicDataKey(tccGraphic, deviceId)
if !find { if !find {
slog.Error("未找到对应的列车方向键deviceId:", deviceId) slog.Error("未找到对应的列车方向键deviceId:", deviceId)
@ -345,30 +338,24 @@ func trainControlDirKey(trainSpeed int32, vobc *state_proto.TrainVobcState, tcc
if tcc.DirKey == nil { if tcc.DirKey == nil {
tcc.DirKey = &state_proto.TrainControlState_DirectionKeySwitch{Id: deviceId} tcc.DirKey = &state_proto.TrainControlState_DirectionKeySwitch{Id: deviceId}
} }
tce := make([]train_pc_sim.TrainControlEvent, 0)
direction := request_proto.TrainControl_Direction(request.Val) direction := request_proto.TrainControl_Direction(request.Val)
if trainSpeed > 0 { if trainSpeed > 0 {
panic(sys_error.New("列车未停稳时,不能变更方向")) panic(sys_error.New("列车未停稳时,不能变更方向"))
} }
vobc.DirectionBackward = false vobc.DirectionBackward = false
vobc.DirectionForward = false vobc.DirectionForward = false
//var zeroState byte = 0
if direction == request_proto.TrainControl_FORWARD { if direction == request_proto.TrainControl_FORWARD {
vobc.DirectionForward = true vobc.DirectionForward = true
} else if direction == request_proto.TrainControl_BACKWARD { } else if direction == request_proto.TrainControl_BACKWARD {
vobc.DirectionBackward = true vobc.DirectionBackward = true
} }
tcc.DirKey.Val = request.Val tcc.DirKey.Val = request.Val
//tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: zeroState}) return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.HANDLE_BACKWORD, message.IsTrue(vobc.DirectionBackward)}},
tce = append(tce, train_pc_sim.TrainControlEvent{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.HANDLE_BACKWORD, message.IsTrue(vobc.DirectionBackward)}}) {Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.HANDLE_FORWORD, message.IsTrue(vobc.DirectionForward)}}}
tce = append(tce, train_pc_sim.TrainControlEvent{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.HANDLE_FORWORD, message.IsTrue(vobc.DirectionForward)}})
return tce
} }
// 列车驾驶端激活 // 列车驾驶端激活
func trainControlDriverKey(train *state_proto.TrainState, request *request_proto.TrainControl_DriverKeySwitch, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []train_pc_sim.TrainControlEvent { func trainControlDriverKey(train *state_proto.TrainState, request *request_proto.TrainControl_DriverKeySwitch, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
obj, find := findTrainTccGraphicDataKey(tccGraphic, deviceId) obj, find := findTrainTccGraphicDataKey(tccGraphic, deviceId)
if !find { if !find {
slog.Error("未找到对应的驾驶端激活设备deviceId:", deviceId) slog.Error("未找到对应的驾驶端激活设备deviceId:", deviceId)
@ -404,69 +391,63 @@ func trainControlDriverKey(train *state_proto.TrainState, request *request_proto
if addNew { if addNew {
tcc.DriverKey = append(tcc.DriverKey, &state_proto.TrainControlState_DriverKeySwitch{Id: deviceId, Val: request.Val}) tcc.DriverKey = append(tcc.DriverKey, &state_proto.TrainControlState_DriverKeySwitch{Id: deviceId, Val: request.Val})
} }
return []train_pc_sim.TrainControlEvent{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.KEY_STATE, message.IsTrue(request.Val)}}} return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.KEY_STATE, message.IsTrue(request.Val)}}}
} }
// 列车牵引控制 // 列车牵引控制
func trainControlHandle(vobc *state_proto.TrainVobcState, tcc *state_proto.TrainControlState, request *request_proto.TrainControl_PushHandler, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []train_pc_sim.TrainControlEvent { func trainControlHandle(vobc *state_proto.TrainVobcState, tcc *state_proto.TrainControlState, request *request_proto.TrainControl_PushHandler, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
_, find := findTrainTccGraphicDataHandler(tccGraphic, deviceId) _, find := findTrainTccGraphicDataHandler(tccGraphic, deviceId)
if !find { if !find {
slog.Error("未找到对应的牵引制动手柄设备deviceId:", deviceId) slog.Error("未找到对应的牵引制动手柄设备deviceId:", deviceId)
return nil return nil
} }
jjzdBtnGraphic, jjzdOk := findTrainTccGraphicDataButtonByCode(tccGraphic, JJZD)
if !jjzdOk { jjzdBtn := tcc.Buttons[JJZD]
slog.Error("未找到紧急停车摁钮 code:", JJZD)
return nil
}
jjzdBtn, finder := findBtnFromTccByDeviceId(tcc.Buttons, jjzdBtnGraphic.Common.Id)
if !finder {
slog.Error("从列车控制数据中未找到紧急停车摁钮 code:", JJZD, "deviceId:", jjzdBtn.Id)
return nil
}
vobc.TractionStatus = false vobc.TractionStatus = false
vobc.TractionForce = 0 vobc.TractionForce = 0
vobc.BrakingStatus = false vobc.BrakingStatus = false
vobc.BrakeForce = 0 vobc.BrakeForce = 0
vobc.MaintainBrakeStatus = false vobc.MaintainBrakeStatus = false
tce := make([]train_pc_sim.TrainControlEvent, 0)
var zeroState byte = 0 var zeroState byte = 0
var brakeState byte = 0 var brakeState byte = 0
if request.Val > 0 { if request.Val > 0 {
vobc.TractionStatus = true vobc.TractionStatus = true
vobc.TractionForce = int64(request.Val * 180) vobc.TractionForce = int64(request.Val * 180)
} else if request.Val < 0 { } else if request.Val < 0 {
vobc.BrakingStatus = true vobc.BrakingStatus = true
vobc.BrakeForce = int64(-request.Val * 180) vobc.BrakeForce = int64(-request.Val * 180)
vobc.EmergencyBrakingStatus = false vobc.EmergencyBrakingStatus = false
jjzdBtn.Passed = false jjzdBtn.Passed = false
brakeState = 1 brakeState = 1
tce = append(tce, train_pc_sim.TrainControlEvent{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, 1}})
} else { } else {
zeroState = 1 zeroState = 1
} }
tce = append(tce, train_pc_sim.TrainControlEvent{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.HANDLE_TO_ZERO, zeroState}})
tce = append(tce, train_pc_sim.TrainControlEvent{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_BRAKE_STATE, brakeState}})
if tcc.PushHandler == nil { if tcc.PushHandler == nil {
tcc.PushHandler = &state_proto.TrainControlState_PushHandler{Id: deviceId} tcc.PushHandler = &state_proto.TrainControlState_PushHandler{Id: deviceId}
} }
tcc.PushHandler.Val = request.Val tcc.PushHandler.Val = request.Val
return tce
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.HANDLE_TO_ZERO, zeroState}},
{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_BRAKE_STATE, brakeState}},
{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, 1}}}
} }
func (s *VerifySimulation) GetConnTrain2() []*state_proto.TrainState { func (s *VerifySimulation) GetConnTrain2() []*state_proto.TrainState {
return s.findConnTrain2(state_proto.TrainConnState_PC_SIM_A, state_proto.TrainConnState_PC_SIM_B) return s.findConnTrain2(state_proto.TrainConnState_PC_SIM)
} }
func (s *VerifySimulation) findConnTrain2(ct1, ct2 state_proto.TrainConnState_TrainConnType) []*state_proto.TrainState { func (s *VerifySimulation) findConnTrain2(ct1 ...state_proto.TrainConnState_TrainConnType) []*state_proto.TrainState {
var trains = make([]*state_proto.TrainState, 0) var trains = make([]*state_proto.TrainState, 0)
s.Memory.Status.TrainStateMap.Range(func(k, v any) bool { s.Memory.Status.TrainStateMap.Range(func(k, v any) bool {
train := v.(*state_proto.TrainState) train := v.(*state_proto.TrainState)
if train.Show { if train.Show {
connState := train.ConnState connState := train.ConnState
if connState.ConnType == ct1 || connState.ConnType == ct2 { finded := index(ct1, connState.ConnType)
if finded >= 0 {
trains = append(trains, train) trains = append(trains, train)
} }
} }
@ -474,6 +455,16 @@ func (s *VerifySimulation) findConnTrain2(ct1, ct2 state_proto.TrainConnState_Tr
}) })
return trains return trains
} }
func index(arr []state_proto.TrainConnState_TrainConnType, search state_proto.TrainConnState_TrainConnType) int {
for i, v := range arr {
if v == search {
return i
}
}
return -1
}
func (s *VerifySimulation) FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState { func (s *VerifySimulation) FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState {
var findTrain *state_proto.TrainState var findTrain *state_proto.TrainState
s.Memory.Status.TrainStateMap.Range(func(k, v any) bool { s.Memory.Status.TrainStateMap.Range(func(k, v any) bool {
@ -489,65 +480,61 @@ func (s *VerifySimulation) FindConnTrain(ct state_proto.TrainConnState_TrainConn
} }
// 反馈atp输出数字量数据 // 反馈atp输出数字量数据
func (s *VerifySimulation) reportTrainMockInitMsg(train *state_proto.TrainState, data1, data3 byte) { func (s *VerifySimulation) reportTrainMockInitMsg(train *state_proto.TrainState, data1, data3 byte, trainInit bool) bool {
vobc := train.VobcState vobc := train.VobcState
tcc := train.Tcc tcc := train.Tcc
tce := make([]message.TrainPcSimBaseMessage, 0) tce := make([]message.TrainPcSimBaseMessage, 0)
if data1 == 0 { tcc.Line12ConnErr = false
tcc.Line12ConnErr = true initResult := trainInit
slog.Warn("接受atp模拟量数据data[4]=0模拟断开")
return
}
if vobc.Tc1Active || vobc.Tc2Active { if vobc.Tc1Active || vobc.Tc2Active {
if tcc.LineInitTimeStamp12 <= 0 {
tcc.LineInitTimeStamp12 = time.Now().Add(time.Second * 5).Unix()
}
state := message.GetBit(data1, 3) state := message.GetBit(data1, 3)
if state == 1 && tcc.InitCount == 0 { if trainInit {
initData := s.ObtainTrainDigitalMockDataForStatus(train) if data1 == 0 {
tce = append(tce, initData...) tcc.Line12ConnErr = true
} else if tcc.LineInitTimeStamp12 > time.Now().Unix() { slog.Warn("接受atp模拟量数据data[4]=0模拟断开")
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}}) }
//驾驶室激活反馈 if state == 0 {
initData := s.ObtainTrainDigitalMockDataForStatus(train) train_pc_sim.Default().ResetPluseCount(train)
tce = append(tce, initData...) jjzdBtn := tcc.Buttons[JJZD]
tcc.InitCount = tcc.InitCount + 1 ebTce := controlEBBtn(vobc, true, jjzdBtn)
/*if message.GetBit(data3, 3) == 0 { tce = append(tce, ebTce...)
if vobc.Tc1Active || vobc.Tc2Active { }
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.DRIVER_ACTIVE_REPORT, Status: 1}) } else {
} initResult = true
}*/ if tcc.LineInitTimeStamp12 <= 0 {
tcc.LineInitTimeStamp12 = time.Now().Add(time.Second * 6).Unix()
}
if tcc.LineInitTimeStamp12 > time.Now().Unix() {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
initData := s.ObtainTrainDigitalMockDataForStatus(train)
tce = append(tce, initData...)
initResult = false
}
} }
//驾驶室激活反馈
if message.GetBit(data3, 3) == 0 {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DRIVER_ACTIVE_REPORT, 1}})
}
} }
train_pc_sim.Default().SendTrainControlMsg(train, tce) train_pc_sim.Default().SendTrainControlMsg(train, tce)
return initResult
} }
// 4.4.1. 车载输出数字量信息报文内容 // 4.4.1. 车载输出数字量信息报文内容
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(connType state_proto.TrainConnState_TrainConnType, data []byte) { func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(train *state_proto.TrainState, trainInit bool, data []byte) bool {
//slog.Info(fmt.Sprintf("处理车载输出数字量信息报文内容:%v", hex.EncodeToString(data))) /*for i, d := range data {
slog.Info(fmt.Sprintf("atp模拟量分析index:%v ,bin:%2b,trainInit:%v", i, d, trainInit))
}*/
train := s.FindConnTrain(connType) initResult := s.reportTrainMockInitMsg(train, data[4], data[1], trainInit)
if train == nil { vobc := train.VobcState
slog.Error("车载输出数字量未找到连接车载pc仿真的列车") trainPcSimDigitalOutInfoHandleCode7_0(data[4], vobc)
return trainPcSimDigitalOutInfoHandleCode15_8(data[3], vobc)
} trainPcSimDigitalOutInfoHandleCode23_16(data[2], vobc)
if !train.ConnState.Conn { trainPcSimDigitalOutInfoHandleCode31_24(data[1], vobc)
slog.Error("车载输出数字量,,列车未连接车载pc仿真") trainPcSimDigitalOutInfoHandleCode39_32(data[0], vobc)
return return initResult
}
for i, d := range data {
slog.Info(fmt.Sprintf("index:%v ,d :%2b", i, d))
}
s.reportTrainMockInitMsg(train, data[4], data[3])
//vobc := train.VobcState
//trainPcSimDigitalOutInfoHandleCode39_32(data[4], vobc)
//trainPcSimDigitalOutInfoHandleCode31_24(connType, data[3], vobc)
//trainPcSimDigitalOutInfoHandleCode23_16(data[2], vobc)
//trainPcSimDigitalOutInfoHandleCode15_8(data[1], vobc)
//trainPcSimDigitalOutInfoHandleCode7_0(data[0], vobc)
} }
func trainPcSimDigitalOutInfoHandleCode39_32(d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode39_32(d byte, vobc *state_proto.TrainVobcState) {
@ -561,25 +548,29 @@ func trainPcSimDigitalOutInfoHandleCode39_32(d byte, vobc *state_proto.TrainVobc
vobc.StopNotAllBrake = message.IsTrueForByte(message.GetBit(d, 7)) //? 停放制动缓解 vobc.StopNotAllBrake = message.IsTrueForByte(message.GetBit(d, 7)) //? 停放制动缓解
} }
func trainPcSimDigitalOutInfoHandleCode31_24(connType state_proto.TrainConnState_TrainConnType, d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode31_24(d byte, vobc *state_proto.TrainVobcState) {
vobc.AtoOpenLeftDoor = message.IsTrueForByte(message.GetBit(d, 0)) //?//ATO开左门 vobc.AtoOpenLeftDoor = message.IsTrueForByte(message.GetBit(d, 0)) //?//ATO开左门
vobc.AtoOpenRightDoor = message.IsTrueForByte(message.GetBit(d, 1)) //?//ATO开右门 vobc.AtoOpenRightDoor = message.IsTrueForByte(message.GetBit(d, 1)) //?//ATO开右门
vobc.AtoCloseLeftDoor = message.IsTrueForByte(message.GetBit(d, 2)) //?//ATO关左门 vobc.AtoCloseLeftDoor = message.IsTrueForByte(message.GetBit(d, 2)) //?//ATO关左门
if connType == state_proto.TrainConnState_PC_SIM_A { /* if connType == state_proto.TrainConnState_PC_SIM_A {
vobc.Tc1Active = message.IsTrueForByte(message.GetBit(d, 3)) vobc.Tc1Active = message.IsTrueForByte(message.GetBit(d, 3))
} else { } else {
vobc.Tc2Active = message.IsTrueForByte(message.GetBit(d, 3)) vobc.Tc2Active = message.IsTrueForByte(message.GetBit(d, 3))
} }*/
//驾驶室激活
vobc.NoSpeedSigle = message.IsTrueForByte(message.GetBit(d, 4)) //?//零速信号
vobc.Fam = message.IsTrueForByte(message.GetBit(d, 5)) //FAM模式
vobc.Cam = message.IsTrueForByte(message.GetBit(d, 6)) //CAM模式
vobc.TrainStartedLed = message.IsTrueForByte(message.GetBit(d, 7)) //?//列车启动指示灯
vobc.LightDriverActive = message.IsTrueForByte(message.GetBit(d, 3)) //驾驶室激活
vobc.NoSpeedSigle = message.IsTrueForByte(message.GetBit(d, 4)) //?//零速信号
vobc.Fam = message.IsTrueForByte(message.GetBit(d, 5)) //FAM模式
vobc.Cam = message.IsTrueForByte(message.GetBit(d, 6)) //CAM模式
vobc.TrainStartedLed = message.IsTrueForByte(message.GetBit(d, 7)) //?//列车启动指示灯
} }
func trainPcSimDigitalOutInfoHandleCode23_16(d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode23_16(d byte, vobc *state_proto.TrainVobcState) {
vobc.DirectionForward = message.IsTrueForByte(message.GetBit(d, 0)) //列车方向1 vobc.LightDir1 = message.IsTrueForByte(message.GetBit(d, 0)) //列车方向1
vobc.DirectionBackward = message.IsTrueForByte(message.GetBit(d, 1)) //列车方向2 vobc.LightDir2 = message.IsTrueForByte(message.GetBit(d, 1)) //列车方向1
//vobc.DirectionForward = message.IsTrueForByte(message.GetBit(d, 0)) //列车方向1
//vobc.DirectionBackward = message.IsTrueForByte(message.GetBit(d, 1)) //列车方向2
vobc.AtoLazyCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?ATO惰行命令输出 vobc.AtoLazyCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?ATO惰行命令输出
vobc.SleepBtn = message.IsTrueForByte(message.GetBit(d, 3)) //?休眠指令 vobc.SleepBtn = message.IsTrueForByte(message.GetBit(d, 3)) //?休眠指令
vobc.WakeUpBtn = message.IsTrueForByte(message.GetBit(d, 4)) //?唤醒指令 vobc.WakeUpBtn = message.IsTrueForByte(message.GetBit(d, 4)) //?唤醒指令
@ -589,6 +580,7 @@ func trainPcSimDigitalOutInfoHandleCode23_16(d byte, vobc *state_proto.TrainVobc
} }
func trainPcSimDigitalOutInfoHandleCode15_8(d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode15_8(d byte, vobc *state_proto.TrainVobcState) {
vobc.LocalAtpControl = message.IsTrueForByte(message.GetBit(d, 0)) //?本端ATP控车 vobc.LocalAtpControl = message.IsTrueForByte(message.GetBit(d, 0)) //?本端ATP控车
vobc.Ato = message.IsTrueForByte(message.GetBit(d, 1)) //ATO模式 vobc.Ato = message.IsTrueForByte(message.GetBit(d, 1)) //ATO模式
vobc.AtoTractionCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?ATO牵引命令输出 vobc.AtoTractionCommandOut = message.IsTrueForByte(message.GetBit(d, 2)) //?ATO牵引命令输出
@ -604,25 +596,18 @@ func trainPcSimDigitalOutInfoHandleCode7_0(d byte, vobc *state_proto.TrainVobcSt
vobc.TrainDoorOutLed = message.IsTrueForByte(message.GetBit(d, 1)) //? 车门外指示灯 vobc.TrainDoorOutLed = message.IsTrueForByte(message.GetBit(d, 1)) //? 车门外指示灯
vobc.ParkingBrakeStatus = message.IsTrueForByte(message.GetBit(d, 2)) //停放制动施加 vobc.ParkingBrakeStatus = message.IsTrueForByte(message.GetBit(d, 2)) //停放制动施加
vobc.EmergencyBrakingStatus = message.AtpLowPowerByte(message.GetBit(d, 3)) //紧急制动 vobc.EmergencyBrakingStatus = message.AtpLowPowerByte(message.GetBit(d, 3)) //紧急制动
vobc.LeftDoorOpenCommand = message.IsTrueForByte(message.GetBit(d, 4)) //开左门允许 vobc.LeftDoorState = message.IsTrueForByte(message.GetBit(d, 4)) //开左门允许
vobc.RightDoorOpenCommand = message.IsTrueForByte(message.GetBit(d, 5)) //开右门允许 vobc.RightDoorState = message.IsTrueForByte(message.GetBit(d, 5)) //开右门允许
vobc.RightDoorCloseCommand = message.IsTrueForByte(message.GetBit(d, 6)) //关右门 vobc.RightDoorCloseCommand = message.IsTrueForByte(message.GetBit(d, 6)) //关右门
vobc.AllDoorClose = message.IsTrueForByte(message.GetBit(d, 7)) //车门保持关闭 vobc.AllDoorClose = message.IsTrueForByte(message.GetBit(d, 7)) //车门保持关闭
vobc.LightTractionSafetyCircuit = vobc.TractionSafetyCircuit //切牵引
vobc.LightEmergencyBrakingStatus = vobc.EmergencyBrakingStatus //紧急制动
} }
// 4.4.2. 车载输出数字反馈量信息报文内容 // 4.4.2. 车载输出数字反馈量信息报文内容
func (s *VerifySimulation) TrainPcSimDigitalReportHandle(connType state_proto.TrainConnState_TrainConnType, data []byte) { func (s *VerifySimulation) TrainPcSimDigitalReportHandle(train *state_proto.TrainState, data []byte) {
slog.Info(fmt.Sprintf("车载输出数字量反馈信息", hex.EncodeToString(data))) slog.Info(fmt.Sprintf("车载输出数字量反馈信息", hex.EncodeToString(data)))
train := s.FindConnTrain(connType)
if train == nil {
slog.Error("车载输出数字反馈量信息,未找到连接车载pc仿真的列车")
return
}
if !train.ConnState.Conn {
slog.Error("车载输出数字反馈量信息,列车未连接车载pc仿真")
return
}
vobc := train.VobcState vobc := train.VobcState
//buf := bytes.NewBuffer(data) //buf := bytes.NewBuffer(data)
@ -641,9 +626,9 @@ func (s *VerifySimulation) TrainPcSimDigitalReportHandle(connType state_proto.Tr
// 创建/删除列车 // 创建/删除列车
func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState, create bool) error { func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState, create bool) error {
connState := train.ConnState connState := train.ConnState
if connState.ConnType == state_proto.TrainConnState_PC_SIM_A || connState.ConnType == state_proto.TrainConnState_PC_SIM_B { if connState.ConnType == state_proto.TrainConnState_PC_SIM {
crErr := train_pc_sim.Default().CreateOrRemoveTrain(train, create) crErr := train_pc_sim.Default().CreateOrRemoveTrain(train, create)
train_pc_sim.Default().CreateOrRemoveSpeedPLace(train) //train_pc_sim.Default().CreateOrRemoveSpeedPLace(train)
if crErr != nil { if crErr != nil {
return crErr return crErr
} }
@ -674,8 +659,8 @@ func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState, create bool) er
}*/ }*/
// 4.4.3. 车载输出模拟量信息报文内容(0x03) // 4.4.3. 车载输出模拟量信息报文内容(0x03)
func (s *VerifySimulation) TrainPcSimMockInfo(connType state_proto.TrainConnState_TrainConnType, data []byte) { func (s *VerifySimulation) TrainPcSimMockInfo(train *state_proto.TrainState, data []byte) {
train := s.FindConnTrain(connType) /*train := s.FindConnTrain(connType)
if train == nil { if train == nil {
slog.Error("车载输出模拟量,未找到连接车载pc仿真的列车") slog.Error("车载输出模拟量,未找到连接车载pc仿真的列车")
return return
@ -683,31 +668,31 @@ func (s *VerifySimulation) TrainPcSimMockInfo(connType state_proto.TrainConnStat
if !train.ConnState.Conn { if !train.ConnState.Conn {
slog.Error("车载输出模拟量,列车未连接车载pc仿真") slog.Error("车载输出模拟量,列车未连接车载pc仿真")
return return
} }*/
mockData := binary.BigEndian.Uint16(data) mockData := binary.BigEndian.Uint16(data)
train.VobcState.MockInfo = uint32(mockData) train.VobcState.MockInfo = uint32(mockData)
} }
// 4.4.4. 车载输出BTM查询同步帧报文内容0x04 // 4.4.4. 车载输出BTM查询同步帧报文内容0x04
func (s *VerifySimulation) TrainBtmQuery(connType state_proto.TrainConnState_TrainConnType, data []byte) { func (s *VerifySimulation) TrainBtmQuery(train *state_proto.TrainState, data []byte) {
//slog.Info(fmt.Sprintf("收到车载输出BTM查询同步帧报文内容:%v", hex.EncodeToString(data))) //slog.Info(fmt.Sprintf("收到车载输出BTM查询同步帧报文内容:%v", hex.EncodeToString(data)))
if len(data) < 12 { if len(data) < 12 {
slog.Error("列车btm查询报文长度错误:", len(data)) slog.Error("列车btm查询报文长度错误:", len(data))
return return
} }
train := s.FindConnTrain(connType) //train := s.FindConnTrain(connType)
if train.BtmState == nil { if train.BtmState == nil {
slog.Warn("列车暂时未获取到应答器信息") slog.Warn("列车暂时未获取到应答器信息")
return return
} }
if train == nil { /*if train == nil {
slog.Error("车载输出btm查询,未找到连接车载pc仿真的列车") slog.Error("车载输出btm查询,未找到连接车载pc仿真的列车")
return return
} }
if !train.ConnState.Conn { if !train.ConnState.Conn {
slog.Error("车载输出btm查询,列车未连接车载pc仿真") slog.Error("车载输出btm查询,列车未连接车载pc仿真")
return return
} }*/
trainAtm := message.NewCanetFrame2(data, true) trainAtm := message.NewCanetFrame2(data, true)
atpReq := &message.AtpRequestFrame{IsTrainPcSim: true} atpReq := &message.AtpRequestFrame{IsTrainPcSim: true}