arm studio build

Dependencies:   libxDot-mbed5

Revision:
31:4539c212ecaa
Parent:
29:b3e9a0477d96
--- a/src/main.cpp	Wed Jul 29 01:25:20 2020 +0000
+++ b/src/main.cpp	Wed Jul 29 05:38:19 2020 +0000
@@ -221,7 +221,7 @@
     dot->setLinkCheckThreshold(link_check_treshold);
 //----------------------------------------------------------------------------------------------------------------------------------------------
     eui = mts::Text::bin2hexString(dot->getDeviceId()).c_str();
-    if(verbose)pc.printf("\r\nEUI: %s\r\n",eui);
+    //if(verbose)pc.printf("\r\nEUI: %s\r\n",eui);
     bool joined = false;
 
     i2c_proc_init();  //init i2c comm
@@ -268,7 +268,7 @@
                 if (bListen4Multicast) {                //in ClassC and receiving multicst pkt, stay here until timeout or bListen4Multicast false
                     if(verbose)pc.printf("\n\r changed to class C\r\n");
                     while(bListen4Multicast) { //stay in mcast bListen4Mutlicast =0, xdot exits -> classA when terminating mcast frag# received else psoc resets xdot
-                        wait(1);
+                        wait_us(1000*1000);
                     }
                 }
                 sleep_wake_interrupt_only(deep_sleep);   //sleep until rising edge of wake signal from proc
@@ -277,11 +277,12 @@
                 #endif
                 if(verbose)pc.printf("\n\r lora wake detected -> monitoring i2c bus\n\r ");
                 break;
-            case I2C_READ:      //psoc -> xdot i2c write
+            case I2C_READ:      //psoc -> xdot i2c write            
                 bPulseLoraWake = true;
                 switch (buf_rcv[0]) {               //switch on command #
                     case XDOT_CMD_XMIT_PKT:         //transmit data pkt                 
                     case XDOT_CMD_GET_GPS:          //get gps time stamp                      //GPS TIME !!!!!!!!!!!!!  
+                    {
                         bool bGpsTimeRequest     = false;                                              
                         bool bOk2XmitFullPayload = true;  //if false we only transmit the mac data
                         pkt_upstrm  *pUp= (pkt_upstrm*)&buf_rcv[0];            //psoc i2c pkt
@@ -465,7 +466,9 @@
                             }
                         }//if joined
                         break;
+                    }    
                     case XDOT_CMD_SET_RADIO:
+                    {
                         if(verbose)pc.printf("\n\r proc cmd: CMD_SET_RADIO");
                         pkt_setradiodwn *pDwnRadio= (pkt_setradiodwn*)&buf_xmt[0];
                         pkt_setradioup  *pUpRadio = (pkt_setradioup*)&buf_rcv[0];
@@ -523,10 +526,10 @@
                         pDwnRadio->params.dataRateCurrent = dot->getSettings()->Session.TxDatarate;  //presently used data rate (adr can change this);see Lora.h
                         pDwnRadio->params.txPowerCurrent = dot->getSettings()->Session.TxPower;//presently used tx power  (adr can change this);see Lora.h
                         pDwnRadio->params.rx1DelayCurrent = dot->getSettings()->Session.RxDelay;//presently used rx1_delay;see Lora.h
-
-
                         break;
+                    }    
                     case XDOT_CMD_GET_EUI:   //0307: modified to include radio parameter settings
+                    {
                         if(verbose)pc.printf("\n\r proc cmd: get EUI");
                         pkt_eui *peui = (pkt_eui*)&buf_xmt[0];
                         peui->ack = I2C_ACK_PROC;
@@ -540,10 +543,12 @@
                         peui->dataLen = sizeof(pkt_eui)-3;  //size of struc minus first 3 bytes
                         if(verbose)pc.printf("\n\r eui data length: %d",peui->dataLen);
                         break;
+                    }    
                     case XDOT_CMD_GET_LORAN_VER:
+                    {
                         if(verbose)pc.printf("\n\r proc cmd: get lorawan version");                        
                         sLoraVersion =  dot->getMtsLoraId();                        
-                        if(verbose)printf("\r\nLoraVersion: %s\r\n",sLoraVersion);         
+                        //if(verbose)printf("\r\nLoraVersion: %s\r\n",sLoraVersion);         
                         pkt_eui *plorawan = (pkt_eui*)&buf_xmt[0];
                         plorawan->ack = I2C_ACK_PROC;
                         plorawan->cmd = XDOT_CMD_GET_LORAN_VER;
@@ -555,8 +560,10 @@
                             i++;
                         }
                         plorawan->euiData[i] = 0;    
-                        break;    
+                        break; 
+                    }       
                     case XDOT_CMD_NVM:
+                    {
                         if(verbose)pc.printf("\n\r proc cmd: NVM OTAA");
                         pkt_setnvmup  *pUpNvm = (pkt_setnvmup*)&buf_rcv[0];
                         pkt_setnvmdwn *pDwnNvm= (pkt_setnvmdwn*)&buf_xmt[0];
@@ -571,7 +578,9 @@
                             pDwnNvm->bChkSumOK = 1;
                         printNmvData(&pDwnNvm->nvmData);
                         break;
+                    }    
                     case XDOT_CMD_RESTORE_SESSION:  //restore OTAA session
+                    {
                         dot->restoreNetworkSession();
                         dot->setDownLinkCounter(0); //reset frame counters
                         dot->setUpLinkCounter(0);
@@ -581,9 +590,11 @@
                         pDwnRstSession->bSetNetwrk = 1;
                         pDwnRstSession->dataLen = sizeof(pkt_ntwrk)-2;
                         if(verbose)pc.printf("\n\r OTAA network session restored\r\n");
-                        wait_ms(I2C_MIN_WAIT_DELAY);
+                        wait_us(1000*I2C_MIN_WAIT_DELAY);
                         break;
+                    }    
                     case XDOT_CMD_SET_RADIO_CLASS:  //multicast_change_class A or C (change only after a join!)
+                    {
                         if(verbose)pc.printf("\n\r proc cmd: change radio class\r\n");
                         pkt_setClassUp  *pUpSetClass =  (pkt_setClassUp*)&buf_rcv[0];
                         pkt_setClassDwn *pDwnSetClass = (pkt_setClassDwn*)&buf_xmt[0];
@@ -597,9 +608,10 @@
                         }
                         pDwnSetClass->bSwitched = bOk;
                         break;
-
+                    }
 
                     case XDOT_CMD_SET_NTWKSESS:  //read or write network session to xdot flash
+                    {
                         bool bWriteSession = (bool)buf_rcv[1];
                         if (bWriteSession) {
                             if(verbose)pc.printf("\n\r proc cmd writing network sesion to flash");
@@ -613,6 +625,7 @@
                         pktwrk->cmd = XDOT_CMD_SET_NTWKSESS;
                         pktwrk->bSetNetwrk = (uint8_t)bWriteSession;
                         break;
+                    }    
                     /*
                                         case XDOT_CMD_SET_KEY_X:
                                             if(verbose)pc.printf("\n\r proc cmd: this command not used\r\n");
@@ -622,6 +635,7 @@
                                             break;
                     */
                     case XDOT_CMD_GATEWAY_PING:
+                    {
                         if(verbose)pc.printf("\n\r proc cmd: xmit gateway ping\r\n");
                         pkt_ping *pPing = (pkt_ping*)&buf_xmt[0];
                         pPing->ack = I2C_ACK_PROC;
@@ -635,14 +649,17 @@
                         pPing->snr = (int8_t)ping_res.snr;
                         if (ping_res.status == 0)
                             if(verbose)pc.printf("\r\n----------- GATEWAY PING SUCCEEDED \r\n");
-                            else if(verbose)pc.printf("\r\n----------- GATEWAY PING FAIL \r\n");
+                        else
+                             if(verbose)pc.printf("\r\n----------- GATEWAY PING FAIL \r\n");
                         break;                        
-                        
+                    }    
                     default:
+                    {
                         if(verbose)pc.printf("\n\r proc cmd not recognized:%x",buf_rcv[0]);
-                        wait_ms(I2C_MIN_WAIT_DELAY);
+                        wait_us(1000*I2C_MIN_WAIT_DELAY);
                         buf_xmt[0] = I2C_ACK_PROC;
                         buf_xmt[1] = XDOT_CMD_UNDEFINED;
+                    }    
                 } //switch buf_rcv[0]
                 //gpio1 =1;       //test
                 if (bPulseLoraWake) i2c_pulse_wake(); //pulse wake-up lo->hi->lo to signal proc that xdot ready to send ack