Checkpoint
Some checks failed
Test and build / Test and lint (push) Failing after 36s
Test and build / Build collector (push) Failing after 43s
Test and build / Build receiver (push) Failing after 42s

This commit is contained in:
2026-03-05 15:38:18 +01:00
parent 3106b2cf45
commit 13afa08e8a
108 changed files with 19509 additions and 729 deletions

View File

@@ -33,13 +33,18 @@ type Broker interface {
SubscribeRadios() (<-chan *Radio, error)
PublishPacket(topic string, packet *protocol.Packet) error
SubscribePackets(topic string) (<-chan *protocol.Packet, error)
SubscribePackets(topic string) (<-chan *Packet, error)
}
type Receiver interface {
Disconnected()
}
type Packet struct {
RadioID string
*protocol.Packet
}
type BrokerConfig struct {
Type string `yaml:"type"`
Config yaml.Node `yaml:"conf"`
@@ -197,7 +202,7 @@ func (broker *mqttBroker) SubscribeRadios() (<-chan *Radio, error) {
}
radios := make(chan *Radio, 8)
token := broker.client.Subscribe("radio/#", 0, func(_ mqtt.Client, message mqtt.Message) {
token := broker.client.Subscribe("radio/+", 0, func(_ mqtt.Client, message mqtt.Message) {
var radio Radio
if err := json.Unmarshal(message.Payload(), &radio); err == nil {
select {
@@ -232,17 +237,24 @@ func (broker *mqttBroker) PublishPacket(topic string, packet *protocol.Packet) e
return nil
}
func (broker *mqttBroker) SubscribePackets(topic string) (<-chan *protocol.Packet, error) {
func (broker *mqttBroker) SubscribePackets(topic string) (<-chan *Packet, error) {
if broker.client == nil {
return nil, ErrBrokerNotStarted
}
packets := make(chan *protocol.Packet, 16)
packets := make(chan *Packet, 16)
token := broker.client.Subscribe(topic, 0, func(_ mqtt.Client, message mqtt.Message) {
var packet protocol.Packet
var (
part = strings.Split(message.Topic(), "/")
id = part[len(part)-1]
packet protocol.Packet
)
if err := json.Unmarshal(message.Payload(), &packet); err == nil {
select {
case packets <- &packet:
case packets <- &Packet{
RadioID: id,
Packet: &packet,
}:
default:
}
}