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/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/snksoft/crc"
|
||||||
"joylink.club/bj-rtsts-server/third_party/message"
|
"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"
|
"joylink.club/bj-rtsts-server/third_party/udp"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
@ -17,6 +19,17 @@ const (
|
|||||||
code2 = "fffee601804f004d00800600002a004984ec6f4e902ef6912284000000000000000000000000000000067e000000000000411b0000f5bbee397698fffd"
|
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
|
var message_id atomic.Uint32
|
||||||
|
|
||||||
func TestConn(t *testing.T) {
|
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
|
preIndex = lastIndex
|
||||||
lastIndex = lastIndex + t.et_out_num
|
lastIndex = lastIndex + t.et_out_num
|
||||||
t.parseByte(t.DriveInfo, buf, preIndex, lastIndex)
|
t.parseByte(buf, preIndex, lastIndex)
|
||||||
// 应答器报文
|
// 应答器报文
|
||||||
preIndex = lastIndex
|
preIndex = lastIndex
|
||||||
lastIndex = lastIndex + t.tcc_output_len
|
lastIndex = lastIndex + t.tcc_output_len
|
||||||
@ -173,11 +173,11 @@ func (t *InterlockReceiveMsgPkg) Decode(buf []byte) error {
|
|||||||
return nil
|
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++ {
|
for i := start; i < end; i++ {
|
||||||
b := buf[i]
|
b := buf[i]
|
||||||
for bit := 7; bit >= 0; bit-- {
|
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
|
const PC_SIM_HEADER = 0xEB
|
||||||
|
|
||||||
type TrainPcSimBaseMessage struct {
|
type TrainPcSimBaseMessage struct {
|
||||||
Type uint16
|
Type byte
|
||||||
DataLen byte
|
DataLen byte
|
||||||
Data []byte
|
Data []byte
|
||||||
Crc uint16 // 校验码
|
Crc uint16 // 校验码
|
||||||
@ -22,13 +22,17 @@ type TrainPcSimBaseMessage struct {
|
|||||||
func (tp *TrainPcSimBaseMessage) Encode() []byte {
|
func (tp *TrainPcSimBaseMessage) Encode() []byte {
|
||||||
pack := make([]byte, 0)
|
pack := make([]byte, 0)
|
||||||
pack = append(pack, PC_SIM_HEADER)
|
pack = append(pack, PC_SIM_HEADER)
|
||||||
pack = binary.BigEndian.AppendUint16(pack, tp.Type)
|
pack = append(pack, tp.Type)
|
||||||
pack = append(pack, byte(len(tp.Data)))
|
|
||||||
|
pack = append(pack, byte(len(tp.Data)+1+1+1+2))
|
||||||
|
if len(tp.Data) > 0 {
|
||||||
dataBufs := bytes.NewBuffer(nil)
|
dataBufs := bytes.NewBuffer(nil)
|
||||||
binary.Write(dataBufs, binary.BigEndian, tp.Data)
|
binary.Write(dataBufs, binary.BigEndian, tp.Data)
|
||||||
data := dataBufs.Bytes()
|
data := dataBufs.Bytes()
|
||||||
pack = append(pack, data...)
|
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
|
return pack
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,20 +46,21 @@ func (tp *TrainPcSimBaseMessage) Decode(data []byte) error {
|
|||||||
if h != PC_SIM_HEADER {
|
if h != PC_SIM_HEADER {
|
||||||
return fmt.Errorf("")
|
return fmt.Errorf("")
|
||||||
}
|
}
|
||||||
var pcType uint16
|
var pcType byte
|
||||||
binary.Read(buf, binary.BigEndian, &pcType)
|
pcType, _ = buf.ReadByte()
|
||||||
len, _ := buf.ReadByte()
|
|
||||||
if buf.Len() < int(len)+2 {
|
dataLen, _ := buf.ReadByte()
|
||||||
|
if buf.Len() < int(dataLen)-1-1-1+2 {
|
||||||
return fmt.Errorf("")
|
return fmt.Errorf("")
|
||||||
}
|
}
|
||||||
|
|
||||||
var dd = make([]byte, len)
|
var dd = make([]byte, dataLen)
|
||||||
|
|
||||||
binary.Read(buf, binary.BigEndian, &dd)
|
binary.Read(buf, binary.BigEndian, &dd)
|
||||||
var crcCode uint16
|
var crcCode uint16
|
||||||
binary.Read(buf, binary.BigEndian, &crcCode)
|
binary.Read(buf, binary.BigEndian, &crcCode)
|
||||||
tp.Type = pcType
|
tp.Type = pcType
|
||||||
tp.DataLen = len
|
tp.DataLen = dataLen
|
||||||
tp.Data = dd
|
tp.Data = dd
|
||||||
tp.Crc = crcCode
|
tp.Crc = crcCode
|
||||||
return nil
|
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)
|
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)
|
PublishTrainControlEvent(train *state_proto.TrainState, events []TrainControlEvent)
|
||||||
// CreateOrRemoveSpeedPLace 创建或删除速度位置信息
|
// CreateOrRemoveSpeedPLace 创建或删除速度位置信息
|
||||||
@ -327,7 +327,7 @@ func (d *trainPcSimService) CreateOrRemoveTrain(train *state_proto.TrainState, m
|
|||||||
log = "创建列车"
|
log = "创建列车"
|
||||||
d.initConn(clientKey)
|
d.initConn(clientKey)
|
||||||
}
|
}
|
||||||
msg := &message.TrainPcSimBaseMessage{Data: data, Type: uint16(msgType)}
|
msg := &message.TrainPcSimBaseMessage{Data: data, Type: msgType}
|
||||||
rd := d.newPcSimclientMap[clientKey]
|
rd := d.newPcSimclientMap[clientKey]
|
||||||
if rd != nil {
|
if rd != nil {
|
||||||
sd := msg.Encode()
|
sd := msg.Encode()
|
||||||
@ -409,6 +409,9 @@ func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
|
|||||||
msg.Type = SENDER_TRAIN_TC_NOT_ACTIVE
|
msg.Type = SENDER_TRAIN_TC_NOT_ACTIVE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//:"创建列车-列车号:1,发送数据:eb0050010156e4"}
|
||||||
|
//{,"msg":"发送驾驶激活列车","1":"数据","!BADKEY":"eb0004002437"}
|
||||||
|
|
||||||
da := msg.Encode()
|
da := msg.Encode()
|
||||||
slog.Info("发送驾驶激活列车", train.Id, "数据", hex.EncodeToString(da))
|
slog.Info("发送驾驶激活列车", train.Id, "数据", hex.EncodeToString(da))
|
||||||
err := rd.tcpClient.Send(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 := &message.TrainPcSimBaseMessage{}
|
||||||
msg.Type = msgType
|
msg.Type = msgType
|
||||||
msg.Data = data
|
msg.Data = data
|
||||||
@ -527,7 +530,13 @@ func (d *trainPcSimService) PublishTrainControlEvent(train *state_proto.TrainSta
|
|||||||
msg.Type = SENDER_TRAIN_OUTR_INFO
|
msg.Type = SENDER_TRAIN_OUTR_INFO
|
||||||
data := []byte{event.Command, event.Status}
|
data := []byte{event.Command, event.Status}
|
||||||
msg.Data = data
|
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())
|
//client.Send(msg.Encode())
|
||||||
//FireTrainControlEventType.Publish(world, &event)
|
//FireTrainControlEventType.Publish(world, &event)
|
||||||
|
|
||||||
|
@ -477,7 +477,10 @@ func (s *VerifySimulation) HandleInterlockDriverInfo(code string, b []byte) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
driverMsg := message.NewInterlockReceiveMsgPkg(0, len(m.QdList), len(m.TransponderId))
|
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
|
driveState := driverMsg.DriveInfo
|
||||||
for i, r := range m.QdList {
|
for i, r := range m.QdList {
|
||||||
ds := driveState[i]
|
ds := driveState[i]
|
||||||
|
@ -167,14 +167,14 @@ func trainControlDriverKey(train *state_proto.TrainState, request *request_proto
|
|||||||
}
|
}
|
||||||
panic(sys_error.New("驾驶端不能同时激活"))
|
panic(sys_error.New("驾驶端不能同时激活"))
|
||||||
}
|
}
|
||||||
train.TrainActiveDirection = 0
|
/*train.TrainActiveDirection = 0
|
||||||
if vobc.Tc1Active {
|
if vobc.Tc1Active {
|
||||||
//train.TrainActiveDirection = 1
|
//train.TrainActiveDirection = 1
|
||||||
train.TrainRunUp = true
|
train.TrainRunUp = true
|
||||||
} else if vobc.Tc2Active {
|
} else if vobc.Tc2Active {
|
||||||
//train.TrainActiveDirection = 2
|
//train.TrainActiveDirection = 2
|
||||||
train.TrainRunUp = false
|
train.TrainRunUp = false
|
||||||
}
|
}*/
|
||||||
var addNew = true
|
var addNew = true
|
||||||
for _, k := range tcc.DriverKey {
|
for _, k := range tcc.DriverKey {
|
||||||
if k.Id == deviceId {
|
if k.Id == deviceId {
|
||||||
|
Loading…
Reference in New Issue
Block a user