2018-10-14 13:26:23 +02:00
|
|
|
#ifndef _GLOBALS_H
|
|
|
|
#define _GLOBALS_H
|
|
|
|
|
|
|
|
// The mother of all embedded development...
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
2019-01-28 11:46:18 +01:00
|
|
|
// Time functions
|
2022-10-31 16:04:09 +01:00
|
|
|
#ifdef HAS_RTC
|
2019-02-21 23:17:01 +01:00
|
|
|
#include <RtcDateTime.h>
|
2022-10-31 16:04:09 +01:00
|
|
|
#endif
|
2019-03-03 00:30:57 +01:00
|
|
|
#include <Ticker.h>
|
2019-01-28 11:46:18 +01:00
|
|
|
|
2018-10-14 13:26:23 +02:00
|
|
|
// std::set for unified array functions
|
|
|
|
#include <set>
|
|
|
|
#include <array>
|
|
|
|
#include <algorithm>
|
2022-08-19 16:35:02 +02:00
|
|
|
|
|
|
|
#ifdef HAS_BME680
|
2020-01-28 21:49:24 +01:00
|
|
|
#include <bsec.h>
|
2022-08-19 16:35:02 +02:00
|
|
|
#endif
|
2018-10-14 13:26:23 +02:00
|
|
|
|
2020-12-24 16:52:07 +01:00
|
|
|
#define _bit(b) (1U << (b))
|
|
|
|
#define _bitl(b) (1UL << (b))
|
|
|
|
|
2018-11-19 00:41:15 +01:00
|
|
|
// bits in payloadmask for filtering payload data
|
2021-01-09 23:52:08 +01:00
|
|
|
#define COUNT_DATA _bit(0)
|
2021-05-07 19:41:36 +02:00
|
|
|
#define RESERVED_DATA _bit(1)
|
2021-01-09 23:52:08 +01:00
|
|
|
#define MEMS_DATA _bit(2)
|
|
|
|
#define GPS_DATA _bit(3)
|
|
|
|
#define SENSOR1_DATA _bit(4)
|
|
|
|
#define SENSOR2_DATA _bit(5)
|
|
|
|
#define SENSOR3_DATA _bit(6)
|
|
|
|
#define BATT_DATA _bit(7)
|
2018-11-19 00:41:15 +01:00
|
|
|
|
2019-10-12 15:59:21 +02:00
|
|
|
// length of display buffer for lmic event messages
|
2019-10-12 14:07:55 +02:00
|
|
|
#define LMIC_EVENTMSG_LEN 17
|
|
|
|
|
2020-10-30 12:24:16 +01:00
|
|
|
// pseudo system halt function, useful to prevent writeloops to NVRAM
|
|
|
|
#ifndef _ASSERT
|
|
|
|
#define _ASSERT(cond) \
|
|
|
|
if ((cond) == 0) { \
|
|
|
|
ESP_LOGE(TAG, "FAILURE in %s:%d", __FILE__, __LINE__); \
|
|
|
|
mask_user_IRQ(); \
|
|
|
|
for (;;) \
|
|
|
|
; \
|
|
|
|
}
|
2021-04-07 00:27:40 +02:00
|
|
|
#endif
|
2020-10-30 12:24:16 +01:00
|
|
|
|
2020-12-09 20:37:03 +01:00
|
|
|
#define _seconds() millis() / 1000.0
|
2020-11-02 12:25:10 +01:00
|
|
|
|
2020-11-09 13:25:12 +01:00
|
|
|
enum snifftype_t { MAC_SNIFF_WIFI, MAC_SNIFF_BLE, MAC_SNIFF_BLE_ENS };
|
2019-08-28 10:48:39 +02:00
|
|
|
|
2019-02-27 00:52:27 +01:00
|
|
|
// Struct holding devices's runtime configuration
|
2020-10-04 19:10:36 +02:00
|
|
|
// using packed to avoid compiler padding, because struct will be memcpy'd to
|
|
|
|
// byte array
|
2020-10-02 23:07:24 +02:00
|
|
|
typedef struct __attribute__((packed)) {
|
2021-12-24 15:15:28 +01:00
|
|
|
char version[10] = ""; // Firmware version
|
|
|
|
uint8_t loradr; // 0-15, lora datarate
|
|
|
|
uint8_t txpower; // 2-15, lora tx power
|
|
|
|
uint8_t adrmode; // 0=disabled, 1=enabled
|
|
|
|
uint8_t screensaver; // 0=disabled, 1=enabled
|
|
|
|
uint8_t screenon; // 0=disabled, 1=enabled
|
2018-10-14 13:26:23 +02:00
|
|
|
uint8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed
|
|
|
|
int16_t rssilimit; // threshold for rssilimiter, negative value!
|
|
|
|
uint8_t sendcycle; // payload send cycle [seconds/2]
|
2021-03-27 18:52:39 +01:00
|
|
|
uint16_t sleepcycle; // sleep cycle [seconds/10]
|
2018-10-14 13:26:23 +02:00
|
|
|
uint8_t wifichancycle; // wifi channel switch cycle [seconds/100]
|
|
|
|
uint8_t blescantime; // BLE scan cycle duration [seconds]
|
|
|
|
uint8_t blescan; // 0=disabled, 1=enabled
|
2019-11-11 12:28:31 +01:00
|
|
|
uint8_t wifiscan; // 0=disabled, 1=enabled
|
2018-10-14 13:26:23 +02:00
|
|
|
uint8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4)
|
|
|
|
uint8_t rgblum; // RGB Led luminosity (0..100%)
|
2018-11-19 00:41:15 +01:00
|
|
|
uint8_t payloadmask; // bitswitches for payload data
|
2020-10-05 13:56:41 +02:00
|
|
|
|
2020-10-02 23:07:24 +02:00
|
|
|
#ifdef HAS_BME680
|
2020-10-05 13:56:41 +02:00
|
|
|
uint8_t
|
|
|
|
bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1]; // BSEC state for BME680 sensor
|
2020-10-02 23:07:24 +02:00
|
|
|
#endif
|
2018-10-14 13:26:23 +02:00
|
|
|
} configData_t;
|
|
|
|
|
|
|
|
// Struct holding payload for data send queue
|
|
|
|
typedef struct {
|
|
|
|
uint8_t MessageSize;
|
|
|
|
uint8_t MessagePort;
|
|
|
|
uint8_t Message[PAYLOAD_BUFFER_SIZE];
|
|
|
|
} MessageBuffer_t;
|
|
|
|
|
2018-11-04 19:25:11 +01:00
|
|
|
typedef struct {
|
2019-01-23 22:14:14 +01:00
|
|
|
int32_t latitude;
|
|
|
|
int32_t longitude;
|
2018-11-04 19:25:11 +01:00
|
|
|
uint8_t satellites;
|
|
|
|
uint16_t hdop;
|
2019-01-23 22:24:20 +01:00
|
|
|
int16_t altitude;
|
2018-11-04 19:25:11 +01:00
|
|
|
} gpsStatus_t;
|
|
|
|
|
2018-11-14 22:11:23 +01:00
|
|
|
typedef struct {
|
2018-12-21 00:35:21 +01:00
|
|
|
float iaq; // IAQ signal
|
|
|
|
uint8_t iaq_accuracy; // accuracy of IAQ signal
|
|
|
|
float temperature; // temperature signal
|
|
|
|
float humidity; // humidity signal
|
|
|
|
float pressure; // pressure signal
|
|
|
|
float raw_temperature; // raw temperature signal
|
|
|
|
float raw_humidity; // raw humidity signal
|
|
|
|
float gas; // raw gas sensor signal
|
2018-11-14 22:11:23 +01:00
|
|
|
} bmeStatus_t;
|
|
|
|
|
2020-02-25 22:18:20 +01:00
|
|
|
typedef struct {
|
|
|
|
float pm10;
|
|
|
|
float pm25;
|
|
|
|
} sdsStatus_t;
|
|
|
|
|
2022-01-13 23:30:18 +01:00
|
|
|
extern char clientId[20]; // unique clientID
|
2018-10-14 13:26:23 +02:00
|
|
|
|
2021-04-07 00:27:40 +02:00
|
|
|
#endif
|