Lora-net / LoRaMac-node

Reference implementation and documentation of a LoRa network node.
Other
1.89k stars 1.09k forks source link

How to add a RU868 band? #200

Closed Cr0s closed 7 years ago

Cr0s commented 7 years ago

Hello.

I'd like to know how to modify definitions in LoRaMAC code in order to add a new frequency band named RU868 (Russian 868 MHz band, LoRa Alliance approval is pending).

The band's characteristics are following: image

My initial guess based on EU868:

LoRaMac-definitions.h:

#elif defined( USE_BAND_868_RU )
/*
 * ***********************************************************
 */

/*!
 * LoRaMac maximum number of channels
 */
#define LORA_MAX_NB_CHANNELS                        7

/*!
 * Minimal datarate that can be used by the node
 */
#define LORAMAC_TX_MIN_DATARATE                     DR_0

/*!
 * Maximal datarate that can be used by the node
 */
#define LORAMAC_TX_MAX_DATARATE                     DR_7

/*!
 * Minimal datarate that can be used by the node
 */
#define LORAMAC_RX_MIN_DATARATE                     DR_0

/*!
 * Maximal datarate that can be used by the node
 */
#define LORAMAC_RX_MAX_DATARATE                     DR_7

/*!
 * Default datarate used by the node
 */
#define LORAMAC_DEFAULT_DATARATE                    DR_0

/*!
 * Minimal Rx1 receive datarate offset
 */
#define LORAMAC_MIN_RX1_DR_OFFSET                   0

/*!
 * Maximal Rx1 receive datarate offset
 */
#define LORAMAC_MAX_RX1_DR_OFFSET                   5

/*!
 * Minimal Tx output power that can be used by the node
 */
#define LORAMAC_MIN_TX_POWER                        TX_POWER_02_DBM

/*!
 * Maximal Tx output power that can be used by the node
 */
#define LORAMAC_MAX_TX_POWER                        TX_POWER_14_DBM

/*!
 * Default Tx output power used by the node
 */
#ifndef LORAMAC_DEFAULT_TX_POWER
#define LORAMAC_DEFAULT_TX_POWER                    TX_POWER_14_DBM
#endif

/*!
 * LoRaMac TxPower definition
 */
#define TX_POWER_20_DBM                             0
#define TX_POWER_14_DBM                             1
#define TX_POWER_11_DBM                             2
#define TX_POWER_08_DBM                             3
#define TX_POWER_05_DBM                             4
#define TX_POWER_02_DBM                             5

/*!
 * LoRaMac datarates definition
 */
#define DR_0                                        0  // SF12 - BW125
#define DR_1                                        1  // SF11 - BW125
#define DR_2                                        2  // SF10 - BW125
#define DR_3                                        3  // SF9  - BW125
#define DR_4                                        4  // SF8  - BW125
#define DR_5                                        5  // SF7  - BW125
#define DR_6                                        6  // SF7  - BW250
#define DR_7                                        7  // FSK

/*!
 * Second reception window channel definition.
 */
// Channel = { Frequency [Hz], Datarate }
#define RX_WND_2_CHANNEL                                  { 864900000, DR_0 }

/*!
 * LoRaMac maximum number of bands
 */
#define LORA_MAX_NB_BANDS                           7

/*!
 * LoRaMac RU868 default bands
 */
typedef enum
{
    BAND_G1_0,
    BAND_G1_1,
    BAND_G1_2,
    BAND_G1_3,
    BAND_G1_4,
    BAND_G1_5,
    BAND_G1_6,
}BandId_t;

// Band = { DutyCycle, TxMaxPower, LastTxDoneTime, TimeOff }
#define BAND0              { 1000 , TX_POWER_14_DBM, 0,  0 }    //  0.1 %
#define BAND1              { 1000 , TX_POWER_14_DBM, 0,  0 }    //  0.1 %
#define BAND2              { 1000, TX_POWER_14_DBM, 0,  0 }     //  0.1 %
#define BAND3              { 1000  , TX_POWER_14_DBM, 0,  0 }   //  0.1 %
#define BAND4              { 1000 , TX_POWER_14_DBM, 0,  0 }    //  1.0 %
#define BAND5              { 100 , TX_POWER_14_DBM, 0,  0 }     //  1.0 %
#define BAND6              { 100 , TX_POWER_14_DBM, 0,  0 }     //  1.0 %

/*!
 * LoRaMac default channels
 */
// Channel = { Frequency [Hz], { ( ( DrMax << 4 ) | DrMin ) }, Band }
#define LC1                { 864100000, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
#define LC2                { 864300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
#define LC3                { 864500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
#define LC4                { 864700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
#define LC5                { 868850000, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }
#define LC6                { 869050000, { ( ( DR_5 << 4 ) | DR_0 ) }, 1 }

/*!
 * LoRaMac duty cycle for the back-off procedure
 */
#define BACKOFF_DC_1_HOUR       100
#define BACKOFF_DC_10_HOURS     1000
#define BACKOFF_DC_24_HOURS     10000

#define BACKOFF_RND_OFFSET      600000

/*!
 * LoRaMac channels which are allowed for the join procedure
 */
#define JOIN_CHANNELS      ( uint16_t )( LC( 1 ) | LC( 2 ) | LC( 3 ) )

LoRaMac.c:

#elif defined( USE_BAND_868_RU )
/*
 * ****************************************
 */
/*!
 * Data rates table definition
 */
const uint8_t Datarates[]  = { 12, 11, 10,  9,  8,  7,  7, 50 };

/*!
 * Maximum payload with respect to the datarate index. Cannot operate with repeater.
 */
const uint8_t MaxPayloadOfDatarate[] = { 51, 51, 51, 115, 242, 242, 242, 242 };

/*!
 * Maximum payload with respect to the datarate index. Can operate with repeater.
 */
const uint8_t MaxPayloadOfDatarateRepeater[] = { 51, 51, 51, 115, 222, 222, 222, 222 };

/*!
 * Tx output powers table definition
 */
const int8_t TxPowers[]    = { 14, 14, 11,  8,  5,  2 };

/*!
 * LoRaMac bands
 */
static Band_t Bands[LORA_MAX_NB_BANDS] =
{
    BAND0,
    BAND1,
    BAND2,
    BAND3,
    BAND4,
    BAND5,
    BAND6,
};

/*!
 * LoRaMAC channels
 */
static ChannelParams_t Channels[LORA_MAX_NB_CHANNELS] =
{
    LC1,
    LC2,
    LC3,
    LC4,
    LC5,
    LC6
};

Cheers!

mluis1 commented 7 years ago

So far I wasn't aware of a Russian band definition by the alliance. But, when they add it to the Regional parameters document we will provide the support for it.

Concerning your changes we think that you have covered almost all the aspects. Maybe the one that is left is searching everywhere the USE_BAND_868 definition usage and add the USE_BAND_868_RU condition as well.

nestorayuso commented 7 years ago

Here are some drafts of regional parameters for Russia https://github.com/brocaar/loraserver/issues/113

mluis1 commented 7 years ago

@nestorayuso Thanks for the info.