removed 2 of 3 set arrays to save RAM

This commit is contained in:
Klaus K Wilting 2018-04-19 10:55:59 +02:00
parent e41aaa45a0
commit 7f7dfaeec8
5 changed files with 43 additions and 59 deletions

View File

@ -3,8 +3,8 @@
// std::set for unified array functions
#include <set>
#include <array>
#include <algorithm>
//#include <array>
//#include <algorithm>
#ifdef HAS_DISPLAY
// OLED Display
@ -49,15 +49,10 @@ extern uint32_t currentMillis ;
extern osjob_t sendjob;
extern char display_lora[], display_lmic[];
extern int countermode, screensaver, adrmode, lorasf, txpower, rlim;
extern uint16_t macs_total, macs_wifi, macs_ble; // MAC counters
extern bool joinstate;
extern std::set<uint16_t> wifis;
extern std::set<uint16_t> macs;
#ifdef HAS_DISPLAY
extern HAS_DISPLAY u8x8;
#endif
#ifdef BLECOUNTER
extern int scanTime;
extern std::set<uint16_t> bles;
#endif

View File

@ -111,15 +111,13 @@ void do_send(osjob_t* j){
uint8_t mydata[4];
uint16_t data;
// Sum of unique WIFI MACs seen
data = (uint16_t) wifis.size();
mydata[0] = (data & 0xff00) >> 8;
mydata[1] = data & 0xff;
mydata[0] = (macs_wifi & 0xff00) >> 8;
mydata[1] = macs_wifi & 0xff;
#ifdef BLECOUNTER
// Sum of unique BLE MACs seen
data = (uint16_t) bles.size();
mydata[2] = (data & 0xff00) >> 8;
mydata[3] = data & 0xff;
mydata[2] = (macs_ble & 0xff00) >> 8;
mydata[3] = macs_ble & 0xff;
#else
mydata[2] = 0;
mydata[3] = 0;
@ -128,8 +126,8 @@ void do_send(osjob_t* j){
// Total BLE+WIFI unique MACs seen
// TBD ?
//data = (uint16_t) macs.size();
//mydata[4] = (data & 0xff00) >> 8;
//mydata[5] = data & 0xff;
//mydata[4] = (macs_total & 0xff00) >> 8;
//mydata[5] = macs_total & 0xff;
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {

View File

@ -53,26 +53,21 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
// Insert only if it was not found on global count
if (added) {
if (sniff_type == MAC_SNIFF_WIFI ) {
macs_wifi++; // increment Wifi MACs counter
set_LED(COLOR_GREEN, 50, 0, 1);
wifis.insert(hashedmac); // add hashed MAC to wifi container
}
#ifdef BLECOUNTER
else if (sniff_type == MAC_SNIFF_BLE ) {
macs_ble++; // increment BLE Macs counter
set_LED(COLOR_MAGENTA, 50, 0, 1);
bles.insert(hashedmac); // add hashed MAC to BLE container
}
#endif
}
ESP_LOGI(TAG, "%s RSSI %ddBi -> MAC %s -> Hash %04X -> WiFi:%d BLTH:%d %s",
sniff_type==MAC_SNIFF_WIFI ? "WiFi":"BLTH",
rssi, buff, hashedmac,
(int) wifis.size(),
#ifdef BLECOUNTER
(int) bles.size(),
#else
0,
#endif
rssi, buff, hashedmac,
macs_wifi,
added ? "new" : "known");
#ifdef VENDORFILTER

View File

@ -24,9 +24,6 @@ Refer to LICENSE.txt file in repository for more details.
// Basic Config
#include "globals.h"
// std::set for unified array functions
#include <set>
// Does nothing and avoid any compilation error with I2C
#include <Wire.h>
@ -43,22 +40,23 @@ Refer to LICENSE.txt file in repository for more details.
configData_t cfg; // struct holds current device configuration
osjob_t sendjob, initjob; // LMIC
enum states {
LED_ON,
LED_OFF
};
// Initialize global variables
char display_lora[16], display_lmic[16]; // display buffers
uint64_t uptimecounter = 0;
uint32_t currentMillis = 0, previousDisplaymillis = 0;
uint8_t DisplayState, LEDState = 0, LEDcount = 0;
uint16_t LEDBlinkduration = 0, LEDInterval = 0, color=COLOR_NONE;
uint8_t channel = 0; // wifi channel counter
bool joinstate = false;
uint64_t uptimecounter = 0; // timer global for uptime counter
uint32_t currentMillis = 0; // timer global for state machine
uint8_t DisplayState, LEDcount = 0; // globals for state machine
uint16_t LEDBlinkduration = 0, LEDInterval = 0, color=COLOR_NONE; // state machine variables
uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0; // MAC counters globals for display
uint8_t channel = 0; // wifi channel rotation counter global for display
enum states LEDState = LED_OFF; // LED state global for state machine
bool joinstate = false; // LoRa network joined? global flag
std::set<uint16_t> macs; // associative container holds total of unique MAC adress hashes (Wifi + BLE)
std::set<uint16_t> wifis; // associative container holds unique Wifi MAC adress hashes
#ifdef BLECOUNTER
std::set<uint16_t> bles; // associative container holds unique BLE MAC adresses hashes
int scanTime;
#endif
// this variable will be changed in the ISR, and read in main loop
static volatile bool ButtonTriggered = false;
@ -83,8 +81,8 @@ void set_LED (uint16_t set_color, uint16_t set_blinkduration, uint16_t set_inter
color = set_color; // set color for RGB LED
LEDBlinkduration = set_blinkduration; // duration on
LEDInterval = set_interval; // duration off - on - off
LEDcount = set_count * 2; // number of blinks before LED off
LEDState = set_count ? 1 : 0; // sets LED to off if 0 blinks
LEDcount = set_count * 2; // number of on/off cycles before LED off
LEDState = set_count ? LED_ON : LED_OFF; // sets LED to off if 0 blinks
}
/* begin LMIC specific parts ------------------------------------------------------------ */
@ -250,10 +248,9 @@ void sniffer_loop(void * pvParameters) {
// clear counter if not in cumulative counter mode
if (cfg.countermode != 1) {
macs.clear(); // clear all macs container
wifis.clear(); // clear Wifi macs couner
#ifdef BLECOUNTER
bles.clear(); // clear BLE macs counter
#endif
macs_total = 0; // reset all counters
macs_wifi = 0;
macs_ble = 0;
salt_reset(); // get new salt for salting hashes
}
@ -358,12 +355,12 @@ uint64_t uptime() {
snprintf(buff, sizeof(buff), "PAX:%-4d", (int) macs.size()); // convert 16-bit MAC counter to decimal counter value
u8x8.draw2x2String(0, 0, buff); // display number on unique macs total Wifi + BLE
u8x8.setCursor(0,4);
u8x8.printf("WIFI: %-4d", (int) wifis.size());
u8x8.printf("WIFI: %-4d", macs_wifi);
#ifdef BLECOUNTER
u8x8.setCursor(0,3);
if (cfg.blescan)
u8x8.printf("BLTH: %-4d", (int) bles.size());
u8x8.printf("BLTH: %-4d", macs_ble);
else
u8x8.printf("%-16s", "BLTH: off");
#endif
@ -387,6 +384,8 @@ uint64_t uptime() {
void updateDisplay() {
// timed display refresh according to refresh cycle setting
uint32_t previousDisplaymillis = currentMillis;
if (currentMillis - previousDisplaymillis >= DISPLAYREFRESH_MS) {
refreshDisplay();
previousDisplaymillis += DISPLAYREFRESH_MS;
@ -414,7 +413,7 @@ uint64_t uptime() {
#ifdef HAS_LED
void switchLED() {
static bool previousLEDState;
enum states previousLEDState;
// led need to change state? avoid digitalWrite() for nothing
if (LEDState != previousLEDState) {
#ifdef LED_ACTIVE_LOW
@ -434,9 +433,9 @@ uint64_t uptime() {
void switchLEDstate() {
if (!LEDcount) // no more blinks? -> switch off LED
LEDState = 0;
LEDState = LED_OFF;
else if (LEDInterval) // blinks left? -> toggle LED and decrement blinks
LEDState = ((currentMillis % LEDInterval) < LEDBlinkduration) ? 1 : 0;
LEDState = ((currentMillis % LEDInterval) < LEDBlinkduration) ? LED_ON : LED_OFF;
} // switchLEDstate()
#endif

View File

@ -65,10 +65,9 @@ void set_reset(int val) {
case 1: // reset MAC counter
ESP_LOGI(TAG, "Remote command: reset MAC counter");
macs.clear(); // clear all macs container
wifis.clear(); // clear Wifi macs container
#ifdef BLECOUNTER
bles.clear(); // clear BLE macs container
#endif
macs_total = 0; // reset all counters
macs_wifi = 0;
macs_ble = 0;
salt_reset(); // get new 16bit salt
sprintf(display_lora, "Reset counter");
break;
@ -151,10 +150,8 @@ void set_blescan(int val) {
ESP_LOGI(TAG, "Remote command: set BLE scan mode to %s", val ? "on" : "off");
switch (val) {
case 0:
cfg.blescan = 0;
#ifdef BLECOUNTER
bles.clear(); // clear BLE macs container
#endif
cfg.blescan = 0;
macs_ble = 0; // clear BLE counter
break;
default:
cfg.blescan = 1;