Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #760 from TheThingsNetwork/develop
Browse files Browse the repository at this point in the history
v2.10.1
  • Loading branch information
htdvisser authored Mar 18, 2019
2 parents 0c47b31 + 7d6d975 commit fc5709a
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 417 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dev-deps: deps
@command -v protoc-gen-gogottn > /dev/null || go install github.com/TheThingsNetwork/ttn/utils/protoc-gen-gogottn
@command -v protoc-gen-ttndoc > /dev/null || go install github.com/TheThingsNetwork/ttn/utils/protoc-gen-ttndoc
@command -v mockgen > /dev/null || go get github.com/golang/mock/mockgen
@command -v golint > /dev/null || go get github.com/golang/lint/golint
@command -v golint > /dev/null || go get golang.org/x/lint/golint
@command -v forego > /dev/null || go get github.com/ddollar/forego

# Protobuf
Expand Down
3 changes: 3 additions & 0 deletions cmd/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The Things Network's backend servers.

```
--allow-insecure Allow insecure fallback if TLS unavailable
--au-fsb int Frequency sub-band for the AU band (0-indexed) (default 1)
--auth-token string The JWT token to be used for the discovery server
--config string config file (default "$HOME/.ttn.yml")
--description string The description of this component
Expand All @@ -23,6 +24,7 @@ The Things Network's backend servers.
--no-cli-logs Disable CLI logs
--public Announce this component as part of The Things Network (public community network)
--tls Use TLS (default true)
--us-fsb int Frequency sub-band for the US band (0-indexed) (default 1)
```


Expand Down Expand Up @@ -145,6 +147,7 @@ ttn gen-keypair generates a public/private keypair
**Options**

```
--force-adr-optimize Force ADR optimization
--net-id int LoRaWAN NetID (default 19)
--redis-address string Redis server and port (default "localhost:6379")
--redis-db int Redis database
Expand Down
3 changes: 3 additions & 0 deletions cmd/networkserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func init() {
"26000000/20": "otaa,abp,world,local,private,testing",
})

networkserverCmd.Flags().Bool("force-adr-optimize", false, "Force ADR optimization")
viper.BindPFlag("networkserver.force-adr-optimize", networkserverCmd.Flags().Lookup("force-adr-optimize"))

networkserverCmd.Flags().String("server-address", "0.0.0.0", "The IP address to listen for communication")
networkserverCmd.Flags().String("server-address-announce", "localhost", "The public IP address to announce")
networkserverCmd.Flags().Int("server-port", 1903, "The port for communication")
Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/TheThingsNetwork/go-utils/log/grpc"
promlog "github.com/TheThingsNetwork/go-utils/log/prometheus"
"github.com/TheThingsNetwork/ttn/api"
"github.com/TheThingsNetwork/ttn/core/band"
esHandler "github.com/TheThingsNetwork/ttn/utils/elasticsearch/handler"
"github.com/apex/log"
jsonHandler "github.com/apex/log/handlers/json"
Expand Down Expand Up @@ -110,6 +111,8 @@ var RootCmd = &cobra.Command{
"Auth Servers": viper.GetStringMapString("auth-servers"),
"Monitors": viper.GetStringMapString("monitor-servers"),
}).Info("Initializing The Things Network")

band.InitializeTables()
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
if logFile != nil {
Expand Down Expand Up @@ -169,6 +172,8 @@ func init() {
RootCmd.PersistentFlags().String("key-dir", path.Clean(dir+"/.ttn/"), "The directory where public/private keys are stored")

RootCmd.PersistentFlags().Int("eu-rx2-dr", 3, "RX2 data rate for the EU band (SF12=0,SF9=3)")
RootCmd.PersistentFlags().Int("us-fsb", 1, "Frequency sub-band for the US band (0-indexed)")
RootCmd.PersistentFlags().Int("au-fsb", 1, "Frequency sub-band for the AU band (0-indexed)")

viper.BindPFlags(RootCmd.PersistentFlags())
}
Expand Down
74 changes: 42 additions & 32 deletions core/band/band.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package band

import (
"sync"

pb_lorawan "github.com/TheThingsNetwork/api/protocol/lorawan"
"github.com/TheThingsNetwork/ttn/core/types"
"github.com/TheThingsNetwork/ttn/utils/errors"
Expand Down Expand Up @@ -48,7 +50,7 @@ func (f *FrequencyPlan) GetTxPowerIndexFor(txPower int) (int, error) {
func Guess(frequency uint64) string {
// Join frequencies
switch {
case frequency == 923200000 && frequency <= 923400000:
case frequency == 923200000 || frequency == 923400000:
// not considering AS_920_923 and AS_923_925 because we're not sure
return pb_lorawan.FrequencyPlan_AS_923.String()
case frequency == 922100000 || frequency == 922300000 || frequency == 922500000:
Expand All @@ -64,13 +66,14 @@ func Guess(frequency uint64) string {
return ""
}

func init() {
viper.SetDefault("eu-rx2-dr", "3")
viper.SetDefault("us-fsb", "1")
viper.SetDefault("au-fsb", "1")
}

// Get the frequency plan for the given region
func Get(region string) (frequencyPlan FrequencyPlan, err error) {
defer func() {
if err == nil && region == pb_lorawan.FrequencyPlan_EU_863_870.String() {
frequencyPlan.RX2DataRate = viper.GetInt("eu-rx2-dr")
}
}()
if fp, ok := frequencyPlans[region]; ok {
return fp, nil
}
Expand All @@ -92,9 +95,10 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
frequencyPlan.DownlinkChannels = frequencyPlan.UplinkChannels
frequencyPlan.CFList = &lorawan.CFList{867100000, 867300000, 867500000, 867700000, 867900000}
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 5, MinTXPower: 2, MaxTXPower: 14, StepTXPower: 3}
frequencyPlan.RX2DataRate = viper.GetInt("eu-rx2-dr")
case pb_lorawan.FrequencyPlan_US_902_928.String():
frequencyPlan.Band, err = lora.GetConfig(lora.US_902_928, false, lorawan.DwellTime400ms)
fsb := 1 // Enable 903.9-905.3/200 kHz, 904.6/500kHz channels
fsb := viper.GetInt("us-fsb") // If this is 1, enables 903.9-905.3/200 kHz, 904.6/500kHz channels, etc.
for channel := 0; channel < 72; channel++ {
if (channel < fsb*8 || channel >= (fsb+1)*8) && channel != fsb+64 {
frequencyPlan.DisableUplinkChannel(channel)
Expand All @@ -107,7 +111,7 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
frequencyPlan.Band, err = lora.GetConfig(lora.EU_433, false, lorawan.DwellTimeNoLimit)
case pb_lorawan.FrequencyPlan_AU_915_928.String():
frequencyPlan.Band, err = lora.GetConfig(lora.AU_915_928, false, lorawan.DwellTime400ms)
fsb := 1 // Enable 916.8-918.2/200 kHz, 917.5/500kHz channels
fsb := viper.GetInt("au-fsb") // If this is 1, enables 916.8-918.2/200 kHz, 917.5/500kHz channels, etc.
for channel := 0; channel < 72; channel++ {
if (channel < fsb*8 || channel >= (fsb+1)*8) && channel != fsb+64 {
frequencyPlan.DisableUplinkChannel(channel)
Expand Down Expand Up @@ -167,6 +171,7 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
}
frequencyPlan.DownlinkChannels = frequencyPlan.UplinkChannels
frequencyPlan.CFList = &lorawan.CFList{922700000, 922900000, 923100000, 923300000, 0}
frequencyPlan.ADR = &ADRConfig{MinDataRate: 0, MaxDataRate: 5, MinTXPower: 2, MaxTXPower: 14, StepTXPower: 2}
case pb_lorawan.FrequencyPlan_IN_865_867.String():
frequencyPlan.Band, err = lora.GetConfig(lora.IN_865_867, false, lorawan.DwellTimeNoLimit)
case pb_lorawan.FrequencyPlan_RU_864_870.String():
Expand Down Expand Up @@ -194,31 +199,36 @@ func Get(region string) (frequencyPlan FrequencyPlan, err error) {
var frequencyPlans map[string]FrequencyPlan
var channels map[int]string

func init() {
frequencyPlans = make(map[string]FrequencyPlan)
channels = make(map[int]string)
for _, r := range []pb_lorawan.FrequencyPlan{ // ordering is important here
pb_lorawan.FrequencyPlan_EU_863_870,
pb_lorawan.FrequencyPlan_IN_865_867,
pb_lorawan.FrequencyPlan_US_902_928,
pb_lorawan.FrequencyPlan_CN_779_787,
pb_lorawan.FrequencyPlan_EU_433,
pb_lorawan.FrequencyPlan_AS_923,
pb_lorawan.FrequencyPlan_AS_920_923,
pb_lorawan.FrequencyPlan_AS_923_925,
pb_lorawan.FrequencyPlan_KR_920_923,
pb_lorawan.FrequencyPlan_AU_915_928,
pb_lorawan.FrequencyPlan_CN_470_510,
pb_lorawan.FrequencyPlan_RU_864_870,
} {
region := r.String()
frequencyPlans[region], _ = Get(region)
for _, ch := range frequencyPlans[region].UplinkChannels {
if len(ch.DataRates) > 1 { // ignore FSK channels
if _, ok := channels[ch.Frequency]; !ok { // ordering indicates priority
channels[ch.Frequency] = region
var initializeOnce sync.Once

// InitializeTables initializes the frequency plan and channel tables.
func InitializeTables() {
initializeOnce.Do(func() {
frequencyPlans = make(map[string]FrequencyPlan)
channels = make(map[int]string)
for _, r := range []pb_lorawan.FrequencyPlan{ // ordering is important here
pb_lorawan.FrequencyPlan_EU_863_870,
pb_lorawan.FrequencyPlan_IN_865_867,
pb_lorawan.FrequencyPlan_US_902_928,
pb_lorawan.FrequencyPlan_CN_779_787,
pb_lorawan.FrequencyPlan_EU_433,
pb_lorawan.FrequencyPlan_AS_923,
pb_lorawan.FrequencyPlan_AS_920_923,
pb_lorawan.FrequencyPlan_AS_923_925,
pb_lorawan.FrequencyPlan_KR_920_923,
pb_lorawan.FrequencyPlan_AU_915_928,
pb_lorawan.FrequencyPlan_CN_470_510,
pb_lorawan.FrequencyPlan_RU_864_870,
} {
region := r.String()
frequencyPlans[region], _ = Get(region)
for _, ch := range frequencyPlans[region].UplinkChannels {
if len(ch.DataRates) > 1 { // ignore FSK channels
if _, ok := channels[ch.Frequency]; !ok { // ordering indicates priority
channels[ch.Frequency] = region
}
}
}
}
}
})
}
4 changes: 3 additions & 1 deletion core/band/band_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
func TestGuess(t *testing.T) {
a := New(t)

InitializeTables()

a.So(Guess(868100000), ShouldEqual, "EU_863_870")
a.So(Guess(903900000), ShouldEqual, "US_902_928")
a.So(Guess(779500000), ShouldEqual, "CN_779_787")
Expand Down Expand Up @@ -98,7 +100,7 @@ func TestGet(t *testing.T) {
fp, err := Get("KR_920_923")
a.So(err, ShouldBeNil)
a.So(fp.CFList, ShouldNotBeNil)
a.So(fp.ADR, ShouldBeNil)
a.So(fp.ADR, ShouldNotBeNil)
}

{
Expand Down
Loading

0 comments on commit fc5709a

Please sign in to comment.