Skip to content

Commit

Permalink
Merge pull request #6575 from TheThingsNetwork/fix/class-b-c-cli
Browse files Browse the repository at this point in the history
Fix class B/C downlink scheduling
  • Loading branch information
adriansmares authored Sep 27, 2023
2 parents d0c02db + eec5059 commit 1daa35a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ For details about compatibility between different releases, see the **Commitment

### Fixed

- Providing fixed downlink paths to the `ttn-lw-cli devices downlink {push|replace}` commands using the `-class-b-c.gateways` parameter. The gateways IDs are comma separated, and the antenna index `i` can be provided by suffixing the ID with `:i` (i.e. `my-gateway:0` for antenna index 0). The group index `j` can be provided by suffixing the ID with `:j` (i.e. `my-gateway:0:1` for antenna index 0 and group index 1). The antenna index is mandatory if a group index is to be provided, but optional otherwise.

### Security

## [3.27.2] - 2023-09-14
Expand Down
25 changes: 12 additions & 13 deletions cmd/ttn-lw-cli/commands/applications_downlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ var (
if err != nil {
return err
}
var downlink ttnpb.ApplicationDownlink
paths, err := downlink.SetFromFlags(cmd.Flags(), "")
downlink := &ttnpb.ApplicationDownlink{}
_, err = downlink.SetFromFlags(cmd.Flags(), "")
if err != nil {
return err
}
antennas, err := GetGatewayAntennaIdentifiers(cmd.Flags(), "class-b-c")
gateways, err := GetClassBCGatewayIdentifiers(cmd.Flags(), "class-b-c")
if err != nil {
return err
}
if len(antennas) > 0 {
paths = append(paths, "class-b-c.gateways")
if len(gateways) > 0 {
downlink.ClassBC.Gateways = gateways
}
as, err := api.Dial(ctx, config.ApplicationServerGRPCAddress)
if err != nil {
return err
}
_, err = ttnpb.NewAppAsClient(as).DownlinkQueuePush(ctx, &ttnpb.DownlinkQueueRequest{
EndDeviceIds: devID,
Downlinks: []*ttnpb.ApplicationDownlink{&downlink},
Downlinks: []*ttnpb.ApplicationDownlink{downlink},
})
if err != nil {
return err
Expand All @@ -71,26 +71,25 @@ var (
if err != nil {
return err
}

var downlink ttnpb.ApplicationDownlink
paths, err := downlink.SetFromFlags(cmd.Flags(), "")
downlink := &ttnpb.ApplicationDownlink{}
_, err = downlink.SetFromFlags(cmd.Flags(), "")
if err != nil {
return err
}
antennas, err := GetGatewayAntennaIdentifiers(cmd.Flags(), "class-b-c")
gateways, err := GetClassBCGatewayIdentifiers(cmd.Flags(), "class-b-c")
if err != nil {
return err
}
if len(antennas) > 0 {
paths = append(paths, "class-b-c.gateways")
if len(gateways) > 0 {
downlink.ClassBC.Gateways = gateways
}
as, err := api.Dial(ctx, config.ApplicationServerGRPCAddress)
if err != nil {
return err
}
_, err = ttnpb.NewAppAsClient(as).DownlinkQueueReplace(ctx, &ttnpb.DownlinkQueueRequest{
EndDeviceIds: devID,
Downlinks: []*ttnpb.ApplicationDownlink{&downlink},
Downlinks: []*ttnpb.ApplicationDownlink{downlink},
})
if err != nil {
return err
Expand Down
38 changes: 30 additions & 8 deletions cmd/ttn-lw-cli/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"io"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -348,18 +349,39 @@ func AddGatewayAntennaIdentifierFlags(flagSet *pflag.FlagSet, prefix string) {
flagSet.AddFlag(flagsplugin.NewStringSliceFlag(flagsplugin.Prefix("gateways", prefix), ""))
}

// GetGatewayAntennaIdentifiers gets a string slice value from a flag and returns a slice of gateway antenna identifiers.
func GetGatewayAntennaIdentifiers(flagSet *pflag.FlagSet, prefix string) (antennas []*ttnpb.GatewayAntennaIdentifiers, err error) {
antennaStrings, changed, err := flagsplugin.GetStringSlice(flagSet, flagsplugin.Prefix("gateways", prefix))
var errInvalidClassBCGatewayIdentifiers = errors.DefineInvalidArgument("class_b_c_gateway_identifiers", "invalid class B/C gateway identifiers")

// GetClassBCGatewayIdentifiers gets a string slice value from a flag and returns a slice of class B/C gateway identifiers.
func GetClassBCGatewayIdentifiers(flagSet *pflag.FlagSet, prefix string) (identifiers []*ttnpb.ClassBCGatewayIdentifiers, err error) {
identifiersStrings, changed, err := flagsplugin.GetStringSlice(flagSet, flagsplugin.Prefix("gateways", prefix))
if err != nil || !changed {
return nil, err
}
for _, id := range antennaStrings {
antennas = append(antennas, &ttnpb.GatewayAntennaIdentifiers{
for _, idStr := range identifiersStrings {
parts := strings.Split(idStr, ":")
ids := &ttnpb.ClassBCGatewayIdentifiers{
GatewayIds: &ttnpb.GatewayIdentifiers{
GatewayId: id,
GatewayId: parts[0],
},
})
}
if len(parts) > 1 {
antennaIdx, err := strconv.ParseUint(parts[1], 10, 32)
if err != nil {
return nil, err
}
ids.AntennaIndex = uint32(antennaIdx)
}
if len(parts) > 2 {
groupIdx, err := strconv.ParseUint(parts[2], 10, 32)
if err != nil {
return nil, err
}
ids.GroupIndex = uint32(groupIdx)
}
if len(parts) > 3 {
return nil, errInvalidClassBCGatewayIdentifiers.New()
}
identifiers = append(identifiers, ids)
}
return antennas, nil
return identifiers, nil
}
9 changes: 9 additions & 0 deletions config/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,15 @@
"file": "end_devices.go"
}
},
"error:cmd/ttn-lw-cli/commands:class_b_c_gateway_identifiers": {
"translations": {
"en": "invalid class B/C gateway identifiers"
},
"description": {
"package": "cmd/ttn-lw-cli/commands",
"file": "flags.go"
}
},
"error:cmd/ttn-lw-cli/commands:conflicting_paths": {
"translations": {
"en": "conflicting set and unset field mask paths"
Expand Down
2 changes: 2 additions & 0 deletions pkg/webui/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@
"error:cmd/ttn-lw-cli/commands:application_server_disabled": "アプリケーションサーバが利用不可",
"error:cmd/ttn-lw-cli/commands:claim_generated_eui": "ランダムに生成されたDevEUIでエンドデバイスをクレームできません。Join Serverに登録された有効なDevEUIを使用してください",
"error:cmd/ttn-lw-cli/commands:claiming_not_supported": "JoinEUI `{join_eui}`に対してはクレームがサポートされていません",
"error:cmd/ttn-lw-cli/commands:class_b_c_gateway_identifiers": "",
"error:cmd/ttn-lw-cli/commands:conflicting_paths": "設定されていないフィールドマスクパスが競合しています",
"error:cmd/ttn-lw-cli/commands:contact_info_exists": "連絡先情報がすでに存在します",
"error:cmd/ttn-lw-cli/commands:contact_info_not_found": "連絡先情報が見つかりません",
Expand Down Expand Up @@ -2750,6 +2751,7 @@
"event:ns.mac.new_channel.answer.reject": "新チャネル拒否を受信",
"event:ns.mac.new_channel.request": "新チャネル要求がエンキューされました",
"event:ns.mac.ping_slot_channel.answer.accept": "スロットチャネルへのPing許可を受信",
"event:ns.mac.ping_slot_channel.answer.reject": "",
"event:ns.mac.ping_slot_channel.request": "スロットチャネルへのPing要求がエンキューされました",
"event:ns.mac.ping_slot_info.answer": "スロット情報へのPing応答がエンキューされました",
"event:ns.mac.ping_slot_info.request": "スロット情報へのPing要求を受信",
Expand Down

0 comments on commit 1daa35a

Please sign in to comment.