Ivano Calabrese / LoRaWAN-lib-st-murata

Dependents:   DISCO-L072CZ-LRWAN1-base

Fork of LoRaWAN-lib by Semtech

Files at this revision

API Documentation at this revision

Comitter:
alphaemmeo
Date:
Mon Dec 04 14:21:26 2017 +0000
Parent:
10:1ac668ce2b15
Commit message:
base test

Changed in this revision

LoRaMac.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/LoRaMac.cpp	Wed Jul 26 01:08:23 2017 +0000
+++ b/LoRaMac.cpp	Mon Dec 04 14:21:26 2017 +0000
@@ -20,10 +20,14 @@
 #include <math.h>
 #include "board.h"
 
+#include "main.h"
+
 #include "LoRaMacCrypto.h"
 #include "LoRaMac.h"
 #include "LoRaMacTest.h"
 
+
+
 /*!
  * Maximum PHY layer payload size
  */
@@ -666,7 +670,7 @@
 /*!
  * \brief Function to be executed on Radio Tx Done event
  */
-static void OnRadioTxDone( void );
+static void OnRadioTxDone( void *radio, void *userThisPtr, void *userData );
 
 /*!
  * \brief This function prepares the MAC to abort the execution of function
@@ -677,22 +681,22 @@
 /*!
  * \brief Function to be executed on Radio Rx Done event
  */
-static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
+static void OnRadioRxDone( void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
 
 /*!
  * \brief Function executed on Radio Tx Timeout event
  */
-static void OnRadioTxTimeout( void );
+static void OnRadioTxTimeout( void *radio, void *userThisPtr, void *userData );
 
 /*!
  * \brief Function executed on Radio Rx error event
  */
-static void OnRadioRxError( void );
+static void OnRadioRxError( void *radio, void *userThisPtr, void *userData );
 
 /*!
  * \brief Function executed on Radio Rx Timeout event
  */
-static void OnRadioRxTimeout( void );
+static void OnRadioRxTimeout( void *radio, void *userThisPtr, void *userData );
 
 /*!
  * \brief Function executed on Resend Frame timer event.
@@ -1047,7 +1051,7 @@
  */
 static RxConfigParams_t ComputeRxWindowParameters( int8_t datarate, uint32_t rxError );
 
-static void OnRadioTxDone( void )
+static void OnRadioTxDone( void *radio, void *userThisPtr, void *userData )
 {
     TimerTime_t curTime = TimerGetCurrentTime( );
 
@@ -1120,7 +1124,7 @@
     TimerStart( &MacStateCheckTimer );
 }
 
-static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
+static void OnRadioRxDone( void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
 {
     LoRaMacHeader_t macHdr;
     LoRaMacFrameCtrl_t fCtrl;
@@ -1532,7 +1536,7 @@
     TimerStart( &MacStateCheckTimer );
 }
 
-static void OnRadioTxTimeout( void )
+static void OnRadioTxTimeout( void *radio, void *userThisPtr, void *userData )
 {
     if( LoRaMacDeviceClass != CLASS_C )
     {
@@ -1548,7 +1552,7 @@
     LoRaMacFlags.Bits.MacDone = 1;
 }
 
-static void OnRadioRxError( void )
+static void OnRadioRxError( void *radio, void *userThisPtr, void *userData )
 {
     if( LoRaMacDeviceClass != CLASS_C )
     {
@@ -1583,7 +1587,7 @@
     }
 }
 
-static void OnRadioRxTimeout( void )
+static void OnRadioRxTimeout( void *radio, void *userThisPtr, void *userData )
 {
     if( LoRaMacDeviceClass != CLASS_C )
     {
@@ -2852,6 +2856,7 @@
 
 LoRaMacStatus_t Send( LoRaMacHeader_t *macHdr, uint8_t fPort, void *fBuffer, uint16_t fBufferSize )
 {
+    ser->printf("[LRMAC] In to the LoRaMacStatus_t Send \n\r");
     LoRaMacFrameCtrl_t fCtrl;
     LoRaMacStatus_t status = LORAMAC_STATUS_PARAMETER_INVALID;
 
@@ -2868,26 +2873,32 @@
     // Validate status
     if( status != LORAMAC_STATUS_OK )
     {
+        ser->printf("[LRMAC] LoRaMacStatus_t Send :: status %u \n\r", status);
         return status;
     }
-
+    ser->printf("[LRMAC] LoRaMacStatus_t Send :: LORAMAC_STATUS_OK \n\r");
+    
     // Reset confirm parameters
     McpsConfirm.NbRetries = 0;
     McpsConfirm.AckReceived = false;
     McpsConfirm.UpLinkCounter = UpLinkCounter;
 
     status = ScheduleTx( );
+    
+    ser->printf("[LRMAC] LoRaMacStatus_t Send :: status %u \n\r", status);
 
     return status;
 }
 
 static LoRaMacStatus_t ScheduleTx( void )
 {
+    ser->printf("[LRMAC] LoRaMacStatus_t ScheduleTx \n\r");
     TimerTime_t dutyCycleTimeOff = 0;
 
     // Check if the device is off
     if( MaxDCycle == 255 )
     {
+        ser->printf("[LRMAC] LoRaMacStatus_t ScheduleTx :: LORAMAC_STATUS_DEVICE_OFF\n\r");
         return LORAMAC_STATUS_DEVICE_OFF;
     }
     if( MaxDCycle == 0 )
@@ -2925,6 +2936,7 @@
     {
         if( ValidatePayloadLength( LoRaMacTxPayloadLen, LoRaMacParams.ChannelsDatarate, MacCommandsBufferIndex ) == false )
         {
+            ser->printf("[LRMAC] LoRaMacStatus_t ScheduleTx :: LORAMAC_STATUS_LENGTH_ERROR\n\r");
             return LORAMAC_STATUS_LENGTH_ERROR;
         }
         RxWindow1Delay = LoRaMacParams.ReceiveDelay1 + RxWindowsParams[0].RxOffset;
@@ -2944,6 +2956,7 @@
         TimerSetValue( &TxDelayedTimer, dutyCycleTimeOff );
         TimerStart( &TxDelayedTimer );
 
+        ser->printf("[LRMAC] LoRaMacStatus_t ScheduleTx :: LORAMAC_STATUS_OK\n\r");
         return LORAMAC_STATUS_OK;
     }
 }
@@ -3100,6 +3113,7 @@
 
 LoRaMacStatus_t PrepareFrame( LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t fPort, void *fBuffer, uint16_t fBufferSize )
 {
+    ser->printf("[LRMAC] LoRaMacStatus_t PrepareFrame \n\r");
     uint16_t i;
     uint8_t pktHeaderLen = 0;
     uint32_t mic = 0;
@@ -3146,8 +3160,10 @@
             NodeAckRequested = true;
             //Intentional fallthrough
         case FRAME_TYPE_DATA_UNCONFIRMED_UP:
+            ser->printf("[LRMAC] LoRaMacStatus_t PrepareFrame :: FRAME_TYPE_DATA_UNCONFIRMED_UP \n\r");
             if( IsLoRaMacNetworkJoined == false )
             {
+                ser->printf("[LRMAC] LoRaMacStatus_t PrepareFrame :: LORAMAC_STATUS_NO_NETWORK_JOINED \n\r");
                 return LORAMAC_STATUS_NO_NETWORK_JOINED; // No network has been joined yet
             }
 
@@ -3240,11 +3256,13 @@
             return LORAMAC_STATUS_SERVICE_UNKNOWN;
     }
 
+    ser->printf("[LRMAC] LoRaMacStatus_t PrepareFrame :: LORAMAC_STATUS_OK \n\r");
     return LORAMAC_STATUS_OK;
 }
 
 LoRaMacStatus_t SendFrameOnChannel( ChannelParams_t channel )
 {
+    ser->printf("[LRMAC] LoRaMacStatus_t SendFrameOnChannel\n\r");
     int8_t datarate = Datarates[LoRaMacParams.ChannelsDatarate];
     int8_t txPowerIndex = 0;
     int8_t txPower = 0;
@@ -3276,6 +3294,8 @@
     }
     else
     { // Normal LoRa channel
+        ser->printf("[LRMAC] LoRaMacStatus_t SendFrameOnChannel :: Normal LoRa channel \n\r");
+        
         Radio.SetMaxPayloadLength( MODEM_LORA, LoRaMacBufferPktLen );
         Radio.SetTxConfig( MODEM_LORA, txPower, 0, 0, datarate, 1, 8, false, true, 0, 0, false, 3e3 );
         TxTimeOnAir = Radio.TimeOnAir( MODEM_LORA, LoRaMacBufferPktLen );
@@ -3311,6 +3331,7 @@
     if( IsLoRaMacNetworkJoined == false )
     {
         JoinRequestTrials++;
+        ser->printf("[LRMAC] [LRMAC] LoRaMacStatus_t SendFrameOnChannel :: JoinRequestTrials++\n\r");
     }
 
     // Send now
@@ -3318,6 +3339,7 @@
 
     LoRaMacState |= LORAMAC_TX_RUNNING;
 
+    ser->printf("[LRMAC] LoRaMacStatus_t SendFrameOnChannel :: LORAMAC_STATUS_OK\n\r");
     return LORAMAC_STATUS_OK;
 }
 
@@ -4334,6 +4356,7 @@
             LoRaMacParams.ChannelsDatarate = AlternateDatarate( JoinRequestTrials + 1 );
 
             status = Send( &macHdr, 0, NULL, 0 );
+                
             break;
         }
         case MLME_LINK_CHECK:
@@ -4384,11 +4407,13 @@
 
     if( mcpsRequest == NULL )
     {
+        ser->printf("[LRMAC] LORAMAC_STATUS_PARAMETER_INVALID 1\n\r");
         return LORAMAC_STATUS_PARAMETER_INVALID;
     }
     if( ( ( LoRaMacState & LORAMAC_TX_RUNNING ) == LORAMAC_TX_RUNNING ) ||
         ( ( LoRaMacState & LORAMAC_TX_DELAYED ) == LORAMAC_TX_DELAYED ) )
     {
+        ser->printf("[LRMAC] LORAMAC_STATUS_BUSY\n\r");
         return LORAMAC_STATUS_BUSY;
     }
 
@@ -4400,6 +4425,7 @@
     {
         case MCPS_UNCONFIRMED:
         {
+            ser->printf("[LRMAC] MCPS_UNCONFIRMED\n\r");
             readyToSend = true;
             AckTimeoutRetries = 1;
 
@@ -4412,6 +4438,7 @@
         }
         case MCPS_CONFIRMED:
         {
+            ser->printf("[LRMAC] MCPS_CONFIRMED\n\r");
             readyToSend = true;
             AckTimeoutRetriesCounter = 1;
             AckTimeoutRetries = mcpsRequest->Req.Confirmed.NbTrials;
@@ -4425,6 +4452,7 @@
         }
         case MCPS_PROPRIETARY:
         {
+            ser->printf("[LRMAC] MCPS_PROPRIETARY\n\r");
             readyToSend = true;
             AckTimeoutRetries = 1;
 
@@ -4448,6 +4476,7 @@
             }
             else
             {
+                ser->printf("[LRMAC] LORAMAC_STATUS_PARAMETER_INVALID 2 \n\r");
                 return LORAMAC_STATUS_PARAMETER_INVALID;
             }
         }
@@ -4463,7 +4492,7 @@
             NodeAckRequested = false;
         }
     }
-
+    ser->printf("[LRMAC] LoRaMacStatus_t LoRaMacMcpsRequest :: status %u \n\r", status);
     return status;
 }