仿真列车模拟量输出修改
Some checks failed
local-test分支打包构建docker并发布运行 / Docker-Build (push) Failing after 2m6s

This commit is contained in:
tiger_zhou 2024-06-27 10:37:52 +08:00
parent ff7abeb414
commit df0c9f77c8
8 changed files with 399 additions and 253 deletions

View File

@ -9,7 +9,6 @@ import (
"joylink.club/bj-rtsts-server/const/balise_const"
"joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/tcp"
"joylink.club/bj-rtsts-server/third_party/train_pc_sim"
"joylink.club/bj-rtsts-server/third_party/udp"
"log/slog"
"strconv"
@ -72,71 +71,178 @@ func initTrainPc() {
return
}
trainpcClient = client2
time.Sleep(time.Millisecond * 1500)
createOrRemoveTrain()
circleSendTrainActive()
circleSendTrainMockData()
go circleSendTrainSpeedPlace()
}
func circleSendTrainActive() {
msg := &message.TrainPcSimBaseMessage{Data: []byte{0x01}, Type: train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE}
func createOrRemoveTrain() {
msgs := make([]*message.TrainPcSimBaseMessage, 0)
//msgs = append(msgs, &message.TrainPcSimBaseMessage{Data: []byte{0x00}, Type: message.RECIVE_TRAIN_CREATE_REMOVE})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Data: []byte{0x01}, Type: message.RECIVE_TRAIN_CREATE_REMOVE})
for _, msg := range msgs {
data := msg.Encode()
fmt.Println(fmt.Sprintf("发送列车创建数据:%v", hex.EncodeToString(data)))
fmt.Println(fmt.Sprintf("发送列车模拟数据:%v,命令码:%v", hex.EncodeToString(data), msg.Data[0]))
trainpcClient.Send(data)
act := &message.TrainPcSimBaseMessage{Data: make([]byte, 0), Type: train_pc_sim.SENDER_TRAIN_TC_ACTIVE}
actData := act.Encode()
time.Sleep(time.Millisecond * 1000)
}
}
func circleSendTrainActive() {
msgs := make([]*message.TrainPcSimBaseMessage, 0)
msgs = append(msgs, &message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.SENDER_TRAIN_TC_ACTIVE})
//msgs = append(msgs, &message.TrainPcSimBaseMessage{Data: []byte{}, Type: message.SENDER_TRAIN_HAND_KEY_FORWARD})
for _, msg := range msgs {
actData := msg.Encode()
fmt.Println(fmt.Sprintf("发送列车驾驶室激活:%v", hex.EncodeToString(actData)))
trainpcClient.Send(actData)
time.Sleep(time.Millisecond * 1000)
}
}
const (
a1 = 0x26
a2 = 0x27
a3 = 0x2d
a4 = 0x03
a5 = 0x1e
a6 = 0x16
a7 = 0x17
a8 = 0x0a
a9 = 0x05
a10 = 0x08
a11 = 0x07
a12 = 0x06
a13 = 0x09
a14 = 0x0f
a15 = 0x0e
a16 = 0x21
a17 = 0x15
a18 = 0x1d
a19 = 0x14
a20 = 0x13
a21 = 0x22
a22 = 0x28
a23 = 0x29
a24 = 0x1f
a25 = 0x10
a26 = 0x0c
a27 = 0x04
a28 = 0x1e
)
//eb0705c383
//eb0805c673
//eb0007040172e5
//eb600600727e
//eb00071e017985
//eb00071600bf85
//eb00071700be15
//eb00070a00b745
//eb00070500b2b5
//eb00070800b625
//eb00070700b3d5
//eb00070600b245
//eb00070900b7b5
//eb00070f00b415
//eb00070e017445
//eb00072600ab85
//eb000727016bd5
//eb500601b3b1
//eb00072100a9b5
//eb000715017eb5
//eb00071d017975
//eb00071400bee5
//eb000713017d15
//eb000722016885
//eb000728016e25
//eb000729016fb5
//eb00071f017815
//eb00071000bc25
//eb01190001000000000000000000000000667b6e43026dfd4e
//
//
//eb0405c373
//eb000714017f25
//eb0905c7e3
//eb0705c383
//eb00072d00acb5
//eb00070300b115
func circleSendTrainMockData() {
msg := &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.SENDER_TRAIN_OUTR_INFO
data := []byte{0x00, 1}
msg.Data = data
code := msg.Encode()
fmt.Println(fmt.Sprintf("发送列车模拟量输出数据:%v 模拟量下标:%v", hex.EncodeToString(code), 0x00))
trainpcClient.Send(code)
//time.Sleep(time.Millisecond * 1000)
msg = &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.SENDER_TRAIN_OUTR_INFO
data = []byte{0x01, 1}
msg.Data = data
code = msg.Encode()
fmt.Println(fmt.Sprintf("发送列车模拟量输出数据:%v 模拟量下标:%v", hex.EncodeToString(code), 0x01))
trainpcClient.Send(code)
//time.Sleep(time.Millisecond * 1000)
msg = &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.SENDER_TRAIN_OUTR_INFO
data = []byte{0x02, 0}
msg.Data = data
code = msg.Encode()
fmt.Println(fmt.Sprintf("发送列车模拟量输出数据:%v 模拟量下标:%v", hex.EncodeToString(code), 0x02))
trainpcClient.Send(code)
msgs := make([]*message.TrainPcSimBaseMessage, 0)
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{byte(0), 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{byte(16), 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{byte(3), 0}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{byte(3), 0}})
//msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{byte(16), 1}})
//msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{byte(45), 1}})
//msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{byte(46), 1}})
/* for i := 3; i <= 50; i++ {
if i != 2 {
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{byte(i), 0}})
}
}*/
//msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{14, 0}})
//msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{1, 1}})
/*msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{1, 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{2, 0}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{12, 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{16, 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{20, 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{3, 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{4, 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{6, 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{7, 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{30, 1}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{22, 0}})
msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{23, 0}})*/
//msgs = append(msgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{3, 0}})
for _, msg := range msgs {
data := msg.Encode()
fmt.Println(fmt.Sprintf("发送列车模拟数据:%v,命令码:%v", hex.EncodeToString(data), msg.Data[0]))
trainpcClient.Send(data)
time.Sleep(time.Millisecond * 1000)
}
}
func circleSendTrainSpeedPlace() {
for {
data := make([]byte, 0)
data = binary.BigEndian.AppendUint16(data, uint16(1))
data = binary.BigEndian.AppendUint32(data, uint32(3))
data = binary.BigEndian.AppendUint32(data, uint32(4))
data = binary.BigEndian.AppendUint32(data, uint32(5))
data = binary.BigEndian.AppendUint32(data, uint32(6))
data = binary.BigEndian.AppendUint16(data, uint16(2))
//data = binary.BigEndian.AppendUint16(data, uint16(1))
//data = binary.BigEndian.AppendUint16(data, uint16(0))
//data = binary.BigEndian.AppendUint16(data, uint16(0))
//data = binary.BigEndian.AppendUint32(data, uint32(940))
//data = binary.BigEndian.AppendUint32(data, uint32(940))
data = binary.BigEndian.AppendUint32(data, uint32(0))
data = binary.BigEndian.AppendUint32(data, uint32(0))
data = binary.BigEndian.AppendUint32(data, uint32(940))
data = binary.BigEndian.AppendUint32(data, uint32(940))
now := time.Now().UTC()
sec := now.Unix()
data = binary.BigEndian.AppendUint32(data, uint32(sec))
data = binary.BigEndian.AppendUint32(data, uint32(27797))
data = binary.BigEndian.AppendUint16(data, uint16(now.UnixMilli()-sec*1000))
bm := &message.TrainPcSimBaseMessage{Type: train_pc_sim.SENDER_TRAIN_LOCATION_INFO, Data: data}
dataCode := bm.Encode()
fmt.Println(fmt.Sprintf("发送列车位置信息:%v", hex.EncodeToString(dataCode)))
trainpcClient.Send(dataCode)
ss := "eb011d000200000000000000000000000000000000000017af0299ffff"
data, _ = hex.DecodeString(ss)
//bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data}
//dataCode := bm.Encode()
//fmt.Println(fmt.Sprintf("发送列车位置信息:%v", hex.EncodeToString(data)))
trainpcClient.Send(data)
//dd := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_OUTR_INFO, Data: []byte{3, 0}}
//trainpcClient.Send(dd.Encode())
time.Sleep(time.Millisecond * 80)
}
}
func trainPcDataHandle(n int, data []byte) {
hexData := hex.EncodeToString(data)
slog.Info(fmt.Sprintf("列车pc仿真接口接受数据:%v", hexData))
return
//hexData := hex.EncodeToString(data[:n])
//slog.Info(fmt.Sprintf("列车pc仿真接口长度:%v,实际长度:%v,接受数据:%v", len(data), n, hexData))
}
func trainPcConnErr(err error) {
@ -145,9 +251,9 @@ func main() {
initConfig()
//initBtmTest()
//initTrainPc()
initTrainPc()
//initAccTest()
initSpeedTest()
//initSpeedTest()
for {
}

View File

@ -7,7 +7,6 @@ import (
"fmt"
"github.com/snksoft/crc"
"joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/train_pc_sim"
"joylink.club/bj-rtsts-server/third_party/udp"
"sync/atomic"
"testing"
@ -21,7 +20,7 @@ const (
func TestMsg22(t *testing.T) {
msg := &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE
msg.Type = message.RECIVE_TRAIN_CREATE_REMOVE
data := []byte{1}
msg.Data = data
code := msg.Encode()

View File

@ -4,7 +4,6 @@ import (
"bytes"
"encoding/binary"
"fmt"
"github.com/snksoft/crc"
"strconv"
"time"
)
@ -33,10 +32,38 @@ func (tp *TrainPcSimBaseMessage) Encode() []byte {
//pack = append(pack, data...)
}
//pack = binary.BigEndian.AppendUint16(pack, uint16(0))
pack = binary.BigEndian.AppendUint16(pack, uint16(crc.CalculateCRC(crc.CRC16, pack[1:])))
pack = binary.BigEndian.AppendUint16(pack, uint16(0xffff))
//pack = binary.BigEndian.AppendUint16(pack, uint16(crc.CalculateCRC(crc.CRC16, pack[1:])))
return pack
}
func TrainPcSimDecode(data []byte) []*TrainPcSimBaseMessage {
bms := make([]*TrainPcSimBaseMessage, 0)
buf := bytes.NewBuffer(data)
//hexData := hex.EncodeToString(data)
for {
if buf.Len() < 3 {
return bms /*, fmt.Errorf("解析仿真pc数据失败数据长度小于3")*/
}
header, _ := buf.ReadByte()
if header != PC_SIM_HEADER {
return bms /*, fmt.Errorf("数据包头错误,数据头为%v", hexData)*/
}
msgType, _ := buf.ReadByte()
dataLen, _ := buf.ReadByte()
dataLen = dataLen - 3 - 2
if buf.Len() < int(dataLen) {
return bms /*, fmt.Errorf("数据长度不够,数据类型为%v,需要长度:%v,实际长度:%v", msgType, dataLen, buf.Len())*/
}
sourceData := make([]byte, dataLen)
buf.Read(sourceData)
var crc uint16
binary.Read(buf, binary.BigEndian, &crc)
bms = append(bms, &TrainPcSimBaseMessage{Type: msgType, DataLen: dataLen - 2, Data: sourceData, Crc: crc})
}
return bms
}
// 解码
func (tp *TrainPcSimBaseMessage) Decode(data []byte) error {
@ -129,14 +156,19 @@ func (tp *TrainSpeedPlaceReportMsg) Decode(d []byte) {
binary.Read(buf, binary.BigEndian, &c2)
var ts uint32
binary.Read(buf, binary.BigEndian, &ts)
fmt.Println(fmt.Sprintf("列车方向:%v,1路脉冲数:%v,2路脉冲数:%v,1路累计数:%v,2路累计数:%v,时间:%v", runDir, s1, s2, c1, c2, ts))
var mts uint16
binary.Read(buf, binary.BigEndian, &mts)
fmt.Println(fmt.Sprintf("列车方向:%v,1路脉冲数:%v,2路脉冲数:%v,1路累计数:%v,2路累计数:%v,时间:%v,时间(毫秒):%v", runDir, s1, s2, c1, c2, ts, mts))
}
// 轨旁向列车pc仿真发送的命令码
const (
//手柄零位方向向前
DIR_ZERO_FORWARD = 0x2d
//钥匙开关状态
KEY_STATE = iota
KEY_STATE = iota - 1
//手柄向前控制
HANDLE_FORWORD
//手柄向后控制

View File

@ -1,4 +1,4 @@
package train_pc_sim
package message
const (
//仿真系统车载pc仿真平台
@ -47,3 +47,13 @@ const (
//状态查询帧
RECIVE_TRAIN_QUERY_STATUS = 0x04
)
const (
FLAG_CAMMAND_CREATE_TRAIN = 0x01
FLAG_CAMMAND_REMOVE_TRAIN = 0x00
//TRAIN_OUT_COMPLATE_STATE = 16 //仿真输出数字量-完成性
//TRAIN_OUT_CONFIRMBTN_STATE = 12 //确认摁钮
//TRAIN_OUT_TRACTOR_BRAKING_HANDLER_TO_ZERO_STATE = 14 //牵引制动力手柄归零
//TRAIN_OUT_DIR_FONT_STATE = 1 //手柄方向向前
//TRAIN_OUT_DIR_BACK_STATE = 2 //手柄方向向后
)

View File

@ -2,10 +2,10 @@ package main
import (
"encoding/binary"
"encoding/hex"
"fmt"
"io"
"joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/train_pc_sim"
"log/slog"
"net"
"strconv"
@ -80,13 +80,13 @@ func createServer(port int, h TcpMsgHandler) {
}
func connTrain() *message.TrainPcSimBaseMessage {
msg := &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE
msg.Type = message.RECIVE_TRAIN_CREATE_REMOVE
msg.Data = []byte{0x01}
return msg
}
func changeDoorMode() *message.TrainPcSimBaseMessage {
msg := &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.RECIVE_TRAIN_DOOR_MODE
msg.Type = message.RECIVE_TRAIN_DOOR_MODE
msg.Data = []byte{0x02}
return msg
}
@ -103,7 +103,7 @@ func boolsToByte(flags [8]bool) byte {
func pcSimInfoOut() *message.TrainPcSimBaseMessage {
msg := &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.RECIVE_TRAIN_INTERFACE_CABINET_OUTR
msg.Type = message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR
data := make([]byte, 0)
data = append(data, boolsToByte([8]bool{false, false, false, false, false, false, false, false}))
data = append(data, boolsToByte([8]bool{false, false, false, false, false, false, false, false}))
@ -115,7 +115,7 @@ func pcSimInfoOut() *message.TrainPcSimBaseMessage {
}
func pcSimInfoOutReport() *message.TrainPcSimBaseMessage {
msg := &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK
msg.Type = message.RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK
data := make([]byte, 0)
data = append(data, boolsToByte([8]bool{true, true, false, false, false, false, false, false}))
msg.Data = data
@ -126,7 +126,7 @@ var autoIncNo = 0
func queryBtm() *message.TrainPcSimBaseMessage {
msg := &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.RECIVE_TRAIN_QUERY_STATUS
msg.Type = message.RECIVE_TRAIN_QUERY_STATUS
autoIncNo = autoIncNo + 1
data := make([]byte, 0)
data = append(data, 0x62)
@ -149,7 +149,7 @@ func queryBtm() *message.TrainPcSimBaseMessage {
func pcSimNumReportOut() *message.TrainPcSimBaseMessage {
msg := &message.TrainPcSimBaseMessage{}
msg.Type = train_pc_sim.RECIVE_TRAIN_MOCK_DATA
msg.Type = message.RECIVE_TRAIN_MOCK_DATA
sd := uint16(1234)
data := make([]byte, 2)
binary.BigEndian.PutUint16(data, sd)
@ -168,16 +168,17 @@ func startService(port int) {
createServer(port, func(n int, data []byte) {
msg := &message.TrainPcSimBaseMessage{}
d := data[:n]
fmt.Println(fmt.Sprintf("接受数据:%v", hex.EncodeToString(d)))
msg.Decode(d)
pd := fmt.Sprintf("%X", d)
if msg.Type == train_pc_sim.SENDER_TRAIN_TC_ACTIVE {
if msg.Type == message.SENDER_TRAIN_TC_ACTIVE {
fmt.Println("接收驾驶端激活 port:", port)
} else if msg.Type == train_pc_sim.SENDER_TRAIN_TC_NOT_ACTIVE {
} else if msg.Type == message.SENDER_TRAIN_TC_NOT_ACTIVE {
fmt.Println("接收驾驶端未激活 port:", port)
fmt.Println(pd)
} else if msg.Type == train_pc_sim.SENDER_TRAIN_OUTR_INFO {
} else if msg.Type == message.SENDER_TRAIN_OUTR_INFO {
fmt.Println(pd)
t := msg.Data[0]
s := msg.Data[1]
@ -196,7 +197,7 @@ func startService(port int) {
}
fmt.Println("接受列车输出数字量", tt, s, port)
fmt.Println(pd)
} else if msg.Type == train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE {
} else if msg.Type == message.RECIVE_TRAIN_CREATE_REMOVE {
state := msg.Data[0]
if state == 0x01 {
fmt.Println("创建列车 port:", port)
@ -205,22 +206,22 @@ func startService(port int) {
}
fmt.Println(pd)
} else if msg.Type == train_pc_sim.SENDER_TRAIN_HAND_KEY_FORWARD {
} else if msg.Type == message.SENDER_TRAIN_HAND_KEY_FORWARD {
fmt.Println("列车手柄向前 port:", port)
fmt.Println(pd)
} else if msg.Type == train_pc_sim.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD {
} else if msg.Type == message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD {
fmt.Println("列车手柄取消向前 port:", port)
fmt.Println(pd)
} else if msg.Type == train_pc_sim.RECIVE_TRAIN_HAND_KEY_BACKWARD {
} else if msg.Type == message.RECIVE_TRAIN_HAND_KEY_BACKWARD {
fmt.Println("列车手柄向后 port:", port)
fmt.Println(pd)
} else if msg.Type == train_pc_sim.RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD {
} else if msg.Type == message.RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD {
fmt.Println("列车手柄取消向后 port:", port)
fmt.Println(pd)
} else if msg.Type == train_pc_sim.RECIVE_TRAIN_BTM_HAS_DATA {
} else if msg.Type == message.RECIVE_TRAIN_BTM_HAS_DATA {
fmt.Println("有数据应答 port:", port)
fmt.Println(pd)
} else if msg.Type == train_pc_sim.RECIVE_TRAIN_BTM_NOT_DATA {
} else if msg.Type == message.RECIVE_TRAIN_BTM_NOT_DATA {
} /*else if msg.Type == train_pc_sim.SENDER_TRAIN_LOCATION_INFO {
fmt.Println("列车速度位置报告")
@ -262,9 +263,13 @@ func main() {
msg := changeDoorMode()
serConn.Write(msg.Encode())
} else if command == "info-out" {
msg := pcSimInfoOut()
serConn.Write(msg.Encode())
hexStr := "eb010a8670400000ffff"
data, _ := hex.DecodeString(hexStr)
//msg := pcSimInfoOut()
//serConn.Write(msg.Encode())
serConn.Write(data)
} else if command == "info-out-report" {
msg := pcSimInfoOutReport()
serConn.Write(msg.Encode())
} else if command == "query-btm" {
@ -273,7 +278,11 @@ func main() {
} else if command == "num-out" {
msg := pcSimNumReportOut()
serConn.Write(msg.Encode())
} else if command == "query" {
hexStr := "eb04110c50204b900000172065fc160000"
data, _ := hex.DecodeString(hexStr)
serConn.Write(data)
}
command = ""
/*content, _ := reader.ReadString('\n')

View File

@ -25,7 +25,8 @@ type TrainPcSim interface {
tpapi.ThirdPartyApiService
Start(pcSimManage TrainPcSimManage)
Stop()
// SendDriverActive 发送驾驶端激活
// SendDriverActive Deprecated 发送驾驶端激活
SendDriverActive(train *state_proto.TrainState)
// SendHandleSwitch 发送牵引制动手柄
SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState)
@ -39,13 +40,15 @@ type TrainPcSim interface {
// CreateOrRemoveSpeedPLace 创建或删除速度位置信息
CreateOrRemoveSpeedPLace(train *state_proto.TrainState)
// CreateOrRemoveTrain 创建或删除列车
CreateOrRemoveTrain(train *state_proto.TrainState, msgType byte, data []byte) error
CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error
}
type TrainPcSimManage interface {
GetTrainPcSimConfig() []config.VehiclePCSimConfig
//GetConnTrain() *state_proto.TrainState
GetConnTrain2() []*state_proto.TrainState
//获取列车模拟量数据
ObtainTrainDigitalMockData(train *state_proto.TrainState) []message.TrainPcSimBaseMessage
// TrainPcSimDigitalOutInfoHandle 4.4.1. 车载输出数字量信息报文内容
TrainPcSimDigitalOutInfoHandle(connType state_proto.TrainConnState_TrainConnType, data []byte)
// TrainPcSimDigitalReportHandle 4.4.2. 车载输出数字反馈量信息报文内容
@ -65,38 +68,40 @@ type trainPcReciverData struct {
}
func (rd *trainPcReciverData) receiverDataHandle(n int, data []byte) {
hexSourceData := hex.EncodeToString(data)
slog.Info(fmt.Sprintf("pc仿真接收数据%v,类型:%v", hexSourceData, hexSourceData))
connType := state_proto.TrainConnState_PC_SIM_A
if rd.clientKey == "B" {
connType = state_proto.TrainConnState_PC_SIM_B
}
baseMsg := &message.TrainPcSimBaseMessage{}
err := baseMsg.Decode(data)
if err != nil {
slog.Error("车载pc仿真接受数据解析失败 ")
return
}
slog.Info(fmt.Sprintf("pc仿真接收数据%v,类型:%v", hexSourceData, baseMsg.Type))
switch baseMsg.Type {
//case RECIVE_TRAIN_CREATE_REMOVE:
// pc.trainPcSimManage.TrainPcSimConnOrRemoveHandle(baseMsg.Data[0])
case RECIVE_TRAIN_INTERFACE_CABINET_OUTR:
rd.pcSimManage.TrainPcSimDigitalOutInfoHandle(connType, baseMsg.Data)
case RECIVE_TRAIN_INTERFACE_CABINET_OUTR_BACK:
rd.pcSimManage.TrainPcSimDigitalReportHandle(connType, baseMsg.Data)
case RECIVE_TRAIN_QUERY_STATUS:
rd.pcSimManage.TrainBtmQuery(connType, baseMsg.Data)
case RECIVE_TRAIN_MOCK_DATA:
rd.pcSimManage.TrainPcSimMockInfo(connType, baseMsg.Data)
//case RECIVE_TRAIN_DOOR_MODE:
// pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0])
}
//receiveData := data[:n]
//
//hexSourceData := hex.EncodeToString(receiveData)
//
//slog.Info(fmt.Sprintf("接受列车激活端:%v pc仿真接收数据%v", rd.clientKey, hexSourceData))
//trainPcMsgs := message.TrainPcSimDecode(receiveData)
//connType := state_proto.TrainConnState_PC_SIM_A
//if rd.clientKey == "B" {
// connType = state_proto.TrainConnState_PC_SIM_B
//}
//for _, baseMsg := range trainPcMsgs {
// slog.Info(fmt.Sprintf("pc仿真接收数据%v,类型:%v", 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_BACK:
// rd.pcSimManage.TrainPcSimDigitalReportHandle(connType, baseMsg.Data)
// case message.RECIVE_TRAIN_QUERY_STATUS:
// rd.pcSimManage.TrainBtmQuery(connType, baseMsg.Data)
// case message.RECIVE_TRAIN_MOCK_DATA:
// rd.pcSimManage.TrainPcSimMockInfo(connType, baseMsg.Data)
// //case RECIVE_TRAIN_DOOR_MODE:
// // pc.trainPcSimManage.TrainDoorModeHandle(baseMsg.Data[0])
// }
//}
}
const Name = "车载pc仿真"
const CLIENT_KEY = "clientKey"
//const CLIENT_KEY = "clientKey"
func FindTrainPcSimClientKey(t *state_proto.TrainState) string {
if t.ConnState.ConnType == state_proto.TrainConnState_PC_SIM_A {
@ -132,8 +137,6 @@ func Default() TrainPcSim {
type trainPcSimService struct {
state tpapi.ThirdPartyApiServiceState
//pcSimClient *tcp.TcpClient
//pcSimClientMap map[string]*tcp.TcpClient
newPcSimclientMap map[string]*trainPcReciverData
cancleContext context.CancelFunc
trainPcSimManage TrainPcSimManage
@ -150,35 +153,19 @@ func (d *trainPcSimService) newCloseAllConn() {
for _, rd := range d.newPcSimclientMap {
if rd != nil {
rd.tcpClient.Close()
rd.tcpClient = nil
}
}
}
/*
func (d *trainPcSimService) closeAllConn() {
for key, client := range d.pcSimClientMap {
if client != nil {
client.Close()
}
delete(d.pcSimClientMap, key)
}
}
*/
func (d *trainPcSimService) newCloseConn(clientKey string) {
rd := d.newPcSimclientMap[clientKey]
if rd != nil {
rd.tcpClient.Close()
rd.tcpClient = nil
}
}
/*
func (d *trainPcSimService) closeConn(clientKey string) {
if d.pcSimClientMap[clientKey] != nil {
d.pcSimClientMap[clientKey].Close()
delete(d.pcSimClientMap, clientKey)
}
}
*/
func (d *trainPcSimService) findConfig(tcChar string) (*config.VehiclePCSimConfig, error) {
configFlag := false
if tcChar == "A" {
@ -186,15 +173,15 @@ func (d *trainPcSimService) findConfig(tcChar string) (*config.VehiclePCSimConfi
} else if tcChar == "B" {
configFlag = false
} else {
return nil, fmt.Errorf("")
return nil, fmt.Errorf(fmt.Sprintf("未知车载pc连接标识:%v", tcChar))
}
for _, config := range d.configs {
if config.Open && config.TrainEnds == configFlag {
return &config, nil
for _, cfg := range d.configs {
if cfg.Open && cfg.TrainEnds == configFlag {
return &cfg, nil
}
}
return nil, fmt.Errorf("")
return nil, fmt.Errorf("未找到对应的车载pc连接配置")
}
func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
@ -202,7 +189,6 @@ func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
for {
select {
case <-ctx.Done():
//d.closeAllConn()
d.newCloseAllConn()
return
default:
@ -213,39 +199,33 @@ func (d *trainPcSimService) connTrainPcSim(ctx context.Context) {
clientKey := FindTrainPcSimClientKey(t)
if clientKey == "" {
slog.Error("未找到对应的pc仿真连接,trainId:", t.Id, "删除对应客户端")
//d.closeConn(clientKey)
d.newCloseConn(clientKey)
continue
}
//client := d.pcSimClientMap[clientKey]
rd := d.newPcSimclientMap[clientKey]
if rd == nil {
d.newPcSimclientMap[clientKey] = &trainPcReciverData{pcSimManage: d.trainPcSimManage, clientKey: clientKey, tcpClient: &tcp.TcpClient{}}
}
if !rd.tcpClient.IsConning() {
//client.Close()
d.newCloseConn(clientKey)
d.initConn(clientKey)
}
}
}
time.Sleep(time.Second)
}
}()
}
func (d *trainPcSimService) initConn(clientKey string) {
rd := d.newPcSimclientMap[clientKey]
if rd == nil {
if rd != nil && rd.tcpClient != nil && rd.tcpClient.IsConning() {
return
}
rd = &trainPcReciverData{pcSimManage: d.trainPcSimManage, clientKey: clientKey, tcpClient: &tcp.TcpClient{}}
d.newPcSimclientMap[clientKey] = rd
}
cfg, _ := d.findConfig(clientKey)
addr := fmt.Sprintf("%v:%v", cfg.PcSimIp, cfg.PcSimPort)
@ -257,41 +237,25 @@ func (d *trainPcSimService) initConn(clientKey string) {
rd.tcpClient = client2
}
/*if d.pcSimClientMap[clientKey] != nil {
return
}
cfg, _ := d.findConfig(clientKey)
addr := fmt.Sprintf("%v:%v", cfg.PcSimIp, cfg.PcSimPort)
properties := map[string]interface{}{
CLIENT_KEY: clientKey,
}
client2, err := tcp.StartTcpClient(addr, properties, d.reivceData, d.readError)
if err != nil {
slog.Error("车载pc连接失败 clientKey:", clientKey, "error:", err.Error())
d.updateState(tpapi.ThirdPartyState_Broken)
} else {
d.pcSimClientMap[clientKey] = client2
}*/
}
func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
configs := pcSimManage.GetTrainPcSimConfig()
d.newPcSimclientMap = make(map[string]*trainPcReciverData)
//d.pcSimClientMap = map[string]*tcp.TcpClient{}
if len(configs) <= 0 {
slog.Info("车载pc仿真配置未开启")
return
}
allClosed := true
closedCount := 0
for _, c := range configs {
if !c.Open {
allClosed = false
closedCount++
}
}
if !allClosed {
slog.Info("车载pc仿真配置未开启")
if closedCount == len(configs) {
slog.Error("车载pc仿真配置未开启")
return
}
d.configs = configs
@ -299,8 +263,6 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
d.cancleContext = ctxFun
d.trainPcSimManage = pcSimManage
d.connTrainPcSim(ctx)
//FireTrainControlEventType.Subscribe(wd, d.trainControlEventHandle)
d.updateState(tpapi.ThirdPartyState_Normal)
go d.sendTrainLocationAndSpeedTask(ctx)
}
@ -323,14 +285,16 @@ func (d *trainPcSimService) CreateOrRemoveSpeedPLace(train *state_proto.TrainSta
d.speedPlace = nil
}
}
func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, msgType byte, data []byte) error {
func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, isCreate bool) error {
clientKey := FindTrainPcSimClientKey(train)
log := "删除列车"
if msgType == RECIVE_TRAIN_CREATE_REMOVE && data[0] == 0x01 {
log = "创建列车"
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: msgType}
msg := &message.TrainPcSimBaseMessage{Data: data, Type: message.RECIVE_TRAIN_CREATE_REMOVE}
rd := d.newPcSimclientMap[clientKey]
if rd != nil {
sd := msg.Encode()
@ -339,16 +303,36 @@ func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, m
if err != nil {
return err
}
if data[0] != 0x01 {
initTrainErr := d.initTrain(rd, train, isCreate)
if !isCreate {
d.newCloseConn(clientKey)
}
if initTrainErr != nil {
return initTrainErr
}
/*client := d.pcSimClientMap[clientKey]
err := client.Send(msg.Encode())
if data[0] != 0x01 {
d.closeConn(clientKey)
}*/
}
return nil
}
func (d *trainPcSimService) initTrain(rd *trainPcReciverData, train *state_proto.TrainState, isCreate bool) error {
msgs := make([]message.TrainPcSimBaseMessage, 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}) //驾驶室激活
}
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)
}
}
return nil
}
@ -369,23 +353,15 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
s1, s2 := train.PluseCount.PulseCount1, train.PluseCount.PulseCount2
d.speedPlace.ParsePulseCount1(s1, s2)
data := d.speedPlace.Encode(train.TrainRunUp, s1, s2)
bm := &message.TrainPcSimBaseMessage{Type: SENDER_TRAIN_LOCATION_INFO, Data: data}
bm := &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_LOCATION_INFO, Data: data}
train.PluseCount.PulseCount1 = 0
train.PluseCount.PulseCount2 = 0
dataCode := bm.Encode()
slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode)))
//slog.Info(fmt.Sprintf("发送列车速度位置,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode)))
err := rd.tcpClient.Send(dataCode)
if err != nil {
slog.Error(fmt.Sprintf("发送列车速度位置失败,列车:%v,发送数据:%v", train.Id, hex.EncodeToString(dataCode)))
}
/*client := d.pcSimClientMap[clientKey]
s1, s2 := train.PluseCount.PulseCount1, train.PluseCount.PulseCount2
d.speedPlace.ParsePulseCount1(s1, s2)
data := d.speedPlace.Encode(train.TrainRunUp, s1, s2)
bm := &message.TrainPcSimBaseMessage{Type: SENDER_TRAIN_LOCATION_INFO, Data: data}
train.PluseCount.PulseCount1 = 0
train.PluseCount.PulseCount2 = 0
client.Send(bm.Encode())*/
}
}
@ -394,7 +370,7 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
}
}
// 发送驾驶激活
// SendDriverActive Deprecated 发送驾驶激活
func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
vobc := train.VobcState
@ -405,15 +381,15 @@ func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
msg := &message.TrainPcSimBaseMessage{Data: defulatBuf}
if train.TrainRunUp {
if vobc.Tc1Active {
msg.Type = SENDER_TRAIN_TC_ACTIVE
msg.Type = message.SENDER_TRAIN_TC_ACTIVE
} else if vobc.Tc1Active == false {
msg.Type = SENDER_TRAIN_TC_NOT_ACTIVE
msg.Type = message.SENDER_TRAIN_TC_NOT_ACTIVE
}
} else if !train.TrainRunUp {
if vobc.Tc2Active {
msg.Type = SENDER_TRAIN_TC_ACTIVE
msg.Type = message.SENDER_TRAIN_TC_ACTIVE
} else if vobc.Tc2Active == false {
msg.Type = SENDER_TRAIN_TC_NOT_ACTIVE
msg.Type = message.SENDER_TRAIN_TC_NOT_ACTIVE
}
}
//:"创建列车-列车号:1,发送数据:eb0050010156e4"}
@ -437,31 +413,33 @@ func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, t
//client := d.pcSimClientMap[clientKey]
msg := &message.TrainPcSimBaseMessage{}
newTraction := vobc.TractionForce
newBrake := -vobc.BrakeForce
newOldBrakeForce := -oldBrakeForce
//newBrake := -vobc.BrakeForce
//newOldBrakeForce := -oldBrakeForce
if tractionState {
if newTraction <= oldTraction && newTraction == 0 {
//手柄取消前进
msg.Type = RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD
msg.Type = message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD
} else if newTraction > oldTraction {
//手柄前进
msg.Type = SENDER_TRAIN_HAND_KEY_FORWARD
msg.Type = message.SENDER_TRAIN_HAND_KEY_FORWARD
} else {
//手柄前进
msg.Type = SENDER_TRAIN_HAND_KEY_FORWARD
msg.Type = message.SENDER_TRAIN_HAND_KEY_FORWARD
}
} else {
if newBrake >= newOldBrakeForce && newBrake == 0 {
/*if newBrake >= newOldBrakeForce && newBrake == 0 {
//手柄取消后退
msg.Type = RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD
} else if newBrake < newOldBrakeForce {
msg.Type = message.RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD
} else
if newBrake < newOldBrakeForce {
//手柄后退
msg.Type = RECIVE_TRAIN_HAND_KEY_BACKWARD
msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD
} else {
//手柄后退
msg.Type = RECIVE_TRAIN_HAND_KEY_BACKWARD
}
msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD
}*/
msg.Type = message.RECIVE_TRAIN_HAND_KEY_BACKWARD
}
da := msg.Encode()
slog.Info("发送列车手柄消息", "clientKey", clientKey, "msg", hex.EncodeToString(da))
@ -476,12 +454,12 @@ func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, tr
baseMsgs := make([]*message.TrainPcSimBaseMessage, 0)
if !trainForward && !trainBackward {
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD})
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD})
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CANCLE_FORWARD})
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_CACLE_BACKWARD})
} else if trainForward {
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: SENDER_TRAIN_HAND_KEY_FORWARD})
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.SENDER_TRAIN_HAND_KEY_FORWARD})
} else if trainBackward {
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: RECIVE_TRAIN_HAND_KEY_BACKWARD})
baseMsgs = append(baseMsgs, &message.TrainPcSimBaseMessage{Type: message.RECIVE_TRAIN_HAND_KEY_BACKWARD})
}
clientKey := FindTrainPcSimClientKey(train)
rd := d.newPcSimclientMap[clientKey]
@ -534,7 +512,7 @@ func (d *trainPcSimService) PublishTrainControlEvent(train *state_proto.TrainSta
//client := d.pcSimClientMap[clientKey]
for _, event := range events {
msg := &message.TrainPcSimBaseMessage{}
msg.Type = SENDER_TRAIN_OUTR_INFO
msg.Type = message.SENDER_TRAIN_OUTR_INFO
data := []byte{event.Command, event.Status}
msg.Data = data
code := msg.Encode()

View File

@ -5,7 +5,6 @@ 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"
@ -171,7 +170,7 @@ func TrainConnTypeUpdate(vs *VerifySimulation, ct *dto.TrainConnThirdDto) {
train.ConnState.ConnType = state_proto.TrainConnState_NONE
panic(sys_error.New(err.Error()))
}
train_pc_sim.Default().SendDriverActive(train)
//train_pc_sim.Default().SendDriverActive(train)
}
}

View File

@ -43,11 +43,11 @@ func ControlTrainUpdate(s *VerifySimulation, ct *request_proto.TrainControl) {
tce = trainControlEB(vobc, tcc, ct.Button, ct.DeviceId, 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
//train_pc_sim.Default().SendTrainDirection(sta.VobcState.DirectionForward, sta.VobcState.DirectionBackward)
train_pc_sim.Default().SendTrainDirection(sta, sta.VobcState.DirectionForward, sta.VobcState.DirectionBackward)
} else if ct.ControlType == request_proto.TrainControl_HANDLER {
oldTraction := sta.VobcState.TractionForce
oldBrakeForce := sta.VobcState.BrakeForce
@ -88,7 +88,7 @@ func trainControlEB(vobc *state_proto.TrainVobcState, tcc *state_proto.TrainCont
vobc.TractionForce = 0
vobc.BrakeForce = DEFAULT_BRAKE_FORCE
return nil
return []train_pc_sim.TrainControlEvent{{Command: message.OUTER_EMERGENCY_BRAKE, Status: 1}, {Command: message.TRAIN_BRAKE_STATE, Status: 1}} //紧急制动
}
// 列车方向
@ -113,32 +113,16 @@ func trainControlDirKey(trainSpeed int32, vobc *state_proto.TrainVobcState, tcc
} else if direction == request_proto.TrainControl_BACKWARD {
vobc.DirectionBackward = true
}
/* if direction == request_proto.TrainControl_NEUTRALWARD {
vobc.DirectionBackward = false
vobc.DirectionForward = false
} else if trainSpeed > 0 && direction != vobc.HistoryDir {
tcc.DirKey.Val = uint32(vobc.HistoryDir.Number())
if vobc.HistoryDir == request_proto.TrainControl_FORWARD {
vobc.DirectionForward = true
} else if vobc.HistoryDir == request_proto.TrainControl_BACKWARD {
vobc.DirectionBackward = true
}
panic(sys_error.New("列车未停稳时,不能变更方向"))
}
vobc.DirectionBackward = false
vobc.DirectionForward = false
if direction == request_proto.TrainControl_FORWARD {
vobc.DirectionForward = true
vobc.HistoryDir = request_proto.TrainControl_FORWARD
} else if direction == request_proto.TrainControl_BACKWARD {
vobc.DirectionBackward = true
vobc.HistoryDir = request_proto.TrainControl_BACKWARD
}*/
tcc.DirKey.Val = request.Val
tce := make([]train_pc_sim.TrainControlEvent, 0)
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_FORWORD, Status: message.IsTrue(vobc.DirectionForward)})
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
}
@ -167,14 +151,6 @@ func trainControlDriverKey(train *state_proto.TrainState, request *request_proto
}
panic(sys_error.New("驾驶端不能同时激活"))
}
/*train.TrainActiveDirection = 0
if vobc.Tc1Active {
//train.TrainActiveDirection = 1
train.TrainRunUp = true
} else if vobc.Tc2Active {
//train.TrainActiveDirection = 2
train.TrainRunUp = false
}*/
var addNew = true
for _, k := range tcc.DriverKey {
if k.Id == deviceId {
@ -217,6 +193,7 @@ func trainControlHandle(vobc *state_proto.TrainVobcState, tcc *state_proto.Train
tcc.Ebutton.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})
} else {
tce = append(tce, train_pc_sim.TrainControlEvent{Command: message.HANDLE_TO_ZERO, Status: 1})
}
@ -265,6 +242,7 @@ func (s *VerifySimulation) FindConnTrain(ct state_proto.TrainConnState_TrainConn
// 4.4.1. 车载输出数字量信息报文内容
func (s *VerifySimulation) TrainPcSimDigitalOutInfoHandle(connType state_proto.TrainConnState_TrainConnType, data []byte) {
slog.Info(fmt.Sprintf("处理车载输出数字量信息报文内容:%v", hex.EncodeToString(data)))
train := s.FindConnTrain(connType)
if train == nil {
slog.Error("车载输出数字量未找到连接车载pc仿真的列车")
@ -433,6 +411,7 @@ func trainPcSimDigitalOutInfoHandleCode7_0(d byte, vobc *state_proto.TrainVobcSt
// 4.4.2. 车载输出数字反馈量信息报文内容
func (s *VerifySimulation) TrainPcSimDigitalReportHandle(connType state_proto.TrainConnState_TrainConnType, data []byte) {
slog.Info(fmt.Sprintf("车载输出数字量反馈信息", hex.EncodeToString(data)))
train := s.FindConnTrain(connType)
if train == nil {
slog.Error("车载输出数字反馈量信息,未找到连接车载pc仿真的列车")
@ -459,14 +438,9 @@ func (s *VerifySimulation) TrainPcSimDigitalReportHandle(connType state_proto.Tr
// 创建/删除列车
func TrainPcSimConnOrRemoveHandle(train *state_proto.TrainState, create bool) error {
var data byte = 0x00
if create {
data = 0x01
}
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, train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE, []byte{data})
crErr := train_pc_sim.Default().CreateOrRemoveTrain(train, create)
if crErr != nil {
return crErr
}
@ -513,6 +487,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)))
if len(data) < 12 {
slog.Error("列车btm查询报文长度错误:", len(data))
return
@ -539,7 +514,7 @@ func (s *VerifySimulation) TrainBtmQuery(connType state_proto.TrainConnState_Tra
//重新发送
if len(train.BtmState.BaliseTelegramForPcSimResend) > 0 {
dd, _ := hex.DecodeString(train.BtmState.BaliseTelegramForPcSimResend)
train_pc_sim.Default().SendBaliseData(train, train_pc_sim.RECIVE_TRAIN_BTM_HAS_DATA, dd)
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_HAS_DATA, dd)
}
} else {
timeSyncF := message.NewBtmTimeSyncCheckFrame(trainAtm.CanId.ID4, true)
@ -551,7 +526,7 @@ func (s *VerifySimulation) TrainBtmQuery(connType state_proto.TrainConnState_Tra
queryData := make([]byte, 0)
queryData = append(queryData, btmRepFrame.Encode().Encode()...)
queryData = append(queryData, timeSyncF.Encode().Encode()...)
train_pc_sim.Default().SendBaliseData(train, train_pc_sim.RECIVE_TRAIN_BTM_NOT_DATA, queryData)
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_NOT_DATA, queryData)
} else {
//有数据
aliseData, _ := hex.DecodeString(train.BtmState.Telegram)
@ -562,7 +537,7 @@ func (s *VerifySimulation) TrainBtmQuery(connType state_proto.TrainConnState_Tra
queryData = append(queryData, timeSyncF.Encode().Encode()...)
queryData = append(queryData, statusDataCf...) //数据帧包含结束帧
train.BtmState.BaliseTelegramForPcSimResend = fmt.Sprintf("%X", statusDataCf)
train_pc_sim.Default().SendBaliseData(train, train_pc_sim.RECIVE_TRAIN_BTM_HAS_DATA, queryData)
train_pc_sim.Default().SendBaliseData(train, message.RECIVE_TRAIN_BTM_HAS_DATA, queryData)
} else {
slog.Error("列车pc仿真 BtmCanetClient应答帧、数据帧编码失败")
}
@ -593,3 +568,41 @@ 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
tcc := train.Tcc
if vs.Tc1Active || vs.Tc2Active {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.KEY_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //钥匙激活
}
if tcc.PushHandler.Val == 0 {
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.TRAIN_BRAKE_STATE, 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 tcc.Ebutton.Passed {
if vs.EmergencyBrakingStatus {
msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.OUTER_EMERGENCY_BRAKE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //紧急制动
}
dir := request_proto.TrainControl_Direction(tcc.DirKey.Val)
if dir == request_proto.TrainControl_FORWARD {
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_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.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}) //关左门按钮
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.LEFT_DOOR_STATE, 1}, Type: message.SENDER_TRAIN_OUTR_INFO}) //左门状态
//msgArr = append(msgArr, message.TrainPcSimBaseMessage{Data: []byte{message.RIGHT_DOOR_STATE, 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}) //右门状态
return msgArr
}