fix: protocol v1

This commit is contained in:
2024-08-02 12:57:07 +02:00
parent 8f89ed7e77
commit b976bde363
23 changed files with 392 additions and 85 deletions

View File

@ -5,18 +5,22 @@ import (
"encoding/json"
"flag"
"fmt"
"log/slog"
"os"
reach "forge.cadoles.com/cadoles/go-emlid/reach/client"
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
"github.com/pkg/errors"
)
var (
host string = "192.168.42.1"
filter string = ""
host string = "192.168.42.1"
filter string = ""
rawLogLevel string = "ERROR"
)
func init() {
flag.StringVar(&rawLogLevel, "log-level", rawLogLevel, "log level")
flag.StringVar(&host, "host", host, "the reachrs module host")
flag.StringVar(&filter, "filter", filter, "filter the broadcast messages by name")
}
@ -27,6 +31,14 @@ func main() {
ctx := context.Background()
client := reach.NewClient(host)
logLevel, err := logger.ParseLevel(rawLogLevel)
if err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)
}
slog.SetLogLoggerLevel(logLevel)
if err := client.Connect(ctx); err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)

View File

@ -5,9 +5,11 @@ import (
"encoding/json"
"flag"
"fmt"
"log/slog"
"os"
reach "forge.cadoles.com/cadoles/go-emlid/reach/client"
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
v1 "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v1"
v2 "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2"
@ -18,9 +20,11 @@ var (
host string = "192.168.42.1"
preferredProtocol string = string(v2.Identifier)
fallbackProtocol string = string(v1.Identifier)
rawLogLevel string = "ERROR"
)
func init() {
flag.StringVar(&rawLogLevel, "log-level", rawLogLevel, "log level")
flag.StringVar(&host, "host", host, "the reachrs module host")
flag.StringVar(&preferredProtocol, "preferred-protocol", preferredProtocol, "preferred-protocol")
flag.StringVar(&fallbackProtocol, "fallback-protocol", fallbackProtocol, "fallback-protocol")
@ -29,6 +33,14 @@ func init() {
func main() {
flag.Parse()
logLevel, err := logger.ParseLevel(rawLogLevel)
if err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)
}
slog.SetLogLoggerLevel(logLevel)
ctx := context.Background()
client := reach.NewClient(
host,

35
cmd/discover/main.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"forge.cadoles.com/cadoles/go-emlid/reach/discovery"
"github.com/pkg/errors"
)
func main() {
services, err := discovery.Watch(context.Background())
if err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)
}
for srv := range services {
data, err := json.MarshalIndent(struct {
Addr string `json:"addr"`
Name string `json:"name"`
}{
Name: srv.Name,
Addr: fmt.Sprintf("%s:%d", srv.AddrV4.String(), srv.Port),
}, "", " ")
if err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)
}
fmt.Printf("%s\n", data)
}
}