![](/media/cache/profiles/ce7206100d5cf8e7bb691376c7d73526.jpg.50x50_q85.jpg)
An example project for the Heltec Turtle LoRa board (STM32L4 and SX1276 chips). The projects is only supported for the Nucleo-L432KC board platform in the mbed online and offline compiler environment. Visit www.radioshuttle.de (choose Turtle board) for instructions. Note that most source files and libraries are open source, however some files especially the RadioShuttle core protocol is copyrighted work. Check header for details.
Dependencies: mbed BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT
Diff: main.cpp
- Revision:
- 34:d3d60dbb84ea
- Parent:
- 30:8bc655c9b224
- Child:
- 35:9e799d093b7f
diff -r 617765dcce6c -r d3d60dbb84ea main.cpp --- a/main.cpp Tue Feb 12 16:54:21 2019 +0100 +++ b/main.cpp Tue Feb 12 17:07:02 2019 +0100 @@ -17,6 +17,8 @@ #include "NVProperty.h" #endif +void RunCommands(int timeout_ms); + DigitalOut statusLED(LED); DigitalOut redLED(LED2); InterruptIn buttonIntr(USER_BUTTON); @@ -34,10 +36,12 @@ else timeout.attach_us(&timerUpdate, 2000000); // setup to call timerUpdate after 2 seconds + redLED = ! redLED; InterrruptMSG(INT_TIMEOUT); } + int main() { /* * inits the Serial or USBSerial when available (230400 baud). @@ -48,51 +52,20 @@ InitSerial(30*1000, &statusLED); dprintf("Welcome to RadioShuttle v%d.%d", RS_MAJOR, RS_MINOR); dprintf("Voltage: %.2f (%s powered)", BatteryVoltage(), BatterySource()); - - char buf[32]; - - bool cmdLoop = true; - while(cmdLoop) { - rprintf("\r\nAvailable commands (p = Property Editor, r = Reset, q = Quit)\r\nwaiting 10 secs ...\r\n"); - rprintf("\r\n$ "); - if (ConsoleReadline(buf, sizeof(buf), true, 10000) == NULL) { - cmdLoop = false; - break; - } - switch(buf[0]) { - case 'p': - case 'P': -#ifdef FEATURE_NVPROPERTYEDITOR - NVPropertyEditor(); -#endif - break; - case 'q': - case 'Q': - cmdLoop = false; - break; - case 'r': - case 'R': - MCUReset(); - break; - default: - break; - } - } - -#ifdef FEATURE_LORA - InitRadio(); -#endif -#ifdef FEATURE_LORA_PING_PONG - DeInitRadio(); - SX1276PingPong(); // basic LoRa raw ping/pong without RadioShuttle -#endif - dprintf("InitDefaults Done"); timerUpdate(); // start timer #if defined (USER_BUTTON_RISE) // attach switchInput function to the rising or falling edge buttonIntr.rise(&switchInput); #else buttonIntr.fall(&switchInput); #endif + + RunCommands(10000); // check for any commands + +#ifdef FEATURE_LORA + InitRadio(); +#endif + + dprintf("InitDefaults Done"); /* * Main event loop, process interrupts and go to sleep @@ -102,7 +75,9 @@ while(true) { while ((readPendingInterrupts() == 0)) { statusLED = 0; +#ifdef FEATURE_USBSERIAL if (!(usb && usb->connected())) +#endif sleep(); statusLED = 1; } @@ -120,7 +95,75 @@ #endif } if (pendirqs & INT_TIMEOUT) { - redLED = ! redLED; } } } + +static const char *cmds = \ + "\r\nThe following commands are available:\r\n\r\n" \ + " p -- Property Editor\r\n" \ + " t -- LoRa PingPong Test\r\n" \ + " d -- Hexdump of memory address [offset count]" + " r -- Reset\r\n" \ + " c -- Continue with RadioShuttle\r\n" \ + "\r\n" \ + "waiting 10 secs ...\r\n" \ + "\r\n"; + +void RunCommands(int timeout_ms) { + bool cmdLoop = true; + while(cmdLoop) { + char buf[32]; + + rprintf(cmds); + rprintf("Turtle$ "); + if (ConsoleReadline(buf, sizeof(buf), true, timeout_ms) == NULL) { + cmdLoop = false; + break; + } + switch(buf[0]) { + case 'p': + case 'P': +#ifdef FEATURE_NVPROPERTYEDITOR + NVPropertyEditor(); +#endif + break; + case 't': + case 'T': +#ifdef FEATURE_LORA_PING_PONG + SX1276PingPong(); // basic LoRa raw ping/pong without RadioShuttle +#endif + break; + case 'r': + case 'R': + MCUReset(); + break; + case 'd': + case 'D': + { + char *addr = strchr(buf, ' '); + if (addr) { + *addr++ = 0; + char *length = strchr(addr, ' '); + if (length) { + *length++ = 0; + } + unsigned long address = strtoll(addr, NULL, 0); + unsigned long cnt = 32; + if (length) + cnt = strtoll(length, NULL, 0); + dump("Hexdump", (void *)address, cnt); + } + } + break; + case 'c': + case 'C': + cmdLoop = false; + break; + default: + break; + } + } + rprintf("\r\n"); + +}