ping pong with modifiable parameters

Dependencies:   mbed SX126xLib

Revision:
5:dc53029f4c02
Parent:
4:99bfe3b61a6a
Child:
6:e155f7cceb5b
--- a/main.cpp	Thu Jun 20 22:04:10 2019 +0000
+++ b/main.cpp	Thu Jun 20 22:53:28 2019 +0000
@@ -7,6 +7,8 @@
 
 
 long unsigned RF_FREQUENCY = 350000000; // Hz
+unsigned int spreading_factor = LORA_SF7;
+unsigned int bandwidth = LORA_BW_500;
 
 Serial s( USBTX, USBRX );
 // additional variables for incoming data
@@ -182,8 +184,8 @@
 
 void LoRa_init() {
     modulationParams.PacketType                  = PACKET_TYPE_LORA;
-    modulationParams.Params.LoRa.SpreadingFactor = LORA_SF7;
-    modulationParams.Params.LoRa.Bandwidth       = LORA_BW_500;
+    modulationParams.Params.LoRa.SpreadingFactor = spreading_factor;
+    modulationParams.Params.LoRa.Bandwidth       = bandwidth;
     modulationParams.Params.LoRa.CodingRate      = LORA_CR_4_5;
 
     PacketParams.PacketType                 = PACKET_TYPE_LORA;
@@ -407,9 +409,81 @@
         if((125000000<=val) && (val<=960000000)) {
             RF_FREQUENCY = val;
             printf("Frequency set to: %lu\n\r", val);
-            LoRa_init();
-            
+            LoRa_init();            
+        }
+    }
+    else if(strcmp(command, "S_F") == 0) {
+        switch(val) {
+            case 5:
+                spreading_factor = LORA_SF5;
+            break;
+            case 6:
+                spreading_factor = LORA_SF6;
+            break;
+            case 7:
+                spreading_factor = LORA_SF7;
+            break;
+            case 8:
+                spreading_factor = LORA_SF8;
+            break;
+            case 9:
+                spreading_factor = LORA_SF9;
+            break;
+            case 10:
+                spreading_factor = LORA_SF10;
+            break;
+            case 11:
+                spreading_factor = LORA_SF11;
+            break;
+            case 12:
+                spreading_factor = LORA_SF12;
+            break;
+            default:
+                printf("enter spreading factor between 5 and 12\n\r");
+                return;
         }
+        printf("Spreading factor changed to %lu\n\r", val);
+        LoRa.init();
+    }
+    else if(strcmp(command, "BW") == 0) {
+        switch(val) {
+            case 500:
+                bandwidth = LORA_BW_500;
+            break;
+            case 250:
+                bandwidth = LORA_BW_250;
+            break;
+            case 125:
+                bandwidth = LORA_BW_125;
+            break;
+            case 062:
+                bandwidth = LORA_BW_062;
+            break;
+            case 041:
+                bandwidth = LORA_BW_041;
+            break;
+            case 031:
+                bandwidth = LORA_BW_031;
+            break;
+            case 020:
+                bandwidth = LORA_BW_020;
+            break;
+            case 015:
+                bandwidth = LORA_BW_015;
+            break;
+            case 010:
+                bandwidth = LORA_BW_010;
+            break;
+            case 007:
+                bandwidth = LORA_BW_007;
+            break;
+            default:
+                printf("Valid bandwidths: 500, 250, 125, 62, 41, 31, 20, ");
+                printf("15, 10, 7\n\r");
+                return;
+        }
+        printf("LoRa bandwidth changed to %lu\n\r", val);
+        LoRa.init();
     }
     else
         printf("Invalid command\n\r");