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: