r g / SX1276GenericLib-us915

Dependents:   DISCO-L072CZ-LRWAN1_LoRa_PingPong

Fork of SX1276GenericLib by Helmut Tschemernjak

Files at this revision

API Documentation at this revision

Comitter:
Helmut Tschemernjak
Date:
Thu Jun 29 19:30:24 2017 +0200
Parent:
62:835c5e20834e
Child:
64:b721e6ab656a
Commit message:
Added userData and userThisPtr into the radio events callback,
this allows to call C++ functions and in can include a context
via the userData

Changed in this revision

LoRa_TODO.txt Show annotated file Show diff for this revision Revisions of this file
radio/radio.h Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/LoRa_TODO.txt	Mon Jun 05 01:35:40 2017 +0200
+++ b/LoRa_TODO.txt	Thu Jun 29 19:30:24 2017 +0200
@@ -39,4 +39,6 @@
 - Added LoRa bandwidth mapping table, now the SetRx/Tx frequency is in Hz. (May 2017 Helmut)
 - Enabled MURATA_SX1276 for the MURATA_SX1276 chip (May 2017 Helmut)
 - Made SetRfTxPower public to allow easily power TX changes (May 2017 Helmut)
+- Added userData and userThisPtr into the radio events, this allows to call C++ 
+  functions and in can include a context via the userData
 
--- a/radio/radio.h	Mon Jun 05 01:35:40 2017 +0200
+++ b/radio/radio.h	Thu Jun 29 19:30:24 2017 +0200
@@ -130,11 +130,11 @@
     /*!
      * @brief  Tx Done callback prototype.
      */
-    void    ( *TxDone )(void *radio);
+    void    ( *TxDone )(void *radio, void *userThisPtr, void *userData);
     /*!
      * @brief  Tx Timeout callback prototype.
      */
-    void    ( *TxTimeout )(void *radio);
+    void    ( *TxTimeout )(void *radio, void *userThisPtr, void *userData);
     /*!
      * @brief Rx Done callback prototype.
      *
@@ -145,28 +145,42 @@
      *                     FSK : N/A ( set to 0 )
      *                     LoRa: SNR value in dB
      */
-    void    ( *RxDone )(void *radio, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
+    void    ( *RxDone )(void *radio, void *userThisPtr, void *userData, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );
     /*!
      * @brief  Rx Timeout callback prototype.
      */
-    void    ( *RxTimeout )(void *radio);
+    void    ( *RxTimeout )(void *radio, void *userThisPtr, void *userData);
     /*!
      * @brief Rx Error callback prototype.
      */
-    void    ( *RxError )(void *radio);
+    void    ( *RxError )(void *radio, void *userThisPtr, void *userData);
     /*!
      * \brief  FHSS Change Channel callback prototype.
      *
      * \param [IN] currentChannel   Index number of the current channel
      */
-    void ( *FhssChangeChannel )(void *radio, uint8_t currentChannel );
+    void ( *FhssChangeChannel )(void *radio, void *userThisPtr, void *userData, uint8_t currentChannel );
 
     /*!
      * @brief CAD Done callback prototype.
      *
      * @param [IN] channelDetected    Channel Activity detected during the CAD
      */
-    void ( *CadDone ) (void *radio, bool channelActivityDetected );
+    void ( *CadDone ) (void *radio, void *userThisPtr, void *userData, bool channelActivityDetected );
+    
+    /*
+     * Optional data which is being provided in callbacks
+     * can be used e.g. for the C++ this pointer.
+     */
+    void *userThisPtr;
+    
+    /*
+     * Optional data which allows to bring in data structures pointer 
+     * for a given radio. As callbacks are being called in interrupt level
+     * the userData is perfect to know the context without iterating this
+     * data structures.
+     */
+    void *userData;
 
 }RadioEvents_t;
 
--- a/sx1276/sx1276.cpp	Mon Jun 05 01:35:40 2017 +0200
+++ b/sx1276/sx1276.cpp	Thu Jun 29 19:30:24 2017 +0200
@@ -1230,9 +1230,9 @@
                 SetTimeout(RXTimeoutSyncWordTimer, NULL);
             }
         }
-        if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxTimeout != NULL ) )
+        if (this->RadioEvents && this->RadioEvents->RxTimeout)
         {
-            this->RadioEvents->RxTimeout(this);
+            this->RadioEvents->RxTimeout(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData);
         }
         break;
     case RF_TX_RUNNING:
@@ -1261,9 +1261,9 @@
 		// END WORKAROUND
             
         this->settings.State = RF_IDLE;
-        if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->TxTimeout != NULL ) )
+        if (this->RadioEvents && this->RadioEvents->TxTimeout)
         {
-            this->RadioEvents->TxTimeout(this);
+            this->RadioEvents->TxTimeout(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData);
         }
         break;
     default:
@@ -1308,9 +1308,9 @@
                             SetTimeout(RXTimeoutSyncWordTimer, &SX1276::OnTimeoutIrq, this->settings.Fsk.RxSingleTimeout * 1e3);
                         }
 
-                        if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxError != NULL ) )
+                        if (this->RadioEvents && this->RadioEvents->RxError)
                         {
-                            this->RadioEvents->RxError(this);
+                            this->RadioEvents->RxError(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData);
                         }
                         this->settings.FskPacketHandler.PreambleDetected = false;
                         this->settings.FskPacketHandler.SyncWordDetected = false;
@@ -1354,9 +1354,9 @@
                     SetTimeout(RXTimeoutSyncWordTimer, &SX1276::OnTimeoutIrq, this->settings.Fsk.RxSingleTimeout * 1e3);
 				}
 
-                if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxDone != NULL ) )
+                if (this->RadioEvents && this->RadioEvents->RxDone)
                 {
-                    this->RadioEvents->RxDone(this, rxtxBuffer, this->settings.FskPacketHandler.Size, this->settings.FskPacketHandler.RssiValue, 0 );
+                    this->RadioEvents->RxDone(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData, rxtxBuffer, this->settings.FskPacketHandler.Size, this->settings.FskPacketHandler.RssiValue, 0 );
                 }
                 this->settings.FskPacketHandler.PreambleDetected = false;
                 this->settings.FskPacketHandler.SyncWordDetected = false;
@@ -1382,9 +1382,9 @@
                         }
                         SetTimeout(RXTimeoutTimer, NULL);
                         
-                        if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxError != NULL ) )
+                        if(this->RadioEvents && this->RadioEvents->RxError)
                         {
-                            this->RadioEvents->RxError(this);
+                            this->RadioEvents->RxError(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData);
                         }
                         break;
                     }
@@ -1437,9 +1437,9 @@
                     }
                     SetTimeout(RXTimeoutTimer, NULL);
                     
-                    if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxDone != NULL ) )
+                    if(this->RadioEvents && this->RadioEvents->RxDone)
                     {
-                        this->RadioEvents->RxDone(this, rxtxBuffer, this->settings.LoRaPacketHandler.Size, this->settings.LoRaPacketHandler.RssiValue, this->settings.LoRaPacketHandler.SnrValue );
+                        this->RadioEvents->RxDone(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData, rxtxBuffer, this->settings.LoRaPacketHandler.Size, this->settings.LoRaPacketHandler.RssiValue, this->settings.LoRaPacketHandler.SnrValue );
                     }
                 }
                 break;
@@ -1459,9 +1459,9 @@
             case MODEM_FSK:
             default:
                 this->settings.State = RF_IDLE;
-                if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->TxDone != NULL ) )
+                if (this->RadioEvents && this->RadioEvents->TxDone)
                 {
-                    this->RadioEvents->TxDone(this);
+                    this->RadioEvents->TxDone(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData);
                 }
                 break;
             }
@@ -1511,9 +1511,9 @@
 				Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXTIMEOUT );
 
                 this->settings.State = RF_IDLE;
-                if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxTimeout != NULL ) )
+                if (this->RadioEvents &&  this->RadioEvents->RxTimeout)
                 {
-                    this->RadioEvents->RxTimeout(this);
+                    this->RadioEvents->RxTimeout(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData);
                 }
                 break;
             default:
@@ -1582,9 +1582,9 @@
                     // Clear Irq
                     Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL );
 
-                    if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->FhssChangeChannel != NULL ) )
+                    if (this->RadioEvents &&  this->RadioEvents->FhssChangeChannel)
                     {
-                        this->RadioEvents->FhssChangeChannel(this, ( Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
+                        this->RadioEvents->FhssChangeChannel(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData, ( Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
                     }
                 }
                 break;
@@ -1603,9 +1603,9 @@
                     // Clear Irq
                     Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL );
 
-                    if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->FhssChangeChannel != NULL ) )
+                    if (this->RadioEvents && this->RadioEvents->FhssChangeChannel)
                     {
-                        this->RadioEvents->FhssChangeChannel(this, ( Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
+                        this->RadioEvents->FhssChangeChannel(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData, ( Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) );
                     }
                 }
                 break;
@@ -1629,18 +1629,18 @@
         {
             // Clear Irq
             Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDETECTED | RFLR_IRQFLAGS_CADDONE );
-            if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->CadDone != NULL ) )
+            if (this->RadioEvents && this->RadioEvents->CadDone)
             {
-                this->RadioEvents->CadDone(this, true );
+                this->RadioEvents->CadDone(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData, true );
             }
         }
         else
         {
             // Clear Irq
             Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDONE );
-            if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->CadDone != NULL ) )
+            if (this->RadioEvents && this->RadioEvents->CadDone)
             {
-                this->RadioEvents->CadDone(this, false );
+                this->RadioEvents->CadDone(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData, false );
             }
         }
         break;