This repository has been archived by the owner on Sep 3, 2020. It is now read-only.
forked from Lora-net/packet_forwarder
/
configuration.go
110 lines (92 loc) · 2.94 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright © 2017 The Things Network. Use of this source code is governed by the MIT license that can be found in the LICENSE file.
package pktfwd
import (
"github.com/TheThingsNetwork/go-account-lib/account"
"github.com/TheThingsNetwork/go-utils/log"
"github.com/TheThingsNetwork/packet_forwarder/util"
"github.com/TheThingsNetwork/packet_forwarder/wrapper"
)
// Multitech concentrators require a clksrc of 0, even if the frequency plan indicates a value of 1.
// This value, modified at build to include the platform type, is currently useful as a flag to
// ignore the frequency plan value of `clksrc`.
var platform = ""
func configureBoard(ctx log.Interface, conf util.Config, gpsPath string) error {
if platform == "multitech" {
ctx.Info("Forcing clock source to 0 (Multitech concentrator)")
conf.Concentrator.Clksrc = 0
}
err := wrapper.SetBoardConf(ctx, conf)
if err != nil {
return err
}
err = configureChannels(ctx, conf)
if err != nil {
return err
}
err = enableGPS(ctx, gpsPath)
if err != nil {
return err
}
return nil
}
func configureIndividualChannels(ctx log.Interface, conf util.Config) error {
// Configuring LoRa standard channel
if lora := conf.Concentrator.LoraSTDChannel; lora != nil {
err := wrapper.SetStandardChannel(ctx, *lora)
if err != nil {
return err
}
ctx.Info("LoRa standard channel configured")
} else {
ctx.Warn("No configuration for LoRa standard channel, ignoring")
}
// Configuring FSK channel
if fsk := conf.Concentrator.FSKChannel; fsk != nil {
err := wrapper.SetFSKChannel(ctx, *fsk)
if err != nil {
return err
}
ctx.Info("FSK channel configured")
} else {
ctx.Warn("No configuration for FSK standard channel, ignoring")
}
return nil
}
func configureChannels(ctx log.Interface, conf util.Config) error {
// Configuring the TX Gain Lut
err := wrapper.SetTXGainConf(ctx, conf.Concentrator)
if err != nil {
return err
}
// Configuring the RF and SF channels
err = wrapper.SetRFChannels(ctx, conf)
if err != nil {
return err
}
wrapper.SetSFChannels(ctx, conf)
// Configuring the individual LoRa standard and FSK channels
err = configureIndividualChannels(ctx, conf)
if err != nil {
return err
}
return nil
}
// FetchConfig reads the configuration from the distant server
func FetchConfig(ctx log.Interface, ttnConfig *TTNConfig) (*util.Config, error) {
a := account.New(ttnConfig.AuthServer)
gw, err := a.FindGateway(ttnConfig.ID)
ctx = ctx.WithFields(log.Fields{"GatewayID": ttnConfig.ID, "AuthServer": ttnConfig.AuthServer})
if err != nil {
ctx.WithError(err).Error("Failed to find gateway specified as gateway ID")
return nil, err
}
ctx.WithField("URL", gw.FrequencyPlanURL).Info("Found gateway parameters, getting frequency plans")
if gw.Attributes.Description != nil {
ttnConfig.GatewayDescription = *gw.Attributes.Description
}
config, err := util.FetchConfigFromURL(ctx, gw.FrequencyPlanURL)
if err != nil {
return nil, err
}
return &config, nil
}