Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ST fw update for band selection at runtime #23

Merged
merged 3 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 51 additions & 46 deletions Middlewares/Third_Party/LoRaWAN/Mac/LoRaMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,53 @@
*/
#define LORAMAC_CRYPTO_MULTICAST_KEYS 127

/*!
* LoRaMAC region enumeration
*/
typedef enum eLoRaMacRegion_t
{
/*!
* AS band on 923MHz
*/
LORAMAC_REGION_AS923,
/*!
* Australian band on 915MHz
*/
LORAMAC_REGION_AU915,
/*!
* Chinese band on 470MHz
*/
LORAMAC_REGION_CN470,
/*!
* Chinese band on 779MHz
*/
LORAMAC_REGION_CN779,
/*!
* European band on 433MHz
*/
LORAMAC_REGION_EU433,
/*!
* European band on 868MHz
*/
LORAMAC_REGION_EU868,
/*!
* South korean band on 920MHz
*/
LORAMAC_REGION_KR920,
/*!
* India band on 865MHz
*/
LORAMAC_REGION_IN865,
/*!
* North american band on 915MHz
*/
LORAMAC_REGION_US915,
/*!
* Russia band on 864MHz
*/
LORAMAC_REGION_RU864,
}LoRaMacRegion_t;

/*!
* End-Device activation type
*/
Expand Down Expand Up @@ -915,6 +962,10 @@ typedef struct sMcpsIndication
* Set if a DeviceTimeAns MAC command was received.
*/
bool DeviceTimeAnsReceived;
/*!
* Set the region currently in use
*/
LoRaMacRegion_t Region;
}McpsIndication_t;

/*!
Expand Down Expand Up @@ -2244,52 +2295,6 @@ typedef enum eLoRaMacStatus
LORAMAC_STATUS_ERROR
}LoRaMacStatus_t;

/*!
* LoRaMAC region enumeration
*/
typedef enum eLoRaMacRegion_t
{
/*!
* AS band on 923MHz
*/
LORAMAC_REGION_AS923,
/*!
* Australian band on 915MHz
*/
LORAMAC_REGION_AU915,
/*!
* Chinese band on 470MHz
*/
LORAMAC_REGION_CN470,
/*!
* Chinese band on 779MHz
*/
LORAMAC_REGION_CN779,
/*!
* European band on 433MHz
*/
LORAMAC_REGION_EU433,
/*!
* European band on 868MHz
*/
LORAMAC_REGION_EU868,
/*!
* South korean band on 920MHz
*/
LORAMAC_REGION_KR920,
/*!
* India band on 865MHz
*/
LORAMAC_REGION_IN865,
/*!
* North american band on 915MHz
*/
LORAMAC_REGION_US915,
/*!
* Russia band on 864MHz
*/
LORAMAC_REGION_RU864,
}LoRaMacRegion_t;

/*!
* Enumeration of modules which have a context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ extern "C" {
#define RADIO_DIO_5_PORT GPIOA
#define RADIO_DIO_5_PIN GPIO_PIN_4

#define RADIO_TCXO_VCC_PORT GPIOA
#define RADIO_TCXO_VCC_PIN GPIO_PIN_12
#define RADIO_TCXO_VCC_PORT GPIOB
#define RADIO_TCXO_VCC_PIN GPIO_PIN_6

#define RADIO_ANT_SWITCH_PORT_RX GPIOA //CRF1
#define RADIO_ANT_SWITCH_PIN_RX GPIO_PIN_1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef enum eATEerror

/* AT Command strings. Commands start with AT */
#define AT_RESET "Z"
#define AT_BAND "+BAND"
#define AT_DEUI "+DEUI"
#define AT_DADDR "+DADDR"
#define AT_APPKEY "+APPKEY"
Expand Down Expand Up @@ -131,6 +132,20 @@ ATEerror_t at_return_error(const char *param);
*/
ATEerror_t at_reset(const char *param);

/**
* @brief Print RF Band in use
* @param Param string of the AT command
* @retval AT_OK if OK, or an appropriate AT_xxx error code
*/
ATEerror_t at_Band_get(const char *param);

/**
* @brief Set RF Band in use
* @param Param string of the AT command
* @retval AT_OK if OK, or an appropriate AT_xxx error code
*/
ATEerror_t at_Band_set(const char *param);

/**
* @brief Print Device EUI
* @param Param string of the AT command - unused
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ typedef struct sLoRaMainCallback
* @param [IN] application parmaters
* @retval none
*/
void LORA_Init(LoRaMainCallback_t *callbacks, LoRaParam_t *LoRaParam);
void LORA_Init(LoRaMainCallback_t *callbacks, LoRaParam_t *LoRaParam, LoRaMacRegion_t region);

/**
* @brief run Lora classA state Machine
Expand Down Expand Up @@ -388,6 +388,13 @@ int8_t lora_config_tx_datarate_get(void);
*/
LoRaMacRegion_t lora_region_get(void);

/**
* @brief triggers a reinit when band gets changed
* @param none
* @retval none
*/
void TriggerReinit( LoRaMacRegion_t region );

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,13 @@ ATEerror_t at_JoinEUI_set(const char *param)
return AT_PARAM_ERROR;
}

MibRequestConfirm_t mib;
LoRaMacStatus_t status;
lora_config_joineui_set(JoinEui);
mib.Type = MIB_JOIN_EUI;
mib.Param.JoinEui = JoinEui;
status = LoRaMacMibSetRequestConfirm(&mib);
CHECK_STATUS(status);
return AT_OK;
}

Expand Down Expand Up @@ -410,6 +416,27 @@ ATEerror_t at_AppKey_set(const char *param)
return AT_OK;
}

extern LoRaMacRegion_t globalRegion;
ATEerror_t at_Band_get(const char *param)
{
print_d(globalRegion);
return AT_OK;
}

ATEerror_t at_Band_set(const char *param)
{
LoRaMacRegion_t region;
if (tiny_sscanf(param, "%hhu", &region) != 1)
{
return AT_PARAM_ERROR;
}
if (region != globalRegion) {
globalRegion = region;
TriggerReinit(globalRegion);
}
return AT_OK;
}

ATEerror_t at_NwkSKey_get(const char *param)
{
MibRequestConfirm_t mib;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ static const struct ATCommand_s ATCommand[] =
},
#endif

#ifndef NO_BAND_RUNTIME_SWITCH
{
.string = AT_BAND,
.size_string = sizeof(AT_BAND) - 1,
#ifndef NO_HELP
.help_string = "AT"AT_BAND ": Get or Set the Regional Band\r\n",
#endif
.get = at_Band_get,
.set = at_Band_set,
.run = at_return_error,
},
#endif

#ifndef NO_KEY_ADDR_EUI
{
.string = AT_APPKEY,
Expand Down
Loading