tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/lora/lorawan/region/us915.go (about) 1 package region 2 3 import "tinygo.org/x/drivers/lora" 4 5 const ( 6 US915_DEFAULT_PREAMBLE_LEN = 8 7 US915_DEFAULT_TX_POWER_DBM = 20 8 US915_FREQUENCY_INCREMENT_DR_0 = 200000 // only for 125 kHz Bandwidth 9 US915_FREQUENCY_INCREMENT_DR_4 = 1600000 // only for 500 kHz Bandwidth 10 ) 11 12 type ChannelUS struct { 13 channel 14 } 15 16 func (c *ChannelUS) Next() bool { 17 switch c.Bandwidth() { 18 case lora.Bandwidth_125_0: 19 freq, ok := stepFrequency125(c.frequency) 20 if ok { 21 c.frequency = freq 22 } else { 23 c.frequency = lora.Mhz_903_0 24 c.bandwidth = lora.Bandwidth_500_0 25 } 26 case lora.Bandwidth_500_0: 27 freq, ok := stepFrequency500(c.frequency) 28 if ok { 29 c.frequency = freq 30 } else { 31 // there are no more frequencies to check after sweeping all 8 500 kHz channels 32 return false 33 } 34 } 35 36 return true 37 } 38 39 func stepFrequency125(freq uint32) (uint32, bool) { 40 f := freq + US915_FREQUENCY_INCREMENT_DR_0 41 if f >= lora.MHZ_915_0 { 42 return 0, false 43 } 44 45 return f, true 46 } 47 48 func stepFrequency500(freq uint32) (uint32, bool) { 49 f := freq + US915_FREQUENCY_INCREMENT_DR_4 50 if f >= lora.MHZ_915_0 { 51 return 0, false 52 } 53 54 return f, true 55 } 56 57 type SettingsUS915 struct { 58 settings 59 } 60 61 func US915() *SettingsUS915 { 62 return &SettingsUS915{settings: settings{ 63 joinRequestChannel: &ChannelUS{channel: channel{lora.MHz_902_3, 64 lora.Bandwidth_125_0, 65 lora.SpreadingFactor10, 66 lora.CodingRate4_5, 67 US915_DEFAULT_PREAMBLE_LEN, 68 US915_DEFAULT_TX_POWER_DBM}}, 69 joinAcceptChannel: &ChannelUS{channel: channel{0, 70 lora.Bandwidth_500_0, 71 lora.SpreadingFactor9, 72 lora.CodingRate4_5, 73 US915_DEFAULT_PREAMBLE_LEN, 74 US915_DEFAULT_TX_POWER_DBM}}, 75 uplinkChannel: &ChannelUS{channel: channel{lora.Mhz_903_0, 76 lora.Bandwidth_500_0, 77 lora.SpreadingFactor9, 78 lora.CodingRate4_5, 79 US915_DEFAULT_PREAMBLE_LEN, 80 US915_DEFAULT_TX_POWER_DBM}}, 81 }} 82 }