Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
72ca826be2
@ -406,7 +406,6 @@ func controlTrain(c *gin.Context) {
|
||||
// @Failure 500 {object} dto.ErrorDto
|
||||
// @Router /api/v1/simulation/train/remove/all [post]
|
||||
func removeAllTrain(c *gin.Context) {
|
||||
|
||||
rt := &dto.RemoveAllTrainRspDto{}
|
||||
if err := c.ShouldBind(&rt); err != nil {
|
||||
panic(sys_error.New("移除所有列车失败,请求参数异常", err))
|
||||
|
@ -160,10 +160,11 @@ type VehiclePCSimConfig2 struct {
|
||||
}
|
||||
|
||||
type VehiclePCSimConfig struct {
|
||||
TrainEnds bool `json:"trainEnds" description:"列车端点A?"`
|
||||
Open bool `json:"open" description:"是否开启"`
|
||||
PcSimIp string `json:"pcSimIp" description:"pc仿真平台通信ip"`
|
||||
PcSimPort uint32 `json:"pcSimPort" description:"pc仿真平台通信端口"`
|
||||
//TrainEnds bool `json:"trainEnds" description:"列车端点A?"`
|
||||
ConfigName string `json:"configName" description:"连接名称"`
|
||||
Open bool `json:"open" description:"是否开启"`
|
||||
PcSimIp string `json:"pcSimIp" description:"pc仿真平台通信ip"`
|
||||
PcSimPort uint32 `json:"pcSimPort" description:"pc仿真平台通信端口"`
|
||||
//LocalTestingPort uint32 `json:"localTestingPort" description:"本地测试端口"`
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ type RunConfigSelectOption 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仿真
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,7 @@ type TrainConnThirdDto struct {
|
||||
SimulationId string `json:"simulationId" form:"simulationId"`
|
||||
Id string `json:"id" form:"id"` // 列车Id
|
||||
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
@ -10,6 +10,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func lowPower(power bool) bool {
|
||||
if power {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// 综合后备盘IBP消息服务
|
||||
func NewTrainControlMs(vs *memory.VerifySimulation, mapId int32) ms_api.MsgTask {
|
||||
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)
|
||||
ts := value.(*state_proto.TrainState)
|
||||
ttcc := ts.Tcc
|
||||
vobc := ts.VobcState
|
||||
lights := make([]*state_proto.TrainControlState_ControlLight, 0)
|
||||
for _, light := range ttcc.LightMaps {
|
||||
lights = append(lights, &state_proto.TrainControlState_ControlLight{Id: light.Id, Val: light.Val})
|
||||
}
|
||||
tcc := &state_proto.TrainControlStateMsg{Buttons: ttcc.Buttons, DriverKey: ttcc.DriverKey, DirKey: ttcc.DirKey, PushHandler: ttcc.PushHandler, Lights: lights}
|
||||
for lightKey, light := range ttcc.LightMaps {
|
||||
switch lightKey {
|
||||
case memory.LIGHT_JJZD:
|
||||
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)
|
||||
if err != nil {
|
||||
slog.Error("发送列车控制mqtt失败", err)
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 4437185ee9fb654dc87cfa6d481e9744b1c43155
|
||||
Subproject commit 2f5d8c3cfdf06ced1a0b0a50f47f9353c441e196
|
@ -1,7 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"joylink.club/bj-rtsts-server/db/dbquery"
|
||||
@ -33,8 +36,31 @@ func ListProjectRunConfigQuery() []*dto.ProjectRunConfigDto {
|
||||
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 {
|
||||
if checkErr := checkRunConfig(dd.ConfigContent); checkErr != nil {
|
||||
panic(checkErr)
|
||||
}
|
||||
|
||||
d := model.ProjectRunConfig{
|
||||
Name: dd.Name,
|
||||
Description: dd.Description,
|
||||
@ -42,6 +68,7 @@ func CreateProjectRunConfig(dd *dto.ProjectRunConfigReqDto) bool {
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
}
|
||||
|
||||
err := dbquery.ProjectRunConfig.Save(&d)
|
||||
if err != nil {
|
||||
panic(sys_error.New("保存失败,数据库错误请联系运维人员", err))
|
||||
@ -75,6 +102,9 @@ func QueryRunConfig(id int32) *dto.ProjectRunConfigDto {
|
||||
|
||||
// 更新项目运行环境
|
||||
func UpdateProjectRunConfig(id int32, dd *dto.ProjectRunConfigReqDto) bool {
|
||||
if checkErr := checkRunConfig(dd.ConfigContent); checkErr != nil {
|
||||
panic(checkErr)
|
||||
}
|
||||
findOldQuery := dbquery.ProjectRunConfig
|
||||
oldD, err := findOldQuery.Where(findOldQuery.ID.Eq(id)).Debug().First()
|
||||
if oldD == nil || err != nil {
|
||||
|
10
third_party/dynamics/dynamics.go
vendored
10
third_party/dynamics/dynamics.go
vendored
@ -93,10 +93,18 @@ func (d *dynamics) updateState(state tpapi.ThirdPartyApiServiceState) {
|
||||
func (d *dynamics) State() tpapi.ThirdPartyApiServiceState {
|
||||
return d.state
|
||||
}
|
||||
|
||||
func (d *dynamics) FindAppendApiService() []tpapi.ThirdPartyApiService {
|
||||
return nil
|
||||
}
|
||||
func (d *dynamics) Name() string {
|
||||
return Name
|
||||
}
|
||||
func (d *dynamics) TrueService() bool {
|
||||
return true
|
||||
}
|
||||
func (d *dynamics) ServiceDesc() string {
|
||||
return Name
|
||||
}
|
||||
|
||||
// 解码列车信息并处理
|
||||
func (d *dynamics) handleDynamicsTrainInfo(b []byte) {
|
||||
|
2
third_party/message/train_pc_sim_message.go
vendored
2
third_party/message/train_pc_sim_message.go
vendored
@ -121,8 +121,6 @@ func AtpLowPowerByte(d byte) bool {
|
||||
|
||||
// 列车速度位置报告
|
||||
type TrainSpeedPlaceReportMsg struct {
|
||||
//列车id
|
||||
TrainId string
|
||||
PulseCount1 uint32
|
||||
PulseCount2 uint32
|
||||
}
|
||||
|
@ -51,7 +51,15 @@ func (s *semiPhysicalTrainImpl) State() tpapi.ThirdPartyApiServiceState {
|
||||
func (s *semiPhysicalTrainImpl) Name() string {
|
||||
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) {
|
||||
s.udpDelayRecorder.RecordInterval()
|
||||
// slog.Debug(fmt.Sprintf("半实物列车控制消息近期消息间隔: %v", s.udpDelayRecorder.GetIntervals()))
|
||||
|
47
third_party/third_party.go
vendored
47
third_party/third_party.go
vendored
@ -40,24 +40,39 @@ func convertServiceName(name string) state_proto.SimulationThirdPartyApiService_
|
||||
func GetRunningServiceStates() *state_proto.SimulationThirdPartyApiService {
|
||||
ss := &state_proto.SimulationThirdPartyApiService{}
|
||||
for _, tpas := range tpapiService {
|
||||
t := convertServiceName(tpas.Name())
|
||||
if t == state_proto.SimulationThirdPartyApiService_Undefined {
|
||||
slog.Error("未知的第三方接口服务类型", "name", tpas.Name())
|
||||
continue
|
||||
}
|
||||
switch tpas.State() {
|
||||
case tpapi.ThirdPartyState_Normal:
|
||||
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,
|
||||
})
|
||||
if tpas.TrueService() {
|
||||
collectServiceState(ss, tpas)
|
||||
} else {
|
||||
trueServices := tpas.FindAppendApiService()
|
||||
if trueServices != nil && len(trueServices) > 0 {
|
||||
for _, trueService := range trueServices {
|
||||
collectServiceState(ss, trueService)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
5
third_party/tpapi/service.go
vendored
5
third_party/tpapi/service.go
vendored
@ -23,6 +23,11 @@ type ThirdPartyApiService interface {
|
||||
Name() string
|
||||
// 服务状态
|
||||
State() ThirdPartyApiServiceState
|
||||
FindAppendApiService() []ThirdPartyApiService
|
||||
//是否真实服务,如果为假,就会调用FindAppendApiService方法
|
||||
TrueService() bool
|
||||
//服务描述
|
||||
ServiceDesc() string
|
||||
}
|
||||
|
||||
// func NewThirdPartyApiService() ThirdPartyApiService {
|
||||
|
@ -1,49 +1,75 @@
|
||||
package train_pc_sim
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"joylink.club/bj-rtsts-server/dto/state_proto"
|
||||
"joylink.club/bj-rtsts-server/third_party/message"
|
||||
"joylink.club/bj-rtsts-server/third_party/tcp"
|
||||
"joylink.club/bj-rtsts-server/third_party/tpapi"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
type trainPcReciverData struct {
|
||||
clientKey string
|
||||
tcpClient *tcp.TcpClient
|
||||
pcSimManage TrainPcSimManage
|
||||
isSleep bool
|
||||
ebCheckIndex uint8
|
||||
ebCheckTime int64
|
||||
type TrainPcReciverData struct {
|
||||
tpapi.ThirdPartyApiService
|
||||
clientKey string
|
||||
tcpClient *tcp.TcpClient
|
||||
pcSimManage TrainPcSimManage
|
||||
trainInit bool
|
||||
state tpapi.ThirdPartyApiServiceState
|
||||
speedPlace *message.TrainSpeedPlaceReportMsg
|
||||
train *state_proto.TrainState
|
||||
}
|
||||
|
||||
func (rd *trainPcReciverData) receiverDataHandle(n int, data []byte) {
|
||||
/*if !rd.isSleep {
|
||||
time.Sleep(time.Second * 5)
|
||||
rd.isSleep = true
|
||||
}*/
|
||||
func (rd *TrainPcReciverData) Name() string {
|
||||
return Name
|
||||
}
|
||||
|
||||
// 服务状态
|
||||
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]
|
||||
hexSourceData := hex.EncodeToString(receiveData)
|
||||
slog.Info(fmt.Sprintf("接受列车激活端:%v pc仿真接收数据:%v", rd.clientKey, hexSourceData))
|
||||
|
||||
trainPcMsgs := message.TrainPcSimDecode(receiveData)
|
||||
connType := state_proto.TrainConnState_PC_SIM_A
|
||||
if rd.clientKey == "B" {
|
||||
connType = state_proto.TrainConnState_PC_SIM_B
|
||||
train := rd.train
|
||||
if train == nil {
|
||||
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 {
|
||||
//slog.Info(fmt.Sprintf("pc仿真接收数据:%v,类型:%X", hexSourceData, baseMsg.Type))
|
||||
switch baseMsg.Type {
|
||||
//case RECIVE_TRAIN_CREATE_REMOVE:
|
||||
// pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0])
|
||||
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:
|
||||
rd.pcSimManage.TrainPcSimDigitalReportHandle(connType, baseMsg.Data)
|
||||
rd.pcSimManage.TrainPcSimDigitalReportHandle(train, baseMsg.Data)
|
||||
case message.RECIVE_TRAIN_QUERY_STATUS:
|
||||
rd.pcSimManage.TrainBtmQuery(connType, baseMsg.Data)
|
||||
rd.pcSimManage.TrainBtmQuery(train, baseMsg.Data)
|
||||
case message.RECIVE_TRAIN_MOCK_DATA:
|
||||
rd.pcSimManage.TrainPcSimMockInfo(connType, baseMsg.Data)
|
||||
rd.pcSimManage.TrainPcSimMockInfo(train, baseMsg.Data)
|
||||
|
||||
//case RECIVE_TRAIN_DOOR_MODE:
|
||||
// pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0])
|
||||
|
320
third_party/train_pc_sim/train_pc_sim.go
vendored
320
third_party/train_pc_sim/train_pc_sim.go
vendored
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"joylink.club/bj-rtsts-server/config"
|
||||
"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/tcp"
|
||||
"joylink.club/bj-rtsts-server/third_party/tpapi"
|
||||
@ -38,15 +39,17 @@ type TrainPcSim interface {
|
||||
SendBaliseData(train *state_proto.TrainState, msgType byte, data []byte)
|
||||
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)
|
||||
// CreateOrRemoveSpeedPLace 创建或删除速度位置信息
|
||||
CreateOrRemoveSpeedPLace(train *state_proto.TrainState)
|
||||
//CreateOrRemoveSpeedPLace(train *state_proto.TrainState)
|
||||
// CreateOrRemoveTrain 创建或删除列车
|
||||
CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error
|
||||
// TrainPluseCount 计算列车脉冲
|
||||
TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32)
|
||||
ResetPluseCount(sta *state_proto.TrainState)
|
||||
//FindAllThirdPartState() []tpapi.ThirdPartyApiService
|
||||
}
|
||||
|
||||
type TrainPcSimManage interface {
|
||||
@ -56,36 +59,25 @@ type TrainPcSimManage interface {
|
||||
//获取列车模拟量数据
|
||||
ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage
|
||||
// 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(connType state_proto.TrainConnState_TrainConnType, data []byte)
|
||||
TrainPcSimDigitalReportHandle(train *state_proto.TrainState, data []byte)
|
||||
FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState
|
||||
// TrainPcSimMockInfo 门模式
|
||||
//TrainDoorModeHandle(state byte)
|
||||
//处理列车pc仿真模拟量数据
|
||||
TrainPcSimMockInfo(connType state_proto.TrainConnState_TrainConnType, data []byte)
|
||||
TrainPcSimMockInfo(train *state_proto.TrainState, data []byte)
|
||||
// TrainBtmQuery 处理列车btm查询
|
||||
TrainBtmQuery(connType state_proto.TrainConnState_TrainConnType, data []byte)
|
||||
TrainBtmQuery(train *state_proto.TrainState, data []byte)
|
||||
}
|
||||
|
||||
const Name = "车载pc仿真"
|
||||
|
||||
func FindTrainPcSimClientKey(t *state_proto.TrainState) string {
|
||||
if t.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_A {
|
||||
return "A"
|
||||
} else if t.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_B {
|
||||
return "B"
|
||||
}
|
||||
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
|
||||
type trainPcSimService struct {
|
||||
state tpapi.ThirdPartyApiServiceState
|
||||
newPcSimclientMap map[string]*TrainPcReciverData
|
||||
cancleContext context.CancelFunc
|
||||
trainPcSimManage TrainPcSimManage
|
||||
//speedPlace *message.TrainSpeedPlaceReportMsg
|
||||
//trainSpeedPlace map[string]*message.TrainSpeedPlaceReportMsg
|
||||
configs []config.VehiclePCSimConfig
|
||||
}
|
||||
|
||||
var (
|
||||
@ -101,14 +93,56 @@ func Default() TrainPcSim {
|
||||
}
|
||||
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 {
|
||||
s1 := speedMeter * 1000
|
||||
pluseCountData := s1 * 200 / math.Pi / float32(wheelDiameter)
|
||||
|
||||
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()
|
||||
initLock.Lock()
|
||||
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()
|
||||
initLock.Lock()
|
||||
sta.PluseCount.PulseCount1 = 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() {
|
||||
trains := d.trainPcSimManage.GetConnTrain2()
|
||||
for _, train := range trains {
|
||||
d.CreateOrRemoveTrain(train, false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) newCloseConn(clientKey string) {
|
||||
@ -162,28 +181,22 @@ func (d *trainPcSimService) newCloseConn(clientKey string) {
|
||||
if rd != nil {
|
||||
rd.tcpClient.Close()
|
||||
rd.tcpClient = nil
|
||||
delete(d.newPcSimclientMap, clientKey)
|
||||
rd.train = nil
|
||||
rd.speedPlace = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) findConfig(tcChar 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))
|
||||
}
|
||||
func (d *trainPcSimService) findConfig(configName string) (*config.VehiclePCSimConfig, error) {
|
||||
|
||||
for _, cfg := range d.configs {
|
||||
if cfg.Open && cfg.TrainEnds == configFlag {
|
||||
if cfg.Open && cfg.ConfigName == configName {
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
}
|
||||
return nil, fmt.Errorf("未找到对应的车载pc连接配置")
|
||||
}
|
||||
func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
|
||||
|
||||
/*func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
|
||||
|
||||
go func() {
|
||||
for {
|
||||
@ -202,10 +215,9 @@ func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
|
||||
d.newCloseConn(clientKey)
|
||||
continue
|
||||
}
|
||||
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
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() {
|
||||
d.newCloseConn(clientKey)
|
||||
@ -216,33 +228,42 @@ func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}*/
|
||||
|
||||
func (d *trainPcSimService) initConn(clientKey string) {
|
||||
func (d *trainPcSimService) initConn(clientKey string) error {
|
||||
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
if rd != nil && rd.tcpClient != nil && rd.tcpClient.IsConning() {
|
||||
rd.ebCheckIndex = 0
|
||||
rd.isSleep = false
|
||||
return
|
||||
return nil
|
||||
} else {
|
||||
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 {
|
||||
slog.Error(fmt.Sprintf("车载pc连接失败 clientKey:%v,error:%v", clientKey, err.Error()))
|
||||
d.updateState(tpapi.ThirdPartyState_Broken)
|
||||
connErrMsg := fmt.Sprintf("车载pc连接失败 clientKey:%v", clientKey)
|
||||
slog.Error(connErrMsg, err.Error())
|
||||
rd.updateState(tpapi.ThirdPartyState_Broken)
|
||||
return sys_error.New(connErrMsg, err)
|
||||
} else {
|
||||
rd.tcpClient = client2
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
||||
|
||||
configs := pcSimManage.GetTrainPcSimConfig()
|
||||
d.newPcSimclientMap = make(map[string]*trainPcReciverData)
|
||||
d.newPcSimclientMap = make(map[string]*TrainPcReciverData)
|
||||
if len(configs) <= 0 {
|
||||
slog.Info("车载pc仿真配置未开启")
|
||||
return
|
||||
@ -251,44 +272,55 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
||||
for _, c := range configs {
|
||||
if !c.Open {
|
||||
closedCount++
|
||||
} else {
|
||||
ck := c.ConfigName
|
||||
pcReciver := &TrainPcReciverData{clientKey: ck, pcSimManage: pcSimManage}
|
||||
pcReciver.updateState(tpapi.ThirdPartyState_Closed)
|
||||
d.newPcSimclientMap[ck] = pcReciver
|
||||
}
|
||||
}
|
||||
|
||||
if closedCount == len(configs) {
|
||||
slog.Error("车载pc仿真配置未开启")
|
||||
return
|
||||
}
|
||||
//third_party.AppendService(d.findAllThirdPartState())
|
||||
d.configs = configs
|
||||
ctx, ctxFun := context.WithCancel(context.Background())
|
||||
d.cancleContext = ctxFun
|
||||
d.trainPcSimManage = pcSimManage
|
||||
d.connTrainPcSim(ctx)
|
||||
d.updateState(tpapi.ThirdPartyState_Normal)
|
||||
//d.connTrainPcSim(ctx)
|
||||
go d.sendTrainLocationAndSpeedTask(ctx)
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) Stop() {
|
||||
|
||||
d.updateState(tpapi.ThirdPartyState_Closed)
|
||||
for _, data := range d.newPcSimclientMap {
|
||||
data.updateState(tpapi.ThirdPartyState_Closed)
|
||||
}
|
||||
if d.cancleContext != nil {
|
||||
d.cancleContext()
|
||||
d.cancleContext = nil
|
||||
}
|
||||
|
||||
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{}
|
||||
d.speedPlace = &message.TrainSpeedPlaceReportMsg{TrainId: train.Id}
|
||||
} else {
|
||||
train.PluseCount = nil
|
||||
d.speedPlace = nil
|
||||
|
||||
/*
|
||||
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{}
|
||||
d.speedPlace = &message.TrainSpeedPlaceReportMsg{TrainId: train.Id}
|
||||
} else {
|
||||
train.PluseCount = nil
|
||||
d.speedPlace = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error {
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
d.initConn(clientKey)
|
||||
clientKey := FindTrainPcSimClientKey2(train)
|
||||
err := d.initConn(clientKey)
|
||||
if err != nil {
|
||||
d.newCloseConn(clientKey)
|
||||
return err
|
||||
}
|
||||
data := []byte{message.FLAG_CAMMAND_REMOVE_TRAIN}
|
||||
if isCreate {
|
||||
data[0] = message.FLAG_CAMMAND_CREATE_TRAIN
|
||||
@ -303,14 +335,19 @@ func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, i
|
||||
if initTrainErr != nil {
|
||||
return initTrainErr
|
||||
}
|
||||
|
||||
}
|
||||
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)
|
||||
sendMsg := make([]byte, 0)
|
||||
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)
|
||||
msgs = append(msgs, tmpMsgs...)
|
||||
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, trains.Encode()...)
|
||||
|
||||
hexData := hex.EncodeToString(sendMsg)
|
||||
slog.Info(fmt.Sprintf("发送列车初始化消息:%v", hexData))
|
||||
rd.tcpClient.Send(sendMsg)
|
||||
@ -348,21 +384,26 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
||||
}
|
||||
trains := d.trainPcSimManage.GetConnTrain2()
|
||||
for _, train := range trains {
|
||||
if train.Tcc.Line12ConnErr {
|
||||
d.updateState(tpapi.ThirdPartyState_Broken)
|
||||
continue
|
||||
}
|
||||
if train.ConnState.Conn && train.PluseCount != nil {
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
trainClient, trainDataErr := d.findTrainConn(train)
|
||||
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
|
||||
d.speedPlace.ParsePulseCount1(s1, s2)
|
||||
data := d.speedPlace.Encode(train.TrainRunUp, s1, s2)
|
||||
trainClient.speedPlace.ParsePulseCount1(s1, s2)
|
||||
data := trainClient.speedPlace.Encode(train.TrainRunUp, s1, s2)
|
||||
bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data}
|
||||
d.TrainPluseCountReset(train)
|
||||
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)))
|
||||
err := rd.tcpClient.Send(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 := trainClient.tcpClient.Send(dataCode)
|
||||
if err != nil {
|
||||
slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode)))
|
||||
}
|
||||
@ -376,9 +417,14 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
||||
|
||||
// SendDriverActive Deprecated 发送驾驶激活
|
||||
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
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
|
||||
defulatBuf := make([]byte, 0)
|
||||
msg := &message.TrainPcSimBaseMessage{Data: defulatBuf}
|
||||
if train.TrainRunUp {
|
||||
@ -405,18 +451,22 @@ func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
|
||||
msgs = append(msgs, msg.Encode()...)
|
||||
hexData := hex.EncodeToString(msgs)
|
||||
slog.Info(fmt.Sprintf("发送驾驶激活列车id:%v,数据:%v", train.Id, hexData))
|
||||
err := rd.tcpClient.Send(msgs)
|
||||
err := trainClient.tcpClient.Send(msgs)
|
||||
|
||||
if err != nil {
|
||||
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) {
|
||||
trainClient, trainDataErr := d.findTrainConn(train)
|
||||
if trainDataErr != nil {
|
||||
slog.Error(fmt.Sprintf("发送列车牵引知道失败,未找到对应的列车id:%v", train.Id))
|
||||
return
|
||||
}
|
||||
tc := train.ConnState
|
||||
if tc.Conn {
|
||||
|
||||
vobc := train.VobcState
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
|
||||
msg := &message.TrainPcSimBaseMessage{}
|
||||
newTraction := vobc.TractionForce
|
||||
@ -443,16 +493,20 @@ func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, t
|
||||
msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD
|
||||
}
|
||||
da := msg.Encode()
|
||||
slog.Info("发送列车手柄消息", "clientKey", clientKey, "msg", hex.EncodeToString(da))
|
||||
err := rd.tcpClient.Send(da)
|
||||
slog.Info("发送列车手柄消息", "msg", hex.EncodeToString(da))
|
||||
err := trainClient.tcpClient.Send(da)
|
||||
//err := client.Send(da)
|
||||
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) {
|
||||
|
||||
trainClient, trainDataErr := d.findTrainConn(train)
|
||||
if trainDataErr != nil {
|
||||
slog.Error(fmt.Sprintf("发送列车方向失败,未找到列车连接,trainId:%s", train.Id))
|
||||
return
|
||||
}
|
||||
baseMsgs := make([]*message.TrainPcSimBaseMessage, 0)
|
||||
if !trainForward && !trainBackward {
|
||||
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 {
|
||||
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_BACKWARD})
|
||||
}
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
|
||||
for _, msg := range baseMsgs {
|
||||
da := msg.Encode()
|
||||
slog.Info(fmt.Sprintf("发送列车方向列车:%v ,数据:%v", train.Id, hex.EncodeToString(da)))
|
||||
err := rd.tcpClient.Send(da)
|
||||
err := trainClient.tcpClient.Send(da)
|
||||
|
||||
if err != nil {
|
||||
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) {
|
||||
trainClient, trainDataErr := d.findTrainConn(train)
|
||||
if trainDataErr != nil {
|
||||
slog.Error(fmt.Sprintf("发送列车PC仿真应答器信息失败2,未找到列车连接,trainId:%v", train.Id))
|
||||
return
|
||||
}
|
||||
for _, hexData := range data {
|
||||
dd, _ := hex.DecodeString(hexData)
|
||||
msg := &message.TrainPcSimBaseMessage{Type: msgType, Data: dd}
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
|
||||
da := msg.Encode()
|
||||
//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 {
|
||||
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) {
|
||||
trainClient, trainDataErr := d.findTrainConn(train)
|
||||
if trainDataErr != nil {
|
||||
slog.Error(fmt.Sprintf("发送列车PC仿真应答器信息失败,未找到列车连接,trainId:%v", train.Id))
|
||||
return
|
||||
}
|
||||
msg := &message.TrainPcSimBaseMessage{}
|
||||
msg.Type = msgType
|
||||
msg.Data = data
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
|
||||
da := msg.Encode()
|
||||
//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 {
|
||||
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 {
|
||||
return
|
||||
}
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
trainClient, trainDataErr := d.findTrainConn(train)
|
||||
if trainDataErr != nil {
|
||||
slog.Error("")
|
||||
return
|
||||
}
|
||||
|
||||
msgs := make([]byte, 0)
|
||||
for _, event := range events {
|
||||
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)
|
||||
slog.Info(fmt.Sprintf("列车数字量信息发送数据:%v", hexCode))
|
||||
err := rd.tcpClient.Send(msgs)
|
||||
err := trainClient.tcpClient.Send(msgs)
|
||||
if err != nil {
|
||||
slog.Error(fmt.Sprintf("列车数字量信息发送失败,数据:%v", hexCode))
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
func (d *trainPcSimService) SendTrainControlMsg(train *state_proto.TrainState, baseMessage []message.TrainPcSimBaseMessage) {
|
||||
if len(baseMessage) <= 0 {
|
||||
return
|
||||
}
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
trainClient, trainDataErr := d.findTrainConn(train)
|
||||
if trainDataErr != nil {
|
||||
slog.Error(fmt.Sprintf("发送列车控制信息失败,无连接,列车Id:%v", train.Id))
|
||||
return
|
||||
}
|
||||
|
||||
for _, msg := range baseMessage {
|
||||
d.sendData(rd.tcpClient, msg.Encode())
|
||||
d.sendData(trainClient.tcpClient, msg.Encode())
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,14 +13,36 @@ const (
|
||||
QHFXKZ = "QHFXKZ" //驾驶方向
|
||||
QYSB = "QYSB" //牵引制动手柄
|
||||
|
||||
ATPQCKG = "ATPQCKG" //ATP切除开关
|
||||
KZM = "KZM" //开左门按钮
|
||||
GZM = "GZM" //关左门按钮
|
||||
GYM = "GYM" //关右门按钮
|
||||
ZAWTGJC = "ZAWTGJC" //障碍物/脱轨检测
|
||||
ZDZGZ = "ZDZGZ" //制动重故障
|
||||
ATPSD = "ATPSD" //ATP上电按钮
|
||||
MSQR = "MSQR" //模式确认
|
||||
ATPQCKG = "ATPQCKG" //ATP切除开关
|
||||
KZM = "KZM" //开左门按钮
|
||||
GZM = "GZM" //关左门按钮
|
||||
GYM = "GYM" //关右门按钮
|
||||
KYM = "KYM" //开右门
|
||||
ZAWTGJC = "ZAWTGJC" //障碍物/脱轨检测
|
||||
ZDZGZ = "ZDZGZ" //制动重故障
|
||||
ATPSD = "ATPSD" //ATP上电按钮
|
||||
MSQR = "MSQR" //模式确认
|
||||
ZF = "ZF"
|
||||
QZMYX = "QZMYX" //强制门允许
|
||||
MSJJ = "MSJJ" //模式降级
|
||||
MSSJ = "MSSJ" // 模式升级
|
||||
HX = "HX" //唤醒按钮
|
||||
JX = "JX" //检修按钮
|
||||
XM = "XM" //休眠按钮
|
||||
LIGHT_JJZD = JJZD
|
||||
LIGHT_QQY = "QQY" //切牵引指示灯
|
||||
LIGHT_JSSJH = "JSSJH" // 驾驶室激活
|
||||
LIGHT_TFZDHJ = "TFZDHJ" //停放制动缓解
|
||||
LIGHT_QYYX = "QYYX" // 牵引有效
|
||||
LIGHT_ZDYX = "ZDYX" //制动有效
|
||||
LIGHT_TFZDSJ = "TFZDSJ" //停放制动施加
|
||||
LIGHT_CYZD = "CYZD" //常用制动
|
||||
LIGHT_ZDGL = "ZDGL" //制动隔离
|
||||
LIGHT_LSXH = "LSXH" //零速信号
|
||||
LIGHT_ZMYX = "ZMYX" //左门允许
|
||||
LIGHT_YMYX = "YMYX" //右门允许
|
||||
LIGHT_ZFZSD = "ZFZSD" //折返指示灯
|
||||
LIGHT_BDATPKC = "BDATPKC" //本段atp控车
|
||||
)
|
||||
|
||||
// 获取列车控制图形数据
|
||||
@ -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 {
|
||||
tcc.LightMaps = make(map[string]*state_proto.TrainControlState_ControlLight)
|
||||
for _, light := range tccGI.TccLights {
|
||||
tcc.LightMaps[light.Code] = &state_proto.TrainControlState_ControlLight{Id: light.Common.Id, Val: light.InitialState}
|
||||
}
|
||||
|
||||
btns := make([]*state_proto.TrainControlState_ControlButton, 0)
|
||||
btns := make(map[string]*state_proto.TrainControlState_ControlButton, 0)
|
||||
for _, b := range tccGI.TccButtons {
|
||||
btn := &state_proto.TrainControlState_ControlButton{Id: b.Common.Id, Passed: false}
|
||||
switch b.Code {
|
||||
case ATPQCKG, GZM, GYM, ZAWTGJC, ZDZGZ, ATPSD, MSQR:
|
||||
btn.Passed = true
|
||||
}
|
||||
btns = append(btns, btn)
|
||||
btns[b.Code] = btn
|
||||
//btns = append(btns, btn)
|
||||
}
|
||||
tcc.Buttons = btns
|
||||
for _, b := range tccGI.TccHandles {
|
||||
|
@ -150,12 +150,11 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
|
||||
//列车连接 半实物或车载pc仿真
|
||||
allTrainMap.Range(func(k, v any) bool {
|
||||
tmpTrain := v.(*state_proto.TrainState)
|
||||
if tmpTrain.ConnState.Conn {
|
||||
connState := tmpTrain.ConnState
|
||||
if connState.Conn {
|
||||
connTypeName := "半实物"
|
||||
if tmpTrain.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_A {
|
||||
connTypeName = "车载pc仿真-A"
|
||||
} else if tmpTrain.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_B {
|
||||
connTypeName = "车载pc仿真-B"
|
||||
if connState.ConnType == state_proto.TrainConnState_PC_SIM && connState.TypeName == ct.TypeName {
|
||||
connTypeName = fmt.Sprintf("车载pc仿真-%v", ct.TypeName)
|
||||
}
|
||||
panic(sys_error.New(fmt.Sprintf("列车[%s]已经连接 [%v],此列车无法连接", k, connTypeName)))
|
||||
return false
|
||||
@ -165,7 +164,8 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
|
||||
}
|
||||
train.ConnState.Conn = true
|
||||
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
|
||||
err := TrainPcSimConnOrRemoveHandle(train, true)
|
||||
if err != nil {
|
||||
@ -180,6 +180,7 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
|
||||
|
||||
// 列车断开三方连接
|
||||
func TrainUnConn(vs *VerifySimulation, trainId string) {
|
||||
|
||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||
data, ok := allTrainMap.Load(trainId)
|
||||
if !ok {
|
||||
@ -190,8 +191,11 @@ func TrainUnConn(vs *VerifySimulation, trainId string) {
|
||||
if err != nil {
|
||||
panic(sys_error.New("未连接车载PC仿真,无法断开连接"))
|
||||
}
|
||||
train.ConnState.Conn = false
|
||||
train.ConnState.ConnType = state_proto.TrainConnState_NONE
|
||||
defer func() {
|
||||
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,
|
||||
trainEndsB dto.ConfigTrainEnds) {
|
||||
@ -438,12 +442,16 @@ func removeTrain(vs *VerifySimulation, trainId string, train *state_proto.TrainS
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if train.ConnState.Conn {
|
||||
train.ConnState.Conn = false
|
||||
thirdConn := train.ConnState
|
||||
if thirdConn.Conn {
|
||||
thirdConn.Conn = false
|
||||
err = TrainPcSimConnOrRemoveHandle(train, false)
|
||||
if err != nil {
|
||||
train.ConnState.Conn = true
|
||||
return err
|
||||
} else {
|
||||
thirdConn.ConnType = state_proto.TrainConnState_NONE
|
||||
thirdConn.TypeName = ""
|
||||
}
|
||||
}
|
||||
if train.VobcState != nil {
|
||||
@ -454,7 +462,7 @@ func removeTrain(vs *VerifySimulation, trainId string, train *state_proto.TrainS
|
||||
vobc.BrakeForce = DEFAULT_BRAKE_FORCE
|
||||
}
|
||||
train.Show = false
|
||||
train.ConnState.ConnType = state_proto.TrainConnState_NONE
|
||||
|
||||
return fi.RemoveTrainFromWorld(vs.World, trainId)
|
||||
}
|
||||
|
||||
|
@ -532,16 +532,12 @@ func (s *VerifySimulation) CollectInterlockRelayInfo(code string) *message.Inter
|
||||
func (s *VerifySimulation) FindTrainConnTypes() []dto.TrainConnTypeConfigDto {
|
||||
typeConfig := make([]dto.TrainConnTypeConfigDto, 0)
|
||||
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 {
|
||||
dto := dto.TrainConnTypeConfigDto{ConnType: state_proto.TrainConnState_PC_SIM_A}
|
||||
if !pcSim.TrainEnds {
|
||||
dd := &dto
|
||||
dd.ConnType = state_proto.TrainConnState_PC_SIM_B
|
||||
}
|
||||
typeConfig = append(typeConfig, dto)
|
||||
|
||||
typeConfig = append(typeConfig, dto.TrainConnTypeConfigDto{TypeName: pcSim.ConfigName, ConnType: state_proto.TrainConnState_PC_SIM})
|
||||
}
|
||||
/* if s.runConfig.PcSimConfig.Open {
|
||||
typeConfig = append(typeConfig, dto.TrainConnTypeConfigDto{ConnType: state_proto.TrainConnState_PC_SIM})
|
||||
|
@ -38,14 +38,15 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
|
||||
sta := data.(*state_proto.TrainState)
|
||||
vobc := sta.VobcState
|
||||
tcc := sta.Tcc
|
||||
var tce []train_pc_sim.TrainControlEvent = nil
|
||||
|
||||
var baseMsg []message.TrainPcSimBaseMessage = nil
|
||||
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 {
|
||||
tce = trainControlDriverKey(sta, ct.DriverKey, ct.DeviceId, tccGraphicData)
|
||||
baseMsg = trainControlDriverKey(sta, ct.DriverKey, ct.DeviceId, tccGraphicData)
|
||||
train_pc_sim.Default().SendDriverActive(sta)
|
||||
} 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
|
||||
train_pc_sim.Default().SendTrainDirection(sta, sta.VobcState.DirectionForward, sta.VobcState.DirectionBackward)
|
||||
} else if ct.ControlType == request_proto.TrainControl_HANDLER {
|
||||
@ -55,13 +56,13 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
|
||||
oldTraction := sta.VobcState.TractionForce
|
||||
oldBrakeForce := sta.VobcState.BrakeForce
|
||||
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)
|
||||
}
|
||||
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 {
|
||||
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 {
|
||||
vobc.TractionStatus = false
|
||||
@ -70,62 +71,56 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
|
||||
if vobc.EmergencyBrakingStatus {
|
||||
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 {
|
||||
train_pc_sim.Default().PublishTrainControlEvent(sta, tce)
|
||||
if sta.ConnState.Conn && (sta.ConnState.ConnType == state_proto.TrainConnState_PC_SIM) && baseMsg != nil {
|
||||
train_pc_sim.Default().SendTrainControlMsg(sta, baseMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func findBtnFromTccByDeviceId(tcc []*state_proto.TrainControlState_ControlButton, deviceId uint32) (*state_proto.TrainControlState_ControlButton, bool) {
|
||||
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 {
|
||||
func trainControlButton(vobc *state_proto.TrainVobcState, buttonMap map[string]*state_proto.TrainControlState_ControlButton, deviceId uint32, active bool, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
|
||||
|
||||
if graphicBtn, ok := findTrainTccGraphicDataButton(tccGraphic, deviceId); ok {
|
||||
btn, btnOk := findBtnFromTccByDeviceId(tcc, deviceId)
|
||||
if btnOk == false {
|
||||
btn := buttonMap[graphicBtn.Code]
|
||||
if btn == nil {
|
||||
slog.Error("未找到对应的车载摁钮code:", graphicBtn.Code, "设备id:", deviceId)
|
||||
return nil
|
||||
}
|
||||
|
||||
switch graphicBtn.Code {
|
||||
case "JJZD": // 紧急制动
|
||||
case JJZD: // 紧急制动
|
||||
return controlEBBtn(vobc, active, btn)
|
||||
case "ATPQCKG": //atp切除
|
||||
case ATPQCKG: //atp切除
|
||||
return controlAtpBtn(vobc, active, btn)
|
||||
/* case "WBJJZDFK": //外部紧急制动反馈
|
||||
return controlOutEbReportBtn(vobc, active, btn)*/
|
||||
case "KZM": //开左门按钮
|
||||
case KZM: //开左门按钮
|
||||
return controlLeftDoorBtn(vobc, active, btn)
|
||||
case "GZM": //关左门按钮
|
||||
case GZM: //关左门按钮
|
||||
return controlLeftDoorCloseBtn(vobc, active, btn)
|
||||
case "KYM": //开右门按钮
|
||||
case KYM: //开右门按钮
|
||||
return controlRightDoorBtn(vobc, active, btn)
|
||||
case "GYM": //关右门按钮
|
||||
case GYM: //关右门按钮
|
||||
return controlRightDoorCloseBtn(vobc, active, btn)
|
||||
case "ZF": //折返按钮
|
||||
case ZF: //折返按钮
|
||||
return controlReverseBtn(vobc, active, btn)
|
||||
case "QZMYX": //强制门允许
|
||||
case QZMYX: //强制门允许
|
||||
return controlDoorAllowBtn(vobc, active, btn)
|
||||
case "MSJJ": //模式降级按钮
|
||||
case MSJJ: //模式降级按钮
|
||||
return controlModeDownBtn(vobc, active, btn)
|
||||
case "MSSJ": //模式升级按钮
|
||||
case MSSJ: //模式升级按钮
|
||||
return controlModeUpBtn(vobc, active, btn)
|
||||
case "MSQR": //模式确认按钮
|
||||
case MSQR: //模式确认按钮
|
||||
return controlModeConfirmBtn(vobc, active, btn)
|
||||
case "ZAWTGJC": //障碍物/脱轨检测
|
||||
case ZAWTGJC: //障碍物/脱轨检测
|
||||
return controlObstacleDetectionBtn(vobc, active, btn)
|
||||
case "ZDZGZ": //制动重故障
|
||||
case ZDZGZ: //制动重故障
|
||||
return controlBrakeHeavyBtn(vobc, active, btn)
|
||||
case "ATPSD": //ATP上电按钮
|
||||
case ATPSD: //ATP上电按钮
|
||||
return controlAtpPowerBtn(vobc, active, btn)
|
||||
case "HX": //唤醒按钮
|
||||
case HX: //唤醒按钮
|
||||
return controlWakeUpBtn(vobc, active, btn)
|
||||
case "JX": //检修按钮
|
||||
case JX: //检修按钮
|
||||
return controlOverhaulBtn(vobc, active, btn)
|
||||
case "XM": //休眠按钮
|
||||
case XM: //休眠按钮
|
||||
return controlSleepBtn(vobc, active, btn)
|
||||
default:
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
@ -144,77 +139,70 @@ func controlEBBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *state_p
|
||||
vobc.EmergencyBrakingStatus = true
|
||||
vobc.TractionForce = 0
|
||||
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 切除
|
||||
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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
vobc.AtpCutSwitch = active
|
||||
tccBtn.Passed = active
|
||||
return []train_pc_sim.TrainControlEvent{{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}}} //紧急制动
|
||||
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.ATP_CUT, 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
vobc.LeftDoorOpenCommand = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
vobc.LeftDoorCloseCommand = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
vobc.RightDoorOpenCommand = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
vobc.RightDoorCloseCommand = 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
|
||||
if active {
|
||||
status = 1
|
||||
@ -222,121 +210,126 @@ func controlReverseBtn(vobc *state_proto.TrainVobcState, active bool, tccBtn *st
|
||||
//vobc.RightDoorCloseCommand = active
|
||||
vobc.TurnbackStatus = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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上电按钮
|
||||
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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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
|
||||
if active {
|
||||
status = 1
|
||||
}
|
||||
tccBtn.Passed = 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)
|
||||
if !find {
|
||||
slog.Error("未找到对应的列车方向键deviceId:", deviceId)
|
||||
@ -345,30 +338,24 @@ func trainControlDirKey(trainSpeed int32, vobc *state_proto.TrainVobcState, tcc
|
||||
if tcc.DirKey == nil {
|
||||
tcc.DirKey = &state_proto.TrainControlState_DirectionKeySwitch{Id: deviceId}
|
||||
}
|
||||
tce := make([]train_pc_sim.TrainControlEvent, 0)
|
||||
direction := request_proto.TrainControl_Direction(request.Val)
|
||||
if trainSpeed > 0 {
|
||||
panic(sys_error.New("列车未停稳时,不能变更方向"))
|
||||
}
|
||||
vobc.DirectionBackward = false
|
||||
vobc.DirectionForward = false
|
||||
//var zeroState byte = 0
|
||||
if direction == request_proto.TrainControl_FORWARD {
|
||||
vobc.DirectionForward = true
|
||||
|
||||
} else if direction == request_proto.TrainControl_BACKWARD {
|
||||
vobc.DirectionBackward = true
|
||||
}
|
||||
tcc.DirKey.Val = request.Val
|
||||
//tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: zeroState})
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{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_FORWORD, message.IsTrue(vobc.DirectionForward)}})
|
||||
|
||||
return tce
|
||||
return []message.TrainPcSimBaseMessage{{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)}}}
|
||||
}
|
||||
|
||||
// 列车驾驶端激活
|
||||
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)
|
||||
if !find {
|
||||
slog.Error("未找到对应的驾驶端激活设备deviceId:", deviceId)
|
||||
@ -404,69 +391,63 @@ func trainControlDriverKey(train *state_proto.TrainState, request *request_proto
|
||||
if addNew {
|
||||
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)
|
||||
if !find {
|
||||
slog.Error("未找到对应的牵引制动手柄设备deviceId:", deviceId)
|
||||
return nil
|
||||
}
|
||||
jjzdBtnGraphic, jjzdOk := findTrainTccGraphicDataButtonByCode(tccGraphic, JJZD)
|
||||
if !jjzdOk {
|
||||
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
|
||||
}
|
||||
|
||||
jjzdBtn := tcc.Buttons[JJZD]
|
||||
vobc.TractionStatus = false
|
||||
vobc.TractionForce = 0
|
||||
vobc.BrakingStatus = false
|
||||
vobc.BrakeForce = 0
|
||||
vobc.MaintainBrakeStatus = false
|
||||
tce := make([]train_pc_sim.TrainControlEvent, 0)
|
||||
|
||||
var zeroState byte = 0
|
||||
var brakeState byte = 0
|
||||
|
||||
if request.Val > 0 {
|
||||
vobc.TractionStatus = true
|
||||
vobc.TractionForce = int64(request.Val * 180)
|
||||
|
||||
} else if request.Val < 0 {
|
||||
vobc.BrakingStatus = true
|
||||
vobc.BrakeForce = int64(-request.Val * 180)
|
||||
vobc.EmergencyBrakingStatus = false
|
||||
jjzdBtn.Passed = false
|
||||
brakeState = 1
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, 1}})
|
||||
} else {
|
||||
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 {
|
||||
tcc.PushHandler = &state_proto.TrainControlState_PushHandler{Id: deviceId}
|
||||
}
|
||||
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 {
|
||||
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)
|
||||
s.Memory.Status.TrainStateMap.Range(func(k, v any) bool {
|
||||
train := v.(*state_proto.TrainState)
|
||||
if train.Show {
|
||||
connState := train.ConnState
|
||||
if connState.ConnType == ct1 || connState.ConnType == ct2 {
|
||||
finded := index(ct1, connState.ConnType)
|
||||
if finded >= 0 {
|
||||
trains = append(trains, train)
|
||||
}
|
||||
}
|
||||
@ -474,6 +455,16 @@ func (s *VerifySimulation) findConnTrain2(ct1, ct2 state_proto.TrainConnState_Tr
|
||||
})
|
||||
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 {
|
||||
var findTrain *state_proto.TrainState
|
||||
s.Memory.Status.TrainStateMap.Range(func(k, v any) bool {
|
||||
@ -489,65 +480,61 @@ func (s *VerifySimulation) FindConnTrain(ct state_proto.TrainConnState_TrainConn
|
||||
}
|
||||
|
||||
// 反馈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
|
||||
tcc := train.Tcc
|
||||
tce := make([]message.TrainPcSimBaseMessage, 0)
|
||||
if data1 == 0 {
|
||||
tcc.Line12ConnErr = true
|
||||
slog.Warn("接受atp模拟量数据,data[4]=0,模拟断开")
|
||||
return
|
||||
}
|
||||
tcc.Line12ConnErr = false
|
||||
initResult := trainInit
|
||||
if vobc.Tc1Active || vobc.Tc2Active {
|
||||
if tcc.LineInitTimeStamp12 <= 0 {
|
||||
tcc.LineInitTimeStamp12 = time.Now().Add(time.Second * 5).Unix()
|
||||
}
|
||||
state := message.GetBit(data1, 3)
|
||||
if state == 1 && tcc.InitCount == 0 {
|
||||
initData := s.ObtainTrainDigitalMockDataForStatus(train)
|
||||
tce = append(tce, initData...)
|
||||
} else 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...)
|
||||
tcc.InitCount = tcc.InitCount + 1
|
||||
/*if message.GetBit(data3, 3) == 0 {
|
||||
if vobc.Tc1Active || vobc.Tc2Active {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.DRIVER_ACTIVE_REPORT, Status: 1})
|
||||
}
|
||||
}*/
|
||||
if trainInit {
|
||||
if data1 == 0 {
|
||||
tcc.Line12ConnErr = true
|
||||
slog.Warn("接受atp模拟量数据,data[4]=0,模拟断开")
|
||||
}
|
||||
if state == 0 {
|
||||
train_pc_sim.Default().ResetPluseCount(train)
|
||||
jjzdBtn := tcc.Buttons[JJZD]
|
||||
ebTce := controlEBBtn(vobc, true, jjzdBtn)
|
||||
tce = append(tce, ebTce...)
|
||||
}
|
||||
} 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)
|
||||
return initResult
|
||||
}
|
||||
|
||||
// 4.4.1. 车载输出数字量信息报文内容
|
||||
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(connType state_proto.TrainConnState_TrainConnType, data []byte) {
|
||||
//slog.Info(fmt.Sprintf("处理车载输出数字量信息报文内容:%v", hex.EncodeToString(data)))
|
||||
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(train *state_proto.TrainState, trainInit bool, data []byte) bool {
|
||||
/*for i, d := range data {
|
||||
slog.Info(fmt.Sprintf("atp模拟量分析index:%v ,bin:%2b,trainInit:%v", i, d, trainInit))
|
||||
}*/
|
||||
|
||||
train := s.FindConnTrain(connType)
|
||||
if train == nil {
|
||||
slog.Error("车载输出数字量,未找到连接车载pc仿真的列车")
|
||||
return
|
||||
}
|
||||
if !train.ConnState.Conn {
|
||||
slog.Error("车载输出数字量,,列车未连接车载pc仿真")
|
||||
return
|
||||
}
|
||||
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)
|
||||
initResult := s.reportTrainMockInitMsg(train, data[4], data[1], trainInit)
|
||||
vobc := train.VobcState
|
||||
trainPcSimDigitalOutInfoHandleCode7_0(data[4], vobc)
|
||||
trainPcSimDigitalOutInfoHandleCode15_8(data[3], vobc)
|
||||
trainPcSimDigitalOutInfoHandleCode23_16(data[2], vobc)
|
||||
trainPcSimDigitalOutInfoHandleCode31_24(data[1], vobc)
|
||||
trainPcSimDigitalOutInfoHandleCode39_32(data[0], vobc)
|
||||
return initResult
|
||||
|
||||
}
|
||||
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)) //? 停放制动缓解
|
||||
|
||||
}
|
||||
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.AtoOpenRightDoor = message.IsTrueForByte(message.GetBit(d, 1)) //?//ATO开右门
|
||||
vobc.AtoCloseLeftDoor = message.IsTrueForByte(message.GetBit(d, 2)) //?//ATO关左门
|
||||
if connType == state_proto.TrainConnState_PC_SIM_A {
|
||||
vobc.Tc1Active = message.IsTrueForByte(message.GetBit(d, 3))
|
||||
} else {
|
||||
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)) //?//列车启动指示灯
|
||||
/* if connType == state_proto.TrainConnState_PC_SIM_A {
|
||||
vobc.Tc1Active = message.IsTrueForByte(message.GetBit(d, 3))
|
||||
} else {
|
||||
vobc.Tc2Active = message.IsTrueForByte(message.GetBit(d, 3))
|
||||
}*/
|
||||
|
||||
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) {
|
||||
vobc.DirectionForward = message.IsTrueForByte(message.GetBit(d, 0)) //列车方向1
|
||||
vobc.DirectionBackward = message.IsTrueForByte(message.GetBit(d, 1)) //列车方向2
|
||||
vobc.LightDir1 = message.IsTrueForByte(message.GetBit(d, 0)) //列车方向1
|
||||
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.SleepBtn = message.IsTrueForByte(message.GetBit(d, 3)) //?休眠指令
|
||||
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) {
|
||||
|
||||
vobc.LocalAtpControl = message.IsTrueForByte(message.GetBit(d, 0)) //?本端ATP控车
|
||||
vobc.Ato = message.IsTrueForByte(message.GetBit(d, 1)) //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.ParkingBrakeStatus = message.IsTrueForByte(message.GetBit(d, 2)) //停放制动施加
|
||||
vobc.EmergencyBrakingStatus = message.AtpLowPowerByte(message.GetBit(d, 3)) //紧急制动
|
||||
vobc.LeftDoorOpenCommand = message.IsTrueForByte(message.GetBit(d, 4)) //开左门允许
|
||||
vobc.RightDoorOpenCommand = message.IsTrueForByte(message.GetBit(d, 5)) //开右门允许
|
||||
vobc.LeftDoorState = message.IsTrueForByte(message.GetBit(d, 4)) //开左门允许
|
||||
vobc.RightDoorState = message.IsTrueForByte(message.GetBit(d, 5)) //开右门允许
|
||||
vobc.RightDoorCloseCommand = message.IsTrueForByte(message.GetBit(d, 6)) //关右门
|
||||
vobc.AllDoorClose = message.IsTrueForByte(message.GetBit(d, 7)) //车门保持关闭
|
||||
|
||||
vobc.LightTractionSafetyCircuit = vobc.TractionSafetyCircuit //切牵引
|
||||
vobc.LightEmergencyBrakingStatus = vobc.EmergencyBrakingStatus //紧急制动
|
||||
}
|
||||
|
||||
// 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)))
|
||||
train := s.FindConnTrain(connType)
|
||||
if train == nil {
|
||||
slog.Error("车载输出数字反馈量信息,未找到连接车载pc仿真的列车")
|
||||
return
|
||||
}
|
||||
if !train.ConnState.Conn {
|
||||
slog.Error("车载输出数字反馈量信息,列车未连接车载pc仿真")
|
||||
return
|
||||
}
|
||||
|
||||
vobc := train.VobcState
|
||||
|
||||
//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 {
|
||||
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)
|
||||
train_pc_sim.Default().CreateOrRemoveSpeedPLace(train)
|
||||
//train_pc_sim.Default().CreateOrRemoveSpeedPLace(train)
|
||||
if crErr != nil {
|
||||
return crErr
|
||||
}
|
||||
@ -674,8 +659,8 @@ func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState, create bool) er
|
||||
}*/
|
||||
|
||||
// 4.4.3. 车载输出模拟量信息报文内容(0x03)
|
||||
func (s *VerifySimulation) TrainPcSimMockInfo(connType state_proto.TrainConnState_TrainConnType, data []byte) {
|
||||
train := s.FindConnTrain(connType)
|
||||
func (s *VerifySimulation) TrainPcSimMockInfo(train *state_proto.TrainState, data []byte) {
|
||||
/*train := s.FindConnTrain(connType)
|
||||
if train == nil {
|
||||
slog.Error("车载输出模拟量,未找到连接车载pc仿真的列车")
|
||||
return
|
||||
@ -683,31 +668,31 @@ func (s *VerifySimulation) TrainPcSimMockInfo(connType state_proto.TrainConnStat
|
||||
if !train.ConnState.Conn {
|
||||
slog.Error("车载输出模拟量,列车未连接车载pc仿真")
|
||||
return
|
||||
}
|
||||
}*/
|
||||
mockData := binary.BigEndian.Uint16(data)
|
||||
train.VobcState.MockInfo = uint32(mockData)
|
||||
}
|
||||
|
||||
// 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)))
|
||||
if len(data) < 12 {
|
||||
slog.Error("列车btm查询报文长度错误:", len(data))
|
||||
return
|
||||
}
|
||||
train := s.FindConnTrain(connType)
|
||||
//train := s.FindConnTrain(connType)
|
||||
if train.BtmState == nil {
|
||||
slog.Warn("列车暂时未获取到应答器信息")
|
||||
return
|
||||
}
|
||||
if train == nil {
|
||||
/*if train == nil {
|
||||
slog.Error("车载输出btm查询,未找到连接车载pc仿真的列车")
|
||||
return
|
||||
}
|
||||
if !train.ConnState.Conn {
|
||||
slog.Error("车载输出btm查询,列车未连接车载pc仿真")
|
||||
return
|
||||
}
|
||||
}*/
|
||||
|
||||
trainAtm := message.NewCanetFrame2(data, true)
|
||||
atpReq := &message.AtpRequestFrame{IsTrainPcSim: true}
|
||||
|
Loading…
Reference in New Issue
Block a user