Compare commits
5 Commits
8aebff96a5
...
d3e9041760
Author | SHA1 | Date | |
---|---|---|---|
d3e9041760 | |||
d610a15fdb | |||
|
6211f61ecd | ||
2a380347c6 | |||
|
815b181a0c |
3
.gitignore
vendored
3
.gitignore
vendored
@ -26,4 +26,5 @@ output/
|
||||
|
||||
# Go workspace file
|
||||
/go.work.sum
|
||||
/pom.xml
|
||||
/pom.xml
|
||||
/bj-rtsts-server
|
||||
|
@ -1,12 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"joylink.club/bj-rtsts-server/bin/config"
|
||||
"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"
|
||||
@ -22,8 +25,8 @@ func initConfig() {
|
||||
cnf := viper.New()
|
||||
cnf.SetConfigName(config_name)
|
||||
cnf.SetConfigType("yml")
|
||||
cnf.AddConfigPath("./bin/config/")
|
||||
//cnf.AddConfigPath("./config/")
|
||||
//cnf.AddConfigPath("./bin/config/")
|
||||
//cnf.AddConfigPath("./")
|
||||
cnf.AddConfigPath(".")
|
||||
err := cnf.ReadInConfig()
|
||||
if err != nil {
|
||||
@ -57,12 +60,94 @@ func initSpeedTest() {
|
||||
speedClient = udp.NewClient(fmt.Sprintf("%v:%v", exampleConfig.Speed.RemoteIp, exampleConfig.Speed.RemotePort))
|
||||
go testSpeed(speedClient, 30)
|
||||
}
|
||||
|
||||
var trainpcClient *tcp.TcpClient
|
||||
|
||||
func initTrainPc() {
|
||||
addr := fmt.Sprintf("%v:%v", exampleConfig.Trainpc.RemoteIp, exampleConfig.Trainpc.RemotePort)
|
||||
|
||||
client2, err := tcp.StartTcpClient(addr, trainPcDataHandle, trainPcConnErr)
|
||||
if err != nil {
|
||||
fmt.Println("仿真列车pc连接失败", err)
|
||||
return
|
||||
}
|
||||
trainpcClient = client2
|
||||
circleSendTrainActive()
|
||||
circleSendTrainMockData()
|
||||
go circleSendTrainSpeedPlace()
|
||||
}
|
||||
|
||||
func circleSendTrainActive() {
|
||||
msg := &message.TrainPcSimBaseMessage{Data: []byte{0x01}, Type: train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE}
|
||||
data := msg.Encode()
|
||||
fmt.Println(fmt.Sprintf("发送列车创建数据:%v", hex.EncodeToString(data)))
|
||||
trainpcClient.Send(data)
|
||||
act := &message.TrainPcSimBaseMessage{Data: make([]byte, 0), Type: train_pc_sim.SENDER_TRAIN_TC_ACTIVE}
|
||||
actData := act.Encode()
|
||||
fmt.Println(fmt.Sprintf("发送列车驾驶室激活:%v", hex.EncodeToString(actData)))
|
||||
trainpcClient.Send(actData)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
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))
|
||||
now := time.Now().UTC()
|
||||
sec := now.Unix()
|
||||
data = binary.BigEndian.AppendUint32(data, uint32(sec))
|
||||
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)
|
||||
time.Sleep(time.Millisecond * 80)
|
||||
}
|
||||
}
|
||||
func trainPcDataHandle(n int, data []byte) {
|
||||
hexData := hex.EncodeToString(data)
|
||||
slog.Info(fmt.Sprintf("列车pc仿真接口接受数据:%v", hexData))
|
||||
}
|
||||
func trainPcConnErr(err error) {
|
||||
|
||||
}
|
||||
func main() {
|
||||
|
||||
initConfig()
|
||||
initBtmTest()
|
||||
//initBtmTest()
|
||||
//initTrainPc()
|
||||
//initAccTest()
|
||||
//initSpeedTest()
|
||||
initSpeedTest()
|
||||
|
||||
for {
|
||||
}
|
||||
@ -74,11 +159,15 @@ var freeBtmMsg = strings.Repeat("00", balise_const.UserTelegramByteLen)
|
||||
func sendPacket(lifeNum uint32, autoId byte) {
|
||||
userMsg, _ := hex.DecodeString(testUserBtmMsg)
|
||||
|
||||
msg := &message.BtmVobcMessage{FontTtl: 5, BtmStatus: 0x00, DecodeTime: 10, BackTtl: 4, BtmMsg: userMsg, ResponseTime: 10,
|
||||
msg := &message.BtmVobcMessage{FontTtl: 2, BtmStatus: 0x00, DecodeTime: 10, BackTtl: 2, BtmMsg: userMsg, ResponseTime: 10,
|
||||
VobcLifeNum: lifeNum, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: autoId}, MsgSerial: message.GetAutoMessageId()}
|
||||
sendData := msg.Encode()
|
||||
fmt.Println("发送btm vobc len:", len(sendData), "报文:", hex.EncodeToString(sendData), "报文序列号:", msg.MsgSerial)
|
||||
btmCli.Send(sendData)
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
err := btmCli.Send(sendData)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprintf("发送失败%v", err.Error()))
|
||||
}
|
||||
|
||||
/*freeMsg, _ := hex.DecodeString(freeBtmMsg)
|
||||
|
||||
@ -96,16 +185,22 @@ func sendPacketFree(lifeNum uint32, autoId byte, msgs byte) {
|
||||
newMsg = 1
|
||||
}
|
||||
msg2 := &message.BtmVobcMsgFree{BtmStatus: 0x00, WorkTemperature: 10, Fun1: uint16(0), Fun2: uint16(0), Fun3: uint16(0), Fun4: uint16(0),
|
||||
FreeMsg: freeMsg, RespTime: 20, VobcLifeNum: lifeNum, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: autoId}, MsgSerial: newMsg}
|
||||
//FreeMsg: freeMsg, RespTime: 20, VobcLifeNum: lifeNum, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: autoId}, MsgSerial: newMsg}
|
||||
FreeMsg: freeMsg, RespTime: 20, VobcLifeNum: lifeNum, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: autoId}, MsgSerial: message.GetAutoMessageId()}
|
||||
sendData2 := msg2.Encode()
|
||||
fmt.Println("发送btm vobc 空报文:", hex.EncodeToString(sendData2), "len:", len(sendData2), "报文序列号:", msg2.MsgSerial, "atoId=", autoId, "报文序列号:", msg2.MsgSerial)
|
||||
btmCli.Send(sendData2)
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
err := btmCli.Send(sendData2)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprintf("发送失败%v", err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
func RequestFramePackets(req *message.BtmVobcReq) {
|
||||
fmt.Println(fmt.Sprintf("接受 请求帧 frameStatus:%v,messageType:%v,lifeNum:%v,序列号:%v", req.FrameStatus, req.MessageType, req.VobcLifeNum, req.MessageSerial))
|
||||
func RequestFramePackets(req *message.BtmVobcReq, vobcLife uint32) {
|
||||
//fmt.Println(fmt.Sprintf("接受 请求帧 frameStatus:%v,messageType:%v,lifeNum:%v,序列号:%v", req.FrameStatus, req.MessageType, req.VobcLifeNum, req.MessageSerial))
|
||||
if req.FrameStatus == message.REQ_FRAME_STATUS_BOOT && req.MessageType == message.REQ_PACKETS_TYPE_BOOT {
|
||||
sendPacketFree(req.VobcLifeNum, req.AutoIdFrame, req.MessageSerial)
|
||||
fmt.Println("000000000000000000000000000")
|
||||
sendPacketFree(vobcLife, req.AutoIdFrame, req.MessageSerial)
|
||||
} else if req.FrameStatus == message.REQ_FRAME_STATUS_OK {
|
||||
//帧正确,删除之前发送的数据
|
||||
fmt.Println("11111111111111111111")
|
||||
@ -115,8 +210,13 @@ func RequestFramePackets(req *message.BtmVobcReq) {
|
||||
fmt.Println("22222222222222222")
|
||||
}
|
||||
}
|
||||
|
||||
var btmReceiveTime = time.Now().UnixMilli()
|
||||
var vobcNumLife uint32 = 0
|
||||
|
||||
func handleBtmVobcFrames(cfs []byte) {
|
||||
fmt.Println("收到源数据:%v", hex.EncodeToString(cfs))
|
||||
|
||||
fmt.Println(fmt.Sprintf("收到源数据:%v ,请求帧时间:%v ,vobcLife:%v", hex.EncodeToString(cfs), time.Now().UnixMilli()-btmReceiveTime, vobcNumLife))
|
||||
frameType, dataText, err := message.BtmVobcDecode(cfs)
|
||||
if err != nil {
|
||||
return
|
||||
@ -124,11 +224,28 @@ func handleBtmVobcFrames(cfs []byte) {
|
||||
if frameType == message.COMMAND_TYPE {
|
||||
idCommand := &message.BtmVobcIdCommand{}
|
||||
idCommand.Decode(dataText)
|
||||
sendPacket(idCommand.VobcLifeNum, idCommand.AutoIdFrame)
|
||||
if vobcNumLife <= 0 {
|
||||
vobcNumLife = idCommand.VobcLifeNum
|
||||
}
|
||||
sendPacketFree(vobcNumLife, idCommand.AutoIdFrame, idCommand.AutoIdFrame)
|
||||
//sendPacket(vobcNumLife, idCommand.AutoIdFrame)
|
||||
} else if frameType == message.REQUEST_TYPE {
|
||||
if vobcNumLife <= 0 {
|
||||
return
|
||||
} else {
|
||||
fmt.Println(fmt.Sprintf("准备发送vobcLife:%v", vobcNumLife))
|
||||
}
|
||||
req := &message.BtmVobcReq{}
|
||||
req.Decode(dataText)
|
||||
RequestFramePackets(req)
|
||||
fmt.Println(fmt.Sprintf("接受 请求帧 frameStatus:%v,messageType:%v,lifeNum:%v,序列号:%v", req.FrameStatus, req.MessageType, req.VobcLifeNum, req.MessageSerial))
|
||||
if time.Now().UnixMilli()-btmReceiveTime > 20*1000 {
|
||||
idCommand := &message.BtmVobcIdCommand{}
|
||||
idCommand.Decode(dataText)
|
||||
sendPacket(vobcNumLife, idCommand.AutoIdFrame)
|
||||
} else {
|
||||
|
||||
RequestFramePackets(req, vobcNumLife)
|
||||
}
|
||||
} else {
|
||||
slog.Error(fmt.Sprintf("btm vobc 解析未知命令帧类型:0x%v,原始数据:%v,长度:%v", strconv.FormatInt(int64(frameType), 16), hex.EncodeToString(cfs), len(cfs)))
|
||||
return
|
||||
|
@ -8,4 +8,8 @@ btm:
|
||||
remoteIp: "192.168.1.199"
|
||||
remotePort: 4196
|
||||
localIp: "192.168.1.150"
|
||||
localPort: 4646
|
||||
localPort: 4646
|
||||
trainpc:
|
||||
remoteIp: "192.168.3.211"
|
||||
remotePort: 10007
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
package config
|
||||
|
||||
type ExampleConfig struct {
|
||||
Acc acc
|
||||
Speed speed
|
||||
Btm btm
|
||||
Acc acc
|
||||
Speed speed
|
||||
Btm btm
|
||||
Trainpc trainpc
|
||||
}
|
||||
type acc struct {
|
||||
RemoteIp string
|
||||
@ -19,3 +20,8 @@ type btm struct {
|
||||
LocalIp string
|
||||
LocalPort int
|
||||
}
|
||||
|
||||
type trainpc struct {
|
||||
RemoteIp string
|
||||
RemotePort int
|
||||
}
|
||||
|
@ -36,7 +36,11 @@ func InitSlog() {
|
||||
|
||||
if logging.Stdout {
|
||||
// 日志输出到控制台
|
||||
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
||||
//slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
||||
// Level: level,
|
||||
// AddSource: false,
|
||||
//})))
|
||||
slog.SetDefault(slog.New(newMyJsonHandler(os.Stdout, &slog.HandlerOptions{
|
||||
Level: level,
|
||||
AddSource: false,
|
||||
})))
|
||||
@ -50,7 +54,11 @@ func InitSlog() {
|
||||
LocalTime: true, // 日志备份使用本地时间
|
||||
Compress: logging.Compress, // 是否压缩日志
|
||||
}
|
||||
slog.SetDefault(slog.New(slog.NewJSONHandler(lumberJackLogger, &slog.HandlerOptions{
|
||||
//slog.SetDefault(slog.New(slog.NewJSONHandler(lumberJackLogger, &slog.HandlerOptions{
|
||||
// Level: level,
|
||||
// AddSource: false,
|
||||
//})))
|
||||
slog.SetDefault(slog.New(newMyJsonHandler(lumberJackLogger, &slog.HandlerOptions{
|
||||
Level: level,
|
||||
AddSource: false,
|
||||
})))
|
||||
|
63
logger/my_json_handler.go
Normal file
63
logger/my_json_handler.go
Normal file
@ -0,0 +1,63 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"log/slog"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type MyJsonHandler struct {
|
||||
output io.Writer
|
||||
mu sync.Mutex
|
||||
jsonHandler slog.Handler
|
||||
}
|
||||
|
||||
var stackChan = make(chan string, 100)
|
||||
|
||||
func newMyJsonHandler(output io.Writer, opts *slog.HandlerOptions) *MyJsonHandler {
|
||||
if opts == nil {
|
||||
opts = &slog.HandlerOptions{}
|
||||
}
|
||||
ra := opts.ReplaceAttr
|
||||
opts.ReplaceAttr = func(groups []string, a slog.Attr) slog.Attr {
|
||||
if a.Key == "stack" {
|
||||
stackChan <- a.Value.String()
|
||||
return slog.Attr{}
|
||||
} else {
|
||||
if ra != nil {
|
||||
return ra(groups, a)
|
||||
} else {
|
||||
return a
|
||||
}
|
||||
}
|
||||
}
|
||||
return &MyJsonHandler{output: output, mu: sync.Mutex{}, jsonHandler: slog.NewJSONHandler(output, opts)}
|
||||
}
|
||||
|
||||
func (s *MyJsonHandler) Enabled(ctx context.Context, level slog.Level) bool {
|
||||
return s.jsonHandler.Enabled(ctx, level)
|
||||
}
|
||||
|
||||
func (s *MyJsonHandler) Handle(ctx context.Context, record slog.Record) error {
|
||||
err := s.jsonHandler.Handle(ctx, record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
select {
|
||||
case stack := <-stackChan:
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
_, err = s.output.Write([]byte(stack))
|
||||
default:
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *MyJsonHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
||||
return s.jsonHandler.WithAttrs(attrs)
|
||||
}
|
||||
|
||||
func (s *MyJsonHandler) WithGroup(name string) slog.Handler {
|
||||
return s.jsonHandler.WithGroup(name)
|
||||
}
|
21
logger/my_json_handler_test.go
Normal file
21
logger/my_json_handler_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkMyJsonHandler_Handle(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
//slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
||||
// AddSource: false,
|
||||
// Level: nil,
|
||||
//})))
|
||||
slog.SetDefault(slog.New(newMyJsonHandler(os.Stdout, &slog.HandlerOptions{
|
||||
AddSource: false,
|
||||
Level: nil,
|
||||
})))
|
||||
slog.Info("这是一条日志", "error", "错误", "stack", "goroutine 10 [running]:\nruntime/debug.Stack()\n\tD:/develop/Go/go1.21.4/src/runtime/debug/stack.go:24 +0x6b\njoylink.club/bj-rtsts-server/starter.customRecoveryWithSlog.func1.1()\n\tD:/GoProject/rts-sim-testing-service/starter/init.go:126 +0x36f\npanic({0x1f0cb40?, 0x226fd50?})\n\tD:/develop/Go/go1.21.4/src/runtime/panic.go:920 +0x290\njoylink.club/bj-rtsts-server/api.createByProjectId(0xc001a06100)\n\tD:/GoProject/rts-sim-testing-service/api/simulation.go:91 +0x26\ngithub.com/gin-gonic/gin.(*Context).Next(0xc001a06100)\n\tC:/Users/thesai/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x7a\njoylink.club/bj-rtsts-server/middleware.permissionMiddleware.func1(0xc001a06100)\n\tD:/GoProject/rts-sim-testing-service/middleware/auth.go:35 +0x178\ngithub.com/gin-gonic/gin.(*Context).Next(0xc001a06100)\n\tC:/Users/thesai/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x7a\ngithub.com/appleboy/gin-jwt/v2.(*GinJWTMiddleware).middlewareImpl(0xc000504340, 0xc001a06100)\n\tC:/Users/thesai/go/pkg/mod/github.com/appleboy/gin-jwt/v2@v2.9.1/auth_jwt.go:462 +0x579\ngithub.com/appleboy/gin-jwt/v2.(*GinJWTMiddleware).MiddlewareFunc.func1(0xc001a06100)\n\tC:/Users/thesai/go/pkg/mod/github.com/appleboy/gin-jwt/v2@v2.9.1/auth_jwt.go:415 +0x26\ngithub.com/gin-gonic/gin.(*Context).Next(0xc001a06100)\n\tC:/Users/thesai/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x7a\njoylink.club/bj-rtsts-server/starter.customRecoveryWithSlog.func1(0xc001a06100)\n\tD:/GoProject/rts-sim-testing-service/starter/init.go:135 +0xef\ngithub.com/gin-gonic/gin.(*Context).Next(0xc001a06100)\n\tC:/Users/thesai/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x7a\ngithub.com/samber/slog-gin.NewWithConfig.func1(0xc001a06100)\n\tC:/Users/thesai/go/pkg/mod/github.com/samber/slog-gin@v1.1.0/middleware.go:70 +0x13f\ngithub.com/gin-gonic/gin.(*Context).Next(0xc001a06100)\n\tC:/Users/thesai/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174 +0x7a\ngithub.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc0004d51e0, 0xc001a06100)\n\tC:/Users/thesai/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/gin.go:620 +0x427\ngithub.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc0004d51e0, {0x227e480, 0xc00012aee0}, 0xc001a07100)\n\tC:/Users/thesai/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/gin.go:576 +0xbc\nnet/http.serverHandler.ServeHTTP({0xc0017f0960}, {0x227e480, 0xc00012aee0}, 0xc001a07100)\n\tD:/develop/Go/go1.21.4/src/net/http/server.go:2938 +0x257\nnet/http.(*conn).serve(0xc0019422d0, {0x2285b38, 0xc001982000})\n\tD:/develop/Go/go1.21.4/src/net/http/server.go:2009 +0x1a39\ncreated by net/http.(*Server).Serve in goroutine 1\n\tD:/develop/Go/go1.21.4/src/net/http/server.go:3086 +0xa25")
|
||||
}
|
||||
}
|
@ -122,11 +122,7 @@ func customRecoveryWithSlog(logger *slog.Logger, stack bool, recovery gin.Recove
|
||||
}
|
||||
|
||||
if stack {
|
||||
logger.Error("请求处理Panic异常",
|
||||
"error", err,
|
||||
"stack", string(debug.Stack()),
|
||||
)
|
||||
debug.PrintStack()
|
||||
logger.Error("请求处理Panic异常", "error", err, "stack", string(debug.Stack()))
|
||||
} else {
|
||||
logger.Error("请求处理Panic异常",
|
||||
"error", err,
|
||||
|
29
third_party/btm_vobc/btm_vobc2_test.go
vendored
29
third_party/btm_vobc/btm_vobc2_test.go
vendored
@ -3,8 +3,11 @@ package btm_vobc
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"joylink.club/bj-rtsts-server/const/balise_const"
|
||||
"joylink.club/bj-rtsts-server/third_party/message"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -106,6 +109,7 @@ func TranslateFromFFFE(pSrc []byte) ([]byte, uint16) {
|
||||
|
||||
return pTgt[:tgtPos], tgtPos
|
||||
}
|
||||
|
||||
func TestTss(t *testing.T) {
|
||||
ss := "fffee601804f004d00921d21002a00ea014fef63995bff009122ce0000000000000000000000000000211d90000000000000000000007b07310379cefffd"
|
||||
ss = "fffee601804f004d00444a1c002a00473bbfa11d4b3b029122a800000000000000000000000000001c4a42000000000000000000008970492fff00d0fffd"
|
||||
@ -130,13 +134,26 @@ func TestFffe(t *testing.T) {
|
||||
msg := &message.BtmVobcMessage{FontTtl: 5, BtmStatus: 0x00, DecodeTime: 10, BackTtl: 4, BtmMsg: userMsg, ResponseTime: 10,
|
||||
VobcLifeNum: 123, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: 123}}
|
||||
sendData := msg.Encode()
|
||||
fmt.Println(hex.EncodeToString(sendData))
|
||||
fmt.Println(len(sendData), hex.EncodeToString(sendData))
|
||||
}
|
||||
|
||||
func TestFffe2(t *testing.T) {
|
||||
var testUserBtmMsg = strings.Repeat("00", balise_const.UserTelegramByteLen)
|
||||
userMsg, _ := hex.DecodeString(testUserBtmMsg)
|
||||
|
||||
msg2 := &message.BtmVobcMsgFree{BtmStatus: 0x00, WorkTemperature: 10, Fun1: uint16(0), Fun2: uint16(0), Fun3: uint16(0), Fun4: uint16(0),
|
||||
//FreeMsg: freeMsg, RespTime: 20, VobcLifeNum: lifeNum, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: autoId}, MsgSerial: newMsg}
|
||||
FreeMsg: userMsg, RespTime: 20, VobcLifeNum: 2266113, BaseBtmVobc: message.BaseBtmVobc{AutoIdFrame: 123}, MsgSerial: message.GetAutoMessageId()}
|
||||
sendData := msg2.Encode()
|
||||
|
||||
fmt.Println(len(sendData), hex.EncodeToString(sendData))
|
||||
}
|
||||
func TestDecode232(t *testing.T) {
|
||||
var dd uint32 = 888888888
|
||||
fmt.Println(dd)
|
||||
fmt.Println(uint16(dd))
|
||||
ss := "9287a8000511006464000a000000000000000000000490007f8181b60b10183280003fff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff000a0023438bf4c27929"
|
||||
ss = "fffe9287d300056f006464000a000000000000000000000490007f8181b60b10183280003fff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff000a00221eedf0be28e9fffd"
|
||||
userMsg, _ := hex.DecodeString(ss)
|
||||
arr, _ := TranslateFromFFFE(userMsg)
|
||||
fmt.Println(arr)
|
||||
@ -144,6 +161,16 @@ func TestDecode232(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestDocode(t *testing.T) {
|
||||
fmt.Println(time.Microsecond * 200)
|
||||
ss := "fffe9287d300056f006464000a000000000000000000000490007f8181b60b10183280003fff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff000a00221eedf0be28e9fffd"
|
||||
cfs, _ := hex.DecodeString(ss)
|
||||
frameType, dataText, err := message.BtmVobcDecode(cfs)
|
||||
fmt.Println(frameType)
|
||||
fmt.Println(hex.EncodeToString(dataText))
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
func TestDecode2311(t *testing.T) {
|
||||
var data uint16 // 初始化为0
|
||||
|
||||
|
17
third_party/btm_vobc/btm_vobc_test.go
vendored
17
third_party/btm_vobc/btm_vobc_test.go
vendored
@ -21,8 +21,8 @@ const (
|
||||
|
||||
func TestMsg22(t *testing.T) {
|
||||
msg := &message.TrainPcSimBaseMessage{}
|
||||
msg.Type = train_pc_sim.SENDER_TRAIN_OUTR_INFO
|
||||
data := []byte{0, 1}
|
||||
msg.Type = train_pc_sim.RECIVE_TRAIN_CREATE_REMOVE
|
||||
data := []byte{1}
|
||||
msg.Data = data
|
||||
code := msg.Encode()
|
||||
hexCode := hex.EncodeToString(code)
|
||||
@ -55,12 +55,11 @@ func TestDecode(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMsg(t *testing.T) {
|
||||
|
||||
index := 1
|
||||
for i := 22; i <= 125; i++ {
|
||||
fmt.Println(index)
|
||||
index++
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
sec := now.Unix()
|
||||
fmt.Println(sec)
|
||||
fmt.Println(now.UnixMilli())
|
||||
fmt.Println(now.UnixMilli() - sec*1000)
|
||||
}
|
||||
|
||||
func TestBytes(t *testing.T) {
|
||||
@ -91,7 +90,7 @@ func TestRes(t *testing.T) {
|
||||
ss = "fffee601804f004d006c1d21002a00e2c732ff00f86276339122a80000000000000000000000000000211d6a0000000000000000000049c46daebcf6fffd"
|
||||
ss = "fffee601804f004d00871d21002a00ee97d0fb1c4b2a849122c30000000000000000000000000000211d8500000000000000000000c4e2343e4117fffd"
|
||||
ss = "fffee601804f004d00444a1c002a00473bbfa11d4b3b029122a800000000000000000000000000001c4a42000000000000000000008970492fff00d0fffd"
|
||||
//ss = "fffee601804f004d00921d21002a00ea014fef63995bff009122ce0000000000000000000000000000211d90000000000000000000007b07310379cefffd"
|
||||
ss = "fffe9287d4000570006464000a000000000000000000000490007f8181b60b10183280003fff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff01ff000a00221eede6c80a6efffd"
|
||||
cfs, _ := hex.DecodeString(ss)
|
||||
frameType, dataText, _ := message.BtmVobcDecode(cfs)
|
||||
if frameType == message.COMMAND_TYPE {
|
||||
|
25
third_party/interlock/beijing12/interlock.go
vendored
25
third_party/interlock/beijing12/interlock.go
vendored
@ -33,13 +33,26 @@ type InterlockProxy interface {
|
||||
var interlockMap = make(map[string]InterlockProxy)
|
||||
var initMutex sync.Mutex
|
||||
|
||||
func Default(c *config.InterlockConfig) InterlockProxy {
|
||||
initMutex.Lock()
|
||||
defer initMutex.Unlock()
|
||||
if interlockMap[c.Code] == nil {
|
||||
interlockMap[c.Code] = &interlockProxy{runConfig: c}
|
||||
//func Default(c *config.InterlockConfig) InterlockProxy {
|
||||
// initMutex.Lock()
|
||||
// defer initMutex.Unlock()
|
||||
// if interlockMap[c.Code] == nil {
|
||||
// interlockMap[c.Code] = &interlockProxy{runConfig: c}
|
||||
// }
|
||||
// return interlockMap[c.Code]
|
||||
//}
|
||||
|
||||
func Start(c *config.InterlockConfig, manager InterlockMessageManager) {
|
||||
proxy := &interlockProxy{runConfig: c}
|
||||
proxy.Start(manager)
|
||||
interlockMap[c.Code] = proxy
|
||||
}
|
||||
|
||||
func Stop(c *config.InterlockConfig) {
|
||||
proxy := interlockMap[c.Code]
|
||||
if proxy != nil {
|
||||
proxy.Stop()
|
||||
}
|
||||
return interlockMap[c.Code]
|
||||
}
|
||||
|
||||
type interlockProxy struct {
|
||||
|
22
third_party/message/btm_vobc_data.go
vendored
22
third_party/message/btm_vobc_data.go
vendored
@ -277,7 +277,7 @@ func TranslateToFFFE(src []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
// TranslateToFFFE 将数据进行FFFE转义处理(不加头FFFE及尾FFFD)。
|
||||
func TranslateToFFFE2(pSrc []byte) []byte {
|
||||
/*func TranslateToFFFE2(pSrc []byte) []byte {
|
||||
var (
|
||||
srcPos, tgtPos, pos1, pos2, iii uint16
|
||||
gap uint16
|
||||
@ -348,7 +348,7 @@ func TranslateToFFFE2(pSrc []byte) []byte {
|
||||
// 截取实际使用的部分返回
|
||||
return pTgt[:tgtPos]
|
||||
}
|
||||
|
||||
*/
|
||||
func TranslateToFFFE3(pSrc []uint8, SrcLen uint16) ([]byte, uint16) {
|
||||
var (
|
||||
SrcPos, TgtPos, Pos1, Pos2, iii uint16
|
||||
@ -447,14 +447,6 @@ func baseEncode(source []byte) []byte {
|
||||
data := make([]byte, 0)
|
||||
crc32 := crc.CalculateCRC(crc.CRC32, source)
|
||||
newSource := binary.BigEndian.AppendUint32(source, uint32(crc32))
|
||||
//fffeData, _ := TranslateToFFFE(newSource)
|
||||
//fffeData := TranslateToFFFE2(newSource)
|
||||
//fffeData := FFFEEncode(newSource)
|
||||
//fffeData, _ := TranslateToFFFE3(newSource, uint16(len(newSource)))
|
||||
|
||||
/*f2 := make([]byte, len(newSource)*2)
|
||||
lens, _ := TranslateToFFFE4(newSource, f2)
|
||||
fffeData := f2[:lens]*/
|
||||
|
||||
f2 := make([]byte, len(newSource)*2)
|
||||
lens := aa(newSource, f2)
|
||||
@ -464,7 +456,8 @@ func baseEncode(source []byte) []byte {
|
||||
data = append(data, PACKAGE_END...)
|
||||
return data
|
||||
}
|
||||
func TranslateToFFFE4(pSrc []byte, pTgt []byte) (int, error) {
|
||||
|
||||
/*func TranslateToFFFE4(pSrc []byte, pTgt []byte) (int, error) {
|
||||
if pSrc == nil || pTgt == nil {
|
||||
return 0, fmt.Errorf("pSrc or pTgt is nil")
|
||||
}
|
||||
@ -524,7 +517,7 @@ func TranslateToFFFE4(pSrc []byte, pTgt []byte) (int, error) {
|
||||
|
||||
return tgtLen, nil
|
||||
}
|
||||
|
||||
*/
|
||||
// ID 命令帧的正文
|
||||
type BtmVobcIdCommand struct {
|
||||
BaseBtmVobc
|
||||
@ -634,7 +627,8 @@ const (
|
||||
btm_status_warn = 0x04
|
||||
)
|
||||
|
||||
var mesage_yuliu = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
var mesage_yuliu = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0} //11~19 预留
|
||||
var yuliu3 = []byte{0, 0, 0, 0, 0, 0} //8~13 保留
|
||||
|
||||
const (
|
||||
BTM_STSTUS_NORMAL = 0x00
|
||||
@ -681,8 +675,6 @@ func (b *BtmVobcMessage) Encode() []byte {
|
||||
return baseEncode(buf.Bytes())
|
||||
}
|
||||
|
||||
var yuliu3 = []byte{0, 0, 0, 0, 0, 0}
|
||||
|
||||
type BtmVobcMsgFree struct {
|
||||
BaseBtmVobc
|
||||
//yuliu1 byte
|
||||
|
18
third_party/message/train_pc_sim_message.go
vendored
18
third_party/message/train_pc_sim_message.go
vendored
@ -26,12 +26,14 @@ func (tp *TrainPcSimBaseMessage) Encode() []byte {
|
||||
|
||||
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 = append(pack, tp.Data...)
|
||||
//dataBufs := bytes.NewBuffer(nil)
|
||||
//binary.Write(dataBufs, binary.BigEndian, tp.Data)
|
||||
//data := dataBufs.Bytes()
|
||||
//pack = append(pack, data...)
|
||||
}
|
||||
|
||||
//pack = binary.BigEndian.AppendUint16(pack, uint16(0))
|
||||
pack = binary.BigEndian.AppendUint16(pack, uint16(crc.CalculateCRC(crc.CRC16, pack[1:])))
|
||||
return pack
|
||||
}
|
||||
@ -48,13 +50,13 @@ func (tp *TrainPcSimBaseMessage) Decode(data []byte) error {
|
||||
}
|
||||
var pcType byte
|
||||
pcType, _ = buf.ReadByte()
|
||||
|
||||
dataLen, _ := buf.ReadByte()
|
||||
if buf.Len() < int(dataLen)-1-1-1+2 {
|
||||
dataLen = dataLen - 3
|
||||
if buf.Len() < int(dataLen) {
|
||||
return fmt.Errorf("")
|
||||
}
|
||||
|
||||
var dd = make([]byte, dataLen)
|
||||
var dd = make([]byte, dataLen-2)
|
||||
|
||||
binary.Read(buf, binary.BigEndian, &dd)
|
||||
var crcCode uint16
|
||||
@ -127,7 +129,7 @@ func (tp *TrainSpeedPlaceReportMsg) Decode(d []byte) {
|
||||
binary.Read(buf, binary.BigEndian, &c2)
|
||||
var ts uint32
|
||||
binary.Read(buf, binary.BigEndian, &ts)
|
||||
fmt.Println(runDir, s1, s2, c1, c2, ts)
|
||||
fmt.Println(fmt.Sprintf("列车方向:%v,1路脉冲数:%v,2路脉冲数:%v,1路累计数:%v,2路累计数:%v,时间:%v", runDir, s1, s2, c1, c2, ts))
|
||||
|
||||
}
|
||||
|
||||
|
23
third_party/train_pc_sim/train_pc_sim.go
vendored
23
third_party/train_pc_sim/train_pc_sim.go
vendored
@ -251,7 +251,7 @@ func (d *trainPcSimService) initConn(clientKey string) {
|
||||
|
||||
client2, err := tcp.StartTcpClient(addr, rd.receiverDataHandle, d.readError)
|
||||
if err != nil {
|
||||
slog.Error("车载pc连接失败 clientKey:", clientKey, "error:", err.Error())
|
||||
slog.Error(fmt.Sprintf("车载pc连接失败 clientKey:%v,error:%v", clientKey, err.Error()))
|
||||
d.updateState(tpapi.ThirdPartyState_Broken)
|
||||
} else {
|
||||
rd.tcpClient = client2
|
||||
@ -304,6 +304,7 @@ func (d *trainPcSimService) Start(pcSimManage TrainPcSimManage) {
|
||||
d.updateState(tpapi.ThirdPartyState_Normal)
|
||||
go d.sendTrainLocationAndSpeedTask(ctx)
|
||||
}
|
||||
|
||||
func (d *trainPcSimService) Stop() {
|
||||
d.updateState(tpapi.ThirdPartyState_Closed)
|
||||
if d.cancleContext != nil {
|
||||
@ -371,8 +372,12 @@ func (d *trainPcSimService) sendTrainLocationAndSpeedTask(ctx context.Context) {
|
||||
bm := &message.TrainPcSimBaseMessage{Type: SENDER_TRAIN_LOCATION_INFO, Data: data}
|
||||
train.PluseCount.PulseCount1 = 0
|
||||
train.PluseCount.PulseCount2 = 0
|
||||
rd.tcpClient.Send(bm.Encode())
|
||||
|
||||
dataCode := bm.Encode()
|
||||
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)
|
||||
@ -415,11 +420,11 @@ func (d *trainPcSimService) SendDriverActive(train *state_proto.TrainState) {
|
||||
//{,"msg":"发送驾驶激活列车","1":"数据","!BADKEY":"eb0004002437"}
|
||||
|
||||
da := msg.Encode()
|
||||
slog.Info("发送驾驶激活列车", train.Id, "数据", hex.EncodeToString(da))
|
||||
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("发送驾驶激活列车", train.Id, "数据", hex.EncodeToString(da), err)
|
||||
slog.Error(fmt.Sprintf("发送驾驶激活失败列车id:%v,数据:%v,err:%v", train.Id, hex.EncodeToString(da), err.Error()))
|
||||
}
|
||||
}
|
||||
func (d *trainPcSimService) SendHandleSwitch(oldTraction, oldBrakeForce int64, tractionState bool, train *state_proto.TrainState) {
|
||||
@ -483,11 +488,11 @@ func (d *trainPcSimService) SendTrainDirection(train *state_proto.TrainState, tr
|
||||
//client := d.pcSimClientMap[clientKey]
|
||||
for _, msg := range baseMsgs {
|
||||
da := msg.Encode()
|
||||
slog.Info("发送列车方向列车", train.Id, "数据", hex.EncodeToString(da))
|
||||
slog.Info(fmt.Sprintf("发送列车方向列车:%v ,数据:%v", train.Id, hex.EncodeToString(da)))
|
||||
err := rd.tcpClient.Send(da)
|
||||
//err := client.Send(da)
|
||||
if err != nil {
|
||||
slog.Error("发送列车方向失败列车", train.Id, "数据", hex.EncodeToString(da))
|
||||
slog.Error(fmt.Sprintf("发送列车方向失败列车:%v ,数据:%v,err:%v", train.Id, hex.EncodeToString(da), err.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -501,11 +506,11 @@ func (d *trainPcSimService) SendBaliseData(train *state_proto.TrainState, msgTyp
|
||||
|
||||
//client := d.pcSimClientMap[clientKey]
|
||||
da := msg.Encode()
|
||||
slog.Info("发送列车PC仿真应答器信息,数据", hex.EncodeToString(da))
|
||||
slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息,数据:%v", hex.EncodeToString(da)))
|
||||
|
||||
err := rd.tcpClient.Send(da)
|
||||
if err != nil {
|
||||
slog.Info("发送列车PC仿真应答器信息失败,数据", hex.EncodeToString(da))
|
||||
slog.Info(fmt.Sprintf("发送列车PC仿真应答器信息失败,数据:%v", hex.EncodeToString(da)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -756,6 +756,10 @@ func buildAndRelateElectronicComponent(repo *proto.Repository, relayGi *data_pro
|
||||
for _, xcj := range repo.Xcjs {
|
||||
xcjMap[xcj.Id] = xcj
|
||||
}
|
||||
sectionMap := make(map[string]*proto.PhysicalSection)
|
||||
for _, section := range repo.PhysicalSections {
|
||||
sectionMap[section.Id] = section
|
||||
}
|
||||
ciecs := stationMap[stationUid] //联锁集中站
|
||||
if ciecs == nil {
|
||||
panic(fmt.Errorf("联锁集中站[%s]不存在", stationUid))
|
||||
@ -907,6 +911,27 @@ func buildAndRelateElectronicComponent(repo *proto.Repository, relayGi *data_pro
|
||||
})
|
||||
}
|
||||
}
|
||||
case data_proto.RelatedRef_Section:
|
||||
{
|
||||
section, ok := sectionMap[GenerateElementUid(city, lineId, []string{station}, relationship.Code)]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for _, group := range relationship.Combinationtypes {
|
||||
var componentIds []string
|
||||
for _, relayId := range group.RefRelays {
|
||||
if relayUidStructure.RelayIds[relayId] == nil {
|
||||
continue
|
||||
}
|
||||
componentIds = append(componentIds, relayUidStructure.RelayIds[relayId].Uid)
|
||||
}
|
||||
section.ElectronicComponentGroups = append(section.ElectronicComponentGroups,
|
||||
&proto.ElectronicComponentGroup{
|
||||
Code: group.Code,
|
||||
ComponentIds: componentIds,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//门控箱
|
||||
|
@ -126,7 +126,7 @@ func runThirdParty(s *memory.VerifySimulation) error {
|
||||
case "11":
|
||||
beijing11.Start(c, s)
|
||||
default:
|
||||
beijing12.Default(c).Start(s)
|
||||
beijing12.Start(c, s)
|
||||
}
|
||||
}
|
||||
// 计轴RSSP启动
|
||||
@ -162,7 +162,7 @@ func stopThirdParty(s *memory.VerifySimulation) {
|
||||
case "11":
|
||||
beijing11.Stop()
|
||||
default:
|
||||
beijing12.Default(c).Stop()
|
||||
beijing12.Stop(c)
|
||||
}
|
||||
}
|
||||
//计轴RSSP启动销毁
|
||||
|
Loading…
Reference in New Issue
Block a user