From ddf561ea3eef9711873435444b787e5f2d400f2b Mon Sep 17 00:00:00 2001 From: Terry Moore Date: Sat, 16 Mar 2019 17:27:46 -0400 Subject: [PATCH] Fix #77: Enable long messages --- README.md | 5 +++++ src/lmic/config.h | 6 ++++++ src/lmic/lorabase.h | 2 +- src/lmic/radio.c | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59592045..7fd1018b 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ requires C99 mode to be enabled by default. - [Disabling Class B MAC commands](#disabling-class-b-mac-commands) - [Disabling user events](#disabling-user-events) - [Disabling external reference to `onEvent()`](#disabling-external-reference-to-onevent) + - [Enabling long messages](#enabling-long-messages) - [Special purpose](#special-purpose) - [Supported hardware](#supported-hardware) - [Pre-Integrated Boards](#pre-integrated-boards) @@ -319,6 +320,10 @@ Code to handle registered callbacks for tx, rx, and events can be suppressed by In some embedded systems, `onEvent()` may be defined for some other purpose; so the weak reference to the function `onEvent` will be satified, causing the LMIC to try to call that function. All reference to `onEvent()` can be suppressed by setting `LMIC_ENABLE_onEvent` to 0. This C preprocessor macro is always defined as a post-condition of `#include "config.h"`; if non-zero, a weak reference to `onEvent()` will be used; if zero, the user `onEvent()` function is not supported, and the client must register an event handler explicitly. +#### Enabling long messages + +To save RAM for simple devices, the LMIC allows message length to be limited to 64 bytes instead of the LoRaWAN standard of 255 bytes max. This saves about 2*192 bytes of RAM. Unfortunately, compliance tests require the full message size. Long messages are enabled by setting `LMIC_ENABLE_long_messages` to 1, or disabled by setting it to zero. This C preprocessor macro is always defined as a post-condition of `#include "config.h"`; if non-zero, the maximum frame size is 255 bytes, and if zero, the maximum frame size is 64 bytes. + #### Special purpose `#define DISABLE_INVERT_IQ_ON_RX` disables the inverted Q-I polarity on RX. If this is defined, end-devices will be able diff --git a/src/lmic/config.h b/src/lmic/config.h index 2a5c14cc..8082efe9 100644 --- a/src/lmic/config.h +++ b/src/lmic/config.h @@ -192,4 +192,10 @@ # define LMIC_ENABLE_onEvent 1 #endif +// LMIC_ENABLE_long_messages +// LMIC certification requires that this be enabled. +#if !defined(LMIC_ENABLE_long_messages) +# define LMIC_ENABLE_long_messages 1 /* PARAM */ +#endif + #endif // _lmic_config_h_ diff --git a/src/lmic/lorabase.h b/src/lmic/lorabase.h index abde580d..ff2f10b0 100644 --- a/src/lmic/lorabase.h +++ b/src/lmic/lorabase.h @@ -59,7 +59,7 @@ enum { ILLEGAL_RPS = 0xFF }; // Global maximum frame length enum { STD_PREAMBLE_LEN = 8 }; -enum { MAX_LEN_FRAME = 64 }; +enum { MAX_LEN_FRAME = LMIC_ENABLE_long_messages ? 255 : 64 }; enum { LEN_DEVNONCE = 2 }; enum { LEN_ARTNONCE = 3 }; enum { LEN_NETID = 3 }; diff --git a/src/lmic/radio.c b/src/lmic/radio.c index 0f858c07..4591b8a0 100644 --- a/src/lmic/radio.c +++ b/src/lmic/radio.c @@ -634,7 +634,7 @@ static void rxlora (u1_t rxmode) { // set LNA gain writeReg(RegLna, LNA_RX_GAIN); // set max payload size - writeReg(LORARegPayloadMaxLength, 64); + writeReg(LORARegPayloadMaxLength, MAX_LEN_FRAME); #if !defined(DISABLE_INVERT_IQ_ON_RX) // use inverted I/Q signal (prevent mote-to-mote communication)