Checkpoint
This commit is contained in:
@@ -2,19 +2,22 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"time"
|
||||
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
"git.maze.io/go/ham/protocol/aprs/aprsis"
|
||||
|
||||
"git.maze.io/go/ham/radio"
|
||||
"git.maze.io/ham/hamview"
|
||||
"git.maze.io/ham/hamview/cmd"
|
||||
)
|
||||
|
||||
type aprsisConfig struct {
|
||||
Broker hamview.BrokerConfig `yaml:"broker"`
|
||||
Receiver hamview.APRSISConfig `yaml:"receiver"`
|
||||
Include []string `yaml:"include"`
|
||||
Broker hamview.BrokerConfig `yaml:"broker"`
|
||||
Receiver hamview.APRSISConfig `yaml:"receiver"`
|
||||
Radio map[string]*radio.Info `yaml:"radio"`
|
||||
Include []string `yaml:"include"`
|
||||
}
|
||||
|
||||
func (config *aprsisConfig) Includes() []string {
|
||||
@@ -43,15 +46,19 @@ func runAPRSIS(ctx context.Context, command *cli.Command) error {
|
||||
}
|
||||
|
||||
proxy.OnClient = func(callsign string, client *aprsis.ProxyClient) {
|
||||
go receiveAPRSIS(&config.Broker, callsign, client)
|
||||
go receiveAPRSIS(&config.Broker, callsign, client, config.Radio[callsign])
|
||||
}
|
||||
|
||||
return waitForInterrupt()
|
||||
}
|
||||
|
||||
func receiveAPRSIS(config *hamview.BrokerConfig, callsign string, client *aprsis.ProxyClient) {
|
||||
func receiveAPRSIS(config *hamview.BrokerConfig, callsign string, client *aprsis.ProxyClient, extra *radio.Info) {
|
||||
defer func() { _ = client.Close() }()
|
||||
|
||||
if extra == nil {
|
||||
logger.Warnf("receiver: no radio info configured for %s!", callsign)
|
||||
}
|
||||
|
||||
broker, err := hamview.NewBroker(config)
|
||||
if err != nil {
|
||||
logger.Errorf("receiver: can't setup to broker: %v", err)
|
||||
@@ -59,19 +66,81 @@ func receiveAPRSIS(config *hamview.BrokerConfig, callsign string, client *aprsis
|
||||
}
|
||||
defer func() { _ = broker.Close() }()
|
||||
|
||||
info := client.Info() // TODO: enrich info from config?
|
||||
info := client.Info()
|
||||
if extra != nil {
|
||||
info.Manufacturer = pick(info.Manufacturer, extra.Manufacturer)
|
||||
info.Device = pick(info.Device, extra.Device)
|
||||
info.FirmwareDate = pickTime(info.FirmwareDate, extra.FirmwareDate)
|
||||
info.FirmwareVersion = pick(info.FirmwareVersion, extra.FirmwareVersion)
|
||||
info.Antenna = pick(info.Antenna, extra.Antenna)
|
||||
info.Modulation = pick(info.Modulation, extra.Modulation)
|
||||
info.Position = pickPosition(info.Position, extra.Position)
|
||||
info.Frequency = pickFloat64(info.Frequency, extra.Frequency)
|
||||
info.Bandwidth = pickFloat64(info.Bandwidth, extra.Bandwidth)
|
||||
info.Power = pickFloat64(info.Power, extra.Power)
|
||||
info.Gain = pickFloat64(info.Gain, extra.Gain)
|
||||
info.LoRaSF = pickUint8(info.LoRaSF, extra.LoRaSF)
|
||||
info.LoRaCR = pickUint8(info.LoRaCR, extra.LoRaCR)
|
||||
}
|
||||
|
||||
if err = broker.StartRadio("aprs", info); err != nil {
|
||||
logger.Fatalf("receiver: can't start broker: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
id := base64.RawURLEncoding.EncodeToString([]byte(callsign))
|
||||
|
||||
logger.Infof("receiver: start receiving packets from station: %s", callsign)
|
||||
for packet := range client.RawPackets() {
|
||||
logger.Debugf("aprs packet: %#+v", packet)
|
||||
if err := broker.PublishPacket("aprs/packet", packet); err != nil {
|
||||
if err := broker.PublishPacket("aprs/packet/"+id, packet); err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
}
|
||||
logger.Infof("receiver: stopped receiving packets from station: %s", callsign)
|
||||
}
|
||||
|
||||
func pick(ss ...string) string {
|
||||
for _, s := range ss {
|
||||
if s != "" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func pickFloat64(vv ...float64) float64 {
|
||||
for _, v := range vv {
|
||||
if v != 0 {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func pickPosition(vv ...*radio.Position) *radio.Position {
|
||||
for _, v := range vv {
|
||||
if v != nil {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func pickTime(tt ...time.Time) time.Time {
|
||||
for _, t := range tt {
|
||||
if !t.Equal(time.Time{}) {
|
||||
return t
|
||||
}
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func pickUint8(vv ...uint8) uint8 {
|
||||
for _, v := range vv {
|
||||
if v != 0 {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
@@ -48,6 +49,9 @@ func runMeshCore(ctx context.Context, command *cli.Command) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Node id
|
||||
id := base64.RawURLEncoding.EncodeToString([]byte(info.Name))
|
||||
|
||||
// Trace scheduler
|
||||
//go receiver.RunTraces()
|
||||
|
||||
@@ -68,7 +72,7 @@ func runMeshCore(ctx context.Context, command *cli.Command) error {
|
||||
payloadType,
|
||||
len(packet.Raw))
|
||||
}
|
||||
if err = broker.PublishPacket("meshcore/packet", packet); err != nil {
|
||||
if err = broker.PublishPacket("meshcore/packet/"+id, packet); err != nil {
|
||||
logger.Errorf("receiver: failed to publish packet: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user