Compare commits

..

2 Commits

Author SHA1 Message Date
tiger_zhou
2569265a1f Merge branch 'develop' into local-test
All checks were successful
local-test分支打包构建docker并发布运行 / Docker-Build (push) Successful in 2m42s
2024-05-20 15:23:20 +08:00
tiger_zhou
06f8445a98 现场加速度计测试连接 2024-05-20 15:22:58 +08:00
3 changed files with 73 additions and 0 deletions

61
bin/acc_conn-example.go Normal file
View File

@ -0,0 +1,61 @@
package main
import (
"fmt"
"github.com/spf13/viper"
"joylink.club/bj-rtsts-server/bin/config"
"joylink.club/bj-rtsts-server/third_party/message"
"joylink.club/bj-rtsts-server/third_party/udp"
"log/slog"
"time"
)
const config_name = "example"
var exampleConfig config.ExampleConfig
func initConfig() {
cnf := viper.New()
cnf.SetConfigName(config_name)
cnf.SetConfigType("yml")
cnf.AddConfigPath("./config/")
cnf.AddConfigPath(".")
err := cnf.ReadInConfig()
if err != nil {
panic(fmt.Errorf("读取配置文件错误: %w", err))
}
err = cnf.Unmarshal(&exampleConfig)
if err != nil {
panic(fmt.Errorf("解析配置文件错误: %w", err))
}
slog.Info("成功加载配置", "config", exampleConfig)
}
func main() {
initConfig()
testAcc()
}
func testAcc() {
var client udp.UdpClient
defer func() {
if client != nil {
client.Close()
}
slog.Info("连接关闭")
}()
client = udp.NewClient(fmt.Sprintf("%v:%v", exampleConfig.Acc.RemoteIp, exampleConfig.Acc.RemotePort))
ac := message.Accelerometer{Acc: 1}
var index int64
for {
err := client.Send(ac.Encode())
index++
if index%10 == 0 {
slog.Info(fmt.Sprintf("发送数据,时间戳:%v,发送次数:%v", time.Now().Unix(), index))
}
if err != nil {
slog.Error("发送数据失败", "err", err)
}
time.Sleep(time.Millisecond * 200)
}
}

3
bin/config/example.yml Normal file
View File

@ -0,0 +1,3 @@
acc:
remoteIp: "127.0.0.1"
remotePort: 1234

View File

@ -0,0 +1,9 @@
package config
type ExampleConfig struct {
Acc acc
}
type acc struct {
RemoteIp string
RemotePort int
}