2024-07-04 09:26:37 +08:00
|
|
|
|
package train_pc_sim
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/message"
|
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/tcp"
|
2024-07-19 15:24:28 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/tpapi"
|
2024-07-11 14:58:34 +08:00
|
|
|
|
"log/slog"
|
2024-07-04 09:26:37 +08:00
|
|
|
|
)
|
|
|
|
|
|
2024-07-19 15:24:28 +08:00
|
|
|
|
type TrainPcReciverData struct {
|
|
|
|
|
tpapi.ThirdPartyApiService
|
|
|
|
|
clientKey string
|
|
|
|
|
tcpClient *tcp.TcpClient
|
|
|
|
|
pcSimManage TrainPcSimManage
|
|
|
|
|
trainInit bool
|
|
|
|
|
state tpapi.ThirdPartyApiServiceState
|
|
|
|
|
speedPlace *message.TrainSpeedPlaceReportMsg
|
|
|
|
|
train *state_proto.TrainState
|
2024-07-04 09:26:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-19 15:24:28 +08:00
|
|
|
|
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) {
|
|
|
|
|
|
2024-07-04 09:26:37 +08:00
|
|
|
|
receiveData := data[:n]
|
2024-07-19 15:24:28 +08:00
|
|
|
|
|
2024-07-04 09:26:37 +08:00
|
|
|
|
trainPcMsgs := message.TrainPcSimDecode(receiveData)
|
2024-07-19 15:24:28 +08:00
|
|
|
|
train := rd.train
|
|
|
|
|
if train == nil {
|
|
|
|
|
slog.Error("车载输出数字量,未找到连接车载pc仿真的列车")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if !train.ConnState.Conn {
|
|
|
|
|
slog.Error("车载输出数字量,,列车未连接车载pc仿真")
|
|
|
|
|
return
|
2024-07-04 09:26:37 +08:00
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
//hexSourceData := hex.EncodeToString(receiveData)
|
|
|
|
|
//slog.Info(fmt.Sprintf("接受列车激活端:%v pc仿真接收数据:%v", rd.clientKey, hexSourceData))
|
2024-07-04 09:26:37 +08:00
|
|
|
|
for _, baseMsg := range trainPcMsgs {
|
2024-07-15 15:00:33 +08:00
|
|
|
|
//slog.Info(fmt.Sprintf("pc仿真接收数据:%v,类型:%X", hexSourceData, baseMsg.Type))
|
2024-07-04 09:26:37 +08:00
|
|
|
|
switch baseMsg.Type {
|
|
|
|
|
//case RECIVE_TRAIN_CREATE_REMOVE:
|
|
|
|
|
// pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0])
|
2024-07-11 14:58:34 +08:00
|
|
|
|
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR:
|
2024-07-19 15:24:28 +08:00
|
|
|
|
initResult := rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(train, rd.trainInit, baseMsg.Data)
|
|
|
|
|
rd.trainInit = initResult
|
2024-07-04 09:26:37 +08:00
|
|
|
|
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK:
|
2024-07-19 15:24:28 +08:00
|
|
|
|
rd.pcSimManage.TrainPcSimDigitalReportHandle(train, baseMsg.Data)
|
2024-07-04 09:26:37 +08:00
|
|
|
|
case message.RECIVE_TRAIN_QUERY_STATUS:
|
2024-07-19 15:24:28 +08:00
|
|
|
|
rd.pcSimManage.TrainBtmQuery(train, baseMsg.Data)
|
2024-07-04 09:26:37 +08:00
|
|
|
|
case message.RECIVE_TRAIN_MOCK_DATA:
|
2024-07-19 15:24:28 +08:00
|
|
|
|
rd.pcSimManage.TrainPcSimMockInfo(train, baseMsg.Data)
|
2024-07-04 09:26:37 +08:00
|
|
|
|
|
|
|
|
|
//case RECIVE_TRAIN_DOOR_MODE:
|
|
|
|
|
// pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|