This is an example program that shows how to use the RadioHeadLite library, and does it using threads.
Dependencies: RadioHeadLite
Diff: main.cpp
- Revision:
- 2:57fefd8ae87c
- Parent:
- 1:75d533f15c95
- Child:
- 3:fd3a7f10eed3
--- a/main.cpp Mon Nov 26 21:01:04 2018 +0000 +++ b/main.cpp Thu May 16 15:21:41 2019 +0000 @@ -1,209 +1,81 @@ #include "mbed.h" #include "USBSerial.h" -#include "Geneva.h" -#define PASSTHROUGH 0 +#define GNSSEN PC_3 +#define GNSSTXD PA_9 +#define GNSSRXD PA_10 +#define GNSSBAUD 9600 /******************** Comms *********************/ -USBSerial pc; // moved the pc interface to the USB serial device -UARTSerial modemUartSerial(MDMTXD, MDMRXD, 115200); +USBSerial pc; +//FileHandle* mbed::mbed_override_console(int) +//{ +// return &pc; +//} + +UARTSerial radio(GNSSTXD, GNSSRXD, 9600); -DigitalInOut cellRst(MDMRST); -DigitalInOut cellPwrKey(MDMPWRON); -DigitalOut cellVcc(MDMVCC, 0); -DigitalOut cellRts(MDMRTS, 0); // Flow control not supported by 410, but RTS must be low -DigitalOut cellCts(MDMCTS, 0); - -DigitalOut gpsEn(PC_3, 0); -DigitalOut bleRst(PB_5, 0); +DigitalOut gpsEn(GNSSEN, 1); -DigitalOut greenLed(LED_GREEN, 1); -DigitalOut blueLed(LED_BLUE, 1); -DigitalOut redLed(LED_RED, 1); - -InterruptIn buttonInt(USER_BUTTON); - -InterruptIn *rxPin; -DigitalOut samplePin(PA_0); Thread myThread; -static char scanBuffer[512]; -static bool buttonWasPushed = false; + -typedef struct +void sendToModem(void) { - DigitalOut *resetPin; - DigitalOut *enablePin; - DigitalOut *dtrPin; - FileHandle *fileHandle; - ATCmdParser *rawParser; - UARTSerial *serial; -} cellContext_t; - -cellContext_t cell; - -char buffer[64]; - -static void buttonPushed(void) -{ - buttonWasPushed = true; + char c; + c = pc.getc(); + radio.write(&c, 1);// push the charcter to the modem } -#if PASSTHROUGH +void sendToPC(void) +{ + char c; + radio.read(&c, 1); + pc.putc(c); +} + + static void passthroughThread(void) { - char c; - pc.printf("Passthrough mode\r\n"); - blueLed = 0; +// pc.attach(&sendToModem); while (1) { // Housekeeping - check button if (pc.readable()) { - c = pc.getc(); - modemUartSerial.write(&c, 1);// push the charcter to the modem + sendToModem(); } - if (modemUartSerial.readable()) + if (radio.readable()) { - modemUartSerial.read(&c, 1); - pc.putc(c); + sendToPC(); } } } -#else -static void autoModeThread(void) -{ - pc.printf("Auto mode\r\n", 11); - - cell.fileHandle = &modemUartSerial; - cell.rawParser = new ATCmdParser(cell.fileHandle); - cell.rawParser->flush(); - cell.rawParser->debug_on(1); - cell.rawParser->set_timeout(2000); - - while (1) - { - cell.rawParser->send("AT"); - if (cell.rawParser->recv("OK")) - break; - wait(1.5); - } - - redLed = 1; - blueLed = 0; - pc.printf("Modem OK\r\n"); - wait(5); - - cell.rawParser->set_timeout(15000); - - while (1) - { - cell.rawParser->send("AT+CCID"); - if (cell.rawParser->recv("OK")) - { - break; - } - wait(4.5); - } - blueLed = 1; - greenLed = 0; - pc.printf("SIM OK\r\n"); - wait(2); - int act; - char plmn[8]; - bool result; - - cell.rawParser->set_timeout(20000); - cell.rawParser->send("AT+CMEE=2") && cell.rawParser->recv("OK"); - - while (1) - { - cell.rawParser->send("AT+COPS?"); - result = cell.rawParser->recv("+COPS: %[^\n]\nOK\n", scanBuffer); - if (true == result) - { - // Parse the registration status - if (sscanf(scanBuffer, "%*d, %*d, \"%[^\"]\", %d", plmn, &act) == 2) - { - if (act == 8) - break; - } - } - wait(3); - } - - pc.printf("Network OK\r\n"); - - while (1) - { - greenLed = 1; - wait(0.75); - greenLed = 0; - wait(0.75); - if (buttonWasPushed) - break; - } - - cell.rawParser->send("AT+COPS=2") && cell.rawParser->recv("OK"); -} -#endif void setup(void) { - // Enable flow control on MDM uart - //modemUartSerial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); - - buttonInt.mode(PullUp); - buttonInt.fall(buttonPushed); - - cellRst.mode(OpenDrainNoPull); - cellRst.output(); - cellRst = 1; - - cellPwrKey.mode(OpenDrainNoPull); - cellPwrKey.output(); - cellPwrKey = 1; - wait(1); // wait just a bit for the USB to enumerate - pc.printf("Modem Test\r\n", 12); pc.set_blocking(false); - modemUartSerial.set_blocking(false); - - // Power up the modem! - cellVcc = 1; - pc.printf("Modem VCC UP\r\n", 14); - wait(3); + radio.set_blocking(false); - cellPwrKey = 0; - wait(0.9); - cellPwrKey = 1; - pc.printf("Modem Power\r\n", 13); - - redLed = 0; - - wait(5); -} + wait(1); +} int main(void) { setup(); -#if PASSTHROUGH myThread.start(passthroughThread); -#else - myThread.start(autoModeThread); -#endif - - Thread::wait(osWaitForever); return 1; }