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
|
2019-03-12 23:50:02 +01:00
|
|
|
#include "microTime.h"
|
2019-01-28 11:46:18 +01:00
|
|
|
#include <Timezone.h>
|
2019-02-21 23:17:01 +01:00
|
|
|
#include <RtcDateTime.h>
|
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>
|
2019-01-14 14:59:44 +01:00
|
|
|
#include "mallocator.h"
|
2018-12-31 16:42:09 +01:00
|
|
|
#include "../lib/Bosch-BSEC/src/inc/bsec_datatypes.h"
|
2018-10-14 13:26:23 +02:00
|
|
|
|
2018-12-02 14:08:50 +01:00
|
|
|
// sniffing types
|
|
|
|
#define MAC_SNIFF_WIFI 0
|
|
|
|
#define MAC_SNIFF_BLE 1
|
|
|
|
|
2018-11-19 00:41:15 +01:00
|
|
|
// bits in payloadmask for filtering payload data
|
|
|
|
#define GPS_DATA (0x01)
|
|
|
|
#define ALARM_DATA (0x02)
|
|
|
|
#define MEMS_DATA (0x04)
|
|
|
|
#define COUNT_DATA (0x08)
|
|
|
|
#define SENSOR1_DATA (0x10)
|
|
|
|
#define SENSOR2_DATA (0x20)
|
|
|
|
#define SENSOR3_DATA (0x40)
|
2018-11-27 11:21:20 +01:00
|
|
|
#define BATT_DATA (0x80)
|
2018-11-19 00:41:15 +01:00
|
|
|
|
|
|
|
// bits in configmask for device runmode control
|
|
|
|
#define GPS_MODE (0x01)
|
|
|
|
#define ALARM_MODE (0x02)
|
|
|
|
#define BEACON_MODE (0x04)
|
|
|
|
#define UPDATE_MODE (0x08)
|
|
|
|
#define FILTER_MODE (0x10)
|
|
|
|
#define ANTENNA_MODE (0x20)
|
|
|
|
#define BLE_MODE (0x40)
|
|
|
|
#define SCREEN_MODE (0x80)
|
|
|
|
|
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
|
|
|
|
|
2019-01-26 12:32:17 +01:00
|
|
|
// I2C bus access control
|
2019-09-20 19:45:37 +02:00
|
|
|
#define I2C_MUTEX_LOCK() \
|
2019-10-12 15:59:21 +02:00
|
|
|
(xSemaphoreTake(I2Caccess, pdMS_TO_TICKS(DISPLAYREFRESH_MS)) == pdTRUE)
|
2019-07-23 12:57:05 +02:00
|
|
|
#define I2C_MUTEX_UNLOCK() (xSemaphoreGive(I2Caccess))
|
2019-02-16 15:02:07 +01:00
|
|
|
|
2019-08-28 10:48:39 +02:00
|
|
|
enum sendprio_t { prio_low, prio_normal, prio_high };
|
|
|
|
enum timesource_t { _gps, _rtc, _lora, _unsynced };
|
2019-10-16 21:14:34 +02:00
|
|
|
enum runmode_t {
|
|
|
|
RUNMODE_NORMAL,
|
|
|
|
RUNMODE_UPDATE,
|
|
|
|
RUNMODE_WAKEUP
|
|
|
|
};
|
2019-08-28 10:48:39 +02:00
|
|
|
|
2019-02-27 00:52:27 +01:00
|
|
|
// Struct holding devices's runtime configuration
|
|
|
|
typedef struct {
|
2019-09-20 13:22:45 +02:00
|
|
|
uint8_t loradr; // 0-15, lora datarate
|
2018-10-14 13:26:23 +02:00
|
|
|
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
|
|
|
|
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]
|
|
|
|
uint8_t wifichancycle; // wifi channel switch cycle [seconds/100]
|
|
|
|
uint8_t blescantime; // BLE scan cycle duration [seconds]
|
|
|
|
uint8_t blescan; // 0=disabled, 1=enabled
|
|
|
|
uint8_t wifiant; // 0=internal, 1=external (for LoPy/LoPy4)
|
|
|
|
uint8_t vendorfilter; // 0=disabled, 1=enabled
|
|
|
|
uint8_t rgblum; // RGB Led luminosity (0..100%)
|
|
|
|
uint8_t monitormode; // 0=disabled, 1=enabled
|
|
|
|
uint8_t runmode; // 0=normal, 1=update
|
2018-11-19 00:41:15 +01:00
|
|
|
uint8_t payloadmask; // bitswitches for payload data
|
2018-10-14 13:26:23 +02:00
|
|
|
char version[10]; // Firmware version
|
2019-02-16 15:02:07 +01:00
|
|
|
uint8_t
|
|
|
|
bsecstate[BSEC_MAX_STATE_BLOB_SIZE + 1]; // BSEC state for BME680 sensor
|
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;
|
2019-08-28 10:48:39 +02:00
|
|
|
sendprio_t MessagePrio;
|
2018-10-14 13:26:23 +02:00
|
|
|
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;
|
|
|
|
|
2019-02-17 19:21:08 +01:00
|
|
|
extern std::set<uint16_t, std::less<uint16_t>, Mallocator<uint16_t>> macs;
|
|
|
|
extern std::array<uint64_t, 0xff>::iterator it;
|
|
|
|
extern std::array<uint64_t, 0xff> beacons;
|
|
|
|
|
2019-10-12 14:07:55 +02:00
|
|
|
extern configData_t cfg; // current device configuration
|
|
|
|
extern char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer
|
|
|
|
extern uint8_t volatile channel; // wifi channel rotation counter
|
2018-10-14 13:26:23 +02:00
|
|
|
extern uint16_t volatile macs_total, macs_wifi, macs_ble,
|
2019-07-15 19:11:01 +02:00
|
|
|
batt_voltage; // display values
|
2019-02-27 00:52:27 +01:00
|
|
|
extern bool volatile TimePulseTick; // 1sec pps flag set by GPS or RTC
|
|
|
|
extern timesource_t timeSource;
|
2019-07-29 10:26:58 +02:00
|
|
|
extern hw_timer_t *displayIRQ, *matrixDisplayIRQ, *ppsIRQ;
|
2019-03-19 01:46:20 +01:00
|
|
|
extern SemaphoreHandle_t I2Caccess;
|
2019-02-17 19:21:08 +01:00
|
|
|
extern TaskHandle_t irqHandlerTask, ClockTask;
|
2019-02-02 21:35:40 +01:00
|
|
|
extern TimerHandle_t WifiChanTimer;
|
|
|
|
extern Timezone myTZ;
|
2019-02-24 01:44:55 +01:00
|
|
|
extern time_t userUTCTime;
|
2018-10-14 13:26:23 +02:00
|
|
|
|
2018-12-31 15:46:52 +01:00
|
|
|
// application includes
|
2018-11-04 19:25:11 +01:00
|
|
|
#include "led.h"
|
|
|
|
#include "payload.h"
|
2018-12-02 14:08:50 +01:00
|
|
|
#include "blescan.h"
|
2019-09-07 23:10:53 +02:00
|
|
|
#include "power.h"
|
2018-11-04 19:25:11 +01:00
|
|
|
|
2019-03-24 19:49:29 +01:00
|
|
|
#if (HAS_GPS)
|
2018-10-21 19:00:20 +02:00
|
|
|
#include "gpsread.h"
|
2018-10-14 13:26:23 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-24 19:49:29 +01:00
|
|
|
#if (HAS_LORA)
|
2018-10-14 13:26:23 +02:00
|
|
|
#include "lorawan.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-13 22:08:05 +01:00
|
|
|
#ifdef HAS_DISPLAY
|
2018-10-14 13:26:23 +02:00
|
|
|
#include "display.h"
|
|
|
|
#endif
|
|
|
|
|
2019-05-05 23:43:18 +02:00
|
|
|
#ifdef HAS_MATRIX_DISPLAY
|
|
|
|
#include "ledmatrixdisplay.h"
|
|
|
|
#endif
|
|
|
|
|
2018-10-14 13:26:23 +02:00
|
|
|
#ifdef HAS_BUTTON
|
|
|
|
#include "button.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAS_ANTENNA_SWITCH
|
|
|
|
#include "antenna.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-24 19:49:29 +01:00
|
|
|
#if (HAS_SENSORS)
|
2018-11-20 15:02:37 +01:00
|
|
|
#include "sensor.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-13 21:15:28 +01:00
|
|
|
#if (HAS_BME)
|
|
|
|
#include "bmesensor.h"
|
2018-12-31 15:46:52 +01:00
|
|
|
#endif
|
|
|
|
|
2018-07-17 15:15:58 +02:00
|
|
|
#endif
|