2018-07-17 15:15:58 +02:00
|
|
|
#ifndef _LORAWAN_H
|
|
|
|
#define _LORAWAN_H
|
2018-06-09 22:28:20 +02:00
|
|
|
|
2018-09-20 17:33:52 +02:00
|
|
|
#include "globals.h"
|
|
|
|
#include "rcommand.h"
|
2019-02-24 01:44:55 +01:00
|
|
|
#include "timekeeper.h"
|
2019-10-19 21:14:04 +02:00
|
|
|
#include <driver/rtc_io.h>
|
2018-09-20 17:33:52 +02:00
|
|
|
|
2018-07-15 14:28:05 +02:00
|
|
|
// LMIC-Arduino LoRaWAN Stack
|
|
|
|
#include <lmic.h>
|
|
|
|
#include <hal/hal.h>
|
2018-11-26 22:49:45 +01:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <arduino_lmic_hal_boards.h>
|
2018-07-15 14:28:05 +02:00
|
|
|
#include "loraconf.h"
|
|
|
|
|
2018-09-20 17:33:52 +02:00
|
|
|
// Needed for 24AA02E64, does not hurt anything if included and not used
|
|
|
|
#ifdef MCP_24AA02E64_I2C_ADDRESS
|
|
|
|
#include <Wire.h>
|
|
|
|
#endif
|
|
|
|
|
2019-08-30 18:54:53 +02:00
|
|
|
extern TaskHandle_t lmicTask, lorasendTask;
|
2018-10-03 00:25:05 +02:00
|
|
|
|
2019-10-20 20:05:13 +02:00
|
|
|
esp_err_t lora_stack_init(bool do_join);
|
2019-10-09 20:07:16 +02:00
|
|
|
void lora_setupForNetwork(bool preJoin);
|
2019-08-02 21:53:05 +02:00
|
|
|
void lmictask(void *pvParameters);
|
2018-06-12 19:50:58 +02:00
|
|
|
void gen_lora_deveui(uint8_t *pdeveui);
|
|
|
|
void RevBytes(unsigned char *b, size_t c);
|
2018-06-09 22:28:20 +02:00
|
|
|
void get_hard_deveui(uint8_t *pdeveui);
|
2018-07-15 14:28:05 +02:00
|
|
|
void os_getDevKey(u1_t *buf);
|
|
|
|
void os_getArtEui(u1_t *buf);
|
|
|
|
void os_getDevEui(u1_t *buf);
|
2019-08-29 10:13:47 +02:00
|
|
|
void lora_send(void *pvParameters);
|
2019-08-28 10:48:39 +02:00
|
|
|
void lora_enqueuedata(MessageBuffer_t *message);
|
2018-11-03 20:29:02 +01:00
|
|
|
void lora_queuereset(void);
|
2020-04-13 15:07:27 +02:00
|
|
|
void lora_setBattLevel(uint8_t batt_percent);
|
2019-12-25 23:21:31 +01:00
|
|
|
void IRAM_ATTR myEventCallback(void *pUserData, ev_t ev);
|
2020-03-06 19:24:58 +01:00
|
|
|
void IRAM_ATTR myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
|
|
|
|
size_t nMsg);
|
|
|
|
void IRAM_ATTR myTxCallback(void *pUserData, int fSuccess);
|
2019-09-20 09:51:33 +02:00
|
|
|
const char *getSfName(rps_t rps);
|
2019-09-20 13:22:45 +02:00
|
|
|
const char *getBwName(rps_t rps);
|
|
|
|
const char *getCrName(rps_t rps);
|
2020-03-06 19:24:58 +01:00
|
|
|
// u1_t os_getBattLevel(void);
|
|
|
|
|
2020-03-07 00:03:05 +01:00
|
|
|
#if (VERBOSE)
|
|
|
|
|
2020-03-06 19:24:58 +01:00
|
|
|
// a table for storage of LORAWAN MAC commands
|
|
|
|
typedef struct {
|
2020-03-07 00:03:05 +01:00
|
|
|
const uint8_t cid;
|
2020-03-06 19:24:58 +01:00
|
|
|
const char cmdname[20];
|
|
|
|
const uint8_t params;
|
|
|
|
} mac_t;
|
2020-03-07 00:03:05 +01:00
|
|
|
|
|
|
|
// table of LORAWAN MAC messages sent by the network to the device
|
|
|
|
// format: CDI, Command (max 19 chars), #parameters (bytes)
|
|
|
|
// source: LoRaWAN 1.1 Specification (October 11, 2017)
|
|
|
|
static const mac_t MACdn_table[] = {
|
|
|
|
{0x01, "ResetConf", 1}, {0x02, "LinkCheckAns", 2},
|
|
|
|
{0x03, "LinkADRReq", 4}, {0x04, "DutyCycleReq", 1},
|
|
|
|
{0x05, "RXParamSetupReq", 4}, {0x06, "DevStatusReq", 0},
|
|
|
|
{0x07, "NewChannelReq", 5}, {0x08, "RxTimingSetupReq", 1},
|
|
|
|
{0x09, "TxParamSetupReq", 1}, {0x0A, "DlChannelReq", 4},
|
|
|
|
{0x0B, "RekeyConf", 1}, {0x0C, "ADRParamSetupReq", 1},
|
|
|
|
{0x0D, "DeviceTimeAns", 5}, {0x0E, "ForceRejoinReq", 2},
|
|
|
|
{0x0F, "RejoinParamSetupReq", 1}};
|
|
|
|
|
|
|
|
static const uint8_t MACdn_tSize = sizeof(MACdn_table) / sizeof(MACdn_table[0]);
|
|
|
|
|
|
|
|
// table of LORAWAN MAC messages sent by the device to the network
|
|
|
|
static const mac_t MACup_table[] = {
|
|
|
|
{0x01, "ResetInd", 1}, {0x02, "LinkCheckReq", 0},
|
|
|
|
{0x03, "LinkADRAns", 1}, {0x04, "DutyCycleAns", 0},
|
|
|
|
{0x05, "RXParamSetupAns", 1}, {0x06, "DevStatusAns", 2},
|
|
|
|
{0x07, "NewChannelAns", 1}, {0x08, "RxTimingSetupAns", 0},
|
|
|
|
{0x09, "TxParamSetupAns", 0}, {0x0A, "DlChannelAns", 1},
|
|
|
|
{0x0B, "RekeyInd", 1}, {0x0C, "ADRParamSetupAns", 0},
|
|
|
|
{0x0D, "DeviceTimeReq", 0}, {0x0F, "RejoinParamSetupAns", 1}};
|
|
|
|
|
|
|
|
static const uint8_t MACup_tSize = sizeof(MACup_table) / sizeof(MACup_table[0]);
|
|
|
|
|
|
|
|
void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, bool is_down);
|
2020-03-06 19:24:58 +01:00
|
|
|
void showLoraKeys(void);
|
2020-03-07 00:03:05 +01:00
|
|
|
#endif // VERBOSE
|
2019-08-31 18:36:49 +02:00
|
|
|
|
2018-07-15 14:28:05 +02:00
|
|
|
#endif
|