arm studio build

Dependencies:   libxDot-mbed5

Revision:
11:77fe4f18a81b
Parent:
10:061fab1195e7
Child:
12:7944e4dbe853
--- a/src/main.cpp	Wed Aug 15 13:51:13 2018 +0000
+++ b/src/main.cpp	Thu Oct 18 17:17:26 2018 +0000
@@ -7,6 +7,9 @@
 #include "RadioEvent.h"
 #include "Lora.h"
 
+bool bRxDone = false;              //true if callback function RxDone() triggered
+bool bDownLinkCntrFail = false;    //true if callback function RxDone() triggered and bad downlink frame count
+
 //nvm storage params
 nvm nvmData;
 nvm *pNvmData = &nvmData;
@@ -26,7 +29,7 @@
 //api_level: proc code will not run if api level (last two bytess) greater than what it expects
 //=======================================================================================================
 uint8_t api_level[4] = { 0x00, 0x00, 0x00, 0x03 };  //api-level, determines if xdot code works with proc code
-uint8_t ver_level[4] = { 0x00, 0x00, 0x00, 0x07 };  //updated for every code check-in
+uint8_t ver_level[4] = { 0x00, 0x00, 0x00, 0x08 };  //updated for every code check-in
 
 //=======================================================================================================
 //configuring mbed pinsa; https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/io/DigitalInOut/
@@ -126,10 +129,7 @@
     public_network = bPublic;
     frequency_sub_band =sub_band;
 // start from a well-known state
-    logInfo("defaulting Dot configuration");
-    //dot->resetConfig();             //reset config to factory default not used for v0307
-    // test dot->resetNetworkSession();     //Reset current network session, essentially disconnecting from the network
-        
+    logInfo("defaulting Dot configuration");        
     if (dot->getJoinMode() != mDot::OTA) {  // update configuration if necessary
         logInfo("changing network join mode to OTA");
         if (dot->setJoinMode(mDot::OTA) != mDot::MDOT_OK) {
@@ -140,7 +140,6 @@
 // in OTA and AUTO_OTA join modes, the credentials can be passed to the library as a name and passphrase or an ID and KEY
 // only one method or the other should be used!
     if (public_network){
-   //     update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack);
         update_ota_config_id_key(nvmData.network_id,nvmData.network_key, frequency_sub_band, public_network, ack);
         logInfo("--------------  network configured for public access -----------------------------");
     }    
@@ -152,21 +151,8 @@
 // declares the Dot disconnected if no acks received within link_check_treshold transmits
     //update_network_link_check_config(3, 5);
     dot->setLinkCheckThreshold(link_check_treshold);
-
-
-        
-/*  done thru radio cmds        
-// save changes to configuration
-        logInfo("saving configuration");
-        if (!dot->saveConfig()) {
-            logError("failed to save configuration");
-            return false;
-        }        
-        display_config();
-*/        
-        return true;
+    return true;
 }    
-
 //=================================================================================================
 //main()
 // main() runs in its own thread in the OS
@@ -182,8 +168,8 @@
     gpio1.output();    
     gpio1 =0;         
 #endif    
-
     pc.baud(115200); 
+    
     pc.printf("\r\n**********************************************************\r\n");
     pc.printf("\r\n XDOT BOOT\r\n");
     pc.printf("COMM api_level = <HEX> %x.%x.%x.%x\r\n",api_level[0],api_level[1],api_level[2],api_level[3]);
@@ -199,19 +185,12 @@
     if (pNvmData->bLogOutputOn == 0){
         pc.printf("\r\nDISABLING TERMINAL OUTPUT\r\n");
         dot->setLogLevel(mts::MTSLog::NONE_LEVEL);         //doesn't work
-        //dot->setLogLevel((true) ? mts::MTSLog::INFO_LEVEL : mts::MTSLog::INFO_LEVEL); //!!!!!!!!!!!! this works
-        //dot->setLogLevel((true) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL); //!!!!!!!!!!!! this works
         verbose = false;
     }             
     else{
        printNmvData(pNvmData);
        dot->setLogLevel((verbose) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL);  // TRACE_LEVEL        , INFO_LEVEL       
     }
-//restore defaults after xdot reset    
-  //   dot->resetConfig(); //TEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! must upload new cfg after each xdot reset if use this !
-  //   dot->setFrequencySubBand(frequency_sub_band);  //set default freq band
-  //   dot->setAdr(1); //test
-     
           
 // getStandbyFlag() should return the state of the standby flag directly from the processor
 // Standby flag: This bit is set by hardware and cleared only by a POR/PDR (power on reset/power down reset) or by setting the CSBF bit in the PWR power control register (PWR_CR)
@@ -296,20 +275,18 @@
                         if(pUp->chksum != chksum){
                             if(verbose)pc.printf(" chksum err, aborting xmit");  
                             pAck->bXmitAttempted = 0;                                                  
-                            pAck->mdot_ret = -2048;  //wbit rtn code?
-                            pAck->chksum_err = 1;
-                            break;
+                           // pAck->mdot_ret = -2048;  //wbit rtn code?
+                           pAck->mdot_ret = XDOT_ERR_I2C_CHKSUM;
+                           pAck->chksum_err = 1;
+                           break;
                         }
 //rev 0307 parameters  
                         if(verbose)pc.printf("\n\r setting application port %d ",pUp->appPort);  //appPort not used in rev < 0307                                 
                         dot->setAppPort(pUp->appPort);
                         uint8_t linkThresholdCnt =  pUp->linkThreshCnt; 
-                        if(verbose)pc.printf("\r\n linkThreshCnt %d\r\n",linkThresholdCnt); 
-                        //if (pUp->bResetLinkCCounter){
-                            //dot->setLinkFailCount(0);
+                        if(verbose)pc.printf("\r\n linkThreshCnt %d\r\n",linkThresholdCnt);                      
                         dot->setLinkCheckThreshold(linkThresholdCnt);
-                          //  if(verbose)pc.printf("\r\n reset link fail threshold to zero"); 
-                        //}                                                
+                                                                
                         if (pUp->dataLen ==  0){ //datalen  non zero?                               
                             pAck->bXmitAttempted = 0;                            
                             break;
@@ -338,14 +315,19 @@
                             if (!joined)
                                if(verbose)pc.printf("\r\n----------- FAILED TO JOIN...GIVING UP\r\n");  // join network if not joined                                                         
                         }         
-                        if (joined){          
+                        if (joined)
+                        {          
                             pAck->bJoined = 1;      //we are joined to the network                            
                             packets_sent++;  
+                            bRxDone = false;              //true if callback function RxDone() triggered
+                            bDownLinkCntrFail = false;    //true if callback function RxDone() triggered and bad downlink frame count
+
  //send packet
  //return code indicates results, send return code back to proc Dec14,2017
                             pAck->mdot_ret = dot->send(upstream_packet);  //xmit the pkt in blocking mode, return false if no ack     
                             if (verbose)printf("\n\rdata->send() return code: %d\r\n",pAck->mdot_ret);                                     
-                            if (pAck->mdot_ret == mDot::MDOT_OK){                                                                                         
+                            if (pAck->mdot_ret == mDot::MDOT_OK)
+                            {                                                                                         
                                 acks_rcvd++;
                                 pAck->bAck = 1;                //we got a Rx1 or Rx2 ack                           
                                 mDot::rssi_stats rssiStats = dot->getRssiStats();        //rssi stat   
@@ -372,11 +354,17 @@
                                     }
                                 } //if  downstream data rcvd                                     
                                 else{
-                                    if (verbose)printf("\n\revents.is_packet_received ()=  false => ack rcvd but no data\r\n");                                                                             
-                                }                                        
+                                    if (verbose)printf("\n\r ack rcvd without data\r\n");                                                  
+                                } //else                                                                            
                              } //send() 
-                             else{
-                                if (verbose)printf("\n\rdata->send()=  false => no ack\r\n");     //could be some other error                                    
+//rev 0308 parameters                             
+                             else
+                             {                                
+                                if (verbose)printf("\n\r no ack rcvd \r\n");     //could be some other error                                    
+                                if ((pAck->mdot_ret != 0)  && bRxDone)  //chk if callback function triggered
+                                    {                                    
+                                        if (bDownLinkCntrFail)pAck->mdot_ret = XDOT_ERR_FRAME_CNT; //bad downlink frame count return err code                                                                                
+                                    } 
                              }                                                                 
                           }//if joined
                         break;