折返
This commit is contained in:
parent
39b4ffb633
commit
f9ffa1cf10
@ -161,11 +161,15 @@ type VehiclePCSimConfig2 struct {
|
||||
}
|
||||
|
||||
type VehiclePCSimConfig struct {
|
||||
Open bool `json:"open" description:"是否开启"`
|
||||
//TrainEnds bool `json:"trainEnds" description:"列车端点A?"`
|
||||
ConfigName string `json:"configName" description:"连接名称"`
|
||||
Open bool `json:"open" description:"是否开启"`
|
||||
PcSimIp string `json:"pcSimIp" description:"pc仿真平台通信ip"`
|
||||
PcSimPort uint32 `json:"pcSimPort" description:"pc仿真平台通信端口"`
|
||||
OpenA bool `json:"openA" description:"是否开启A端"`
|
||||
APcSimIp string `json:"apcSimIp" description:"pc仿真平台通信ip A端"`
|
||||
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:"本地测试端口"`
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@ server:
|
||||
# 数据源
|
||||
datasource:
|
||||
# 数据库访问url
|
||||
# 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: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
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
@ -33,7 +33,7 @@ logging:
|
||||
# 消息配置
|
||||
messaging:
|
||||
mqtt:
|
||||
# address: tcp://127.0.0.1:1883
|
||||
address: tcp://192.168.33.233:1883
|
||||
address: tcp://127.0.0.1:1883
|
||||
# address: tcp://192.168.33.233:1883
|
||||
username: rtsts_service
|
||||
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
|
@ -45,7 +45,7 @@ func checkRunConfig(jsonConfigStr string) *sys_error.BusinessError {
|
||||
checkSameMap := make(map[string]bool)
|
||||
for _, simConfig := range configMap.PcSimConfigs {
|
||||
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] {
|
||||
return sys_error.New(fmt.Sprintf("车载运行配置重复的名称:%v", simConfig.ConfigName), err)
|
||||
|
15
third_party/can_btm/balise_btm.go
vendored
15
third_party/can_btm/balise_btm.go
vendored
@ -68,7 +68,7 @@ type BtmCanetClient interface {
|
||||
Stop()
|
||||
//HandleTrainHeadPositionInfo 处理收到列车位置信息
|
||||
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 (
|
||||
@ -84,7 +84,7 @@ func Default() BtmCanetClient {
|
||||
}
|
||||
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)
|
||||
repo := wd.Repo
|
||||
h2 := &TrainHeadPositionInfo{
|
||||
@ -94,8 +94,15 @@ func (s *btmCanetClient) HandleTrainHeadPositionInfoForTrain(w ecs.World, btmCac
|
||||
LinkOffset: h.OldLinkOffset,
|
||||
Speed: h.Speed,
|
||||
Acceleration: h.Acceleration}
|
||||
s.baliseDetector.newDetect(wd, repo, h, h2, btmCache, h.IsLine12)
|
||||
//s.baliseDetector.detect2(wd, repo, h, h2, vobcBtm)
|
||||
s.baliseDetector.newDetect(wd, repo, h, h2, train.BtmBaliseCacheA, h.IsLine12, false, "11")
|
||||
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 处理来自动力学的列车位置信息
|
||||
|
18
third_party/can_btm/balise_detection.go
vendored
18
third_party/can_btm/balise_detection.go
vendored
@ -77,7 +77,7 @@ func (t *BaliseDetector) tryRebind(th *TrainHeadPositionInfo) {
|
||||
//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天线中心点运行信息
|
||||
curAntennaRi := t.createBtmAntennaRunningInfo(wd, repo, th) //目前车头
|
||||
curAntennaRi2 := t.createBtmAntennaRunningInfo(wd, repo, th2) //上次车头
|
||||
@ -103,7 +103,15 @@ func (t *BaliseDetector) newDetect(wd *component.WorldData, repo *repository.Rep
|
||||
if len(balises) > 0 {
|
||||
balise := balises[0]
|
||||
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 {
|
||||
return fixBalise.Telegram, fixBalise.UserTelegram
|
||||
} 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
|
||||
} else {
|
||||
return baliseVar.Telegram, baliseVar.UserTelegram
|
||||
@ -187,10 +195,10 @@ func (t *BaliseDetector) rcvTelegram(wd *component.WorldData, baliseId string) (
|
||||
} else if workedState.Work {
|
||||
return fixBalise.Telegram, fixBalise.UserTelegram
|
||||
} else {
|
||||
slog.Warn(fmt.Sprintf("BTM天线未接受到应答器报文,应答器未工作 baliseId: %v", baliseId))
|
||||
//slog.Warn(fmt.Sprintf("BTM天线未接受到应答器报文,应答器未工作 baliseId: %v", baliseId))
|
||||
}
|
||||
} else {
|
||||
slog.Warn(fmt.Sprintf("BTM天线接收应答器报文,未找到 baliseId: %v", baliseId))
|
||||
//slog.Warn(fmt.Sprintf("BTM天线接收应答器报文,未找到 baliseId: %v", baliseId))
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
28
third_party/can_btm/train_balise_cache.go
vendored
28
third_party/can_btm/train_balise_cache.go
vendored
@ -58,56 +58,56 @@ func AddNewExpectedBalise(balise *repository.Transponder, btmCache *state_proto.
|
||||
|
||||
// HandleTrainHeadPositionInfoForTrain 处理列车位置信息
|
||||
// 参数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()
|
||||
defer baliseLock.Unlock()
|
||||
cache := train.BtmBaliseCache
|
||||
for _, balise := range cache.BaliseList {
|
||||
if balise != nil && balise.BaliseId == cache.ResendBaliseId && balise.ResendCount < 3 {
|
||||
balise.ResendCount++
|
||||
ndsn := BaliseCounterAdd(cache.Dsn, IsLine12(train))
|
||||
ndsn := BaliseCounterAdd(cache.Dsn, isLine12)
|
||||
cache.Dsn = uint32(ndsn)
|
||||
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
|
||||
}
|
||||
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()
|
||||
defer baliseLock.Unlock()
|
||||
cache := train.BtmBaliseCache
|
||||
|
||||
for _, btmCache := range cache.BaliseList {
|
||||
if btmCache != nil && !btmCache.IsSend {
|
||||
ndsn := BaliseCounterAdd(cache.Dsn, IsLine12(train))
|
||||
ndsn := BaliseCounterAdd(cache.Dsn, isLine12)
|
||||
cache.Dsn = uint32(ndsn)
|
||||
cache.ResendBaliseId = btmCache.BaliseId
|
||||
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
|
||||
}
|
||||
func ClearBalise(train *state_proto.TrainState) {
|
||||
baliseLock.Lock()
|
||||
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号线根据序列号查询
|
||||
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()
|
||||
defer baliseLock.Unlock()
|
||||
cache := train.BtmBaliseCache
|
||||
|
||||
for _, btmCache := range cache.BaliseList {
|
||||
if btmCache != nil {
|
||||
if btmCache.BaliseId == cache.ResendBaliseId {
|
||||
if byte(btmCache.PackageDataSN) == ms {
|
||||
bt, dsn, _, _ := FindBaliseByNotSend(train)
|
||||
bt, dsn, _, _ := FindBaliseByNotSend(cache, isLine12)
|
||||
return bt, dsn, true
|
||||
} else {
|
||||
ndsn := BaliseCounterAdd(cache.Dsn, IsLine12(train))
|
||||
ndsn := BaliseCounterAdd(cache.Dsn, isLine12)
|
||||
cache.Dsn = uint32(ndsn)
|
||||
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
|
||||
|
||||
}
|
||||
|
5
third_party/message/train_pc_sim_message.go
vendored
5
third_party/message/train_pc_sim_message.go
vendored
@ -122,7 +122,7 @@ func AtpLowPowerByte(d byte) bool {
|
||||
// 列车速度位置报告
|
||||
type TrainSpeedPlaceReportMsg struct {
|
||||
PulseCount1 float32
|
||||
PulseCount2 float32
|
||||
//PulseCount2 float32
|
||||
}
|
||||
|
||||
func (tp *TrainSpeedPlaceReportMsg) Encode(runDir uint16, s1, runRange uint32) []byte {
|
||||
@ -255,4 +255,7 @@ const (
|
||||
DOOR_MODE_MM
|
||||
_
|
||||
NOT_BREAK
|
||||
//aa = 0x2e
|
||||
//bb = 0x2f
|
||||
cc = 0x2d
|
||||
)
|
||||
|
4
third_party/semi_physical_train/btm_vobc.go
vendored
4
third_party/semi_physical_train/btm_vobc.go
vendored
@ -164,11 +164,11 @@ func (b *BtmVobcClient) requestFramePackets(requestId string, req *message.BtmVo
|
||||
|
||||
if req.FrameStatus == message.REQ_FRAME_STATUS_ERROR {
|
||||
//抢答器错误,重新发送
|
||||
btmState, dsn, _, _ = can_btm.FindBaliseResend(train)
|
||||
btmState, dsn, _, _ = can_btm.FindBaliseResend(train.BtmBaliseCacheA, false)
|
||||
} else {
|
||||
//判断 报文序列号与之前发送的 是否一致,不一致
|
||||
//如果一致返回新的应答器,如果不一致返回之前发送的应答器,如果不一致并且没有找到之前发送的应答器,则返回新应答器
|
||||
btmState, dsn, matcher = can_btm.FindBaliseByMessageSerial(train, req.MessageSerial)
|
||||
btmState, dsn, matcher = can_btm.FindBaliseByMessageSerial(train.BtmBaliseCacheA, false, req.MessageSerial)
|
||||
if matcher {
|
||||
if btmState != nil {
|
||||
//正常应答
|
||||
|
4
third_party/tcp/tcp_client.go
vendored
4
third_party/tcp/tcp_client.go
vendored
@ -88,3 +88,7 @@ func (c *TcpClient) Send(data []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *TcpClient) RemoteInfo() net.Addr {
|
||||
return c.conn.RemoteAddr()
|
||||
}
|
||||
|
2
third_party/third_party.go
vendored
2
third_party/third_party.go
vendored
@ -46,9 +46,11 @@ func GetRunningServiceStates() *state_proto.SimulationThirdPartyApiService {
|
||||
trueServices := tpas.FindAppendApiService()
|
||||
if trueServices != nil && len(trueServices) > 0 {
|
||||
for _, trueService := range trueServices {
|
||||
if trueService != nil {
|
||||
collectServiceState(ss, trueService)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package train_pc_sim
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"joylink.club/bj-rtsts-server/dto/state_proto"
|
||||
"joylink.club/bj-rtsts-server/third_party/message"
|
||||
"joylink.club/bj-rtsts-server/third_party/tcp"
|
||||
@ -13,10 +14,11 @@ type TrainPcReciverData struct {
|
||||
clientKey string
|
||||
tcpClient *tcp.TcpClient
|
||||
pcSimManage TrainPcSimManage
|
||||
//trainInit bool
|
||||
state tpapi.ThirdPartyApiServiceState
|
||||
speedPlace *message.TrainSpeedPlaceReportMsg
|
||||
train *state_proto.TrainState
|
||||
success bool
|
||||
aPort bool
|
||||
}
|
||||
|
||||
func (rd *TrainPcReciverData) Name() string {
|
||||
@ -35,17 +37,19 @@ func (d *TrainPcReciverData) readError(err error) {
|
||||
slog.Error("连接车载pc仿真tcp服务断开", err)
|
||||
d.updateState(tpapi.ThirdPartyState_Broken)
|
||||
d.tcpClient = nil
|
||||
|
||||
}
|
||||
|
||||
func (d *TrainPcReciverData) ServiceDesc() string {
|
||||
return d.clientKey
|
||||
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) {
|
||||
|
||||
receiveData := data[:n]
|
||||
|
||||
trainPcMsgs := message.TrainPcSimDecode(receiveData)
|
||||
train := rd.train
|
||||
//vs := train.VobcState
|
||||
if train == nil {
|
||||
slog.Error("车载输出数字量,未找到连接车载pc仿真的列车")
|
||||
return
|
||||
@ -54,15 +58,20 @@ func (rd *TrainPcReciverData) receiverDataHandle(n int, data []byte) {
|
||||
slog.Error("车载输出数字量,,列车未连接车载pc仿真")
|
||||
return
|
||||
}
|
||||
//hexSourceData := hex.EncodeToString(receiveData)
|
||||
//slog.Info(fmt.Sprintf("接受列车激活端:%v pc仿真接收数据:%v", rd.clientKey, hexSourceData))
|
||||
//a := rd.tcpClient.RemoteInfo()
|
||||
//slog.Info(fmt.Sprintf("nw:%v ,add:%v", a.Network(), a.String()), rd.aPort)
|
||||
//slog.Info(fmt.Sprintf("接受atp信息 列车:%v 列车端口:%v ,钥匙1:%v,钥匙2:%v", train.Id, rd.aPort, train.VobcState.Tc1Active, train.VobcState.Tc2Active))
|
||||
receiveData := data[:n]
|
||||
trainPcMsgs := message.TrainPcSimDecode(receiveData)
|
||||
|
||||
for _, baseMsg := range trainPcMsgs {
|
||||
//slog.Info(fmt.Sprintf("pc仿真接收数据:%v,类型:%X", hexSourceData, baseMsg.Type))
|
||||
|
||||
switch baseMsg.Type {
|
||||
//case RECIVE_TRAIN_CREATE_REMOVE:
|
||||
// pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0])
|
||||
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:
|
||||
rd.pcSimManage.TrainPcSimDigitalReportHandle(train, baseMsg.Data)
|
||||
|
186
third_party/train_pc_sim/train_pc_sim.go
vendored
186
third_party/train_pc_sim/train_pc_sim.go
vendored
@ -16,10 +16,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type TrainControlEvent struct {
|
||||
Type byte
|
||||
Data []byte
|
||||
}
|
||||
//type TrainControlEvent struct {
|
||||
// Type byte
|
||||
// Data []byte
|
||||
//}
|
||||
|
||||
//var FireTrainControlEventType = ecs.NewEventType[TrainControlEvent]()
|
||||
|
||||
@ -57,7 +57,7 @@ type TrainPcSimManage interface {
|
||||
//获取列车模拟量数据
|
||||
ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage
|
||||
// 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(train *state_proto.TrainState, data []byte)
|
||||
FindConnTrain(ct state_proto.TrainConnState_TrainConnType) *state_proto.TrainState
|
||||
@ -71,7 +71,10 @@ type TrainPcSimManage interface {
|
||||
}
|
||||
type trainPcSimService struct {
|
||||
state tpapi.ThirdPartyApiServiceState
|
||||
newPcSimclientMap map[string]*TrainPcReciverData
|
||||
//newPcSimclientMap map[string]*TrainPcReciverData
|
||||
|
||||
newPcSimclientMap3 map[string][]*TrainPcReciverData
|
||||
|
||||
cancleContextFun context.CancelFunc
|
||||
context context.Context
|
||||
trainPcSimManage TrainPcSimManage
|
||||
@ -113,17 +116,29 @@ func (d *trainPcSimService) ServiceDesc() string {
|
||||
func FindTrainPcSimClientKey2(t *state_proto.TrainState) string {
|
||||
return t.ConnState.TypeName
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) findTrainConn(sta *state_proto.TrainState) (*TrainPcReciverData, error) {
|
||||
trainPcReciver := d.newPcSimclientMap[sta.ConnState.TypeName]
|
||||
if trainPcReciver == nil {
|
||||
rds := d.newPcSimclientMap3[sta.ConnState.TypeName]
|
||||
if rds == nil {
|
||||
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 {
|
||||
services := make([]tpapi.ThirdPartyApiService, 0)
|
||||
for _, data := range d.newPcSimclientMap {
|
||||
services = append(services, data)
|
||||
for _, data := range d.newPcSimclientMap3 {
|
||||
for _, rd := range data {
|
||||
services = append(services, rd)
|
||||
}
|
||||
}
|
||||
return services
|
||||
}
|
||||
@ -161,10 +176,13 @@ func (d *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2,
|
||||
return
|
||||
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 += float32(uint32(h1 * 10))
|
||||
sd.speedPlace.PulseCount2 = sd.speedPlace.PulseCount1
|
||||
}
|
||||
if sta.TrainRunUp {
|
||||
if sta.TrainEndsA.SpeedSensorEnableA {
|
||||
@ -202,15 +220,22 @@ func (d *trainPcSimService) newCloseAllConn() {
|
||||
}
|
||||
|
||||
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 {
|
||||
rd.tcpClient.Close()
|
||||
rd.tcpClient = nil
|
||||
rd.train = nil
|
||||
rd.speedPlace = nil
|
||||
//rd.trainInit = false
|
||||
//d.cancleContextFun()
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
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连接配置")
|
||||
}
|
||||
|
||||
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 A,B端配置均为打开", 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() {
|
||||
return nil
|
||||
} else {
|
||||
//rd.trainInit = false
|
||||
rd.tcpClient = nil
|
||||
}
|
||||
cfg, cfgErr := d.findConfig(clientKey)
|
||||
if cfgErr != nil {
|
||||
errMsg := fmt.Sprintf("没找到对应的配置信息 key:%v", clientKey)
|
||||
//slog.Error(errMsg, cfgErr.Error())
|
||||
rd.updateState(tpapi.ThirdPartyState_Broken)
|
||||
return sys_error.New(errMsg, cfgErr)
|
||||
if !open {
|
||||
rd.success = false
|
||||
return nil
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
connErrMsg := fmt.Sprintf("车载pc连接失败 clientKey:%v", clientKey)
|
||||
//slog.Error(connErrMsg, err.Error())
|
||||
rd.updateState(tpapi.ThirdPartyState_Broken)
|
||||
return sys_error.New(connErrMsg, err)
|
||||
} else {
|
||||
rd.success = true
|
||||
rd.tcpClient = client2
|
||||
}
|
||||
return nil
|
||||
@ -255,7 +297,8 @@ func (d *trainPcSimService) initConn(clientKey string) error {
|
||||
func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
||||
|
||||
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 {
|
||||
slog.Info("车载pc仿真配置未开启")
|
||||
return
|
||||
@ -266,9 +309,16 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
||||
closedCount++
|
||||
} else {
|
||||
ck := c.ConfigName
|
||||
pcReciver := &TrainPcReciverData{clientKey: ck, pcSimManage: pcSimManage}
|
||||
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)
|
||||
d.newPcSimclientMap[ck] = pcReciver
|
||||
pcReceivers[i] = pcReciver
|
||||
}
|
||||
d.newPcSimclientMap3[ck] = pcReceivers
|
||||
//d.newPcSimclientMap[ck] = pcReciver
|
||||
|
||||
}
|
||||
}
|
||||
if closedCount == len(configs) {
|
||||
@ -285,8 +335,11 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
||||
}
|
||||
|
||||
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 {
|
||||
d.cancleContextFun()
|
||||
@ -297,7 +350,7 @@ func (d *trainPcSimService) Stop() {
|
||||
|
||||
func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error {
|
||||
clientKey := FindTrainPcSimClientKey2(train)
|
||||
err := d.initConn(clientKey)
|
||||
err := d.initConn2(clientKey)
|
||||
if err != nil {
|
||||
d.newCloseConn(clientKey)
|
||||
return err
|
||||
@ -307,8 +360,11 @@ func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, i
|
||||
data[0] = message.FLAG_CAMMAND_CREATE_TRAIN
|
||||
}
|
||||
msg := &message.TrainPcSimBaseMessage{Data: data, Type: message.RECIVE_TRAIN_CREATE_REMOVE}
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
if rd != nil {
|
||||
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)
|
||||
@ -317,6 +373,10 @@ func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, i
|
||||
return initTrainErr
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
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{}
|
||||
rd.train = train
|
||||
tcc := train.Tcc
|
||||
tcc.LineInitTimeStamp12 = 0
|
||||
tcc.Line12ConnErr = false
|
||||
tcc.LineInitTimeStamp12PortA = 0
|
||||
tcc.LineInitTimeStamp12PortB = 0
|
||||
tcc.Line12ConnErrPortA = false
|
||||
tcc.Line12ConnErrPortB = false
|
||||
//tcc.LineInitTimeStamp12 = 0
|
||||
//tcc.Line12ConnErr = false
|
||||
if isCreate {
|
||||
tmpMsgs := d.trainPcSimManage.ObtainTrainDigitalMockData(train)
|
||||
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{}, Type: message.RECIVE_TRAIN_BTN_CLEAR_ALL_PRE_DATA}) //清空应答器
|
||||
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.SENDER_TRAIN_TC_ACTIVE}) //清空应答器
|
||||
} else {
|
||||
train.VobcState.Tc1Active = false
|
||||
train.VobcState.Tc2Active = false
|
||||
|
||||
for _, key := range tcc.DriverKey {
|
||||
key.Val = false
|
||||
}
|
||||
@ -357,29 +421,32 @@ func (d *trainPcSimService) initTrain(rd *TrainPcReciverData, train *state_proto
|
||||
|
||||
// 依据文档80ms发送列车速度位置
|
||||
func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
||||
for {
|
||||
for range time.Tick(time.Millisecond * 80) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
trains := d.trainPcSimManage.GetConnTrain2()
|
||||
for _, train := range trains {
|
||||
if train.ConnState.Conn && train.PluseCount != nil {
|
||||
trainClient, trainDataErr := d.findTrainConn(train)
|
||||
if trainDataErr != nil {
|
||||
slog.Error(fmt.Sprintf("pc仿真速度位置未找到对应的列车 id:%v", train.Id))
|
||||
continue
|
||||
}
|
||||
trainClients := d.newPcSimclientMap3[train.ConnState.TypeName]
|
||||
for _, trainClient := range trainClients {
|
||||
if trainClient.success {
|
||||
if trainClient.speedPlace == nil {
|
||||
slog.Error(fmt.Sprintf("pc仿真速度位置脉冲对象为空 列车id:%v", train.Id))
|
||||
continue
|
||||
}
|
||||
|
||||
connState := tpapi.ThirdPartyState_Normal
|
||||
if train.Tcc.Line12ConnErr {
|
||||
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)
|
||||
@ -390,14 +457,16 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
||||
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)))
|
||||
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)))
|
||||
}
|
||||
}
|
||||
}
|
||||
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))
|
||||
return
|
||||
}
|
||||
|
||||
vobc := train.VobcState
|
||||
|
||||
msg := &message.TrainPcSimBaseMessage{}
|
||||
if train.TrainRunUp {
|
||||
/*if train.TrainRunUp {
|
||||
if vobc.Tc1Active {
|
||||
msg.Type = message.SENDER_TRAIN_TC_ACTIVE
|
||||
} else if vobc.Tc1Active == false {
|
||||
msg.Type = message.SENDER_TRAIN_TC_NOT_ACTIVE
|
||||
}
|
||||
} else if !train.TrainRunUp {
|
||||
if vobc.Tc2Active {
|
||||
if vobc.Tc1Active {
|
||||
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
|
||||
}
|
||||
}*/
|
||||
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)
|
||||
if msg.Type == message.SENDER_TRAIN_TC_ACTIVE {
|
||||
|
@ -77,6 +77,7 @@ func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, conf
|
||||
calctailOffset := calcTrailTailOffset(loffset, status.TrainLength, up)
|
||||
// 车尾位置
|
||||
tailLink, tailDeviceId, tailDevicePort, tailLOffset, tailDeviceOffset, _, e1 := CalcInitializeLink(vs, linkId, calctailOffset, up)
|
||||
|
||||
if e1 != nil {
|
||||
panic(sys_error.New("添加列车失败,列车车尾占用位置计算出错", e1))
|
||||
}
|
||||
@ -95,7 +96,8 @@ func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, conf
|
||||
status.TailDeviceId = vs.GetComIdByUid(tailDeviceId)
|
||||
status.TailOffset = tailDeviceOffset
|
||||
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)
|
||||
@ -168,7 +170,10 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
|
||||
train.ConnState.ConnType = ct.ConnType
|
||||
train.ConnState.TypeName = ct.TypeName
|
||||
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)
|
||||
if err != nil {
|
||||
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), trainHeadActUp)
|
||||
tailLinkId, tailDeviceId, tailDevicePort, tailLinkOffset, tailOffset, _, e2 := CalcInitializeLink(vs, outLinkId, calctailOffset, !info.Up)
|
||||
|
||||
tailUp, _ := QueryUpAndABByDevice(vs.Repo, tailDeviceId, tailDevicePort, sta.TrainRunUp)
|
||||
if e2 != nil {
|
||||
panic(sys_error.New("动力学传输数据:列车车尾位置计算出错", e2))
|
||||
}
|
||||
@ -336,8 +343,12 @@ func UpdateTrainStateByDynamics(vs *VerifySimulation, trainId string, info *mess
|
||||
sta.OldLinkOffset = outLinkOffset
|
||||
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))
|
||||
if sta.OldLink != outLinkId {
|
||||
sta.OldLink = outLinkId
|
||||
@ -399,10 +410,10 @@ 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中列车位置信息
|
||||
//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,
|
||||
Up: info.Up,
|
||||
Link: outLinkId,
|
||||
@ -411,22 +422,13 @@ func updateTrainBtmPosition(vs *VerifySimulation, info *message.DynamicsTrainInf
|
||||
Acceleration: info.Acceleration,
|
||||
OldLinkOffset: sta.OldLinkOffset,
|
||||
OldLink: sta.OldLink,
|
||||
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
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,11 @@ import (
|
||||
"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/message"
|
||||
"joylink.club/bj-rtsts-server/third_party/tcp"
|
||||
train_pc_sim "joylink.club/bj-rtsts-server/third_party/train_pc_sim"
|
||||
"log/slog"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -43,7 +45,7 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
|
||||
baseMsg = trainControlButton(sta, ct.DeviceId, ct.ControlButton.Active, tccGraphicData)
|
||||
} else if ct.ControlType == request_proto.TrainControl_DRIVER_KEY_SWITCH {
|
||||
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 {
|
||||
baseMsg = trainControlDirKey(sta.DynamicState.Speed, vobc, tcc, ct.SwitchKey, ct.DeviceId, tccGraphicData)
|
||||
//此处先注释,根据现场调试情况 2024-4-16
|
||||
@ -96,10 +98,8 @@ func trainControlButton(train *state_proto.TrainState, deviceId uint32, active b
|
||||
return controlAtpBtn(vobc, active, btn)
|
||||
case KZM, KYM: //开左门按钮
|
||||
return controlDoorOpenBtn(vobc, active, btn, graphicBtn.Code == KZM, true)
|
||||
|
||||
case GZM, GYM: //关左门按钮
|
||||
return controlDoorCloseBtn(vobc, active, btn, graphicBtn.Code == GZM, true)
|
||||
|
||||
case ZF: //折返按钮
|
||||
return controlReverseBtn(vobc, active, btn)
|
||||
case QZMYX: //强制门允许
|
||||
@ -410,7 +410,15 @@ func trainControlDriverKey(train *state_proto.TrainState, request *request_proto
|
||||
if addNew {
|
||||
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 {
|
||||
@ -607,18 +615,26 @@ func (s *VerifySimulation) FindConnTrain(ct state_proto.TrainConnState_TrainConn
|
||||
}
|
||||
|
||||
// 反馈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
|
||||
tcc := train.Tcc
|
||||
tce := make([]message.TrainPcSimBaseMessage, 0)
|
||||
tcc.Line12ConnErr = false
|
||||
//initResult := trainInit
|
||||
initTimeStamp := tcc.LineInitTimeStamp12PortA
|
||||
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 {
|
||||
state := message.GetBit(data1, 3)
|
||||
//if trainInit {
|
||||
if vobc.TrainConnInitComplate {
|
||||
if /* vobc.TrainConnInitComplate*/ initConn {
|
||||
if data1 == 0 {
|
||||
tcc.Line12ConnErr = true
|
||||
//tcc.Line12ConnErr = true
|
||||
connErr = true
|
||||
}
|
||||
if state == 0 {
|
||||
jjzdBtn := tcc.Buttons[JJZD]
|
||||
@ -630,36 +646,126 @@ func (s *VerifySimulation) reportTrainMockInitMsg(train *state_proto.TrainState,
|
||||
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 {
|
||||
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.OUTER_EMERGENCY_BRAKE, state}})
|
||||
}
|
||||
} else {
|
||||
//initResult = false
|
||||
vobc.TrainConnInitComplate = true
|
||||
if tcc.LineInitTimeStamp12 <= 0 {
|
||||
tcc.LineInitTimeStamp12 = time.Now().Add(time.Second * 6).Unix()
|
||||
initConn = true
|
||||
if initTimeStamp <= 0 {
|
||||
initTimeStamp = 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}})
|
||||
initData := s.ObtainTrainDigitalMockDataForStatus(train)
|
||||
tce = append(tce, initData...)
|
||||
if aport {
|
||||
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...)
|
||||
//initResult = false
|
||||
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 {
|
||||
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}})
|
||||
|
||||
}
|
||||
|
||||
train_pc_sim.Default().SendTrainControlMsg(train, tce)
|
||||
//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
|
||||
}
|
||||
}
|
||||
|
||||
//驾驶室激活反馈
|
||||
if message.GetBit(data3, 3) == 0 {
|
||||
tce = append(tce, message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{message.DRIVER_ACTIVE_REPORT, 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)
|
||||
//return initResult
|
||||
return initTimeStamp, initConn, connErr, tce
|
||||
}
|
||||
func trainAtoLevel(at3, at2, at1 bool) state_proto.TrainVobcState_AtoStepLevel {
|
||||
switch {
|
||||
case at3 == false && at2 == false && at1 == true:
|
||||
return state_proto.TrainVobcState_ATO_STEP_LEVEL_1
|
||||
|
||||
case at3 == false && at2 == true && at1 == true:
|
||||
return state_proto.TrainVobcState_ATO_STEP_LEVEL_2
|
||||
case at3 == false && at2 == true && at1 == false:
|
||||
@ -676,22 +782,54 @@ func trainAtoLevel(at3, at2, at1 bool) state_proto.TrainVobcState_AtoStepLevel {
|
||||
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. 车载输出数字量信息报文内容
|
||||
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(train *state_proto.TrainState, data []byte) {
|
||||
/* slog.Info("开始接受atp输出模拟量==============")
|
||||
for i, d := range data {
|
||||
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(aport bool, client *tcp.TcpClient, train *state_proto.TrainState, data []byte) bool {
|
||||
|
||||
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(fmt.Sprintf("接受atp模拟量id:%v,data:%b,bits:%v", i, d, dd.String()))
|
||||
|
||||
}*/
|
||||
d := data[4]
|
||||
for j := 0; j < 8; j++ {
|
||||
dd.WriteString(fmt.Sprintf(" bit%v val:%v , ", j, message.GetBit(d, uint(j))))
|
||||
}
|
||||
slog.Info("结束接受atp输出模拟量eeeeeeeeeeeeeeeeee")*/
|
||||
s.reportTrainMockInitMsg(train, data[4], data[1])
|
||||
//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)
|
||||
@ -700,7 +838,28 @@ func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(train *state_proto.Tra
|
||||
if vobc.Ato {
|
||||
vobc.AtoStepLevel = trainAtoLevel(vobc.AtoTractionCommand3, vobc.AtoTractionCommand2, vobc.AtoTractionCommand1)
|
||||
}
|
||||
//return initResult
|
||||
}
|
||||
} 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) {
|
||||
@ -856,10 +1015,14 @@ func (s *VerifySimulation) TrainBtmQuery2(train *state_proto.TrainState, data []
|
||||
}
|
||||
var balise *state_proto.BTMState
|
||||
var dsn, bc, mc byte
|
||||
btmCache := train.BtmBaliseCacheA
|
||||
if train.VobcState.Tc2Active {
|
||||
btmCache = train.BtmBaliseCacheB
|
||||
}
|
||||
if atpReq.IsResend() {
|
||||
balise, dsn, bc, mc = can_btm.FindBaliseResend(train)
|
||||
balise, dsn, bc, mc = can_btm.FindBaliseResend(btmCache, true)
|
||||
} else {
|
||||
balise, dsn, bc, mc = can_btm.FindBaliseByNotSend(train)
|
||||
balise, dsn, bc, mc = can_btm.FindBaliseByNotSend(btmCache, true)
|
||||
}
|
||||
cl := clock(atpReq)
|
||||
btmRepFrame := createBtmStatus(trainAtm.CanId.ID4, balise, atpReq, cl, dsn, bc, mc)
|
||||
@ -930,10 +1093,10 @@ func (s *VerifySimulation) ObtainTrainDigitalMockDataForStatus(train *state_prot
|
||||
|
||||
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.DRIVER_ACTIVE_REPORT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
|
||||
} else {
|
||||
//msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DRIVER_ACTIVE_REPORT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
|
||||
} /* else {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DRIVER_ACTIVE_REPORT, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
|
||||
}
|
||||
}*/
|
||||
if vs.BrakeForce == 0 {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_TO_ZERO, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车制动状态
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user