Skip to content

Commit be24a23

Browse files
committed
Fix GitHub issue #190
Update implementation to resolve the NbTrials mixture between join and other frames.
1 parent 7775117 commit be24a23

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

src/mac/LoRaMac.c

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,51 +1499,58 @@ static void OnMacStateCheckTimerEvent( void )
14991499

15001500
if( ( NodeAckRequested == false ) && ( txTimeout == false ) )
15011501
{
1502-
if( LoRaMacFlags.Bits.MlmeReq == 1 )
1502+
if( ( LoRaMacFlags.Bits.MlmeReq == 1 ) || ( ( LoRaMacFlags.Bits.McpsReq == 1 ) ) )
15031503
{
1504-
if( MlmeConfirm.MlmeRequest == MLME_JOIN )
1505-
{
1504+
if( ( LoRaMacFlags.Bits.MlmeReq == 1 ) && ( MlmeConfirm.MlmeRequest == MLME_JOIN ) )
1505+
{// Procedure for the join request
1506+
MlmeConfirm.NbRetries = JoinRequestTrials;
1507+
15061508
if( MlmeConfirm.Status == LORAMAC_EVENT_INFO_STATUS_OK )
1507-
{
1508-
// The UpLinkCounter must be set to 0
1509+
{// Node joined successfully
15091510
UpLinkCounter = 0;
1510-
LoRaMacParams.ChannelsNbRep = JoinRequestTrials;
1511+
ChannelsNbRepCounter = 0;
1512+
LoRaMacState &= ~LORAMAC_TX_RUNNING;
15111513
}
15121514
else
15131515
{
1514-
LoRaMacParams.ChannelsNbRep = MaxJoinRequestTrials;
1516+
if( ( JoinRequestTrials >= MaxJoinRequestTrials ) )
1517+
{
1518+
LoRaMacState &= ~LORAMAC_TX_RUNNING;
1519+
}
1520+
else
1521+
{
1522+
LoRaMacFlags.Bits.MacDone = 0;
1523+
// Sends the same frame again
1524+
OnTxDelayedTimerEvent( );
1525+
}
15151526
}
1516-
1517-
// Use join counter settings for the next condition
1518-
// Counter variables will be reset with every new join trial
1519-
ChannelsNbRepCounter = JoinRequestTrials;
15201527
}
1521-
}
1522-
if( ( LoRaMacFlags.Bits.MlmeReq == 1 ) || ( ( LoRaMacFlags.Bits.McpsReq == 1 ) ) )
1523-
{
1524-
if( ( ChannelsNbRepCounter >= LoRaMacParams.ChannelsNbRep ) || ( LoRaMacFlags.Bits.McpsInd == 1 ) )
1525-
{
1526-
ChannelsNbRepCounter = 0;
1527-
1528-
AdrAckCounter++;
1529-
if( IsUpLinkCounterFixed == false )
1528+
else
1529+
{// Procedure for all other frames
1530+
if( ( ChannelsNbRepCounter >= LoRaMacParams.ChannelsNbRep ) || ( LoRaMacFlags.Bits.McpsInd == 1 ) )
15301531
{
1531-
UpLinkCounter++;
1532-
}
1532+
ChannelsNbRepCounter = 0;
15331533

1534-
LoRaMacState &= ~LORAMAC_TX_RUNNING;
1535-
}
1536-
else
1537-
{
1538-
LoRaMacFlags.Bits.MacDone = 0;
1539-
// Sends the same frame again
1540-
OnTxDelayedTimerEvent( );
1534+
AdrAckCounter++;
1535+
if( IsUpLinkCounterFixed == false )
1536+
{
1537+
UpLinkCounter++;
1538+
}
1539+
1540+
LoRaMacState &= ~LORAMAC_TX_RUNNING;
1541+
}
1542+
else
1543+
{
1544+
LoRaMacFlags.Bits.MacDone = 0;
1545+
// Sends the same frame again
1546+
OnTxDelayedTimerEvent( );
1547+
}
15411548
}
15421549
}
15431550
}
15441551

15451552
if( LoRaMacFlags.Bits.McpsInd == 1 )
1546-
{
1553+
{// Procedure if we received a frame
15471554
if( ( McpsConfirm.AckReceived == true ) || ( AckTimeoutRetriesCounter > AckTimeoutRetries ) )
15481555
{
15491556
AckTimeoutRetry = false;
@@ -1559,7 +1566,7 @@ static void OnMacStateCheckTimerEvent( void )
15591566
}
15601567

15611568
if( ( AckTimeoutRetry == true ) && ( ( LoRaMacState & LORAMAC_TX_DELAYED ) == 0 ) )
1562-
{
1569+
{// Retransmissions procedure for confirmed uplinks
15631570
AckTimeoutRetry = false;
15641571
if( ( AckTimeoutRetriesCounter < AckTimeoutRetries ) && ( AckTimeoutRetriesCounter <= MAX_ACK_RETRIES ) )
15651572
{

src/mac/LoRaMac.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,10 @@ typedef struct sMlmeConfirm
10381038
* Number of gateways which received the last LinkCheckReq
10391039
*/
10401040
uint8_t NbGateways;
1041+
/*!
1042+
* Provides the number of retransmissions
1043+
*/
1044+
uint8_t NbRetries;
10411045
}MlmeConfirm_t;
10421046

10431047
/*!

0 commit comments

Comments
 (0)