MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / BuildSX1301Config

Function BuildSX1301Config

pkg/pfconfig/shared/shared.go:279–373  ·  view source on GitHub ↗

BuildSX1301Config builds the SX1301 configuration for the given frequency plan.

(frequencyPlan *frequencyplans.FrequencyPlan)

Source from the content-addressed store, hash-verified

277
278// BuildSX1301Config builds the SX1301 configuration for the given frequency plan.
279func BuildSX1301Config(frequencyPlan *frequencyplans.FrequencyPlan) (*SX1301Config, error) {
280 phy, err := band.GetLatest(frequencyPlan.BandID)
281 if err != nil {
282 return nil, err
283 }
284
285 conf := new(SX1301Config)
286
287 conf.LoRaWANPublic = true
288 conf.ClockSource = frequencyPlan.ClockSource
289
290 if frequencyPlan.LBT != nil {
291 lbtConfig := &LBTConfig{
292 Enable: true,
293 RSSITarget: frequencyPlan.LBT.RSSITarget,
294 RSSIOffset: frequencyPlan.LBT.RSSIOffset,
295 }
296 for i, channel := range frequencyPlan.DownlinkChannels {
297 if i > 7 {
298 break
299 }
300 lbtConfig.ChannelConfigs = append(lbtConfig.ChannelConfigs, LBTChannelConfig{
301 Frequency: channel.Frequency,
302 ScanTimeMicroseconds: uint32(frequencyPlan.LBT.ScanTime / time.Microsecond),
303 })
304 }
305 conf.LBTConfig = lbtConfig
306 }
307
308 conf.Radios = make([]RFConfig, len(frequencyPlan.Radios))
309 for i, radio := range frequencyPlan.Radios {
310 rfConfig := RFConfig{
311 Enable: radio.Enable,
312 Type: radio.ChipType,
313 Frequency: radio.Frequency,
314 RSSIOffset: radio.RSSIOffset,
315 }
316 if radio.TxConfiguration != nil {
317 rfConfig.TxEnable = true
318 rfConfig.TxFreqMin = radio.TxConfiguration.MinFrequency
319 rfConfig.TxFreqMax = radio.TxConfiguration.MaxFrequency
320 if radio.TxConfiguration.NotchFrequency != nil {
321 rfConfig.TxNotchFreq = *radio.TxConfiguration.NotchFrequency
322 }
323 }
324 conf.Radios[i] = rfConfig
325 }
326
327 numChannels := max(len(frequencyPlan.UplinkChannels), 8)
328 conf.Channels = make([]IFConfig, numChannels)
329 for i, channel := range frequencyPlan.UplinkChannels {
330 ifConfig := IFConfig{
331 Enable: true,
332 Radio: channel.Radio,
333 IFValue: int32(int64(channel.Frequency) - int64(conf.Radios[channel.Radio].Frequency)),
334 }
335 conf.Channels[i] = ifConfig
336 }

Callers 6

GetRouterConfigFunction · 0.92
BuildLoradFunction · 0.92
TestBuildLoradFunction · 0.92
BuildFunction · 0.92
TestSX1301ConfFunction · 0.85

Calls 4

GetLatestFunction · 0.92
DataRateIndexTypeAlias · 0.92
GetLoraMethod · 0.80
GetFskMethod · 0.80

Tested by 2

TestBuildLoradFunction · 0.74
TestSX1301ConfFunction · 0.68