Skip to content

Commit 772a404

Browse files
committed
util: Move Gateways field to FrequencyPlanDescription
1 parent b7a44d9 commit 772a404

File tree

4 files changed

+13
-118
lines changed

4 files changed

+13
-118
lines changed

pkg/frequencyplans/frequencyplans.go

+2-31
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,6 @@ type FrequencyPlan struct {
346346
DefaultRx2DataRate *uint8 `yaml:"rx2-default-data-rate,omitempty"`
347347
// MaxEIRP is the maximum EIRP as ceiling for any (sub-)band value.
348348
MaxEIRP *float32 `yaml:"max-eirp,omitempty"`
349-
// Gateways is a boolean indicating whether the frequency plan is suitable for gateways.
350-
Gateways *bool `yaml:"gateways,omitempty"`
351349
}
352350

353351
// Extend returns the same frequency plan, with values overridden by the passed frequency plan.
@@ -414,10 +412,6 @@ func (fp FrequencyPlan) Extend(extension FrequencyPlan) FrequencyPlan {
414412
val := *extension.MaxEIRP
415413
extended.MaxEIRP = &val
416414
}
417-
if extension.Gateways != nil {
418-
val := *extension.Gateways
419-
extended.Gateways = &val
420-
}
421415

422416
return extended
423417
}
@@ -534,6 +528,8 @@ type FrequencyPlanDescription struct {
534528
BaseFrequency uint16 `yaml:"base-frequency"`
535529
// File is the file where the frequency plan is defined.
536530
File string `yaml:"file"`
531+
// Gateways is a boolean indicating whether the frequency plan is suitable for gateways.
532+
Gateways *bool `yaml:"gateways,omitempty"`
537533
}
538534

539535
var errFetchFailed = errors.Define("fetch", "fetching failed")
@@ -735,28 +731,3 @@ func (s *Store) GetAllIDs() ([]string, error) {
735731

736732
return ids, nil
737733
}
738-
739-
// GetGatewayFrequencyPlans returns the list of frequency plans that are suitable for gateways.
740-
func (s *Store) GetGatewayFrequencyPlans() ([]*FrequencyPlan, error) {
741-
if s == nil {
742-
return nil, errNotConfigured.New()
743-
}
744-
745-
descriptions, err := s.descriptions()
746-
if err != nil {
747-
return nil, errReadList.WithCause(err)
748-
}
749-
750-
var gatewayFrequencyPlans []*FrequencyPlan
751-
for _, description := range descriptions {
752-
frequencyPlan, err := s.getByID(description.ID)
753-
if err != nil {
754-
return nil, err
755-
}
756-
if frequencyPlan.Gateways != nil && *frequencyPlan.Gateways {
757-
gatewayFrequencyPlans = append(gatewayFrequencyPlans, frequencyPlan)
758-
}
759-
}
760-
761-
return gatewayFrequencyPlans, nil
762-
}

pkg/frequencyplans/frequencyplans_test.go

+6-68
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,19 @@ func TestStore(t *testing.T) {
8888
description: South East Asia
8989
base-frequency: 915
9090
file: AS_923.yml
91+
gateways: true
9192
- id: JP
9293
base-id: AS_923
9394
description: Japan
9495
base-frequency: 915
9596
file: JP.yml
97+
gateways: true
9698
- id: KR
9799
base-id: AS_923
98100
description: South Korea
99101
base-frequency: 915
100102
file: KR.yml
103+
gateways: true
101104
- id: EU_863_870
102105
description: European Union
103106
file: EU.yml
@@ -106,16 +109,19 @@ func TestStore(t *testing.T) {
106109
description: United States
107110
file: US_915.yml
108111
base-frequency: 915
112+
gateways: true
109113
- id: SA
110114
base-id: AFRICA
111115
description: South Africa
112116
file: AS_923.yml
113117
base-frequency: 868
118+
gateways: false
114119
- id: CA
115120
base-id: US_915
116121
description: Canada
117122
file: EU.yml
118123
base-frequency: 915
124+
gateways: false
119125
`),
120126
"AS_923.yml": []byte(`band-id: AS_923
121127
uplink-channels:
@@ -486,71 +492,3 @@ dwell-time:
486492
})
487493
}
488494
}
489-
490-
func TestGetGatewayFrequencyPlans(t *testing.T) {
491-
t.Parallel()
492-
a := assertions.New(t)
493-
494-
store := frequencyplans.NewStore(fetch.NewMemFetcher(map[string][]byte{
495-
"frequency-plans.yml": []byte(`- id: EU_863_870
496-
band-id: EU_863_870
497-
name: Europe 863-870 MHz (SF12 for RX2)
498-
description: Default frequency plan for Europe
499-
base-frequency: 868
500-
file: EU_863_870.yml
501-
- id: EU_863_870_TTN
502-
band-id: EU_863_870
503-
name: Europe 863-870 MHz (SF9 for RX2 - recommended)
504-
description: TTN Community Network frequency plan for Europe, using SF9 for RX2
505-
base-frequency: 868
506-
base-id: EU_863_870
507-
file: EU_863_870_TTN.yml
508-
- id: US_902_928_FSB_1
509-
band-id: US_902_928
510-
name: United States 902-928 MHz, FSB 1
511-
description: Default frequency plan for the United States and Canada, using sub-band 1
512-
base-frequency: 915
513-
file: US_902_928_FSB_1.yml
514-
- id: AS_923_2
515-
band-id: AS_923_2
516-
name: Asia 920-923 MHz (AS923 Group 2) with only default channels
517-
description: Compatibility frequency plan for Asian countries with common channels in the 921.4-922.0 MHz sub-band
518-
base-frequency: 915
519-
file: AS_923_2.yml
520-
- id: AS_923_2_DT
521-
band-id: AS_923_2
522-
name: Asia 920-923 MHz (AS923 Group 2) with only default channels and dwell time enabled
523-
base-frequency: 915
524-
base-id: AS_923_2
525-
file: enable_dwell_time_400ms.yml
526-
`),
527-
"EU_863_870.yml": []byte(`band-id: EU_863_870
528-
max-eirp: 1
529-
gateways: false
530-
`),
531-
"EU_863_870_TTN.yml": []byte(`max-eirp: 2
532-
gateways: true
533-
`),
534-
"US_902_928_FSB_1.yml": []byte(`band-id: US_902_928
535-
max-eirp: 3
536-
`),
537-
"AS_923_2.yml": []byte(`band-id: AS_923_2
538-
max-eirp: 4
539-
gateways: true
540-
`),
541-
"enable_dwell_time_400ms.yml": []byte(`max-eirp: 5
542-
gateways: false
543-
`),
544-
}))
545-
546-
// Frequency plan with gateways
547-
{
548-
plans, err := store.GetGatewayFrequencyPlans()
549-
a.So(err, should.BeNil)
550-
a.So(plans, should.HaveLength, 2)
551-
a.So(plans[0].BandID, should.Equal, "EU_863_870")
552-
a.So(plans[1].BandID, should.Equal, "AS_923_2")
553-
a.So(*plans[0].MaxEIRP, should.Equal, 2)
554-
a.So(*plans[1].MaxEIRP, should.Equal, 4)
555-
}
556-
}

pkg/frequencyplans/rpc.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,8 @@ func (s *RPCServer) ListFrequencyPlans(ctx context.Context, req *ttnpb.ListFrequ
4242
if req.BandId != "" && req.BandId != desc.BandID {
4343
continue
4444
}
45-
if req.GatewaysOnly {
46-
frequencyPlan, err := s.store.getByID(desc.ID)
47-
if err != nil {
48-
return nil, err
49-
}
50-
if frequencyPlan.Gateways == nil || !*frequencyPlan.Gateways {
51-
continue
52-
}
45+
if req.GatewaysOnly && (desc.Gateways == nil || !*desc.Gateways) {
46+
continue
5347
}
5448
res.FrequencyPlans = append(res.FrequencyPlans, &ttnpb.FrequencyPlanDescription{
5549
Id: desc.ID,

pkg/frequencyplans/rpc_test.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,18 @@ func TestRPCServer(t *testing.T) {
3535
description: Frequency Plan A
3636
base-frequency: 868
3737
file: A.yml
38+
gateways: true
3839
- id: B
3940
band-id: AS_923
4041
base-id: A
4142
description: Frequency Plan B
4243
file: B.yml
44+
gateways: false
4345
- id: C
4446
band-id: US_902_928
4547
description: Frequency Plan C
4648
base-frequency: 915
4749
file: C.yml`),
48-
"A.yml": []byte(`band-id: EU_863_870
49-
max-eirp: 1
50-
gateways: false
51-
`),
52-
"B.yml": []byte(`max-eirp: 2
53-
gateways: true
54-
`),
55-
"C.yml": []byte(`band-id: US_902_928
56-
max-eirp: 3
57-
`),
5850
}))
5951

6052
server := frequencyplans.NewRPCServer(store)
@@ -102,5 +94,5 @@ max-eirp: 3
10294
})
10395
a.So(err, should.BeNil)
10496
a.So(gateways.FrequencyPlans, should.HaveLength, 1)
105-
a.So(bandAS.FrequencyPlans[0], should.Resemble, expectedAll[1])
97+
a.So(gateways.FrequencyPlans[0], should.Resemble, expectedAll[0])
10698
}

0 commit comments

Comments
 (0)