summaryrefslogtreecommitdiff
path: root/recipes-connectivity/lora/lora-gateway/lora-gateway-spectral-scan-skip-fpga-reset.patch
blob: e4a8b2b8669bb34df9efdd85a761b59748b40aef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
diff --git a/util_spectral_scan/src/util_spectral_scan.c b/util_spectral_scan/src/util_spectral_scan.c
index d2aecda..f070f4b 100644
--- a/util_spectral_scan/src/util_spectral_scan.c
+++ b/util_spectral_scan/src/util_spectral_scan.c
@@ -30,6 +30,7 @@ Maintainer: Michael Coracin
 #include <stdlib.h>     /* EXIT atoi */
 #include <unistd.h>     /* getopt */
 #include <string.h>
+#include <signal.h>
 
 #include "loragw_aux.h"
 #include "loragw_reg.h"
@@ -66,11 +67,22 @@ Maintainer: Michael Coracin
 /* -------------------------------------------------------------------------- */
 /* --- GLOBAL VARIABLES ----------------------------------------------------- */
 
+bool shutdown_signal_recv = false;
+
+void signalHandler() {
+    shutdown_signal_recv = true;
+}
+
+
 /* -------------------------------------------------------------------------- */
 /* --- MAIN FUNCTION -------------------------------------------------------- */
 
 int main( int argc, char ** argv )
 {
+
+    signal(SIGINT, signalHandler);
+    signal(SIGTERM, signalHandler);
+
     int i, j, k; /* loop and temporary variables */
     int x; /* return code for functions */
     int32_t reg_val;
@@ -200,6 +212,10 @@ int main( int argc, char ** argv )
         }
     }
 
+    if (shutdown_signal_recv) {
+       return 0;
+    }
+
     /* Start message */
     printf("+++ Start spectral scan of LoRa gateway channels +++\n");
 
@@ -264,7 +280,7 @@ int main( int argc, char ** argv )
             printf("ERROR: Failed to disconnect from FPGA\n");
             return EXIT_FAILURE;
         }
-        x = lgw_connect(false, LGW_DEFAULT_NOTCH_FREQ); /* FPGA reset/configure */
+        x = lgw_connect(true, LGW_DEFAULT_NOTCH_FREQ); /* FPGA reset/configure */
         if(x != 0) {
             printf("ERROR: Failed to connect to FPGA\n");
             return EXIT_FAILURE;
@@ -382,6 +398,10 @@ int main( int argc, char ** argv )
         }
         fprintf(log_file, "\n");
         printf("\n");
+
+        if (shutdown_signal_recv) {
+            break;
+        }
     }
     fclose(log_file);