mirror of
https://github.com/manuelbl/ttn-esp32.git
synced 2025-07-27 03:42:51 +02:00
Simplify conditional compilation; add region Japan
This commit is contained in:
@ -20,7 +20,7 @@
|
||||
#include "lmic/lmic.h"
|
||||
#include "hal/hal_esp32.h"
|
||||
|
||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
||||
#if defined(TTN_HAS_AT_COMMANDS)
|
||||
const uart_port_t UART_NUM = (uart_port_t) CONFIG_TTN_PROVISION_UART_NUM;
|
||||
const int MAX_LINE_LENGTH = 128;
|
||||
#endif
|
||||
@ -35,7 +35,10 @@ static uint8_t global_dev_eui[8];
|
||||
static uint8_t global_app_eui[8];
|
||||
static uint8_t global_app_key[16];
|
||||
|
||||
|
||||
#if defined(TTN_HAS_AT_COMMANDS)
|
||||
void ttn_provisioning_task_caller(void* pvParameter);
|
||||
#endif
|
||||
|
||||
|
||||
// --- LMIC callbacks
|
||||
@ -67,7 +70,7 @@ void os_getDevKey (u1_t* buf)
|
||||
|
||||
TTNProvisioning::TTNProvisioning()
|
||||
: have_keys(false)
|
||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
||||
#if defined(TTN_HAS_AT_COMMANDS)
|
||||
, uart_queue(nullptr), line_buf(nullptr), line_length(0), last_line_end_char(0), quit_task(false)
|
||||
#endif
|
||||
{
|
||||
@ -76,9 +79,11 @@ TTNProvisioning::TTNProvisioning()
|
||||
|
||||
// --- Provisioning task
|
||||
|
||||
#if defined(TTN_HAS_AT_COMMANDS)
|
||||
|
||||
void TTNProvisioning::startTask()
|
||||
{
|
||||
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
||||
#if defined(TTN_CONFIG_UART)
|
||||
configUART();
|
||||
#endif
|
||||
|
||||
@ -287,7 +292,10 @@ void TTNProvisioning::processLine()
|
||||
uart_write_bytes(UART_NUM, is_ok ? "OK\r\n" : "ERROR\r\n", is_ok ? 4 : 7);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(TTN_CONFIG_UART)
|
||||
|
||||
void TTNProvisioning::configUART()
|
||||
{
|
||||
|
@ -22,23 +22,29 @@ class TTNProvisioning
|
||||
public:
|
||||
TTNProvisioning();
|
||||
|
||||
void startTask();
|
||||
bool haveKeys();
|
||||
bool decodeKeys(const char *dev_eui, const char *app_eui, const char *app_key);
|
||||
bool fromMAC(const char *app_eui, const char *app_key);
|
||||
bool saveKeys();
|
||||
bool restoreKeys(bool silent);
|
||||
|
||||
#if defined(TTN_HAS_AT_COMMANDS)
|
||||
void startTask();
|
||||
#endif
|
||||
|
||||
private:
|
||||
void provisioningTask();
|
||||
bool decode(bool incl_dev_eui, const char *dev_eui, const char *app_eui, const char *app_key);
|
||||
void addLineData(int numBytes);
|
||||
void detectLineEnd(int start_at);
|
||||
void processLine();
|
||||
bool readNvsValue(nvs_handle handle, const char* key, uint8_t* data, size_t expected_length, bool silent);
|
||||
bool writeNvsValue(nvs_handle handle, const char* key, const uint8_t* data, size_t len);
|
||||
|
||||
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
||||
#if defined(TTN_HAS_AT_COMMANDS)
|
||||
void provisioningTask();
|
||||
void addLineData(int numBytes);
|
||||
void detectLineEnd(int start_at);
|
||||
void processLine();
|
||||
#endif
|
||||
|
||||
#if defined(TTN_CONFIG_UART)
|
||||
void configUART();
|
||||
#endif
|
||||
|
||||
@ -53,15 +59,15 @@ private:
|
||||
private:
|
||||
bool have_keys = false;
|
||||
|
||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
||||
#if defined(TTN_HAS_AT_COMMANDS)
|
||||
QueueHandle_t uart_queue;
|
||||
char* line_buf;
|
||||
int line_length;
|
||||
uint8_t last_line_end_char;
|
||||
bool quit_task;
|
||||
#endif
|
||||
|
||||
friend void ttn_provisioning_task_caller(void* pvParameter);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -93,16 +93,21 @@ bool TheThingsNetwork::provisionWithMAC(const char *appEui, const char *appKey)
|
||||
return provisioning.saveKeys();
|
||||
}
|
||||
|
||||
|
||||
void TheThingsNetwork::startProvisioningTask()
|
||||
{
|
||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
||||
#if defined(TTN_HAS_AT_COMMANDS)
|
||||
provisioning.startTask();
|
||||
#else
|
||||
ESP_LOGE(TAG, "AT commands are disabled. Change the configuration using 'make menuconfig'");
|
||||
ASSERT(0);
|
||||
esp_restart();
|
||||
#endif
|
||||
}
|
||||
|
||||
void TheThingsNetwork::waitForProvisioning()
|
||||
{
|
||||
#if !defined(CONFIG_TTN_PROVISION_UART_NONE)
|
||||
#if defined(TTN_HAS_AT_COMMANDS)
|
||||
if (isProvisioned())
|
||||
{
|
||||
ESP_LOGI(TAG, "Device is already provisioned");
|
||||
@ -113,6 +118,10 @@ void TheThingsNetwork::waitForProvisioning()
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
ESP_LOGI(TAG, "Device successfully provisioned");
|
||||
#else
|
||||
ESP_LOGE(TAG, "AT commands are disabled. Change the configuration using 'make menuconfig'");
|
||||
ASSERT(0);
|
||||
esp_restart();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user