日志调整及现场测试
All checks were successful
local-test分支打包构建docker并发布运行 / Docker-Build (push) Successful in 1m45s
All checks were successful
local-test分支打包构建docker并发布运行 / Docker-Build (push) Successful in 1m45s
This commit is contained in:
parent
081581140e
commit
1b3f130e4e
13
third_party/btm_vobc/btm_vobc_test.go
vendored
13
third_party/btm_vobc/btm_vobc_test.go
vendored
@ -5,7 +5,9 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"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"
|
||||
@ -17,6 +19,17 @@ const (
|
||||
code2 = "fffee601804f004d00800600002a004984ec6f4e902ef6912284000000000000000000000000000000067e000000000000411b0000f5bbee397698fffd"
|
||||
)
|
||||
|
||||
func TestMsg22(t *testing.T) {
|
||||
msg := &message.TrainPcSimBaseMessage{}
|
||||
msg.Type = train_pc_sim.SENDER_TRAIN_OUTR_INFO
|
||||
data := []byte{0, 1}
|
||||
msg.Data = data
|
||||
code := msg.Encode()
|
||||
hexCode := hex.EncodeToString(code)
|
||||
fmt.Println(hexCode)
|
||||
fmt.Println(crc.CalculateCRC(crc.CRC16, []byte{0}))
|
||||
}
|
||||
|
||||
var message_id atomic.Uint32
|
||||
|
||||
func TestConn(t *testing.T) {
|
||||
|
25
third_party/message/train_pc_sim_message.go
vendored
25
third_party/message/train_pc_sim_message.go
vendored
@ -12,7 +12,7 @@ import (
|
||||
const PC_SIM_HEADER = 0xEB
|
||||
|
||||
type TrainPcSimBaseMessage struct {
|
||||
Type uint16
|
||||
Type byte
|
||||
DataLen byte
|
||||
Data []byte
|
||||
Crc uint16 // 校验码
|
||||
@ -22,13 +22,17 @@ type TrainPcSimBaseMessage struct {
|
||||
func (tp *TrainPcSimBaseMessage) Encode() []byte {
|
||||
pack := make([]byte, 0)
|
||||
pack = append(pack, PC_SIM_HEADER)
|
||||
pack = binary.BigEndian.AppendUint16(pack, tp.Type)
|
||||
pack = append(pack, byte(len(tp.Data)))
|
||||
pack = append(pack, tp.Type)
|
||||
|
||||
pack = append(pack, byte(len(tp.Data)+1+1+1+2))
|
||||
if len(tp.Data) > 0 {
|
||||
dataBufs := bytes.NewBuffer(nil)
|
||||
binary.Write(dataBufs, binary.BigEndian, tp.Data)
|
||||
data := dataBufs.Bytes()
|
||||
pack = append(pack, data...)
|
||||
pack = binary.BigEndian.AppendUint16(pack, uint16(crc.CalculateCRC(crc.CRC16, data)))
|
||||
}
|
||||
|
||||
pack = binary.BigEndian.AppendUint16(pack, uint16(crc.CalculateCRC(crc.CRC16, pack[1:])))
|
||||
return pack
|
||||
}
|
||||
|
||||
@ -42,20 +46,21 @@ func (tp *TrainPcSimBaseMessage) Decode(data []byte) error {
|
||||
if h != PC_SIM_HEADER {
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
var pcType uint16
|
||||
binary.Read(buf, binary.BigEndian, &pcType)
|
||||
len, _ := buf.ReadByte()
|
||||
if buf.Len() < int(len)+2 {
|
||||
var pcType byte
|
||||
pcType, _ = buf.ReadByte()
|
||||
|
||||
dataLen, _ := buf.ReadByte()
|
||||
if buf.Len() < int(dataLen)-1-1-1+2 {
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
|
||||
var dd = make([]byte, len)
|
||||
var dd = make([]byte, dataLen)
|
||||
|
||||
binary.Read(buf, binary.BigEndian, &dd)
|
||||
var crcCode uint16
|
||||
binary.Read(buf, binary.BigEndian, &crcCode)
|
||||
tp.Type = pcType
|
||||
tp.DataLen = len
|
||||
tp.DataLen = dataLen
|
||||
tp.Data = dd
|
||||
tp.Crc = crcCode
|
||||
return nil
|
||||
|
17
third_party/train_pc_sim/train_pc_sim.go
vendored
17
third_party/train_pc_sim/train_pc_sim.go
vendored
@ -33,7 +33,7 @@ type TrainPcSim interface {
|
||||
//因文档说明不清楚,在调用的时候目前是注释状态,现场调试可能会用到
|
||||
SendTrainDirection(train *state_proto.TrainState, trainForward, trainBackward bool)
|
||||
//发送应答器信息数据
|
||||
SendBaliseData(train *state_proto.TrainState, msgType uint16, data []byte)
|
||||
SendBaliseData(train *state_proto.TrainState, msgType byte, data []byte)
|
||||
//发布列车控制的相关事件
|
||||
PublishTrainControlEvent(train *state_proto.TrainState, events []TrainControlEvent)
|
||||
// CreateOrRemoveSpeedPLace 创建或删除速度位置信息
|
||||
@ -327,7 +327,7 @@ func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, m
|
||||
log = "创建列车"
|
||||
d.initConn(clientKey)
|
||||
}
|
||||
msg := &message.TrainPcSimBaseMessage{Data: data, Type: uint16(msgType)}
|
||||
msg := &message.TrainPcSimBaseMessage{Data: data, Type: msgType}
|
||||
rd := d.newPcSimclientMap[clientKey]
|
||||
if rd != nil {
|
||||
sd := msg.Encode()
|
||||
@ -409,6 +409,9 @@ func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
|
||||
msg.Type = SENDER_TRAIN_TC_NOT_ACTIVE
|
||||
}
|
||||
}
|
||||
//:"创建列车-列车号:1,发送数据:eb0050010156e4"}
|
||||
//{,"msg":"发送驾驶激活列车","1":"数据","!BADKEY":"eb0004002437"}
|
||||
|
||||
da := msg.Encode()
|
||||
slog.Info("发送驾驶激活列车", train.Id, "数据", hex.EncodeToString(da))
|
||||
err := rd.tcpClient.Send(da)
|
||||
@ -487,7 +490,7 @@ func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, tr
|
||||
}
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) SendBaliseData(train *state_proto.TrainState, msgType uint16, data []byte) {
|
||||
func (d *trainPcSimService) SendBaliseData(train *state_proto.TrainState, msgType byte, data []byte) {
|
||||
msg := &message.TrainPcSimBaseMessage{}
|
||||
msg.Type = msgType
|
||||
msg.Data = data
|
||||
@ -527,7 +530,13 @@ func (d *trainPcSimService) PublishTrainControlEvent(train *state_proto.TrainSta
|
||||
msg.Type = SENDER_TRAIN_OUTR_INFO
|
||||
data := []byte{event.Command, event.Status}
|
||||
msg.Data = data
|
||||
rd.tcpClient.Send(msg.Encode())
|
||||
code := msg.Encode()
|
||||
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)
|
||||
|
||||
|
@ -167,14 +167,14 @@ func trainControlDriverKey(train *state_proto.TrainState, request *request_proto
|
||||
}
|
||||
panic(sys_error.New("驾驶端不能同时激活"))
|
||||
}
|
||||
train.TrainActiveDirection = 0
|
||||
/*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 {
|
||||
|
Loading…
Reference in New Issue
Block a user