Skip to content

Commit

Permalink
Add MAC counter reset function
Browse files Browse the repository at this point in the history
  • Loading branch information
beegee-tokyo committed Aug 27, 2023
1 parent 73b892e commit 49ab0f4
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**_
Expand Down
5 changes: 4 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SX126x-Arduino
version=2.0.19
version=2.0.20
author=Bernd Giesecke <[email protected]>
maintainer=Bernd Giesecke <[email protected]>
sentence=Arduino library to use Semtech SX126x LoRa chips and modules to communicate
Expand Down
23 changes: 23 additions & 0 deletions src/mac/LoRaMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/mac/LoRaMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -1958,4 +1958,6 @@ LoRaMacStatus_t LoRaMacMlmeRequest(MlmeReq_t *mlmeRequest);
*/
LoRaMacStatus_t LoRaMacMcpsRequest(McpsReq_t *mcpsRequest);

void ResetMacCounters(void);

#endif // __LORAMAC_H__
38 changes: 38 additions & 0 deletions src/mac/LoRaMacHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand All @@ -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();
}
6 changes: 6 additions & 0 deletions src/mac/LoRaMacHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 49ab0f4

Please sign in to comment.