arm studio build

Dependencies:   libxDot-mbed5

Revision:
17:74d60177c6b6
Parent:
16:5cc10d804d49
Child:
18:d95e1a2c4303
diff -r 5cc10d804d49 -r 74d60177c6b6 src/main.cpp
--- a/src/main.cpp	Sun Jan 20 15:19:57 2019 +0000
+++ b/src/main.cpp	Fri Jan 25 01:46:26 2019 +0000
@@ -9,14 +9,14 @@
 #include "ChannelPlans.h"
 #include "Lora.h"
 
-bool verbose =  true;
-bool bRxDone = false;              //true if callback function RxDone() triggered
-bool bDownLinkCntrFail = false;    //true if callback function RxDone() triggered and bad downlink frame count
-bool bClassA =  true;              //false => Class C multicast mode
-
+bool        verbose =  true;
+bool        bRxDone = false;              //true if callback function RxDone() triggered
+bool        bDownLinkCntrFail = false;    //true if callback function RxDone() triggered and bad downlink frame count
+bool        bListen4Multicast;        
+uint16_t    maxMulticastSessionTime = 0;
 //nvm storage params
-nvm nvmData;
-nvm *pNvmData = &nvmData;
+nvm         nvmData;
+nvm         *pNvmData = &nvmData;
 
 
 
@@ -194,7 +194,7 @@
     }             
     else{
        printNmvData(pNvmData);
-       dot->setLogLevel((verbose) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL);  // TRACE_LEVEL        , INFO_LEVEL       
+       //dot->setLogLevel((verbose) ? mts::MTSLog::TRACE_LEVEL : mts::MTSLog::TRACE_LEVEL);  // TRACE_LEVEL        , INFO_LEVEL       
     }
           
 // getStandbyFlag() should return the state of the standby flag directly from the processor
@@ -255,15 +255,17 @@
                gpio1 =0; 
 #endif
                 wait_us(wait_before_sleep_usec);         //wait for i2c to complete data transfer before sleeping
-//#ifdef NOTYET
-                if (!bClassA){      
-                    if(verbose)pc.printf("\n\r changed to class C, LISTEN ONLY \r\n");                                  
-                    wait(1800);    // CLASS C MODE LISTEN ONLY !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-                }    
-//#endif                
-                else{
-                    sleep_wake_interrupt_only(deep_sleep);   //sleep until rising edge of wake signal from proc
-                }    
+
+                if (bListen4Multicast){      //in ClassC and receiving multicst pkt, stay here until timeout or unitl ?????
+                    if(verbose)pc.printf("\n\r changed to class C, LISTEN ONLY,for max sec:%d\r\n",maxMulticastSessionTime);                                  
+                    uint16_t wait_cnt = maxMulticastSessionTime;
+                    while(wait_cnt > 0){
+                        wait_cnt--;
+                        wait(1);
+                    }
+               }    
+               sleep_wake_interrupt_only(deep_sleep);   //sleep until rising edge of wake signal from proc
+
                 
 #ifdef GPIO_ENABLE
               gpio1 =1;  
@@ -325,12 +327,13 @@
                             joined = join_network_wbit(pUp->joinAttemps);      //try joinAttemps times to join network
                             pAck->joinAttempts = join_network_attempts_wbit(); //# of join attemps made
                             pAck->mdot_ret = dot->send(upstream_packet);  //<--------------------------------------- extra xmit ???????????????
+                            save_OTAA_session_keys();
                             if (!joined)
                                if(verbose)pc.printf("\r\n----------- FAILED TO JOIN...GIVING UP\r\n");  // join network if not joined                                                         
-                            else {
-                                save_OTAA_session_keys();
-                                plan.SetRx2DatarateIndex(8);  //LORIOT FIX FOR RX2 & OTA !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  ---> doesn't work here????    
-                            }                                   
+                            //else {
+                            //    save_OTAA_session_keys();
+                            //    plan.SetRx2DatarateIndex(8);  //LORIOT FIX FOR RX2 & OTA !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  ---> doesn't work here????    
+                            //}                                   
                         }         
                         if (joined)
                         {          
@@ -458,7 +461,7 @@
                         for (i=0; i< 4;i++) peui->verLvlData[i] =  ver_level[i];
                         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;    
+                        break;                            
                     case XDOT_CMD_NVM:
                         if(verbose)pc.printf("\n\r proc cmd: NVM OTAA");                                                
                         pkt_setnvmup  *pUpNvm = (pkt_setnvmup*)&buf_rcv[0];                
@@ -473,37 +476,24 @@
                         if (nvmRead(&pDwnNvm->nvmData))
                             pDwnNvm->bChkSumOK = 1;    
                         printNmvData(&pDwnNvm->nvmData);    
-                        break;                                                   
-                    case XDOT_CMD_NVM_ABP:
-                        if(verbose)pc.printf("\n\r proc cmd: NVM ABP");                                                
-                        pkt_setnvmABPup  *pUpNvmABP = (pkt_setnvmABPup*)&buf_rcv[0];                
-                        pkt_setnvmABPdwn *pDwnNvmABP= (pkt_setnvmABPdwn*)&buf_xmt[0];                                                 
-                        pDwnNvmABP->ack = I2C_ACK_PROC;
-                        pDwnNvmABP->cmd = XDOT_CMD_NVM_ABP;
-                        pDwnNvmABP->dataLen = sizeof(nvmABP)-2;
-                        if (pUpNvmABP->nvm_option == XDOT_NVM_SET) nvmWriteABP(&pUpNvmABP->nvmData);
-                                                                    
-                        pDwnNvmABP->bChkSumOK = 0;        
-                        if (nvmReadABP(&pDwnNvmABP->nvmData))
-                            pDwnNvmABP->bChkSumOK = 1;    
-                        printNvmABPData(&pDwnNvmABP->nvmData);    
-                                            
-                        break;   
-
+                        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];                                                 
                         pDwnSetClass->ack = I2C_ACK_PROC;
                         pDwnSetClass->cmd = XDOT_CMD_SET_RADIO_CLASS;
-                        pDwnSetClass->dataLen = sizeof(class_switch)-2;                        
-                        bool bOk = multicast_change_class(&pUpSetClass->classData);
-                        if (bOk && pUpSetClass->classData.bClassC) bClassA = false;                        
+                        pDwnSetClass->dataLen = sizeof(class_switch)-2;                                                
+                        bool bOk = multicast_change_class(&pUpSetClass->classData);                        
+                        if (bOk && pUpSetClass->classData.bListen4Multicast){  //go into listen only mode for multicast pkts?
+                            bListen4Multicast = true;;        
+                            maxMulticastSessionTime = pUpSetClass->classData.maxMulticastSessionTime;
+                        }                                            
                         pDwnSetClass->bSwitched = bOk;                                                                                                                                       
                         break;   
                        
                         
-                    case XDOT_CMD_SET_NTWKSESS:  //read or write network seesion to xdot flash
+                    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");                        
@@ -518,12 +508,14 @@
                         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");                                  
                         wait_ms(I2C_MIN_WAIT_DELAY);
                         buf_xmt[0] = I2C_ACK_PROC;
                         buf_xmt[1] = XDOT_CMD_SET_KEY_X;
                         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];