Fork of Semtech LoRaWAN stack
Fork of LoRaWAN-lib by
Diff: LoRaMac.cpp
- Branch:
- v4.2.0
- Revision:
- 16:1e01c8728daa
- Parent:
- 15:167ad88b7272
- Child:
- 17:fca344a6ff18
--- a/LoRaMac.cpp Tue Sep 13 05:39:43 2016 +0000
+++ b/LoRaMac.cpp Tue Sep 13 12:17:45 2016 +0000
@@ -402,6 +402,22 @@
#endif
+/*!
+ * Defines the first channel for RX window 2 for US band
+ */
+#define LORAMAC_FIRST_RX2_CHANNEL ( (uint32_t) 923.3e6 )
+
+/*!
+ * Defines the last channel for RX window 2 for US band
+ */
+#define LORAMAC_LAST_RX2_CHANNEL ( (uint32_t) 927.5e6 )
+
+/*!
+ * Defines the step width of the channels for RX window 2
+ */
+#define LORAMAC_STEPWIDTH_RX2_CHANNEL ( (uint32_t) 600e3 )
+
+
#else
#error "Please define a frequency band in the compiler options."
#endif
@@ -699,6 +715,16 @@
static void RxWindowSetup( uint32_t freq, int8_t datarate, uint32_t bandwidth, uint16_t timeout, bool rxContinuous );
/*!
+ * \brief Verifies if the RX window 2 frequency is in range
+ *
+ * \param [IN] freq window channel frequency
+ *
+ * \retval status Function status [1: OK, 0: Frequency not applicable]
+ */
+static bool Rx2FreqInRange( uint32_t freq );
+
+
+/*!
* \brief Adds a new MAC command to be sent.
*
* \Remark MAC layer internal function
@@ -2058,6 +2084,23 @@
}
}
+static bool Rx2FreqInRange( uint32_t freq )
+{
+#if defined( USE_BAND_433 ) || defined( USE_BAND_780 ) || defined( USE_BAND_868 )
+ if( Radio.CheckRfFrequency( freq ) == true )
+#elif ( defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) )
+ if( ( Radio.CheckRfFrequency( freq ) == true ) &&
+ ( freq >= LORAMAC_FIRST_RX2_CHANNEL ) &&
+ ( freq <= LORAMAC_LAST_RX2_CHANNEL ) &&
+ ( ( ( freq - ( uint32_t ) LORAMAC_FIRST_RX2_CHANNEL ) % ( uint32_t ) LORAMAC_STEPWIDTH_RX2_CHANNEL ) == 0 ) )
+#endif
+ {
+ return true;
+ }
+ return false;
+}
+
+
static bool ValidatePayloadLength( uint8_t lenN, int8_t datarate, uint8_t fOptsLen )
{
uint16_t maxN = 0;
@@ -2538,28 +2581,11 @@
freq |= ( uint32_t )payload[macIndex++] << 8;
freq |= ( uint32_t )payload[macIndex++] << 16;
freq *= 100;
-
-
-#if ( defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID ) )
- if( ( freq < 923.2e6 ) || ( freq > 927.5e6 ) )
+
+ if( Rx2FreqInRange( freq ) == false )
{
status &= 0xFE; // Channel frequency KO
}
- else
- {
- uint32_t freqTmp;
- freqTmp = (int)( freq - 923.3e6 )/600e3;
- if( ( freq - 923.3e6 ) - ( freqTmp * 600e3 ) > 0 )
- {
- status &= 0xFE; // Channel frequency KO
- }
- }
-#else
- if( Radio.CheckRfFrequency( freq ) == false )
- {
- status &= 0xFE; // Channel frequency KO
- }
-#endif
if( ValueInRange( datarate, LORAMAC_RX_MIN_DATARATE, LORAMAC_RX_MAX_DATARATE ) == false )


