Skip to content

Commit

Permalink
dev: Create MAC state for Firefly devices
Browse files Browse the repository at this point in the history
  • Loading branch information
KrishnaIyer committed Nov 6, 2023
1 parent 609f8de commit dabeba5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 11 additions & 1 deletion pkg/source/firefly/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
package firefly

import (
"net/http"
"os"

"github.com/spf13/pflag"

"go.thethings.network/lorawan-stack-migrate/pkg/source"
"go.thethings.network/lorawan-stack-migrate/pkg/source/firefly/client"
"go.thethings.network/lorawan-stack/v3/pkg/fetch"
"go.thethings.network/lorawan-stack/v3/pkg/frequencyplans"
"go.thethings.network/lorawan-stack/v3/pkg/ttnpb"
)

Expand All @@ -38,7 +41,8 @@ type Config struct {
derivedMacVersion ttnpb.MACVersion
derivedPhyVersion ttnpb.PHYVersion

flags *pflag.FlagSet
flags *pflag.FlagSet
fpStore *frequencyplans.Store
}

// NewConfig returns a new Firefly configuration.
Expand Down Expand Up @@ -139,6 +143,12 @@ func (c *Config) Initialize(src source.Config) error {
return errInvalidMACVersion.WithAttributes("mac_version", c.macVersion)
}

fpFetcher, err := fetch.FromHTTP(http.DefaultClient, src.FrequencyPlansURL)
if err != nil {
return err
}
c.fpStore = frequencyplans.NewStore(fpFetcher)

return nil
}

Expand Down
15 changes: 9 additions & 6 deletions pkg/source/firefly/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import (
"context"

"github.com/TheThingsNetwork/go-utils/random"
"go.thethings.network/lorawan-stack/v3/pkg/networkserver/mac"
"go.thethings.network/lorawan-stack/v3/pkg/ttnpb"
"go.thethings.network/lorawan-stack/v3/pkg/types"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"

"go.thethings.network/lorawan-stack-migrate/pkg/iterator"
"go.thethings.network/lorawan-stack-migrate/pkg/log"
Expand Down Expand Up @@ -96,10 +95,7 @@ func (s Source) ExportDevice(devEUIString string) (*ttnpb.EndDevice, error) {
JoinEui: joinEUI.Bytes(),
},
MacSettings: &ttnpb.MACSettings{
DesiredAdrAckLimitExponent: &ttnpb.ADRAckLimitExponentValue{Value: ttnpb.ADRAckLimitExponent(ffdev.AdrLimit)},
Rx2DataRateIndex: &ttnpb.DataRateIndexValue{Value: ttnpb.DataRateIndex(ffdev.Rx2DataRate)},
StatusCountPeriodicity: wrapperspb.UInt32(0),
StatusTimePeriodicity: durationpb.New(0),
Rx2DataRateIndex: &ttnpb.DataRateIndexValue{Value: ttnpb.DataRateIndex(ffdev.Rx2DataRate)},
},
SupportsClassC: ffdev.ClassC,
SupportsJoin: ffdev.OTAA,
Expand Down Expand Up @@ -174,6 +170,13 @@ func (s Source) ExportDevice(devEUIString string) (*ttnpb.EndDevice, error) {
v3dev.Session.LastFCntUp = uint32(packet.FCnt)
v3dev.Session.LastAFCntDown = uint32(ffdev.FrameCounter)
v3dev.Session.LastNFCntDown = uint32(ffdev.FrameCounter)

// Create a MACState.
if v3dev.MacState, err = mac.NewState(v3dev, s.fpStore, &ttnpb.MACSettings{}); err != nil {
return nil, err
}
v3dev.MacState.CurrentParameters = v3dev.MacState.DesiredParameters
v3dev.MacState.CurrentParameters.Rx1Delay = ttnpb.RxDelay_RX_DELAY_1
}

if s.invalidateKeys {
Expand Down

0 comments on commit dabeba5

Please sign in to comment.