Signed-off-by: DaneEvans <dane@goneepic.com>
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Co-authored-by: DaneEvans <dane@goneepic.com>
Co-authored-by: James Rich <2199651+jamesarich@users.noreply.github.com>
pull/2485/head
Pedro 2025-07-21 22:52:30 -03:00 zatwierdzone przez GitHub
rodzic 94187c5098
commit f1d2dacf4f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 100 dodań i 78 usunięć

Wyświetl plik

@ -26,7 +26,9 @@ import kotlin.math.floor
* hash a string into an integer using the djb2 algorithm by Dan Bernstein * hash a string into an integer using the djb2 algorithm by Dan Bernstein
* http://www.cse.yorku.ca/~oz/hash.html * http://www.cse.yorku.ca/~oz/hash.html
*/ */
private fun hash(name: String): UInt { // using UInt instead of Long to match RadioInterface.cpp results private fun hash(
name: String
): UInt { // using UInt instead of Long to match RadioInterface.cpp results
var hash = 5381u var hash = 5381u
for (c in name) { for (c in name) {
hash += (hash shl 5) + c.code.toUInt() hash += (hash shl 5) + c.code.toUInt()
@ -42,19 +44,20 @@ private val ModemPreset.bandwidth: Float
return 0f return 0f
} }
private fun LoRaConfig.bandwidth(regionInfo: RegionInfo?) = if (usePreset) { private fun LoRaConfig.bandwidth(regionInfo: RegionInfo?) =
modemPreset.bandwidth * if (regionInfo?.wideLora == true) 3.25f else 1f if (usePreset) {
} else { modemPreset.bandwidth * if (regionInfo?.wideLora == true) 3.25f else 1f
when (bandwidth) { } else {
31 -> .03125f when (bandwidth) {
62 -> .0625f 31 -> .03125f
200 -> .203125f 62 -> .0625f
400 -> .40625f 200 -> .203125f
800 -> .8125f 400 -> .40625f
1600 -> 1.6250f 800 -> .8125f
else -> bandwidth / 1000f 1600 -> 1.6250f
else -> bandwidth / 1000f
}
} }
}
val LoRaConfig.numChannels: Int val LoRaConfig.numChannels: Int
get() { get() {
@ -70,17 +73,19 @@ val LoRaConfig.numChannels: Int
return if (num > 0) num.toInt() else 1 return if (num > 0) num.toInt() else 1
} }
internal fun LoRaConfig.channelNum(primaryName: String): Int = when { internal fun LoRaConfig.channelNum(primaryName: String): Int =
channelNum != 0 -> channelNum when {
numChannels == 0 -> 0 channelNum != 0 -> channelNum
else -> (hash(primaryName) % numChannels.toUInt()).toInt() + 1 numChannels == 0 -> 0
} else -> (hash(primaryName) % numChannels.toUInt()).toInt() + 1
}
internal fun LoRaConfig.radioFreq(channelNum: Int): Float { internal fun LoRaConfig.radioFreq(channelNum: Int): Float {
if (overrideFrequency != 0f) return overrideFrequency + frequencyOffset if (overrideFrequency != 0f) return overrideFrequency + frequencyOffset
val regionInfo = RegionInfo.fromRegionCode(region) val regionInfo = RegionInfo.fromRegionCode(region)
return if (regionInfo != null) { return if (regionInfo != null) {
(regionInfo.freqStart + bandwidth(regionInfo) / 2) + (channelNum - 1) * bandwidth(regionInfo) (regionInfo.freqStart + bandwidth(regionInfo) / 2) +
(channelNum - 1) * bandwidth(regionInfo)
} else { } else {
0f 0f
} }
@ -94,8 +99,8 @@ internal fun LoRaConfig.radioFreq(channelNum: Int): Float {
* @property freqStart The starting frequency in MHz * @property freqStart The starting frequency in MHz
* @property freqEnd The ending frequency in MHz * @property freqEnd The ending frequency in MHz
* @property wideLora Whether the region uses wide Lora * @property wideLora Whether the region uses wide Lora
* * @see
* @see [LoRaWAN Regional Parameters](https://lora-alliance.org/wp-content/uploads/2020/11/lorawan_regional_parameters_v1.0.3reva_0.pdf) * [LoRaWAN Regional Parameters](https://lora-alliance.org/wp-content/uploads/2020/11/lorawan_regional_parameters_v1.0.3reva_0.pdf)
*/ */
@Suppress("MagicNumber") @Suppress("MagicNumber")
enum class RegionInfo( enum class RegionInfo(
@ -110,6 +115,7 @@ enum class RegionInfo(
/** /**
* United States * United States
*
* @see [Springer Link](https://link.springer.com/content/pdf/bbm%3A978-1-4842-4357-2%2F1.pdf) * @see [Springer Link](https://link.springer.com/content/pdf/bbm%3A978-1-4842-4357-2%2F1.pdf)
* @see [The Things Network](https://www.thethingsnetwork.org/docs/lorawan/regional-parameters/) * @see [The Things Network](https://www.thethingsnetwork.org/docs/lorawan/regional-parameters/)
*/ */
@ -121,13 +127,14 @@ enum class RegionInfo(
/** /**
* European Union 868MHz * European Union 868MHz
* *
* Special Note: * Special Note: The link above describes LoRaWAN's band plan, stating a power limit of 16 dBm.
* The link above describes LoRaWAN's band plan, stating a power limit of 16 dBm. This is their own * This is their own suggested specification, we do not need to follow it. The European Union
* suggested specification, we do not need to follow it. The European Union regulations clearly * regulations clearly state that the power limit for this frequency range is 500 mW, or 27 dBm.
* state that the power limit for this frequency range is 500 mW, or 27 dBm. It also states that * It also states that we can use interference avoidance and spectrum access techniques (such as
* we can use interference avoidance and spectrum access techniques (such as LBT + AFA) to avoid * LBT + AFA) to avoid a duty cycle. (Please refer to line P page 22 of this document.)
* a duty cycle. (Please refer to line P page 22 of this document.) *
* @see [ETSI EN 300 220-2 V3.1.1](https://www.etsi.org/deliver/etsi_en/300200_300299/30022002/03.01.01_60/en_30022002v030101p.pdf) * @see
* [ETSI EN 300 220-2 V3.1.1](https://www.etsi.org/deliver/etsi_en/300200_300299/30022002/03.01.01_60/en_30022002v030101p.pdf)
*/ */
EU_868(RegionCode.EU_868, "European Union 868MHz", 869.4f, 869.65f), EU_868(RegionCode.EU_868, "European Union 868MHz", 869.4f, 869.65f),
@ -136,6 +143,7 @@ enum class RegionInfo(
/** /**
* Japan * Japan
*
* @see [ARIB STD-T108](https://www.arib.or.jp/english/html/overview/doc/5-STD-T108v1_5-E1.pdf) * @see [ARIB STD-T108](https://www.arib.or.jp/english/html/overview/doc/5-STD-T108v1_5-E1.pdf)
* @see [Qiita](https://qiita.com/ammo0613/items/d952154f1195b64dc29f) * @see [Qiita](https://qiita.com/ammo0613/items/d952154f1195b64dc29f)
*/ */
@ -143,31 +151,38 @@ enum class RegionInfo(
/** /**
* Australia / New Zealand * Australia / New Zealand
* @see [IoT Spectrum Fact Sheet](https://www.iot.org.au/wp/wp-content/uploads/2016/12/IoTSpectrumFactSheet.pdf) *
* @see [IoT Spectrum in NZ Briefing Paper](https://iotalliance.org.nz/wp-content/uploads/sites/4/2019/05/IoT-Spectrum-in-NZ-Briefing-Paper.pdf) * @see
* [IoT Spectrum Fact Sheet](https://www.iot.org.au/wp/wp-content/uploads/2016/12/IoTSpectrumFactSheet.pdf)
* @see
* [IoT Spectrum in NZ Briefing Paper](https://iotalliance.org.nz/wp-content/uploads/sites/4/2019/05/IoT-Spectrum-in-NZ-Briefing-Paper.pdf)
*/ */
ANZ(RegionCode.ANZ, "Australia / New Zealand", 915.0f, 928.0f), ANZ(RegionCode.ANZ, "Australia / Brazil / New Zealand", 915.0f, 928.0f),
/** /**
* Korea * Korea
*
* @see [Law.go.kr](https://www.law.go.kr/LSW/admRulLsInfoP.do?admRulId=53943&efYd=0) * @see [Law.go.kr](https://www.law.go.kr/LSW/admRulLsInfoP.do?admRulId=53943&efYd=0)
* @see [LoRaWAN Regional Parameters](https://resources.lora-alliance.org/technical-specifications/rp002-1-0-4-regional-parameters) * @see
* [LoRaWAN Regional Parameters](https://resources.lora-alliance.org/technical-specifications/rp002-1-0-4-regional-parameters)
*/ */
KR(RegionCode.KR, "Korea", 920.0f, 923.0f), KR(RegionCode.KR, "Korea", 920.0f, 923.0f),
/** /**
* Taiwan, 920-925Mhz, limited to 0.5W indoor or coastal, 1.0W outdoor. * Taiwan, 920-925Mhz, limited to 0.5W indoor or coastal, 1.0W outdoor. 5.8.1 in the Low-power
* 5.8.1 in the Low-power Radio-frequency Devices Technical Regulations * Radio-frequency Devices Technical Regulations
*
* @see [NCC Taiwan](https://www.ncc.gov.tw/english/files/23070/102_5190_230703_1_doc_C.PDF) * @see [NCC Taiwan](https://www.ncc.gov.tw/english/files/23070/102_5190_230703_1_doc_C.PDF)
* @see [National Gazette](https://gazette.nat.gov.tw/egFront/e_detail.do?metaid=147283) * @see [National Gazette](https://gazette.nat.gov.tw/egFront/e_detail.do?metaid=147283)
*/ */
TW(RegionCode.TW, "Taiwan", 920.0f, 925.0f), TW(RegionCode.TW, "Taiwan", 920.0f, 925.0f),
/** /**
* Russia * Russia Note:
* Note:
* - We do LBT, so 100% is allowed. * - We do LBT, so 100% is allowed.
* @see [Digital.gov.ru](https://digital.gov.ru/uploaded/files/prilozhenie-12-k-reshenyu-gkrch-18-46-03-1.pdf) *
* @see
* [Digital.gov.ru](https://digital.gov.ru/uploaded/files/prilozhenie-12-k-reshenyu-gkrch-18-46-03-1.pdf)
*/ */
RU(RegionCode.RU, "Russia", 868.7f, 869.2f), RU(RegionCode.RU, "Russia", 868.7f, 869.2f),
@ -176,8 +191,11 @@ enum class RegionInfo(
/** /**
* New Zealand 865MHz * New Zealand 865MHz
* @see [RSM NZ](https://rrf.rsm.govt.nz/smart-web/smart/page/-smart/domain/licence/LicenceSummary.wdk?id=219752) *
* @see [IoT Spectrum in NZ Briefing Paper](https://iotalliance.org.nz/wp-content/uploads/sites/4/2019/05/IoT-Spectrum-in-NZ-Briefing-Paper.pdf) * @see
* [RSM NZ](https://rrf.rsm.govt.nz/smart-web/smart/page/-smart/domain/licence/LicenceSummary.wdk?id=219752)
* @see
* [IoT Spectrum in NZ Briefing Paper](https://iotalliance.org.nz/wp-content/uploads/sites/4/2019/05/IoT-Spectrum-in-NZ-Briefing-Paper.pdf)
*/ */
NZ_865(RegionCode.NZ_865, "New Zealand 865MHz", 864.0f, 868.0f), NZ_865(RegionCode.NZ_865, "New Zealand 865MHz", 864.0f, 868.0f),
@ -185,60 +203,65 @@ enum class RegionInfo(
TH(RegionCode.TH, "Thailand", 920.0f, 925.0f), TH(RegionCode.TH, "Thailand", 920.0f, 925.0f),
/** /**
* Ukraine 433MHz * Ukraine 433MHz 433,05-434,7 Mhz 10 mW
* 433,05-434,7 Mhz 10 mW *
* @see [NKZRZI](https://nkrzi.gov.ua/images/upload/256/5810/PDF_UUZ_19_01_2016.pdf) * @see [NKZRZI](https://nkrzi.gov.ua/images/upload/256/5810/PDF_UUZ_19_01_2016.pdf)
*/ */
UA_433(RegionCode.UA_433, "Ukraine 433MHz", 433.0f, 434.7f), UA_433(RegionCode.UA_433, "Ukraine 433MHz", 433.0f, 434.7f),
/** /**
* Ukraine 868MHz * Ukraine 868MHz 868,0-868,6 Mhz 25 mW
* 868,0-868,6 Mhz 25 mW *
* @see [NKZRZI](https://nkrzi.gov.ua/images/upload/256/5810/PDF_UUZ_19_01_2016.pdf) * @see [NKZRZI](https://nkrzi.gov.ua/images/upload/256/5810/PDF_UUZ_19_01_2016.pdf)
*/ */
UA_868(RegionCode.UA_868, "Ukraine 868MHz", 868.0f, 868.6f), UA_868(RegionCode.UA_868, "Ukraine 868MHz", 868.0f, 868.6f),
/** /**
* Malaysia 433MHz * Malaysia 433MHz 433 - 435 MHz at 100mW, no restrictions.
* 433 - 435 MHz at 100mW, no restrictions. *
* @see [MCMC](https://www.mcmc.gov.my/skmmgovmy/media/General/pdf/Short-Range-Devices-Specification.pdf) * @see
* [MCMC](https://www.mcmc.gov.my/skmmgovmy/media/General/pdf/Short-Range-Devices-Specification.pdf)
*/ */
MY_433(RegionCode.MY_433, "Malaysia 433MHz", 433.0f, 435.0f), MY_433(RegionCode.MY_433, "Malaysia 433MHz", 433.0f, 435.0f),
/** /**
* Malaysia 919MHz * Malaysia 919MHz 919 - 923 Mhz at 500mW, no restrictions. 923 - 924 MHz at 500mW with 1% duty
* 919 - 923 Mhz at 500mW, no restrictions. * cycle OR frequency hopping. Frequency hopping is used for 919 - 923 MHz.
* 923 - 924 MHz at 500mW with 1% duty cycle OR frequency hopping. *
* Frequency hopping is used for 919 - 923 MHz. * @see
* @see [MCMC](https://www.mcmc.gov.my/skmmgovmy/media/General/pdf/Short-Range-Devices-Specification.pdf) * [MCMC](https://www.mcmc.gov.my/skmmgovmy/media/General/pdf/Short-Range-Devices-Specification.pdf)
*/ */
MY_919(RegionCode.MY_919, "Malaysia 919MHz", 919.0f, 924.0f), MY_919(RegionCode.MY_919, "Malaysia 919MHz", 919.0f, 924.0f),
/** /**
* Singapore 923MHz * Singapore 923MHz SG_923 Band 30d: 917 - 925 MHz at 100mW, no restrictions.
* SG_923 Band 30d: 917 - 925 MHz at 100mW, no restrictions. *
* @see [IMDA](https://www.imda.gov.sg/-/media/imda/files/regulation-licensing-and-consultations/ict-standards/telecommunication-standards/radio-comms/imdatssrd.pdf) * @see
* [IMDA](https://www.imda.gov.sg/-/media/imda/files/regulation-licensing-and-consultations/ict-standards/telecommunication-standards/radio-comms/imdatssrd.pdf)
*/ */
SG_923(RegionCode.SG_923, "Singapore 923MHz", 917.0f, 925.0f), SG_923(RegionCode.SG_923, "Singapore 923MHz", 917.0f, 925.0f),
/** /**
* Philippines 433MHz * Philippines 433MHz 433 - 434.7 MHz <10 mW erp, NTC approved device required
* 433 - 434.7 MHz <10 mW erp, NTC approved device required *
* @see [Firmware Issue #4948](https://github.com/meshtastic/firmware/issues/4948#issuecomment-2394926135) * @see
* [Firmware Issue #4948](https://github.com/meshtastic/firmware/issues/4948#issuecomment-2394926135)
*/ */
PH_433(RegionCode.PH_433, "Philippines 433MHz", 433.0f, 434.7f), PH_433(RegionCode.PH_433, "Philippines 433MHz", 433.0f, 434.7f),
/** /**
* Philippines 868MHz * Philippines 868MHz 868 - 869.4 MHz <25 mW erp, NTC approved device required
* 868 - 869.4 MHz <25 mW erp, NTC approved device required *
* @see [Firmware Issue #4948](https://github.com/meshtastic/firmware/issues/4948#issuecomment-2394926135) * @see
* [Firmware Issue #4948](https://github.com/meshtastic/firmware/issues/4948#issuecomment-2394926135)
*/ */
PH_868(RegionCode.PH_868, "Philippines 868MHz", 868.0f, 869.4f), PH_868(RegionCode.PH_868, "Philippines 868MHz", 868.0f, 869.4f),
/** /**
* Philippines 915MHz * Philippines 915MHz 915 - 918 MHz <250 mW EIRP, no external antenna allowed
* 915 - 918 MHz <250 mW EIRP, no external antenna allowed *
* @see [Firmware Issue #4948](https://github.com/meshtastic/firmware/issues/4948#issuecomment-2394926135) * @see
* [Firmware Issue #4948](https://github.com/meshtastic/firmware/issues/4948#issuecomment-2394926135)
*/ */
PH_915(RegionCode.PH_915, "Philippines 915MHz", 915.0f, 918.0f), PH_915(RegionCode.PH_915, "Philippines 915MHz", 915.0f, 918.0f),
@ -246,38 +269,36 @@ enum class RegionInfo(
LORA_24(RegionCode.LORA_24, "2.4 GHz", 2400.0f, 2483.5f, wideLora = true), LORA_24(RegionCode.LORA_24, "2.4 GHz", 2400.0f, 2483.5f, wideLora = true),
/** /**
* Australia / New Zealand 433MHz * Australia / New Zealand 433MHz 433.05 - 434.79 MHz, 25mW EIRP max, No duty cycle restrictions
* 433.05 - 434.79 MHz, 25mW EIRP max, No duty cycle restrictions *
* @see [ACMA](https://www.acma.gov.au/licences/low-interference-potential-devices-lipd-class-licence) * @see
* [ACMA](https://www.acma.gov.au/licences/low-interference-potential-devices-lipd-class-licence)
* @see [NZ Gazette](https://gazette.govt.nz/notice/id/2022-go3100) * @see [NZ Gazette](https://gazette.govt.nz/notice/id/2022-go3100)
*/ */
ANZ_433(RegionCode.ANZ_433, "Australia / New Zealand 433MHz", 433.05f, 434.79f), ANZ_433(RegionCode.ANZ_433, "Australia / New Zealand 433MHz", 433.05f, 434.79f),
/** /**
* Kazakhstan 433MHz * Kazakhstan 433MHz 433.075 - 434.775 MHz <10 mW EIRP, Low Powered Devices (LPD)
* 433.075 - 434.775 MHz <10 mW EIRP, Low Powered Devices (LPD) *
* @see [Firmware Issue #7204](https://github.com/meshtastic/firmware/issues/7204) * @see [Firmware Issue #7204](https://github.com/meshtastic/firmware/issues/7204)
*/ */
KZ_433(RegionCode.KZ_433, "Kazakhstan 433MHz", 433.075f, 434.775f), KZ_433(RegionCode.KZ_433, "Kazakhstan 433MHz", 433.075f, 434.775f),
/** /**
* Kazakhstan 863MHz * Kazakhstan 863MHz 863 - 868 MHz <25 mW EIRP, 500kHz channels allowed, must not be used at
* 863 - 868 MHz <25 mW EIRP, 500kHz channels allowed, must not be used at airfields * airfields
*
* @see [Firmware Issue #7204](https://github.com/meshtastic/firmware/issues/7204) * @see [Firmware Issue #7204](https://github.com/meshtastic/firmware/issues/7204)
*/ */
KZ_863(RegionCode.KZ_863, "Kazakhstan 863MHz", 863.0f, 868.0f, wideLora = true); KZ_863(RegionCode.KZ_863, "Kazakhstan 863MHz", 863.0f, 868.0f, wideLora = true);
companion object { companion object {
fun fromRegionCode(regionCode: RegionCode): RegionInfo? { fun fromRegionCode(regionCode: RegionCode): RegionInfo? =
return entries.find { it.regionCode == regionCode } entries.find { it.regionCode == regionCode }
}
} }
} }
enum class ChannelOption( enum class ChannelOption(val modemPreset: ModemPreset, val bandwidth: Float) {
val modemPreset: ModemPreset,
val bandwidth: Float,
) {
SHORT_TURBO(ModemPreset.SHORT_TURBO, bandwidth = .500f), SHORT_TURBO(ModemPreset.SHORT_TURBO, bandwidth = .500f),
SHORT_FAST(ModemPreset.SHORT_FAST, .250f), SHORT_FAST(ModemPreset.SHORT_FAST, .250f),
SHORT_SLOW(ModemPreset.SHORT_SLOW, .250f), SHORT_SLOW(ModemPreset.SHORT_SLOW, .250f),

Wyświetl plik

@ -14,3 +14,4 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */