Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Add support for EU433 region
Browse files Browse the repository at this point in the history
Thanks to @robert-hh for the contribution via robert-hh@3b12fc5

Co-Authored-By: robert-hh <robert-hh@users.noreply.github.com>
  • Loading branch information
Xykon and robert-hh committed Jun 26, 2020
1 parent 57b8aab commit 3c72da7
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 6 deletions.
3 changes: 2 additions & 1 deletion esp32/application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ APP_LIB_LORA_SRC_C = $(addprefix lib/lora/,\
mac/region/RegionEU868.c \
mac/region/RegionUS915.c \
mac/region/RegionCN470.c \
mac/region/RegionEU433.c \
mac/region/RegionIN865.c \
system/delay.c \
system/gpio.c \
Expand Down Expand Up @@ -375,7 +376,7 @@ APP_LDFLAGS += $(LDFLAGS) -T esp32_out.ld -T esp32.project.ld -T esp32.rom.ld -T
# add the application specific CFLAGS
CFLAGS += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM -DFFCONF_H=\"lib/oofatfs/ffconf.h\" -DWITH_POSIX
CFLAGS_SIGFOX += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM
CFLAGS += -DREGION_AS923 -DREGION_AU915 -DREGION_EU868 -DREGION_US915 -DREGION_CN470 -DREGION_IN865 -DBASE=0 -DPYBYTES=1
CFLAGS += -DREGION_AS923 -DREGION_AU915 -DREGION_EU868 -DREGION_US915 -DREGION_CN470 -DREGION_EU433 -DREGION_IN865 -DBASE=0 -DPYBYTES=1
# Specify if this is base or Pybytes Firmware
ifeq ($(VARIANT),BASE)
CFLAGS += -DVARIANT=0
Expand Down
30 changes: 26 additions & 4 deletions esp32/mods/modlora.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "lora/mac/region/RegionEU868.h"
#include "lora/mac/region/RegionCN470.h"
#include "lora/mac/region/RegionIN865.h"
#include "lora/mac/region/RegionEU433.h"

// openThread includes
#ifdef LORA_OPENTHREAD_ENABLED
Expand Down Expand Up @@ -1361,12 +1362,17 @@ static void lora_validate_frequency (uint32_t frequency) {
goto freq_error;
}
break;
case LORAMAC_REGION_EU868:
case LORAMAC_REGION_EU433:
#if defined(LOPY4)
if (frequency < 410000000 || frequency > 870000000) {
if (frequency < 433000000 || frequency > 435000000) { // LoRa 433 - 434
goto freq_error;
}
#else
if (frequency < 863000000 || frequency > 870000000) {
goto freq_error;
#endif
break;
case LORAMAC_REGION_EU868:
if (frequency < 863000000 || frequency > 870000000) {
goto freq_error;
}
break;
Expand Down Expand Up @@ -1437,6 +1443,7 @@ static bool lora_validate_data_rate (uint32_t data_rate) {
case LORAMAC_REGION_AS923:
case LORAMAC_REGION_EU868:
case LORAMAC_REGION_AU915:
case LORAMAC_REGION_EU433:
case LORAMAC_REGION_CN470:
case LORAMAC_REGION_IN865:
if (data_rate > DR_6) {
Expand Down Expand Up @@ -1489,11 +1496,16 @@ static void lora_validate_device_class (DeviceClass_t device_class) {
static void lora_validate_region (LoRaMacRegion_t region) {
if (region != LORAMAC_REGION_AS923 && region != LORAMAC_REGION_AU915
&& region != LORAMAC_REGION_EU868 && region != LORAMAC_REGION_US915
&& region != LORAMAC_REGION_CN470 && region != LORAMAC_REGION_IN865) {
&& region != LORAMAC_REGION_IN865
#if defined(LOPY4)
&& region != LORAMAC_REGION_EU433 && region != LORAMAC_REGION_CN470
#endif
) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid region %d", region));
}
}


static void lora_set_config (lora_cmd_data_t *cmd_data) {
lora_obj.stack_mode = cmd_data->info.init.stack_mode;
lora_obj.bandwidth = cmd_data->info.init.bandwidth;
Expand Down Expand Up @@ -1710,6 +1722,9 @@ static mp_obj_t lora_init_helper(lora_obj_t *self, const mp_arg_val_t *args) {
case LORAMAC_REGION_EU868:
cmd_data.info.init.frequency = 868000000;
break;
case LORAMAC_REGION_EU433:
cmd_data.info.init.frequency = 433175000;
break;
case LORAMAC_REGION_CN470:
cmd_data.info.init.frequency = 470000000;
case LORAMAC_REGION_IN865:
Expand All @@ -1735,6 +1750,9 @@ static mp_obj_t lora_init_helper(lora_obj_t *self, const mp_arg_val_t *args) {
case LORAMAC_REGION_EU868:
cmd_data.info.init.tx_power = 14;
break;
case LORAMAC_REGION_EU433:
cmd_data.info.init.tx_power = 12;
break;
default:
break;
}
Expand Down Expand Up @@ -1894,6 +1912,7 @@ STATIC mp_obj_t lora_join(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *
break;
case LORAMAC_REGION_CN470:
case LORAMAC_REGION_EU868:
case LORAMAC_REGION_EU433:
case LORAMAC_REGION_IN865:
dr = DR_5;
break;
Expand Down Expand Up @@ -1925,6 +1944,7 @@ STATIC mp_obj_t lora_join(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *
goto dr_error;
}
break;
case LORAMAC_REGION_EU433:
case LORAMAC_REGION_CN470:
case LORAMAC_REGION_EU868:
if (dr > DR_5) {
Expand Down Expand Up @@ -2506,6 +2526,7 @@ STATIC const mp_map_elem_t lora_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_US915), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_US915) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_CN470), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_CN470) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_IN865), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_IN865) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_EU433), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_EU433) },
};

STATIC MP_DEFINE_CONST_DICT(lora_locals_dict, lora_locals_dict_table);
Expand Down Expand Up @@ -2551,6 +2572,7 @@ static int lora_socket_socket (mod_network_socket_obj_t *s, int *_errno) {
switch (lora_obj.region) {
case LORAMAC_REGION_AS923:
case LORAMAC_REGION_EU868:
case LORAMAC_REGION_EU433:
case LORAMAC_REGION_CN470:
dr = DR_5;
break;
Expand Down
6 changes: 6 additions & 0 deletions lib/lora/mac/region/Region.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,11 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
#define EU433_NEXT_CHANNEL( ) else if(region == LORAMAC_REGION_EU433) { return RegionEU433NextChannel( nextChanParams, channel, time, aggregatedTimeOff ); }
#define EU433_CHANNEL_ADD( ) else if(region == LORAMAC_REGION_EU433) { return RegionEU433ChannelAdd( channelAdd ); }
#define EU433_CHANNEL_REMOVE( ) else if(region == LORAMAC_REGION_EU433) { return RegionEU433ChannelsRemove( channelRemove ); }
#define EU433_CHANNEL_MANUAL_ADD( ) EU433_CASE { return RegionEU433ChannelManualAdd( channelAdd ); }
#define EU433_CHANNEL_MANUAL_REMOVE( ) EU433_CASE { return RegionEU433ChannelsRemove( channelRemove ); }
#define EU433_SET_CONTINUOUS_WAVE( ) else if(region == LORAMAC_REGION_EU433) { RegionEU433SetContinuousWave( continuousWave );}
#define EU433_APPLY_DR_OFFSET( ) else if(region == LORAMAC_REGION_EU433) { return RegionEU433ApplyDrOffset( downlinkDwellTime, dr, drOffset ); }
#define EU433_FORCE_JOIN_DATARATE( ) EU433_CASE { return RegionEU433ForceJoinDataRate( joinDr, alternateDr ); }
#else
#define EU433_IS_ACTIVE( )
#define EU433_GET_PHY_PARAM( )
Expand All @@ -310,8 +313,11 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
#define EU433_NEXT_CHANNEL( )
#define EU433_CHANNEL_ADD( )
#define EU433_CHANNEL_REMOVE( )
#define EU433_CHANNEL_MANUAL_ADD( )
#define EU433_CHANNEL_MANUAL_REMOVE( )
#define EU433_SET_CONTINUOUS_WAVE( )
#define EU433_APPLY_DR_OFFSET( )
#define EU433_FORCE_JOIN_DATARATE( )
#endif

#ifdef REGION_EU868
Expand Down
81 changes: 80 additions & 1 deletion lib/lora/mac/region/RegionEU433.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jae
#include <math.h>

#include "board.h"
#include "LoRaMac.h"
#include "lora/mac/LoRaMac.h"
#include "esp_attr.h"

#include "utilities.h"
Expand Down Expand Up @@ -1007,6 +1007,76 @@ LoRaMacStatus_t RegionEU433ChannelAdd( ChannelAddParams_t* channelAdd )
return LORAMAC_STATUS_OK;
}

LoRaMacStatus_t RegionEU433ChannelManualAdd( ChannelAddParams_t* channelAdd )
{
uint8_t band = 0;
bool drInvalid = false;
bool freqInvalid = false;
uint8_t id = channelAdd->ChannelId;

if( id >= EU433_MAX_NB_CHANNELS )
{
return LORAMAC_STATUS_PARAMETER_INVALID;
}

// Validate the datarate range
if( RegionCommonValueInRange( channelAdd->NewChannel->DrRange.Fields.Min, EU433_TX_MIN_DATARATE, EU433_TX_MAX_DATARATE ) == false )
{
drInvalid = true;
}
if( RegionCommonValueInRange( channelAdd->NewChannel->DrRange.Fields.Max, EU433_TX_MIN_DATARATE, EU433_TX_MAX_DATARATE ) == false )
{
drInvalid = true;
}
if( channelAdd->NewChannel->DrRange.Fields.Min > channelAdd->NewChannel->DrRange.Fields.Max )
{
drInvalid = true;
}

// Default channels don't accept all values
if( id < EU433_NUMB_DEFAULT_CHANNELS )
{
// Validate the datarate range for min: must be DR_0
if( channelAdd->NewChannel->DrRange.Fields.Min > DR_0 )
{
drInvalid = true;
}
// Validate the datarate range for max: must be DR_5 <= Max <= TX_MAX_DATARATE
if( RegionCommonValueInRange( channelAdd->NewChannel->DrRange.Fields.Max, DR_5, EU433_TX_MAX_DATARATE ) == false )
{
drInvalid = true;
}
}

// Check frequency
if( freqInvalid == false )
{
if( VerifyTxFreq( channelAdd->NewChannel->Frequency ) == false )
{
freqInvalid = true;
}
}

// Check status
if( ( drInvalid == true ) && ( freqInvalid == true ) )
{
return LORAMAC_STATUS_FREQ_AND_DR_INVALID;
}
if( drInvalid == true )
{
return LORAMAC_STATUS_DATARATE_INVALID;
}
if( freqInvalid == true )
{
return LORAMAC_STATUS_FREQUENCY_INVALID;
}

memcpy( &(Channels[id]), channelAdd->NewChannel, sizeof( Channels[id] ) );
Channels[id].Band = band;
ChannelsMask[0] |= ( 1 << id );
return LORAMAC_STATUS_OK;
}

bool RegionEU433ChannelsRemove( ChannelRemoveParams_t* channelRemove )
{
uint8_t id = channelRemove->ChannelId;
Expand Down Expand Up @@ -1044,3 +1114,12 @@ uint8_t RegionEU433ApplyDrOffset( uint8_t downlinkDwellTime, int8_t dr, int8_t d
}
return datarate;
}

bool RegionEU433ForceJoinDataRate( int8_t joinDr, AlternateDrParams_t* alternateDr )
{
uint8_t DRToCounter[6] = { 48, 32, 24, 16, 8, 1 };
if (joinDr < sizeof(DRToCounter)) {
alternateDr->NbTrials = DRToCounter[joinDr];
}
return true;
}
11 changes: 11 additions & 0 deletions lib/lora/mac/region/RegionEU433.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ LoRaMacStatus_t RegionEU433ChannelAdd( ChannelAddParams_t* channelAdd );
*/
bool RegionEU433ChannelsRemove( ChannelRemoveParams_t* channelRemove );

/*!
* \brief Adds a channel manually.
*
* \param [IN] channelAdd Pointer to the function parameters.
*
* \retval Status of the operation.
*/
LoRaMacStatus_t RegionEU433ChannelManualAdd( ChannelAddParams_t* channelAdd );

/*!
* \brief Sets the radio into continuous wave mode.
*
Expand All @@ -461,6 +470,8 @@ void RegionEU433SetContinuousWave( ContinuousWaveParams_t* continuousWave );
*/
uint8_t RegionEU433ApplyDrOffset( uint8_t downlinkDwellTime, int8_t dr, int8_t drOffset );

bool RegionCN470ForceJoinDataRate( int8_t joinDr, AlternateDrParams_t *alternateDr );

/*! \} defgroup REGIONEU433 */

#endif // __REGION_EU433_H__

0 comments on commit 3c72da7

Please sign in to comment.