 
 Author:
     Terry Moore, MCCI Corporation   March 2019
-
-Description:
-    This sketch demonstrates use of the LMIC compliance-test mode. Tested
-    with an RWC5020A LoRaWAN Tester.
 
 */
 

    // Reset the MAC state. Session and pending data transfers will be discarded.
    LMIC_reset();

    // do the network-specific setup.
    setupForNetwork();

    // Start job (sending automatically starts OTAA too)
    do_send(&sendjob);
}

void setupForNetwork(void) {
#if defined(CFG_us915)
    LMIC_setLinkCheckMode(0);
    LMIC_setDrTxpow(DR_SF7, 14);
    LMIC_selectSubBand(1);
#endif
}

void loop() {
    os_runloop_once();
}

        ||     break;
        */
        case EV_JOIN_FAILED:
            // print out rx info
            Serial.print(F(":  freq=")); printFreq(e.freq);
            printRps(e.rps);
            Serial.print(F(" opmode=")); Serial.print(e.opmode, HEX);
            printf(" irqLevel %u", hal_getIrqLevel());

            do {
                uint8_t regbuf[0x80];
                regbuf[0] = 0;
                hal_spi_read(1, regbuf + 1, sizeof(regbuf) - 1);

                for (unsigned i = 0; i < sizeof(regbuf); ++i) {
                    if (i % 16 == 0) {
                        printf("\r\n%02x:", i);
                    }
                    printf("%s%02x", ((i % 16) == 8) ? " - " : " ", regbuf[i]);
                }

            hal_pin_rst(0);
            delay(2);
            hal_pin_rst(2);
            delay(6);

            const uint8_t opmode = 0x88;    // LoRa and sleep.
            hal_spi_write(0x81, &opmode, 1);

            } while (0);
            break;

        case EV_REJOIN_FAILED:
            // this event means that someone tried a rejoin, and it failed.
            // it doesn't really mean anything bad, it's just advisory.
            break;

        case EV_TXCOMPLETE:
            Serial.print(F(": ch "));
            Serial.print(e.txChnl);
            printRps(e.rps);
            Serial.print(F(" txrxflags 0x")); Serial.print(e.txrxFlags, HEX);
            if (e.txrxFlags & TXRX_ACK)
                Serial.print(F("; Received ack"));
            break;
        case EV_LOST_TSYNC:
            break;
        case EV_RESET:
            break;
        case EV_RXCOMPLETE:
            break;
        case EV_LINK_DEAD:
            break;
        case EV_LINK_ALIVE:
            break;
        /*
        || This event is defined but not used in the code. No
