rts-sim-testing-service/third_party/train_pc_sim/train_pc_receive_handler.go
thesai 54e2d88db3
Some checks failed
local-test分支打包构建docker并发布运行 / Docker-Build (push) Failing after 5m19s
[新增]11号线联锁、12号线联锁、12号计轴第三方通信服务的状态采集
2024-10-09 17:38:52 +08:00

103 lines
3.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package train_pc_sim
import (
"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 {
tpapi.ThirdPartyApiService
clientKey string
tcpClient *tcp.TcpClient
pcSimManage TrainPcSimManage
state tpapi.ThirdPartyApiServiceState
speedPlace *message.TrainSpeedPlaceReportMsg
train *state_proto.TrainState
success bool
//aPort bool //列车钥匙激活端口 true = 1端 false = 2端
RealTrainPort state_proto.TrainState_TrainPort
LineInitTimeStamp int64
TrainConnInitComplate bool
ConnErr bool
}
func (rd *TrainPcReciverData) ConnError() bool {
connState := tpapi.ThirdPartyState_Normal
if rd.ConnErr {
connState = tpapi.ThirdPartyState_Broken
}
rd.updateState(connState)
return rd.ConnErr
}
func (rd *TrainPcReciverData) Type() state_proto.SimulationThirdPartyApiService_Type {
return state_proto.SimulationThirdPartyApiService_Train_pc_sim
}
// 服务状态
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 {
if d.RealTrainPort == state_proto.TrainState_PORT_A {
return fmt.Sprintf("%v-A端", d.clientKey)
} else if d.RealTrainPort == state_proto.TrainState_PORT_B {
return fmt.Sprintf("%v-B端", d.clientKey)
} else {
return fmt.Sprintf("%v-位置服务端口", d.clientKey)
}
}
func (rd *TrainPcReciverData) receiverDataHandle(n int, data []byte) {
train := rd.train
//vs := train.VobcState
if train == nil {
slog.Error("车载输出数字量未找到连接车载pc仿真的列车")
return
}
if !train.ConnState.Conn {
slog.Error("车载输出数字量,,列车未连接车载pc仿真")
return
}
//a := rd.tcpClient.RemoteInfo()
//slog.Info(fmt.Sprintf("nw:%v ,add:%v", a.Network(), a.String()), rd.aPort)
//slog.Info(fmt.Sprintf("接受atp信息 列车:%v 列车端口:%v ,钥匙1:%v,钥匙2:%v", train.Id, rd.aPort, train.VobcState.Tc1Active, train.VobcState.Tc2Active))
receiveData := data[:n]
trainPcMsgs := message.TrainPcSimDecode(receiveData)
for _, baseMsg := range trainPcMsgs {
switch baseMsg.Type {
//case RECIVE_TRAIN_CREATE_REMOVE:
// pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0])
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR:
rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(rd, train, baseMsg.Data)
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK:
rd.pcSimManage.TrainPcSimDigitalReportHandle(train, baseMsg.Data)
case message.RECIVE_TRAIN_QUERY_STATUS:
rd.pcSimManage.TrainBtmQuery2(train, baseMsg.Data, rd.RealTrainPort)
//case message.RECIVE_TRAIN_MOCK_DATA:
// rd.pcSimManage.TrainPcSimMockInfo(train, baseMsg.Data)
//case RECIVE_TRAIN_DOOR_MODE:
// pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0])
}
}
}