standalone sx1276 demo program

Dependencies:   SX1276Lib mbed

Fork of SX1276_GPS by CaryCoders

Revision:
33:319cbac3b6eb
Parent:
32:a2472bbe7c92
Child:
34:75e4c3600d2f
diff -r a2472bbe7c92 -r 319cbac3b6eb hello.cpp
--- a/hello.cpp	Wed Jul 29 12:14:42 2015 +0000
+++ b/hello.cpp	Thu Sep 03 14:33:55 2015 +0000
@@ -3,14 +3,16 @@
 #include "main.h"
 #include "debug.h"
 #include "serial_api.h"
+#ifndef STANDALONE
 #include "GPS.h"
+#endif
 #include <math.h>
 
 
 void start_hello(void)
 {
     int len = get_kbd_str(pcbuf, PCBUF_SIZE);
-    //printf("in start gps/hello\r\n");
+    //printf("in start gps/hello len=%d\r\n",len);
     if (len < 0) {
         fflush(stdout);
         Radio.Rx( RX_TIMEOUT_VALUE );
@@ -28,6 +30,7 @@
     }
     else
     {   
+       Radio.Rx( RX_TIMEOUT_VALUE / 3  );
        hello();
     }
 }
@@ -37,8 +40,8 @@
  
     // srand ( randomSeed() );
     // generate a random wait time
-    // int mywait = ((rand()%2 +1));
-    int mywait = 3;
+    int mywait = ((rand()%2 +1));
+   // int mywait = 3;
     int i=0;
     int rcvd=0;
     int lost=0;
@@ -78,25 +81,33 @@
             r_latitude = 0;
             r_longitude = 0;
             // printf("rcv - rssi = %d snr = %d msg=%s\r\n", RssiValue, SnrValue, BufferRx);
+            #ifndef STANDALONE
             cLCD.setCursor(0,0);
             cLCD.printf("RI:NA SR:NA      ");
+            #endif
         case RX:
              
             if( BufferSize > 0 )
             {
+                RXin = !RXin;
                 if( strncmp( ( const char* )BufferRx, ( const char* )HelloMsg, 5 ) == 0 )
                 {
                     // radfta led = !led;     
                     printf("rcv - rssi = %d snr = %d msg=%s ", RssiValue, SnrValue, BufferRx );
                     printf("per=%d\r\n", per);
+                    #ifndef STANDALONE
                     cLCD.setCursor(0,0);
                     cLCD.printf("RI:%d SR:%d   ", RssiValue, SnrValue);
+                    #endif
                 }
+                #ifndef STANDALONE
                 else
                 {
 
                   if(sscanf((char *)BufferRx, "GP,%f,%f", &r_latitude, &r_longitude ) >= 1) 
-                  {                    
+                  {    
+                    r_latitude_last = r_latitude;     
+                    r_longitude_last = r_longitude;           
                     // radfta led = !led;     
                     printf("rssi=%d snr=%d rlat=%0.5f rlon=%0.5f llat=%0.5f llon=%0.5f dst=%0.0fm ", RssiValue, SnrValue, r_latitude, r_longitude, gpsd.lat_deg, gpsd.lon_deg, distance);
                     printf("per=%d\r\n", per);
@@ -107,27 +118,31 @@
                   else
                     printf("strange received message: %s\r\n", BufferRx);
            
-              }                  
+                }
+                #else
+                    printf("rssi=%d \tsnr=%d \tper=%d  \tmsg=%s\r\n", RssiValue, SnrValue, per, BufferRx);
+                #endif
             }
        case RX_ERROR:
-         
+#ifndef STANDALONE         
             if (gpsEnabled)
                 sprintf((char *)BufferTx, "GP,%4.5f,%4.5f", gpsd.lat_deg, gpsd.lon_deg);
             else
+#endif            
                 strcpy( ( char* )BufferTx, ( char* )HelloMsg );
-#if 0
-radfta     
+#if 1
             BufferSize=strlen((char *)BufferTx);
             //printf("Sending new buffer\r\n");
             Radio.Send( BufferTx, BufferSize );
+            State = LOWPOWER;
+#else            
+            State = CAD;
 #endif            
-            State = LOWPOWER;
 
             break;
         case TX:    
-            //printf("tx state\r\n");
-            //wait_ms (30);
- 
+            // printf("tx state\r\n");
+            // wait_ms (10);
             Radio.Rx( RX_TIMEOUT_VALUE / mywait  );
             State = LOWPOWER;
             break;
@@ -138,10 +153,18 @@
             break;
         case LOWPOWER:
             //printf("in wait\r\n");
-           // wait_ms (1);
+            //wait_ms (1);
+            //wait_us(200);
+#ifndef STANDALONE
+            check_gps();
+#endif      
+            break;
+        case CAD:
+             printf("in cad\r\n");
+            //State = LOWPOWER;
             break;
         default:
-            debug("state is set to low power\r\n");
+             //debug("state is set to CAD\r\n");
             State = LOWPOWER;
             break;
     }