12号线列车控制基本调试
This commit is contained in:
parent
aa04a9fbf4
commit
037cf2f1be
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
||||
Subproject commit 6cdf88a92d573fdb6502047d10abd1af7d0e40a2
|
||||
Subproject commit 1e7e693004e7f0e5b0f4d7de58408984a7d52f2c
|
12
third_party/message/can_btm_data.go
vendored
12
third_party/message/can_btm_data.go
vendored
@ -66,6 +66,12 @@ type BtmDataMessageTimeAFrame struct {
|
||||
IsTrainPcSim bool
|
||||
}
|
||||
|
||||
func NewBtmDataMessageTimeAFrame2(sn byte, isTrainPcSim bool) *BtmDataMessageTimeAFrame {
|
||||
return &BtmDataMessageTimeAFrame{
|
||||
FId: *NewCanFrameId(CAN_ADDR_RSP_ATP, CAN_ADDR_RSP_BTM, 0x80+0x0e, sn),
|
||||
IsTrainPcSim: isTrainPcSim,
|
||||
}
|
||||
}
|
||||
func NewBtmDataMessageTimeAFrame(sn byte, isTrainPcSim bool) *BtmDataMessageTimeAFrame {
|
||||
return &BtmDataMessageTimeAFrame{
|
||||
FId: *NewCanFrameId(CAN_ADDR_RSP_ATP, CAN_ADDR_RSP_BTM, 0x80+0x0d, sn),
|
||||
@ -276,6 +282,12 @@ type BtmDataMessageEndFrame struct {
|
||||
IsTrainPcSim bool
|
||||
}
|
||||
|
||||
func NewBtmDataMessageEndFrame2(sn byte, isTrainPcSim bool) *BtmDataMessageEndFrame {
|
||||
return &BtmDataMessageEndFrame{
|
||||
FId: *NewCanFrameId(CAN_ADDR_RSP_ATP, CAN_ADDR_RSP_BTM, 0xff, sn),
|
||||
IsTrainPcSim: isTrainPcSim,
|
||||
}
|
||||
}
|
||||
func NewBtmDataMessageEndFrame(sn byte, isTrainPcSim bool) *BtmDataMessageEndFrame {
|
||||
return &BtmDataMessageEndFrame{
|
||||
FId: *NewCanFrameId(CAN_ADDR_RSP_ATP, CAN_ADDR_RSP_BTM, 0x80+0x7f, sn),
|
||||
|
95
third_party/message/can_btm_rsp.go
vendored
95
third_party/message/can_btm_rsp.go
vendored
@ -2,6 +2,101 @@ package message
|
||||
|
||||
import "log/slog"
|
||||
|
||||
func CreateBtmRspFramesData2(statusRsp *BtmStatusRspFrame, msg []byte, msgPackError bool, msgTimeA uint32, msgTimeB uint32, tkTimeB uint32, isTrainPcSim bool) ([]byte, bool) {
|
||||
/* if len(msg) > 104 { //数据帧最多存储13*8个字节
|
||||
return nil, false
|
||||
}*/
|
||||
//最近一次ATP查询请求序列号
|
||||
sn := statusRsp.FId.ID4
|
||||
//13个BtmDataMessageFrame [0x00,0x0c]
|
||||
//数据
|
||||
dms := make([]*BtmDataMessageFrame, 13)
|
||||
for mr := 0x00; mr <= 0x0c; mr++ {
|
||||
dms[mr] = NewBtmDataMessageFrame(sn, byte(mr), isTrainPcSim)
|
||||
dms[mr].Message = make([]byte, 8) //8字节数组,默认值0
|
||||
//
|
||||
if !msgPackError {
|
||||
mi := mr * 8
|
||||
if mi < len(msg) { //数据帧中有<=8个字节数据
|
||||
if mi+7 < len(msg) {
|
||||
dms[mr].Message = msg[mi : mi+8]
|
||||
} else {
|
||||
for i, d := range msg[mi:] {
|
||||
dms[mr].Message[i] = d
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { //BTM解包发生错误,则数据帧及CRC32A/B全填“0xFF”
|
||||
for c := 0; c < 8; c++ {
|
||||
dms[mr].Message[c] = 0xff
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
dtA := NewBtmDataMessageTimeAFrame(sn, isTrainPcSim)
|
||||
dtA.TimeA = msgTimeA
|
||||
if !msgPackError {
|
||||
var crc32AData []byte
|
||||
crc32AData = append(crc32AData, msg...)
|
||||
crc32AData = append(crc32AData, canTimeToBytes(dtA.TimeA)...)
|
||||
dtA.Crc32A = Can_Crc32(crc32AData) //CRC32A的校验范围是:报文+时间戳A
|
||||
} else { //BTM解包发生错误,则数据帧及CRC32A/B全填“0xFF”
|
||||
dtA.Crc32A = 0xff_ff_ff_ff
|
||||
}
|
||||
//
|
||||
dtB := NewBtmDataMessageTimeBFrame(sn, isTrainPcSim)
|
||||
dtB.TimeB = msgTimeB
|
||||
if !msgPackError {
|
||||
var crc32BData []byte
|
||||
crc32BData = append(crc32BData, msg...)
|
||||
crc32BData = append(crc32BData, canTimeToBytes(dtB.TimeB)...)
|
||||
dtB.Crc32B = Can_Crc32(crc32BData) //CRC32B的校验范围是:报文+时间戳B
|
||||
} else { //BTM解包发生错误,则数据帧及CRC32A/B全填“0xFF”
|
||||
dtB.Crc32B = 0xff_ff_ff_ff
|
||||
}
|
||||
//
|
||||
end := NewBtmDataMessageEndFrame(sn, isTrainPcSim)
|
||||
end.TkB = tkTimeB
|
||||
//
|
||||
statusCf := statusRsp.Encode()
|
||||
dmsCfs := make([]*CanetFrame, 0, 13)
|
||||
for _, dm := range dms {
|
||||
dmsCfs = append(dmsCfs, dm.Encode())
|
||||
}
|
||||
dtACf := dtA.Encode()
|
||||
dtBCf := dtB.Encode()
|
||||
//
|
||||
crc32cData := make([]byte, 0, 132)
|
||||
crc32cData = append(crc32cData, statusCf.CanData...)
|
||||
for _, dmCf := range dmsCfs {
|
||||
crc32cData = append(crc32cData, dmCf.CanData...)
|
||||
}
|
||||
crc32cData = append(crc32cData, dtACf.CanData...)
|
||||
crc32cData = append(crc32cData, dtBCf.CanData...)
|
||||
crc32cData = append(crc32cData, canTimeToBytes(end.TkB)...)
|
||||
//
|
||||
end.Crc32C = Can_Crc32(crc32cData)
|
||||
//
|
||||
endCf := end.Encode()
|
||||
//
|
||||
rt := make([]byte, 0, 221) //17*13
|
||||
rt = append(rt, statusCf.Encode2()...)
|
||||
for _, dmCf := range dmsCfs {
|
||||
rt = append(rt, dmCf.Encode2()...)
|
||||
}
|
||||
rt = append(rt, dtACf.Encode2()...)
|
||||
rt = append(rt, dtBCf.Encode2()...)
|
||||
rt = append(rt, endCf.Encode2()...)
|
||||
if isTrainPcSim && len(rt) != 221 {
|
||||
|
||||
} else if len(rt) != 221 {
|
||||
slog.Warn("len(rt)!=221")
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return rt, true
|
||||
}
|
||||
|
||||
// CreateBtmRspFramesData BTM与ATP之间为双向通信,ATP(主)定时发送请求帧,BTM(从)在未接收到应答器报文时回复状态应答器帧和时间同步帧,在接收到应答器报文时回复所有帧
|
||||
//
|
||||
// 数据帧与状态应答帧同时发送给ATP
|
||||
|
2
third_party/message/train_pc_sim_message.go
vendored
2
third_party/message/train_pc_sim_message.go
vendored
@ -255,4 +255,6 @@ const (
|
||||
DOOR_MODE_AM
|
||||
//MM人开人关
|
||||
DOOR_MODE_MM
|
||||
_
|
||||
NOT_BREAK
|
||||
)
|
||||
|
@ -1,22 +1,30 @@
|
||||
package train_pc_sim
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"joylink.club/bj-rtsts-server/dto/state_proto"
|
||||
"joylink.club/bj-rtsts-server/third_party/message"
|
||||
"joylink.club/bj-rtsts-server/third_party/tcp"
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
type trainPcReciverData struct {
|
||||
clientKey string
|
||||
tcpClient *tcp.TcpClient
|
||||
pcSimManage TrainPcSimManage
|
||||
isSleep bool
|
||||
}
|
||||
|
||||
func (rd *trainPcReciverData) receiverDataHandle(n int, data []byte) {
|
||||
|
||||
if !rd.isSleep {
|
||||
time.Sleep(time.Second * 5)
|
||||
rd.isSleep = true
|
||||
}
|
||||
receiveData := data[:n]
|
||||
|
||||
//hexSourceData := hex.EncodeToString(receiveData)
|
||||
hexSourceData := hex.EncodeToString(receiveData)
|
||||
//slog.Info(fmt.Sprintf("接受列车激活端:%v pc仿真接收数据:%v", rd.clientKey, hexSourceData))
|
||||
trainPcMsgs := message.TrainPcSimDecode(receiveData)
|
||||
connType := state_proto.TrainConnState_PC_SIM_A
|
||||
@ -24,12 +32,13 @@ func (rd *trainPcReciverData) receiverDataHandle(n int, data []byte) {
|
||||
connType = state_proto.TrainConnState_PC_SIM_B
|
||||
}
|
||||
for _, baseMsg := range trainPcMsgs {
|
||||
//slog.Info(fmt.Sprintf("pc仿真接收数据:%v,类型:%X", hexSourceData, baseMsg.Type))
|
||||
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(connType, baseMsg.Data)
|
||||
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR:
|
||||
rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(connType, baseMsg.Data)
|
||||
|
||||
case message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK:
|
||||
rd.pcSimManage.TrainPcSimDigitalReportHandle(connType, baseMsg.Data)
|
||||
case message.RECIVE_TRAIN_QUERY_STATUS:
|
||||
|
149
third_party/train_pc_sim/train_pc_sim.go
vendored
149
third_party/train_pc_sim/train_pc_sim.go
vendored
@ -10,6 +10,7 @@ import (
|
||||
"joylink.club/bj-rtsts-server/third_party/tcp"
|
||||
"joylink.club/bj-rtsts-server/third_party/tpapi"
|
||||
"log/slog"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@ -42,6 +43,9 @@ type TrainPcSim interface {
|
||||
CreateOrRemoveSpeedPLace(train *state_proto.TrainState)
|
||||
// CreateOrRemoveTrain 创建或删除列车
|
||||
CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error
|
||||
|
||||
//TestSendData(train *state_proto.TrainState, data []byte)
|
||||
TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32)
|
||||
}
|
||||
|
||||
type TrainPcSimManage interface {
|
||||
@ -96,6 +100,39 @@ func Default() TrainPcSim {
|
||||
}
|
||||
return singleObj
|
||||
}
|
||||
func pluseCountSpeed(wheelDiameter int32, speedMeter float32) uint32 {
|
||||
s1 := speedMeter * 1000
|
||||
pluseCountData := s1 * 200 / math.Pi / float32(wheelDiameter)
|
||||
fmt.Println(fmt.Sprintf("----------------------%v", pluseCountData))
|
||||
return uint32(pluseCountData)
|
||||
}
|
||||
|
||||
func (s *trainPcSimService) TrainPluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) {
|
||||
defer initLock.Unlock()
|
||||
initLock.Lock()
|
||||
if sta.TrainRunUp {
|
||||
if sta.TrainEndsA.SpeedSensorEnableA {
|
||||
sta.PluseCount.PulseCount1 = pluseCountSpeed(sta.WheelDiameter, h1)
|
||||
}
|
||||
if sta.TrainEndsA.SpeedSensorEnableB {
|
||||
sta.PluseCount.PulseCount2 = pluseCountSpeed(sta.WheelDiameter, h2)
|
||||
}
|
||||
} else {
|
||||
if sta.TrainEndsB.SpeedSensorEnableA {
|
||||
sta.PluseCount.PulseCount1 = pluseCountSpeed(sta.WheelDiameter, t1)
|
||||
}
|
||||
if sta.TrainEndsB.SpeedSensorEnableB {
|
||||
sta.PluseCount.PulseCount2 = pluseCountSpeed(sta.WheelDiameter, t2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *trainPcSimService) TrainPluseCountReset(sta *state_proto.TrainState) {
|
||||
defer initLock.Unlock()
|
||||
initLock.Lock()
|
||||
sta.PluseCount.PulseCount1 = 0
|
||||
sta.PluseCount.PulseCount2 = 0
|
||||
}
|
||||
|
||||
type trainPcSimService struct {
|
||||
state tpapi.ThirdPartyApiServiceState
|
||||
@ -112,12 +149,11 @@ func (d *trainPcSimService) readError(err error) {
|
||||
d.updateState(tpapi.ThirdPartyState_Broken)
|
||||
}
|
||||
func (d *trainPcSimService) newCloseAllConn() {
|
||||
for _, rd := range d.newPcSimclientMap {
|
||||
if rd != nil {
|
||||
rd.tcpClient.Close()
|
||||
rd.tcpClient = nil
|
||||
}
|
||||
trains := d.trainPcSimManage.GetConnTrain2()
|
||||
for _, train := range trains {
|
||||
d.CreateOrRemoveTrain(train, false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) newCloseConn(clientKey string) {
|
||||
@ -203,12 +239,10 @@ func (d *trainPcSimService) initConn(clientKey string) {
|
||||
func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
||||
configs := pcSimManage.GetTrainPcSimConfig()
|
||||
d.newPcSimclientMap = make(map[string]*trainPcReciverData)
|
||||
|
||||
if len(configs) <= 0 {
|
||||
slog.Info("车载pc仿真配置未开启")
|
||||
return
|
||||
}
|
||||
|
||||
closedCount := 0
|
||||
for _, c := range configs {
|
||||
if !c.Open {
|
||||
@ -230,12 +264,13 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) Stop() {
|
||||
|
||||
d.updateState(tpapi.ThirdPartyState_Closed)
|
||||
if d.cancleContext != nil {
|
||||
d.cancleContext()
|
||||
d.cancleContext = nil
|
||||
}
|
||||
//d.closeAllConn()
|
||||
|
||||
d.newCloseAllConn()
|
||||
}
|
||||
func (d *trainPcSimService) CreateOrRemoveSpeedPLace(train *state_proto.TrainState) {
|
||||
@ -250,22 +285,14 @@ func (d *trainPcSimService) CreateOrRemoveSpeedPLace(train *state_proto.TrainSta
|
||||
func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error {
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
d.initConn(clientKey)
|
||||
log := "删除列车"
|
||||
data := []byte{message.FLAG_CAMMAND_REMOVE_TRAIN}
|
||||
if isCreate {
|
||||
log = "创建列车"
|
||||
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 {
|
||||
sd := msg.Encode()
|
||||
slog.Info(fmt.Sprintf("%v-列车号:%v,发送数据:%v", log, train.Id, hex.EncodeToString(sd)))
|
||||
err := rd.tcpClient.Send(sd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
initTrainErr := d.initTrain(rd, train, isCreate)
|
||||
initTrainErr := d.initTrain(rd, train, isCreate, msg)
|
||||
if !isCreate {
|
||||
d.newCloseConn(clientKey)
|
||||
}
|
||||
@ -276,25 +303,32 @@ func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, i
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (d *trainPcSimService) initTrain(rd *trainPcReciverData, train *state_proto.TrainState, isCreate bool) error {
|
||||
func (d *trainPcSimService) initTrain(rd *trainPcReciverData, train *state_proto.TrainState, isCreate bool, trains *message.TrainPcSimBaseMessage) error {
|
||||
msgs := make([]message.TrainPcSimBaseMessage, 0)
|
||||
sendMsg := make([]byte, 0)
|
||||
if isCreate {
|
||||
tmpMsgs := d.trainPcSimManage.ObtainTrainDigitalMockData(train)
|
||||
msgs = append(msgs, tmpMsgs...)
|
||||
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.SENDER_TRAIN_TC_ACTIVE}) //驾驶室激活
|
||||
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{message.DRIVER_ACTIVE_REPORT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //驾驶室激活反馈按钮
|
||||
} else {
|
||||
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.SENDER_TRAIN_TC_NOT_ACTIVE}) //驾驶室激活
|
||||
train.VobcState.Tc1Active = false
|
||||
train.VobcState.Tc2Active = false
|
||||
tcc := train.Tcc
|
||||
for _, key := range tcc.DriverKey {
|
||||
key.Val = false
|
||||
}
|
||||
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{message.TRAIN_BRAKE_STATE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //驾驶室激活
|
||||
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{message.KEY_STATE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //驾驶室激活
|
||||
msgs = append(msgs, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.SENDER_TRAIN_TC_NOT_ACTIVE}) //驾驶室激活
|
||||
}
|
||||
for _, msg := range msgs {
|
||||
data := msg.Encode()
|
||||
hexData := hex.EncodeToString(data)
|
||||
err := rd.tcpClient.Send(data)
|
||||
if err != nil {
|
||||
slog.Error(fmt.Sprintf("列车设置激活%v 失败:%v", isCreate, hexData))
|
||||
return fmt.Errorf(fmt.Sprintf("列车设置激活%v 失败:%v", isCreate, hex.EncodeToString(data)), err)
|
||||
}
|
||||
sendMsg = append(sendMsg, data...)
|
||||
}
|
||||
sendMsg = append(sendMsg, trains.Encode()...)
|
||||
|
||||
hexData := hex.EncodeToString(sendMsg)
|
||||
slog.Info(fmt.Sprintf("发送列车初始化消息:%v", hexData))
|
||||
rd.tcpClient.Send(sendMsg)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -316,8 +350,7 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
||||
d.speedPlace.ParsePulseCount1(s1, s2)
|
||||
data := d.speedPlace.Encode(train.TrainRunUp, s1, s2)
|
||||
bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data}
|
||||
train.PluseCount.PulseCount1 = 0
|
||||
train.PluseCount.PulseCount2 = 0
|
||||
d.TrainPluseCountReset(train)
|
||||
dataCode := bm.Encode()
|
||||
slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,s1: %v,s2: %v,c2: %v,c2: %v,发送数据:%v", train.Id, s1, s2, d.speedPlace.PulseCount1, d.speedPlace.PulseCount2, hex.EncodeToString(dataCode)))
|
||||
err := rd.tcpClient.Send(dataCode)
|
||||
@ -335,9 +368,7 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
||||
// SendDriverActive Deprecated 发送驾驶激活
|
||||
func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
|
||||
vobc := train.VobcState
|
||||
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
//client := d.pcSimClientMap[clientKey]
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
defulatBuf := make([]byte, 0)
|
||||
msg := &message.TrainPcSimBaseMessage{Data: defulatBuf}
|
||||
@ -354,15 +385,21 @@ func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
|
||||
msg.Type = message.SENDER_TRAIN_TC_NOT_ACTIVE
|
||||
}
|
||||
}
|
||||
//:"创建列车-列车号:1,发送数据:eb0050010156e4"}
|
||||
//{,"msg":"发送驾驶激活列车","1":"数据","!BADKEY":"eb0004002437"}
|
||||
msgs := make([]byte, 0)
|
||||
if msg.Type == message.SENDER_TRAIN_TC_ACTIVE {
|
||||
dd3 := message.TrainPcSimBaseMessage{Data: []byte{message.KEY_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}
|
||||
msgs = append(msgs, dd3.Encode()...)
|
||||
} else {
|
||||
dd3 := message.TrainPcSimBaseMessage{Data: []byte{message.KEY_STATE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}
|
||||
msgs = append(msgs, dd3.Encode()...)
|
||||
}
|
||||
msgs = append(msgs, msg.Encode()...)
|
||||
hexData := hex.EncodeToString(msgs)
|
||||
slog.Info(fmt.Sprintf("发送驾驶激活列车id:%v,数据:%v", train.Id, hexData))
|
||||
err := rd.tcpClient.Send(msgs)
|
||||
|
||||
da := msg.Encode()
|
||||
slog.Info(fmt.Sprintf("发送驾驶激活列车id:%v,数据:%v", train.Id, hex.EncodeToString(da)))
|
||||
err := rd.tcpClient.Send(da)
|
||||
//err := client.Send(da)
|
||||
if err != nil {
|
||||
slog.Error(fmt.Sprintf("发送驾驶激活失败列车id:%v,数据:%v,err:%v", train.Id, hex.EncodeToString(da), err.Error()))
|
||||
slog.Error(fmt.Sprintf("发送驾驶激活失败列车id:%v,数据:%v,err:%v", train.Id, hexData, err.Error()))
|
||||
}
|
||||
}
|
||||
func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState) {
|
||||
@ -372,18 +409,12 @@ func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, t
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
|
||||
//client := d.pcSimClientMap[clientKey]
|
||||
msg := &message.TrainPcSimBaseMessage{}
|
||||
newTraction := vobc.TractionForce
|
||||
//newBrake := -vobc.BrakeForce
|
||||
//newOldBrakeForce := -oldBrakeForce
|
||||
if tractionState {
|
||||
if newTraction <= oldTraction && newTraction == 0 {
|
||||
if newTraction <= oldTraction && newTraction <= 0 {
|
||||
//手柄取消前进
|
||||
msg.Type = message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD
|
||||
} else if newTraction > oldTraction {
|
||||
//手柄前进
|
||||
msg.Type = message.SENDER_TRAIN_HAND_KEY_FORWARD
|
||||
} else {
|
||||
//手柄前进
|
||||
msg.Type = message.SENDER_TRAIN_HAND_KEY_FORWARD
|
||||
@ -393,8 +424,7 @@ func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, t
|
||||
/*if newBrake >= newOldBrakeForce && newBrake == 0 {
|
||||
//手柄取消后退
|
||||
msg.Type = message.RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD
|
||||
} else
|
||||
if newBrake < newOldBrakeForce {
|
||||
} else if newBrake < newOldBrakeForce {
|
||||
//手柄后退
|
||||
msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD
|
||||
} else {
|
||||
@ -436,6 +466,7 @@ func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, tr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) SendBaliseData2(train *state_proto.TrainState, msgType byte, data []string) {
|
||||
for _, hexData := range data {
|
||||
dd, _ := hex.DecodeString(hexData)
|
||||
@ -443,8 +474,7 @@ func (d *trainPcSimService) SendBaliseData2(train *state_proto.TrainState, msgTy
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
da := msg.Encode()
|
||||
slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,数据类型:0x%X,数据:%v", msgType, hex.EncodeToString(da)))
|
||||
|
||||
//slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,数据类型:0x%X,数据:%v", msgType, hex.EncodeToString(da)))
|
||||
err := rd.tcpClient.Send(da)
|
||||
if err != nil {
|
||||
slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息失败,数据:%v", hex.EncodeToString(da)))
|
||||
@ -458,10 +488,8 @@ func (d *trainPcSimService) SendBaliseData(train *state_proto.TrainState, msgTyp
|
||||
msg.Data = data
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
|
||||
da := msg.Encode()
|
||||
slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,无应答器:%v,数据:%v", msgType == message.RECIVE_TRAIN_BTM_NOT_DATA, hex.EncodeToString(da)))
|
||||
|
||||
//slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,无应答器:%v,数据:%v", msgType == message.RECIVE_TRAIN_BTM_NOT_DATA, hex.EncodeToString(da)))
|
||||
err := rd.tcpClient.Send(da)
|
||||
if err != nil {
|
||||
slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息失败,数据:%v", hex.EncodeToString(da)))
|
||||
@ -475,22 +503,25 @@ func (d *trainPcSimService) PublishTrainControlEvent(train *state_proto.TrainSta
|
||||
}
|
||||
clientKey := FindTrainPcSimClientKey(train)
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
|
||||
//client := d.pcSimClientMap[clientKey]
|
||||
msgs := make([]byte, 0)
|
||||
for _, event := range events {
|
||||
msg := &message.TrainPcSimBaseMessage{}
|
||||
msg.Type = message.SENDER_TRAIN_OUTR_INFO
|
||||
data := []byte{event.Command, event.Status}
|
||||
msg.Data = data
|
||||
code := msg.Encode()
|
||||
hexCode := hex.EncodeToString(code)
|
||||
msgs = append(msgs, code...)
|
||||
/*hexCode := hex.EncodeToString(code)
|
||||
slog.Info(fmt.Sprintf("输出列车控制输出量,命令码位:%v 对应状态:%v,发送数据:%v", event.Command, event.Status, hexCode))
|
||||
err := rd.tcpClient.Send(code)
|
||||
if err != nil {
|
||||
slog.Error(fmt.Sprintf("输出列车控制输出量发送失败,命令码位:%v 对应状态:%v,发送数据:%v", event.Command, event.Status, hexCode))
|
||||
}
|
||||
//client.Send(msg.Encode())
|
||||
//FireTrainControlEventType.Publish(world, &event)
|
||||
|
||||
}*/
|
||||
}
|
||||
hexCode := hex.EncodeToString(msgs)
|
||||
slog.Info(fmt.Sprintf("列车初始化发送数字量:%v", hexCode))
|
||||
err := rd.tcpClient.Send(msgs)
|
||||
if err != nil {
|
||||
slog.Error(fmt.Sprintf("1111111111111111111"))
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,15 @@ const (
|
||||
JJZD = "JJZD" //紧急停车
|
||||
QHFXKZ = "QHFXKZ" //驾驶方向
|
||||
QYSB = "QYSB" //牵引制动手柄
|
||||
|
||||
ATPQCKG = "ATPQCKG" //ATP切除开关
|
||||
KZM = "KZM" //开左门按钮
|
||||
GZM = "GZM" //关左门按钮
|
||||
GYM = "GYM" //关右门按钮
|
||||
ZAWTGJC = "ZAWTGJC" //障碍物/脱轨检测
|
||||
ZDZGZ = "ZDZGZ" //制动重故障
|
||||
ATPSD = "ATPSD" //ATP上电按钮
|
||||
MSQR = "MSQR" //模式确认
|
||||
)
|
||||
|
||||
// 获取列车控制图形数据
|
||||
@ -68,14 +77,17 @@ func findTrainTccGraphicDataHandler(tccG *data_proto.TccGraphicStorage, id uint3
|
||||
}
|
||||
|
||||
func initTrainVobc(trainLoad int64, trainIsUp bool) (*state_proto.TrainVobcState, uint32) {
|
||||
vobc := &state_proto.TrainVobcState{TrainLoad: int64(trainLoad), BrakingStatus: true, BrakeForce: DEFAULT_BRAKE_FORCE, DirectionForward: true}
|
||||
vobc := &state_proto.TrainVobcState{TrainLoad: int64(trainLoad), BrakingStatus: true, BrakeForce: 100, DirectionForward: true,
|
||||
AllDoorClose: true, ObstacleCheckBtn: true, RightDoorCloseCommand: true, LeftDoorCloseCommand: true, BrakeHeavyFault: true, AtpCutSwitch: true,
|
||||
ConfirmBtn: true, AtpPowerOnBtn: true,
|
||||
}
|
||||
|
||||
var trainActDir uint32 = 0
|
||||
if trainIsUp {
|
||||
vobc.Tc1Active = true
|
||||
//vobc.Tc1Active = true
|
||||
trainActDir = 1
|
||||
} else {
|
||||
//vobc.Tc1Active = true
|
||||
vobc.Tc2Active = true
|
||||
//vobc.Tc2Active = true
|
||||
trainActDir = 2
|
||||
}
|
||||
return vobc, trainActDir
|
||||
@ -101,12 +113,12 @@ func initTrainTcc(vs *VerifySimulation, runDir bool, breaking int32) *state_prot
|
||||
btns := make([]*state_proto.TrainControlState_ControlButton, 0)
|
||||
for _, b := range tccGI.TccButtons {
|
||||
btn := &state_proto.TrainControlState_ControlButton{Id: b.Common.Id, Passed: false}
|
||||
if b.Code == JJZD {
|
||||
btn.Passed = false
|
||||
switch b.Code {
|
||||
case ATPQCKG, GZM, GYM, ZAWTGJC, ZDZGZ, ATPSD, MSQR:
|
||||
btn.Passed = true
|
||||
}
|
||||
btns = append(btns, btn)
|
||||
}
|
||||
|
||||
tcc.Buttons = btns
|
||||
for _, b := range tccGI.TccHandles {
|
||||
if b.Code == QYSB {
|
||||
@ -117,11 +129,11 @@ func initTrainTcc(vs *VerifySimulation, runDir bool, breaking int32) *state_prot
|
||||
for _, b := range tccGI.TccKeys {
|
||||
if b.GetType() == data_proto.TccKey_driverControllerActivationClint {
|
||||
val := false
|
||||
if b.Code == SKQYS1 && runDir {
|
||||
val = true
|
||||
} else if b.Code == SKQYS2 && !runDir {
|
||||
val = true
|
||||
}
|
||||
/* if b.Code == SKQYS1 && runDir {
|
||||
val = true
|
||||
} else if b.Code == SKQYS2 && !runDir {
|
||||
val = true
|
||||
}*/
|
||||
ds = append(ds, &state_proto.TrainControlState_DriverKeySwitch{Id: b.Common.Id, Val: val})
|
||||
} else if b.GetType() == data_proto.TccKey_frontAndRearDirectionalControl {
|
||||
tcc.DirKey = &state_proto.TrainControlState_DirectionKeySwitch{Id: b.Common.Id, Val: uint32(message.IsTrue(true))}
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"joylink.club/bj-rtsts-server/dto/common_proto"
|
||||
"joylink.club/bj-rtsts-server/service"
|
||||
"joylink.club/bj-rtsts-server/third_party/can_btm"
|
||||
"joylink.club/bj-rtsts-server/third_party/train_pc_sim"
|
||||
"log/slog"
|
||||
"math"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -143,7 +143,9 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
|
||||
panic(sys_error.New(fmt.Sprintf("列车【%s】不存在", ct.Id)))
|
||||
}
|
||||
train := data.(*state_proto.TrainState)
|
||||
|
||||
if train.DynamicState.Speed != 0 {
|
||||
panic(sys_error.New(fmt.Sprintf("列车[%s]需要停稳才能连接半实物", train.Id)))
|
||||
}
|
||||
if ct.ConnType != state_proto.TrainConnState_NONE {
|
||||
//列车连接 半实物或车载pc仿真
|
||||
allTrainMap.Range(func(k, v any) bool {
|
||||
@ -407,50 +409,12 @@ func handleTrainPositionFromDynamic(vs *VerifySimulation, info *message.Dynamics
|
||||
})
|
||||
}
|
||||
|
||||
// 接受动力学时间15毫米
|
||||
const RECEIVE_DYNAMIC_DATA_RATE = 15
|
||||
|
||||
func formatSpeedTime(s int32) int32 {
|
||||
//d3, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", s), 64)
|
||||
return int32(math.Abs(math.Round(float64(s))))
|
||||
}
|
||||
func formatSpeedTime2(s int32) uint32 {
|
||||
return uint32(math.Abs(float64(float32(s) / 3.6 / 100 * 1000)))
|
||||
}
|
||||
|
||||
const (
|
||||
aa = 0x79
|
||||
)
|
||||
|
||||
func pluseCount(sta *state_proto.TrainState, h1, h2, t1, t2 float32) {
|
||||
if sta.PluseCount == nil {
|
||||
return
|
||||
}
|
||||
if sta.TrainRunUp {
|
||||
//p1 := formatSpeedTime2(sta.DynamicState.HeadSensorSpeed1)
|
||||
//p2 := formatSpeedTime2(sta.DynamicState.HeadSensorSpeed2)
|
||||
train_pc_sim.Default().TrainPluseCount(sta, h1, h2, t1, t2)
|
||||
|
||||
//p1 := uint32(formatSpeedTime(sta.DynamicState.HeadSensorSpeed1 * RECEIVE_DYNAMIC_DATA_RATE))
|
||||
//p2 := uint32(formatSpeedTime(sta.DynamicState.HeadSensorSpeed2 * RECEIVE_DYNAMIC_DATA_RATE))
|
||||
|
||||
if sta.TrainEndsA.SpeedSensorEnableA {
|
||||
sta.PluseCount.PulseCount1 = sta.PluseCount.PulseCount1 + uint32(h1*1000*0.08)
|
||||
}
|
||||
if sta.TrainEndsA.SpeedSensorEnableB {
|
||||
sta.PluseCount.PulseCount2 = sta.PluseCount.PulseCount2 + uint32(h2*1000*0.08)
|
||||
}
|
||||
} else {
|
||||
//t1 := uint32(formatSpeedTime(sta.DynamicState.TailSensorSpeed1 * RECEIVE_DYNAMIC_DATA_RATE))
|
||||
//t2 := uint32(formatSpeedTime(sta.DynamicState.TailSensorSpeed2 * RECEIVE_DYNAMIC_DATA_RATE))
|
||||
//t1 := formatSpeedTime2(sta.DynamicState.HeadSensorSpeed1)
|
||||
//t2 := formatSpeedTime2(sta.DynamicState.HeadSensorSpeed2)
|
||||
if sta.TrainEndsB.SpeedSensorEnableA {
|
||||
sta.PluseCount.PulseCount1 = sta.PluseCount.PulseCount1 + uint32(t1*1000*0.08)
|
||||
}
|
||||
if sta.TrainEndsB.SpeedSensorEnableB {
|
||||
sta.PluseCount.PulseCount2 = sta.PluseCount.PulseCount2 + uint32(t2*1000*0.08)
|
||||
}
|
||||
}
|
||||
}
|
||||
func RemoveAllTrain(vs *VerifySimulation) {
|
||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||
|
@ -40,11 +40,10 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
|
||||
tcc := sta.Tcc
|
||||
var tce []train_pc_sim.TrainControlEvent = nil
|
||||
if ct.ControlType == request_proto.TrainControl_EMERGENT_BUTTON {
|
||||
//tce = trainControlEB(vobc, tcc, ct.Button, ct.DeviceId, tccGraphicData)
|
||||
tce = trainControlButton(vobc, tcc.Buttons, ct.DeviceId, ct.ControlButton.Active, tccGraphicData)
|
||||
} else if ct.ControlType == request_proto.TrainControl_DRIVER_KEY_SWITCH {
|
||||
tce = 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 {
|
||||
tce = trainControlDirKey(sta.DynamicState.Speed, vobc, tcc, ct.DirKey, ct.DeviceId, tccGraphicData)
|
||||
//此处先注释,根据现场调试情况 2024-4-16
|
||||
@ -56,7 +55,11 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
|
||||
tce = trainControlHandle(vobc, tcc, ct.Handler, ct.DeviceId, tccGraphicData)
|
||||
train_pc_sim.Default().SendHandleSwitch(oldTraction, oldBrakeForce, isTraction, sta)
|
||||
}
|
||||
|
||||
if vobc.DirectionForward && vobc.TractionForce == 0 {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.DIR_ZERO_FORWARD, Status: 1})
|
||||
} else {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.DIR_ZERO_FORWARD, Status: 0})
|
||||
}
|
||||
if !vobc.DirectionForward && !vobc.DirectionBackward {
|
||||
vobc.TractionStatus = false
|
||||
vobc.TractionForce = 0
|
||||
@ -338,28 +341,25 @@ func trainControlDirKey(trainSpeed int32, vobc *state_proto.TrainVobcState, tcc
|
||||
if tcc.DirKey == nil {
|
||||
tcc.DirKey = &state_proto.TrainControlState_DirectionKeySwitch{Id: deviceId}
|
||||
}
|
||||
|
||||
tce := make([]train_pc_sim.TrainControlEvent, 0)
|
||||
direction := request_proto.TrainControl_Direction(request.Val)
|
||||
if trainSpeed > 0 {
|
||||
panic(sys_error.New("列车未停稳时,不能变更方向"))
|
||||
}
|
||||
vobc.DirectionBackward = false
|
||||
vobc.DirectionForward = false
|
||||
//var zeroState byte = 0
|
||||
if direction == request_proto.TrainControl_FORWARD {
|
||||
vobc.DirectionForward = true
|
||||
|
||||
} else if direction == request_proto.TrainControl_BACKWARD {
|
||||
vobc.DirectionBackward = true
|
||||
}
|
||||
|
||||
tcc.DirKey.Val = request.Val
|
||||
tce := make([]train_pc_sim.TrainControlEvent, 0)
|
||||
//tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: zeroState})
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_BACKWORD, Status: message.IsTrue(vobc.DirectionBackward)})
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_FORWORD, Status: message.IsTrue(vobc.DirectionForward)})
|
||||
if vobc.DirectionForward {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.DIR_ZERO_FORWARD, Status: 1})
|
||||
} else {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.DIR_ZERO_FORWARD, Status: 0})
|
||||
}
|
||||
|
||||
return tce
|
||||
}
|
||||
|
||||
@ -427,23 +427,23 @@ func trainControlHandle(vobc *state_proto.TrainVobcState, tcc *state_proto.Train
|
||||
vobc.BrakeForce = 0
|
||||
vobc.MaintainBrakeStatus = false
|
||||
tce := make([]train_pc_sim.TrainControlEvent, 0)
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: 0})
|
||||
var zeroState byte = 0
|
||||
var brakeState byte = 0
|
||||
|
||||
if request.Val > 0 {
|
||||
vobc.TractionStatus = true
|
||||
vobc.TractionForce = int64(request.Val * 180)
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.TRAIN_BRAKE_STATE, Status: 0})
|
||||
} else if request.Val < 0 {
|
||||
|
||||
vobc.BrakingStatus = true
|
||||
vobc.BrakeForce = int64(-request.Val * 180)
|
||||
vobc.EmergencyBrakingStatus = false
|
||||
jjzdBtn.Passed = false
|
||||
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.TRAIN_BRAKE_STATE, Status: 1})
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.OUTER_EMERGENCY_BRAKE, Status: 0})
|
||||
brakeState = 1
|
||||
} else {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: 1})
|
||||
zeroState = 1
|
||||
}
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: zeroState})
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.TRAIN_BRAKE_STATE, Status: brakeState})
|
||||
if tcc.PushHandler == nil {
|
||||
tcc.PushHandler = &state_proto.TrainControlState_PushHandler{Id: deviceId}
|
||||
}
|
||||
@ -451,10 +451,6 @@ func trainControlHandle(vobc *state_proto.TrainVobcState, tcc *state_proto.Train
|
||||
return tce
|
||||
}
|
||||
|
||||
/*func (s *VerifySimulation) GetConnTrain() *state_proto.TrainState {
|
||||
return s.findConnTrain(state_proto.TrainConnState_PC_SIM)
|
||||
}*/
|
||||
|
||||
func (s *VerifySimulation) GetConnTrain2() []*state_proto.TrainState {
|
||||
return s.findConnTrain2(state_proto.TrainConnState_PC_SIM_A, state_proto.TrainConnState_PC_SIM_B)
|
||||
}
|
||||
@ -487,6 +483,9 @@ func (s *VerifySimulation) FindConnTrain(ct state_proto.TrainConnState_TrainConn
|
||||
return findTrain
|
||||
}
|
||||
|
||||
var tmpFlag bool = false
|
||||
var testIndex uint32 = 0
|
||||
|
||||
// 4.4.1. 车载输出数字量信息报文内容
|
||||
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(connType state_proto.TrainConnState_TrainConnType, data []byte) {
|
||||
slog.Info(fmt.Sprintf("处理车载输出数字量信息报文内容:%v", hex.EncodeToString(data)))
|
||||
@ -499,12 +498,53 @@ func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(connType state_proto.T
|
||||
slog.Error("车载输出数字量,,列车未连接车载pc仿真")
|
||||
return
|
||||
}
|
||||
vobc := train.VobcState
|
||||
trainPcSimDigitalOutInfoHandleCode39_32(data[4], vobc)
|
||||
trainPcSimDigitalOutInfoHandleCode31_24(connType, data[3], vobc)
|
||||
trainPcSimDigitalOutInfoHandleCode23_16(data[2], vobc)
|
||||
trainPcSimDigitalOutInfoHandleCode15_8(data[1], vobc)
|
||||
trainPcSimDigitalOutInfoHandleCode7_0(data[0], vobc)
|
||||
d1 := data[4]
|
||||
//d2 := data[3]
|
||||
|
||||
for i, d := range data {
|
||||
slog.Info(fmt.Sprintf("index:%v ,d :%2b", i, d))
|
||||
}
|
||||
tce := make([]train_pc_sim.TrainControlEvent, 0)
|
||||
|
||||
if message.GetBit(d1, 3) == 0 {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.OUTER_EMERGENCY_BRAKE, Status: 0})
|
||||
slog.Info("111111111111111111111111111111111")
|
||||
} else {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.OUTER_EMERGENCY_BRAKE, Status: 1})
|
||||
slog.Info("22222222222222222222222222222222222222")
|
||||
}
|
||||
if message.GetBit(d1, 2) == 0 {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.TRAIN_BRAKE_STATE, Status: 1})
|
||||
}
|
||||
|
||||
/*if message.GetBit(d1, 0) == 0 {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.TRAIN_TRACTION_CUTED, Status: 1})
|
||||
}*/
|
||||
/*if message.GetBit(d2, 3) == 0 {
|
||||
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.DRIVER_ACTIVE_REPORT, Status: 1})
|
||||
}*/
|
||||
//tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.LEFT_DOOR_STATE, Status: 0})
|
||||
//tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.RIGHT_DOOR_STATE, Status: 0})
|
||||
//tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.TRAIN_INTEGRITY, Status: 1})
|
||||
|
||||
train_pc_sim.Default().PublishTrainControlEvent(train, tce)
|
||||
/*if train.VobcState.Tc1Active || train.VobcState.Tc2Active {
|
||||
aas := make([]byte, 0)
|
||||
d11 := message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD}
|
||||
d21 := message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD}
|
||||
if !tmpFlag {
|
||||
aas = append(aas, d11.Encode()...)
|
||||
aas = append(aas, d21.Encode()...)
|
||||
train_pc_sim.Default().TestSendData(train, aas)
|
||||
tmpFlag = true
|
||||
}
|
||||
}*/
|
||||
//vobc := train.VobcState
|
||||
//trainPcSimDigitalOutInfoHandleCode39_32(data[4], vobc)
|
||||
//trainPcSimDigitalOutInfoHandleCode31_24(connType, data[3], vobc)
|
||||
//trainPcSimDigitalOutInfoHandleCode23_16(data[2], vobc)
|
||||
//trainPcSimDigitalOutInfoHandleCode15_8(data[1], vobc)
|
||||
//trainPcSimDigitalOutInfoHandleCode7_0(data[0], vobc)
|
||||
}
|
||||
func trainPcSimDigitalOutInfoHandleCode39_32(d byte, vobc *state_proto.TrainVobcState) {
|
||||
vobc.MostUseBrake = message.IsTrueForByte(message.GetBit(d, 0)) //? 常用制动
|
||||
@ -599,10 +639,11 @@ func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState, create bool) er
|
||||
connState := train.ConnState
|
||||
if connState.ConnType == state_proto.TrainConnState_PC_SIM_A || connState.ConnType == state_proto.TrainConnState_PC_SIM_B {
|
||||
crErr := train_pc_sim.Default().CreateOrRemoveTrain(train, create)
|
||||
train_pc_sim.Default().CreateOrRemoveSpeedPLace(train)
|
||||
if crErr != nil {
|
||||
return crErr
|
||||
}
|
||||
train_pc_sim.Default().CreateOrRemoveSpeedPLace(train)
|
||||
|
||||
} else if connState.ConnType == state_proto.TrainConnState_VOBC {
|
||||
electrical_machinery.Default().ClearOrRemoveTrain(train)
|
||||
}
|
||||
@ -645,7 +686,7 @@ func (s *VerifySimulation) TrainPcSimMockInfo(connType state_proto.TrainConnStat
|
||||
|
||||
// 4.4.4. 车载输出BTM查询同步帧报文内容(0x04)
|
||||
func (s *VerifySimulation) TrainBtmQuery(connType state_proto.TrainConnState_TrainConnType, data []byte) {
|
||||
slog.Info(fmt.Sprintf("收到车载输出BTM查询同步帧报文内容:%v", hex.EncodeToString(data)))
|
||||
//slog.Info(fmt.Sprintf("收到车载输出BTM查询同步帧报文内容:%v", hex.EncodeToString(data)))
|
||||
if len(data) < 12 {
|
||||
slog.Error("列车btm查询报文长度错误:", len(data))
|
||||
return
|
||||
@ -693,14 +734,21 @@ func (s *VerifySimulation) TrainBtmQuery(connType state_proto.TrainConnState_Tra
|
||||
} else {
|
||||
//有数据
|
||||
aliseData, _ := hex.DecodeString(train.BtmState.Telegram)
|
||||
statusDataCf, statusDataCfOk := message.CreateBtmRspFramesData(btmRepFrame, aliseData, false, cl.TkNow(), cl.TkNow(), cl.TkNow(), true)
|
||||
statusDataCf, statusDataCfOk := message.CreateBtmRspFramesData2(btmRepFrame, aliseData, false, cl.TkNow(), cl.TkNow(), cl.TkNow(), true)
|
||||
if statusDataCfOk {
|
||||
queryData := make([]byte, 0)
|
||||
queryData = append(queryData, btmRepFrame.Encode().Encode2()...)
|
||||
queryData = append(queryData, timeSyncF.Encode().Encode2()...)
|
||||
queryData = append(queryData, statusDataCf...) //数据帧包含结束帧
|
||||
/* queryData := make([]byte, 0)
|
||||
queryData = append(queryData, btmRepFrame.Encode().Encode2()...)
|
||||
queryData = append(queryData, timeSyncF.Encode().Encode2()...)
|
||||
queryData = append(queryData, statusDataCf...) //数据帧包含结束帧
|
||||
train.BtmState.BaliseTelegramForPcSimResend = fmt.Sprintf("%X", statusDataCf)
|
||||
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_HAS_DATA, queryData)*/
|
||||
queryDataStr := make([]string, 0)
|
||||
queryDataStr = append(queryDataStr, hex.EncodeToString(btmRepFrame.Encode().Encode2()))
|
||||
queryDataStr = append(queryDataStr, hex.EncodeToString(timeSyncF.Encode().Encode2()))
|
||||
queryDataStr = append(queryDataStr, hex.EncodeToString(statusDataCf)) //数据帧包含结束帧
|
||||
train.BtmState.BaliseTelegramForPcSimResend = fmt.Sprintf("%X", statusDataCf)
|
||||
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_HAS_DATA, queryData)
|
||||
train_pc_sim.Default().SendBaliseData2(train, message.RECIVE_TRAIN_BTM_HAS_DATA, queryDataStr)
|
||||
|
||||
} else {
|
||||
slog.Error("列车pc仿真 BtmCanetClient应答帧、数据帧编码失败")
|
||||
}
|
||||
@ -733,6 +781,7 @@ func clock(atpReq *message.AtpRequestFrame) can_btm.BtmClock {
|
||||
now := time.Now()
|
||||
return can_btm.BtmClock{BtmTk: atpReq.Time, SysTk: now}
|
||||
}
|
||||
|
||||
func (s *VerifySimulation) ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage {
|
||||
msgArr := make([]message.TrainPcSimBaseMessage, 0)
|
||||
vs := train.VobcState
|
||||
@ -741,37 +790,66 @@ func (s *VerifySimulation) ObtainTrainDigitalMockData(train *state_proto.TrainSt
|
||||
if vs.Tc1Active || vs.Tc2Active {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.KEY_STATE, 1}, 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}) //列车制动状态
|
||||
}
|
||||
if vs.BrakingStatus {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.TRAIN_BRAKE_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车制动状态
|
||||
}
|
||||
|
||||
if vs.EmergencyBrakingStatus {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.OUTER_EMERGENCY_BRAKE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //紧急制动
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.OUTER_EMERGENCY_BRAKE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //紧急制动
|
||||
}
|
||||
|
||||
dir := request_proto.TrainControl_Direction(tcc.DirKey.Val)
|
||||
if dir == request_proto.TrainControl_FORWARD {
|
||||
/*if vs.DirectionForward && vs.TractionForce == 0 {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DIR_ZERO_FORWARD, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //手柄零位方向向前
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_FORWORD, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_BACKWORD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
|
||||
} else*/if dir == request_proto.TrainControl_FORWARD {
|
||||
//msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DIR_ZERO_FORWARD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //手柄零位方向向前
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_FORWORD, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_BACKWORD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
|
||||
} else if dir == request_proto.TrainControl_BACKWARD {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_FORWORD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DIR_ZERO_FORWARD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //手柄零位方向向前
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_BACKWORD, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
|
||||
//msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DIR_ZERO_FORWARD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //手柄零位方向向前
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_FORWORD, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.HANDLE_BACKWORD, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //方向手柄向前控制
|
||||
}
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.CLOSE_RIGHT_DOOR, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //关右门按钮
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.CLOSE_LEFT_DOOR, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //关左门按钮
|
||||
if vs.RightDoorCloseCommand {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.CLOSE_RIGHT_DOOR, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //关右门按钮
|
||||
}
|
||||
if vs.LeftDoorCloseCommand {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.CLOSE_LEFT_DOOR, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //关左门按钮
|
||||
}
|
||||
if vs.AllDoorClose {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DOOR_LOCK_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //车门锁闭状态
|
||||
}
|
||||
if vs.ObstacleCheckBtn {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.OBSTACLE_CHECK, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //障碍物检测按钮
|
||||
}
|
||||
if vs.BrakeHeavyFault {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.BRAKE_HEAVY_FAULT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //制动重故障
|
||||
}
|
||||
if vs.AtpCutSwitch {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.ATP_CUT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //atp切除
|
||||
}
|
||||
if vs.AtpPowerOnBtn {
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.ATP_POWER_ON, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //atp上电
|
||||
}
|
||||
|
||||
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.ATO_SEND_TRAIN, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.TURN_BACK, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.LEFT_DOOR_STATE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.RIGHT_DOOR_STATE, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.CONFIRM, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.TRAIN_INTEGRITY, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //列车完整性
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.DOOR_LOCK_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //车门锁闭状态
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.OBSTACLE_CHECK, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //障碍物检测按钮
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.BRAKE_HEAVY_FAULT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //制动重故障
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.EMERGENT_HANDLE_DOWN, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //紧急手柄拉下
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.LIFE_DOOR, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //逃生门状态
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.ATP_CUT, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //atp切除
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{39, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //非制动
|
||||
//msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{40, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //本端机械钩
|
||||
//msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{41, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //对端机械钩
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.RECIVE_TRAIN_BTN_CLEAR_ALL_PRE_DATA}) //清空应答器
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.NOT_BREAK, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //非制动
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{38, 0}, Type: message.SENDER_TRAIN_OUTR_INFO}) //只牵引
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{40, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //本端机械钩
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{41, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //对端机械钩
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.RECIVE_TRAIN_BTN_CLEAR_ALL_PRE_DATA}) //清空应答器
|
||||
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{0x00}, Type: message.RECIVE_TRAIN_DOOR_MODE}) //清空应答器
|
||||
train.BtmState = nil
|
||||
return msgArr
|
||||
}
|
||||
|
@ -153,8 +153,7 @@ func runThirdParty(s *memory.VerifySimulation) error {
|
||||
|
||||
// 停止仿真
|
||||
func stopThirdParty(s *memory.VerifySimulation) {
|
||||
// 停止动力学接口功能
|
||||
dynamics.Default().Stop()
|
||||
|
||||
// 停止半实物
|
||||
semi_physical_train.Default().Stop()
|
||||
// 联锁启动
|
||||
@ -183,6 +182,8 @@ func stopThirdParty(s *memory.VerifySimulation) {
|
||||
train_pc_sim.Default().Stop()
|
||||
|
||||
btm_vobc.Default().Stop()
|
||||
// 停止动力学接口功能
|
||||
dynamics.Default().Stop()
|
||||
}
|
||||
|
||||
func createSimulationId(projectId int32) string {
|
||||
|
Loading…
Reference in New Issue
Block a user