rts-sim-testing-service/third_party/train_pc_sim/train_pc_receive_handler.go

54 lines
1.7 KiB
Go
Raw Normal View History

package train_pc_sim
import (
2024-07-11 14:58:34 +08:00
"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"
2024-07-11 14:58:34 +08:00
"log/slog"
)
type trainPcReciverData struct {
clientKey string
tcpClient *tcp.TcpClient
pcSimManage TrainPcSimManage
isSleep bool
ebCheckIndex uint8
ebCheckTime int64
}
func (rd *trainPcReciverData) receiverDataHandle(n int, data []byte) {
/*if !rd.isSleep {
2024-07-11 14:58:34 +08:00
time.Sleep(time.Second * 5)
rd.isSleep = true
}*/
receiveData := data[:n]
2024-07-11 14:58:34 +08:00
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
}
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])
2024-07-11 14:58:34 +08:00
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR:
rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(connType, baseMsg.Data)
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK:
rd.pcSimManage.TrainPcSimDigitalReportHandle(connType, baseMsg.Data)
case message.RECIVE_TRAIN_QUERY_STATUS:
rd.pcSimManage.TrainBtmQuery(connType, baseMsg.Data)
case message.RECIVE_TRAIN_MOCK_DATA:
rd.pcSimManage.TrainPcSimMockInfo(connType, baseMsg.Data)
//case RECIVE_TRAIN_DOOR_MODE:
// pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0])
}
}
}