From c2f8168a625160c38645d65eb795e8e7bf4114f0 Mon Sep 17 00:00:00 2001 From: Adrian-Stefan Mares Date: Thu, 19 Oct 2023 10:32:34 +0200 Subject: [PATCH] api: Add transmission settings set flags generation --- api/ttn/lorawan/v3/identifiers.proto | 2 +- api/ttn/lorawan/v3/lorawan.proto | 12 +- pkg/ttnpb/identifiers.pb.go | 2 +- pkg/ttnpb/identifiers_flags.pb.go | 51 +++++++ pkg/ttnpb/lorawan.pb.go | 12 +- pkg/ttnpb/lorawan_flags.pb.go | 221 +++++++++++++++++++++++++++ pkg/ttnpb/messages_flags.pb.go | 26 +++- 7 files changed, 308 insertions(+), 18 deletions(-) diff --git a/api/ttn/lorawan/v3/identifiers.proto b/api/ttn/lorawan/v3/identifiers.proto index 4d32b24d20..0e17fc72a3 100644 --- a/api/ttn/lorawan/v3/identifiers.proto +++ b/api/ttn/lorawan/v3/identifiers.proto @@ -228,7 +228,7 @@ message EndDeviceVersionIdentifiers { message NetworkIdentifiers { option (thethings.flags.message) = { select: true, - set: false + set: true }; // LoRa Alliance NetID. bytes net_id = 1 [ diff --git a/api/ttn/lorawan/v3/lorawan.proto b/api/ttn/lorawan/v3/lorawan.proto index 245e7de7ec..0f50e376cd 100644 --- a/api/ttn/lorawan/v3/lorawan.proto +++ b/api/ttn/lorawan/v3/lorawan.proto @@ -530,7 +530,7 @@ enum TxSchedulePriority { message LoRaDataRate { option (thethings.flags.message) = { select: true, - set: false + set: true }; // Bandwidth (Hz). uint32 bandwidth = 1; @@ -541,7 +541,7 @@ message LoRaDataRate { message FSKDataRate { option (thethings.flags.message) = { select: true, - set: false + set: true }; // Bit rate (bps). uint32 bit_rate = 1; @@ -550,7 +550,7 @@ message FSKDataRate { message LRFHSSDataRate { option (thethings.flags.message) = { select: true, - set: false + set: true }; uint32 modulation_type = 1; // Operating Channel Width (Hz). @@ -561,7 +561,7 @@ message LRFHSSDataRate { message DataRate { option (thethings.flags.message) = { select: true, - set: false + set: true }; oneof modulation { option (validate.required) = true; @@ -578,13 +578,13 @@ message DataRate { message TxSettings { option (thethings.flags.message) = { select: true, - set: false + set: true }; // Transmission settings for downlink. message Downlink { option (thethings.flags.message) = { select: true, - set: false + set: true }; // Index of the antenna on which the uplink was received and/or downlink must be sent. uint32 antenna_index = 1; diff --git a/pkg/ttnpb/identifiers.pb.go b/pkg/ttnpb/identifiers.pb.go index 50edfa43e1..7d605e5a1e 100644 --- a/pkg/ttnpb/identifiers.pb.go +++ b/pkg/ttnpb/identifiers.pb.go @@ -1198,7 +1198,7 @@ var file_ttn_lorawan_v3_identifiers_proto_rawDesc = []byte{ 0x61, 0x6e, 0x74, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x72, 0x03, 0x18, 0x80, 0x02, 0x52, 0x0d, 0x74, 0x65, 0x6e, 0x61, 0x6e, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x3a, 0x08, 0xf2, 0xaa, 0x19, 0x04, - 0x08, 0x01, 0x10, 0x00, 0x22, 0x69, 0x0a, 0x1e, 0x4c, 0x6f, 0x52, 0x61, 0x41, 0x6c, 0x6c, 0x69, + 0x08, 0x01, 0x10, 0x01, 0x22, 0x69, 0x0a, 0x1e, 0x4c, 0x6f, 0x52, 0x61, 0x41, 0x6c, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x65, 0x6e, 0x64, 0x6f, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x76, 0x65, 0x6e, 0x64, 0x6f, diff --git a/pkg/ttnpb/identifiers_flags.pb.go b/pkg/ttnpb/identifiers_flags.pb.go index 7b7580ee87..f2e69fd0aa 100644 --- a/pkg/ttnpb/identifiers_flags.pb.go +++ b/pkg/ttnpb/identifiers_flags.pb.go @@ -481,3 +481,54 @@ func PathsFromSelectFlagsForNetworkIdentifiers(flags *pflag.FlagSet, prefix stri } return paths, nil } + +// AddSetFlagsForNetworkIdentifiers adds flags to select fields in NetworkIdentifiers. +func AddSetFlagsForNetworkIdentifiers(flags *pflag.FlagSet, prefix string, hidden bool) { + flags.AddFlag(customflags.New3BytesFlag(flagsplugin.Prefix("net-id", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(customflags.New8BytesFlag(flagsplugin.Prefix("ns-id", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewStringFlag(flagsplugin.Prefix("tenant-id", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewStringFlag(flagsplugin.Prefix("cluster-id", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewStringFlag(flagsplugin.Prefix("cluster-address", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewStringFlag(flagsplugin.Prefix("tenant-address", prefix), "", flagsplugin.WithHidden(hidden))) +} + +// SetFromFlags sets the NetworkIdentifiers message from flags. +func (m *NetworkIdentifiers) SetFromFlags(flags *pflag.FlagSet, prefix string) (paths []string, err error) { + if val, changed, err := customflags.GetExactBytes(flags, flagsplugin.Prefix("net_id", prefix)); err != nil { + return nil, err + } else if changed { + m.NetId = val + paths = append(paths, flagsplugin.Prefix("net_id", prefix)) + } + if val, changed, err := customflags.GetExactBytes(flags, flagsplugin.Prefix("ns_id", prefix)); err != nil { + return nil, err + } else if changed { + m.NsId = val + paths = append(paths, flagsplugin.Prefix("ns_id", prefix)) + } + if val, changed, err := flagsplugin.GetString(flags, flagsplugin.Prefix("tenant_id", prefix)); err != nil { + return nil, err + } else if changed { + m.TenantId = val + paths = append(paths, flagsplugin.Prefix("tenant_id", prefix)) + } + if val, changed, err := flagsplugin.GetString(flags, flagsplugin.Prefix("cluster_id", prefix)); err != nil { + return nil, err + } else if changed { + m.ClusterId = val + paths = append(paths, flagsplugin.Prefix("cluster_id", prefix)) + } + if val, changed, err := flagsplugin.GetString(flags, flagsplugin.Prefix("cluster_address", prefix)); err != nil { + return nil, err + } else if changed { + m.ClusterAddress = val + paths = append(paths, flagsplugin.Prefix("cluster_address", prefix)) + } + if val, changed, err := flagsplugin.GetString(flags, flagsplugin.Prefix("tenant_address", prefix)); err != nil { + return nil, err + } else if changed { + m.TenantAddress = val + paths = append(paths, flagsplugin.Prefix("tenant_address", prefix)) + } + return paths, nil +} diff --git a/pkg/ttnpb/lorawan.pb.go b/pkg/ttnpb/lorawan.pb.go index ad1fea9de8..6f8ebae936 100644 --- a/pkg/ttnpb/lorawan.pb.go +++ b/pkg/ttnpb/lorawan.pb.go @@ -6345,10 +6345,10 @@ var file_ttn_lorawan_v3_lorawan_proto_rawDesc = []byte{ 0x61, 0x64, 0x69, 0x6e, 0x67, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x52, 0x61, 0x74, 0x65, 0x3a, 0x08, 0xf2, 0xaa, - 0x19, 0x04, 0x08, 0x01, 0x10, 0x00, 0x22, 0x32, 0x0a, 0x0b, 0x46, 0x53, 0x4b, 0x44, 0x61, 0x74, + 0x19, 0x04, 0x08, 0x01, 0x10, 0x01, 0x22, 0x32, 0x0a, 0x0b, 0x46, 0x53, 0x4b, 0x44, 0x61, 0x74, 0x61, 0x52, 0x61, 0x74, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x62, 0x69, 0x74, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x62, 0x69, 0x74, 0x52, 0x61, 0x74, 0x65, - 0x3a, 0x08, 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, 0x10, 0x00, 0x22, 0x9c, 0x01, 0x0a, 0x0e, 0x4c, + 0x3a, 0x08, 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, 0x10, 0x01, 0x22, 0x9c, 0x01, 0x0a, 0x0e, 0x4c, 0x52, 0x46, 0x48, 0x53, 0x53, 0x44, 0x61, 0x74, 0x61, 0x52, 0x61, 0x74, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x61, 0x74, 0x69, @@ -6358,7 +6358,7 @@ var file_ttn_lorawan_v3_lorawan_proto_rawDesc = []byte{ 0x6e, 0x67, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x57, 0x69, 0x64, 0x74, 0x68, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x52, 0x61, 0x74, 0x65, 0x3a, - 0x08, 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, 0x10, 0x00, 0x22, 0xc6, 0x01, 0x0a, 0x08, 0x44, 0x61, + 0x08, 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, 0x10, 0x01, 0x22, 0xc6, 0x01, 0x0a, 0x08, 0x44, 0x61, 0x74, 0x61, 0x52, 0x61, 0x74, 0x65, 0x12, 0x32, 0x0a, 0x04, 0x6c, 0x6f, 0x72, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x4c, 0x6f, 0x52, 0x61, 0x44, 0x61, 0x74, 0x61, 0x52, 0x61, @@ -6369,7 +6369,7 @@ var file_ttn_lorawan_v3_lorawan_proto_rawDesc = []byte{ 0x72, 0x66, 0x68, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x74, 0x74, 0x6e, 0x2e, 0x6c, 0x6f, 0x72, 0x61, 0x77, 0x61, 0x6e, 0x2e, 0x76, 0x33, 0x2e, 0x4c, 0x52, 0x46, 0x48, 0x53, 0x53, 0x44, 0x61, 0x74, 0x61, 0x52, 0x61, 0x74, 0x65, 0x48, 0x00, 0x52, 0x06, 0x6c, - 0x72, 0x66, 0x68, 0x73, 0x73, 0x3a, 0x08, 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, 0x10, 0x00, 0x42, + 0x72, 0x66, 0x68, 0x73, 0x73, 0x3a, 0x08, 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, 0x10, 0x01, 0x42, 0x11, 0x0a, 0x0a, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x03, 0xf8, 0x42, 0x01, 0x22, 0xf9, 0x03, 0x0a, 0x0a, 0x54, 0x78, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x3f, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x72, 0x61, 0x74, 0x65, 0x18, 0x01, @@ -6401,8 +6401,8 @@ var file_ttn_lorawan_v3_lorawan_proto_rawDesc = []byte{ 0x13, 0x69, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x5f, 0x70, 0x6f, 0x6c, 0x61, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x69, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x08, - 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, 0x10, 0x00, 0x3a, 0x08, 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, - 0x10, 0x00, 0x4a, 0x04, 0x08, 0x02, 0x10, 0x03, 0x4a, 0x04, 0x08, 0x03, 0x10, 0x04, 0x22, 0x8f, + 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, 0x10, 0x01, 0x3a, 0x08, 0xf2, 0xaa, 0x19, 0x04, 0x08, 0x01, + 0x10, 0x01, 0x4a, 0x04, 0x08, 0x02, 0x10, 0x03, 0x4a, 0x04, 0x08, 0x03, 0x10, 0x04, 0x22, 0x8f, 0x01, 0x0a, 0x19, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x41, 0x6e, 0x74, 0x65, 0x6e, 0x6e, 0x61, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x73, 0x12, 0x4d, 0x0a, 0x0b, 0x67, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, diff --git a/pkg/ttnpb/lorawan_flags.pb.go b/pkg/ttnpb/lorawan_flags.pb.go index c46fef0ce9..79d29f75fc 100644 --- a/pkg/ttnpb/lorawan_flags.pb.go +++ b/pkg/ttnpb/lorawan_flags.pb.go @@ -8,6 +8,7 @@ package ttnpb import ( flagsplugin "github.com/TheThingsIndustries/protoc-gen-go-flags/flagsplugin" + golang "github.com/TheThingsIndustries/protoc-gen-go-flags/golang" pflag "github.com/spf13/pflag" customflags "go.thethings.network/lorawan-stack/v3/cmd/ttn-lw-cli/customflags" ) @@ -509,6 +510,36 @@ func PathsFromSelectFlagsForLoRaDataRate(flags *pflag.FlagSet, prefix string) (p return paths, nil } +// AddSetFlagsForLoRaDataRate adds flags to select fields in LoRaDataRate. +func AddSetFlagsForLoRaDataRate(flags *pflag.FlagSet, prefix string, hidden bool) { + flags.AddFlag(flagsplugin.NewUint32Flag(flagsplugin.Prefix("bandwidth", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewUint32Flag(flagsplugin.Prefix("spreading-factor", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewStringFlag(flagsplugin.Prefix("coding-rate", prefix), "", flagsplugin.WithHidden(hidden))) +} + +// SetFromFlags sets the LoRaDataRate message from flags. +func (m *LoRaDataRate) SetFromFlags(flags *pflag.FlagSet, prefix string) (paths []string, err error) { + if val, changed, err := flagsplugin.GetUint32(flags, flagsplugin.Prefix("bandwidth", prefix)); err != nil { + return nil, err + } else if changed { + m.Bandwidth = val + paths = append(paths, flagsplugin.Prefix("bandwidth", prefix)) + } + if val, changed, err := flagsplugin.GetUint32(flags, flagsplugin.Prefix("spreading_factor", prefix)); err != nil { + return nil, err + } else if changed { + m.SpreadingFactor = val + paths = append(paths, flagsplugin.Prefix("spreading_factor", prefix)) + } + if val, changed, err := flagsplugin.GetString(flags, flagsplugin.Prefix("coding_rate", prefix)); err != nil { + return nil, err + } else if changed { + m.CodingRate = val + paths = append(paths, flagsplugin.Prefix("coding_rate", prefix)) + } + return paths, nil +} + // AddSelectFlagsForFSKDataRate adds flags to select fields in FSKDataRate. func AddSelectFlagsForFSKDataRate(flags *pflag.FlagSet, prefix string, hidden bool) { flags.AddFlag(flagsplugin.NewBoolFlag(flagsplugin.Prefix("bit-rate", prefix), flagsplugin.SelectDesc(flagsplugin.Prefix("bit-rate", prefix), false), flagsplugin.WithHidden(hidden))) @@ -524,6 +555,22 @@ func PathsFromSelectFlagsForFSKDataRate(flags *pflag.FlagSet, prefix string) (pa return paths, nil } +// AddSetFlagsForFSKDataRate adds flags to select fields in FSKDataRate. +func AddSetFlagsForFSKDataRate(flags *pflag.FlagSet, prefix string, hidden bool) { + flags.AddFlag(flagsplugin.NewUint32Flag(flagsplugin.Prefix("bit-rate", prefix), "", flagsplugin.WithHidden(hidden))) +} + +// SetFromFlags sets the FSKDataRate message from flags. +func (m *FSKDataRate) SetFromFlags(flags *pflag.FlagSet, prefix string) (paths []string, err error) { + if val, changed, err := flagsplugin.GetUint32(flags, flagsplugin.Prefix("bit_rate", prefix)); err != nil { + return nil, err + } else if changed { + m.BitRate = val + paths = append(paths, flagsplugin.Prefix("bit_rate", prefix)) + } + return paths, nil +} + // AddSelectFlagsForLRFHSSDataRate adds flags to select fields in LRFHSSDataRate. func AddSelectFlagsForLRFHSSDataRate(flags *pflag.FlagSet, prefix string, hidden bool) { flags.AddFlag(flagsplugin.NewBoolFlag(flagsplugin.Prefix("modulation-type", prefix), flagsplugin.SelectDesc(flagsplugin.Prefix("modulation-type", prefix), false), flagsplugin.WithHidden(hidden))) @@ -551,6 +598,36 @@ func PathsFromSelectFlagsForLRFHSSDataRate(flags *pflag.FlagSet, prefix string) return paths, nil } +// AddSetFlagsForLRFHSSDataRate adds flags to select fields in LRFHSSDataRate. +func AddSetFlagsForLRFHSSDataRate(flags *pflag.FlagSet, prefix string, hidden bool) { + flags.AddFlag(flagsplugin.NewUint32Flag(flagsplugin.Prefix("modulation-type", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewUint32Flag(flagsplugin.Prefix("operating-channel-width", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewStringFlag(flagsplugin.Prefix("coding-rate", prefix), "", flagsplugin.WithHidden(hidden))) +} + +// SetFromFlags sets the LRFHSSDataRate message from flags. +func (m *LRFHSSDataRate) SetFromFlags(flags *pflag.FlagSet, prefix string) (paths []string, err error) { + if val, changed, err := flagsplugin.GetUint32(flags, flagsplugin.Prefix("modulation_type", prefix)); err != nil { + return nil, err + } else if changed { + m.ModulationType = val + paths = append(paths, flagsplugin.Prefix("modulation_type", prefix)) + } + if val, changed, err := flagsplugin.GetUint32(flags, flagsplugin.Prefix("operating_channel_width", prefix)); err != nil { + return nil, err + } else if changed { + m.OperatingChannelWidth = val + paths = append(paths, flagsplugin.Prefix("operating_channel_width", prefix)) + } + if val, changed, err := flagsplugin.GetString(flags, flagsplugin.Prefix("coding_rate", prefix)); err != nil { + return nil, err + } else if changed { + m.CodingRate = val + paths = append(paths, flagsplugin.Prefix("coding_rate", prefix)) + } + return paths, nil +} + // AddSelectFlagsForDataRate adds flags to select fields in DataRate. func AddSelectFlagsForDataRate(flags *pflag.FlagSet, prefix string, hidden bool) { flags.AddFlag(flagsplugin.NewBoolFlag(flagsplugin.Prefix("modulation.lora", prefix), flagsplugin.SelectDesc(flagsplugin.Prefix("modulation.lora", prefix), true), flagsplugin.WithHidden(hidden))) @@ -596,6 +673,54 @@ func PathsFromSelectFlagsForDataRate(flags *pflag.FlagSet, prefix string) (paths return paths, nil } +// AddSetFlagsForDataRate adds flags to select fields in DataRate. +func AddSetFlagsForDataRate(flags *pflag.FlagSet, prefix string, hidden bool) { + AddSetFlagsForLoRaDataRate(flags, flagsplugin.Prefix("modulation.lora", prefix), hidden) + AddSetFlagsForFSKDataRate(flags, flagsplugin.Prefix("modulation.fsk", prefix), hidden) + AddSetFlagsForLRFHSSDataRate(flags, flagsplugin.Prefix("modulation.lrfhss", prefix), hidden) +} + +// SetFromFlags sets the DataRate message from flags. +func (m *DataRate) SetFromFlags(flags *pflag.FlagSet, prefix string) (paths []string, err error) { + if changed := flagsplugin.IsAnyPrefixSet(flags, flagsplugin.Prefix("modulation.lora", prefix)); changed { + ov := &DataRate_Lora{} + if ov.Lora == nil { + ov.Lora = &LoRaDataRate{} + } + if setPaths, err := ov.Lora.SetFromFlags(flags, flagsplugin.Prefix("modulation.lora", prefix)); err != nil { + return nil, err + } else { + paths = append(paths, setPaths...) + } + m.Modulation = ov + } + if changed := flagsplugin.IsAnyPrefixSet(flags, flagsplugin.Prefix("modulation.fsk", prefix)); changed { + ov := &DataRate_Fsk{} + if ov.Fsk == nil { + ov.Fsk = &FSKDataRate{} + } + if setPaths, err := ov.Fsk.SetFromFlags(flags, flagsplugin.Prefix("modulation.fsk", prefix)); err != nil { + return nil, err + } else { + paths = append(paths, setPaths...) + } + m.Modulation = ov + } + if changed := flagsplugin.IsAnyPrefixSet(flags, flagsplugin.Prefix("modulation.lrfhss", prefix)); changed { + ov := &DataRate_Lrfhss{} + if ov.Lrfhss == nil { + ov.Lrfhss = &LRFHSSDataRate{} + } + if setPaths, err := ov.Lrfhss.SetFromFlags(flags, flagsplugin.Prefix("modulation.lrfhss", prefix)); err != nil { + return nil, err + } else { + paths = append(paths, setPaths...) + } + m.Modulation = ov + } + return paths, nil +} + // AddSelectFlagsForTxSettings_Downlink adds flags to select fields in TxSettings_Downlink. func AddSelectFlagsForTxSettings_Downlink(flags *pflag.FlagSet, prefix string, hidden bool) { flags.AddFlag(flagsplugin.NewBoolFlag(flagsplugin.Prefix("antenna-index", prefix), flagsplugin.SelectDesc(flagsplugin.Prefix("antenna-index", prefix), false), flagsplugin.WithHidden(hidden))) @@ -623,6 +748,36 @@ func PathsFromSelectFlagsForTxSettings_Downlink(flags *pflag.FlagSet, prefix str return paths, nil } +// AddSetFlagsForTxSettings_Downlink adds flags to select fields in TxSettings_Downlink. +func AddSetFlagsForTxSettings_Downlink(flags *pflag.FlagSet, prefix string, hidden bool) { + flags.AddFlag(flagsplugin.NewUint32Flag(flagsplugin.Prefix("antenna-index", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewFloat32Flag(flagsplugin.Prefix("tx-power", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewBoolFlag(flagsplugin.Prefix("invert-polarization", prefix), "", flagsplugin.WithHidden(hidden))) +} + +// SetFromFlags sets the TxSettings_Downlink message from flags. +func (m *TxSettings_Downlink) SetFromFlags(flags *pflag.FlagSet, prefix string) (paths []string, err error) { + if val, changed, err := flagsplugin.GetUint32(flags, flagsplugin.Prefix("antenna_index", prefix)); err != nil { + return nil, err + } else if changed { + m.AntennaIndex = val + paths = append(paths, flagsplugin.Prefix("antenna_index", prefix)) + } + if val, changed, err := flagsplugin.GetFloat32(flags, flagsplugin.Prefix("tx_power", prefix)); err != nil { + return nil, err + } else if changed { + m.TxPower = val + paths = append(paths, flagsplugin.Prefix("tx_power", prefix)) + } + if val, changed, err := flagsplugin.GetBool(flags, flagsplugin.Prefix("invert_polarization", prefix)); err != nil { + return nil, err + } else if changed { + m.InvertPolarization = val + paths = append(paths, flagsplugin.Prefix("invert_polarization", prefix)) + } + return paths, nil +} + // AddSelectFlagsForTxSettings adds flags to select fields in TxSettings. func AddSelectFlagsForTxSettings(flags *pflag.FlagSet, prefix string, hidden bool) { flags.AddFlag(flagsplugin.NewBoolFlag(flagsplugin.Prefix("data-rate", prefix), flagsplugin.SelectDesc(flagsplugin.Prefix("data-rate", prefix), true), flagsplugin.WithHidden(hidden))) @@ -686,6 +841,72 @@ func PathsFromSelectFlagsForTxSettings(flags *pflag.FlagSet, prefix string) (pat return paths, nil } +// AddSetFlagsForTxSettings adds flags to select fields in TxSettings. +func AddSetFlagsForTxSettings(flags *pflag.FlagSet, prefix string, hidden bool) { + AddSetFlagsForDataRate(flags, flagsplugin.Prefix("data-rate", prefix), hidden) + flags.AddFlag(flagsplugin.NewUint64Flag(flagsplugin.Prefix("frequency", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewBoolFlag(flagsplugin.Prefix("enable-crc", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewUint32Flag(flagsplugin.Prefix("timestamp", prefix), "", flagsplugin.WithHidden(hidden))) + flags.AddFlag(flagsplugin.NewTimestampFlag(flagsplugin.Prefix("time", prefix), "", flagsplugin.WithHidden(hidden))) + AddSetFlagsForTxSettings_Downlink(flags, flagsplugin.Prefix("downlink", prefix), hidden) + flags.AddFlag(flagsplugin.NewInt64Flag(flagsplugin.Prefix("concentrator-timestamp", prefix), "", flagsplugin.WithHidden(hidden))) +} + +// SetFromFlags sets the TxSettings message from flags. +func (m *TxSettings) SetFromFlags(flags *pflag.FlagSet, prefix string) (paths []string, err error) { + if changed := flagsplugin.IsAnyPrefixSet(flags, flagsplugin.Prefix("data_rate", prefix)); changed { + if m.DataRate == nil { + m.DataRate = &DataRate{} + } + if setPaths, err := m.DataRate.SetFromFlags(flags, flagsplugin.Prefix("data_rate", prefix)); err != nil { + return nil, err + } else { + paths = append(paths, setPaths...) + } + } + if val, changed, err := flagsplugin.GetUint64(flags, flagsplugin.Prefix("frequency", prefix)); err != nil { + return nil, err + } else if changed { + m.Frequency = val + paths = append(paths, flagsplugin.Prefix("frequency", prefix)) + } + if val, changed, err := flagsplugin.GetBool(flags, flagsplugin.Prefix("enable_crc", prefix)); err != nil { + return nil, err + } else if changed { + m.EnableCrc = val + paths = append(paths, flagsplugin.Prefix("enable_crc", prefix)) + } + if val, changed, err := flagsplugin.GetUint32(flags, flagsplugin.Prefix("timestamp", prefix)); err != nil { + return nil, err + } else if changed { + m.Timestamp = val + paths = append(paths, flagsplugin.Prefix("timestamp", prefix)) + } + if val, changed, err := flagsplugin.GetTimestamp(flags, flagsplugin.Prefix("time", prefix)); err != nil { + return nil, err + } else if changed { + m.Time = golang.SetTimestamp(val) + paths = append(paths, flagsplugin.Prefix("time", prefix)) + } + if changed := flagsplugin.IsAnyPrefixSet(flags, flagsplugin.Prefix("downlink", prefix)); changed { + if m.Downlink == nil { + m.Downlink = &TxSettings_Downlink{} + } + if setPaths, err := m.Downlink.SetFromFlags(flags, flagsplugin.Prefix("downlink", prefix)); err != nil { + return nil, err + } else { + paths = append(paths, setPaths...) + } + } + if val, changed, err := flagsplugin.GetInt64(flags, flagsplugin.Prefix("concentrator_timestamp", prefix)); err != nil { + return nil, err + } else if changed { + m.ConcentratorTimestamp = val + paths = append(paths, flagsplugin.Prefix("concentrator_timestamp", prefix)) + } + return paths, nil +} + // AddSelectFlagsForFrequencyValue adds flags to select fields in FrequencyValue. func AddSelectFlagsForFrequencyValue(flags *pflag.FlagSet, prefix string, hidden bool) { flags.AddFlag(flagsplugin.NewBoolFlag(flagsplugin.Prefix("value", prefix), flagsplugin.SelectDesc(flagsplugin.Prefix("value", prefix), false), flagsplugin.WithHidden(hidden))) diff --git a/pkg/ttnpb/messages_flags.pb.go b/pkg/ttnpb/messages_flags.pb.go index e8dfada3f1..38ea4ccdd8 100644 --- a/pkg/ttnpb/messages_flags.pb.go +++ b/pkg/ttnpb/messages_flags.pb.go @@ -165,7 +165,7 @@ func AddSetFlagsForApplicationUplink(flags *pflag.FlagSet, prefix string, hidden // FIXME: Skipping NormalizedPayload because this repeated WKT is currently not supported. flags.AddFlag(flagsplugin.NewStringSliceFlag(flagsplugin.Prefix("normalized-payload-warnings", prefix), "", flagsplugin.WithHidden(hidden))) // FIXME: Skipping RxMetadata because repeated messages are currently not supported. - // FIXME: Skipping Settings because it does not seem to implement AddSetFlags. + AddSetFlagsForTxSettings(flags, flagsplugin.Prefix("settings", prefix), hidden) flags.AddFlag(flagsplugin.NewTimestampFlag(flagsplugin.Prefix("received-at", prefix), "", flagsplugin.WithHidden(hidden))) AddSetFlagsForKeyEnvelope(flags, flagsplugin.Prefix("app-s-key", prefix), hidden) flags.AddFlag(flagsplugin.NewUint32Flag(flagsplugin.Prefix("last-a-f-cnt-down", prefix), "", flagsplugin.WithHidden(hidden))) @@ -173,7 +173,7 @@ func AddSetFlagsForApplicationUplink(flags *pflag.FlagSet, prefix string, hidden flags.AddFlag(flagsplugin.NewDurationFlag(flagsplugin.Prefix("consumed-airtime", prefix), "", flagsplugin.WithHidden(hidden))) // FIXME: Skipping Locations because maps with message value types are currently not supported. AddSetFlagsForEndDeviceVersionIdentifiers(flags, flagsplugin.Prefix("version-ids", prefix), hidden) - // FIXME: Skipping NetworkIds because it does not seem to implement AddSetFlags. + AddSetFlagsForNetworkIdentifiers(flags, flagsplugin.Prefix("network-ids", prefix), hidden) } // SetFromFlags sets the ApplicationUplink message from flags. @@ -217,7 +217,16 @@ func (m *ApplicationUplink) SetFromFlags(flags *pflag.FlagSet, prefix string) (p paths = append(paths, flagsplugin.Prefix("normalized_payload_warnings", prefix)) } // FIXME: Skipping RxMetadata because it does not seem to implement AddSetFlags. - // FIXME: Skipping Settings because it does not seem to implement AddSetFlags. + if changed := flagsplugin.IsAnyPrefixSet(flags, flagsplugin.Prefix("settings", prefix)); changed { + if m.Settings == nil { + m.Settings = &TxSettings{} + } + if setPaths, err := m.Settings.SetFromFlags(flags, flagsplugin.Prefix("settings", prefix)); err != nil { + return nil, err + } else { + paths = append(paths, setPaths...) + } + } if val, changed, err := flagsplugin.GetTimestamp(flags, flagsplugin.Prefix("received_at", prefix)); err != nil { return nil, err } else if changed { @@ -263,7 +272,16 @@ func (m *ApplicationUplink) SetFromFlags(flags *pflag.FlagSet, prefix string) (p paths = append(paths, setPaths...) } } - // FIXME: Skipping NetworkIds because it does not seem to implement AddSetFlags. + if changed := flagsplugin.IsAnyPrefixSet(flags, flagsplugin.Prefix("network_ids", prefix)); changed { + if m.NetworkIds == nil { + m.NetworkIds = &NetworkIdentifiers{} + } + if setPaths, err := m.NetworkIds.SetFromFlags(flags, flagsplugin.Prefix("network_ids", prefix)); err != nil { + return nil, err + } else { + paths = append(paths, setPaths...) + } + } return paths, nil }