Merge pull request #135 from cyberman54/development

v1.4.23
This commit is contained in:
Verkehrsrot 2018-08-11 19:33:57 +02:00 committed by GitHub
commit a5ad7ad5bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 120 additions and 164 deletions

View File

@ -43,10 +43,18 @@ build_flags =
; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <---
; otherwise device may leak RAM
;
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
; None
; -DCORE_DEBUG_LEVEL=0
; Error
; -DCORE_DEBUG_LEVEL=1
; Warn
-DCORE_DEBUG_LEVEL=2
; Info
; -DCORE_DEBUG_LEVEL=3
; Debug
; -DCORE_DEBUG_LEVEL=4
; Verbose
; -DCORE_DEBUG_LEVEL=5
;
; override lora settings from LMiC library in lmic/config.h and use main.h instead
-D_lmic_config_h_

View File

@ -114,7 +114,7 @@ void refreshtheDisplay() {
// update Battery status (line 2)
#ifdef HAS_BATTERY_PROBE
u8x8.setCursor(0, 2);
u8x8.printf("B:%.1fV", batt_voltage / 1000.0);
u8x8.printf(batt_voltage > 4000 ? "B:USB " : "B:%.1fV", batt_voltage / 1000.0);
#endif
// update GPS status (line 2)

View File

@ -4,11 +4,8 @@
// The mother of all embedded development...
#include <Arduino.h>
// needed for ESP_LOGx on arduino framework
#include <esp32-hal-log.h>
// attn: increment version after modifications to configData_t truct!
#define PROGVERSION "1.4.21" // use max 10 chars here!
#define PROGVERSION "1.4.23" // use max 10 chars here!
#define PROGNAME "PAXCNT"
// std::set for unified array functions
@ -37,6 +34,13 @@ typedef struct {
char version[10]; // Firmware version
} 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;
// global variables
extern configData_t cfg; // current device configuration
extern char display_line6[], display_line7[]; // screen buffers

View File

@ -1,7 +1,7 @@
// Hardware related definitions for ebox ESP32-bit with external connected RFM95 LoRa
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1
#define HAS_LED GPIO_NUM_23 // blue LED on board

View File

@ -1,7 +1,7 @@
// Hardware related definitions for generic ESP32 boards
#define HAS_LORA 1 // comment out if device shall not send data via LoRa or has no LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1 // select LoRa chip
//#define CFG_sx1272_radio 1 // select LoRa chip

View File

@ -1,7 +1,7 @@
// Hardware related definitions for Heltec LoRa-32 Board
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board

View File

@ -5,4 +5,4 @@
#define HAS_LED 22 // on board LED on GPIO22
#define LED_ACTIVE_LOW 1 // Onboard LED is active when pin is LOW
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_SPI 1 // comment out if device shall not send data via SPI

View File

@ -1,7 +1,7 @@
// Hardware related definitions for Pycom LoPy Board (NOT LoPy4)
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1272_radio 1
#define HAS_LED NOT_A_PIN // LoPy has no on board LED, so we use RGB LED on LoPy
#define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0

View File

@ -1,7 +1,7 @@
// Hardware related definitions for Pycom LoPy Board (not: LoPy4)
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1
#define HAS_LED NOT_A_PIN // LoPy4 has no on board LED, so we use RGB LED on LoPy4
#define HAS_RGB_LED GPIO_NUM_0 // WS2812B RGB LED on GPIO0

View File

@ -1,7 +1,7 @@
// Hardware related definitions for TTGO T-Beam board
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
#define BOARD_HAS_PSRAM // use extra 4MB external RAM

View File

@ -1,7 +1,7 @@
// Hardware related definitions for TTGOv1 board
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C // OLED-Display on board

View File

@ -1,7 +1,7 @@
// Hardware related definitions for TTGO V2 Board
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C

View File

@ -6,8 +6,8 @@
/ - labelled v1.6 on pcb -> "new"
*/
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define HAS_SPI 1 // comment out if device shall not send data via SPI
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C

View File

@ -172,13 +172,13 @@ void onEvent(ev_t ev) {
strcpy_P(buff, PSTR("JOINED"));
sprintf(display_line6, " "); // clear previous lmic status
// set cyclic lmic link check to off because is not supported by ttn
// (but enabled by lmic after join)
LMIC_setLinkCheckMode(0);
// set data rate adaptation according to saved setting
LMIC_setAdrMode(cfg.adrmode);
// set cyclic lmic link check to off if no ADR because is not supported by
// ttn (but enabled by lmic after join)
LMIC_setLinkCheckMode(cfg.adrmode);
// Set data rate and transmit power (note: txpower seems to be ignored by
// the library)
switch_lora(cfg.lorasf, cfg.txpower);

View File

@ -42,14 +42,19 @@ volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0,
DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
// RTos send queues for payload transmit
QueueHandle_t LoraSendQueue, SPISendQueue;
#ifdef HAS_LORA
QueueHandle_t LoraSendQueue;
#endif
#ifdef HAS_SPI
QueueHandle_t SPISendQueue;
#endif
portMUX_TYPE timerMux =
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
// handler shared variables
std::set<uint16_t> macs; // associative container holding unique MAC
// adress hashes (Wifi + BLE)
std::set<uint16_t> macs; // container holding unique MAC adress hashes
// initialize payload encoder
PayloadConvert payload(PAYLOAD_BUFFER_SIZE);
@ -107,26 +112,6 @@ void setup() {
#endif // verbose
// initialize send queues for transmit channels
#ifdef HAS_LORA
LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
if (LoraSendQueue == 0) {
ESP_LOGE(TAG, "Could not create LORA send queue. Aborting.");
exit(0);
} else
ESP_LOGI(TAG, "LORA send queue created, size %d Bytes",
SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE);
#endif
#ifdef HAS_SPI
SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
if (SPISendQueue == 0) {
ESP_LOGE(TAG, "Could not create SPI send queue. Aborting.");
exit(0);
} else
ESP_LOGI(TAG, "SPI send queue created, size %d Bytes",
SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE);
#endif
// read settings from NVRAM
loadConfig(); // includes initialize if necessary
@ -137,9 +122,28 @@ void setup() {
// initialize LoRa
#ifdef HAS_LORA
strcat_P(features, " LORA");
LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
if (LoraSendQueue == 0) {
ESP_LOGE(TAG, "Could not create LORA send queue. Aborting.");
exit(0);
} else
ESP_LOGI(TAG, "LORA send queue created, size %d Bytes",
SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE);
#endif
// initialize led
// initialize SPI
#ifdef HAS_SPI
strcat_P(features, " SPI");
SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
if (SPISendQueue == 0) {
ESP_LOGE(TAG, "Could not create SPI send queue. Aborting.");
exit(0);
} else
ESP_LOGI(TAG, "SPI send queue created, size %d Bytes",
SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE);
#endif
// initialize led
#if (HAS_LED != NOT_A_PIN)
pinMode(HAS_LED, OUTPUT);
strcat_P(features, " LED");
@ -326,8 +330,6 @@ void loop() {
processSendBuffer();
// check send cycle and enqueue payload if cycle is expired
sendPayload();
// reset watchdog
vTaskDelay(1 / portTICK_PERIOD_MS);
} // loop()
}

View File

@ -34,12 +34,12 @@ void set_reset(uint8_t val[]) {
default:
ESP_LOGW(TAG, "Remote command: reset called with invalid parameter(s)");
}
};
}
void set_rssi(uint8_t val[]) {
cfg.rssilimit = val[0] * -1;
ESP_LOGI(TAG, "Remote command: set RSSI limit to %d", cfg.rssilimit);
};
}
void set_sendcycle(uint8_t val[]) {
cfg.sendcycle = val[0];
@ -48,7 +48,7 @@ void set_sendcycle(uint8_t val[]) {
// reload interrupt after each trigger of channel switch cycle
ESP_LOGI(TAG, "Remote command: set send cycle to %d seconds",
cfg.sendcycle * 2);
};
}
void set_wifichancycle(uint8_t val[]) {
cfg.wifichancycle = val[0];
@ -58,7 +58,7 @@ void set_wifichancycle(uint8_t val[]) {
ESP_LOGI(TAG,
"Remote command: set Wifi channel switch interval to %.1f seconds",
cfg.wifichancycle / float(100));
};
}
void set_blescantime(uint8_t val[]) {
cfg.blescantime = val[0];
@ -71,7 +71,7 @@ void set_blescantime(uint8_t val[]) {
start_BLEscan();
}
#endif
};
}
void set_countmode(uint8_t val[]) {
switch (val[0]) {
@ -92,43 +92,22 @@ void set_countmode(uint8_t val[]) {
TAG,
"Remote command: set counter mode called with invalid parameter(s)");
}
};
}
void set_screensaver(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set screen saver to %s ",
val[0] ? "on" : "off");
switch (val[0]) {
case 1:
cfg.screensaver = 1;
break;
default:
cfg.screensaver = 0;
break;
}
};
cfg.screensaver = val[0] ? 1 : 0;
}
void set_display(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set screen to %s", val[0] ? "on" : "off");
switch (val[0]) {
case 1:
cfg.screenon = 1;
break;
default:
cfg.screenon = 0;
break;
}
};
cfg.screenon = val[0] ? 1 : 0;
}
void set_gps(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set GPS mode to %s", val[0] ? "on" : "off");
switch (val[0]) {
case 1:
cfg.gpsmode = 1;
break;
default:
cfg.gpsmode = 0;
break;
};
cfg.gpsmode = val[0] ? 1 : 0;
}
void set_beacon(uint8_t val[]) {
@ -137,20 +116,13 @@ void set_beacon(uint8_t val[]) {
beacons[id] = macConvert(val); // store beacon MAC in array
ESP_LOGI(TAG, "Remote command: set beacon ID#%d", id);
printKey("MAC", val, 6, false); // show beacon MAC
};
}
void set_monitor(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set beacon monitor mode to %s",
val ? "on" : "off");
switch (val[0]) {
case 1:
cfg.monitormode = 1;
break;
default:
cfg.monitormode = 0;
break;
}
};
cfg.monitormode = val[0] ? 1 : 0;
}
void set_lorasf(uint8_t val[]) {
#ifdef HAS_LORA
@ -159,73 +131,46 @@ void set_lorasf(uint8_t val[]) {
#else
ESP_LOGW(TAG, "Remote command: LoRa not implemented");
#endif // HAS_LORA
};
}
void set_loraadr(uint8_t val[]) {
#ifdef HAS_LORA
ESP_LOGI(TAG, "Remote command: set LoRa ADR mode to %s",
val[0] ? "on" : "off");
switch (val[0]) {
case 1:
cfg.adrmode = 1;
break;
default:
cfg.adrmode = 0;
break;
}
LMIC_setAdrMode(cfg.adrmode);
cfg.adrmode = val[0] ? 1 : 0;
LMIC_setAdrMode(cfg.adrmode);
#else
ESP_LOGW(TAG, "Remote command: LoRa not implemented");
#endif // HAS_LORA
};
}
void set_blescan(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val[0] ? "on" : "off");
switch (val[0]) {
case 0:
cfg.blescan = 0;
macs_ble = 0; // clear BLE counter
#ifdef BLECOUNTER
stop_BLEscan();
#endif
break;
default:
cfg.blescan = 1;
cfg.blescan = val[0] ? 1 : 0;
#ifdef BLECOUNTER
if (cfg.blescan)
start_BLEscan();
#endif
break;
else {
macs_ble = 0; // clear BLE counter
stop_BLEscan();
}
};
#endif
}
void set_wifiant(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set Wifi antenna to %s",
val[0] ? "external" : "internal");
switch (val[0]) {
case 1:
cfg.wifiant = 1;
break;
default:
cfg.wifiant = 0;
break;
}
cfg.wifiant = val[0] ? 1 : 0;
#ifdef HAS_ANTENNA_SWITCH
antenna_select(cfg.wifiant);
#endif
};
}
void set_vendorfilter(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set vendorfilter mode to %s",
val[0] ? "on" : "off");
switch (val[0]) {
case 1:
cfg.vendorfilter = 1;
break;
default:
cfg.vendorfilter = 0;
break;
}
};
cfg.vendorfilter = val[0] ? 1 : 0;
}
void set_rgblum(uint8_t val[]) {
// Avoid wrong parameters

View File

@ -1,26 +1,28 @@
// Basic Config
#include "globals.h"
MessageBuffer_t SendBuffer;
// put data to send in RTos Queues used for transmit over channels Lora and SPI
void SendData(uint8_t port) {
MessageBuffer_t SendBuffer;
SendBuffer.MessageSize = payload.getSize();
SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2
? port
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT);
? port
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT);
memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize());
// enqueue message in LoRa send queue
#ifdef HAS_LORA
if (xQueueSendToBack(LoraSendQueue, (void *)&SendBuffer, (TickType_t)0))
if (xQueueSendToBack(LoraSendQueue, (void *)&SendBuffer, (TickType_t)0) ==
pdTRUE)
ESP_LOGI(TAG, "%d bytes enqueued to send on LoRa", payload.getSize());
#endif
// enqueue message in SPI send queue
#ifdef HAS_SPI
if (xQueueSendToBack(SPISendQueue, (void *)&SendBuffer, (TickType_t)0))
if (xQueueSendToBack(SPISendQueue, (void *)&SendBuffer, (TickType_t)0) ==
pdTRUE)
ESP_LOGI(TAG, "%d bytes enqueued to send on SPI", payload.getSize());
#endif
@ -30,11 +32,11 @@ void SendData(uint8_t port) {
reset_salt(); // get new salt for salting hashes
ESP_LOGI(TAG, "Counter cleared");
}
} // SendData
// cyclic called function to prepare payload to send
void sendPayload() {
if (SendCycleTimerIRQ) {
portENTER_CRITICAL(&timerMux);
SendCycleTimerIRQ = 0;
@ -77,23 +79,25 @@ void IRAM_ATTR SendCycleIRQ() {
// cyclic called function to eat data from RTos send queues and transmit it
void processSendBuffer() {
MessageBuffer_t SendBuffer;
#ifdef HAS_LORA
// Check if there is a pending TX/RX job running
if ((LMIC.opmode & (OP_JOINING | OP_REJOIN | OP_TXDATA | OP_POLL)) != 0) {
// LoRa Busy -> don't eat data from queue, since it cannot be sent
} else {
if (xQueueReceive(LoraSendQueue, &(SendBuffer), (TickType_t)10)) {
// SendBuffer now holds the struct MessageBuffer with next payload from queue
LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message, SendBuffer.MessageSize,
(cfg.countermode & 0x02));
ESP_LOGI(TAG, "%d bytes sent to LORA", SendBuffer.MessageSize);
if (xQueueReceive(LoraSendQueue, &SendBuffer, (TickType_t)0) == pdTRUE) {
// SendBuffer gets struct MessageBuffer with next payload from queue
LMIC_setTxData2(SendBuffer.MessagePort, SendBuffer.Message,
SendBuffer.MessageSize, (cfg.countermode & 0x02));
ESP_LOGI(TAG, "%d bytes sent to LoRa", SendBuffer.MessageSize);
sprintf(display_line7, "PACKET QUEUED");
}
}
#endif
#ifdef HAS_SPI
if (xQueueReceive(SPISendQueue, &(SendBuffer), (TickType_t)10)) {
if (xQueueReceive(SPISendQueue, &SendBuffer, (TickType_t)0) == pdTRUE) {
ESP_LOGI(TAG, "%d bytes sent to SPI", SendBuffer.MessageSize);
}
#endif
@ -102,9 +106,9 @@ void processSendBuffer() {
void flushQueues() {
#ifdef HAS_LORA
xQueueReset(LoraSendQueue);
xQueueReset(LoraSendQueue);
#endif
#ifdef HAS_SPI
xQueueReset(SPISendQueue);
xQueueReset(SPISendQueue);
#endif
}

View File

@ -1,13 +1,6 @@
#ifndef _SENDDATA_H
#define _SENDDATA_H
// Struct holding payload for data send queue
typedef struct {
uint8_t MessageSize;
uint8_t MessagePort;
uint8_t Message[PAYLOAD_BUFFER_SIZE];
} MessageBuffer_t;
void SendData(uint8_t port);
void sendPayload(void);
void SendCycleIRQ(void);