Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add band ID to list frequency plans RPC #6709

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/ttn/lorawan/v3/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,7 @@ PeerInfo
| `base_id` | [`string`](#string) | | The ID of the frequency that the current frequency plan is based on. |
| `name` | [`string`](#string) | | |
| `base_frequency` | [`uint32`](#uint32) | | Base frequency in MHz for hardware support (433, 470, 868 or 915) |
| `band_id` | [`string`](#string) | | |

### <a name="ttn.lorawan.v3.GetPhyVersionsRequest">Message `GetPhyVersionsRequest`</a>

Expand Down Expand Up @@ -2714,6 +2715,7 @@ PeerInfo
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `base_frequency` | [`uint32`](#uint32) | | Optional base frequency in MHz for hardware support (433, 470, 868 or 915) |
| `band_id` | [`string`](#string) | | Optional Band ID to filter the results. |

### <a name="ttn.lorawan.v3.ListFrequencyPlansResponse">Message `ListFrequencyPlansResponse`</a>

Expand Down
10 changes: 10 additions & 0 deletions api/ttn/lorawan/v3/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6707,6 +6707,13 @@
"required": false,
"type": "integer",
"format": "int64"
},
{
"name": "band_id",
"description": "Optional Band ID to filter the results.",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
Expand Down Expand Up @@ -22869,6 +22876,9 @@
"type": "integer",
"format": "int64",
"title": "Base frequency in MHz for hardware support (433, 470, 868 or 915)"
},
"band_id": {
"type": "string"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions api/ttn/lorawan/v3/configuration_services.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ message ListFrequencyPlansRequest {
};
// Optional base frequency in MHz for hardware support (433, 470, 868 or 915)
uint32 base_frequency = 1;
// Optional Band ID to filter the results.
string band_id = 2;
}

message FrequencyPlanDescription {
Expand All @@ -41,6 +43,7 @@ message FrequencyPlanDescription {
string name = 3;
// Base frequency in MHz for hardware support (433, 470, 868 or 915)
uint32 base_frequency = 4;
string band_id = 5;
}

message ListFrequencyPlansResponse {
Expand Down
2 changes: 2 additions & 0 deletions pkg/frequencyplans/frequencyplans.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ type FrequencyPlanDescription struct {
ID string `yaml:"id"`
// BaseID is the ID of the base frequency plan that this frequency plan extends (optional).
BaseID string `yaml:"base-id,omitempty"`
// BandID is the ID of the band that this frequency plan uses.
BandID string `yaml:"band-id,omitempty"`
// Name is a human readable name of the frequency plan.
Name string `yaml:"name"`
// BaseFrequency is the base frequency of the frequency plan (i.e. 868, 915)
Expand Down
4 changes: 4 additions & 0 deletions pkg/frequencyplans/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ func (s *RPCServer) ListFrequencyPlans(ctx context.Context, req *ttnpb.ListFrequ
if req.BaseFrequency != 0 && uint16(req.BaseFrequency) != desc.BaseFrequency {
continue
}
if req.BandId != "" && req.BandId != desc.BandID {
continue
}
res.FrequencyPlans = append(res.FrequencyPlans, &ttnpb.FrequencyPlanDescription{
Id: desc.ID,
BandId: desc.BandID,
BaseId: desc.BaseID,
Name: desc.Name,
BaseFrequency: uint32(desc.BaseFrequency),
Expand Down
36 changes: 34 additions & 2 deletions pkg/frequencyplans/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,64 @@ import (
)

func TestRPCServer(t *testing.T) {
t.Parallel()
a := assertions.New(t)

store := frequencyplans.NewStore(fetch.NewMemFetcher(map[string][]byte{
"frequency-plans.yml": []byte(`- id: A
band-id: EU_863_870
description: Frequency Plan A
base-frequency: 868
file: A.yml
- id: B
band-id: AS_923
base-id: A
description: Frequency Plan B
file: B.yml
- id: C
band-id: US_902_928
description: Frequency Plan C
base-frequency: 915
file: C.yml`),
}))

server := frequencyplans.NewRPCServer(store)

all, err := server.ListFrequencyPlans(context.Background(), &ttnpb.ListFrequencyPlansRequest{})
expectedAll := []*ttnpb.FrequencyPlanDescription{
{
Id: "A",
BandId: "EU_863_870",
BaseFrequency: 868,
},
{
Id: "B",
BaseId: "A",
BaseFrequency: 868,
BandId: "AS_923",
},
{
Id: "C",
BaseFrequency: 915,
BandId: "US_902_928",
},
}

actualAll, err := server.ListFrequencyPlans(context.Background(), &ttnpb.ListFrequencyPlansRequest{})
a.So(err, should.BeNil)
a.So(all.FrequencyPlans, should.HaveLength, 3)
a.So(actualAll.FrequencyPlans, should.HaveLength, 3)
a.So(actualAll.FrequencyPlans[0], should.Resemble, expectedAll[0])

base915, err := server.ListFrequencyPlans(context.Background(), &ttnpb.ListFrequencyPlansRequest{
BaseFrequency: 868,
})
a.So(err, should.BeNil)
a.So(base915.FrequencyPlans, should.HaveLength, 2)
a.So(base915.FrequencyPlans, should.Resemble, expectedAll[:2])

bandAS, err := server.ListFrequencyPlans(context.Background(), &ttnpb.ListFrequencyPlansRequest{
BandId: "AS_923",
})
a.So(err, should.BeNil)
a.So(bandAS.FrequencyPlans, should.HaveLength, 1)
a.So(bandAS.FrequencyPlans[0], should.Resemble, expectedAll[1])
}
Loading
Loading