CaryCoders
/
demo_SX1276_standalone
standalone sx1276 demo program
Fork of SX1276_GPS by
Diff: hello.cpp
- Revision:
- 32:a2472bbe7c92
- Parent:
- 31:2c813f321db7
- Child:
- 33:319cbac3b6eb
--- a/hello.cpp Tue Jul 14 14:58:23 2015 +0000 +++ b/hello.cpp Wed Jul 29 12:14:42 2015 +0000 @@ -2,16 +2,15 @@ #include "sx1276-hal.h" #include "main.h" #include "debug.h" -// radfta #include "vt100.h" #include "serial_api.h" #include "GPS.h" #include <math.h> -#define PI 3.14159265 + void start_hello(void) { int len = get_kbd_str(pcbuf, PCBUF_SIZE); - printf("in start gps/hello\r\n"); + //printf("in start gps/hello\r\n"); if (len < 0) { fflush(stdout); Radio.Rx( RX_TIMEOUT_VALUE ); @@ -29,147 +28,22 @@ } else { - hello(); - } -} - -void find_distance() -{ - //float dist = 0; - float lat2 = 0; - float lon2 = 0; - float lat1 = 0; - float lon1 = 0; - float dLat = 0; - float dLon = 0; - float c = 0; - float a = 0; - float d = 0; - -#ifdef radfta - gpsd.distance = 0; - if (gpsd.l_latitude == 0.0) - { - gpsd.distance = -1; - return; - } - if (gpsd.l_longitude == 0.0) - { - gpsd.distance = -1; - return; - } - - //lat1 = 35.73244; - //lon1 = -78.79333; - - lat1 = gpsd.r_latitude; - lon1 = gpsd.r_longitude; - - lat2 = gpsd.l_latitude; - lon2 = gpsd.l_longitude; - //Calculate Distance - dLat = (lat2-lat1)*(PI/180); - dLon = (lon2-lon1)*(PI/180); - a = sin(dLat/2) * sin(dLat/2) + - sin(dLon/2) * sin(dLon/2) * cos(lat1*(PI/180)) * cos(lat2*(PI/180)); - c = 2 * atan2(sqrt(a), sqrt(1-a)); - d = 6371000 * c; - - //GPS is only precise to 5 meters, so throw out bad data - if ( d <= 5) { - d = 0; + hello(); } - gpsd.distance = gpsd.distance + d; - // printf("distance: %f\r\n", gpsd.distance); -#endif -} - -void check_gps(void) -{ - static int gps_count=0; -#ifdef radfta - if (gps_count >= 0) - { - //printf("checking gps\r\n"); - gps_count=0; // reset for next cycle - if(gpsd.sample()) - { - led = !led; - static int swap=0; - //printf("gps sample is true \r\n"); - if (gpsd.l_latitude != 0) - { - if (RADIO_INSTALLED) - { - cLCD.setCursor(0,1); - cLCD.printf("d:NA per:%d ", per); - //cLCD.printf("%0.4f %0.4f", gpsd.l_latitude, gpsd.l_longitude); - } - else - { - if (swap) - { - cLCD.setCursor(0,0); - cLCD.printf("Lat: %0.6f ", gpsd.l_latitude); - cLCD.setCursor(0,1); - cLCD.printf("Lon: %0.6f ", gpsd.l_longitude); - swap = 0; - } - else - { - cLCD.setCursor(0,1); - cLCD.printf("Lat: %0.6f ", gpsd.l_latitude); - cLCD.setCursor(0,0); - cLCD.printf("Lon: %0.6f ", gpsd.l_longitude); - swap = 1; - } - } - - if (gpsd.r_latitude != 0) - { - find_distance(); - if (gpsd.distance < 50000 ) - { - if (gpsd.distance >= 0) - cLCD.setCursor(0,1); - cLCD.printf("d:%0.1fm per:%d ", gpsd.distance,per); - } - } - } - else - { - cLCD.setCursor(0,1); - cLCD.printf("No GPS. per:%d ",per); - } - } - else - { - //printf("gps sample is false \r\n"); - cLCD.setCursor(0,1); - cLCD.printf("No GPS. per:%d ",per); - } - } - else - { - #if 0 - if (gps_count % 5) - gpsd.flushSerialBuffer(); - #endif - //printf("not checking gps\r\n"); - gps_count++; - } -#endif } void hello(void) { - srand ( randomSeed() ); + + // srand ( randomSeed() ); // generate a random wait time - int mywait = ((rand()%2 +1)); + // int mywait = ((rand()%2 +1)); + int mywait = 3; int i=0; int rcvd=0; int lost=0; - + + // check_gps(); for (i=0;i<max_pkts;i++) { @@ -201,8 +75,8 @@ printf("rx timeout in gps/hello loop. "); printf("per=%d\r\n", per); - // radfta gpsd.r_latitude = 0; - // radfta gpsd.r_longitude = 0; + r_latitude = 0; + r_longitude = 0; // printf("rcv - rssi = %d snr = %d msg=%s\r\n", RssiValue, SnrValue, BufferRx); cLCD.setCursor(0,0); cLCD.printf("RI:NA SR:NA "); @@ -212,7 +86,7 @@ { if( strncmp( ( const char* )BufferRx, ( const char* )HelloMsg, 5 ) == 0 ) { - led = !led; + // radfta led = !led; printf("rcv - rssi = %d snr = %d msg=%s ", RssiValue, SnrValue, BufferRx ); printf("per=%d\r\n", per); cLCD.setCursor(0,0); @@ -220,12 +94,11 @@ } else { - // float latitude, longitude; -#ifdef radfta - if(sscanf((char *)BufferRx, "GP,%f,%f", &gpsd.r_latitude, &gpsd.r_longitude ) >= 1) + + if(sscanf((char *)BufferRx, "GP,%f,%f", &r_latitude, &r_longitude ) >= 1) { - led = !led; - printf("rssi=%d snr=%d rlat=%0.5f rlon=%0.5f llat=%0.5f llon=%0.5f dst=%0.0fm ", RssiValue, SnrValue, gpsd.r_latitude, gpsd.r_longitude, gpsd.l_latitude, gpsd.l_longitude, gpsd.distance); + // 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); cLCD.setCursor(0,0); cLCD.printf("RI:%d SR:%d ", RssiValue,SnrValue); @@ -233,28 +106,21 @@ } else printf("strange received message: %s\r\n", BufferRx); -#else - cLCD.setCursor(0,0); - cLCD.printf("RI:%d SR:%d ", RssiValue,SnrValue); - printf("received message: %s\r\n", BufferRx); -#endif + } } case RX_ERROR: - if (gpsEnabled) - { - check_gps(); - } -#ifdef radfta + if (gpsEnabled) - sprintf((char *)BufferTx, "GP,%4.5f,%4.5f", gpsd.l_latitude, gpsd.l_longitude); + sprintf((char *)BufferTx, "GP,%4.5f,%4.5f", gpsd.lat_deg, gpsd.lon_deg); else -#else strcpy( ( char* )BufferTx, ( char* )HelloMsg ); -#endif +#if 0 +radfta BufferSize=strlen((char *)BufferTx); //printf("Sending new buffer\r\n"); Radio.Send( BufferTx, BufferSize ); +#endif State = LOWPOWER; break; @@ -271,7 +137,8 @@ State = LOWPOWER; break; case LOWPOWER: - wait_ms (5); + //printf("in wait\r\n"); + // wait_ms (1); break; default: debug("state is set to low power\r\n");