arm studio build

Dependencies:   libxDot-mbed5

Revision:
22:034c134f17c7
Parent:
21:60e5b6becdb0
Child:
24:e5ff476cd04e
--- a/src/main.cpp	Wed Jul 24 23:24:18 2019 +0000
+++ b/src/main.cpp	Wed Aug 14 17:22:36 2019 +0000
@@ -34,7 +34,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, 0x04 };  //api-level, determines if xdot code works with proc code
-uint8_t ver_level[4] = { 0x00, 0x00, 0x00, 0x09 };  //updated for every code check-in
+uint8_t ver_level[4] = { 0x00, 0x00, 0x00, 0x0A };  //updated for every code check-in
 
 //=======================================================================================================
 //configuring mbed pinsa; https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/io/DigitalInOut/
@@ -203,7 +203,7 @@
 //  1: Device has been in Standby mode
 //  The xDot should enter standby mode when deep sleep in invoked. So you should see the standby flag set if it came out of deep sleep.
     if (!dot->getStandbyFlag()) {  //if 0 => power-up/reset which should always be the case at this point
-        logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);        
+//        logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);  //  MBED_LIBRARY_VERSION no longer declared?    
         frequency_sub_band = dot->getFrequencySubBand();      
         printRadioCfg();  
         cfg_network(true,public_network,frequency_sub_band);  //force network cfg,
@@ -218,11 +218,7 @@
 // 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);
-//----------------------------------------------------------------------------------------------------------------------------------------------
-
-// save changes to configuration
-//    logInfo("saving configuration");
-  
+//---------------------------------------------------------------------------------------------------------------------------------------------- 
    eui = mts::Text::bin2hexString(dot->getDeviceId()).c_str();
    if(verbose)pc.printf("\r\nEUI: %s\r\n",eui);       
    bool joined = false;        
@@ -257,16 +253,10 @@
                 wait_us(wait_before_sleep_usec);         //wait for i2c to complete data transfer before sleeping
 
                 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, LISTEN ONLY,for max sec:%d\r\n",maxMulticastSessionTime);                                  
                     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);
                     }
-                    //uint16_t wait_cnt = maxMulticastSessionTime;
-                    //while((wait_cnt > 0) && bListen4Multicast){ //stay in mcast listen only until either timeout or end of mcast session
-                      //  wait_cnt--;
-                       // wait(1);
-                    //}
                }    
                sleep_wake_interrupt_only(deep_sleep);   //sleep until rising edge of wake signal from proc
 
@@ -276,20 +266,33 @@
 #endif
                 if(verbose)pc.printf("\n\r lora wake detected -> monitoring i2c bus\n\r ");                                                                 
                 break;                            
-            case I2C_READ:      //xdot <- proc  
+            case I2C_READ:      //psoc -> xdot i2c write  
                 bPulseLoraWake = true;                    
                 switch (buf_rcv[0])
                 {
                     case XDOT_CMD_XMIT_PKT:    
+                        bool bOk2XmitFullPayload = true;  //if false we only transmit the mac data
                         pkt_upstrm  *pUp= (pkt_upstrm*)&buf_rcv[0];                  
                         for (i=0; i < sizeof(buf_xmt);i++)buf_xmt[i] = 0xff;   //bfr fill            
                         pkt_ack *pAck = (pkt_ack*)&buf_xmt[0];                                                                
                         pAck->ack = I2C_ACK_PROC;
                         pAck->cmd = XDOT_CMD_XMIT_PKT;                                                             
-                        pAck->dataLen = pUp->dataLen; //data len of xmitted pkt                                  
-                        if(verbose)pc.printf("\r\npkt to xmit data len: %d\r\n",pAck->dataLen);                                                
+                        pAck->dataLen = pUp->dataLen; //data len of xmitted pkt                   
+//rev 040A change: if next tx pkt includes mac data => only xmit mac data and abort psoc payload                                       
+                        if(verbose)pc.printf("\r\ndatalen of pkt to xmit: %d",pAck->dataLen);                             
+                        uint8_t maxPayLoad = dot->getMaxPacketLength();
+                        uint8_t maxSizeNxtTxPkt = dot->getNextTxMaxSize();  //max payload available to transmit in next pkt
+                        if(verbose)pc.printf("\r\nmax datalen of next pkt: %d",maxSizeNxtTxPkt);     
+                        if (maxSizeNxtTxPkt < maxPayLoad){
+                            if(verbose)pc.printf("\r\n can't fit payload in next pkt,xmit only mac data\r\n");                                                                        
+                            bOk2XmitFullPayload = false;   
+                        }   
+                        else{
+                            if(verbose)pc.printf("\r\nok to xmit full payload");                                                                                                    
+                       }                                             
+//i2c pkt chksum from psoc ok?                        
                         uint8_t chksum = chksum_proc(buf_rcv);                        
-                        if(verbose)pc.printf("\r\nI2C chksum rcvd/computer: %d/%d ",pUp->chksum,chksum);                                               
+                        if(verbose)pc.printf("\r\nI2C chksum rcvd/computed: %d/%d ",pUp->chksum,chksum);                                               
                         pAck->bXmitAttempted = 1;                            
                         pAck->chksum_err = 0;
                         if(pUp->chksum != chksum){
@@ -300,25 +303,27 @@
                            break;
                         }
 //rev 0307 parameters  
-                        if(verbose)pc.printf("\n\r setting application port %d ",pUp->appPort);  //appPort not used in rev < 0307                                 
+                        if(verbose)pc.printf("\r\nsetting 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(verbose)pc.printf("\r\nlinkThreshCnt %d\r\n",linkThresholdCnt);                      
                         dot->setLinkCheckThreshold(linkThresholdCnt);
                                                                 
                         if (pUp->dataLen ==  0){ //datalen  non zero?                               
                             pAck->bXmitAttempted = 0;                            
                             break;
-                        }    
-                        upstream_packet.clear();    //xfr data from incoming bfr to xmit bfr
-                        for (i=0; i< pUp->dataLen;i++) upstream_packet.push_back(pUp->txData[i]);                                  
-                        
+                        }   
+//rev 040A change                        
+                        upstream_packet.clear();    //clear the xmit payload array
+                        if(bOk2XmitFullPayload)     //if no mac data to xmit xfr data from incoming bfr to xmit bfr
+                           for (i=0; i< pUp->dataLen;i++) upstream_packet.push_back(pUp->txData[i]);                                                         
                         if(verbose){
                             pc.printf("\r\n[TEST],Upstream Packet Received");                     
                             for(std::vector<uint8_t>::iterator it = upstream_packet.begin(); it != upstream_packet.end(); ++it)
                             pc.printf(",0x%x", *it);                                 
                             pc.printf("\r\n"); // see i told you.       
                         }
+                        
                         joined = dot->getNetworkJoinStatus();   //are we joined to Lorawan?
                         pAck->joinAttempts = 0;                 //no attempts made yet to join                
                         pAck->bAck = 0;                         //won't know if we receive a lorawan ack until after xmit
@@ -332,26 +337,32 @@
                             if(verbose)pc.printf("\r\n----------- NETWORK NOT JOINED YET, WILL TRY TO JOIN %d TIMES\r\n",pUp->joinAttemps);                                                            
                             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 ???????????????
+                            //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????    
-                            //}                                   
-                        }         
-                        if (joined)
+                            if (!joined)                        
+                               if(verbose)pc.printf("\r\n----------- FAILED TO JOIN...GIVING UP\r\n");  // join network if not joined                                                                                 }         
+                        }                               
+                        if (joined)                             //we are joined to the network                            
                         {          
-                            pAck->bJoined = 1;      //we are joined to the network                            
+                            pAck->bJoined = 1;      
                             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
-                    plan.SetRx2DatarateIndex(8);  //LORIOT FIX FOR RX2 & OT  --- work here?????
-                            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);                                     
+                            plan.SetRx2DatarateIndex(8);  //LORIOT FIX FOR RX2 & OT  --- work here?????
+                            
+//rev 040A change                        
+                            if(bOk2XmitFullPayload){  //send normal payload, no mac data to send
+                                pAck->mdot_ret = dot->send(upstream_packet);  //xmit the pkt     
+                                if (verbose)printf("\n\rdata->send() return code: %d\r\n",pAck->mdot_ret);  
+                            }                                       
+                            else{  //just xmit mac payload without psoc payload, return errcode for max payload exceeded        
+                                dot->send(upstream_packet);  //xmit the pkt in blocking mode, return false if no ack     
+                                pAck->mdot_ret = XDOT_ERR_MAX_PAYLOAD;                                                                                                       
+                                pAck->bXmitAttempted = 0;           
+                            }                                                              
+                                
                             if (pAck->mdot_ret == mDot::MDOT_OK)
                             {                                                                                         
                                 acks_rcvd++;
@@ -423,10 +434,10 @@
                             dot->setTxPower(pUpRadio->params.txPower);
                             if(verbose)pc.printf("\n\r setting tx datarate to %d ",pUpRadio->params.dataRate);                                   
                             dot->setTxDataRate(pUpRadio->params.dataRate);                         
-                            if(verbose)pc.printf("\n\r setting tx inverted to %d ",(bool)pUpRadio->params.txInverted);                                   
-                            dot->setTxInverted((bool)pUpRadio->params.txInverted);                         
-                            if(verbose)pc.printf("\n\r setting rx inverted to %d ",(bool)pUpRadio->params.rxInverted);                                   
-                            dot->setRxInverted((bool)pUpRadio->params.rxInverted);                         
+//deprecated                     if(verbose)pc.printf("\n\r setting tx inverted to %d ",(bool)pUpRadio->params.txInverted);                                   
+//deprecated                     dot->setTxInverted((bool)pUpRadio->params.txInverted);                               
+//deprecated                     if(verbose)pc.printf("\n\r setting rx inverted to %d ",(bool)pUpRadio->params.rxInverted);                                   
+//deprecated                     dot->setRxInverted((bool)pUpRadio->params.rxInverted);                         
                             if(verbose)pc.printf("\n\r setting rx delay to %d ",pUpRadio->params.rxDelay);                                   
                             dot->setRxDelay(pUpRadio->params.rxDelay);                         
                             if(verbose)pc.printf("\n\r setting join delay to %d ",pUpRadio->params.join_delay);                                   
@@ -440,8 +451,10 @@
                         pDwnRadio->params.public_network = public_network;
                         pDwnRadio->params.sub_band = dot->getFrequencySubBand();
                         pDwnRadio->params.join_delay = dot->getJoinDelay();
-                        pDwnRadio->params.txInverted = dot->getTxInverted();
-                        pDwnRadio->params.rxInverted = dot->getRxInverted();
+ //deprecated             pDwnRadio->params.txInverted = dot->getTxInverted();
+ //deprecated             pDwnRadio->params.rxInverted = dot->getRxInverted();
+                        pDwnRadio->params.txInverted = false;  //not used anymorer
+                        pDwnRadio->params.rxInverted = false;  //not used anymorer
                         pDwnRadio->params.rxDelay = dot->getRxDelay();                      
                         pDwnRadio->params.maxDataLen = dot->getMaxPacketLength();                   
                         pDwnRadio->params.maxTxPowerdBm = dot->getMaxTxPower();