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 wayne roberts

See wiki Page for a detailed

This is a link to the wiki page

Revision:
5:329557e0625c
Parent:
4:1efa46cff1b3
Child:
6:8defa260bc10
--- a/main.cpp	Mon Feb 09 23:27:58 2015 +0000
+++ b/main.cpp	Mon Apr 13 23:05:15 2015 +0000
@@ -23,6 +23,8 @@
 GPS gps;
 DigitalOut pd2(PD_2);
 DigitalOut hdr_fem_ctx(PC_7);
+DigitalOut hdr_fem_csd(PC_0);
+DigitalOut sx9500_txen(PA_9);
 
 DigitalOut red_led(PB_1);
 DigitalOut green_led(PB_7);
@@ -43,7 +45,7 @@
 float hop_base_MHz = 902.3;
 float hop_step_MHz = 0.2;
 
-
+bool abort_key;
 bool per_en;
 int PacketRxSequencePrev;
 uint32_t PacketPerKoCnt;
@@ -106,6 +108,7 @@
         } else {
             // todo: sx1276
         }
+        hdr_fem_csd = 1;    //debug
     } else if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_CAD) { // start of reception
         if (radio.HF) {
             rfsw2 = 1;
@@ -113,9 +116,11 @@
         } else {
             // todo: sx1276
         }
+        hdr_fem_csd = 0;    //debug
     } else { // RF switch shutdown
         rfsw2 = 0;
-        rfsw1 = 0;              
+        rfsw1 = 0;     
+        hdr_fem_csd = 0;    //debug         
     }
 }
 
@@ -474,9 +479,6 @@
 
     printf("\r\n");
     lora_printAgcAutoOn();
-    if (radio.type == SX1272) {
-        printf(" LowDataRateOptimize:%d\r\n", lora.RegModemConfig.sx1272bits.LowDataRateOptimize);
-    }
 
     printf("\r\nHeaderCount:%d PacketCount:%d, ",
         radio.read_u16(REG_LR_RXHEADERCNTVALUE_MSB), radio.read_u16(REG_LR_RXPACKETCNTVALUE_MSB));
@@ -705,7 +707,9 @@
         printf("On ");
     else
         printf("OFF ");
-    if (!fsk.RegRxConfig.bits.AgcAutoOn) {
+    if (fsk.RegRxConfig.bits.AgcAutoOn) {
+        printf("AgcAutoOn ");
+    } else {
         radio.RegLna.octet = radio.read_reg(REG_LNA);
         printf("AgcAutoOff:G%d ", radio.RegLna.bits.LnaGain);
     }
@@ -989,6 +993,29 @@
     clear_valid_header = true;
 }
 
+bool lora_sync_sweep_hi;
+uint8_t lora_sync_byte;
+void lora_sync_sweep()
+{
+    if (abort_key) {
+        abort_key = false;
+        return;
+    }
+    
+    hop_timeout.attach(&lora_sync_sweep, 0.1);
+    if (lora_sync_sweep_hi) {
+        lora_sync_byte += 0x10;
+    } else {
+        if ((lora_sync_byte & 0x0f) == 0x0f)
+            lora_sync_byte &= 0xf0;
+        else
+            lora_sync_byte++;
+    }
+     printf("%02x\r\n", lora_sync_byte);
+    radio.write_reg(REG_LR_SYNC_BYTE, lora_sync_byte);
+    
+    lora.start_tx(lora.RegPayloadLength);
+}
 
 float hop_MHz;
 bool new_hop;
@@ -1131,6 +1158,7 @@
                 break;
             case SERVICE_TX_DONE:
                 red_led = LED_OFF;
+                hdr_fem_csd = 0;    //debug
                 if (app == APP_CHAT) {
                     lora.start_rx();
                 } else if (per_en)
@@ -1211,6 +1239,7 @@
             } else if (c == 3) {
                 // ctrl-C abort
                 per_en = false;
+                abort_key = true;
                 return -1;
             } else if (i < size) {
                 buf[i++] = c;
@@ -1327,7 +1356,7 @@
                 break;
             case 'L':  
                 if (radio.RegOpMode.bits.LongRangeMode)
-                    fsk.enable();
+                    fsk.enable(false);
                 else
                     lora.enable();
 
@@ -1430,6 +1459,7 @@
                     printf("mp          FSK toggle MapPreambleDetect\r\n");
                     printf("ar          FSK change AutoRestartRxMode\r\n");
                     printf("alc          FSK toggle AfcAutoClearOn\r\n");
+                    printf("ag          FSK toggle AgcAutoOn\r\n");
                     printf("pre[%%d}    FSK get-set TX preamble length\r\n");
                 }
                 break;
@@ -1615,7 +1645,29 @@
         } /*else if (pcbuf[0] == 'm' && pcbuf[1] == 'p' && pcbuf[2] == 'l') {
             mpl3115a2.try_read();
         }*/ else if (pcbuf[0] == '9' && pcbuf[1] == '5') {
-            sx9500.try_read();
+            if (pcbuf[2] == '?') {
+                printf("95R     reset\n");
+                printf("95s     read sensor\n");
+                printf("95.     read status\n");
+                printf("95S     put to sleep\n");
+            } else if (pcbuf[2] == '.') {
+                printf("RegIrqSrc:%02x\n", sx9500.read_single(SX9500_REG_IRQSRC));
+                printf("RegStat:%02x\n", sx9500.read_single(SX9500_REG_STAT));
+                printf("RegProxCtrl0:%02x\n", sx9500.read_single(SX9500_REG_PROXCTRL0));
+                printf("RegProxCtrl1:%02x\n", sx9500.read_single(SX9500_REG_PROXCTRL1));
+                printf("RegProxCtrl2:%02x\n", sx9500.read_single(SX9500_REG_PROXCTRL2));
+                printf("RegProxCtrl3:%02x\n", sx9500.read_single(SX9500_REG_PROXCTRL3));
+                printf("RegProxCtrl4:%02x\n", sx9500.read_single(SX9500_REG_PROXCTRL4));
+                printf("RegProxCtrl5:%02x\n", sx9500.read_single(SX9500_REG_PROXCTRL5));
+                printf("RegProxCtrl6:%02x\n", sx9500.read_single(SX9500_REG_PROXCTRL6));
+            } else if (pcbuf[2] == 's') {
+                printf("sensor:%d\n", sx9500.get_sensor());
+            } else if (pcbuf[2] == 'R') {
+                sx9500.reset();
+            } else if (pcbuf[2] == 'S') {
+                sx9500.write(SX9500_REG_PROXCTRL0, 0);  // put SENSOREN=0
+                printf("sx9500 sleep\r\n");
+            }        
         } 
 #endif /* !I2C_PIN_TEST */
         else if (pcbuf[0] == 'm' && pcbuf[1] == 'p' && !radio.RegOpMode.bits.LongRangeMode) {
@@ -1645,6 +1697,10 @@
             lora.RegModemConfig.octet = radio.read_reg(REG_LR_MODEMCONFIG);
             lora_printHeaderMode();
             printf("\r\n");
+        } else if (pcbuf[0] == 'a' && pcbuf[1] == 'g' && !radio.RegOpMode.bits.LongRangeMode) {
+            fsk.RegRxConfig.bits.AgcAutoOn ^= 1;
+            radio.write_reg(REG_FSK_RXCONFIG, fsk.RegRxConfig.octet);
+            printf("AgcAutoOn:%d\r\n", fsk.RegRxConfig.bits.AgcAutoOn);            
         } else if (pcbuf[0] == 'a' && pcbuf[1] == 'l' && !radio.RegOpMode.bits.LongRangeMode) {
             fsk.RegAfcFei.bits.AfcAutoClearOn ^= 1;
             printf("AfcAutoClearOn: ");
@@ -1747,14 +1803,24 @@
             for (i = 0; i <= fsk.RegSyncConfig.bits.SyncSize; i++)
                 printf("%02x ", radio.read_reg(REG_FSK_SYNCVALUE1+i));
             printf("\r\n");
-        } else if (pcbuf[0] == 's' && pcbuf[1] == 's' && !radio.RegOpMode.bits.LongRangeMode) {
-            if (pcbuf[2] >= '0' && pcbuf[2] <= '9') {
-                sscanf(pcbuf+2, "%d", &i);
-                fsk.RegSyncConfig.bits.SyncSize = i;
-                radio.write_reg(REG_FSK_SYNCCONFIG, fsk.RegSyncConfig.octet);
+        } else if (pcbuf[0] == 's' && pcbuf[1] == 's') {
+            if (radio.RegOpMode.bits.LongRangeMode) { // sweep test on lora sync
+                if (pcbuf[2] == 'h') { // sweep high nibble
+                    lora_sync_sweep_hi = 1;
+                } else if (pcbuf[2] == 'l') { // sweep low nibble
+                    lora_sync_sweep_hi = 0;
+                }
+                lora_sync_byte = radio.read_reg(REG_LR_SYNC_BYTE);
+                hop_timeout.attach(&lora_sync_sweep, 0.1);
+            } else {
+                if (pcbuf[2] >= '0' && pcbuf[2] <= '9') {
+                    sscanf(pcbuf+2, "%d", &i);
+                    fsk.RegSyncConfig.bits.SyncSize = i;
+                    radio.write_reg(REG_FSK_SYNCCONFIG, fsk.RegSyncConfig.octet);
+                }
+                fsk.RegSyncConfig.octet = radio.read_reg(REG_FSK_SYNCCONFIG);
+                printf("SyncSize:%d\r\n", fsk.RegSyncConfig.bits.SyncSize);
             }
-            fsk.RegSyncConfig.octet = radio.read_reg(REG_FSK_SYNCCONFIG);
-            printf("SyncSize:%d\r\n", fsk.RegSyncConfig.bits.SyncSize);
         } else if (pcbuf[0] == 's' && pcbuf[1] == 'f' && radio.RegOpMode.bits.LongRangeMode) {
             if (pcbuf[2] >= '0' && pcbuf[2] <= '9') {
                 sscanf(pcbuf+2, "%d", &i);
@@ -1767,6 +1833,9 @@
             lora.RegModemConfig2.octet = radio.read_reg(REG_LR_MODEMCONFIG2);
             lora_printSf();
             printf("\r\n");
+        } else if (pcbuf[0] == 'f' && pcbuf[1] == 'i' && !radio.RegOpMode.bits.LongRangeMode) {
+            fsk.init();
+            printf("fsk.init\r\n");
         } else if (pcbuf[0] == 'f' && pcbuf[1] == 'd' && pcbuf[2] == 'e' && !radio.RegOpMode.bits.LongRangeMode) {
             if (pcbuf[4] >= '0' && pcbuf[4] <= '9') {
                 sscanf(pcbuf+4, "%d", &i);
@@ -1892,11 +1961,11 @@
                     break;
                 case '4':
                     radio.RegDioMapping2.bits.Dio4Mapping++;
-                    radio.write_reg(REG_DIOMAPPING1, radio.RegDioMapping2.octet);
+                    radio.write_reg(REG_DIOMAPPING2, radio.RegDioMapping2.octet);
                     break; 
                 case '5':
                     radio.RegDioMapping2.bits.Dio5Mapping++;
-                    radio.write_reg(REG_DIOMAPPING1, radio.RegDioMapping2.octet);
+                    radio.write_reg(REG_DIOMAPPING2, radio.RegDioMapping2.octet);
                     break;                                                                                             
             } // ...switch (pcbuf[1])
             if (radio.RegOpMode.bits.LongRangeMode)
@@ -1943,6 +2012,8 @@
     
     if (radio.RegOpMode.bits.LongRangeMode)
         last_RxCurrentAddr = radio.read_reg(REG_LR_FIFORXCURRENTADDR);
+        
+    sx9500_txen = 0;
 
     while(1) {
         switch (app) {