Compare commits
8 Commits
bec948357a
...
1b3f130e4e
Author | SHA1 | Date | |
---|---|---|---|
|
1b3f130e4e | ||
|
081581140e | ||
|
8a6b5a0145 | ||
|
63032efdba | ||
|
cdfffc65e8 | ||
|
c22ddfcae9 | ||
c23c70ce05 | |||
|
e7b7ff6781 |
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) {
|
||||
|
6
third_party/message/interlock.go
vendored
6
third_party/message/interlock.go
vendored
@ -163,7 +163,7 @@ func (t *InterlockReceiveMsgPkg) Decode(buf []byte) error {
|
||||
// 驱动数据
|
||||
preIndex = lastIndex
|
||||
lastIndex = lastIndex + t.et_out_num
|
||||
t.parseByte(t.DriveInfo, buf, preIndex, lastIndex)
|
||||
t.parseByte(buf, preIndex, lastIndex)
|
||||
// 应答器报文
|
||||
preIndex = lastIndex
|
||||
lastIndex = lastIndex + t.tcc_output_len
|
||||
@ -173,11 +173,11 @@ func (t *InterlockReceiveMsgPkg) Decode(buf []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *InterlockReceiveMsgPkg) parseByte(r []bool, buf []byte, start, end int) {
|
||||
func (t *InterlockReceiveMsgPkg) parseByte(buf []byte, start, end int) {
|
||||
for i := start; i < end; i++ {
|
||||
b := buf[i]
|
||||
for bit := 7; bit >= 0; bit-- {
|
||||
r = append(r, (b&(1<<bit)) != 0)
|
||||
t.DriveInfo = append(t.DriveInfo, (b&(1<<bit)) != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
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)
|
||||
|
||||
|
@ -477,7 +477,10 @@ func (s *VerifySimulation) HandleInterlockDriverInfo(code string, b []byte) {
|
||||
continue
|
||||
}
|
||||
driverMsg := message.NewInterlockReceiveMsgPkg(0, len(m.QdList), len(m.TransponderId))
|
||||
driverMsg.Decode(b)
|
||||
err := driverMsg.Decode(b)
|
||||
if err != nil {
|
||||
slog.Error(fmt.Sprintf("联锁驱动数据解析失败:%s", err))
|
||||
}
|
||||
driveState := driverMsg.DriveInfo
|
||||
for i, r := range m.QdList {
|
||||
ds := driveState[i]
|
||||
|
@ -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