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

Allow LoRa NVRAM save/restore of current RX2 settings #94

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 19 additions & 1 deletion esp32/mods/modlora.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static lora_rx_data_t rx_data_isr;
static TimerEvent_t TxNextActReqTimer;

static nvs_handle modlora_nvs_handle;
static const char *modlora_nvs_data_key[E_LORA_NVS_NUM_KEYS] = { "JOINED", "UPLNK", "DWLNK", "DEVADDR", "NWSKEY", "APPSKEY", "NETID", "ADRACK", "CHNLMASK", "CHANNELS"};
static const char *modlora_nvs_data_key[E_LORA_NVS_NUM_KEYS] = { "JOINED", "UPLNK", "DWLNK", "DEVADDR", "NWSKEY", "APPSKEY", "NETID", "ADRACK", "CHNLMASK", "CHANNELS", "RX2CHANNEL"};

/******************************************************************************
DECLARE PRIVATE FUNCTIONS
Expand Down Expand Up @@ -336,6 +336,14 @@ bool modlora_nvs_get_uint(uint32_t key_idx, uint32_t *value) {
return false;
}

bool modlora_nvs_get_uint8(uint32_t key_idx, uint8_t *value) {
esp_err_t err;
if (ESP_OK == (err = nvs_get_u8(modlora_nvs_handle, modlora_nvs_data_key[key_idx], value))) {
return true;
}
return false;
}

bool modlora_nvs_get_blob(uint32_t key_idx, void *value, uint32_t *length) {
esp_err_t err;
if (ESP_OK == (err = nvs_get_blob(modlora_nvs_handle, modlora_nvs_data_key[key_idx], value, length))) {
Expand Down Expand Up @@ -734,6 +742,11 @@ static void TASK_LoRa (void *pvParameters) {
uint16_t ChannelsMask[6];
length = sizeof(ChannelsMask);
result &= modlora_nvs_get_blob(E_LORA_NVS_ELE_CHANNEL_MASK, (void *)ChannelsMask, &length);


Rx2ChannelParams_t rx2Channel;
length = sizeof(Rx2ChannelParams_t);
result &= modlora_nvs_get_blob(E_LORA_NVS_ELE_RX2_CHANNEL, &rx2Channel, &length);

if (result) {
mibReq.Type = MIB_UPLINK_COUNTER;
Expand All @@ -755,6 +768,11 @@ static void TASK_LoRa (void *pvParameters) {
// write the channel list directly from the NVRAM
length = LORA_MAX_NB_CHANNELS * sizeof(ChannelParams_t);
modlora_nvs_get_blob(E_LORA_NVS_ELE_CHANNELS, (void *)LoRaMacGetChannelList(), &length);

// Write RX2 window parameters from NVRAM
mibReq.Type = MIB_RX2_CHANNEL;
mibReq.Param.Rx2Channel = rx2Channel;
LoRaMacMibSetRequestConfirm( &mibReq );

lora_obj.activation = E_LORA_ACTIVATION_ABP;
lora_obj.state = E_LORA_STATE_JOIN;
Expand Down
3 changes: 2 additions & 1 deletion esp32/mods/modlora.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ typedef enum {
E_LORA_NVS_ELE_NET_ID,
E_LORA_NVS_ELE_ADR_ACKS,
E_LORA_NVS_ELE_CHANNEL_MASK,
E_LORA_NVS_ELE_CHANNELS,
E_LORA_NVS_ELE_CHANNELS,
E_LORA_NVS_ELE_RX2_CHANNEL,
E_LORA_NVS_NUM_KEYS
} e_lora_nvs_key_t;

Expand Down
2 changes: 2 additions & 0 deletions lib/lora/mac/LoRaMac.c
Original file line number Diff line number Diff line change
Expand Up @@ -4316,6 +4316,8 @@ void LoRaMacNvsSave( void )
modlora_nvs_set_uint(E_LORA_NVS_ELE_ADR_ACKS, AdrAckCounter);
modlora_nvs_set_blob(E_LORA_NVS_ELE_CHANNEL_MASK, LoRaMacParams.ChannelsMask, sizeof(LoRaMacParams.ChannelsMask));
modlora_nvs_set_blob(E_LORA_NVS_ELE_CHANNELS, Channels, sizeof(Channels));

modlora_nvs_set_blob(E_LORA_NVS_ELE_RX2_CHANNEL, &LoRaMacParams.Rx2Channel, sizeof(LoRaMacParams.Rx2Channel));
}

void LoRaMacTestSetDutyCycleOn( bool enable )
Expand Down