Compare commits
No commits in common. "2569265a1fe58119938eeaa2050bae304adc9969" and "8d28ac1d596ab48e3a1e1bb5a3f5adf5afea00ac" have entirely different histories.
2569265a1f
...
8d28ac1d59
@ -1,61 +0,0 @@
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
acc:
|
||||
remoteIp: "127.0.0.1"
|
||||
remotePort: 1234
|
@ -1,9 +0,0 @@
|
||||
package config
|
||||
|
||||
type ExampleConfig struct {
|
||||
Acc acc
|
||||
}
|
||||
type acc struct {
|
||||
RemoteIp string
|
||||
RemotePort int
|
||||
}
|
Loading…
Reference in New Issue
Block a user