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:
Tue May 16 17:51:21 2017 +0200
Parent:
49:a41aafb5e12f
Child:
51:aef3234bcb71
Commit message:
Added optional Send() parameter to include a header,
this saves additional buffers.

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
sx1276/sx1276.h Show annotated file Show diff for this revision Revisions of this file
--- a/LoRa_TODO.txt	Sun May 14 14:27:37 2017 +0000
+++ b/LoRa_TODO.txt	Tue May 16 17:51:21 2017 +0200
@@ -26,5 +26,8 @@
 - Verify the Murata ANT Switch code
 - MURATA PA_BOOST case,is _antSwitchTXBoost right? (Same as STM sample code)
 - Check of the MURATA TCXO config is correct (implemented, check JP9 on STM L0 board)
-- Make the timers more generic and move the OS code into the HAL layer. (May Helmut)
-- Removed pull down on dio=-dio5 for L151 &LPC11U6X which make no sense to me. May 2017 Helmut
+- Make the timers more generic and move the OS code into the HAL layer. (May 2017 Helmut)
+- Removed pull down on dio=-dio5 for L151 &LPC11U6X which make no sense to me. May 2017 Helmut
+- Added radio API support to receive the MaxMTUSize (May 2017 Helmut)
+- Added Send optional Send() parameter to include a header,
+  this saves additional buffers. (May 2017 Helmut)
--- a/radio/radio.h	Sun May 14 14:27:37 2017 +0000
+++ b/radio/radio.h	Tue May 16 17:51:21 2017 +0200
@@ -205,7 +205,7 @@
     /*!
      * @brief Return current radio status
      *
-     * @param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
+     * @param status Radio status. [RF_IDLE, RX_RUNNING, TX_RUNNING, CAD_RUNNING]
      */
     virtual RadioState GetStatus( void ) = 0; 
 
@@ -350,8 +350,10 @@
      *
      * @param [IN]: buffer     Buffer pointer
      * @param [IN]: size       Buffer size
+     * @param [IN]: buffer     Header pointer
+     * @param [IN]: size       Header size
      */
-    virtual void Send( uint8_t *buffer, uint8_t size ) = 0;
+    virtual void Send( uint8_t *buffer, uint8_t size, uint8_t *header = NULL, uint8_t hsize = 0) = 0;
 
     /*!
      * @brief Sets the radio in sleep mode
@@ -392,6 +394,13 @@
     virtual void SetTxContinuousWave( uint32_t freq, int8_t power, uint16_t time ) = 0;
 
     /*!
+     * @brief Returns the maximal transfer unit for a given modem
+     *
+     * @retval MTU size in bytes
+     */
+    virtual int16_t MaxMTUSize( RadioModems_t modem ) = 0;
+    
+    /*!
      * @brief Reads the current RSSI value
      *
      * @retval rssiValue Current RSSI value in [dBm]
--- a/sx1276/sx1276.cpp	Sun May 14 14:27:37 2017 +0000
+++ b/sx1276/sx1276.cpp	Tue May 16 17:51:21 2017 +0200
@@ -633,7 +633,7 @@
     return airTime;
 }
 
-void SX1276::Send( uint8_t *buffer, uint8_t size )
+void SX1276::Send( uint8_t *buffer, uint8_t size, uint8_t *header, uint8_t hsize )
 {
     uint32_t txTimeout = 0;
 
@@ -642,28 +642,35 @@
     case MODEM_FSK:
         {
             this->settings.FskPacketHandler.NbBytes = 0;
-            this->settings.FskPacketHandler.Size = size;
+            this->settings.FskPacketHandler.Size = size + hsize;
 
             if( this->settings.Fsk.FixLen == false )
             {
-                WriteFifo( ( uint8_t* )&size, 1 );
+                uint8_t tmpsize = size + hsize;
+                WriteFifo( ( uint8_t* )&tmpsize, 1 );
             }
             else
             {
-                Write( REG_PAYLOADLENGTH, size );
+                Write( REG_PAYLOADLENGTH, size + hsize);
 			}
 
-            if( ( size > 0 ) && ( size <= 64 ) )
+            if( ( size + hsize > 0 ) && ( size + hsize <= 64 ) )
             {
-                this->settings.FskPacketHandler.ChunkSize = size;
+                this->settings.FskPacketHandler.ChunkSize = size + hsize;
             }
             else
             {
-				memcpy( rxtxBuffer, buffer, size );
+                if (header) {
+                    WriteFifo( header, hsize );
+                    memcpy( rxtxBuffer, header, hsize );
+                }
+				memcpy( rxtxBuffer+hsize, buffer+hsize, size );
                 this->settings.FskPacketHandler.ChunkSize = 32;
             }
 
             // Write payload buffer
+            if (header)
+                WriteFifo( header, hsize );
             WriteFifo( buffer, this->settings.FskPacketHandler.ChunkSize );
             this->settings.FskPacketHandler.NbBytes += this->settings.FskPacketHandler.ChunkSize;
             txTimeout = this->settings.Fsk.TxTimeout;
@@ -682,10 +689,10 @@
                 Write( REG_LR_INVERTIQ2, RFLR_INVERTIQ2_OFF );
             }
 
-            this->settings.LoRaPacketHandler.Size = size;
+            this->settings.LoRaPacketHandler.Size = size + hsize;
 
             // Initializes the payload size
-            Write( REG_LR_PAYLOADLENGTH, size );
+            Write( REG_LR_PAYLOADLENGTH, size + hsize);
 
             // Full buffer used for Tx
             Write( REG_LR_FIFOTXBASEADDR, 0 );
@@ -698,6 +705,8 @@
                 wait_ms( 1 );
             }
             // Write payload buffer
+            if (header)
+                WriteFifo( header, hsize );
             WriteFifo( buffer, size );
             txTimeout = this->settings.LoRa.TxTimeout;
         }
@@ -1002,6 +1011,24 @@
     SetOpMode( RF_OPMODE_TRANSMITTER );
 }
 
+int16_t SX1276::MaxMTUSize( RadioModems_t modem )
+{
+    int16_t mtuSize = 0;
+    
+    switch( modem )
+    {
+        case MODEM_FSK:
+            mtuSize = RX_BUFFER_SIZE;
+        case MODEM_LORA:
+            mtuSize = RX_BUFFER_SIZE;
+            break;
+        default:
+            mtuSize = -1;
+            break;
+    }
+    return mtuSize;
+}
+
 int16_t SX1276::GetRssi( RadioModems_t modem )
 {
     int16_t rssi = 0;
--- a/sx1276/sx1276.h	Sun May 14 14:27:37 2017 +0000
+++ b/sx1276/sx1276.h	Tue May 16 17:51:21 2017 +0200
@@ -208,7 +208,7 @@
     /*!
      * Return current radio status
      *
-     * @param status Radio status. [RF_IDLE, RX_RUNNING, TX_RUNNING]
+     * @param status Radio status. [RF_IDLE, RX_RUNNING, TX_RUNNING, CAD_RUNNING]
      */
     virtual RadioState GetStatus( void ); 
 
@@ -354,8 +354,10 @@
      *
      * @param [IN]: buffer     Buffer pointer
      * @param [IN]: size       Buffer size
+     * @param [IN]: buffer     Header pointer
+     * @param [IN]: size       Header size
      */
-    virtual void Send( uint8_t *buffer, uint8_t size );
+    virtual void Send( uint8_t *buffer, uint8_t size, uint8_t *header = NULL, uint8_t hsize = 0);
 
     /*!
      * @brief Sets the radio in sleep mode
@@ -397,6 +399,13 @@
     virtual void SetTxContinuousWave( uint32_t freq, int8_t power, uint16_t time );
 
     /*!
+     * @brief Returns the maximal transfer unit for a given modem
+     *
+     * @retval MTU size in bytes
+     */
+    virtual int16_t MaxMTUSize( RadioModems_t modem );
+    
+    /*!
      * @brief Reads the current RSSI value
      *
      * @retval rssiValue Current RSSI value in [dBm]