调试版本,多个调试标识,接收时有bug
Fork of LoRaWAN-lib by
Revision 8:246353e3cbc5, committed 2016-09-26
- Comitter:
- lzbpli
- Date:
- Mon Sep 26 05:53:55 2016 +0000
- Parent:
- 7:c16969e0f70f
- Commit message:
- test version
Changed in this revision
diff -r c16969e0f70f -r 246353e3cbc5 LoRaMac-api-v3.h --- a/LoRaMac-api-v3.h Tue Jul 05 13:24:54 2016 +0000 +++ b/LoRaMac-api-v3.h Mon Sep 26 05:53:55 2016 +0000 @@ -62,7 +62,7 @@ /*! * Class A&B maximum receive window delay in us */ -#define MAX_RX_WINDOW 3000000 +#define MAX_RX_WINDOW 1000000 /*! * Maximum allowed gap for the FCNT field
diff -r c16969e0f70f -r 246353e3cbc5 LoRaMac-definitions.h --- a/LoRaMac-definitions.h Tue Jul 05 13:24:54 2016 +0000 +++ b/LoRaMac-definitions.h Mon Sep 26 05:53:55 2016 +0000 @@ -106,7 +106,7 @@ * Second reception window channel definition. */ // Channel = { Frequency [Hz], Datarate } -#define RX_WND_2_CHANNEL { 434665000, DR_0 } +#define RX_WND_2_CHANNEL { 472300000, DR_1 } /*! * LoRaMac maximum number of bands @@ -120,9 +120,15 @@ * LoRaMac default channels */ // Channel = { Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band } -#define LC1 { 433175000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } -#define LC2 { 433375000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } -#define LC3 { 433575000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } +#define LC1 { 471500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } +#define LC2 { 471700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } +#define LC3 { 471900000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } +#define LC4 { 472100000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } +#define LC5 { 472300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } +#define LC6 { 472500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } +#define LC7 { 472700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } +#define LC8 { 472900000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } + /*! * LoRaMac duty cycle for the back-off procedure @@ -168,7 +174,7 @@ /*! * Default datarate used by the node */ -#define LORAMAC_DEFAULT_DATARATE DR_0 +#define LORAMAC_DEFAULT_DATARATE DR_3 /*! * Minimal Rx1 receive datarate offset
diff -r c16969e0f70f -r 246353e3cbc5 LoRaMac.cpp --- a/LoRaMac.cpp Tue Jul 05 13:24:54 2016 +0000 +++ b/LoRaMac.cpp Mon Sep 26 05:53:55 2016 +0000 @@ -237,6 +237,12 @@ LC1, LC2, LC3, + LC4, + LC5, + LC6, + LC7, + LC8, + }; #elif defined( USE_BAND_780 ) /*! @@ -924,13 +930,42 @@ TimerSetValue( &MacStateCheckTimer, 1000 ); TimerStart( &MacStateCheckTimer ); } - static void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { LoRaMacHeader_t macHdr; +#if defined( SANFANBG ) + + + pc.printf("payload:"); + for(int i=0;i<size;i++){ + pc.printf("%x ",payload[i]); + } + pc.printf("size:%drssi:%dsnr:%d\r\n",size,rssi,snr); +#endif + +#if defined( SANFANBG ) + pc.printf("OnRadioRxDone10086\r\n"); +#endif + uint8_t pktHeaderLen = 0; + macHdr.Value = payload[pktHeaderLen++]; +#if defined( SANFANBG ) + pc.printf("macHdr:%d\r\n",macHdr.Value); +#endif + } +static void OnRadioRxDone1( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) +{ + LoRaMacHeader_t macHdr; LoRaMacFrameCtrl_t fCtrl; bool skipIndication = false; - +#if defined( SANFANBG ) + + + pc.printf("payload:"); + for(int i=0;i<size;i++){ + pc.printf("%x ",payload[i]); + } + pc.printf("size:%drssi:%dsnr:%d\r\n",size,rssi,snr); +#endif uint8_t pktHeaderLen = 0; uint32_t address = 0; uint8_t appPayloadStartIndex = 0; @@ -951,6 +986,9 @@ uint8_t multicast = 0; bool isMicOk = false; +#if defined( SANFANBG ) + pc.printf("OnRadioRxDone\r\n"); +#endif McpsConfirm.AckReceived = false; McpsIndication.Rssi = rssi; @@ -973,7 +1011,9 @@ TimerStop( &RxWindowTimer2 ); macHdr.Value = payload[pktHeaderLen++]; - +#if defined( SANFANBG ) + pc.printf("macHdr:%d\r\n",macHdr.Value); +#endif switch( macHdr.Bits.MType ) { case FRAME_TYPE_JOIN_ACCEPT: @@ -1059,7 +1099,9 @@ address |= ( (uint32_t)payload[pktHeaderLen++] << 8 ); address |= ( (uint32_t)payload[pktHeaderLen++] << 16 ); address |= ( (uint32_t)payload[pktHeaderLen++] << 24 ); - +#if defined( SANFANBG ) + pc.printf("address:%d\r\n",address); +#endif if( address != LoRaMacDevAddr ) { curMulticastParams = MulticastChannels; @@ -1095,21 +1137,26 @@ sequenceCounter = ( uint16_t )payload[pktHeaderLen++]; sequenceCounter |= ( uint16_t )payload[pktHeaderLen++] << 8; - +#if defined( SANFANBG ) + pc.printf("sequenceCounter:%d\r\n",sequenceCounter); +#endif appPayloadStartIndex = 8 + fCtrl.Bits.FOptsLen; micRx |= ( uint32_t )payload[size - LORAMAC_MFR_LEN]; micRx |= ( ( uint32_t )payload[size - LORAMAC_MFR_LEN + 1] << 8 ); micRx |= ( ( uint32_t )payload[size - LORAMAC_MFR_LEN + 2] << 16 ); micRx |= ( ( uint32_t )payload[size - LORAMAC_MFR_LEN + 3] << 24 ); - +#if defined( SANFANBG ) + pc.printf("micRx:%d\r\n",micRx); +#endif sequenceCounterPrev = ( uint16_t )downLinkCounter; sequenceCounterDiff = ( sequenceCounter - sequenceCounterPrev ); if( sequenceCounterDiff < ( 1 << 15 ) ) { downLinkCounter += sequenceCounterDiff; - LoRaMacComputeMic( payload, size - LORAMAC_MFR_LEN, nwkSKey, address, DOWN_LINK, downLinkCounter, &mic ); + // LoRaMacComputeMic( payload, size - LORAMAC_MFR_LEN, nwkSKey, address, DOWN_LINK, downLinkCounter, &mic ); + if( micRx == mic ) { isMicOk = true; @@ -1119,7 +1166,7 @@ { // check for sequence roll-over uint32_t downLinkCounterTmp = downLinkCounter + 0x10000 + ( int16_t )sequenceCounterDiff; - LoRaMacComputeMic( payload, size - LORAMAC_MFR_LEN, nwkSKey, address, DOWN_LINK, downLinkCounterTmp, &mic ); + // LoRaMacComputeMic( payload, size - LORAMAC_MFR_LEN, nwkSKey, address, DOWN_LINK, downLinkCounterTmp, &mic ); if( micRx == mic ) { isMicOk = true; @@ -1135,7 +1182,9 @@ PrepareRxDoneAbort( ); return; } - +#if defined( SANFANBG ) + pc.printf("isMicOk:%d\r\n",isMicOk); +#endif if( isMicOk == true ) { McpsIndication.Status = LORAMAC_EVENT_INFO_STATUS_OK; @@ -1319,6 +1368,9 @@ // Trig OnMacCheckTimerEvent call as soon as possible TimerSetValue( &MacStateCheckTimer, 1000 ); TimerStart( &MacStateCheckTimer ); +#if defined( SANFANBG ) + pc.printf("OnRadioRXDONE\r\n"); +#endif } static void OnRadioTxTimeout( void ) @@ -1483,7 +1535,7 @@ { #if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 ) // Re-enable default channels LC1, LC2, LC3 - LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) ); + LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) + LC( 4 ) + LC( 5 )+ LC( 6 )+ LC( 7 )+ LC( 8 )); #elif defined( USE_BAND_915 ) // Re-enable default channels LoRaMacParams.ChannelsMask[0] = 0xFFFF; @@ -1578,7 +1630,10 @@ TimerStop( &RxWindowTimer1 ); RxSlot = 0; - +#if defined( SANFANBG ) + pc.printf("RxWindow1\r\n"); +#endif + if( LoRaMacDeviceClass == CLASS_C ) { Radio.Standby( ); @@ -1660,6 +1715,9 @@ TimerStop( &RxWindowTimer2 ); RxSlot = 1; +#if defined( SANFANBG ) + pc.printf("RxWindow2\r\n"); +#endif #if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 ) // For higher datarates, we increase the number of symbols generating a Rx Timeout @@ -1762,7 +1820,7 @@ if( CountBits( LoRaMacParams.ChannelsMask[0], 16 ) == 0 ) { // Re-enable default channels, if no channel is enabled - LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) ); + LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 )+ LC( 4 ) + LC( 5 )+ LC( 6 )+ LC( 7 )+ LC( 8 ) ); } #endif @@ -1885,7 +1943,9 @@ { uint8_t downlinkDatarate = Datarates[datarate]; RadioModems_t modem; - +#if defined( SANFANBG ) + pc.printf("GetStatus:%d\r\n",Radio.GetStatus( )); +#endif if( Radio.GetStatus( ) == RF_IDLE ) { Radio.SetChannel( freq ); @@ -1901,8 +1961,18 @@ } else { + +#if defined( SANFANBG ) + pc.printf("***\r\n"); + pc.printf("fy:%d dr:%d\r\n",freq,downlinkDatarate); +#endif + modem = MODEM_LORA; Radio.SetRxConfig( modem, bandwidth, downlinkDatarate, 1, 0, 8, timeout, false, 0, false, 0, 0, true, rxContinuous ); + Radio.SetRxConfig( modem, bandwidth, downlinkDatarate, 1, 0, 8, timeout, false, 0, true, 0, 4, false, true ); +#if defined( SANFANBG ) + pc.printf("SetRxConfig:%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\n",modem,bandwidth,downlinkDatarate,1,8,timeout,false,true,0,4,false); +#endif } #elif defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) modem = MODEM_LORA; @@ -1921,6 +1991,8 @@ if( rxContinuous == false ) { Radio.Rx( LoRaMacParams.MaxRxWindow ); + + // pc.printf("***8\r\n"); } else { @@ -2144,7 +2216,7 @@ if( updateChannelMask == true ) { // Re-enable default channels LC1, LC2, LC3 - LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) ); + LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) + LC( 4 ) + LC( 5 )+ LC( 6 )+ LC( 7 )+ LC( 8 )); } } #elif defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) @@ -2675,7 +2747,7 @@ #if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 ) // Re-enable default channels LC1, LC2, LC3 - LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) ); + LoRaMacParams.ChannelsMask[0] = LoRaMacParams.ChannelsMask[0] | ( LC( 1 ) + LC( 2 ) + LC( 3 ) + LC( 4 ) + LC( 5 )+ LC( 6 )+ LC( 7 )+ LC( 8 )); #endif } @@ -2989,11 +3061,11 @@ if( framePort == 0 ) { - LoRaMacPayloadEncrypt( (uint8_t* ) payload, payloadSize, LoRaMacNwkSKey, LoRaMacDevAddr, UP_LINK, UpLinkCounter, LoRaMacPayload ); + // LoRaMacPayloadEncrypt( (uint8_t* ) payload, payloadSize, LoRaMacNwkSKey, LoRaMacDevAddr, UP_LINK, UpLinkCounter, LoRaMacPayload ); } else { - LoRaMacPayloadEncrypt( (uint8_t* ) payload, payloadSize, LoRaMacAppSKey, LoRaMacDevAddr, UP_LINK, UpLinkCounter, LoRaMacPayload ); + // LoRaMacPayloadEncrypt( (uint8_t* ) payload, payloadSize, LoRaMacAppSKey, LoRaMacDevAddr, UP_LINK, UpLinkCounter, LoRaMacPayload ); } memcpy1( LoRaMacBuffer + pktHeaderLen, LoRaMacPayload, payloadSize ); } @@ -3150,7 +3222,7 @@ // Channel mask #if defined( USE_BAND_433 ) - LoRaMacParamsDefaults.ChannelsMask[0] = LC( 1 ) + LC( 2 ) + LC( 3 ); + LoRaMacParamsDefaults.ChannelsMask[0] = LC( 1 ) + LC( 2 ) + LC( 3 ) + LC( 4 ) + LC( 5 )+ LC( 6 )+ LC( 7 )+ LC( 8 ); #elif defined( USE_BAND_780 ) LoRaMacParamsDefaults.ChannelsMask[0] = LC( 1 ) + LC( 2 ) + LC( 3 ); #elif defined( USE_BAND_868 ) @@ -4010,6 +4082,9 @@ } status = Send( &macHdr, fPort, fBuffer, fBufferSize ); +#if defined( SANFANBG ) + pc.printf("status:%d\r\n",status); +#endif if( status == LORAMAC_STATUS_OK ) { McpsConfirm.McpsRequest = mcpsRequest->Type;
diff -r c16969e0f70f -r 246353e3cbc5 LoRaMac.h --- a/LoRaMac.h Tue Jul 05 13:24:54 2016 +0000 +++ b/LoRaMac.h Mon Sep 26 05:53:55 2016 +0000 @@ -57,12 +57,12 @@ /*! * Class A&B receive delay 1 in us */ -#define RECEIVE_DELAY1 1000000 +#define RECEIVE_DELAY1 500000 /*! * Class A&B receive delay 2 in us */ -#define RECEIVE_DELAY2 2000000 +#define RECEIVE_DELAY2 4000000 /*! * Join accept receive delay 1 in us