lora/lorawan: refactor shared functionality for ChannelUS, etc into embedded type

named channel, do the same for RegionSettings, and then change RegionSettings to
just Settings to avoid the redundant naming.

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2023-10-17 17:46:49 +02:00
committed by Ron Evans
parent 7dd1067cc1
commit 6b79a1b386
7 changed files with 105 additions and 161 deletions
+12 -47
View File
@@ -8,71 +8,36 @@ const (
)
type ChannelEU struct {
frequency uint32
bandwidth uint8
spreadingFactor uint8
codingRate uint8
preambleLength uint16
txPowerDBm int8
channel
}
// Getter functions
func (c *ChannelEU) Frequency() uint32 { return c.frequency }
func (c *ChannelEU) Bandwidth() uint8 { return c.bandwidth }
func (c *ChannelEU) SpreadingFactor() uint8 { return c.spreadingFactor }
func (c *ChannelEU) CodingRate() uint8 { return c.codingRate }
func (c *ChannelEU) PreambleLength() uint16 { return c.preambleLength }
func (c *ChannelEU) TxPowerDBm() int8 { return c.txPowerDBm }
// Set functions
func (c *ChannelEU) SetFrequency(v uint32) { c.frequency = v }
func (c *ChannelEU) SetBandwidth(v uint8) { c.bandwidth = v }
func (c *ChannelEU) SetSpreadingFactor(v uint8) { c.spreadingFactor = v }
func (c *ChannelEU) SetCodingRate(v uint8) { c.codingRate = v }
func (c *ChannelEU) SetPreambleLength(v uint16) { c.preambleLength = v }
func (c *ChannelEU) SetTxPowerDBm(v int8) { c.txPowerDBm = v }
func (c *ChannelEU) Next() bool {
return false
}
type RegionSettingsEU868 struct {
joinRequestChannel *ChannelEU
joinAcceptChannel *ChannelEU
uplinkChannel *ChannelEU
type SettingsEU868 struct {
settings
}
func EU868() *RegionSettingsEU868 {
return &RegionSettingsEU868{
joinRequestChannel: &ChannelEU{lora.MHz_868_1,
func EU868() *SettingsEU868 {
return &SettingsEU868{settings: settings{
joinRequestChannel: &ChannelEU{channel: channel{lora.MHz_868_1,
lora.Bandwidth_125_0,
lora.SpreadingFactor9,
lora.CodingRate4_7,
EU868_DEFAULT_PREAMBLE_LEN,
EU868_DEFAULT_TX_POWER_DBM},
joinAcceptChannel: &ChannelEU{lora.MHz_868_1,
EU868_DEFAULT_TX_POWER_DBM}},
joinAcceptChannel: &ChannelEU{channel: channel{lora.MHz_868_1,
lora.Bandwidth_125_0,
lora.SpreadingFactor9,
lora.CodingRate4_7,
EU868_DEFAULT_PREAMBLE_LEN,
EU868_DEFAULT_TX_POWER_DBM},
uplinkChannel: &ChannelEU{lora.MHz_868_1,
EU868_DEFAULT_TX_POWER_DBM}},
uplinkChannel: &ChannelEU{channel: channel{lora.MHz_868_1,
lora.Bandwidth_125_0,
lora.SpreadingFactor9,
lora.CodingRate4_7,
EU868_DEFAULT_PREAMBLE_LEN,
EU868_DEFAULT_TX_POWER_DBM},
}
}
func (r *RegionSettingsEU868) JoinRequestChannel() Channel {
return r.joinRequestChannel
}
func (r *RegionSettingsEU868) JoinAcceptChannel() Channel {
return r.joinAcceptChannel
}
func (r *RegionSettingsEU868) UplinkChannel() Channel {
return r.uplinkChannel
EU868_DEFAULT_TX_POWER_DBM}},
}}
}