Skip to content

Commit 16e90fa

Browse files
committed
Bug fix in resetting variable MacCommandsBufferIndex
1 parent a32de9a commit 16e90fa

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/mac/LoRaMac.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,22 @@ static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t
13881388
DownLinkCounter = downLinkCounter;
13891389
}
13901390

1391+
// This must be done before parsing the payload and the MAC commands.
1392+
// We need to reset the MacCommandsBufferIndex here, since we need
1393+
// to take retransmissions and repititions into account. Error cases
1394+
// will be handled in function OnMacStateCheckTimerEvent.
1395+
if( McpsConfirm.McpsRequest == MCPS_CONFIRMED )
1396+
{
1397+
if( fCtrl.Bits.Ack == 1 )
1398+
{// Reset MacCommandsBufferIndex when we have received an ACK.
1399+
MacCommandsBufferIndex = 0;
1400+
}
1401+
}
1402+
else
1403+
{// Reset the variable if we have received any valid frame.
1404+
MacCommandsBufferIndex = 0;
1405+
}
1406+
13911407
if( ( ( size - 4 ) - appPayloadStartIndex ) > 0 )
13921408
{
13931409
port = payload[appPayloadStartIndex++];
@@ -1473,6 +1489,7 @@ static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t
14731489
}
14741490
LoRaMacFlags.Bits.McpsInd = 1;
14751491
}
1492+
LoRaMacFlags.Bits.McpsIndSkip = skipIndication;
14761493
}
14771494
else
14781495
{
@@ -1600,6 +1617,7 @@ static void OnMacStateCheckTimerEvent( void )
16001617
{
16011618
// Stop transmit cycle due to tx timeout.
16021619
LoRaMacState &= ~LORAMAC_TX_RUNNING;
1620+
MacCommandsBufferIndex = 0;
16031621
McpsConfirm.NbRetries = AckTimeoutRetriesCounter;
16041622
McpsConfirm.AckReceived = false;
16051623
McpsConfirm.TxTimeOnAir = 0;
@@ -1639,6 +1657,12 @@ static void OnMacStateCheckTimerEvent( void )
16391657
{// Procedure for all other frames
16401658
if( ( ChannelsNbRepCounter >= LoRaMacParams.ChannelsNbRep ) || ( LoRaMacFlags.Bits.McpsInd == 1 ) )
16411659
{
1660+
if( ( LoRaMacFlags.Bits.McpsInd == 0 ) && ( LoRaMacFlags.Bits.McpsIndSkip == 0 ) )
1661+
{ // Maximum repititions without downlink. Reset MacCommandsBufferIndex. Increase ADR Ack counter.
1662+
// Only process the case when the MAC did not receive a downlink.
1663+
MacCommandsBufferIndex = 0;
1664+
}
1665+
16421666
ChannelsNbRepCounter = 0;
16431667

16441668
AdrAckCounter++;
@@ -1696,6 +1720,7 @@ static void OnMacStateCheckTimerEvent( void )
16961720
// The DR is not applicable for the payload size
16971721
McpsConfirm.Status = LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR;
16981722

1723+
MacCommandsBufferIndex = 0;
16991724
LoRaMacState &= ~LORAMAC_TX_RUNNING;
17001725
NodeAckRequested = false;
17011726
McpsConfirm.AckReceived = false;
@@ -1726,6 +1751,7 @@ static void OnMacStateCheckTimerEvent( void )
17261751
#endif
17271752
LoRaMacState &= ~LORAMAC_TX_RUNNING;
17281753

1754+
MacCommandsBufferIndex = 0;
17291755
NodeAckRequested = false;
17301756
McpsConfirm.AckReceived = false;
17311757
McpsConfirm.NbRetries = AckTimeoutRetriesCounter;
@@ -1756,7 +1782,7 @@ static void OnMacStateCheckTimerEvent( void )
17561782
}
17571783

17581784
// Procedure done. Reset variables.
1759-
MacCommandsBufferIndex = 0;
1785+
LoRaMacFlags.Bits.McpsIndSkip = 0;
17601786
LoRaMacFlags.Bits.MacDone = 0;
17611787
}
17621788
else
@@ -3177,7 +3203,6 @@ LoRaMacStatus_t PrepareFrame( LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl
31773203
{
31783204
MacCommandsInNextTx = true;
31793205
}
3180-
MacCommandsBufferIndex = 0;
31813206

31823207
if( ( payload != NULL ) && ( LoRaMacTxPayloadLen > 0 ) )
31833208
{
@@ -4476,7 +4501,7 @@ static RxConfigParams_t ComputeRxWindowParameters( int8_t datarate, uint32_t rxE
44764501
rxConfigParams.Bandwidth = 2;
44774502
break;
44784503
}
4479-
4504+
44804505
#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
44814506
if( datarate == DR_7 )
44824507
{ // FSK

src/mac/LoRaMac.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,10 @@ typedef union eLoRaMacFlags_t
635635
* MCPS-Ind pending
636636
*/
637637
uint8_t McpsInd : 1;
638+
/*!
639+
* MCPS-Ind pending. Skip indication to the application layer
640+
*/
641+
uint8_t McpsIndSkip : 1;
638642
/*!
639643
* MLME-Req pending
640644
*/

0 commit comments

Comments
 (0)