2018-03-18 19:45:17 +01:00
|
|
|
// The mother of all embedded development...
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
// std::set for unified array functions
|
|
|
|
#include <set>
|
2018-04-24 22:37:20 +02:00
|
|
|
#include <array>
|
|
|
|
#include <algorithm>
|
2018-03-18 19:45:17 +01:00
|
|
|
|
2018-04-24 22:37:20 +02:00
|
|
|
// OLED Display
|
2018-04-16 20:56:29 +02:00
|
|
|
#ifdef HAS_DISPLAY
|
|
|
|
#include <U8x8lib.h>
|
|
|
|
#endif
|
2018-03-18 19:45:17 +01:00
|
|
|
|
2018-06-08 22:41:37 +02:00
|
|
|
//GPS
|
|
|
|
#ifdef HAS_GPS
|
|
|
|
#include <TinyGPS++.h>
|
|
|
|
#endif
|
|
|
|
|
2018-03-18 19:45:17 +01:00
|
|
|
// LMIC-Arduino LoRaWAN Stack
|
|
|
|
#include <lmic.h>
|
|
|
|
#include <hal/hal.h>
|
|
|
|
|
2018-04-03 17:47:11 +02:00
|
|
|
// LED controls
|
2018-04-02 01:36:51 +02:00
|
|
|
#ifdef HAS_RGB_LED
|
2018-04-03 17:47:11 +02:00
|
|
|
#include <SmartLeds.h>
|
2018-04-02 01:36:51 +02:00
|
|
|
#endif
|
2018-04-03 17:47:11 +02:00
|
|
|
|
2018-04-02 01:36:51 +02:00
|
|
|
#include "rgb_led.h"
|
|
|
|
#include "macsniff.h"
|
2018-04-19 15:17:23 +02:00
|
|
|
#include "main.h"
|
2018-04-02 01:36:51 +02:00
|
|
|
|
2018-03-21 17:34:11 +01:00
|
|
|
// Struct holding devices's runtime configuration
|
|
|
|
typedef struct {
|
2018-04-28 14:09:27 +02:00
|
|
|
uint8_t lorasf; // 7-12, lora spreadfactor
|
|
|
|
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
|
2018-06-08 22:41:37 +02:00
|
|
|
int16_t rssilimit; // threshold for rssilimiter, negative value!
|
2018-04-28 14:09:27 +02:00
|
|
|
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%)
|
2018-06-08 22:41:37 +02:00
|
|
|
uint8_t gpsmode; // 0=disabled, 1=enabled
|
|
|
|
char version[10]; // Firmware version
|
2018-03-21 17:34:11 +01:00
|
|
|
} configData_t;
|
2018-03-18 19:45:17 +01:00
|
|
|
|
2018-06-08 22:41:37 +02:00
|
|
|
#ifdef HAS_GPS
|
|
|
|
typedef struct {
|
2018-06-09 23:10:40 +02:00
|
|
|
uint32_t latitude;
|
|
|
|
uint32_t longitude;
|
2018-06-09 21:15:35 +02:00
|
|
|
uint8_t satellites;
|
2018-06-09 22:21:23 +02:00
|
|
|
uint16_t hdop;
|
2018-06-09 21:15:35 +02:00
|
|
|
uint16_t altitude;
|
2018-06-08 22:41:37 +02:00
|
|
|
} gpsStatus_t;
|
|
|
|
extern gpsStatus_t gps_status; // struct for storing gps data
|
2018-06-09 19:20:34 +02:00
|
|
|
extern TinyGPSPlus gps; // Make TinyGPS++ instance globally availabe
|
2018-06-08 22:41:37 +02:00
|
|
|
#endif
|
|
|
|
|
2018-03-21 17:34:11 +01:00
|
|
|
extern configData_t cfg;
|
2018-04-17 19:20:54 +02:00
|
|
|
extern uint64_t uptimecounter;
|
2018-06-08 22:41:37 +02:00
|
|
|
extern osjob_t sendjob, rcmdjob;
|
2018-04-27 21:29:46 +02:00
|
|
|
extern char display_lora[], display_lmic[];
|
2018-04-04 12:39:40 +02:00
|
|
|
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
|
2018-04-19 10:55:59 +02:00
|
|
|
extern uint16_t macs_total, macs_wifi, macs_ble; // MAC counters
|
2018-04-28 14:09:27 +02:00
|
|
|
extern std::set<uint16_t> macs;
|
2018-06-08 22:41:37 +02:00
|
|
|
extern hw_timer_t * channelSwitch; // hardware timer used for wifi channel switching
|
|
|
|
extern xref2u1_t rcmd_data; // buffer for rcommand results size
|
|
|
|
extern u1_t rcmd_data_size; // buffer for rcommand results size
|