Compare commits

..

3 Commits

Author SHA1 Message Date
tiger_zhou
7fc152ad67 Merge remote-tracking branch 'origin/local-test' into local-test
All checks were successful
local-test分支打包构建docker并发布运行 / Docker-Build (push) Successful in 3m18s
2024-04-29 14:22:03 +08:00
3c018ddad3 【修改】成工院本地部署配置 2024-04-29 14:21:16 +08:00
tiger_zhou
4b77a87785 仿真列车连接调整 2024-04-29 13:58:14 +08:00
5 changed files with 49 additions and 39 deletions

View File

@ -50,7 +50,7 @@ func StartTcpClient(rAddr string, handler func(n int, data []byte), readErr func
return &TcpClient{conn: conn, ctx: ctxFun}, nil return &TcpClient{conn: conn, ctx: ctxFun}, nil
} }
func (c *TcpClient) Close() { func (c *TcpClient) Close() {
if c.conn != nil { if c != nil && c.conn != nil {
slog.Info(fmt.Sprintf("TCP客户端[rAddr:%s]关闭连接", c.conn.RemoteAddr().String())) slog.Info(fmt.Sprintf("TCP客户端[rAddr:%s]关闭连接", c.conn.RemoteAddr().String()))
c.ctx() c.ctx()
c.conn.Close() c.conn.Close()

View File

@ -23,39 +23,39 @@ type TrainControlEvent struct {
var FireTrainControlEventType = ecs.NewEventType[TrainControlEvent]() var FireTrainControlEventType = ecs.NewEventType[TrainControlEvent]()
type TrainPcSim interface { type TrainPcSim interface {
Start(wd ecs.World, pcSimManage TrainPcSimManage) tpapi.ThirdPartyApiService
Start(pcSimManage TrainPcSimManage)
Stop() Stop()
//发送驾驶端激活 // SendDriverActive 发送驾驶端激活
SendDriverActive(tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState) SendDriverActive(tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState)
//发送牵引制动手柄 // SendHandleSwitch 发送牵引制动手柄
SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState) SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, tc *state_proto.TrainConnState, vobc *state_proto.TrainVobcState)
//列车运行方向 // SendTrainDirection 列车运行方向
//因文档说明不清楚,在调用的时候目前是注释状态,现场调试可能会用到 //因文档说明不清楚,在调用的时候目前是注释状态,现场调试可能会用到
SendTrainDirection(trainForward, trainBackward bool) SendTrainDirection(trainForward, trainBackward bool)
//发送应答器信息数据 //发送应答器信息数据
SendBaliseData(msgType uint16, data []byte) SendBaliseData(msgType uint16, data []byte)
//发布列车控制的相关事件 //发布列车控制的相关事件
PublishTrainControlEvent(world ecs.World, events []TrainControlEvent) PublishTrainControlEvent(events []TrainControlEvent)
// CreateOrRemoveSpeedPLace 创建或删除速度位置信息
CreateOrRemoveSpeedPLace(train *state_proto.TrainState) CreateOrRemoveSpeedPLace(train *state_proto.TrainState)
// CreateOrRemoveTrain 创建或删除列车
CreateOrRemoveTrain(msgType byte, data []byte) error CreateOrRemoveTrain(msgType byte, data []byte) error
tpapi.ThirdPartyApiService
} }
type TrainPcSimManage interface { type TrainPcSimManage interface {
GetTrainPcSimConfig() config.VehiclePCSimConfig GetTrainPcSimConfig() config.VehiclePCSimConfig
GetConnTrain() *state_proto.TrainState GetConnTrain() *state_proto.TrainState
//4.4.1. 车载输出数字量信息报文内容 // TrainPcSimDigitalOutInfoHandle 4.4.1. 车载输出数字量信息报文内容
TrainPcSimDigitalOutInfoHandle(data []byte) TrainPcSimDigitalOutInfoHandle(data []byte)
//4.4.2. 车载输出数字反馈量信息报文内容 // TrainPcSimDigitalReportHandle 4.4.2. 车载输出数字反馈量信息报文内容
TrainPcSimDigitalReportHandle(data []byte) TrainPcSimDigitalReportHandle(data []byte)
//门模式 // TrainPcSimMockInfo 门模式
//TrainDoorModeHandle(state byte) //TrainDoorModeHandle(state byte)
//处理列车pc仿真模拟量数据 //处理列车pc仿真模拟量数据
TrainPcSimMockInfo(data []byte) TrainPcSimMockInfo(data []byte)
//处理列车btm查询 // TrainBtmQuery 处理列车btm查询
TrainBtmQuery(data []byte) TrainBtmQuery(data []byte)
} }
@ -111,6 +111,7 @@ func (d *trainPcSimService) connTrainPcSim() {
return return
default: default:
} }
d.pcSimClient.Close()
client, err := tcp.StartTcpClient(fmt.Sprintf("%v:%v", d.config.PcSimIp, d.config.PcSimPort), d.reivceData, d.readError) client, err := tcp.StartTcpClient(fmt.Sprintf("%v:%v", d.config.PcSimIp, d.config.PcSimPort), d.reivceData, d.readError)
if err != nil { if err != nil {
reconnIndex++ reconnIndex++
@ -128,7 +129,7 @@ func (d *trainPcSimService) connTrainPcSim() {
}() }()
} }
func (d *trainPcSimService) Start(wd ecs.World, pcSimManage TrainPcSimManage) { func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
config := pcSimManage.GetTrainPcSimConfig() config := pcSimManage.GetTrainPcSimConfig()
if config.PcSimIp == "" || !config.Open { if config.PcSimIp == "" || !config.Open {
slog.Info("车载pc仿真配置未开启") slog.Info("车载pc仿真配置未开启")
@ -266,14 +267,16 @@ func (d *trainPcSimService) SendBaliseData(msgType uint16, data []byte) {
d.pcSimClient.Send(msg.Encode()) d.pcSimClient.Send(msg.Encode())
} }
func (d *trainPcSimService) trainControlEventHandle(w ecs.World, event TrainControlEvent) { /*
func (d *trainPcSimService) trainControlEventHandle( event TrainControlEvent) {
msg := &message.TrainPcSimBaseMessage{} msg := &message.TrainPcSimBaseMessage{}
msg.Type = SENDER_TRAIN_OUTR_INFO msg.Type = SENDER_TRAIN_OUTR_INFO
data := []byte{event.Command, event.Status} data := []byte{event.Command, event.Status}
msg.Data = data msg.Data = data
d.pcSimClient.Send(msg.Encode()) d.pcSimClient.Send(msg.Encode())
} }
func (d *trainPcSimService) PublishTrainControlEvent(world ecs.World, events []TrainControlEvent) { */
func (d *trainPcSimService) PublishTrainControlEvent(events []TrainControlEvent) {
if len(events) <= 0 { if len(events) <= 0 {
slog.Warn("发布事件数量为空") slog.Warn("发布事件数量为空")
return return

View File

@ -150,15 +150,18 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
return true return true
}) })
} }
train.ConnState.Conn = true
train.ConnState.ConnType = ct.ConnType
if ct.ConnType == state_proto.TrainConnState_PC_SIM { if ct.ConnType == state_proto.TrainConnState_PC_SIM {
err := TrainPcSimConnOrRemoveHandle(train) err := TrainPcSimConnOrRemoveHandle(train)
if err != nil { if err != nil {
panic(sys_error.New("连接车载PC仿真失败")) train.ConnState.Conn = false
train.ConnState.ConnType = state_proto.TrainConnState_NONE
panic(sys_error.New(err.Error()))
} }
train_pc_sim.Default().SendDriverActive(train.ConnState, train.VobcState) train_pc_sim.Default().SendDriverActive(train.ConnState, train.VobcState)
} }
train.ConnState.Conn = true
train.ConnState.ConnType = ct.ConnType
} }
// 列车断开三方连接 // 列车断开三方连接
@ -405,12 +408,6 @@ func RemoveAllTrain(vs *VerifySimulation) {
allTrainMap.Range(func(k any, t any) bool { allTrainMap.Range(func(k any, t any) bool {
id := k.(string) id := k.(string)
RemoveTrainState(vs, id) RemoveTrainState(vs, id)
//train := t.(*state_proto.TrainState)
//err := removeTrain(vs, train.Id, train)
//if err != nil {
// slog.Error("列车id:", train.Id, "移除失败,原因:", err.Error())
//}
//allTrainMap.Store(train.Id, t)
return true return true
}) })
} }
@ -423,10 +420,17 @@ func removeTrain(vs *VerifySimulation, trainId string, train *state_proto.TrainS
if err != nil { if err != nil {
return err return err
} }
train.Show = false
if train.ConnState.Conn { if train.ConnState.Conn {
train.ConnState.ConnType = state_proto.TrainConnState_NONE train.ConnState.Conn = false
err = TrainPcSimConnOrRemoveHandle(train)
if err != nil {
train.ConnState.Conn = true
return err
} }
}
train.Show = false
train.ConnState.ConnType = state_proto.TrainConnState_NONE
return fi.RemoveTrainFromWorld(vs.World, trainId) return fi.RemoveTrainFromWorld(vs.World, trainId)
} }

View File

@ -54,7 +54,7 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
} }
if sta.ConnState.Conn && sta.ConnState.ConnType == state_proto.TrainConnState_PC_SIM && tce != nil { if sta.ConnState.Conn && sta.ConnState.ConnType == state_proto.TrainConnState_PC_SIM && tce != nil {
train_pc_sim.Default().PublishTrainControlEvent(s.World, tce) train_pc_sim.Default().PublishTrainControlEvent(tce)
} }
} }
@ -386,15 +386,18 @@ func (s *VerifySimulation) TrainPcSimDigitalReportHandle(data []byte) {
// 创建/删除列车 // 创建/删除列车
func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState) error { func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState) error {
var data byte = 0x01 var data byte = 0x01
if train.ConnState.Conn == false { if train.ConnState.Conn == false {
data = 0x00 data = 0x00
} }
if train.ConnState.ConnType == state_proto.TrainConnState_PC_SIM {
crErr := train_pc_sim.Default().CreateOrRemoveTrain(train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE, []byte{data}) crErr := train_pc_sim.Default().CreateOrRemoveTrain(train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE, []byte{data})
if crErr != nil { if crErr != nil {
return crErr return crErr
} }
train_pc_sim.Default().CreateOrRemoveSpeedPLace(train) train_pc_sim.Default().CreateOrRemoveSpeedPLace(train)
}
return nil return nil
} }

View File

@ -137,7 +137,7 @@ func runThirdParty(s *memory.VerifySimulation) error {
radar.Default().Start(s) radar.Default().Start(s)
//列车加速计发送vobc //列车加速计发送vobc
acc.Default().Start(s) acc.Default().Start(s)
train_pc_sim.Default().Start(s.World, s) train_pc_sim.Default().Start(s)
return nil return nil
} }