Skip to content

Commit

Permalink
all: Add multiple freq plans to sx1301 config file
Browse files Browse the repository at this point in the history
  • Loading branch information
cvetkovski98 committed Nov 16, 2023
1 parent 1b7cd8d commit d03137b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pkg/pfconfig/semtechudp/semtechudp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

// Config represents the full configuration for Semtech's UDP Packet Forwarder.
type Config struct {
SX1301Conf shared.SX1301Config `json:"SX1301_conf"`
GatewayConf GatewayConf `json:"gateway_conf"`
SX1301Conf []*shared.SX1301Config `json:"SX1301_conf"`
GatewayConf GatewayConf `json:"gateway_conf"`
}

// GatewayConf contains the configuration for the gateway's server connection.
Expand All @@ -50,22 +50,26 @@ func Build(gateway *ttnpb.Gateway, store *frequencyplans.Store) (*Config, error)
if gateway.GetIds().GetEui() != nil {
c.GatewayConf.GatewayID = types.MustEUI64(gateway.GetIds().GetEui()).String()
}
c.GatewayConf.ServerAddress, c.GatewayConf.ServerPortUp, c.GatewayConf.ServerPortDown = host, uint32(port), uint32(port)
c.GatewayConf.ServerAddress = host
c.GatewayConf.ServerPortUp = uint32(port)
c.GatewayConf.ServerPortDown = uint32(port)
server := c.GatewayConf
server.Enabled = true
c.GatewayConf.Servers = append(c.GatewayConf.Servers, server)

frequencyPlan, err := store.GetByID(gateway.FrequencyPlanId)
if err != nil {
return nil, err
}
if len(frequencyPlan.Radios) != 0 {
sx1301Config, err := shared.BuildSX1301Config(frequencyPlan)
c.SX1301Conf = make([]*shared.SX1301Config, 0, len(gateway.FrequencyPlanIds))
for _, frequencyPlanID := range gateway.FrequencyPlanIds {
frequencyPlan, err := store.GetByID(frequencyPlanID)
if err != nil {
return nil, err
}
c.SX1301Conf = *sx1301Config
if len(frequencyPlan.Radios) != 0 {
sx1301Config, err := shared.BuildSX1301Config(frequencyPlan)
if err != nil {
return nil, err
}
c.SX1301Conf = append(c.SX1301Conf, sx1301Config)
}
}

return &c, nil
}

0 comments on commit d03137b

Please sign in to comment.