LMiC LoRa Semtech + Nucleo version sending every 10secs
Dependents: LoRaWAN-test-10secs
Fork of LMiC by
Diff: lmic.cpp
- Revision:
- 8:34cb24e0b061
- Parent:
- 6:71f4de8e79e0
- Child:
- 9:c5820ce68bd6
--- a/lmic.cpp Wed Jan 13 14:23:31 2016 +0000 +++ b/lmic.cpp Mon Feb 08 10:39:01 2016 +0000 @@ -181,12 +181,12 @@ static void aes_cipher (xref2cu1_t key, u4_t devaddr, u4_t seqno, int dndir, xref2u1_t payload, int len) { - debug_str("Frame Cnt: "); +/* debug_str("Frame Cnt: "); debug_uint(seqno); debug_char( '\r' ); debug_char( '\n' ); debug_str("Payload before AES treatment: "); - debug_buf(payload, len); + debug_buf(payload, len);*/ if( len <= 0 ) return; os_clearMem(AESaux, 16); @@ -195,13 +195,13 @@ os_wlsbf4(AESaux+ 6,devaddr); os_wlsbf4(AESaux+10,seqno); os_copyMem(AESkey,key,16); - debug_str("A:"); - debug_buf(AESaux,16); +// debug_str("A:"); +// debug_buf(AESaux,16); os_aes(AES_CTR, payload, len); - debug_str("A after AES treatment:"); + /*debug_str("A after AES treatment:"); debug_buf(AESaux,16); debug_str("Payload after AES treatment: "); - debug_buf(payload, len); + debug_buf(payload, len);*/ } @@ -1069,7 +1069,11 @@ LMIC.seqnoDn = seqno+1; // next number to be expected DO_DEVDB(LMIC.seqnoDn,seqnoDn); // DN frame requested confirmation - provide ACK once with next UP frame - LMIC.dnConf = (ftype == HDR_FTYPE_DCDN ? FCT_ACK : 0); + + // PANY if port is 3 no ack + + if (port != 3) LMIC.dnConf = (ftype == HDR_FTYPE_DCDN ? FCT_ACK : 0); + else LMIC.dnConf = 0; } if( LMIC.dnConf || (fct & FCT_MORE) ) @@ -1089,9 +1093,9 @@ //debug_val("Port: ", port); while( oidx < olen ) { // debug_str("Port: "); - debug_str("Process OPTS..."); - debug_hex(opts[oidx]); - debug_str("\r\n"); + //debug_str("Process OPTS..."); + //debug_hex(opts[oidx]); + //debug_str("\r\n"); switch( opts[oidx] ) { case MCMD_LCHK_ANS: { debug_str("MCMD_LCHK_ANS\r\n"); @@ -1306,9 +1310,9 @@ //debug_val("Data Len: ", LMIC.dataLen); while( oidx < olen ) { // debug_str("Port: "); - debug_str("Process OPTS..."); - debug_hex(opts[oidx]); - debug_str("\r\n"); + //debug_str("Process OPTS..."); + //debug_hex(opts[oidx]); + //debug_str("\r\n"); switch( opts[oidx] ) { case MCMD_LCHK_ANS: { debug_str("MCMD_LCHK_ANS\r\n"); @@ -1959,6 +1963,10 @@ LMIC.txCnt += 1; setDrTxpow(DRCHG_NOACK, lowerDR(LMIC.datarate, DRADJUST[LMIC.txCnt]), KEEP_TXPOW); // Schedule another retransmission + debug_str("Delayed!! -- 1966"); + debug_uint(LMIC.rxtime); + debug_char( '\r' ); + debug_char( '\n' ); txDelay(LMIC.rxtime, RETRY_PERIOD_secs); LMIC.opmode &= ~OP_TXRXPEND; engineUpdate(); @@ -2053,6 +2061,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_uint(LMIC.bcninfo.txtime + BCN_RESERVE_osticks); + 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 @@ -2129,6 +2141,10 @@ txbeg + (jacc ? JOIN_GUARD_osticks : TXRX_GUARD_osticks) - rxtime > 0 ) { // Not enough time to complete TX-RX before beacon - postpone after beacon. // In order to avoid clustering of postponed TX right after beacon randomize start! + debug_str("Delayed!! -- 2144"); + debug_uint(rxtime + BCN_RESERVE_osticks); + debug_char( '\r' ); + debug_char( '\n' ); txDelay(rxtime + BCN_RESERVE_osticks, 16); txbeg = 0; goto checkrx; @@ -2136,6 +2152,9 @@ // Earliest possible time vs overhead to setup radio if( txbeg - (now + TX_RAMPUP) < 0 ) { // We could send right now! + debug_str("We could send right now!"); + debug_char( '\r' ); + debug_char( '\n' ); dr_t txdr = (dr_t)LMIC.datarate; if( jacc ) { u1_t ftype; @@ -2181,7 +2200,13 @@ } // 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_char( '\r' ); + debug_char( '\n' ); + //return; goto txdelay; // We don't track the beacon - nothing else to do - so wait for the time to TX + } // Consider RX tasks if( txbeg == 0 ) // zero indicates no TX pending txbeg += 1; // TX delayed by one tick (insignificant amount of time) @@ -2225,11 +2250,20 @@ 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' ); 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)); }