Skip to content

Commit 98e3662

Browse files
author
Daniel Jaeckle
committed
Issue(#468): Fix for resetting MAC commands buffer on any downlink
1 parent 8ff45c7 commit 98e3662

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

src/mac/LoRaMac.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,15 @@ static LoRaMacStatus_t SecureFrame( uint8_t txDr, uint8_t txCh );
555555
*/
556556
static void CalculateBackOff( uint8_t channel );
557557

558+
/*
559+
* \brief Function to remove pending MAC commands
560+
*
561+
* \param [IN] rxSlot The RX slot on which the frame was received
562+
* \param [IN] fCtrl The frame control field of the received frame
563+
* \param [IN] request The request type
564+
*/
565+
static void RemoveMacCommands( LoRaMacRxSlot_t rxSlot, LoRaMacFrameCtrl_t fCtrl, Mcps_t request );
566+
558567
/*!
559568
* \brief LoRaMAC layer prepared frame buffer transmission with channel specification
560569
*
@@ -1164,19 +1173,7 @@ static void ProcessRadioRxDone( void )
11641173
return;
11651174
}
11661175

1167-
// Remove all sticky MAC commands answers since we can assume
1168-
// that they have been received by the server.
1169-
if( MacCtx.McpsConfirm.McpsRequest == MCPS_CONFIRMED )
1170-
{
1171-
if( macMsgData.FHDR.FCtrl.Bits.Ack == 1 )
1172-
{ // For confirmed uplinks only if we have received an ACK.
1173-
LoRaMacCommandsRemoveStickyAnsCmds( );
1174-
}
1175-
}
1176-
else
1177-
{
1178-
LoRaMacCommandsRemoveStickyAnsCmds( );
1179-
}
1176+
RemoveMacCommands( MacCtx.McpsIndication.RxSlot, macMsgData.FHDR.FCtrl, MacCtx.McpsConfirm.McpsRequest );
11801177

11811178
switch( fType )
11821179
{
@@ -2371,6 +2368,27 @@ static void CalculateBackOff( uint8_t channel )
23712368
MacCtx.AggregatedTimeOff = ( MacCtx.TxTimeOnAir * MacCtx.NvmCtx->AggregatedDCycle - MacCtx.TxTimeOnAir );
23722369
}
23732370

2371+
static void RemoveMacCommands( LoRaMacRxSlot_t rxSlot, LoRaMacFrameCtrl_t fCtrl, Mcps_t request )
2372+
{
2373+
if( rxSlot == RX_SLOT_WIN_1 || rxSlot == RX_SLOT_WIN_2 )
2374+
{
2375+
// Remove all sticky MAC commands answers since we can assume
2376+
// that they have been received by the server.
2377+
if( request == MCPS_CONFIRMED )
2378+
{
2379+
if( fCtrl.Bits.Ack == 1 )
2380+
{ // For confirmed uplinks only if we have received an ACK.
2381+
LoRaMacCommandsRemoveStickyAnsCmds( );
2382+
}
2383+
}
2384+
else
2385+
{
2386+
LoRaMacCommandsRemoveStickyAnsCmds( );
2387+
}
2388+
}
2389+
}
2390+
2391+
23742392
static void ResetMacParameters( void )
23752393
{
23762394
MacCtx.NvmCtx->NetworkActivation = ACTIVATION_TYPE_NONE;

0 commit comments

Comments
 (0)