From 49ab0f47bfadb2e137b1b564abee5d6591419830 Mon Sep 17 00:00:00 2001 From: beegee-tokyo Date: Sun, 27 Aug 2023 12:27:19 +0800 Subject: [PATCH] Add MAC counter reset function --- CHANGELOG.md | 3 +++ README.md | 2 ++ library.json | 5 ++++- library.properties | 2 +- src/mac/LoRaMac.cpp | 23 +++++++++++++++++++++++ src/mac/LoRaMac.h | 2 ++ src/mac/LoRaMacHelper.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/mac/LoRaMacHelper.h | 6 ++++++ 8 files changed, 79 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c462c22..0fcc138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Arduino library for LoRa communication with Semtech SX126x chips. It is based on # Release Notes +## V2.0.20 Add MAC parameter reset function + - Add option to reset the MAC counters + ## V2.0.19 Fix the release mess - Sorry released the wrong branch diff --git a/README.md b/README.md index ae17e3b..580f44f 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---- ## Changelog [Code releases](CHANGELOG.md) +- 2023-08-27 + - Add function to reset MAC counters - 2023-05-16 - Fix typo in RadioTimeOnAir for FSK - Improve RadioTimeOnAir for FSK, thanks to _**@mikedupi**_ diff --git a/library.json b/library.json index b9000a4..c170f28 100644 --- a/library.json +++ b/library.json @@ -1,10 +1,13 @@ { "name": "SX126x-Arduino", - "version": "2.0.19", + "version": "2.0.20", "keywords": [ "lora", "Semtech", "SX126x", + "nRF52", + "ESP32", + "RP2040", "RAK4630", "RAK11200", "RAK11300", diff --git a/library.properties b/library.properties index 5b55ed9..810588d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SX126x-Arduino -version=2.0.19 +version=2.0.20 author=Bernd Giesecke maintainer=Bernd Giesecke sentence=Arduino library to use Semtech SX126x LoRa chips and modules to communicate diff --git a/src/mac/LoRaMac.cpp b/src/mac/LoRaMac.cpp index 67c8ce7..57b7dca 100644 --- a/src/mac/LoRaMac.cpp +++ b/src/mac/LoRaMac.cpp @@ -2094,6 +2094,29 @@ static void CalculateBackOff(uint8_t channel) AggregatedTimeOff = AggregatedTimeOff + (TxTimeOnAir * AggregatedDCycle - TxTimeOnAir); } +void ResetMacCounters(void) +{ + + // Counters + UpLinkCounter = 0; + DownLinkCounter = 0; + AdrAckCounter = 0; + + ChannelsNbRepCounter = 0; + + AckTimeoutRetries = 1; + AckTimeoutRetriesCounter = 1; + AckTimeoutRetry = false; + + MaxDCycle = 0; + AggregatedDCycle = 1; + + MacCommandsBufferIndex = 0; + MacCommandsBufferToRepeatIndex = 0; + + IsRxWindowsEnabled = true; +} + static void ResetMacParameters(void) { // Counters diff --git a/src/mac/LoRaMac.h b/src/mac/LoRaMac.h index 9885500..8787913 100644 --- a/src/mac/LoRaMac.h +++ b/src/mac/LoRaMac.h @@ -1958,4 +1958,6 @@ LoRaMacStatus_t LoRaMacMlmeRequest(MlmeReq_t *mlmeRequest); */ LoRaMacStatus_t LoRaMacMcpsRequest(McpsReq_t *mcpsRequest); +void ResetMacCounters(void); + #endif // __LORAMAC_H__ diff --git a/src/mac/LoRaMacHelper.cpp b/src/mac/LoRaMacHelper.cpp index 77cd458..7a14b3c 100644 --- a/src/mac/LoRaMacHelper.cpp +++ b/src/mac/LoRaMacHelper.cpp @@ -1114,6 +1114,11 @@ lmh_error_status lmh_class_request(DeviceClass_t newClass) return Errorstatus; } +/** + * @brief Get the device class + * + * @param currentClass 0 or 2 for Class A or C (Class B is not supported) + */ void lmh_class_get(DeviceClass_t *currentClass) { MibRequestConfirm_t mibReq; @@ -1124,16 +1129,35 @@ void lmh_class_get(DeviceClass_t *currentClass) *currentClass = mibReq.Param.Class; } +/** + * @brief Get device LoRaWAN address + * + * @return uint32_t device address + */ uint32_t lmh_getDevAddr(void) { return LoRaMacGetOTAADevId(); } +/** + * @brief Set the AS923 frequency variant + * + * @param version 1, 2, 3 or 4 for AS923-1 (default), AS923-2, AS923-3 or AS923-4 + * @return true + * @return false + */ bool lmh_setAS923Version(uint8_t version) { return RegionAS923SetVersion(version); } +/** + * @brief Set number of retries for confirmed packages + * + * @param retries number of retries + * @return true if success + * @return false if failed (number of retries to small or large) + */ bool lmh_setConfRetries(uint8_t retries) { if ((retries > 0) && (retries < 8)) @@ -1144,7 +1168,21 @@ bool lmh_setConfRetries(uint8_t retries) return false; } +/** + * @brief Get number of retries + * + * @return uint8_t number of retries + */ uint8_t lmh_getConfRetries(void) { return max_ack_retries; +} + +/** + * @brief Reset MAC parameters + * + */ +void lmh_reset_mac(void) +{ + ResetMacCounters(); } \ No newline at end of file diff --git a/src/mac/LoRaMacHelper.h b/src/mac/LoRaMacHelper.h index dfece3d..08268c6 100644 --- a/src/mac/LoRaMacHelper.h +++ b/src/mac/LoRaMacHelper.h @@ -308,4 +308,10 @@ bool lmh_setConfRetries(uint8_t retries); */ uint8_t lmh_getConfRetries(void); +/** + * @brief Reset MAC counters + * + */ +void lmh_reset_mac(void); + #endif