From 617b0b66b86a78cff3715672a55f1f90651c27e3 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Fri, 28 Jul 2023 10:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=9B=E5=A2=9E=E5=8A=A0bj-rtss-message=E4=BD=9C?= =?UTF-8?q?=E4=B8=BAgit=E5=AD=90=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 3 +++ dynamics/{example/main.go => example_test.go} | 18 ++++++++-------- dynamics/http_test.go | 17 +++++++++++++++ dynamics/udp_test.go | 21 +++++++++++++++++++ xiannccda.setting.yml | 3 ++- 5 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 .gitmodules rename dynamics/{example/main.go => example_test.go} (84%) create mode 100644 dynamics/http_test.go create mode 100644 dynamics/udp_test.go diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..89c9781 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "bj-rtss-message"] + path = bj-rtss-message + url = https://git.code.tencent.com/beijing-rtss-test/bj-rtss-message.git diff --git a/dynamics/example/main.go b/dynamics/example_test.go similarity index 84% rename from dynamics/example/main.go rename to dynamics/example_test.go index ace1e57..f566759 100644 --- a/dynamics/example/main.go +++ b/dynamics/example_test.go @@ -1,4 +1,4 @@ -package main +package dynamics import ( "encoding/hex" @@ -7,21 +7,21 @@ import ( "github.com/gin-gonic/gin" "github.com/panjf2000/gnet/v2" "joylink.club/bj-rtsts-server/config" - "joylink.club/bj-rtsts-server/dynamics" "log" "net" "strconv" + "testing" "time" ) // 这里用来测试通信与数据传输是否正常 -func main() { +func TestAll(t *testing.T) { loadAndChangeConfig() //注册列车信息处理逻辑 - dynamics.RegisterTrainInfoHandler(&ExampleTrainInfoHandler{}) + RegisterTrainInfoHandler(&ExampleTrainInfoHandler{}) //启动udp服务 - go dynamics.RunUdpServer() + go RunUdpServer() ////启动仅用于的测试的模拟远程udp服务 go runTestUdpServer() ////启动http服务 @@ -30,9 +30,9 @@ func main() { //向本地udp服务发送数据 sendDataToLocalUdpServer() //向远程udp服务发送数据 - _ = dynamics.SendTurnoutInfo(&dynamics.TurnoutInfo{Code: 02}) + _ = SendTurnoutInfo(&TurnoutInfo{Code: 02}) //发送http请求 - _, _, _ = dynamics.SendTrainInitReq(&dynamics.InitTrainInfo{Speed: 10}) + _, _, _ = SendTrainInitReq(&InitTrainInfo{Speed: 10}) } func loadAndChangeConfig() { @@ -52,7 +52,7 @@ func sendDataToLocalUdpServer() { func runTestHttpServer() { engine := gin.Default() engine.POST("/api/aerodynamics/init/train", func(context *gin.Context) { - info := dynamics.InitTrainInfo{} + info := InitTrainInfo{} err := context.ShouldBindJSON(&info) if err != nil { println(err.Error()) @@ -95,7 +95,7 @@ func (server *testUdpServer) OnTraffic(c gnet.Conn) gnet.Action { type ExampleTrainInfoHandler struct { } -func (handler *ExampleTrainInfoHandler) HandleTrainInfo(info dynamics.TrainInfo) { +func (handler *ExampleTrainInfoHandler) HandleTrainInfo(info TrainInfo) { fmt.Println("处理列车信息...") fmt.Println(info) } diff --git a/dynamics/http_test.go b/dynamics/http_test.go new file mode 100644 index 0000000..f6012a5 --- /dev/null +++ b/dynamics/http_test.go @@ -0,0 +1,17 @@ +package dynamics + +import ( + "joylink.club/bj-rtsts-server/config" + "testing" +) + +func TestSendTrainInitReq(t *testing.T) { + config.LoadConfig() + SendTrainInitReq(&InitTrainInfo{ + TrainIndex: 1, + LinkIndex: 2, + LinkOffset: 3, + Speed: 4, + Up: true, + }) +} diff --git a/dynamics/udp_test.go b/dynamics/udp_test.go new file mode 100644 index 0000000..8b60f2e --- /dev/null +++ b/dynamics/udp_test.go @@ -0,0 +1,21 @@ +package dynamics + +import ( + "joylink.club/bj-rtsts-server/config" + "testing" +) + +func TestRunUdpServer(t *testing.T) { + config.LoadConfig() + RegisterTrainInfoHandler(&ExampleTrainInfoHandler{}) + RunUdpServer() +} + +func TestSendTurnoutInfo(t *testing.T) { + config.LoadConfig() + SendTurnoutInfo(&TurnoutInfo{ + Code: 2, + NPosition: true, + RPosition: false, + }) +} diff --git a/xiannccda.setting.yml b/xiannccda.setting.yml index 70d1863..2cc9a7e 100644 --- a/xiannccda.setting.yml +++ b/xiannccda.setting.yml @@ -6,9 +6,10 @@ server: port: 8080 # 动力学端口配置 dynamics: - ip: 127.0.0.1 + ip: 192.168.3.5 udpLocalPort: 4000 udpRemotePort: 3000 + httpPort: 9092 # 数据源 datasource: