NAMote72 Utility Application – Serial Terminal Monitor control for NAMote72 (note: this application replaces the previous na_mote1 test code application)
Dependencies: SX127x lib_gps lib_mma8451q lib_mpl3115a2 lib_sx9500 mbed
Fork of na_mote1 by
See wiki Page for a detailed
This is a link to the wiki page
Diff: main.cpp
- Revision:
- 4:1efa46cff1b3
- Parent:
- 3:8924027a8933
- Child:
- 5:329557e0625c
diff -r 8924027a8933 -r 1efa46cff1b3 main.cpp --- a/main.cpp Fri Oct 31 22:52:58 2014 +0000 +++ b/main.cpp Mon Feb 09 23:27:58 2015 +0000 @@ -29,8 +29,6 @@ #define LED_ON 0 #define LED_OFF 1 -//volatile uint32_t dio2_cnt = 0; -//InterruptIn dio2(PC_11); Timeout hop_timeout; InterruptIn dio3(PC_8); @@ -66,24 +64,6 @@ app_e app = APP_NONE; -#if 0 -const uint32_t frfs[] = { /* frequency hopping table */ - MHZ_TO_FRF(903.0), - MHZ_TO_FRF(904.0), - MHZ_TO_FRF(905.0), - MHZ_TO_FRF(906.0), - MHZ_TO_FRF(907.0), - MHZ_TO_FRF(908.0), - MHZ_TO_FRF(909.0), - MHZ_TO_FRF(910.0), - MHZ_TO_FRF(911.0), - MHZ_TO_FRF(912.0), - MHZ_TO_FRF(913.0), - MHZ_TO_FRF(914.0), - MHZ_TO_FRF(915.0) -}; -#endif /* #if 0 */ - #define FSK_LARGE_PKT_THRESHOLD 0x3f /******************************************************************************/ @@ -104,12 +84,41 @@ #define RFSW2 PC_13 //NorAm_Mote RFSwitch_CNTR_2 // pin: 3 8 1 7 10 12 5 20 18 -// mosi, miso, sclk, cs, rst, dio0, dio1, fctx, fcps -//SX127x radio(D11, D12, D13, D10, D7, D2, D3, D8, D9); // nucleo-L152RE -SX127x radio(RADIO_MOSI, RADIO_MISO, RADIO_SCLK, RADIO_NSS, RADIO_RESET, RADIO_DIO_0, RADIO_DIO_1, RFSW1, RFSW2); // NA-mote +// mosi, miso, sclk, cs, rst, dio0, dio1 +SX127x radio(RADIO_MOSI, RADIO_MISO, RADIO_SCLK, RADIO_NSS, RADIO_RESET, RADIO_DIO_0, RADIO_DIO_1); SX127x_fsk fsk(radio); SX127x_lora lora(radio); +DigitalOut rfsw1(RFSW1); +DigitalOut rfsw2(RFSW2); + +void rfsw_callback() +{ + if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) { // start of transmission + if (radio.HF) { + if (radio.RegPaConfig.bits.PaSelect) { // if PA_BOOST + rfsw2 = 0; + rfsw1 = 1; + } else { // RFO to power amp + rfsw2 = 1; + rfsw1 = 0; + } + } else { + // todo: sx1276 + } + } else if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_CAD) { // start of reception + if (radio.HF) { + rfsw2 = 1; + rfsw1 = 1; + } else { + // todo: sx1276 + } + } else { // RF switch shutdown + rfsw2 = 0; + rfsw1 = 0; + } +} + void printLoraIrqs_(bool clear) { //in radio class -- RegIrqFlags_t RegIrqFlags; @@ -1034,7 +1043,7 @@ printf("\r\n"); } -void print_rx_verbose() +void print_rx_verbose(uint8_t len) { float dbm; printLoraIrqs_(false); @@ -1049,7 +1058,7 @@ lora.RegPktSnrValue / 4.0, dbm ); - print_rx_buf(lora.RegRxNbBytes); + print_rx_buf(/*lora.RegRxNbBytes*/len); } void @@ -1064,6 +1073,7 @@ switch (act) { case SERVICE_READ_FIFO: green_led = LED_OFF; // ValidHeader indication + if (app == APP_NONE) { if (per_en) { if (lora.RegRxNbBytes > 8 && radio.rx_buf[5] == 'P' && radio.rx_buf[6] == 'E' && radio.rx_buf[7] == 'R') { @@ -1096,10 +1106,10 @@ printf("per:%f\n", per); } else { PacketNormalCnt++; - print_rx_verbose(); + print_rx_verbose(lora.RegRxNbBytes); } } else - print_rx_verbose(); + print_rx_verbose(lora.RegRxNbBytes); } else if (app == APP_CHAT) { if (lora.RegHopChannel.bits.RxPayloadCrcOn) { if (lora.RegIrqFlags.bits.PayloadCrcError) @@ -1236,7 +1246,8 @@ } } - +uint8_t last_RxCurrentAddr; +uint8_t last_RxNbBytes; void console() @@ -1535,9 +1546,10 @@ PacketPerOkCnt = 0; dio3.rise(&dio3_cb); } - if (radio.RegOpMode.bits.LongRangeMode) + if (radio.RegOpMode.bits.LongRangeMode) { + last_RxCurrentAddr = radio.read_reg(REG_LR_FIFORXCURRENTADDR); lora.start_rx(); - else + } else fsk.start_rx(); } else if (pcbuf[0] == 'r' && pcbuf[1] == ' ') { // read single register sscanf(pcbuf+2, "%x", &i); @@ -1922,13 +1934,15 @@ pc.baud(57600); gps.init(); - - //radio.frfs = frfs; printf("\nreset\n"); green_led = LED_OFF; red_led = LED_OFF; + radio.rf_switch.attach(rfsw_callback); + + if (radio.RegOpMode.bits.LongRangeMode) + last_RxCurrentAddr = radio.read_reg(REG_LR_FIFORXCURRENTADDR); while(1) { switch (app) {