添加测试代码;增加bj-rtss-message作为git子模块
This commit is contained in:
parent
1c878c2962
commit
617b0b66b8
|
@ -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
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package dynamics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
@ -7,21 +7,21 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/panjf2000/gnet/v2"
|
"github.com/panjf2000/gnet/v2"
|
||||||
"joylink.club/bj-rtsts-server/config"
|
"joylink.club/bj-rtsts-server/config"
|
||||||
"joylink.club/bj-rtsts-server/dynamics"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 这里用来测试通信与数据传输是否正常
|
// 这里用来测试通信与数据传输是否正常
|
||||||
|
|
||||||
func main() {
|
func TestAll(t *testing.T) {
|
||||||
loadAndChangeConfig()
|
loadAndChangeConfig()
|
||||||
//注册列车信息处理逻辑
|
//注册列车信息处理逻辑
|
||||||
dynamics.RegisterTrainInfoHandler(&ExampleTrainInfoHandler{})
|
RegisterTrainInfoHandler(&ExampleTrainInfoHandler{})
|
||||||
//启动udp服务
|
//启动udp服务
|
||||||
go dynamics.RunUdpServer()
|
go RunUdpServer()
|
||||||
////启动仅用于的测试的模拟远程udp服务
|
////启动仅用于的测试的模拟远程udp服务
|
||||||
go runTestUdpServer()
|
go runTestUdpServer()
|
||||||
////启动http服务
|
////启动http服务
|
||||||
|
@ -30,9 +30,9 @@ func main() {
|
||||||
//向本地udp服务发送数据
|
//向本地udp服务发送数据
|
||||||
sendDataToLocalUdpServer()
|
sendDataToLocalUdpServer()
|
||||||
//向远程udp服务发送数据
|
//向远程udp服务发送数据
|
||||||
_ = dynamics.SendTurnoutInfo(&dynamics.TurnoutInfo{Code: 02})
|
_ = SendTurnoutInfo(&TurnoutInfo{Code: 02})
|
||||||
//发送http请求
|
//发送http请求
|
||||||
_, _, _ = dynamics.SendTrainInitReq(&dynamics.InitTrainInfo{Speed: 10})
|
_, _, _ = SendTrainInitReq(&InitTrainInfo{Speed: 10})
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadAndChangeConfig() {
|
func loadAndChangeConfig() {
|
||||||
|
@ -52,7 +52,7 @@ func sendDataToLocalUdpServer() {
|
||||||
func runTestHttpServer() {
|
func runTestHttpServer() {
|
||||||
engine := gin.Default()
|
engine := gin.Default()
|
||||||
engine.POST("/api/aerodynamics/init/train", func(context *gin.Context) {
|
engine.POST("/api/aerodynamics/init/train", func(context *gin.Context) {
|
||||||
info := dynamics.InitTrainInfo{}
|
info := InitTrainInfo{}
|
||||||
err := context.ShouldBindJSON(&info)
|
err := context.ShouldBindJSON(&info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println(err.Error())
|
println(err.Error())
|
||||||
|
@ -95,7 +95,7 @@ func (server *testUdpServer) OnTraffic(c gnet.Conn) gnet.Action {
|
||||||
type ExampleTrainInfoHandler struct {
|
type ExampleTrainInfoHandler struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *ExampleTrainInfoHandler) HandleTrainInfo(info dynamics.TrainInfo) {
|
func (handler *ExampleTrainInfoHandler) HandleTrainInfo(info TrainInfo) {
|
||||||
fmt.Println("处理列车信息...")
|
fmt.Println("处理列车信息...")
|
||||||
fmt.Println(info)
|
fmt.Println(info)
|
||||||
}
|
}
|
|
@ -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,
|
||||||
|
})
|
||||||
|
}
|
|
@ -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,
|
||||||
|
})
|
||||||
|
}
|
|
@ -6,9 +6,10 @@ server:
|
||||||
port: 8080
|
port: 8080
|
||||||
# 动力学端口配置
|
# 动力学端口配置
|
||||||
dynamics:
|
dynamics:
|
||||||
ip: 127.0.0.1
|
ip: 192.168.3.5
|
||||||
udpLocalPort: 4000
|
udpLocalPort: 4000
|
||||||
udpRemotePort: 3000
|
udpRemotePort: 3000
|
||||||
|
httpPort: 9092
|
||||||
|
|
||||||
# 数据源
|
# 数据源
|
||||||
datasource:
|
datasource:
|
||||||
|
|
Loading…
Reference in New Issue