LMiC LoRa Semtech + Nucleo version sending every 10secs

Dependents:   LoRaWAN-test-10secs

Fork of LMiC by Alcatel-Lucent IoT Development

Files at this revision

API Documentation at this revision

Comitter:
pnysten
Date:
Tue Feb 23 08:41:36 2016 +0000
Parent:
8:34cb24e0b061
Commit message:
LR-test3 version sending uplinks every 10 secs

Changed in this revision

aes.cpp Show annotated file Show diff for this revision Revisions of this file
lmic.cpp Show annotated file Show diff for this revision Revisions of this file
oslmic.cpp Show annotated file Show diff for this revision Revisions of this file
oslmic.h Show annotated file Show diff for this revision Revisions of this file
diff -r 34cb24e0b061 -r c5820ce68bd6 aes.cpp
--- a/aes.cpp	Mon Feb 08 10:39:01 2016 +0000
+++ b/aes.cpp	Tue Feb 23 08:41:36 2016 +0000
@@ -337,8 +337,8 @@
                 if( mode & AES_CTR ) { // xor block (partially)
                 
                     t0 = (len > 16) ? 16: len;
-                    debug_str("Payload before XOR:");
-                    debug_buf(buf,len);
+                    /*debug_str("Payload before XOR:");
+                    debug_buf(buf,len);*/
                     for(t1=0; t1<t0; t1++) {
                         buf[t1] ^= (a0>>24);
                         a0 <<= 8;
diff -r 34cb24e0b061 -r c5820ce68bd6 lmic.cpp
--- a/lmic.cpp	Mon Feb 08 10:39:01 2016 +0000
+++ b/lmic.cpp	Tue Feb 23 08:41:36 2016 +0000
@@ -409,6 +409,7 @@
 
 
 static ostime_t calcRxWindow (u1_t secs, dr_t dr) {
+    //debug_str("calcRxWindow\r\n");                                      
     ostime_t rxoff, err;
     if( secs==0 ) {
         // aka 128 secs (next becaon)
@@ -429,6 +430,7 @@
 
 // Setup beacon RX parameters assuming we have an error of ms (aka +/-(ms/2))
 static void calcBcnRxWindowFromMillis (u1_t ms, bit_t ini) {
+    //debug_str("calcBcnRxWindowFromMillis\r\n");                                      
     if( ini ) {
         LMIC.drift = 0;
         LMIC.maxDriftDiff = 0;
@@ -443,6 +445,7 @@
 
 // Setup scheduled RX window (ping/multicast slot)
 static void rxschedInit (xref2rxsched_t rxsched) {
+    //debug_str("rxschedInit\r\n");                                      
     os_clearMem(AESkey,16);
     os_clearMem(LMIC.frame+8,8);
     os_wlsbf4(LMIC.frame, LMIC.bcninfo.time);
@@ -460,6 +463,7 @@
 
 
 static bit_t rxschedNext (xref2rxsched_t rxsched, ostime_t cando) {
+    //debug_str("rxschedNext\r\n");                                      
   again:
     if( rxsched->rxtime - cando >= 0 )
         return 1;
@@ -478,6 +482,7 @@
 
 
 static ostime_t rndDelay (u1_t secSpan) {
+    //debug_str("rndDelay\r\n");                                      
     u2_t r = os_getRndU2();
     ostime_t delay = r;
     if( delay > OSTICKS_PER_SEC )
@@ -489,6 +494,7 @@
 
 
 static void txDelay (ostime_t reftime, u1_t secSpan) {
+    //debug_str("txDelay\r\n");                                      
     reftime += rndDelay(secSpan);
     if( LMIC.globalDutyRate == 0  ||  (reftime - LMIC.globalDutyAvail) > 0 ) {
         LMIC.globalDutyAvail = reftime;
@@ -498,6 +504,7 @@
 
 
 static void setDrJoin (u1_t reason, u1_t dr) {
+    //debug_str("setDrJoin\r\n");                                      
     EV(drChange, INFO, (e_.reason    = reason,
                         e_.deveui    = MAIN::CDEV->getEui(),
                         e_.dr        = dr|DR_PAGE,
@@ -510,6 +517,7 @@
 
 
 static void setDrTxpow (u1_t reason, u1_t dr, s1_t pow) {
+    //debug_str("setDrTxpow\r\n");                                      
     EV(drChange, INFO, (e_.reason    = reason,
                         e_.deveui    = MAIN::CDEV->getEui(),
                         e_.dr        = dr|DR_PAGE,
@@ -528,11 +536,13 @@
 
 
 void LMIC_stopPingable (void) {
+    //debug_str("LMIC_stopPingable\r\n");                                      
     LMIC.opmode &= ~(OP_PINGABLE|OP_PINGINI);
 }
 
 
 void LMIC_setPingable (u1_t intvExp) {
+    //debug_str("LMIC_setPingable\r\n");                                      
     // Change setting
     LMIC.ping.intvExp = (intvExp & 0x7);
     LMIC.opmode |= OP_PINGABLE;
@@ -560,6 +570,7 @@
 };
 
 static void initDefaultChannels (bit_t join) {
+    //debug_str("initDefaultChannels\r\n");                                      
     os_clearMem(&LMIC.channelFreq, sizeof(LMIC.channelFreq));
     os_clearMem(&LMIC.channelDrMap, sizeof(LMIC.channelDrMap));
     os_clearMem(&LMIC.bands, sizeof(LMIC.bands));
@@ -585,11 +596,12 @@
     LMIC.bands[BAND_DECI ].txpow    = 27;
     LMIC.bands[BAND_CENTI].lastchnl = os_getRndU1() % MAX_CHANNELS;
     LMIC.bands[BAND_MILLI].avail = 
-    LMIC.bands[BAND_CENTI].avail =
+    LMIC.bands[BAND_CENTI].avail = 
     LMIC.bands[BAND_DECI ].avail = os_getTime();
 }
 
 bit_t LMIC_setupBand (u1_t bandidx, s1_t txpow, u2_t txcap) {
+    //debug_str("LMIC_setupBand\r\n");                                      
     if( bandidx > BAND_AUX ) return 0;
     band_t* b = &LMIC.bands[bandidx];
     b->txpow = txpow;
@@ -600,6 +612,7 @@
 }
 
 bit_t LMIC_setupChannel (u1_t chidx, u4_t freq, u2_t drmap, s1_t band) {
+    //debug_str("LMIC_setupChannel\r\n");                                      
     if( chidx >= MAX_CHANNELS )
         return 0;
     if( band == -1 ) {
@@ -621,12 +634,14 @@
 }
 
 void LMIC_disableChannel (u1_t channel) {
+    //debug_str("LMIC_disableChannel\r\n");                                      
     LMIC.channelFreq[channel] = 0;
     LMIC.channelDrMap[channel] = 0;
     LMIC.channelMap &= ~(1<<channel);
 }
 
 static u4_t convFreq (xref2u1_t ptr) {
+    //debug_str("convFreq\r\n");                                      
     u4_t freq = (os_rlsbf4(ptr-1) >> 8) * 100;
     if( freq < EU868_FREQ_MIN || freq > EU868_FREQ_MAX )
         freq = 0;
@@ -634,6 +649,7 @@
 }
 
 static u1_t mapChannels (u1_t chpage, u2_t chmap) {
+    //debug_str("mapChannels\r\n");                                      
     // Bad page, disable all channel, enable non-existent
     if( chpage != 0 || chmap==0 || (chmap & ~LMIC.channelMap) != 0 )
         return 0;  // illegal input
@@ -647,6 +663,7 @@
 
 
 static void updateTx (ostime_t txbeg) {
+    //debug_str("updateTx\r\n");                                      
     u4_t freq = LMIC.channelFreq[LMIC.txChnl];
     // Update global/band specific duty cycle stats
     ostime_t airtime = calcAirTime(LMIC.rps, LMIC.dataLen);
@@ -660,6 +677,7 @@
 }
 
 static ostime_t nextTx (ostime_t now) {
+    //debug_str("nextTx\r\n");                                      
     u1_t bmap=0xF;
     do {
         ostime_t mintime = now + /*10h*/36000*OSTICKS_PER_SEC;
@@ -676,12 +694,14 @@
             if( (LMIC.channelMap & (1<<chnl)) != 0  &&  // channel enabled
                 (LMIC.channelDrMap[chnl] & (1<<(LMIC.datarate&0xF))) != 0  &&
                 band == (LMIC.channelFreq[chnl] & 0x3) ) { // in selected band
+                //debug_str("channel enabled in selected band\r\n");
                 LMIC.txChnl = LMIC.bands[band].lastchnl = chnl;
                 return mintime;
             }
         }
         if( (bmap &= ~(1<<band)) == 0 ) {
             // No feasible channel  found!
+            //debug_str("No feasible channel  found!\r\n");
             return mintime;
         }
     } while(1);
@@ -689,6 +709,7 @@
 
 
 static void setBcnRxParams (void) {
+    //debug_str("setBcnRxParams\r\n");                                      
     LMIC.dataLen = 0;
     LMIC.freq = LMIC.channelFreq[LMIC.bcnChnl] & ~(u4_t)3;
     LMIC.rps  = setIh(setNocrc(dndr2rps((dr_t)DR_BCN),1),LEN_BCN);
@@ -697,6 +718,7 @@
 #define setRx1Params() /*LMIC.freq/rps remain unchanged*/
 
 static void initJoinLoop (void) {
+    //debug_str("initJoinLoop\r\n");                                      
     LMIC.txChnl = os_getRndU1() % 6;
     LMIC.adrTxPow = 14;
     setDrJoin(DRCHG_SET, DR_SF7);
@@ -707,6 +729,7 @@
 
 
 static ostime_t nextJoinState (void) {
+    //debug_str("nextJoinState\r\n");                                      
     u1_t failed = 0;
 
     // Try 869.x and then 864.x with same DR
@@ -750,12 +773,14 @@
 
 
 static void initDefaultChannels (void) {
+    //debug_str("initDefaultChannels\r\n");                                      
     for( u1_t i=0; i<4; i++ )
         LMIC.channelMap[i] = 0xFFFF;
     LMIC.channelMap[4] = 0x00FF;
 }
 
 static u4_t convFreq (xref2u1_t ptr) {
+    //debug_str("convFreq\r\n");                                      
     u4_t freq = (os_rlsbf4(ptr-1) >> 8) * 100;
     if( freq >= US915_FREQ_MIN && freq <= US915_FREQ_MAX )
         freq = 0;
@@ -763,6 +788,7 @@
 }
 
 bit_t LMIC_setupChannel (u1_t chidx, u4_t freq, u2_t drmap, s1_t band) {
+    //debug_str("LMIC_setupChannel\r\n");                                      
     if( chidx < 72 || chidx >= 72+MAX_XCHANNELS )
         return 0; // channels 0..71 are hardwired
     chidx -= 72;
@@ -773,11 +799,13 @@
 }
 
 void LMIC_disableChannel (u1_t channel) {
+    //debug_str("LMIC_disableChannel\r\n");                                      
     if( channel < 72+MAX_XCHANNELS )
         LMIC.channelMap[channel/4] &= ~(1<<(channel&0xF));
 }
 
 static u1_t mapChannels (u1_t chpage, u2_t chmap) {
+    //debug_str("mapChannels\r\n");                                      
     if( chpage == MCMD_LADR_CHP_125ON || chpage == MCMD_LADR_CHP_125OFF ) {
         u2_t en125 = chpage == MCMD_LADR_CHP_125ON ? 0xFFFF : 0x0000;
         for( u1_t u=0; u<4; u++ )
@@ -792,6 +820,7 @@
 }
 
 static void updateTx (ostime_t txbeg) {
+    //debug_str("updateTx\r\n");                                      
     u1_t chnl = LMIC.txChnl;
     if( chnl < 64 ) {
         LMIC.freq = US915_125kHz_UPFBASE + chnl*US915_125kHz_UPFSTEP;
@@ -816,6 +845,7 @@
 // US does not have duty cycling - return now as earliest TX time
 #define nextTx(now) (_nextTx(),(now))
 static void _nextTx (void) {
+    //debug_str("_nextTx\r\n");                                      
     if( LMIC.chRnd==0 )
         LMIC.chRnd = os_getRndU1() & 0x3F;
     if( LMIC.datarate >= DR_SF8C ) { // 500kHz
@@ -839,12 +869,14 @@
 }
 
 static void setBcnRxParams (void) {
+    //debug_str("setBcnRxParams\r\n");                                      
     LMIC.dataLen = 0;
     LMIC.freq = US915_500kHz_DNFBASE + LMIC.bcnChnl * US915_500kHz_DNFSTEP;
     LMIC.rps  = setIh(setNocrc(dndr2rps((dr_t)DR_BCN),1),LEN_BCN);
 }
 
 #define setRx1Params() {                                                \
+    //debug_str("setRx1Params\r\n");                                      \
     LMIC.freq = US915_500kHz_DNFBASE + (LMIC.txChnl & 0x7) * US915_500kHz_DNFSTEP; \
     if( /* TX datarate */LMIC.dndr < DR_SF8C )                          \
         LMIC.dndr += DR_SF10CR - DR_SF10;                               \
@@ -854,6 +886,7 @@
 }
 
 static void initJoinLoop (void) {
+    //debug_str("initJoinLoop\r\n");
     LMIC.chRnd = 0;
     LMIC.txChnl = 0;
     LMIC.adrTxPow = 20;
@@ -863,6 +896,7 @@
 }
 
 static ostime_t nextJoinState (void) {
+    //debug_str("nextJoinState\r\n");
     // Try the following:
     //   SF7/8/9/10  on a random channel 0..63
     //   SF8C        on a random channel 64..71
@@ -902,11 +936,13 @@
 
 
 static void runEngineUpdate (xref2osjob_t osjob) {
+    //debug_str("runEngineUpdate\r\n");
     engineUpdate();
 }
 
 
 static void reportEvent (ev_t ev) {
+    //debug_str("reportEvent\r\n");
     EV(devCond, INFO, (e_.reason = EV::devCond_t::LMIC_EV,
                        e_.eui    = MAIN::CDEV->getEui(),
                        e_.info   = ev));
@@ -916,6 +952,7 @@
 
 
 static void runReset (xref2osjob_t osjob) {
+    //debug_str("runReset\r\n");
     // Disable session
     LMIC_reset();
     LMIC_startJoining();
@@ -923,6 +960,7 @@
 }
 
 static void stateJustJoined (void) {
+    //debug_str("stateJustJoined\r\n");
     LMIC.seqnoDn     = LMIC.seqnoUp = 0;
     LMIC.rejoinCnt   = 0;
     LMIC.dnConf      = LMIC.adrChanged = LMIC.ladrAns = LMIC.devsAns = 0;
@@ -944,6 +982,7 @@
 
 // Decode beacon  - do not overwrite bcninfo unless we have a match!
 static int decodeBeacon (void) {
+    //debug_str("decodeBeacon\r\n");
     ASSERT(LMIC.dataLen == LEN_BCN); // implicit header RX guarantees this
     xref2u1_t d = LMIC.frame;
     if(
@@ -980,6 +1019,7 @@
 
 
 static bit_t decodeFrame (void) {
+    //debug_str("decodeFrame\r\n");
     //debug_str("decodeFrame: ");
     //debug_buf(LMIC.frame, LMIC.dataLen);
     xref2u1_t d = LMIC.frame;
@@ -1074,6 +1114,8 @@
         
         if (port != 3) LMIC.dnConf = (ftype == HDR_FTYPE_DCDN ? FCT_ACK : 0);
         else LMIC.dnConf = 0;
+        
+//        if (LMIC.dnConf != 0) debug_str("ACK IS ON!!\r\n");
     }
 
     if( LMIC.dnConf || (fct & FCT_MORE) )
@@ -1463,6 +1505,7 @@
 
 
 static void setupRx2 (void) {
+    //debug_str("setupRx2\r\n");
     LMIC.txrxFlags = TXRX_DNW2;
     LMIC.rps = dndr2rps(LMIC.dn2Dr);
     LMIC.freq = LMIC.dn2Freq;
@@ -1472,12 +1515,14 @@
 
 
 static void schedRx2 (ostime_t delay, osjobcb_t func) {
+    //debug_str("schedRx2\r\n");
     // Add 1.5 symbols we need 5 out of 8. Try to sync 1.5 symbols into the preamble.
     LMIC.rxtime = LMIC.txend + delay + (PAMBL_SYMS-MINRX_SYMS)*dr2hsym(LMIC.dn2Dr);
     os_setTimedCallback(&LMIC.osjob, LMIC.rxtime - RX_RAMPUP, func);
 }
 
 static void setupRx1 (osjobcb_t func) {
+    //debug_str("setupRx1\r\n");
     LMIC.txrxFlags = TXRX_DNW1;
     // Turn LMIC.rps from TX over to RX
     LMIC.rps = setNocrc(LMIC.rps,1);
@@ -1489,6 +1534,7 @@
 
 // Called by HAL once TX complete and delivers exact end of TX time stamp in LMIC.rxtime
 static void txDone (ostime_t delay, osjobcb_t func) {
+    //debug_str("txDone\r\n");
     if( (LMIC.opmode & (OP_TRACK|OP_PINGABLE|OP_PINGINI)) == (OP_TRACK|OP_PINGABLE) ) {
         rxschedInit(&LMIC.ping);    // note: reuses LMIC.frame buffer!
         LMIC.opmode |= OP_PINGINI;
@@ -1517,6 +1563,7 @@
 
 
 static void onJoinFailed (xref2osjob_t osjob) {
+    //debug_str("onJoinFailed\r\n");
     // Notify app - must call LMIC_reset() to stop joining
     // otherwise join procedure continues.
     reportEvent(EV_JOIN_FAILED);
@@ -1524,6 +1571,7 @@
 
 
 static bit_t processJoinAccept (void) {
+    //debug_str("processJoinAccept\r\n");
     ASSERT(LMIC.txrxFlags != TXRX_DNW1 || LMIC.dataLen != 0);
     ASSERT((LMIC.opmode & OP_TXRXPEND)!=0);
 
@@ -1622,6 +1670,7 @@
 
 
 static void processRx2Jacc (xref2osjob_t osjob) {
+    //debug_str("processRx2Jacc\r\n");
     if( LMIC.dataLen == 0 )
         LMIC.txrxFlags = 0;  // nothing in 1st/2nd DN slot
     processJoinAccept();
@@ -1629,23 +1678,27 @@
 
 
 static void setupRx2Jacc (xref2osjob_t osjob) {
+    //debug_str("setupRx2Jacc\r\n");
     LMIC.osjob.func = FUNC_ADDR(processRx2Jacc);
     setupRx2();
 }
 
 
 static void processRx1Jacc (xref2osjob_t osjob) {
+    //debug_str("processRx1Jacc\r\n");
     if( LMIC.dataLen == 0 || !processJoinAccept() )
         schedRx2(DELAY_JACC2_osticks, FUNC_ADDR(setupRx2Jacc));
 }
 
 
 static void setupRx1Jacc (xref2osjob_t osjob) {
+    //debug_str("setupRx1Jacc\r\n");
     setupRx1(FUNC_ADDR(processRx1Jacc));
 }
 
 
 static void jreqDone (xref2osjob_t osjob) {
+    //debug_str("jreqDone\r\n");
     txDone(DELAY_JACC1_osticks, FUNC_ADDR(setupRx1Jacc));
 }
 
@@ -1655,10 +1708,12 @@
 static bit_t processDnData(void);
 
 static void processRx2DnDataDelay (xref2osjob_t osjob) {
+    //debug_str("processDnData\r\n");
     processDnData();
 }
 
 static void processRx2DnData (xref2osjob_t osjob) {
+    //debug_str("processRx2DnData\r\n");
     if( LMIC.dataLen == 0 ) {
         LMIC.txrxFlags = 0;  // nothing in 1st/2nd DN slot
         // Delay callback processing to avoid up TX while gateway is txing our missed frame! 
@@ -1673,23 +1728,28 @@
 
 
 static void setupRx2DnData (xref2osjob_t osjob) {
+    //debug_str("setupRx2DnData\r\n");
     LMIC.osjob.func = FUNC_ADDR(processRx2DnData);
     setupRx2();
 }
 
 
 static void processRx1DnData (xref2osjob_t osjob) {
+    //debug_str("processRx1DnData\r\n");
     if( LMIC.dataLen == 0 || !processDnData() )
         schedRx2(DELAY_DNW2_osticks, FUNC_ADDR(setupRx2DnData));
 }
 
 
 static void setupRx1DnData (xref2osjob_t osjob) {
+    //debug_str("setupRx1DnData\r\n");
+
     setupRx1(FUNC_ADDR(processRx1DnData));
 }
 
 
 static void updataDone (xref2osjob_t osjob) {
+    //debug_str("updataDone\r\n");
     txDone(DELAY_DNW1_osticks, FUNC_ADDR(setupRx1DnData));
 }
 
@@ -1700,6 +1760,7 @@
     //debug_str("buildDataFrame\r\n");
     bit_t txdata = ((LMIC.opmode & (OP_TXDATA|OP_POLL)) != OP_POLL);
     u1_t dlen = txdata ? LMIC.pendTxLen : 0;
+    if (LMIC.dnConf != 0) debug_str("ACK IS ON!!\r\n");
 
     // Piggyback MAC options
     // Prioritize by importance
@@ -1817,6 +1878,7 @@
 
 // Callback from HAL during scan mode or when job timer expires.
 static void onBcnRx (xref2osjob_t job) {
+    //debug_str("onBcnRx\r\n");
     // If we arrive via job timer make sure to put radio to rest.
     os_radio(RADIO_RST);
     os_clearCallback(&LMIC.osjob);
@@ -1849,6 +1911,7 @@
 // Implicitely cancels any pending TX/RX transaction.
 // Also cancels an onpoing joining procedure.
 static void startScan (void) {
+    //debug_str("startScan\r\n");
     ASSERT(LMIC.devaddr!=0 && (LMIC.opmode & OP_JOINING)==0);
     if( (LMIC.opmode & OP_SHUTDOWN) != 0 )
         return;
@@ -1863,6 +1926,7 @@
 
 
 bit_t LMIC_enableTracking (u1_t tryBcnInfo) {
+    //debug_str("LMIC_enableTracking\r\n");
     if( (LMIC.opmode & (OP_SCAN|OP_TRACK|OP_SHUTDOWN)) != 0 )
         return 0;  // already in progress or failed to enable
     // If BCN info requested from NWK then app has to take are
@@ -1874,6 +1938,7 @@
 
 
 void LMIC_disableTracking (void) {
+    //debug_str("LMIC_disableTracking\r\n");
     LMIC.opmode &= ~(OP_SCAN|OP_TRACK);
     LMIC.bcninfoTries = 0;
     engineUpdate();
@@ -1887,6 +1952,7 @@
 // ================================================================================
 
 static void buildJoinRequest (u1_t ftype) {
+    //debug_str("buildJoinRequest\r\n");
     // Do not use pendTxData since we might have a pending
     // user level frame in there. Use RX holding area instead.
     xref2u1_t d = LMIC.frame;
@@ -1910,11 +1976,13 @@
 }
 
 static void startJoining (xref2osjob_t osjob) {
+    //debug_str("startJoining\r\n");
     reportEvent(EV_JOINING);
 }
 
 // Start join procedure if not already joined.
 bit_t LMIC_startJoining (void) {
+    //debug_str("LMIC_startJoining\r\n");
     if( LMIC.devaddr == 0 ) {
         // There should be no TX/RX going on
         ASSERT((LMIC.opmode & (OP_POLL|OP_TXRXPEND)) == 0);
@@ -1941,6 +2009,7 @@
 // ================================================================================
 
 static void processPingRx (xref2osjob_t osjob) {
+    //debug_str("processPingRx\r\n");
     if( LMIC.dataLen != 0 ) {
         LMIC.txrxFlags = TXRX_PING;
         if( decodeFrame() ) {
@@ -1954,6 +2023,7 @@
 
 
 static bit_t processDnData (void) {
+    //debug_str("processDnData\r\n");
     ASSERT((LMIC.opmode & OP_TXRXPEND)!=0);
 
     if( LMIC.dataLen == 0 ) {
@@ -2022,6 +2092,7 @@
 
 
 static void processBeacon (xref2osjob_t osjob) {
+    //debug_str("processBeacon\r\n");
     ostime_t lasttx = LMIC.bcninfo.txtime;   // save here - decodeBeacon might overwrite
     u1_t flags = LMIC.bcninfo.flags;
     ev_t ev;
@@ -2061,10 +2132,10 @@
         LMIC.bcninfo.time   += BCN_INTV_sec;
         LMIC.missedBcns++;
         // Delay any possible TX after surmised beacon - it's there although we missed it
-        debug_str("Delayed!! -- 2064"); 
+        //debug_str("Delayed!! -- 2064"); 
         debug_uint(LMIC.bcninfo.txtime + BCN_RESERVE_osticks);
-        debug_char( '\r' );
-        debug_char( '\n' );
+        //debug_char( '\r' );
+        //debug_char( '\n' );
         txDelay(LMIC.bcninfo.txtime + BCN_RESERVE_osticks, 4);
         if( LMIC.missedBcns > MAX_MISSED_BCNS )
             LMIC.opmode |= OP_REJOIN;  // try if we can roam to another network
@@ -2087,12 +2158,14 @@
 
 
 static void startRxBcn (xref2osjob_t osjob) {
+    //debug_str("startRxBcn\r\n");
     LMIC.osjob.func = FUNC_ADDR(processBeacon);
     os_radio(RADIO_RX);
 }
 
 
 static void startRxPing (xref2osjob_t osjob) {
+    //debug_str("startRxPing\r\n");
     LMIC.osjob.func = FUNC_ADDR(processPingRx);
     os_radio(RADIO_RX);
 }
@@ -2101,7 +2174,7 @@
 // Decide what to do next for the MAC layer of a device
 static void engineUpdate (void) {
     
-//    debug_str("Engine Update\r\n");
+    //debug_str("Engine Update\r\n");
     // Check for ongoing state: scan or TX/RX transaction
     if( (LMIC.opmode & (OP_SCAN|OP_TXRXPEND|OP_SHUTDOWN)) != 0 ) 
         return;
@@ -2150,7 +2223,7 @@
             goto checkrx;
         }
         // Earliest possible time vs overhead to setup radio
-        if( txbeg - (now + TX_RAMPUP) < 0 ) {
+        /*PANYif( txbeg - (now + TX_RAMPUP) < 0 ) {PANY*/
             // We could send right now!
             debug_str("We could send right now!"); 
             debug_char( '\r' );
@@ -2197,14 +2270,13 @@
             updateTx(txbeg);
             os_radio(RADIO_TX);
             return;
-        }
+        /*PANY}PANY*/
         // Cannot yet TX
         if( (LMIC.opmode & OP_TRACK) == 0 )
         {
-            debug_str("We don't track the beacon - nothing else to do - so wait for the time to TX!"); 
+            /*debug_str("We don't track the beacon - nothing else to do - so wait for the time to TX!"); 
             debug_char( '\r' );
-            debug_char( '\n' );
-            //return;
+            debug_char( '\n' );*/
             goto txdelay; // We don't track the beacon - nothing else to do - so wait for the time to TX
         }
         // Consider RX tasks
@@ -2250,35 +2322,41 @@
     return;
 
   txdelay:
-    debug_char( '\r' );
-    debug_char( '\n' );
-    debug_str("TX DELAY: Wait for ");
-    debug_uint(txbeg-TX_RAMPUP); 
-    debug_char( '\r' );
-    debug_char( '\n' );
+    //debug_char( '\r' );
+    //debug_char( '\n' );
+    debug_str("TX DELAY: Wait ...");
+    char buffer[10];
+    sprintf(buffer, "%d", (txbeg-TX_RAMPUP));
+    
+    debug_str(buffer); 
+    //debug_char( '\r' );
+    //debug_char( '\n' );
     debug_char( '\r' );
     debug_char( '\n' );
     EV(devCond, INFO, (e_.reason = EV::devCond_t::TX_DELAY,
                        e_.eui    = MAIN::CDEV->getEui(),
                        e_.info   = osticks2ms(txbeg-now),
                        e_.info2  = LMIC.seqnoUp-1));
-    os_setTimedCallback(&LMIC.osjob, txbeg-TX_RAMPUP, FUNC_ADDR(runEngineUpdate));
-    //os_setCallback(&LMIC.osjob, FUNC_ADDR(runEngineUpdate));
+    os_setTimedCallback(&LMIC.osjob, (txbeg-TX_RAMPUP), FUNC_ADDR(runEngineUpdate));
+    //debug_str("TX DELAY: Stop To Wait ...");
 }
 
 
 void LMIC_setAdrMode (bit_t enabled) {
+    //debug_str("LMIC_setAdrMode\r\n");
     LMIC.adrEnabled = enabled ? FCT_ADREN : 0;
 }
 
 
 //  Should we have/need an ext. API like this?
 void LMIC_setDrTxpow (dr_t dr, s1_t txpow) {
+    //debug_str("LMIC_setDrTxpow\r\n");
     setDrTxpow(DRCHG_SET, dr, txpow);
 }
 
 
 void LMIC_shutdown (void) {
+    //debug_str("LMIC_shutdown\r\n");
     os_clearCallback(&LMIC.osjob);
     os_radio(RADIO_RST);
     LMIC.opmode |= OP_SHUTDOWN;
@@ -2286,6 +2364,7 @@
 
 
 void LMIC_reset (void) {
+    //debug_str("LMIC_reset\r\n");
     EV(devCond, INFO, (e_.reason = EV::devCond_t::LMIC_EV,
                        e_.eui    = MAIN::CDEV->getEui(),
                        e_.info   = EV_RESET));
@@ -2317,11 +2396,13 @@
 
 
 void LMIC_init (void) {
+    //debug_str("LMIC_init\r\n");
     LMIC.opmode = OP_SHUTDOWN;
 }
 
 
 void LMIC_clrTxData (void) {
+    //debug_str("LMIC_clrTxData\r\n");
     LMIC.opmode &= ~(OP_TXDATA|OP_TXRXPEND|OP_POLL);
     LMIC.pendTxLen = 0;
     if( (LMIC.opmode & (OP_JOINING|OP_SCAN)) != 0 ) // do not interfere with JOINING
@@ -2333,6 +2414,7 @@
 
 
 void LMIC_setTxData (void) {
+    //debug_str("LMIC_setTxData\r\n");
     LMIC.opmode |= OP_TXDATA;
     if( (LMIC.opmode & OP_JOINING) == 0 )
     {
@@ -2344,6 +2426,7 @@
 
 //
 int LMIC_setTxData2 (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed) {
+    //debug_str("LMIC_setTxData2\r\n");
 /*    debug_val("Data Length: ", dlen);
     debug_val("Data Length: ", SIZEOFEXPR(LMIC.pendTxData));*/
     if( dlen > SIZEOFEXPR(LMIC.pendTxData) )
@@ -2367,6 +2450,7 @@
 
 // Send a payload-less message to signal device is alive
 void LMIC_sendAlive (void) {
+    //debug_str("LMIC_sendAlive\r\n");
     LMIC.opmode |= OP_POLL;
     engineUpdate();
 }
@@ -2374,6 +2458,7 @@
 
 // Check if other networks are around.
 void LMIC_tryRejoin (void) {
+    //debug_str("LMIC_tryRejoin\r\n");
     LMIC.opmode |= OP_REJOIN;
     engineUpdate();
 }
@@ -2393,6 +2478,7 @@
 //! \param artKey  the 16 byte application router session key used for message confidentiality.
 //!     If NULL the caller has copied the key into `LMIC.artKey` before.
 void LMIC_setSession (u4_t netid, devaddr_t devaddr, xref2u1_t nwkKey, xref2u1_t artKey) {
+    //debug_str("LMIC_setSession\r\n");
     LMIC.netid = netid;
     LMIC.devaddr = devaddr;
     if( nwkKey != (xref2u1_t)0 )
@@ -2418,6 +2504,7 @@
 // nor is the datarate changed.
 // This must be called only if a session is established (e.g. after EV_JOINED)
 void LMIC_setLinkCheckMode (bit_t enabled) {
+    //debug_str("LMIC_setLinkCheckMode\r\n");
     LMIC.adrChanged = 0;
     LMIC.adrAckReq = enabled ? LINK_CHECK_INIT : LINK_CHECK_OFF;
 }
diff -r 34cb24e0b061 -r c5820ce68bd6 oslmic.cpp
--- a/oslmic.cpp	Mon Feb 08 10:39:01 2016 +0000
+++ b/oslmic.cpp	Tue Feb 23 08:41:36 2016 +0000
@@ -86,8 +86,10 @@
     job->next = NULL;
     // insert into schedule
     for(pnext=&OS.scheduledjobs; *pnext; pnext=&((*pnext)->next)) {
+        //debug_str(".");
         if((*pnext)->deadline - time > 0) { // (cmp diff, not abs!)
             // enqueue before next element and stop
+            //debug_str("Stop To Wait...\r\n");
             job->next = *pnext;
             break;
         }
diff -r 34cb24e0b061 -r c5820ce68bd6 oslmic.h
--- a/oslmic.h	Mon Feb 08 10:39:01 2016 +0000
+++ b/oslmic.h	Tue Feb 23 08:41:36 2016 +0000
@@ -89,7 +89,8 @@
 #define RX_RAMPUP  (us2osticks(2000))
 #endif
 #ifndef TX_RAMPUP
-#define TX_RAMPUP  (us2osticks(2000))
+//#define TX_RAMPUP  (us2osticks(2000))
+#define TX_RAMPUP  (sec2osticks(200))
 #endif
 
 #ifndef OSTICKS_PER_SEC