Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SX1276_GPS by
hello.cpp
- Committer:
- ftagius
- Date:
- 2015-07-29
- Revision:
- 32:a2472bbe7c92
- Parent:
- 31:2c813f321db7
- Child:
- 33:319cbac3b6eb
File content as of revision 32:a2472bbe7c92:
#include "mbed.h"
#include "sx1276-hal.h"
#include "main.h"
#include "debug.h"
#include "serial_api.h"
#include "GPS.h"
#include <math.h>
void start_hello(void)
{
int len = get_kbd_str(pcbuf, PCBUF_SIZE);
//printf("in start gps/hello\r\n");
if (len < 0) {
fflush(stdout);
Radio.Rx( RX_TIMEOUT_VALUE );
Radio.Tx( TX_TIMEOUT_VALUE );
Radio.Sleep( );
if (gpsEnabled)
debug("GPS exchange ended\r\n");
else
debug("Hello exchange ended\r\n");
app = APP_CONSOLE;
print_help();
printf("> ");
fflush(stdout);
return;
}
else
{
hello();
}
}
void hello(void)
{
// srand ( randomSeed() );
// generate a random wait time
// 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++)
{
if (pkt_data[i]==1)
{
//printf("rcvd, pkt count=%d\r\n",i);
rcvd++;
}
else if (pkt_data[i] == 2)
{
//printf("lose, pkt count=%d\r\n",i);
lost++;
}
}
if ((rcvd + lost) > 0)
{
per = 100 - (rcvd*100 / (rcvd + lost));
//printf("rcvd = %d, lost = %d per = %d\r\n",rcvd, lost, per);
}
else
per = 0;
switch( State )
{
case RX_TIMEOUT:
printf("rx timeout in gps/hello loop. ");
printf("per=%d\r\n", per);
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 ");
case RX:
if( BufferSize > 0 )
{
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);
cLCD.setCursor(0,0);
cLCD.printf("RI:%d SR:%d ", RssiValue, SnrValue);
}
else
{
if(sscanf((char *)BufferRx, "GP,%f,%f", &r_latitude, &r_longitude ) >= 1)
{
// 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);
//printf("Msg received - Lat: %0.4f Lon: %0.4f\r\n", latitude, longitude);
}
else
printf("strange received message: %s\r\n", BufferRx);
}
}
case RX_ERROR:
if (gpsEnabled)
sprintf((char *)BufferTx, "GP,%4.5f,%4.5f", gpsd.lat_deg, gpsd.lon_deg);
else
strcpy( ( char* )BufferTx, ( char* )HelloMsg );
#if 0
radfta
BufferSize=strlen((char *)BufferTx);
//printf("Sending new buffer\r\n");
Radio.Send( BufferTx, BufferSize );
#endif
State = LOWPOWER;
break;
case TX:
//printf("tx state\r\n");
//wait_ms (30);
Radio.Rx( RX_TIMEOUT_VALUE / mywait );
State = LOWPOWER;
break;
case TX_TIMEOUT:
debug("tx timeout\r\n");
Radio.Tx( TX_TIMEOUT_VALUE );
State = LOWPOWER;
break;
case LOWPOWER:
//printf("in wait\r\n");
// wait_ms (1);
break;
default:
debug("state is set to low power\r\n");
State = LOWPOWER;
break;
}
}
