Build builds a packet forwarder configuration for the given gateway, using the given frequency plan store.
(gateway *ttnpb.Gateway, store *frequencyplans.Store)
| 73 | |
| 74 | // Build builds a packet forwarder configuration for the given gateway, using the given frequency plan store. |
| 75 | func Build(gateway *ttnpb.Gateway, store *frequencyplans.Store) (*Config, error) { |
| 76 | var c Config |
| 77 | |
| 78 | host, port, err := shared.ParseGatewayServerAddress(gateway.GatewayServerAddress) |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | |
| 83 | if gateway.GetIds().GetEui() != nil { |
| 84 | c.GatewayConf.GatewayID = types.MustEUI64(gateway.GetIds().GetEui()).String() |
| 85 | } |
| 86 | c.GatewayConf.ServerAddress = host |
| 87 | c.GatewayConf.ServerPortUp = uint32(port) |
| 88 | c.GatewayConf.ServerPortDown = uint32(port) |
| 89 | server := c.GatewayConf |
| 90 | server.Enabled = true |
| 91 | c.GatewayConf.Servers = append(c.GatewayConf.Servers, server) |
| 92 | |
| 93 | c.SX1301Conf = make([]*shared.SX1301Config, 0, len(gateway.FrequencyPlanIds)) |
| 94 | for _, frequencyPlanID := range gateway.FrequencyPlanIds { |
| 95 | frequencyPlan, err := store.GetByID(frequencyPlanID) |
| 96 | if err != nil { |
| 97 | return nil, err |
| 98 | } |
| 99 | if len(frequencyPlan.Radios) != 0 { |
| 100 | sx1301Config, err := shared.BuildSX1301Config(frequencyPlan) |
| 101 | if err != nil { |
| 102 | return nil, err |
| 103 | } |
| 104 | c.SX1301Conf = append(c.SX1301Conf, sx1301Config) |
| 105 | } |
| 106 | } |
| 107 | return &c, nil |
| 108 | } |