LoRaWAN MAC layer implementation

Dependents:   LoRa LoRa

Fork of LoRaWAN-lib by Semtech

Revision:
4:28021ec4f3ae
Parent:
3:b9d87593a8ae
diff -r b9d87593a8ae -r 28021ec4f3ae LoRaMac.cpp
--- a/LoRaMac.cpp	Mon Mar 14 09:09:54 2016 +0000
+++ b/LoRaMac.cpp	Mon May 09 08:06:09 2016 +0000
@@ -2324,7 +2324,7 @@
     fCtrl.Bits.Ack           = false;
     fCtrl.Bits.AdrAckReq     = false;
     fCtrl.Bits.Adr           = AdrCtrlOn;
-
+    
     // Prepare the frame
     status = PrepareFrame( macHdr, &fCtrl, fPort, fBuffer, fBufferSize );
 
@@ -2338,7 +2338,7 @@
     McpsConfirm.NbRetries = 0;
     McpsConfirm.AckReceived = false;
     McpsConfirm.UpLinkCounter = UpLinkCounter;
-
+    
     status = ScheduleTx( );
 
     return status;
@@ -2374,10 +2374,12 @@
     if( dutyCycleTimeOff == 0 )
     {
         // Try to send now
+        printf("frame sent right away .. \r\n");
         return SendFrameOnChannel( Channels[Channel] );
     }
     else
     {
+        printf("frame was scheduled .. \r\n");
         // Send later - prepare timer
         LoRaMacState |= MAC_TX_DELAYED;
         TimerSetValue( &TxDelayedTimer, dutyCycleTimeOff );
@@ -2443,12 +2445,10 @@
             }
 
             fCtrl->Bits.AdrAckReq = AdrNextDr( fCtrl->Bits.Adr, true, &ChannelsDatarate );
-
             if( ValidatePayloadLength( fBufferSize, ChannelsDatarate, MacCommandsBufferIndex ) == false )
             {
                 return LORAMAC_STATUS_LENGTH_ERROR;
             }
-
             RxWindow1Delay = ReceiveDelay1 - RADIO_WAKEUP_TIME;
             RxWindow2Delay = ReceiveDelay2 - RADIO_WAKEUP_TIME;
 
@@ -2473,7 +2473,6 @@
                 if( ( MacCommandsBufferIndex <= LORA_MAC_COMMAND_MAX_LENGTH ) && ( MacCommandsInNextTx == true ) )
                 {
                     fCtrl->Bits.FOptsLen += MacCommandsBufferIndex;
-
                     // Update FCtrl field with new value of OptionsLength
                     LoRaMacBuffer[0x05] = fCtrl->Value;
                     for( i = 0; i < MacCommandsBufferIndex; i++ )
@@ -2493,7 +2492,6 @@
             }
             MacCommandsInNextTx = false;
             MacCommandsBufferIndex = 0;
-
             if( ( payload != NULL ) && ( payloadSize > 0 ) )
             {
                 LoRaMacBuffer[pktHeaderLen++] = framePort;
@@ -2516,9 +2514,7 @@
             LoRaMacBuffer[LoRaMacBufferPktLen + 1] = ( mic >> 8 ) & 0xFF;
             LoRaMacBuffer[LoRaMacBufferPktLen + 2] = ( mic >> 16 ) & 0xFF;
             LoRaMacBuffer[LoRaMacBufferPktLen + 3] = ( mic >> 24 ) & 0xFF;
-
             LoRaMacBufferPktLen += LORAMAC_MFR_LEN;
-
             break;
         case FRAME_TYPE_PROPRIETARY:
             if( ( fBuffer != NULL ) && ( fBufferSize > 0 ) )