2024-04-02 18:20:10 +08:00
|
|
|
|
package train_pc_sim
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-05-29 15:19:04 +08:00
|
|
|
|
"encoding/hex"
|
2024-04-02 18:20:10 +08:00
|
|
|
|
"fmt"
|
|
|
|
|
"joylink.club/bj-rtsts-server/config"
|
|
|
|
|
"joylink.club/bj-rtsts-server/dto/state_proto"
|
2024-07-19 15:24:28 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/sys_error"
|
2024-04-09 08:55:33 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/message"
|
2024-04-02 18:20:10 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/tcp"
|
2024-04-13 09:40:25 +08:00
|
|
|
|
"joylink.club/bj-rtsts-server/third_party/tpapi"
|
2024-04-02 18:20:10 +08:00
|
|
|
|
"log/slog"
|
2024-07-11 14:58:34 +08:00
|
|
|
|
"math"
|
2024-04-02 18:20:10 +08:00
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2024-09-10 15:37:40 +08:00
|
|
|
|
//type TrainControlEvent struct {
|
|
|
|
|
// Type byte
|
|
|
|
|
// Data []byte
|
|
|
|
|
//}
|
2024-04-09 08:55:33 +08:00
|
|
|
|
|
2024-05-24 09:00:43 +08:00
|
|
|
|
//var FireTrainControlEventType = ecs.NewEventType[TrainControlEvent]()
|
2024-04-09 08:55:33 +08:00
|
|
|
|
|
2024-04-02 18:20:10 +08:00
|
|
|
|
type TrainPcSim interface {
|
2024-04-29 13:58:14 +08:00
|
|
|
|
tpapi.ThirdPartyApiService
|
|
|
|
|
Start(pcSimManage TrainPcSimManage)
|
2024-04-02 18:20:10 +08:00
|
|
|
|
Stop()
|
2024-06-27 10:37:52 +08:00
|
|
|
|
|
|
|
|
|
// SendDriverActive Deprecated 发送驾驶端激活
|
2024-09-10 18:55:15 +08:00
|
|
|
|
//SendDriverActive(train *state_proto.TrainState)
|
2024-04-29 13:58:14 +08:00
|
|
|
|
// SendHandleSwitch 发送牵引制动手柄
|
2024-05-24 09:00:43 +08:00
|
|
|
|
SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState)
|
2024-04-29 13:58:14 +08:00
|
|
|
|
// SendTrainDirection 列车运行方向
|
2024-04-16 17:26:37 +08:00
|
|
|
|
//因文档说明不清楚,在调用的时候目前是注释状态,现场调试可能会用到
|
2024-05-24 09:00:43 +08:00
|
|
|
|
SendTrainDirection(train *state_proto.TrainState, trainForward, trainBackward bool)
|
2024-04-09 08:55:33 +08:00
|
|
|
|
//发送应答器信息数据
|
2024-09-11 21:19:42 +08:00
|
|
|
|
|
|
|
|
|
SendBaliseData2(train *state_proto.TrainState, trainClientPort state_proto.TrainState_TrainPort, msgType byte, data []byte)
|
2024-08-05 16:32:21 +08:00
|
|
|
|
|
2024-04-09 08:55:33 +08:00
|
|
|
|
//发布列车控制的相关事件
|
2024-07-19 15:24:28 +08:00
|
|
|
|
//PublishTrainControlEvent(train *state_proto.TrainState, events []TrainControlEvent)
|
2024-07-15 15:00:33 +08:00
|
|
|
|
|
2024-09-11 21:19:42 +08:00
|
|
|
|
SendTrainControlMsg2(train *state_proto.TrainState, baseMessage []message.TrainPcSimBaseMessage, trainClientPort state_proto.TrainState_TrainPort)
|
2024-04-29 13:58:14 +08:00
|
|
|
|
// CreateOrRemoveSpeedPLace 创建或删除速度位置信息
|
2024-07-19 15:24:28 +08:00
|
|
|
|
//CreateOrRemoveSpeedPLace(train *state_proto.TrainState)
|
2024-04-29 13:58:14 +08:00
|
|
|
|
// CreateOrRemoveTrain 创建或删除列车
|
2024-06-27 10:37:52 +08:00
|
|
|
|
CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error
|
2024-07-15 15:00:33 +08:00
|
|
|
|
// TrainPluseCount 计算列车脉冲
|
2024-07-11 14:58:34 +08:00
|
|
|
|
TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32)
|
2024-04-02 18:20:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TrainPcSimManage interface {
|
2024-05-24 09:00:43 +08:00
|
|
|
|
GetTrainPcSimConfig() []config.VehiclePCSimConfig
|
|
|
|
|
//GetConnTrain() *state_proto.TrainState
|
|
|
|
|
GetConnTrain2() []*state_proto.TrainState
|
2024-06-27 10:37:52 +08:00
|
|
|
|
//获取列车模拟量数据
|
|
|
|
|
ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage
|
2024-04-29 13:58:14 +08:00
|
|
|
|
// TrainPcSimDigitalOutInfoHandle 4.4.1. 车载输出数字量信息报文内容
|
2024-09-11 21:19:42 +08:00
|
|
|
|
TrainPcSimDigitalOutInfoHandle(pc *TrainPcReciverData, train *state_proto.TrainState, data []byte) bool
|
2024-04-29 13:58:14 +08:00
|
|
|
|
// TrainPcSimDigitalReportHandle 4.4.2. 车载输出数字反馈量信息报文内容
|
2024-07-19 15:24:28 +08:00
|
|
|
|
TrainPcSimDigitalReportHandle(train *state_proto.TrainState, data []byte)
|
2024-07-04 09:26:37 +08:00
|
|
|
|
FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState
|
2024-04-29 13:58:14 +08:00
|
|
|
|
// TrainPcSimMockInfo 门模式
|
2024-04-13 09:40:25 +08:00
|
|
|
|
//TrainDoorModeHandle(state byte)
|
2024-04-09 08:55:33 +08:00
|
|
|
|
//处理列车pc仿真模拟量数据
|
2024-07-19 15:24:28 +08:00
|
|
|
|
TrainPcSimMockInfo(train *state_proto.TrainState, data []byte)
|
2024-04-29 13:58:14 +08:00
|
|
|
|
// TrainBtmQuery 处理列车btm查询
|
2024-08-15 14:54:16 +08:00
|
|
|
|
|
2024-09-11 21:19:42 +08:00
|
|
|
|
TrainBtmQuery2(train *state_proto.TrainState, data []byte, trainClientPort state_proto.TrainState_TrainPort)
|
2024-04-02 18:20:10 +08:00
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
type trainPcSimService struct {
|
2024-09-10 15:37:40 +08:00
|
|
|
|
state tpapi.ThirdPartyApiServiceState
|
|
|
|
|
//newPcSimclientMap map[string]*TrainPcReciverData
|
|
|
|
|
|
|
|
|
|
newPcSimclientMap3 map[string][]*TrainPcReciverData
|
|
|
|
|
|
|
|
|
|
cancleContextFun context.CancelFunc
|
|
|
|
|
context context.Context
|
|
|
|
|
trainPcSimManage TrainPcSimManage
|
|
|
|
|
configs []config.VehiclePCSimConfig
|
2024-04-13 09:40:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-02 18:20:10 +08:00
|
|
|
|
var (
|
|
|
|
|
initLock = &sync.Mutex{}
|
|
|
|
|
singleObj *trainPcSimService
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Default() TrainPcSim {
|
|
|
|
|
defer initLock.Unlock()
|
|
|
|
|
initLock.Lock()
|
|
|
|
|
if singleObj == nil {
|
|
|
|
|
singleObj = &trainPcSimService{}
|
|
|
|
|
}
|
|
|
|
|
return singleObj
|
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
2024-07-25 14:55:46 +08:00
|
|
|
|
|
2024-07-19 15:24:28 +08:00
|
|
|
|
func FindTrainPcSimClientKey2(t *state_proto.TrainState) string {
|
|
|
|
|
return t.ConnState.TypeName
|
|
|
|
|
}
|
2024-09-11 21:19:42 +08:00
|
|
|
|
func (d *trainPcSimService) findTrainConnForPort2(sta *state_proto.TrainState, trainClientPort state_proto.TrainState_TrainPort) (*TrainPcReciverData, error) {
|
2024-09-10 18:00:44 +08:00
|
|
|
|
rds := d.newPcSimclientMap3[sta.ConnState.TypeName]
|
|
|
|
|
if rds == nil {
|
|
|
|
|
return nil, fmt.Errorf("")
|
|
|
|
|
}
|
|
|
|
|
for _, rd := range rds {
|
2024-09-11 21:19:42 +08:00
|
|
|
|
if rd.RealTrainPort == trainClientPort {
|
2024-09-10 18:00:44 +08:00
|
|
|
|
return rd, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil, fmt.Errorf("")
|
|
|
|
|
}
|
2024-09-11 21:19:42 +08:00
|
|
|
|
|
2024-07-19 15:24:28 +08:00
|
|
|
|
func (d *trainPcSimService) findTrainConn(sta *state_proto.TrainState) (*TrainPcReciverData, error) {
|
2024-09-10 15:37:40 +08:00
|
|
|
|
rds := d.newPcSimclientMap3[sta.ConnState.TypeName]
|
|
|
|
|
if rds == nil {
|
2024-07-19 15:24:28 +08:00
|
|
|
|
return nil, fmt.Errorf("")
|
|
|
|
|
}
|
2024-09-10 15:37:40 +08:00
|
|
|
|
if sta.VobcState.Tc1Active {
|
|
|
|
|
return rds[0], nil
|
|
|
|
|
} else {
|
|
|
|
|
return rds[1], nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (d *trainPcSimService) findTrainAllConn(sta *state_proto.TrainState) []*TrainPcReciverData {
|
|
|
|
|
rds := d.newPcSimclientMap3[sta.ConnState.TypeName]
|
|
|
|
|
return rds
|
2024-07-19 15:24:28 +08:00
|
|
|
|
}
|
2024-09-10 15:37:40 +08:00
|
|
|
|
|
2024-07-19 15:24:28 +08:00
|
|
|
|
func (d *trainPcSimService) findAllThirdPartState() []tpapi.ThirdPartyApiService {
|
|
|
|
|
services := make([]tpapi.ThirdPartyApiService, 0)
|
2024-09-10 15:37:40 +08:00
|
|
|
|
for _, data := range d.newPcSimclientMap3 {
|
|
|
|
|
for _, rd := range data {
|
|
|
|
|
services = append(services, rd)
|
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
}
|
|
|
|
|
return services
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 16:32:21 +08:00
|
|
|
|
// 速度(单位mm/s)对应的脉冲数:速度*200/pi/840;
|
|
|
|
|
// 里程(单位mm)对应的脉冲:总里程*200/pi/840
|
2024-07-11 14:58:34 +08:00
|
|
|
|
func pluseCountSpeed(wheelDiameter int32, speedMeter float32) uint32 {
|
2024-08-07 10:23:44 +08:00
|
|
|
|
|
|
|
|
|
pluseCountData := speedMeter * 200 / math.Pi / float32(wheelDiameter)
|
2024-07-11 14:58:34 +08:00
|
|
|
|
return uint32(pluseCountData)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 13:28:56 +08:00
|
|
|
|
func (d *trainPcSimService) pluseSpeed(pc *state_proto.SensorSpeedPulseCount, wheelDiameter int32) (uint32, float32) {
|
2024-08-05 16:32:21 +08:00
|
|
|
|
defer initLock.Unlock()
|
|
|
|
|
initLock.Lock()
|
2024-09-11 13:28:56 +08:00
|
|
|
|
|
2024-08-05 16:32:21 +08:00
|
|
|
|
var sum float32 = 0
|
2024-09-11 13:28:56 +08:00
|
|
|
|
pcLen := len(pc.PulseCount3)
|
2024-08-05 16:32:21 +08:00
|
|
|
|
if pcLen == 0 {
|
|
|
|
|
return 0, 0
|
|
|
|
|
}
|
2024-09-11 13:28:56 +08:00
|
|
|
|
for _, f := range pc.PulseCount3 {
|
2024-08-05 16:32:21 +08:00
|
|
|
|
sum += f
|
|
|
|
|
}
|
2024-09-11 13:28:56 +08:00
|
|
|
|
d.trainPluseCountReset(pc)
|
2024-08-05 16:32:21 +08:00
|
|
|
|
speed := sum / float32(pcLen)
|
2024-09-11 13:28:56 +08:00
|
|
|
|
return pluseCountSpeed(wheelDiameter, speed*1000), speed
|
2024-07-19 15:24:28 +08:00
|
|
|
|
}
|
2024-09-11 13:28:56 +08:00
|
|
|
|
|
2024-07-19 15:24:28 +08:00
|
|
|
|
func (d *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) {
|
2024-07-11 14:58:34 +08:00
|
|
|
|
defer initLock.Unlock()
|
|
|
|
|
initLock.Lock()
|
2024-08-07 10:23:44 +08:00
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
case <-d.context.Done():
|
|
|
|
|
return
|
|
|
|
|
default:
|
|
|
|
|
}
|
2024-09-10 15:37:40 +08:00
|
|
|
|
|
|
|
|
|
for _, sd := range d.findTrainAllConn(sta) {
|
2024-09-10 18:00:44 +08:00
|
|
|
|
if sd.speedPlace != nil {
|
|
|
|
|
sd.speedPlace.PulseCount1 += sta.DynamicState.Displacement
|
|
|
|
|
}
|
2024-08-05 16:32:21 +08:00
|
|
|
|
}
|
2024-09-11 13:28:56 +08:00
|
|
|
|
for _, pc := range sta.PulseCountMap {
|
|
|
|
|
|
|
|
|
|
if sta.TrainRunUp {
|
|
|
|
|
if sta.TrainEndsA.SpeedSensorEnableA || sta.TrainEndsA.SpeedSensorEnableB {
|
|
|
|
|
pc.PulseCount1 = pluseCountSpeed(sta.WheelDiameter, h1)
|
|
|
|
|
pc.PulseCount3 = append(pc.PulseCount3, h1)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if sta.TrainEndsB.SpeedSensorEnableA || sta.TrainEndsB.SpeedSensorEnableB {
|
|
|
|
|
pc.PulseCount1 = pluseCountSpeed(sta.WheelDiameter, t1)
|
|
|
|
|
pc.PulseCount3 = append(pc.PulseCount3, t1)
|
|
|
|
|
}
|
2024-07-11 14:58:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-11 13:28:56 +08:00
|
|
|
|
|
2024-07-11 14:58:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 13:28:56 +08:00
|
|
|
|
func (d *trainPcSimService) trainPluseCountReset(pc *state_proto.SensorSpeedPulseCount) {
|
|
|
|
|
pc.PulseCount1 = 0
|
|
|
|
|
pc.PulseCount3 = make([]float32, 0)
|
2024-07-11 14:58:34 +08:00
|
|
|
|
}
|
2024-04-02 18:20:10 +08:00
|
|
|
|
|
2024-06-12 19:50:36 +08:00
|
|
|
|
func (d *trainPcSimService) newCloseAllConn() {
|
2024-07-11 14:58:34 +08:00
|
|
|
|
trains := d.trainPcSimManage.GetConnTrain2()
|
|
|
|
|
for _, train := range trains {
|
|
|
|
|
d.CreateOrRemoveTrain(train, false)
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-12 19:50:36 +08:00
|
|
|
|
|
|
|
|
|
func (d *trainPcSimService) newCloseConn(clientKey string) {
|
2024-09-10 15:37:40 +08:00
|
|
|
|
rds := d.newPcSimclientMap3[clientKey]
|
|
|
|
|
if rds != nil {
|
|
|
|
|
for _, rd := range rds {
|
|
|
|
|
rd.tcpClient.Close()
|
|
|
|
|
rd.tcpClient = nil
|
|
|
|
|
rd.train = nil
|
|
|
|
|
rd.speedPlace = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-11 13:28:56 +08:00
|
|
|
|
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
2024-06-12 19:50:36 +08:00
|
|
|
|
|
2024-07-19 15:24:28 +08:00
|
|
|
|
func (d *trainPcSimService) findConfig(configName string) (*config.VehiclePCSimConfig, error) {
|
|
|
|
|
|
2024-06-27 10:37:52 +08:00
|
|
|
|
for _, cfg := range d.configs {
|
2024-07-19 15:24:28 +08:00
|
|
|
|
if cfg.Open && cfg.ConfigName == configName {
|
2024-06-27 10:37:52 +08:00
|
|
|
|
return &cfg, nil
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-27 10:37:52 +08:00
|
|
|
|
return nil, fmt.Errorf("未找到对应的车载pc连接配置")
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
|
2024-09-10 15:37:40 +08:00
|
|
|
|
func (d *trainPcSimService) initConn2(clientKey string) error {
|
|
|
|
|
|
|
|
|
|
rds := d.newPcSimclientMap3[clientKey]
|
|
|
|
|
rd1 := rds[0]
|
|
|
|
|
rd2 := rds[1]
|
|
|
|
|
cfg, cfgErr := d.findConfig(clientKey)
|
|
|
|
|
if cfgErr != nil {
|
|
|
|
|
return sys_error.New(fmt.Sprintf("没找到对应的配置信息 key:%v", clientKey), cfgErr)
|
|
|
|
|
}
|
|
|
|
|
if !cfg.OpenB && !cfg.OpenA {
|
|
|
|
|
return sys_error.New(fmt.Sprintf("配置:%v A,B端配置均为打开", clientKey))
|
|
|
|
|
}
|
|
|
|
|
e1 := d.connServer(cfg.OpenA, cfg.APcSimIp, cfg.APcSimPort, rd1)
|
|
|
|
|
if e1 != nil {
|
2024-09-11 21:19:42 +08:00
|
|
|
|
rd1.updateState(tpapi.ThirdPartyState_Broken)
|
2024-09-10 15:37:40 +08:00
|
|
|
|
return sys_error.New(fmt.Sprintf("配置:%v 端口A连接失败", clientKey))
|
|
|
|
|
}
|
|
|
|
|
e2 := d.connServer(cfg.OpenB, cfg.BPcSimIp, cfg.BPcSimPort, rd2)
|
|
|
|
|
if e2 != nil {
|
2024-09-11 21:19:42 +08:00
|
|
|
|
rd1.updateState(tpapi.ThirdPartyState_Broken)
|
2024-09-10 15:37:40 +08:00
|
|
|
|
return sys_error.New(fmt.Sprintf("配置:%v 端口B连接失败", clientKey))
|
|
|
|
|
}
|
2024-09-11 21:19:42 +08:00
|
|
|
|
if rd1.success {
|
|
|
|
|
//rd1.aPort = true
|
|
|
|
|
rd1.RealTrainPort = state_proto.TrainState_PORT_A
|
|
|
|
|
}
|
|
|
|
|
if rd2.success {
|
|
|
|
|
rd2.RealTrainPort = state_proto.TrainState_PORT_B
|
|
|
|
|
}
|
2024-09-10 15:37:40 +08:00
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-05-24 09:00:43 +08:00
|
|
|
|
|
2024-09-10 15:37:40 +08:00
|
|
|
|
func (d *trainPcSimService) connServer(open bool, ip string, port uint32, rd *TrainPcReciverData) *sys_error.BusinessError {
|
2024-06-27 10:37:52 +08:00
|
|
|
|
if rd != nil && rd.tcpClient != nil && rd.tcpClient.IsConning() {
|
2024-07-19 15:24:28 +08:00
|
|
|
|
return nil
|
|
|
|
|
} else {
|
|
|
|
|
rd.tcpClient = nil
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
2024-09-10 15:37:40 +08:00
|
|
|
|
if !open {
|
|
|
|
|
rd.success = false
|
|
|
|
|
return nil
|
2024-07-19 15:24:28 +08:00
|
|
|
|
}
|
2024-09-10 15:37:40 +08:00
|
|
|
|
addr := fmt.Sprintf("%v:%v", ip, port)
|
|
|
|
|
//slog.Info(addr, "连接.,...")
|
2024-07-19 15:24:28 +08:00
|
|
|
|
client2, err := tcp.StartTcpClient(addr, rd.receiverDataHandle, rd.readError)
|
2024-05-24 09:00:43 +08:00
|
|
|
|
if err != nil {
|
2024-09-11 21:19:42 +08:00
|
|
|
|
return sys_error.New(fmt.Sprintf("车载atp连接失败,add:%v ,message:%v", addr, err))
|
2024-05-24 09:00:43 +08:00
|
|
|
|
} else {
|
2024-09-10 15:37:40 +08:00
|
|
|
|
rd.success = true
|
2024-06-12 19:50:36 +08:00
|
|
|
|
rd.tcpClient = client2
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
return nil
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
|
2024-04-29 13:58:14 +08:00
|
|
|
|
func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
2024-07-19 15:24:28 +08:00
|
|
|
|
|
2024-05-24 09:00:43 +08:00
|
|
|
|
configs := pcSimManage.GetTrainPcSimConfig()
|
2024-09-10 15:37:40 +08:00
|
|
|
|
//d.newPcSimclientMap = make(map[string]*TrainPcReciverData)
|
|
|
|
|
d.newPcSimclientMap3 = make(map[string][]*TrainPcReciverData)
|
2024-05-24 09:00:43 +08:00
|
|
|
|
if len(configs) <= 0 {
|
|
|
|
|
slog.Info("车载pc仿真配置未开启")
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-06-27 10:37:52 +08:00
|
|
|
|
closedCount := 0
|
2024-05-24 09:00:43 +08:00
|
|
|
|
for _, c := range configs {
|
|
|
|
|
if !c.Open {
|
2024-06-27 10:37:52 +08:00
|
|
|
|
closedCount++
|
2024-07-19 15:24:28 +08:00
|
|
|
|
} else {
|
|
|
|
|
ck := c.ConfigName
|
2024-09-10 15:37:40 +08:00
|
|
|
|
pcReceivers := make([]*TrainPcReciverData, 2)
|
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
|
ss := fmt.Sprintf("%v%v", c.ConfigName, i)
|
|
|
|
|
pcReciver := &TrainPcReciverData{clientKey: ss, pcSimManage: pcSimManage}
|
|
|
|
|
pcReciver.updateState(tpapi.ThirdPartyState_Closed)
|
|
|
|
|
pcReceivers[i] = pcReciver
|
|
|
|
|
}
|
|
|
|
|
d.newPcSimclientMap3[ck] = pcReceivers
|
|
|
|
|
//d.newPcSimclientMap[ck] = pcReciver
|
|
|
|
|
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-27 10:37:52 +08:00
|
|
|
|
if closedCount == len(configs) {
|
|
|
|
|
slog.Error("车载pc仿真配置未开启")
|
2024-04-02 18:20:10 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2024-07-25 14:55:46 +08:00
|
|
|
|
|
2024-05-24 09:00:43 +08:00
|
|
|
|
d.configs = configs
|
2024-04-02 18:20:10 +08:00
|
|
|
|
ctx, ctxFun := context.WithCancel(context.Background())
|
2024-08-07 10:23:44 +08:00
|
|
|
|
d.cancleContextFun = ctxFun
|
|
|
|
|
d.context = ctx
|
2024-04-13 09:40:25 +08:00
|
|
|
|
d.trainPcSimManage = pcSimManage
|
2024-06-18 17:10:21 +08:00
|
|
|
|
go d.sendTrainLocationAndSpeedTask(ctx)
|
2024-04-02 18:20:10 +08:00
|
|
|
|
}
|
2024-06-18 17:10:21 +08:00
|
|
|
|
|
2024-04-13 09:40:25 +08:00
|
|
|
|
func (d *trainPcSimService) Stop() {
|
2024-09-10 15:37:40 +08:00
|
|
|
|
|
|
|
|
|
for _, rds := range d.newPcSimclientMap3 {
|
|
|
|
|
for _, rd := range rds {
|
|
|
|
|
rd.updateState(tpapi.ThirdPartyState_Closed)
|
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
}
|
2024-08-07 10:23:44 +08:00
|
|
|
|
if d.cancleContextFun != nil {
|
|
|
|
|
d.cancleContextFun()
|
|
|
|
|
d.cancleContextFun = nil
|
2024-04-13 09:40:25 +08:00
|
|
|
|
}
|
2024-06-12 19:50:36 +08:00
|
|
|
|
d.newCloseAllConn()
|
2024-04-09 08:55:33 +08:00
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
|
2024-06-27 10:37:52 +08:00
|
|
|
|
func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error {
|
2024-07-19 15:24:28 +08:00
|
|
|
|
clientKey := FindTrainPcSimClientKey2(train)
|
2024-09-11 21:19:42 +08:00
|
|
|
|
|
2024-06-27 10:37:52 +08:00
|
|
|
|
data := []byte{message.FLAG_CAMMAND_REMOVE_TRAIN}
|
|
|
|
|
if isCreate {
|
2024-09-11 21:19:42 +08:00
|
|
|
|
err := d.initConn2(clientKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
d.newCloseConn(clientKey)
|
|
|
|
|
return err
|
|
|
|
|
}
|
2024-06-27 10:37:52 +08:00
|
|
|
|
data[0] = message.FLAG_CAMMAND_CREATE_TRAIN
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
2024-06-27 10:37:52 +08:00
|
|
|
|
msg := &message.TrainPcSimBaseMessage{Data: data, Type: message.RECIVE_TRAIN_CREATE_REMOVE}
|
2024-09-10 15:37:40 +08:00
|
|
|
|
rds := d.newPcSimclientMap3[clientKey]
|
|
|
|
|
if rds != nil {
|
|
|
|
|
for index, rd := range rds {
|
|
|
|
|
if rd != nil && rd.success {
|
|
|
|
|
slog.Info(fmt.Sprintf("index%v---rd client:%v clientnil :%v", index, rd.tcpClient, rd.tcpClient == nil))
|
|
|
|
|
initTrainErr := d.initTrain(rd, train, isCreate, msg)
|
|
|
|
|
if !isCreate {
|
|
|
|
|
d.newCloseConn(clientKey)
|
|
|
|
|
}
|
|
|
|
|
if initTrainErr != nil {
|
|
|
|
|
return initTrainErr
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-27 10:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-10 15:37:40 +08:00
|
|
|
|
|
2024-06-27 10:37:52 +08:00
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-07-19 15:24:28 +08:00
|
|
|
|
func (d *trainPcSimService) initTrain(rd *TrainPcReciverData, train *state_proto.TrainState, isCreate bool, trains *message.TrainPcSimBaseMessage) error {
|
2024-06-27 10:37:52 +08:00
|
|
|
|
msgs := make([]message.TrainPcSimBaseMessage, 0)
|
2024-07-11 14:58:34 +08:00
|
|
|
|
sendMsg := make([]byte, 0)
|
2024-08-07 10:23:44 +08:00
|
|
|
|
rd.speedPlace = &message.TrainSpeedPlaceReportMsg{}
|
2024-09-11 13:28:56 +08:00
|
|
|
|
train.PulseCountMap = make(map[int32]*state_proto.SensorSpeedPulseCount)
|
|
|
|
|
train.PulseCountMap[int32(state_proto.TrainState_PORT_A.Number())] = &state_proto.SensorSpeedPulseCount{}
|
|
|
|
|
train.PulseCountMap[int32(state_proto.TrainState_PORT_B.Number())] = &state_proto.SensorSpeedPulseCount{}
|
2024-08-07 10:23:44 +08:00
|
|
|
|
rd.train = train
|
|
|
|
|
tcc := train.Tcc
|
2024-09-11 21:19:42 +08:00
|
|
|
|
rd.TrainConnInitComplate = false
|
|
|
|
|
rd.LineInitTimeStamp = 0
|
|
|
|
|
|
2024-06-27 10:37:52 +08:00
|
|
|
|
if isCreate {
|
|
|
|
|
tmpMsgs := d.trainPcSimManage.ObtainTrainDigitalMockData(train)
|
|
|
|
|
msgs = append(msgs, tmpMsgs...)
|
2024-07-15 15:00:33 +08:00
|
|
|
|
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{0x00}, Type: message.RECIVE_TRAIN_DOOR_MODE}) //门模式
|
|
|
|
|
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.RECIVE_TRAIN_BTN_CLEAR_ALL_PRE_DATA}) //清空应答器
|
2024-09-10 15:37:40 +08:00
|
|
|
|
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.SENDER_TRAIN_TC_ACTIVE}) //清空应答器
|
2024-06-27 10:37:52 +08:00
|
|
|
|
} else {
|
2024-07-11 14:58:34 +08:00
|
|
|
|
train.VobcState.Tc1Active = false
|
|
|
|
|
train.VobcState.Tc2Active = false
|
|
|
|
|
for _, key := range tcc.DriverKey {
|
|
|
|
|
key.Val = false
|
|
|
|
|
}
|
|
|
|
|
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{message.TRAIN_BRAKE_STATE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //驾驶室激活
|
|
|
|
|
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{message.KEY_STATE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //驾驶室激活
|
|
|
|
|
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.SENDER_TRAIN_TC_NOT_ACTIVE}) //驾驶室激活
|
2024-06-27 10:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
for _, msg := range msgs {
|
|
|
|
|
data := msg.Encode()
|
2024-07-11 14:58:34 +08:00
|
|
|
|
sendMsg = append(sendMsg, data...)
|
2024-06-27 10:37:52 +08:00
|
|
|
|
}
|
2024-07-11 14:58:34 +08:00
|
|
|
|
sendMsg = append(sendMsg, trains.Encode()...)
|
|
|
|
|
hexData := hex.EncodeToString(sendMsg)
|
|
|
|
|
slog.Info(fmt.Sprintf("发送列车初始化消息:%v", hexData))
|
|
|
|
|
rd.tcpClient.Send(sendMsg)
|
2024-06-12 19:50:36 +08:00
|
|
|
|
return nil
|
2024-04-13 09:40:25 +08:00
|
|
|
|
}
|
2024-04-02 18:20:10 +08:00
|
|
|
|
|
|
|
|
|
// 依据文档80ms发送列车速度位置
|
2024-04-13 09:40:25 +08:00
|
|
|
|
func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
2024-09-10 15:37:40 +08:00
|
|
|
|
for range time.Tick(time.Millisecond * 80) {
|
2024-04-02 18:20:10 +08:00
|
|
|
|
select {
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
|
return
|
|
|
|
|
default:
|
|
|
|
|
}
|
2024-09-10 15:37:40 +08:00
|
|
|
|
|
2024-05-24 09:00:43 +08:00
|
|
|
|
trains := d.trainPcSimManage.GetConnTrain2()
|
|
|
|
|
for _, train := range trains {
|
2024-09-11 13:28:56 +08:00
|
|
|
|
if train.ConnState.Conn {
|
|
|
|
|
for numKey, pc := range train.PulseCountMap {
|
|
|
|
|
trainPort := state_proto.TrainState_TrainPort(numKey)
|
2024-09-11 21:19:42 +08:00
|
|
|
|
trainClient, _ := d.findTrainConnForPort2(train, trainPort)
|
2024-09-10 15:37:40 +08:00
|
|
|
|
if trainClient.success {
|
2024-09-10 18:00:44 +08:00
|
|
|
|
if trainClient.speedPlace == nil || trainClient.tcpClient == nil {
|
2024-09-10 15:37:40 +08:00
|
|
|
|
slog.Error(fmt.Sprintf("pc仿真速度位置脉冲对象为空 列车id:%v", train.Id))
|
|
|
|
|
continue
|
|
|
|
|
}
|
2024-09-11 21:19:42 +08:00
|
|
|
|
if trainClient.ConnError() {
|
|
|
|
|
continue
|
2024-09-10 15:37:40 +08:00
|
|
|
|
}
|
2024-09-11 21:19:42 +08:00
|
|
|
|
s1, speed := d.pluseSpeed(pc, train.WheelDiameter)
|
|
|
|
|
runDir := d.trainDirection(speed, train, trainClient.RealTrainPort)
|
2024-09-10 15:37:40 +08:00
|
|
|
|
disPluse := pluseCountSpeed(train.WheelDiameter, trainClient.speedPlace.PulseCount1)
|
|
|
|
|
data := trainClient.speedPlace.Encode(runDir, s1, disPluse)
|
|
|
|
|
bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data}
|
|
|
|
|
dataCode := bm.Encode()
|
2024-09-11 21:19:42 +08:00
|
|
|
|
slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,列车服务端:%v,列车速度:%v,计数脉冲: %v,累计里程: %v ,发送数据:%X", train.Id, trainClient.RealTrainPort.String(), speed, s1, trainClient.speedPlace.PulseCount1, dataCode))
|
2024-09-10 15:37:40 +08:00
|
|
|
|
err := trainClient.tcpClient.Send(dataCode)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode)))
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-13 09:09:25 +08:00
|
|
|
|
}
|
2024-05-24 09:00:43 +08:00
|
|
|
|
}
|
2024-04-16 17:26:37 +08:00
|
|
|
|
}
|
2024-04-02 18:20:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-09 08:55:33 +08:00
|
|
|
|
|
2024-09-11 21:19:42 +08:00
|
|
|
|
func (d *trainPcSimService) trainDirection(speed float32, train *state_proto.TrainState, clientPort state_proto.TrainState_TrainPort) uint16 {
|
|
|
|
|
runDir := uint16(2)
|
2024-05-24 09:00:43 +08:00
|
|
|
|
vobc := train.VobcState
|
2024-09-11 21:19:42 +08:00
|
|
|
|
if speed == 0 || train.TrainPort == state_proto.TrainState_PORT_NONE || (vobc.DirectionForward == false && vobc.DirectionBackward == false) {
|
|
|
|
|
return runDir
|
|
|
|
|
}
|
|
|
|
|
if vobc.DirectionForward {
|
|
|
|
|
runDir = 1
|
|
|
|
|
} else if vobc.DirectionBackward {
|
|
|
|
|
runDir = 0
|
|
|
|
|
}
|
|
|
|
|
if train.TrainPort != clientPort {
|
|
|
|
|
if vobc.DirectionForward {
|
|
|
|
|
runDir = 0
|
|
|
|
|
} else if vobc.DirectionBackward {
|
|
|
|
|
runDir = 1
|
2024-09-10 18:00:44 +08:00
|
|
|
|
}
|
2024-07-11 14:58:34 +08:00
|
|
|
|
}
|
2024-06-13 18:13:21 +08:00
|
|
|
|
|
2024-09-11 21:19:42 +08:00
|
|
|
|
return runDir
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 09:00:43 +08:00
|
|
|
|
func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState) {
|
2024-07-19 15:24:28 +08:00
|
|
|
|
trainClient, trainDataErr := d.findTrainConn(train)
|
|
|
|
|
if trainDataErr != nil {
|
2024-08-13 17:32:49 +08:00
|
|
|
|
slog.Error(fmt.Sprintf("发送列车牵引失败,未找到对应的列车id:%v", train.Id))
|
2024-07-19 15:24:28 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2024-05-24 09:00:43 +08:00
|
|
|
|
tc := train.ConnState
|
|
|
|
|
if tc.Conn {
|
|
|
|
|
vobc := train.VobcState
|
2024-04-09 08:55:33 +08:00
|
|
|
|
msg := &message.TrainPcSimBaseMessage{}
|
2024-04-02 18:20:10 +08:00
|
|
|
|
newTraction := vobc.TractionForce
|
2024-04-18 11:14:05 +08:00
|
|
|
|
if tractionState {
|
2024-07-11 14:58:34 +08:00
|
|
|
|
if newTraction <= oldTraction && newTraction <= 0 {
|
2024-04-16 17:26:37 +08:00
|
|
|
|
//手柄取消前进
|
2024-06-27 10:37:52 +08:00
|
|
|
|
msg.Type = message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD
|
2024-04-18 11:14:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
//手柄前进
|
2024-06-27 10:37:52 +08:00
|
|
|
|
msg.Type = message.SENDER_TRAIN_HAND_KEY_FORWARD
|
2024-04-18 11:14:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
2024-06-27 10:37:52 +08:00
|
|
|
|
/*if newBrake >= newOldBrakeForce && newBrake == 0 {
|
2024-04-18 11:14:05 +08:00
|
|
|
|
//手柄取消后退
|
2024-06-27 10:37:52 +08:00
|
|
|
|
msg.Type = message.RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD
|
2024-07-11 14:58:34 +08:00
|
|
|
|
} else if newBrake < newOldBrakeForce {
|
2024-04-18 11:14:05 +08:00
|
|
|
|
//手柄后退
|
2024-06-27 10:37:52 +08:00
|
|
|
|
msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD
|
2024-04-18 11:14:05 +08:00
|
|
|
|
} else {
|
|
|
|
|
//手柄后退
|
2024-06-27 10:37:52 +08:00
|
|
|
|
msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD
|
|
|
|
|
}*/
|
|
|
|
|
msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD
|
2024-04-02 18:20:10 +08:00
|
|
|
|
}
|
2024-05-29 15:19:04 +08:00
|
|
|
|
da := msg.Encode()
|
2024-07-25 14:55:46 +08:00
|
|
|
|
//slog.Info("发送列车手柄消息", "msg", hex.EncodeToString(da))
|
2024-07-19 15:24:28 +08:00
|
|
|
|
err := trainClient.tcpClient.Send(da)
|
2024-06-12 19:50:36 +08:00
|
|
|
|
//err := client.Send(da)
|
2024-05-29 15:19:04 +08:00
|
|
|
|
if err != nil {
|
2024-07-19 15:24:28 +08:00
|
|
|
|
slog.Error("发送列车手柄消息失败", "msg", hex.EncodeToString(da))
|
2024-05-29 15:19:04 +08:00
|
|
|
|
}
|
2024-04-02 18:20:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-24 09:00:43 +08:00
|
|
|
|
func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, trainForward, trainBackward bool) {
|
2024-07-19 15:24:28 +08:00
|
|
|
|
trainClient, trainDataErr := d.findTrainConn(train)
|
|
|
|
|
if trainDataErr != nil {
|
|
|
|
|
slog.Error(fmt.Sprintf("发送列车方向失败,未找到列车连接,trainId:%s", train.Id))
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-04-16 17:26:37 +08:00
|
|
|
|
baseMsgs := make([]*message.TrainPcSimBaseMessage, 0)
|
|
|
|
|
if !trainForward && !trainBackward {
|
2024-06-27 10:37:52 +08:00
|
|
|
|
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD})
|
|
|
|
|
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD})
|
2024-04-16 17:26:37 +08:00
|
|
|
|
} else if trainForward {
|
2024-06-27 10:37:52 +08:00
|
|
|
|
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_HAND_KEY_FORWARD})
|
2024-04-16 17:26:37 +08:00
|
|
|
|
} else if trainBackward {
|
2024-06-27 10:37:52 +08:00
|
|
|
|
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_BACKWARD})
|
2024-04-16 17:26:37 +08:00
|
|
|
|
}
|
2024-07-15 15:00:33 +08:00
|
|
|
|
|
2024-04-16 17:26:37 +08:00
|
|
|
|
for _, msg := range baseMsgs {
|
2024-05-29 15:19:04 +08:00
|
|
|
|
da := msg.Encode()
|
2024-07-25 14:55:46 +08:00
|
|
|
|
//slog.Info(fmt.Sprintf("发送列车方向列车:%v ,数据:%v", train.Id, hex.EncodeToString(da)))
|
2024-07-19 15:24:28 +08:00
|
|
|
|
err := trainClient.tcpClient.Send(da)
|
2024-07-15 15:00:33 +08:00
|
|
|
|
|
2024-05-29 15:19:04 +08:00
|
|
|
|
if err != nil {
|
2024-06-18 17:10:21 +08:00
|
|
|
|
slog.Error(fmt.Sprintf("发送列车方向失败列车:%v ,数据:%v,err:%v", train.Id, hex.EncodeToString(da), err.Error()))
|
2024-05-29 15:19:04 +08:00
|
|
|
|
}
|
2024-04-16 17:26:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-11 14:58:34 +08:00
|
|
|
|
|
2024-09-11 21:19:42 +08:00
|
|
|
|
func (d *trainPcSimService) SendBaliseData2(train *state_proto.TrainState, trainClientPort state_proto.TrainState_TrainPort, msgType byte, data []byte) {
|
|
|
|
|
|
|
|
|
|
trainClient, trainDataErr := d.findTrainConnForPort2(train, trainClientPort)
|
2024-07-19 15:24:28 +08:00
|
|
|
|
if trainDataErr != nil {
|
|
|
|
|
slog.Error(fmt.Sprintf("发送列车PC仿真应答器信息失败,未找到列车连接,trainId:%v", train.Id))
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-04-09 08:55:33 +08:00
|
|
|
|
msg := &message.TrainPcSimBaseMessage{}
|
2024-04-02 18:20:10 +08:00
|
|
|
|
msg.Type = msgType
|
|
|
|
|
msg.Data = data
|
2024-07-19 15:24:28 +08:00
|
|
|
|
|
2024-05-29 15:19:04 +08:00
|
|
|
|
da := msg.Encode()
|
2024-08-05 16:32:21 +08:00
|
|
|
|
//slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,数据类型:0x%x,源数据长度:%v,数据:%v", msgType, len(data), hex.EncodeToString(da)))
|
2024-07-19 15:24:28 +08:00
|
|
|
|
err := trainClient.tcpClient.Send(da)
|
2024-05-29 15:19:04 +08:00
|
|
|
|
if err != nil {
|
2024-06-18 17:10:21 +08:00
|
|
|
|
slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息失败,数据:%v", hex.EncodeToString(da)))
|
2024-05-29 15:19:04 +08:00
|
|
|
|
}
|
2024-04-02 18:20:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 21:19:42 +08:00
|
|
|
|
func (d *trainPcSimService) SendTrainControlMsg2(train *state_proto.TrainState, baseMessage []message.TrainPcSimBaseMessage, trainClientPort state_proto.TrainState_TrainPort) {
|
2024-07-15 15:00:33 +08:00
|
|
|
|
if len(baseMessage) <= 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-09-10 18:00:44 +08:00
|
|
|
|
//trainClient, trainDataErr := d.findTrainConn(train)
|
2024-09-11 21:19:42 +08:00
|
|
|
|
trainClient, trainDataErr := d.findTrainConnForPort2(train, trainClientPort)
|
2024-07-19 15:24:28 +08:00
|
|
|
|
if trainDataErr != nil {
|
|
|
|
|
slog.Error(fmt.Sprintf("发送列车控制信息失败,无连接,列车Id:%v", train.Id))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-15 15:00:33 +08:00
|
|
|
|
for _, msg := range baseMessage {
|
2024-08-22 13:12:03 +08:00
|
|
|
|
dd := msg.Encode()
|
2024-09-11 21:19:42 +08:00
|
|
|
|
//slog.Info(fmt.Sprintf("发送操控列车控制信息:%x", dd), aport)
|
2024-08-22 13:12:03 +08:00
|
|
|
|
d.sendData(trainClient.tcpClient, dd)
|
2024-07-15 15:00:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-11 21:19:42 +08:00
|
|
|
|
|
2024-07-15 15:00:33 +08:00
|
|
|
|
func (d *trainPcSimService) sendData(client *tcp.TcpClient, data []byte) {
|
|
|
|
|
err := client.Send(data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error(fmt.Sprintf("列车数字量信息发送失败,数据:%v", err.Error()))
|
2024-04-02 18:20:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|