Skip to content

Commit

Permalink
Parameterize initLmic() and setAbpParameters()
Browse files Browse the repository at this point in the history
Parameterize initLmic() and setAbpParameters().
Fix incorrect #if statement.
  • Loading branch information
lnlp committed May 15, 2021
1 parent 6e8e458 commit f0b8b86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/LMIC-node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void printHeader(void)


#ifdef ABP_ACTIVATION
void setAbpParameters(void)
void setAbpParameters(dr_t dataRate = DR_SF7, s1_t txPower = 14)
{
// Set static session parameters. Instead of dynamically establishing a session
// by joining the network, precomputed session parameters are be provided.
Expand Down Expand Up @@ -459,34 +459,32 @@ void printHeader(void)
LMIC.dn2Dr = DR_SF9;

// Set data rate and transmit power (note: txpow seems to be ignored by the library)
LMIC_setDrTxpow(DR_SF7, 14);
LMIC_setDrTxpow(dataRate, txPower);
}
#endif //ABP_ACTIVATION


void initLmic() {
void initLmic(bit_t adrEnabled = 1, dr_t dataRate = DR_SF7, s1_t txPower = 14, bool setDrTxPowForOtaaExplicit = false) {

// Initialize LMIC runtime environment
os_init();
// Reset MAC state
LMIC_reset();

#ifdef ABP_ACTIVATION
setAbpParameters();
setAbpParameters(dataRate, txPower);
#endif

// Enable or disable ADR (data rate adaptation).
// Should be turned off if the device is not stationary (mobile).
// 1 is on, 0 is off.
const bit_t adrEnabled = 1;
LMIC_setAdrMode(adrEnabled);

// Set/override data rate and transmit power.
// Should only be used if ADR is disabled.
// Note: When using ABP activation below values will override those set in setAbpParameters();
#if adrEnabled == 0
// LMIC_setDrTxpow(DR_SF7, 14);
#endif
// Optional: set/override data rate and transmit power for OTAA (only use if ADR is disabled).
if (setDrTxPowForOtaaExplicit && !adrEnabled && activationType == ActivationType::OTAA)
{
LMIC_setDrTxpow(dataRate, txPower);
}

// Relax LMIC timing if defined
#if defined(LMIC_CLOCK_ERROR_PPM) && LMIC_CLOCK_ERROR_PPM > 0
Expand Down
7 changes: 7 additions & 0 deletions src/LMIC-node.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ void processDownlink(ostime_t eventTimestamp, uint8_t fPort, uint8_t* data, uint
#define OTAA_ACTIVATION
#endif

enum class ActivationType {OTAA, ABP};
#ifdef OTAA_ACTIVATION
const ActivationType activationType = ActivationType::OTAA;
#else
const ActivationType activationType = ActivationType::ABP;
#endif


#include BSFILE // Include Board Support File
#include "../keyfiles/lorawan-keys.h"
Expand Down

0 comments on commit f0b8b86

Please sign in to comment.