local copy of sx1276 library

Dependents:   SX1276_GPS demo_SX1276_standalone

Fork of SX1276Lib by Gregory Cristian

Revision:
16:29f09ac61412
Parent:
13:618826a997e2
Child:
17:20ce6dab2237
--- a/sx1276/sx1276.cpp	Tue Dec 16 10:02:45 2014 +0000
+++ b/sx1276/sx1276.cpp	Tue Jun 16 11:52:30 2015 +0000
@@ -122,6 +122,26 @@
     Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
 }
 
+float SX1276::GetChannel(void)
+{
+    uint32_t frf;
+    uint8_t lsb, mid, msb;
+    float MHz;
+    
+    msb = Read(REG_FRFMSB);
+    mid = Read(REG_FRFMID);
+    lsb = Read(REG_FRFLSB);
+    frf = msb;
+    frf <<= 8;
+    frf += mid;
+    frf <<= 8;
+    frf += lsb;
+    MHz = frf * FREQ_STEP_MHZ;
+    //printf("frf=%d mhz=%f\r\n", frf, MHz);
+    return MHz;
+}
+
+
 bool SX1276::IsChannelFree( ModemType modem, uint32_t freq, int8_t rssiThresh )
 {
     int16_t rssi = 0;
@@ -345,7 +365,7 @@
         break;
     }
 }
-
+ 
 void SX1276::SetTxConfig( ModemType modem, int8_t power, uint32_t fdev, 
                         uint32_t bandwidth, uint32_t datarate,
                         uint8_t coderate, uint16_t preambleLen,
@@ -363,6 +383,7 @@
     paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | GetPaSelect( this->settings.Channel );
     paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70;
 
+    printf("getpa = %x  paConfig =%x power = %d\r\n",GetPaSelect( this->settings.Channel),paConfig, power );
     if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST )
     {
         if( power > 17 )
@@ -375,6 +396,7 @@
         }
         if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON )
         {
+            //printf("padacc20dbm on\r\n");
             if( power < 5 )
             {
                 power = 5;
@@ -383,10 +405,12 @@
             {
                 power = 20;
             }
+            //printf("radfta set power - 5, power = %d\r\n",power);
             paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
         }
         else
         {
+            // printf("padacc20dbm not on\r\n");
             if( power < 2 )
             {
                 power = 2;
@@ -395,6 +419,7 @@
             {
                 power = 17;
             }
+            //printf("radfta set power - 2, power=%d\r\n",power);
             paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
         }
     }
@@ -406,6 +431,7 @@
         }
         if( power > 14 )
         {
+            printf("Max power for this radio is 14dBm\r\n");
             power = 14;
         }
         paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
@@ -746,7 +772,7 @@
             {
                 Write( REG_LR_INVERTIQ, ( ( Read( REG_LR_INVERTIQ ) & RFLR_INVERTIQ_TX_MASK & RFLR_INVERTIQ_RX_MASK ) | RFLR_INVERTIQ_RX_OFF | RFLR_INVERTIQ_TX_OFF ) );
             }         
-        
+            // printf("radfta lora rx\n\r");
             rxContinuous = this->settings.LoRa.RxContinuous;
             
             if( this->settings.LoRa.FreqHopOn == true )
@@ -809,10 +835,13 @@
     {
         if( rxContinuous == true )
         {
+            //printf("radfta rx continuous \r\n");
             SetOpMode( RFLR_OPMODE_RECEIVER );
         }
         else
         {
+            
+            //printf("radfta rx single \r\n");
             SetOpMode( RFLR_OPMODE_RECEIVER_SINGLE );
         }
     }
@@ -936,6 +965,14 @@
         rssi = -1;
         break;
     }
+    if (rssi > 100)
+    {
+        rssi *= -1;
+        printf("rssi sign change %d\r\n",rssi);
+    }
+    else
+        printf("no rssi sign change %d\r\n", rssi
+        );
     return rssi;
 }
 
@@ -1170,17 +1207,20 @@
                     }
 
                     int16_t rssi = Read( REG_LR_PKTRSSIVALUE );
+            
                     if( this->settings.LoRaPacketHandler.SnrValue < 0 )
                     {
                         if( this->settings.Channel > RF_MID_BAND_THRESH )
                         {
                             this->settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 ) +
                                                                           snr;
+                            //printf("1 rssi=%x snr=%d rssi_4=%x\r\n", rssi, snr, rssi>> 4);
                         }
                         else
                         {
                             this->settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 ) +
                                                                           snr;
+                         //printf("2\r\n");
                         }
                     }
                     else
@@ -1188,13 +1228,25 @@
                         if( this->settings.Channel > RF_MID_BAND_THRESH )
                         {
                             this->settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 );
+                            //printf("3\r\n");
+                            //printf("3 rssi=%x snr=%d rssi_4=%x\r\n", rssi, snr, rssi>> 4);
                         }
                         else
                         {
                             this->settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 );
+                            //printf("4\r\n");
                         }
                     }
+                     
+                    if (this->settings.LoRaPacketHandler.RssiValue > 50)
+                    {
+                        this->settings.LoRaPacketHandler.RssiValue16 = this->settings.LoRaPacketHandler.RssiValue - 256;
+                        //printf("rssi in irq done, WAS FIXED is %d\r\n", this->settings.LoRaPacketHandler.RssiValue16);
+                    }
+                    else
+                        this->settings.LoRaPacketHandler.RssiValue16 = this->settings.LoRaPacketHandler.RssiValue;
 
+                    
                     this->settings.LoRaPacketHandler.Size = Read( REG_LR_RXNBBYTES );
                     ReadFifo( rxBuffer, this->settings.LoRaPacketHandler.Size );
                 
@@ -1206,7 +1258,7 @@
 
                     if( ( rxDone != NULL ) )
                     {
-                        rxDone( rxBuffer, this->settings.LoRaPacketHandler.Size, this->settings.LoRaPacketHandler.RssiValue, this->settings.LoRaPacketHandler.SnrValue );
+                        rxDone( rxBuffer, this->settings.LoRaPacketHandler.Size, this->settings.LoRaPacketHandler.RssiValue16, this->settings.LoRaPacketHandler.SnrValue );
                     }
                 }
                 break;