CaryCoders
/
demo_SX1276_standalone
standalone sx1276 demo program
Fork of SX1276_GPS by
Diff: main.cpp
- Revision:
- 33:319cbac3b6eb
- Parent:
- 32:a2472bbe7c92
diff -r a2472bbe7c92 -r 319cbac3b6eb main.cpp --- a/main.cpp Wed Jul 29 12:14:42 2015 +0000 +++ b/main.cpp Thu Sep 03 14:33:55 2015 +0000 @@ -1,8 +1,10 @@ #include "mbed.h" +#include "main.h" +#ifndef STANDALONE #include "lcdadafruit.h" +#include "GPS.h" +#endif #include "sx1276-hal.h" -#include "GPS.h" -#include "main.h" #include "debug.h" #include "serial_api.h" #include "datetime.h" @@ -11,9 +13,9 @@ #define USE_MODEM_LORA 1 -//#define RF_FREQUENCY 868000000 // Hz +#define RF_FREQUENCY 868000000 // Hz //#define RF_FREQUENCY 880030000 -#define RF_FREQUENCY 915000000.0 // Hz +//#define RF_FREQUENCY 914000000.0 // Hz //#define RF_FREQUENCY 413000000.0 // Hz @@ -30,7 +32,9 @@ float Frequency = RF_FREQUENCY; float distance = -1; float r_latitude = 0; +float r_latitude_last = 0; float r_longitude = 0; +float r_longitude_last = 0; int TxPower = TX_OUTPUT_POWER; int Bandwidth = LORA_BANDWIDTH; int SpreadingFactor = LORA_SPREADING_FACTOR; @@ -43,13 +47,16 @@ typedef RadioState States_t; volatile States_t State = LOWPOWER; +//SX1276MB1xAS Radio( OnTxDone, OnTxTimeout, OnRxDone, OnRxTimeout, OnRxError, NULL, OnCadDone ); SX1276MB1xAS Radio( OnTxDone, OnTxTimeout, OnRxDone, OnRxTimeout, OnRxError, NULL, NULL ); // for hand wired I2C cI2C(PTC9, PTC8); I2C cI2C(PTC9, PTC8); // for stacked shield I2C cI2C(PTC2, PTC1); //I2C cI2C(PTC2, PTC1); +#ifndef STANDALONE LCDadafruit cLCD(cI2C); GPS gpsd(PTE0,PTE1); +#endif // for other board GPS gpsd(PTE20, PTE21); @@ -67,7 +74,7 @@ int max_pkts = 20; int pkt_data[20]; int per = 0; -int tx_rate_us = 100000; // 1 second +int tx_rate_us = 1000000; // 1 second app_e app = APP_NONE; bool isMaster = true; bool AlwaysMaster = false; @@ -75,15 +82,24 @@ bool ackRcvd = true; bool rxTimeout = false; bool gpsEnabled = true; -InterruptIn PPS(PTA1); //pps IRQ +InterruptIn PPS(PTD7); //pps IRQ +DigitalOut RXin(PTD6); Ticker usec_tick; void tx_pkt() { led = !led; + BufferSize=strlen((char *)BufferTx); + #if 1 // printf("Buffersize = %d\r\n",BufferSize); - Radio.Send( BufferTx, BufferSize ); - //Radio.Rx( RX_TIMEOUT_VALUE / 1 ); + // Radio.Send( BufferTx, BufferSize ); + Radio.Rx( RX_TIMEOUT_VALUE / 1 ); +#else + // printf("calling start cat\r\n"); + // Radio.Send( BufferTx, BufferSize ); + // Radio.Rx( RX_TIMEOUT_VALUE / 1 ); + // Radio.StartCad(); +#endif } void ppsSync() @@ -95,15 +111,16 @@ { // detach the timer usec_tick.detach(); - printf("call attach\r\n"); - //wait_ms(500); + + wait_ms(500); usec_tick.attach_us(&tx_pkt, tx_rate_us); + // printf("call attach\r\n"); } else { if (pps_count > 10) { - pps_count = 1; + pps_count = 0; } } @@ -115,18 +132,22 @@ { int i; + RXin=0; Timer refresh_Timer; //sets up a timer for use in loop; how often do we print GPS info? const int refresh_Time = 1000; //refresh time in ms bool gpsFix=false; - gps_setup(); + pc.baud(9600); cI2C.frequency(400000); // I2C can handle two different frequencies - switch to high speed if asked + #ifndef STANDALONE + gps_setup(); cLCD.clear(); cLCD.home(); cLCD.setCursor(0,0); cLCD.printf(" HOMER "); cLCD.setCursor(0,1); cLCD.printf(" DOH! "); + #endif rxTimeout = false; // PTD1 (the SCK pin for the one SPI interface onboard the KL25z) is actually an output to the Blue LED. @@ -154,6 +175,8 @@ debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1LAS ) ) , "> Board Type: SX1276MB1LAS < \r\n" ); debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1MAS ) ) , "> Board Type: SX1276MB1MAS < \r\n" ); Radio.SetChannel( Frequency ); + // Radio.StartCad(); + // printf("start cad\r\n"); debug_if( !LORA_FHSS_ENABLED, "> LORA Mode < \r\n"); configRxTx(); @@ -171,6 +194,7 @@ Radio.Tx( TX_TIMEOUT_VALUE ); app = APP_HELLO; + //app = APP_CHAT; } else { @@ -178,17 +202,22 @@ pc.printf("Starting GPS App\r\n"); } - refresh_Timer.start(); //starts the clock on the timer - usec_tick.attach_us(&tx_pkt, tx_rate_us); // attach a timer to periodically call tx. this timer will be restarted in ppsSync to synronize timer accross systems - PPS.rise(&ppsSync); // call ppsSync when the PPS irq is detected - + refresh_Timer.start(); //starts the clock on the timer used for gps refreshes + // usec_tick.attach_us(&tx_pkt, tx_rate_us); // attach a timer to periodically call tx. this timer will be restarted in ppsSync to synronize timer accross systems + // PPS.rise(&ppsSync); // call ppsSync when the PPS irq is detected + // printf("start cad 2\r\n"); + // Radio.StartCad(); + while( 1 ) { +#ifndef STANDALONE + //printf("call check \r\n"); check_gps(); if (refresh_Timer.read_ms() >= refresh_Time) { - // printf("reset timer popped\r\n"); - if (gpsd.fix) { + //printf("reset timer popped\r\n"); + if (gpsd.fix) + { // got a gps fix if (gpsFix == false) { @@ -227,6 +256,7 @@ refresh_Timer.reset(); } +#endif switch (app) { case APP_PING: start_ping_pong(); @@ -235,9 +265,12 @@ console_chat(); break; case APP_GPS: +#ifndef STANDALONE check_gps(); +#endif break; case APP_HELLO: + wait(1); start_hello(); break; case APP_CONSOLE: