This commit is contained in:
tiger_zhou 2024-09-10 15:37:40 +08:00
parent 39b4ffb633
commit f9ffa1cf10
17 changed files with 1583 additions and 1185 deletions

View File

@ -161,11 +161,15 @@ type VehiclePCSimConfig2 struct {
} }
type VehiclePCSimConfig struct { type VehiclePCSimConfig struct {
Open bool `json:"open" description:"是否开启"`
//TrainEnds bool `json:"trainEnds" description:"列车端点A?"` //TrainEnds bool `json:"trainEnds" description:"列车端点A?"`
ConfigName string `json:"configName" description:"连接名称"` ConfigName string `json:"configName" description:"连接名称"`
Open bool `json:"open" description:"是否开启"` OpenA bool `json:"openA" description:"是否开启A端"`
PcSimIp string `json:"pcSimIp" description:"pc仿真平台通信ip"` APcSimIp string `json:"apcSimIp" description:"pc仿真平台通信ip A端"`
PcSimPort uint32 `json:"pcSimPort" description:"pc仿真平台通信端口"` APcSimPort uint32 `json:"apcSimPort" description:"pc仿真平台通信端口A端"`
OpenB bool `json:"openB" description:"是否开启B端"`
BPcSimIp string `json:"bpcSimIp" description:"pc仿真平台通信ip B端"`
BPcSimPort uint32 `json:"bpcSimPort" description:"pc仿真平台通信端口B端"`
//LocalTestingPort uint32 `json:"localTestingPort" description:"本地测试端口"` //LocalTestingPort uint32 `json:"localTestingPort" description:"本地测试端口"`
} }

View File

@ -6,8 +6,8 @@ server:
# 数据源 # 数据源
datasource: datasource:
# 数据库访问url # 数据库访问url
# dsn: root:root@tcp(127.0.0.1:3306)/bj-rtss?charset=utf8mb4&parseTime=true&loc=UTC dsn: root:root@tcp(127.0.0.1:3306)/bj-rtss?charset=utf8mb4&parseTime=true&loc=UTC
dsn: root:joylink0503@tcp(192.168.33.233:3306)/bj-rtss?charset=utf8mb4&parseTime=true&loc=UTC # dsn: root:joylink0503@tcp(192.168.33.233:3306)/bj-rtss?charset=utf8mb4&parseTime=true&loc=UTC
# 日志配置 # 日志配置
logging: logging:
@ -33,7 +33,7 @@ logging:
# 消息配置 # 消息配置
messaging: messaging:
mqtt: mqtt:
# address: tcp://127.0.0.1:1883 address: tcp://127.0.0.1:1883
address: tcp://192.168.33.233:1883 # address: tcp://192.168.33.233:1883
username: rtsts_service username: rtsts_service
password: joylink@0503 password: joylink@0503

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit 693576459c8875f7fd82c84df1cd39d4487be65d Subproject commit 91f3fdb23d7080be99e2a2573e281bb3c5c056ed

@ -1 +1 @@
Subproject commit 3d7da35731be5af7bb126c276b4f9486c1f68e3a Subproject commit 4e275a7b14a645c84d15842106cc4ed883234382

View File

@ -45,7 +45,7 @@ func checkRunConfig(jsonConfigStr string) *sys_error.BusinessError {
checkSameMap := make(map[string]bool) checkSameMap := make(map[string]bool)
for _, simConfig := range configMap.PcSimConfigs { for _, simConfig := range configMap.PcSimConfigs {
if simConfig.ConfigName == "" || len(strings.TrimSpace(simConfig.ConfigName)) == 0 { if simConfig.ConfigName == "" || len(strings.TrimSpace(simConfig.ConfigName)) == 0 {
return sys_error.New(fmt.Sprintf("车载运行配置名称不能为空 配置ip:%v,端口%v", simConfig.PcSimIp, simConfig.PcSimPort), err) return sys_error.New(fmt.Sprintf("车载运行配置名称不能为空 "), err)
} }
if checkSameMap[simConfig.ConfigName] { if checkSameMap[simConfig.ConfigName] {
return sys_error.New(fmt.Sprintf("车载运行配置重复的名称:%v", simConfig.ConfigName), err) return sys_error.New(fmt.Sprintf("车载运行配置重复的名称:%v", simConfig.ConfigName), err)

View File

@ -68,7 +68,7 @@ type BtmCanetClient interface {
Stop() Stop()
//HandleTrainHeadPositionInfo 处理收到列车位置信息 //HandleTrainHeadPositionInfo 处理收到列车位置信息
HandleTrainHeadPositionInfo(w ecs.World, h *TrainHeadPositionInfo) HandleTrainHeadPositionInfo(w ecs.World, h *TrainHeadPositionInfo)
HandleTrainHeadPositionInfoForTrain(w ecs.World, train *state_proto.TrainBtmCache, h *TrainHeadPositionInfo) HandleTrainHeadPositionInfoForTrain(w ecs.World, train *state_proto.TrainState, h *TrainHeadPositionInfo)
} }
var ( var (
@ -84,7 +84,7 @@ func Default() BtmCanetClient {
} }
return btmClient return btmClient
} }
func (s *btmCanetClient) HandleTrainHeadPositionInfoForTrain(w ecs.World, btmCache *state_proto.TrainBtmCache, h *TrainHeadPositionInfo) { func (s *btmCanetClient) HandleTrainHeadPositionInfoForTrain(w ecs.World, train *state_proto.TrainState, h *TrainHeadPositionInfo) {
wd := entity.GetWorldData(w) wd := entity.GetWorldData(w)
repo := wd.Repo repo := wd.Repo
h2 := &TrainHeadPositionInfo{ h2 := &TrainHeadPositionInfo{
@ -94,8 +94,15 @@ func (s *btmCanetClient) HandleTrainHeadPositionInfoForTrain(w ecs.World, btmCac
LinkOffset: h.OldLinkOffset, LinkOffset: h.OldLinkOffset,
Speed: h.Speed, Speed: h.Speed,
Acceleration: h.Acceleration} Acceleration: h.Acceleration}
s.baliseDetector.newDetect(wd, repo, h, h2, btmCache, h.IsLine12) s.baliseDetector.newDetect(wd, repo, h, h2, train.BtmBaliseCacheA, h.IsLine12, false, "11")
//s.baliseDetector.detect2(wd, repo, h, h2, vobcBtm) h.Up = h.TailUp
h.Link = h.TailLink
h.LinkOffset = h.TailLinkOffset
h2.Up = h.TailUp
h2.Link = h.OldTailLink
h2.LinkOffset = h.OldTailLinkOffset
s.baliseDetector.newDetect(wd, repo, h, h2, train.BtmBaliseCacheB, h.IsLine12, false, "222")
} }
// HandleTrainHeadPositionInfo 处理来自动力学的列车位置信息 // HandleTrainHeadPositionInfo 处理来自动力学的列车位置信息

View File

@ -77,7 +77,7 @@ func (t *BaliseDetector) tryRebind(th *TrainHeadPositionInfo) {
//slog.Debug(fmt.Sprintf("列车[%s]与CAN-BTM绑定", t.trianId)) //slog.Debug(fmt.Sprintf("列车[%s]与CAN-BTM绑定", t.trianId))
} }
} }
func (t *BaliseDetector) newDetect(wd *component.WorldData, repo *repository.Repository, th, th2 *TrainHeadPositionInfo, btmCache *state_proto.TrainBtmCache, isLine12 bool) { func (t *BaliseDetector) newDetect(wd *component.WorldData, repo *repository.Repository, th, th2 *TrainHeadPositionInfo, btmCache *state_proto.TrainBtmCache, isLine12, show bool, id string) {
//BTM天线中心点运行信息 //BTM天线中心点运行信息
curAntennaRi := t.createBtmAntennaRunningInfo(wd, repo, th) //目前车头 curAntennaRi := t.createBtmAntennaRunningInfo(wd, repo, th) //目前车头
curAntennaRi2 := t.createBtmAntennaRunningInfo(wd, repo, th2) //上次车头 curAntennaRi2 := t.createBtmAntennaRunningInfo(wd, repo, th2) //上次车头
@ -103,7 +103,15 @@ func (t *BaliseDetector) newDetect(wd *component.WorldData, repo *repository.Rep
if len(balises) > 0 { if len(balises) > 0 {
balise := balises[0] balise := balises[0]
telegram, utel := t.rcvTelegram(wd, balise.Id()) telegram, utel := t.rcvTelegram(wd, balise.Id())
AddNewExpectedBalise(balise, btmCache, telegram, utel, isLine12) /*if show {
slog.Info(fmt.Sprintf("%v --------------------id:%v ,offset:%v, up: %v,linkeId:%v ,headoffset:%v,tailOffset:%v", id, balise.Id(), balise.LinkPosition().Offset(), th.Up, curAntennaRi.LinkId, curAntennaRi.LinkOffset, curAntennaRi2.LinkOffset))
}*/
if AddNewExpectedBalise(balise, btmCache, telegram, utel, isLine12) {
if show {
slog.Info(fmt.Sprintf("%v +++++++++++++id:%v ,offset:%v, up: %v,linkeId:%v ,headoffset:%v,tailOffset:%v", id, balise.Id(), balise.LinkPosition().Offset(), th.Up, curAntennaRi.LinkId, curAntennaRi.LinkOffset, curAntennaRi2.LinkOffset))
}
}
} }
} }
@ -179,7 +187,7 @@ func (t *BaliseDetector) rcvTelegram(wd *component.WorldData, baliseId string) (
if !workedState.Work { if !workedState.Work {
return fixBalise.Telegram, fixBalise.UserTelegram return fixBalise.Telegram, fixBalise.UserTelegram
} else if baliseVar.UserTelegram == nil || len(baliseVar.UserTelegram) == 0 { } else if baliseVar.UserTelegram == nil || len(baliseVar.UserTelegram) == 0 {
slog.Warn(fmt.Sprintf("BTM天线未接受到应答器可变报文即将使用对应的固定报文, baliseId: %v", baliseId)) //slog.Warn(fmt.Sprintf("BTM天线未接受到应答器可变报文即将使用对应的固定报文, baliseId: %v", baliseId))
return fixBalise.Telegram, fixBalise.UserTelegram return fixBalise.Telegram, fixBalise.UserTelegram
} else { } else {
return baliseVar.Telegram, baliseVar.UserTelegram return baliseVar.Telegram, baliseVar.UserTelegram
@ -187,10 +195,10 @@ func (t *BaliseDetector) rcvTelegram(wd *component.WorldData, baliseId string) (
} else if workedState.Work { } else if workedState.Work {
return fixBalise.Telegram, fixBalise.UserTelegram return fixBalise.Telegram, fixBalise.UserTelegram
} else { } else {
slog.Warn(fmt.Sprintf("BTM天线未接受到应答器报文应答器未工作 baliseId: %v", baliseId)) //slog.Warn(fmt.Sprintf("BTM天线未接受到应答器报文应答器未工作 baliseId: %v", baliseId))
} }
} else { } else {
slog.Warn(fmt.Sprintf("BTM天线接收应答器报文未找到 baliseId: %v", baliseId)) //slog.Warn(fmt.Sprintf("BTM天线接收应答器报文未找到 baliseId: %v", baliseId))
} }
return nil, nil return nil, nil
} }

View File

@ -58,56 +58,56 @@ func AddNewExpectedBalise(balise *repository.Transponder, btmCache *state_proto.
// HandleTrainHeadPositionInfoForTrain 处理列车位置信息 // HandleTrainHeadPositionInfoForTrain 处理列车位置信息
// 参数1 参数2发送序列号参数3应答器计数每过一个应答器加一在同一个应答器内不变)参数4报文计数器 (每解出一个报文加一)0~255 // 参数1 参数2发送序列号参数3应答器计数每过一个应答器加一在同一个应答器内不变)参数4报文计数器 (每解出一个报文加一)0~255
func FindBaliseResend(train *state_proto.TrainState) (*state_proto.BTMState, byte, byte, byte) { func FindBaliseResend(cache *state_proto.TrainBtmCache, isLine12 bool) (*state_proto.BTMState, byte, byte, byte) {
baliseLock.Lock() baliseLock.Lock()
defer baliseLock.Unlock() defer baliseLock.Unlock()
cache := train.BtmBaliseCache
for _, balise := range cache.BaliseList { for _, balise := range cache.BaliseList {
if balise != nil && balise.BaliseId == cache.ResendBaliseId && balise.ResendCount < 3 { if balise != nil && balise.BaliseId == cache.ResendBaliseId && balise.ResendCount < 3 {
balise.ResendCount++ balise.ResendCount++
ndsn := BaliseCounterAdd(cache.Dsn, IsLine12(train)) ndsn := BaliseCounterAdd(cache.Dsn, isLine12)
cache.Dsn = uint32(ndsn) cache.Dsn = uint32(ndsn)
return balise, ndsn, byte(cache.BaliseCount), byte(cache.MessageCounter) return balise, ndsn, byte(cache.BaliseCount), byte(cache.MessageCounter)
} }
} }
ndsn := BaliseCounterAdd(cache.Dsn, IsLine12(train)) ndsn := BaliseCounterAdd(cache.Dsn, isLine12)
return nil, ndsn, 0, 0 return nil, ndsn, 0, 0
} }
func FindBaliseByNotSend(train *state_proto.TrainState) (*state_proto.BTMState, byte, byte, byte) {
func FindBaliseByNotSend(cache *state_proto.TrainBtmCache, isLine12 bool) (*state_proto.BTMState, byte, byte, byte) {
baliseLock.Lock() baliseLock.Lock()
defer baliseLock.Unlock() defer baliseLock.Unlock()
cache := train.BtmBaliseCache
for _, btmCache := range cache.BaliseList { for _, btmCache := range cache.BaliseList {
if btmCache != nil && !btmCache.IsSend { if btmCache != nil && !btmCache.IsSend {
ndsn := BaliseCounterAdd(cache.Dsn, IsLine12(train)) ndsn := BaliseCounterAdd(cache.Dsn, isLine12)
cache.Dsn = uint32(ndsn) cache.Dsn = uint32(ndsn)
cache.ResendBaliseId = btmCache.BaliseId cache.ResendBaliseId = btmCache.BaliseId
return btmCache, ndsn, byte(cache.BaliseCount), byte(cache.MessageCounter) return btmCache, ndsn, byte(cache.BaliseCount), byte(cache.MessageCounter)
} }
} }
ndsn := BaliseCounterAdd(cache.Dsn, IsLine12(train)) ndsn := BaliseCounterAdd(cache.Dsn, isLine12)
return nil, ndsn, 0, 0 return nil, ndsn, 0, 0
} }
func ClearBalise(train *state_proto.TrainState) { func ClearBalise(train *state_proto.TrainState) {
baliseLock.Lock() baliseLock.Lock()
defer baliseLock.Unlock() defer baliseLock.Unlock()
train.BtmBaliseCache.BaliseList = make([]*state_proto.BTMState, 3) train.BtmBaliseCacheA.BaliseList = make([]*state_proto.BTMState, 3)
train.BtmBaliseCacheB.BaliseList = make([]*state_proto.BTMState, 3)
} }
// 11号线根据序列号查询 // 11号线根据序列号查询
func FindBaliseByMessageSerial(train *state_proto.TrainState, ms byte) (*state_proto.BTMState, byte, bool) { func FindBaliseByMessageSerial(cache *state_proto.TrainBtmCache, isLine12 bool, ms byte) (*state_proto.BTMState, byte, bool) {
baliseLock.Lock() baliseLock.Lock()
defer baliseLock.Unlock() defer baliseLock.Unlock()
cache := train.BtmBaliseCache
for _, btmCache := range cache.BaliseList { for _, btmCache := range cache.BaliseList {
if btmCache != nil { if btmCache != nil {
if btmCache.BaliseId == cache.ResendBaliseId { if btmCache.BaliseId == cache.ResendBaliseId {
if byte(btmCache.PackageDataSN) == ms { if byte(btmCache.PackageDataSN) == ms {
bt, dsn, _, _ := FindBaliseByNotSend(train) bt, dsn, _, _ := FindBaliseByNotSend(cache, isLine12)
return bt, dsn, true return bt, dsn, true
} else { } else {
ndsn := BaliseCounterAdd(cache.Dsn, IsLine12(train)) ndsn := BaliseCounterAdd(cache.Dsn, isLine12)
cache.Dsn = uint32(ndsn) cache.Dsn = uint32(ndsn)
return btmCache, ndsn, false return btmCache, ndsn, false
} }
@ -115,7 +115,7 @@ func FindBaliseByMessageSerial(train *state_proto.TrainState, ms byte) (*state_p
} }
} }
bt, dsn, _, _ := FindBaliseByNotSend(train) bt, dsn, _, _ := FindBaliseByNotSend(cache, isLine12)
return bt, dsn, true return bt, dsn, true
} }

View File

@ -122,7 +122,7 @@ func AtpLowPowerByte(d byte) bool {
// 列车速度位置报告 // 列车速度位置报告
type TrainSpeedPlaceReportMsg struct { type TrainSpeedPlaceReportMsg struct {
PulseCount1 float32 PulseCount1 float32
PulseCount2 float32 //PulseCount2 float32
} }
func (tp *TrainSpeedPlaceReportMsg) Encode(runDir uint16, s1, runRange uint32) []byte { func (tp *TrainSpeedPlaceReportMsg) Encode(runDir uint16, s1, runRange uint32) []byte {
@ -255,4 +255,7 @@ const (
DOOR_MODE_MM DOOR_MODE_MM
_ _
NOT_BREAK NOT_BREAK
//aa = 0x2e
//bb = 0x2f
cc = 0x2d
) )

View File

@ -164,11 +164,11 @@ func (b *BtmVobcClient) requestFramePackets(requestId string, req *message.BtmVo
if req.FrameStatus == message.REQ_FRAME_STATUS_ERROR { if req.FrameStatus == message.REQ_FRAME_STATUS_ERROR {
//抢答器错误,重新发送 //抢答器错误,重新发送
btmState, dsn, _, _ = can_btm.FindBaliseResend(train) btmState, dsn, _, _ = can_btm.FindBaliseResend(train.BtmBaliseCacheA, false)
} else { } else {
//判断 报文序列号与之前发送的 是否一致,不一致 //判断 报文序列号与之前发送的 是否一致,不一致
//如果一致返回新的应答器,如果不一致返回之前发送的应答器,如果不一致并且没有找到之前发送的应答器,则返回新应答器 //如果一致返回新的应答器,如果不一致返回之前发送的应答器,如果不一致并且没有找到之前发送的应答器,则返回新应答器
btmState, dsn, matcher = can_btm.FindBaliseByMessageSerial(train, req.MessageSerial) btmState, dsn, matcher = can_btm.FindBaliseByMessageSerial(train.BtmBaliseCacheA, false, req.MessageSerial)
if matcher { if matcher {
if btmState != nil { if btmState != nil {
//正常应答 //正常应答

View File

@ -88,3 +88,7 @@ func (c *TcpClient) Send(data []byte) error {
} }
return nil return nil
} }
func (c *TcpClient) RemoteInfo() net.Addr {
return c.conn.RemoteAddr()
}

View File

@ -46,7 +46,9 @@ func GetRunningServiceStates() *state_proto.SimulationThirdPartyApiService {
trueServices := tpas.FindAppendApiService() trueServices := tpas.FindAppendApiService()
if trueServices != nil && len(trueServices) > 0 { if trueServices != nil && len(trueServices) > 0 {
for _, trueService := range trueServices { for _, trueService := range trueServices {
collectServiceState(ss, trueService) if trueService != nil {
collectServiceState(ss, trueService)
}
} }
} }

View File

@ -1,6 +1,7 @@
package train_pc_sim package train_pc_sim
import ( import (
"fmt"
"joylink.club/bj-rtsts-server/dto/state_proto" "joylink.club/bj-rtsts-server/dto/state_proto"
"joylink.club/bj-rtsts-server/third_party/message" "joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/tcp" "joylink.club/bj-rtsts-server/third_party/tcp"
@ -13,10 +14,11 @@ type TrainPcReciverData struct {
clientKey string clientKey string
tcpClient *tcp.TcpClient tcpClient *tcp.TcpClient
pcSimManage TrainPcSimManage pcSimManage TrainPcSimManage
//trainInit bool state tpapi.ThirdPartyApiServiceState
state tpapi.ThirdPartyApiServiceState speedPlace *message.TrainSpeedPlaceReportMsg
speedPlace *message.TrainSpeedPlaceReportMsg train *state_proto.TrainState
train *state_proto.TrainState success bool
aPort bool
} }
func (rd *TrainPcReciverData) Name() string { func (rd *TrainPcReciverData) Name() string {
@ -35,17 +37,19 @@ func (d *TrainPcReciverData) readError(err error) {
slog.Error("连接车载pc仿真tcp服务断开", err) slog.Error("连接车载pc仿真tcp服务断开", err)
d.updateState(tpapi.ThirdPartyState_Broken) d.updateState(tpapi.ThirdPartyState_Broken)
d.tcpClient = nil d.tcpClient = nil
} }
func (d *TrainPcReciverData) ServiceDesc() string { func (d *TrainPcReciverData) ServiceDesc() string {
return d.clientKey if d.aPort {
return fmt.Sprintf("%v-A端", d.clientKey)
} else {
return fmt.Sprintf("%v-B端", d.clientKey)
}
} }
func (rd *TrainPcReciverData) receiverDataHandle(n int, data []byte) { func (rd *TrainPcReciverData) receiverDataHandle(n int, data []byte) {
receiveData := data[:n]
trainPcMsgs := message.TrainPcSimDecode(receiveData)
train := rd.train train := rd.train
//vs := train.VobcState
if train == nil { if train == nil {
slog.Error("车载输出数字量未找到连接车载pc仿真的列车") slog.Error("车载输出数字量未找到连接车载pc仿真的列车")
return return
@ -54,15 +58,20 @@ func (rd *TrainPcReciverData) receiverDataHandle(n int, data []byte) {
slog.Error("车载输出数字量,,列车未连接车载pc仿真") slog.Error("车载输出数字量,,列车未连接车载pc仿真")
return return
} }
//hexSourceData := hex.EncodeToString(receiveData) //a := rd.tcpClient.RemoteInfo()
//slog.Info(fmt.Sprintf("接受列车激活端:%v pc仿真接收数据%v", rd.clientKey, hexSourceData)) //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 { for _, baseMsg := range trainPcMsgs {
//slog.Info(fmt.Sprintf("pc仿真接收数据%v,类型:%X", hexSourceData, baseMsg.Type))
switch baseMsg.Type { switch baseMsg.Type {
//case RECIVE_TRAIN_CREATE_REMOVE: //case RECIVE_TRAIN_CREATE_REMOVE:
// pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0]) // pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0])
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR: case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR:
rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(train, baseMsg.Data)
rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(rd.aPort, rd.tcpClient, train, baseMsg.Data)
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK: case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK:
rd.pcSimManage.TrainPcSimDigitalReportHandle(train, baseMsg.Data) rd.pcSimManage.TrainPcSimDigitalReportHandle(train, baseMsg.Data)

View File

@ -16,10 +16,10 @@ import (
"time" "time"
) )
type TrainControlEvent struct { //type TrainControlEvent struct {
Type byte // Type byte
Data []byte // Data []byte
} //}
//var FireTrainControlEventType = ecs.NewEventType[TrainControlEvent]() //var FireTrainControlEventType = ecs.NewEventType[TrainControlEvent]()
@ -57,7 +57,7 @@ type TrainPcSimManage interface {
//获取列车模拟量数据 //获取列车模拟量数据
ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage
// TrainPcSimDigitalOutInfoHandle 4.4.1. 车载输出数字量信息报文内容 // TrainPcSimDigitalOutInfoHandle 4.4.1. 车载输出数字量信息报文内容
TrainPcSimDigitalOutInfoHandle(train *state_proto.TrainState, data []byte) TrainPcSimDigitalOutInfoHandle(aport bool, client *tcp.TcpClient, train *state_proto.TrainState, data []byte) bool
// TrainPcSimDigitalReportHandle 4.4.2. 车载输出数字反馈量信息报文内容 // TrainPcSimDigitalReportHandle 4.4.2. 车载输出数字反馈量信息报文内容
TrainPcSimDigitalReportHandle(train *state_proto.TrainState, data []byte) TrainPcSimDigitalReportHandle(train *state_proto.TrainState, data []byte)
FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState
@ -70,12 +70,15 @@ type TrainPcSimManage interface {
TrainBtmQuery2(train *state_proto.TrainState, data []byte) TrainBtmQuery2(train *state_proto.TrainState, data []byte)
} }
type trainPcSimService struct { type trainPcSimService struct {
state tpapi.ThirdPartyApiServiceState state tpapi.ThirdPartyApiServiceState
newPcSimclientMap map[string]*TrainPcReciverData //newPcSimclientMap map[string]*TrainPcReciverData
cancleContextFun context.CancelFunc
context context.Context newPcSimclientMap3 map[string][]*TrainPcReciverData
trainPcSimManage TrainPcSimManage
configs []config.VehiclePCSimConfig cancleContextFun context.CancelFunc
context context.Context
trainPcSimManage TrainPcSimManage
configs []config.VehiclePCSimConfig
} }
var ( var (
@ -113,17 +116,29 @@ func (d *trainPcSimService) ServiceDesc() string {
func FindTrainPcSimClientKey2(t *state_proto.TrainState) string { func FindTrainPcSimClientKey2(t *state_proto.TrainState) string {
return t.ConnState.TypeName return t.ConnState.TypeName
} }
func (d *trainPcSimService) findTrainConn(sta *state_proto.TrainState) (*TrainPcReciverData, error) { func (d *trainPcSimService) findTrainConn(sta *state_proto.TrainState) (*TrainPcReciverData, error) {
trainPcReciver := d.newPcSimclientMap[sta.ConnState.TypeName] rds := d.newPcSimclientMap3[sta.ConnState.TypeName]
if trainPcReciver == nil { if rds == nil {
return nil, fmt.Errorf("") return nil, fmt.Errorf("")
} }
return trainPcReciver, nil 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
}
func (d *trainPcSimService) findAllThirdPartState() []tpapi.ThirdPartyApiService { func (d *trainPcSimService) findAllThirdPartState() []tpapi.ThirdPartyApiService {
services := make([]tpapi.ThirdPartyApiService, 0) services := make([]tpapi.ThirdPartyApiService, 0)
for _, data := range d.newPcSimclientMap { for _, data := range d.newPcSimclientMap3 {
services = append(services, data) for _, rd := range data {
services = append(services, rd)
}
} }
return services return services
} }
@ -161,10 +176,13 @@ func (d *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2,
return return
default: default:
} }
if sd, err := d.findTrainConn(sta); err == nil {
/*if sd, err := d.findTrainConn(sta); err == nil {
sd.speedPlace.PulseCount1 += sta.DynamicState.Displacement
//sd.speedPlace.PulseCount2 = sd.speedPlace.PulseCount1
}*/
for _, sd := range d.findTrainAllConn(sta) {
sd.speedPlace.PulseCount1 += sta.DynamicState.Displacement sd.speedPlace.PulseCount1 += sta.DynamicState.Displacement
//sd.speedPlace.PulseCount1 += float32(uint32(h1 * 10))
sd.speedPlace.PulseCount2 = sd.speedPlace.PulseCount1
} }
if sta.TrainRunUp { if sta.TrainRunUp {
if sta.TrainEndsA.SpeedSensorEnableA { if sta.TrainEndsA.SpeedSensorEnableA {
@ -202,15 +220,22 @@ func (d *trainPcSimService) newCloseAllConn() {
} }
func (d *trainPcSimService) newCloseConn(clientKey string) { func (d *trainPcSimService) newCloseConn(clientKey string) {
rd := d.newPcSimclientMap[clientKey] rds := d.newPcSimclientMap3[clientKey]
if rds != nil {
for _, rd := range rds {
rd.tcpClient.Close()
rd.tcpClient = nil
rd.train = nil
rd.speedPlace = nil
}
}
/*rd := d.newPcSimclientMap[clientKey]
if rd != nil { if rd != nil {
rd.tcpClient.Close() rd.tcpClient.Close()
rd.tcpClient = nil rd.tcpClient = nil
rd.train = nil rd.train = nil
rd.speedPlace = nil rd.speedPlace = nil
//rd.trainInit = false }*/
//d.cancleContextFun()
}
} }
func (d *trainPcSimService) findConfig(configName string) (*config.VehiclePCSimConfig, error) { func (d *trainPcSimService) findConfig(configName string) (*config.VehiclePCSimConfig, error) {
@ -223,30 +248,47 @@ func (d *trainPcSimService) findConfig(configName string) (*config.VehiclePCSimC
return nil, fmt.Errorf("未找到对应的车载pc连接配置") return nil, fmt.Errorf("未找到对应的车载pc连接配置")
} }
func (d *trainPcSimService) initConn(clientKey string) error { func (d *trainPcSimService) initConn2(clientKey string) error {
rd := d.newPcSimclientMap[clientKey] 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 AB端配置均为打开", clientKey))
}
e1 := d.connServer(cfg.OpenA, cfg.APcSimIp, cfg.APcSimPort, rd1)
if e1 != nil {
return sys_error.New(fmt.Sprintf("配置:%v 端口A连接失败", clientKey))
}
e2 := d.connServer(cfg.OpenB, cfg.BPcSimIp, cfg.BPcSimPort, rd2)
if e2 != nil {
return sys_error.New(fmt.Sprintf("配置:%v 端口B连接失败", clientKey))
}
rd1.aPort = true
return nil
}
func (d *trainPcSimService) connServer(open bool, ip string, port uint32, rd *TrainPcReciverData) *sys_error.BusinessError {
if rd != nil && rd.tcpClient != nil && rd.tcpClient.IsConning() { if rd != nil && rd.tcpClient != nil && rd.tcpClient.IsConning() {
return nil return nil
} else { } else {
//rd.trainInit = false
rd.tcpClient = nil rd.tcpClient = nil
} }
cfg, cfgErr := d.findConfig(clientKey) if !open {
if cfgErr != nil { rd.success = false
errMsg := fmt.Sprintf("没找到对应的配置信息 key:%v", clientKey) return nil
//slog.Error(errMsg, cfgErr.Error())
rd.updateState(tpapi.ThirdPartyState_Broken)
return sys_error.New(errMsg, cfgErr)
} }
addr := fmt.Sprintf("%v:%v", cfg.PcSimIp, cfg.PcSimPort) addr := fmt.Sprintf("%v:%v", ip, port)
//slog.Info(addr, "连接.,...")
client2, err := tcp.StartTcpClient(addr, rd.receiverDataHandle, rd.readError) client2, err := tcp.StartTcpClient(addr, rd.receiverDataHandle, rd.readError)
if err != nil { if err != nil {
connErrMsg := fmt.Sprintf("车载pc连接失败 clientKey:%v", clientKey)
//slog.Error(connErrMsg, err.Error())
rd.updateState(tpapi.ThirdPartyState_Broken) rd.updateState(tpapi.ThirdPartyState_Broken)
return sys_error.New(connErrMsg, err)
} else { } else {
rd.success = true
rd.tcpClient = client2 rd.tcpClient = client2
} }
return nil return nil
@ -255,7 +297,8 @@ func (d *trainPcSimService) initConn(clientKey string) error {
func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) { func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
configs := pcSimManage.GetTrainPcSimConfig() configs := pcSimManage.GetTrainPcSimConfig()
d.newPcSimclientMap = make(map[string]*TrainPcReciverData) //d.newPcSimclientMap = make(map[string]*TrainPcReciverData)
d.newPcSimclientMap3 = make(map[string][]*TrainPcReciverData)
if len(configs) <= 0 { if len(configs) <= 0 {
slog.Info("车载pc仿真配置未开启") slog.Info("车载pc仿真配置未开启")
return return
@ -266,9 +309,16 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
closedCount++ closedCount++
} else { } else {
ck := c.ConfigName ck := c.ConfigName
pcReciver := &TrainPcReciverData{clientKey: ck, pcSimManage: pcSimManage} pcReceivers := make([]*TrainPcReciverData, 2)
pcReciver.updateState(tpapi.ThirdPartyState_Closed) for i := 0; i < 2; i++ {
d.newPcSimclientMap[ck] = pcReciver 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
} }
} }
if closedCount == len(configs) { if closedCount == len(configs) {
@ -285,8 +335,11 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
} }
func (d *trainPcSimService) Stop() { func (d *trainPcSimService) Stop() {
for _, data := range d.newPcSimclientMap {
data.updateState(tpapi.ThirdPartyState_Closed) for _, rds := range d.newPcSimclientMap3 {
for _, rd := range rds {
rd.updateState(tpapi.ThirdPartyState_Closed)
}
} }
if d.cancleContextFun != nil { if d.cancleContextFun != nil {
d.cancleContextFun() d.cancleContextFun()
@ -297,7 +350,7 @@ func (d *trainPcSimService) Stop() {
func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error { func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error {
clientKey := FindTrainPcSimClientKey2(train) clientKey := FindTrainPcSimClientKey2(train)
err := d.initConn(clientKey) err := d.initConn2(clientKey)
if err != nil { if err != nil {
d.newCloseConn(clientKey) d.newCloseConn(clientKey)
return err return err
@ -307,16 +360,23 @@ func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, i
data[0] = message.FLAG_CAMMAND_CREATE_TRAIN data[0] = message.FLAG_CAMMAND_CREATE_TRAIN
} }
msg := &message.TrainPcSimBaseMessage{Data: data, Type: message.RECIVE_TRAIN_CREATE_REMOVE} msg := &message.TrainPcSimBaseMessage{Data: data, Type: message.RECIVE_TRAIN_CREATE_REMOVE}
rd := d.newPcSimclientMap[clientKey] rds := d.newPcSimclientMap3[clientKey]
if rd != nil { if rds != nil {
initTrainErr := d.initTrain(rd, train, isCreate, msg) for index, rd := range rds {
if !isCreate { if rd != nil && rd.success {
d.newCloseConn(clientKey) 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 initTrainErr != nil { if !isCreate {
return initTrainErr d.newCloseConn(clientKey)
}
if initTrainErr != nil {
return initTrainErr
}
}
} }
} }
return nil return nil
} }
func (d *trainPcSimService) initTrain(rd *TrainPcReciverData, train *state_proto.TrainState, isCreate bool, trains *message.TrainPcSimBaseMessage) error { func (d *trainPcSimService) initTrain(rd *TrainPcReciverData, train *state_proto.TrainState, isCreate bool, trains *message.TrainPcSimBaseMessage) error {
@ -326,17 +386,21 @@ func (d *trainPcSimService) initTrain(rd *TrainPcReciverData, train *state_proto
train.PluseCount = &state_proto.SensorSpeedPulseCount{} train.PluseCount = &state_proto.SensorSpeedPulseCount{}
rd.train = train rd.train = train
tcc := train.Tcc tcc := train.Tcc
tcc.LineInitTimeStamp12 = 0 tcc.LineInitTimeStamp12PortA = 0
tcc.Line12ConnErr = false tcc.LineInitTimeStamp12PortB = 0
tcc.Line12ConnErrPortA = false
tcc.Line12ConnErrPortB = false
//tcc.LineInitTimeStamp12 = 0
//tcc.Line12ConnErr = false
if isCreate { if isCreate {
tmpMsgs := d.trainPcSimManage.ObtainTrainDigitalMockData(train) tmpMsgs := d.trainPcSimManage.ObtainTrainDigitalMockData(train)
msgs = append(msgs, tmpMsgs...) msgs = append(msgs, tmpMsgs...)
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{0x00}, Type: message.RECIVE_TRAIN_DOOR_MODE}) //门模式 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}) //清空应答器 msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.RECIVE_TRAIN_BTN_CLEAR_ALL_PRE_DATA}) //清空应答器
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.SENDER_TRAIN_TC_ACTIVE}) //清空应答器
} else { } else {
train.VobcState.Tc1Active = false train.VobcState.Tc1Active = false
train.VobcState.Tc2Active = false train.VobcState.Tc2Active = false
for _, key := range tcc.DriverKey { for _, key := range tcc.DriverKey {
key.Val = false key.Val = false
} }
@ -357,47 +421,52 @@ func (d *trainPcSimService) initTrain(rd *TrainPcReciverData, train *state_proto
// 依据文档80ms发送列车速度位置 // 依据文档80ms发送列车速度位置
func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) { func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
for { for range time.Tick(time.Millisecond * 80) {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
default: default:
} }
trains := d.trainPcSimManage.GetConnTrain2() trains := d.trainPcSimManage.GetConnTrain2()
for _, train := range trains { for _, train := range trains {
if train.ConnState.Conn && train.PluseCount != nil { if train.ConnState.Conn && train.PluseCount != nil {
trainClient, trainDataErr := d.findTrainConn(train) trainClients := d.newPcSimclientMap3[train.ConnState.TypeName]
if trainDataErr != nil { for _, trainClient := range trainClients {
slog.Error(fmt.Sprintf("pc仿真速度位置未找到对应的列车 id:%v", train.Id)) if trainClient.success {
continue if trainClient.speedPlace == nil {
} slog.Error(fmt.Sprintf("pc仿真速度位置脉冲对象为空 列车id:%v", train.Id))
if trainClient.speedPlace == nil { continue
slog.Error(fmt.Sprintf("pc仿真速度位置脉冲对象为空 列车id:%v", train.Id)) }
continue connState := tpapi.ThirdPartyState_Normal
if trainClient.aPort && train.Tcc.Line12ConnErrPortA {
connState = tpapi.ThirdPartyState_Broken
} else if trainClient.aPort == false && train.Tcc.Line12ConnErrPortB {
connState = tpapi.ThirdPartyState_Broken
}
/*if train.Tcc.Line12ConnErr {
connState = tpapi.ThirdPartyState_Broken
}*/
trainClient.updateState(connState)
s1, speed := d.pluseSpeed(train)
runDir := uint16(2)
if train.VobcState.DirectionForward {
runDir = 1
}
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()
slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,A端:%v,列车速度:%v,计数脉冲: %v,累计里程: %v ,发送数据:%v", train.Id, trainClient.aPort, speed, s1, trainClient.speedPlace.PulseCount1, hex.EncodeToString(dataCode)), trainClient.aPort)
err := trainClient.tcpClient.Send(dataCode)
if err != nil {
slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode)))
}
}
} }
connState := tpapi.ThirdPartyState_Normal
if train.Tcc.Line12ConnErr {
connState = tpapi.ThirdPartyState_Broken
}
trainClient.updateState(connState)
s1, speed := d.pluseSpeed(train)
runDir := uint16(2)
if train.VobcState.DirectionForward {
runDir = 1
}
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()
slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,列车速度:%v,计数脉冲: %v,累计里程: %v ,发送数据:%v", train.Id, speed, s1, trainClient.speedPlace.PulseCount1, hex.EncodeToString(dataCode)))
err := trainClient.tcpClient.Send(dataCode)
if err != nil {
slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode)))
}
} }
} }
time.Sleep(time.Millisecond * 80)
} }
} }
@ -408,22 +477,25 @@ func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
slog.Error(fmt.Sprintf("发送驾驶激活未找到对应的列车连接列车id%v", train.Id)) slog.Error(fmt.Sprintf("发送驾驶激活未找到对应的列车连接列车id%v", train.Id))
return return
} }
vobc := train.VobcState vobc := train.VobcState
msg := &message.TrainPcSimBaseMessage{} msg := &message.TrainPcSimBaseMessage{}
if train.TrainRunUp { /*if train.TrainRunUp {
if vobc.Tc1Active { if vobc.Tc1Active {
msg.Type = message.SENDER_TRAIN_TC_ACTIVE msg.Type = message.SENDER_TRAIN_TC_ACTIVE
} else if vobc.Tc1Active == false { } else if vobc.Tc1Active == false {
msg.Type = message.SENDER_TRAIN_TC_NOT_ACTIVE msg.Type = message.SENDER_TRAIN_TC_NOT_ACTIVE
} }
} else if !train.TrainRunUp { } else if !train.TrainRunUp {
if vobc.Tc2Active { if vobc.Tc1Active {
msg.Type = message.SENDER_TRAIN_TC_ACTIVE msg.Type = message.SENDER_TRAIN_TC_ACTIVE
} else if vobc.Tc2Active == false { } else if vobc.Tc1Active == false {
msg.Type = message.SENDER_TRAIN_TC_NOT_ACTIVE msg.Type = message.SENDER_TRAIN_TC_NOT_ACTIVE
} }
}*/
if vobc.Tc1Active || vobc.Tc2Active {
msg.Type = message.SENDER_TRAIN_TC_ACTIVE
} else {
msg.Type = message.SENDER_TRAIN_TC_NOT_ACTIVE
} }
msgs := make([]byte, 0) msgs := make([]byte, 0)
if msg.Type == message.SENDER_TRAIN_TC_ACTIVE { if msg.Type == message.SENDER_TRAIN_TC_ACTIVE {

View File

@ -77,6 +77,7 @@ func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, conf
calctailOffset := calcTrailTailOffset(loffset, status.TrainLength, up) calctailOffset := calcTrailTailOffset(loffset, status.TrainLength, up)
// 车尾位置 // 车尾位置
tailLink, tailDeviceId, tailDevicePort, tailLOffset, tailDeviceOffset, _, e1 := CalcInitializeLink(vs, linkId, calctailOffset, up) tailLink, tailDeviceId, tailDevicePort, tailLOffset, tailDeviceOffset, _, e1 := CalcInitializeLink(vs, linkId, calctailOffset, up)
if e1 != nil { if e1 != nil {
panic(sys_error.New("添加列车失败,列车车尾占用位置计算出错", e1)) panic(sys_error.New("添加列车失败,列车车尾占用位置计算出错", e1))
} }
@ -95,7 +96,8 @@ func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, conf
status.TailDeviceId = vs.GetComIdByUid(tailDeviceId) status.TailDeviceId = vs.GetComIdByUid(tailDeviceId)
status.TailOffset = tailDeviceOffset status.TailOffset = tailDeviceOffset
status.TailDevicePort = tailDevicePort status.TailDevicePort = tailDevicePort
status.BtmBaliseCache = &state_proto.TrainBtmCache{BaliseList: make([]*state_proto.BTMState, 3)} status.BtmBaliseCacheA = &state_proto.TrainBtmCache{BaliseList: make([]*state_proto.BTMState, 3)}
status.BtmBaliseCacheB = &state_proto.TrainBtmCache{BaliseList: make([]*state_proto.BTMState, 3)}
//初始化列车参数状态 //初始化列车参数状态
createOrUpdateStateDynamicConfig(status, configTrainData, trainEndsA, trainEndsB) createOrUpdateStateDynamicConfig(status, configTrainData, trainEndsA, trainEndsB)
@ -168,7 +170,10 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
train.ConnState.ConnType = ct.ConnType train.ConnState.ConnType = ct.ConnType
train.ConnState.TypeName = ct.TypeName train.ConnState.TypeName = ct.TypeName
if ct.ConnType == state_proto.TrainConnState_PC_SIM { if ct.ConnType == state_proto.TrainConnState_PC_SIM {
train.Tcc.LineInitTimeStamp12 = 0 //train.Tcc.LineInitTimeStamp12 = 0
train.Tcc.LineInitTimeStamp12PortA = 0
train.Tcc.LineInitTimeStamp12PortB = 0
err := TrainPcSimConnOrRemoveHandle(train, true) err := TrainPcSimConnOrRemoveHandle(train, true)
if err != nil { if err != nil {
train.ConnState.Conn = false train.ConnState.Conn = false
@ -324,6 +329,8 @@ func UpdateTrainStateByDynamics(vs *VerifySimulation, trainId string, info *mess
//calctailOffset := calcTrailTailOffset(outLinkOffset, int64(info.Len), info.Up) //calctailOffset := calcTrailTailOffset(outLinkOffset, int64(info.Len), info.Up)
calctailOffset := calcTrailTailOffset(outLinkOffset, int64(info.Len), trainHeadActUp) calctailOffset := calcTrailTailOffset(outLinkOffset, int64(info.Len), trainHeadActUp)
tailLinkId, tailDeviceId, tailDevicePort, tailLinkOffset, tailOffset, _, e2 := CalcInitializeLink(vs, outLinkId, calctailOffset, !info.Up) tailLinkId, tailDeviceId, tailDevicePort, tailLinkOffset, tailOffset, _, e2 := CalcInitializeLink(vs, outLinkId, calctailOffset, !info.Up)
tailUp, _ := QueryUpAndABByDevice(vs.Repo, tailDeviceId, tailDevicePort, sta.TrainRunUp)
if e2 != nil { if e2 != nil {
panic(sys_error.New("动力学传输数据:列车车尾位置计算出错", e2)) panic(sys_error.New("动力学传输数据:列车车尾位置计算出错", e2))
} }
@ -336,8 +343,12 @@ func UpdateTrainStateByDynamics(vs *VerifySimulation, trainId string, info *mess
sta.OldLinkOffset = outLinkOffset sta.OldLinkOffset = outLinkOffset
sta.OldLink = outLinkId sta.OldLink = outLinkId
} }
if sta.OldTailLinkOffset == 0 {
sta.OldTailLinkOffset = tailLinkOffset
sta.OldTailLink = tailLinkId
}
updateTrainBtmPosition(vs, info, sta, outLinkId, outLinkOffset) updateTrainBtmPosition(vs, info, sta, outLinkId, outLinkOffset, tailUp, tailLinkId, tailLinkOffset)
//slog.Info(fmt.Sprintf("动力学,当前速度(米/秒):%v,加速度:%v,位移距离:%v", info.Speed, info.Acceleration, info.Displacement)) //slog.Info(fmt.Sprintf("动力学,当前速度(米/秒):%v,加速度:%v,位移距离:%v", info.Speed, info.Acceleration, info.Displacement))
if sta.OldLink != outLinkId { if sta.OldLink != outLinkId {
sta.OldLink = outLinkId sta.OldLink = outLinkId
@ -399,34 +410,25 @@ func updateTrainActiveDirFromDynamic(vs *VerifySimulation, info *message.Dynamic
} }
// 根据列车位置修改列车应答器 // 根据列车位置修改列车应答器
func updateTrainBtmPosition(vs *VerifySimulation, info *message.DynamicsTrainInfo, sta *state_proto.TrainState, outLinkId string, outLinkOffset int64) { func updateTrainBtmPosition(vs *VerifySimulation, info *message.DynamicsTrainInfo, sta *state_proto.TrainState, outLinkId string, outLinkOffset int64, tailUp bool, tailLinkId string, tailLinkOffset int64) {
// 更新BTM中列车位置信息 // 更新BTM中列车位置信息
//isup := sta.TrainActiveDirection == 1 //isup := sta.TrainActiveDirection == 1
can_btm.Default().HandleTrainHeadPositionInfoForTrain(vs.World, sta.BtmBaliseCache, &fi.TrainHeadPositionInfo{ can_btm.Default().HandleTrainHeadPositionInfoForTrain(vs.World, sta, &fi.TrainHeadPositionInfo{
TrainId: sta.Id, TrainId: sta.Id,
Up: info.Up, Up: info.Up,
Link: outLinkId, Link: outLinkId,
LinkOffset: outLinkOffset, LinkOffset: outLinkOffset,
Speed: info.Speed, Speed: info.Speed,
Acceleration: info.Acceleration, Acceleration: info.Acceleration,
OldLinkOffset: sta.OldLinkOffset, OldLinkOffset: sta.OldLinkOffset,
OldLink: sta.OldLink, OldLink: sta.OldLink,
IsLine12: can_btm.IsLine12(sta), TailUp: tailUp,
TailLink: tailLinkId,
TailLinkOffset: tailLinkOffset,
OldTailLink: sta.OldTailLink,
OldTailLinkOffset: sta.OldTailLinkOffset,
IsLine12: can_btm.IsLine12(sta),
}) })
/*can_btm.Default().HandleTrainHeadPositionInfo(vs.World, sta.VobcBtm, &fi.TrainHeadPositionInfo{
TrainId: sta.Id,
Up: info.Up,
Link: outLinkId,
LinkOffset: outLinkOffset,
Speed: info.Speed,
Acceleration: info.Acceleration,
OldLinkOffset: sta.OldLinkOffset,
OldLink: sta.OldLink,
})*/
/* state := can_btm.Default().GetState()
if sta.BtmState == nil || sta.BtmState.BaliseId != state.BaliseId {
sta.BtmState = &state
}*/
} }

View File

@ -12,9 +12,11 @@ import (
"joylink.club/bj-rtsts-server/third_party/can_btm" "joylink.club/bj-rtsts-server/third_party/can_btm"
"joylink.club/bj-rtsts-server/third_party/electrical_machinery" "joylink.club/bj-rtsts-server/third_party/electrical_machinery"
"joylink.club/bj-rtsts-server/third_party/message" "joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/tcp"
train_pc_sim "joylink.club/bj-rtsts-server/third_party/train_pc_sim" train_pc_sim "joylink.club/bj-rtsts-server/third_party/train_pc_sim"
"log/slog" "log/slog"
"math" "math"
"strings"
"time" "time"
) )
@ -43,7 +45,7 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
baseMsg = trainControlButton(sta, ct.DeviceId, ct.ControlButton.Active, tccGraphicData) baseMsg = trainControlButton(sta, ct.DeviceId, ct.ControlButton.Active, tccGraphicData)
} else if ct.ControlType == request_proto.TrainControl_DRIVER_KEY_SWITCH { } else if ct.ControlType == request_proto.TrainControl_DRIVER_KEY_SWITCH {
baseMsg = trainControlDriverKey(sta, ct.DriverKey, ct.DeviceId, tccGraphicData) baseMsg = trainControlDriverKey(sta, ct.DriverKey, ct.DeviceId, tccGraphicData)
train_pc_sim.Default().SendDriverActive(sta) //train_pc_sim.Default().SendDriverActive(sta)
} else if ct.ControlType == request_proto.TrainControl_DIRECTION_KEY_SWITCH { } else if ct.ControlType == request_proto.TrainControl_DIRECTION_KEY_SWITCH {
baseMsg = trainControlDirKey(sta.DynamicState.Speed, vobc, tcc, ct.SwitchKey, ct.DeviceId, tccGraphicData) baseMsg = trainControlDirKey(sta.DynamicState.Speed, vobc, tcc, ct.SwitchKey, ct.DeviceId, tccGraphicData)
//此处先注释,根据现场调试情况 2024-4-16 //此处先注释,根据现场调试情况 2024-4-16
@ -96,10 +98,8 @@ func trainControlButton(train *state_proto.TrainState, deviceId uint32, active b
return controlAtpBtn(vobc, active, btn) return controlAtpBtn(vobc, active, btn)
case KZM, KYM: //开左门按钮 case KZM, KYM: //开左门按钮
return controlDoorOpenBtn(vobc, active, btn, graphicBtn.Code == KZM, true) return controlDoorOpenBtn(vobc, active, btn, graphicBtn.Code == KZM, true)
case GZM, GYM: //关左门按钮 case GZM, GYM: //关左门按钮
return controlDoorCloseBtn(vobc, active, btn, graphicBtn.Code == GZM, true) return controlDoorCloseBtn(vobc, active, btn, graphicBtn.Code == GZM, true)
case ZF: //折返按钮 case ZF: //折返按钮
return controlReverseBtn(vobc, active, btn) return controlReverseBtn(vobc, active, btn)
case QZMYX: //强制门允许 case QZMYX: //强制门允许
@ -410,7 +410,15 @@ func trainControlDriverKey(train *state_proto.TrainState, request *request_proto
if addNew { if addNew {
tcc.DriverKey = append(tcc.DriverKey, &state_proto.TrainControlState_DriverKeySwitch{Id: deviceId, Val: request.Val}) tcc.DriverKey = append(tcc.DriverKey, &state_proto.TrainControlState_DriverKeySwitch{Id: deviceId, Val: request.Val})
} }
return []message.TrainPcSimBaseMessage{{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.KEY_STATE, message.IsTrue(request.Val)}}} tce := make([]message.TrainPcSimBaseMessage, 0)
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.KEY_STATE, message.IsTrue(request.Val)}})
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DRIVER_ACTIVE_REPORT, message.IsTrue(request.Val)}})
if request.Val == false {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{0x2d, 0}})
}
return tce
} }
func trainDoorModeChangeHandle(vobc *state_proto.TrainVobcState, tcc *state_proto.TrainControlState, request *request_proto.TrainControl_SwitchKeyChange, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage { func trainDoorModeChangeHandle(vobc *state_proto.TrainVobcState, tcc *state_proto.TrainControlState, request *request_proto.TrainControl_SwitchKeyChange, deviceId uint32, tccGraphic *data_proto.TccGraphicStorage) []message.TrainPcSimBaseMessage {
@ -607,18 +615,26 @@ func (s *VerifySimulation) FindConnTrain(ct state_proto.TrainConnState_TrainConn
} }
// 反馈atp输出数字量数据 // 反馈atp输出数字量数据
func (s *VerifySimulation) reportTrainMockInitMsg(train *state_proto.TrainState, data1, data3 byte) { func (s *VerifySimulation) reportTrainMockInitMsg(aport bool, client *tcp.TcpClient, train *state_proto.TrainState, data1, data3 byte) {
vobc := train.VobcState vobc := train.VobcState
tcc := train.Tcc tcc := train.Tcc
tce := make([]message.TrainPcSimBaseMessage, 0) tce := make([]message.TrainPcSimBaseMessage, 0)
tcc.Line12ConnErr = false initTimeStamp := tcc.LineInitTimeStamp12PortA
//initResult := trainInit connErr := tcc.Line12ConnErrPortA
initConn := tcc.TrainConnInitComplatePortA
if vobc.Tc2Active {
initTimeStamp = tcc.LineInitTimeStamp12PortB
connErr = tcc.Line12ConnErrPortB
initConn = tcc.TrainConnInitComplatePortB
}
//tcc.Line12ConnErr = false
if vobc.Tc1Active || vobc.Tc2Active { if vobc.Tc1Active || vobc.Tc2Active {
state := message.GetBit(data1, 3) state := message.GetBit(data1, 3)
//if trainInit { if /* vobc.TrainConnInitComplate*/ initConn {
if vobc.TrainConnInitComplate {
if data1 == 0 { if data1 == 0 {
tcc.Line12ConnErr = true //tcc.Line12ConnErr = true
connErr = true
} }
if state == 0 { if state == 0 {
jjzdBtn := tcc.Buttons[JJZD] jjzdBtn := tcc.Buttons[JJZD]
@ -630,36 +646,126 @@ func (s *VerifySimulation) reportTrainMockInitMsg(train *state_proto.TrainState,
tce = append(tce, ebTce...) tce = append(tce, ebTce...)
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}}) tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_TRACTION_CUTED, 1}}) tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_TRACTION_CUTED, 1}})
} else {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
} }
} else { } else {
//initResult = false initConn = true
vobc.TrainConnInitComplate = true if initTimeStamp <= 0 {
if tcc.LineInitTimeStamp12 <= 0 { initTimeStamp = time.Now().Add(time.Second * 6).Unix()
tcc.LineInitTimeStamp12 = time.Now().Add(time.Second * 6).Unix()
} }
if tcc.LineInitTimeStamp12 > time.Now().Unix() { if initTimeStamp > time.Now().Unix() {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}}) tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
initData := s.ObtainTrainDigitalMockDataForStatus(train) initData := s.ObtainTrainDigitalMockDataForStatus(train)
tce = append(tce, initData...) tce = append(tce, initData...)
//initResult = false if aport {
vobc.TrainConnInitComplate = false tcc.ActiveTrainA = true
} else {
tcc.ActiveTrainB = true
}
initConn = false
} }
} /*if vobc.LineInitTimeStamp12 <= 0 {
vobc.LineInitTimeStamp12 = time.Now().Add(time.Second * 6).Unix()
}*/
/*if tcc.LineInitTimeStamp12 > time.Now().Unix() {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
initData := s.ObtainTrainDigitalMockDataForStatus(train)
tce = append(tce, initData...)
vobc.TrainConnInitComplate = false
}*/
}
if vobc.Tc1Active {
tcc.LineInitTimeStamp12PortA = initTimeStamp
tcc.Line12ConnErrPortB = connErr
tcc.TrainConnInitComplatePortA = initConn
} else if vobc.Tc2Active {
tcc.LineInitTimeStamp12PortA = initTimeStamp
tcc.Line12ConnErrPortB = connErr
tcc.TrainConnInitComplatePortB = initConn
}
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DRIVER_ACTIVE_REPORT, 1}})
//驾驶室激活反馈 //驾驶室激活反馈
if message.GetBit(data3, 3) == 0 { if message.GetBit(data3, 3) == 0 {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DRIVER_ACTIVE_REPORT, 1}}) act := byte(0)
if vobc.Tc1Active || vobc.Tc2Active {
act = 1
}
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DRIVER_ACTIVE_REPORT, act}})
} }
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_INTEGRITY, 1}}) tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_INTEGRITY, 1}})
} }
train_pc_sim.Default().SendTrainControlMsg(train, tce) train_pc_sim.Default().SendTrainControlMsg(train, tce)
//return initResult //return initResult
} }
func (s *VerifySimulation) reportTrainMockInitMsg2(aport, act, initConn bool, initTimeStamp int64, train *state_proto.TrainState, data1, data3 byte) (int64, bool, bool, []message.TrainPcSimBaseMessage) {
tcc := train.Tcc
tce := make([]message.TrainPcSimBaseMessage, 0)
connErr := false
state := message.GetBit(data1, 3)
//slog.Info(fmt.Sprintf("act:%v ,t1:%v ,a1 :%v,t2:%v,a2:%v,init:%v,ts:%v", act, train.VobcState.Tc1Active, tcc.ActiveTrainA, train.VobcState.Tc2Active, tcc.ActiveTrainB, initConn, initTimeStamp), aport)
if message.GetBit(data3, 3) == 0 {
actt := byte(0)
if act {
actt = 1
}
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DRIVER_ACTIVE_REPORT, actt}})
}
if act == false {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
//tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_INTEGRITY, 1}})
return initTimeStamp, initConn, false, tce
}
if initConn {
if data1 == 0 {
connErr = true
}
if state == 0 {
slog.Info("列车紧急制动%v", aport)
jjzdBtn := tcc.Buttons[JJZD]
ebTce := controlEBBtn(train, true, jjzdBtn)
tce = append(tce, ebTce...)
} else if message.GetBit(data1, 0) == 0 {
slog.Info(fmt.Sprintf("列车紧切牵引%v ,state :%v", aport, state))
jjzdBtn := tcc.Buttons[JJZD]
ebTce := controlEBBtn(train, true, jjzdBtn)
tce = append(tce, ebTce...)
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.TRAIN_TRACTION_CUTED, 1}})
}
} else {
initConn = true
if initTimeStamp <= 0 {
initTimeStamp = time.Now().Add(time.Second * 6).Unix()
}
if initTimeStamp > time.Now().Unix() {
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
initData := s.ObtainTrainDigitalMockDataForStatus(train)
tce = append(tce, initData...)
if aport {
tcc.ActiveTrainA = true
} else if aport == false {
tcc.ActiveTrainB = true
}
initConn = false
}
}
return initTimeStamp, initConn, connErr, tce
}
func trainAtoLevel(at3, at2, at1 bool) state_proto.TrainVobcState_AtoStepLevel { func trainAtoLevel(at3, at2, at1 bool) state_proto.TrainVobcState_AtoStepLevel {
switch { switch {
case at3 == false && at2 == false && at1 == true: case at3 == false && at2 == false && at1 == true:
return state_proto.TrainVobcState_ATO_STEP_LEVEL_1 return state_proto.TrainVobcState_ATO_STEP_LEVEL_1
case at3 == false && at2 == true && at1 == true: case at3 == false && at2 == true && at1 == true:
return state_proto.TrainVobcState_ATO_STEP_LEVEL_2 return state_proto.TrainVobcState_ATO_STEP_LEVEL_2
case at3 == false && at2 == true && at1 == false: case at3 == false && at2 == true && at1 == false:
@ -676,31 +782,84 @@ func trainAtoLevel(at3, at2, at1 bool) state_proto.TrainVobcState_AtoStepLevel {
return state_proto.TrainVobcState_ATO_STEP_LEVEL_NONE return state_proto.TrainVobcState_ATO_STEP_LEVEL_NONE
} }
} }
func (s *VerifySimulation) shuziliang(aport bool, client *tcp.TcpClient, baseMessage []message.TrainPcSimBaseMessage) {
for _, msg := range baseMessage {
dd := msg.Encode()
//slog.Info(fmt.Sprintf("发送列车控制信息:%x", dd), aport)
client.Send(dd)
}
}
// 4.4.1. 车载输出数字量信息报文内容 // 4.4.1. 车载输出数字量信息报文内容
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(train *state_proto.TrainState, data []byte) { func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(aport bool, client *tcp.TcpClient, train *state_proto.TrainState, data []byte) bool {
/* slog.Info("开始接受atp输出模拟量==============")
for i, d := range data {
dd := &strings.Builder{}
for j := 0; j < 8; j++ {
dd.WriteString(fmt.Sprintf(" bit%v val:%v , ", j, message.GetBit(d, uint(j))))
}
slog.Info(fmt.Sprintf("接受atp模拟量id:%v,data:%b,bits:%v", i, d, dd.String()))
dd := &strings.Builder{}
//slog.Info("开始接受atp输出模拟量==============%v", aport)
/* for i, d := range data {
for j := 0; j < 8; j++ {
dd.WriteString(fmt.Sprintf(" bit%v val:%v , ", j, message.GetBit(d, uint(j))))
} }
slog.Info("结束接受atp输出模拟量eeeeeeeeeeeeeeeeee")*/ slog.Info(fmt.Sprintf("接受atp模拟量id:%v,data:%b,bits:%v", i, d, dd.String()))
s.reportTrainMockInitMsg(train, data[4], data[1]) }*/
vobc := train.VobcState d := data[4]
trainPcSimDigitalOutInfoHandleCode7_0(data[4], vobc) for j := 0; j < 8; j++ {
trainPcSimDigitalOutInfoHandleCode15_8(data[3], vobc) dd.WriteString(fmt.Sprintf(" bit%v val:%v , ", j, message.GetBit(d, uint(j))))
trainPcSimDigitalOutInfoHandleCode23_16(data[2], vobc)
trainPcSimDigitalOutInfoHandleCode31_24(data[1], vobc)
trainPcSimDigitalOutInfoHandleCode39_32(data[0], vobc)
if vobc.Ato {
vobc.AtoStepLevel = trainAtoLevel(vobc.AtoTractionCommand3, vobc.AtoTractionCommand2, vobc.AtoTractionCommand1)
} }
//return initResult //slog.Info(fmt.Sprintf("%v", dd.String()), aport)
//slog.Info("结束接受atp输出模拟量eeeeeeeeeeeeeeeeee", aport)
//s.reportTrainMockInitMsg(aport, client, train, data[4], data[1])
vobc := train.VobcState
if aport {
ts, initConn, connErr, tce := s.reportTrainMockInitMsg2(aport, vobc.Tc1Active, train.Tcc.TrainConnInitComplatePortA, train.Tcc.LineInitTimeStamp12PortA, train, data[4], data[1])
if train.Tcc.ActiveTrainA {
train.Tcc.LineInitTimeStamp12PortA = ts
train.Tcc.TrainConnInitComplatePortA = initConn
train.Tcc.Line12ConnErrPortA = connErr
//slog.Info("发送数字量")
s.shuziliang(aport, client, tce)
}
/* if initConn {
train.Tcc.TrainConnInitComplatePortB = initConn
train.Tcc.LineInitTimeStamp12PortB = ts
}
if train.Tcc.ActiveTrainA {
train.Tcc.ActiveTrainB = train.Tcc.ActiveTrainA
}
*/
if train.VobcState.Tc1Active {
trainPcSimDigitalOutInfoHandleCode7_0(data[4], vobc)
trainPcSimDigitalOutInfoHandleCode15_8(data[3], vobc)
trainPcSimDigitalOutInfoHandleCode23_16(data[2], vobc)
trainPcSimDigitalOutInfoHandleCode31_24(data[1], vobc)
trainPcSimDigitalOutInfoHandleCode39_32(data[0], vobc)
if vobc.Ato {
vobc.AtoStepLevel = trainAtoLevel(vobc.AtoTractionCommand3, vobc.AtoTractionCommand2, vobc.AtoTractionCommand1)
}
}
} else {
ts, initConn, connErr, tce := s.reportTrainMockInitMsg2(aport, vobc.Tc2Active, train.Tcc.TrainConnInitComplatePortB, train.Tcc.LineInitTimeStamp12PortB, train, data[4], data[1])
if train.Tcc.ActiveTrainB {
train.Tcc.LineInitTimeStamp12PortB = ts
train.Tcc.TrainConnInitComplatePortB = initConn
train.Tcc.Line12ConnErrPortB = connErr
s.shuziliang(aport, client, tce)
}
if train.VobcState.Tc2Active {
trainPcSimDigitalOutInfoHandleCode7_0(data[4], vobc)
trainPcSimDigitalOutInfoHandleCode15_8(data[3], vobc)
trainPcSimDigitalOutInfoHandleCode23_16(data[2], vobc)
trainPcSimDigitalOutInfoHandleCode31_24(data[1], vobc)
trainPcSimDigitalOutInfoHandleCode39_32(data[0], vobc)
if vobc.Ato {
vobc.AtoStepLevel = trainAtoLevel(vobc.AtoTractionCommand3, vobc.AtoTractionCommand2, vobc.AtoTractionCommand1)
}
}
}
return true
} }
func trainPcSimDigitalOutInfoHandleCode39_32(d byte, vobc *state_proto.TrainVobcState) { func trainPcSimDigitalOutInfoHandleCode39_32(d byte, vobc *state_proto.TrainVobcState) {
@ -856,10 +1015,14 @@ func (s *VerifySimulation) TrainBtmQuery2(train *state_proto.TrainState, data []
} }
var balise *state_proto.BTMState var balise *state_proto.BTMState
var dsn, bc, mc byte var dsn, bc, mc byte
btmCache := train.BtmBaliseCacheA
if train.VobcState.Tc2Active {
btmCache = train.BtmBaliseCacheB
}
if atpReq.IsResend() { if atpReq.IsResend() {
balise, dsn, bc, mc = can_btm.FindBaliseResend(train) balise, dsn, bc, mc = can_btm.FindBaliseResend(btmCache, true)
} else { } else {
balise, dsn, bc, mc = can_btm.FindBaliseByNotSend(train) balise, dsn, bc, mc = can_btm.FindBaliseByNotSend(btmCache, true)
} }
cl := clock(atpReq) cl := clock(atpReq)
btmRepFrame := createBtmStatus(trainAtm.CanId.ID4, balise, atpReq, cl, dsn, bc, mc) btmRepFrame := createBtmStatus(trainAtm.CanId.ID4, balise, atpReq, cl, dsn, bc, mc)
@ -929,11 +1092,11 @@ func (s *VerifySimulation) ObtainTrainDigitalMockDataForStatus(train *state_prot
vs := train.VobcState vs := train.VobcState
if vs.Tc1Active || vs.Tc2Active { if vs.Tc1Active || vs.Tc2Active {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.KEY_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //钥匙激活 msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.KEY_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //钥匙激活
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DRIVER_ACTIVE_REPORT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性 //msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DRIVER_ACTIVE_REPORT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
} else { } /* else {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DRIVER_ACTIVE_REPORT, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性 msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DRIVER_ACTIVE_REPORT, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
} }*/
if vs.BrakeForce == 0 { if vs.BrakeForce == 0 {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_TO_ZERO, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车制动状态 msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_TO_ZERO, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车制动状态
} }