Skip to content

Commit

Permalink
api: WIP 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 15, 2023
1 parent 1b7cd8d commit a2a357f
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions pkg/pfconfig/semtechudp/semtechudp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ import (
"go.thethings.network/lorawan-stack/v3/pkg/types"
)

// SX1301FreqConfig represents the SX1301 configuration for a single frequency plan.
type SX1301FreqConfig struct {
FrequencyPlanID string `json:"frequency_plan_id"`
SX1301Conf *shared.SX1301Config `json:"SX1301_conf"`
}

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

Expand All @@ -50,22 +56,29 @@ 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([]*SX1301FreqConfig, 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, &SX1301FreqConfig{
SX1301Conf: sx1301Config,
FrequencyPlanID: frequencyPlanID,
})
}
}

return &c, nil
}

0 comments on commit a2a357f

Please sign in to comment.