Skip to content

Commit dad8b8a

Browse files
committed
Added LoRaMacMlmeRequest return value handling.
1 parent 5865432 commit dad8b8a

File tree

18 files changed

+396
-126
lines changed

18 files changed

+396
-126
lines changed

src/apps/LoRaMac/classA/LoRaMote/main.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,14 @@ static void McpsIndication( McpsIndication_t *mcpsIndication )
631631
mlmeReq.Req.Join.AppKey = AppKey;
632632
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
633633

634-
LoRaMacMlmeRequest( &mlmeReq );
635-
DeviceState = DEVICE_STATE_SLEEP;
634+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
635+
{
636+
DeviceState = DEVICE_STATE_SLEEP;
637+
}
638+
else
639+
{
640+
DeviceState = DEVICE_STATE_CYCLE;
641+
}
636642
}
637643
break;
638644
case 7: // (x)
@@ -698,8 +704,14 @@ static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
698704
mlmeReq.Req.Join.AppKey = AppKey;
699705
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
700706

701-
LoRaMacMlmeRequest( &mlmeReq );
702-
DeviceState = DEVICE_STATE_SLEEP;
707+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
708+
{
709+
DeviceState = DEVICE_STATE_SLEEP;
710+
}
711+
else
712+
{
713+
DeviceState = DEVICE_STATE_CYCLE;
714+
}
703715
}
704716
break;
705717
}
@@ -807,11 +819,14 @@ int main( void )
807819
mlmeReq.Req.Join.AppKey = AppKey;
808820
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
809821

810-
if( NextTx == true )
822+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
811823
{
812-
LoRaMacMlmeRequest( &mlmeReq );
824+
DeviceState = DEVICE_STATE_SLEEP;
825+
}
826+
else
827+
{
828+
DeviceState = DEVICE_STATE_CYCLE;
813829
}
814-
DeviceState = DEVICE_STATE_SLEEP;
815830
#else
816831
// Choose a random device address if not already defined in Commissioning.h
817832
if( DevAddr == 0 )

src/apps/LoRaMac/classA/MoteII/main.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,14 @@ static void McpsIndication( McpsIndication_t *mcpsIndication )
681681
mlmeReq.Req.Join.AppKey = AppSettings.AppKey;
682682
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
683683

684-
LoRaMacMlmeRequest( &mlmeReq );
685-
DeviceState = DEVICE_STATE_SLEEP;
684+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
685+
{
686+
DeviceState = DEVICE_STATE_SLEEP;
687+
}
688+
else
689+
{
690+
DeviceState = DEVICE_STATE_CYCLE;
691+
}
686692
}
687693
break;
688694
case 7: // (x)
@@ -750,8 +756,14 @@ static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
750756
mlmeReq.Req.Join.AppKey = AppSettings.AppKey;
751757
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
752758

753-
LoRaMacMlmeRequest( &mlmeReq );
754-
DeviceState = DEVICE_STATE_SLEEP;
759+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
760+
{
761+
DeviceState = DEVICE_STATE_SLEEP;
762+
}
763+
else
764+
{
765+
DeviceState = DEVICE_STATE_CYCLE;
766+
}
755767
}
756768
break;
757769
}
@@ -902,11 +914,14 @@ int main( void )
902914
mlmeReq.Req.Join.AppKey = AppSettings.AppKey;
903915
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
904916

905-
if( NextTx == true )
917+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
906918
{
907-
LoRaMacMlmeRequest( &mlmeReq );
919+
DeviceState = DEVICE_STATE_SLEEP;
920+
}
921+
else
922+
{
923+
DeviceState = DEVICE_STATE_CYCLE;
908924
}
909-
DeviceState = DEVICE_STATE_SLEEP;
910925
#else
911926
// Choose a random device address if not already defined in Commissioning.h
912927
if( AppSettings.DevAddr == 0 )

src/apps/LoRaMac/classA/NAMote72/main.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,14 @@ static void McpsIndication( McpsIndication_t *mcpsIndication )
649649
mlmeReq.Req.Join.AppKey = AppKey;
650650
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
651651

652-
LoRaMacMlmeRequest( &mlmeReq );
653-
DeviceState = DEVICE_STATE_SLEEP;
652+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
653+
{
654+
DeviceState = DEVICE_STATE_SLEEP;
655+
}
656+
else
657+
{
658+
DeviceState = DEVICE_STATE_CYCLE;
659+
}
654660
}
655661
break;
656662
case 7: // (x)
@@ -716,8 +722,14 @@ static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
716722
mlmeReq.Req.Join.AppKey = AppKey;
717723
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
718724

719-
LoRaMacMlmeRequest( &mlmeReq );
720-
DeviceState = DEVICE_STATE_SLEEP;
725+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
726+
{
727+
DeviceState = DEVICE_STATE_SLEEP;
728+
}
729+
else
730+
{
731+
DeviceState = DEVICE_STATE_CYCLE;
732+
}
721733
}
722734
break;
723735
}
@@ -825,11 +837,14 @@ int main( void )
825837
mlmeReq.Req.Join.AppKey = AppKey;
826838
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
827839

828-
if( NextTx == true )
840+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
829841
{
830-
LoRaMacMlmeRequest( &mlmeReq );
842+
DeviceState = DEVICE_STATE_SLEEP;
843+
}
844+
else
845+
{
846+
DeviceState = DEVICE_STATE_CYCLE;
831847
}
832-
DeviceState = DEVICE_STATE_SLEEP;
833848
#else
834849
// Choose a random device address if not already defined in Commissioning.h
835850
if( DevAddr == 0 )

src/apps/LoRaMac/classA/SAML21/main.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,14 @@ static void McpsIndication( McpsIndication_t *mcpsIndication )
558558
mlmeReq.Req.Join.AppKey = AppKey;
559559
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
560560

561-
LoRaMacMlmeRequest( &mlmeReq );
562-
DeviceState = DEVICE_STATE_SLEEP;
561+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
562+
{
563+
DeviceState = DEVICE_STATE_SLEEP;
564+
}
565+
else
566+
{
567+
DeviceState = DEVICE_STATE_CYCLE;
568+
}
563569
}
564570
break;
565571
case 7: // (x)
@@ -625,8 +631,14 @@ static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
625631
mlmeReq.Req.Join.AppKey = AppKey;
626632
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
627633

628-
LoRaMacMlmeRequest( &mlmeReq );
629-
DeviceState = DEVICE_STATE_SLEEP;
634+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
635+
{
636+
DeviceState = DEVICE_STATE_SLEEP;
637+
}
638+
else
639+
{
640+
DeviceState = DEVICE_STATE_CYCLE;
641+
}
630642
}
631643
break;
632644
}
@@ -752,11 +764,14 @@ int main( void )
752764
mlmeReq.Req.Join.AppKey = AppKey;
753765
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
754766

755-
if( NextTx == true )
767+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
756768
{
757-
LoRaMacMlmeRequest( &mlmeReq );
769+
DeviceState = DEVICE_STATE_SLEEP;
770+
}
771+
else
772+
{
773+
DeviceState = DEVICE_STATE_CYCLE;
758774
}
759-
DeviceState = DEVICE_STATE_SLEEP;
760775
#else
761776
// Choose a random device address if not already defined in Commissioning.h
762777
if( DevAddr == 0 )

src/apps/LoRaMac/classA/SK-iM880A/main.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,14 @@ static void McpsIndication( McpsIndication_t *mcpsIndication )
569569
mlmeReq.Req.Join.AppKey = AppKey;
570570
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
571571

572-
LoRaMacMlmeRequest( &mlmeReq );
573-
DeviceState = DEVICE_STATE_SLEEP;
572+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
573+
{
574+
DeviceState = DEVICE_STATE_SLEEP;
575+
}
576+
else
577+
{
578+
DeviceState = DEVICE_STATE_CYCLE;
579+
}
574580
}
575581
break;
576582
case 7: // (x)
@@ -636,8 +642,14 @@ static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
636642
mlmeReq.Req.Join.AppKey = AppKey;
637643
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
638644

639-
LoRaMacMlmeRequest( &mlmeReq );
640-
DeviceState = DEVICE_STATE_SLEEP;
645+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
646+
{
647+
DeviceState = DEVICE_STATE_SLEEP;
648+
}
649+
else
650+
{
651+
DeviceState = DEVICE_STATE_CYCLE;
652+
}
641653
}
642654
break;
643655
}
@@ -745,11 +757,14 @@ int main( void )
745757
mlmeReq.Req.Join.AppKey = AppKey;
746758
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
747759

748-
if( NextTx == true )
760+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
749761
{
750-
LoRaMacMlmeRequest( &mlmeReq );
762+
DeviceState = DEVICE_STATE_SLEEP;
763+
}
764+
else
765+
{
766+
DeviceState = DEVICE_STATE_CYCLE;
751767
}
752-
DeviceState = DEVICE_STATE_SLEEP;
753768
#else
754769
// Choose a random device address if not already defined in Commissioning.h
755770
if( DevAddr == 0 )

src/apps/LoRaMac/classA/SensorNode/main.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,14 @@ static void McpsIndication( McpsIndication_t *mcpsIndication )
649649
mlmeReq.Req.Join.AppKey = AppKey;
650650
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
651651

652-
LoRaMacMlmeRequest( &mlmeReq );
653-
DeviceState = DEVICE_STATE_SLEEP;
652+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
653+
{
654+
DeviceState = DEVICE_STATE_SLEEP;
655+
}
656+
else
657+
{
658+
DeviceState = DEVICE_STATE_CYCLE;
659+
}
654660
}
655661
break;
656662
case 7: // (x)
@@ -716,8 +722,14 @@ static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
716722
mlmeReq.Req.Join.AppKey = AppKey;
717723
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
718724

719-
LoRaMacMlmeRequest( &mlmeReq );
720-
DeviceState = DEVICE_STATE_SLEEP;
725+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
726+
{
727+
DeviceState = DEVICE_STATE_SLEEP;
728+
}
729+
else
730+
{
731+
DeviceState = DEVICE_STATE_CYCLE;
732+
}
721733
}
722734
break;
723735
}
@@ -828,11 +840,14 @@ int main( void )
828840
mlmeReq.Req.Join.AppKey = AppKey;
829841
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
830842

831-
if( NextTx == true )
843+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
832844
{
833-
LoRaMacMlmeRequest( &mlmeReq );
845+
DeviceState = DEVICE_STATE_SLEEP;
846+
}
847+
else
848+
{
849+
DeviceState = DEVICE_STATE_CYCLE;
834850
}
835-
DeviceState = DEVICE_STATE_SLEEP;
836851
#else
837852
// Choose a random device address if not already defined in Commissioning.h
838853
if( DevAddr == 0 )

src/apps/LoRaMac/classB/LoRaMote/main.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,14 @@ static void McpsIndication( McpsIndication_t *mcpsIndication )
631631
mlmeReq.Req.Join.AppKey = AppKey;
632632
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
633633

634-
LoRaMacMlmeRequest( &mlmeReq );
635-
DeviceState = DEVICE_STATE_SLEEP;
634+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
635+
{
636+
DeviceState = DEVICE_STATE_SLEEP;
637+
}
638+
else
639+
{
640+
DeviceState = DEVICE_STATE_CYCLE;
641+
}
636642
}
637643
break;
638644
case 7: // (x)
@@ -698,8 +704,14 @@ static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
698704
mlmeReq.Req.Join.AppKey = AppKey;
699705
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
700706

701-
LoRaMacMlmeRequest( &mlmeReq );
702-
DeviceState = DEVICE_STATE_SLEEP;
707+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
708+
{
709+
DeviceState = DEVICE_STATE_SLEEP;
710+
}
711+
else
712+
{
713+
DeviceState = DEVICE_STATE_CYCLE;
714+
}
703715
}
704716
break;
705717
}
@@ -807,11 +819,14 @@ int main( void )
807819
mlmeReq.Req.Join.AppKey = AppKey;
808820
mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
809821

810-
if( NextTx == true )
822+
if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
811823
{
812-
LoRaMacMlmeRequest( &mlmeReq );
824+
DeviceState = DEVICE_STATE_SLEEP;
825+
}
826+
else
827+
{
828+
DeviceState = DEVICE_STATE_CYCLE;
813829
}
814-
DeviceState = DEVICE_STATE_SLEEP;
815830
#else
816831
// Choose a random device address if not already defined in Commissioning.h
817832
if( DevAddr == 0 )

0 commit comments

Comments
 (0)