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! <--- ; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <---
; otherwise device may leak RAM ; otherwise device may leak RAM
; ;
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE ; None
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=0
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ; Error
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ; -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 ; override lora settings from LMiC library in lmic/config.h and use main.h instead
-D_lmic_config_h_ -D_lmic_config_h_

View File

@ -114,7 +114,7 @@ void refreshtheDisplay() {
// update Battery status (line 2) // update Battery status (line 2)
#ifdef HAS_BATTERY_PROBE #ifdef HAS_BATTERY_PROBE
u8x8.setCursor(0, 2); 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 #endif
// update GPS status (line 2) // update GPS status (line 2)

View File

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

View File

@ -172,13 +172,13 @@ void onEvent(ev_t ev) {
strcpy_P(buff, PSTR("JOINED")); strcpy_P(buff, PSTR("JOINED"));
sprintf(display_line6, " "); // clear previous lmic status 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 // set data rate adaptation according to saved setting
LMIC_setAdrMode(cfg.adrmode); 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 // Set data rate and transmit power (note: txpower seems to be ignored by
// the library) // the library)
switch_lora(cfg.lorasf, cfg.txpower); switch_lora(cfg.lorasf, cfg.txpower);

View File

@ -42,14 +42,19 @@ volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0,
DisplayTimerIRQ = 0, HomeCycleIRQ = 0; DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
// RTos send queues for payload transmit // 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_TYPE timerMux =
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
// handler shared variables // handler shared variables
std::set<uint16_t> macs; // associative container holding unique MAC std::set<uint16_t> macs; // container holding unique MAC adress hashes
// adress hashes (Wifi + BLE)
// initialize payload encoder // initialize payload encoder
PayloadConvert payload(PAYLOAD_BUFFER_SIZE); PayloadConvert payload(PAYLOAD_BUFFER_SIZE);
@ -107,26 +112,6 @@ void setup() {
#endif // verbose #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 // read settings from NVRAM
loadConfig(); // includes initialize if necessary loadConfig(); // includes initialize if necessary
@ -137,6 +122,25 @@ void setup() {
// initialize LoRa // initialize LoRa
#ifdef HAS_LORA #ifdef HAS_LORA
strcat_P(features, " 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 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 #endif
// initialize led // initialize led
@ -326,8 +330,6 @@ void loop() {
processSendBuffer(); processSendBuffer();
// check send cycle and enqueue payload if cycle is expired // check send cycle and enqueue payload if cycle is expired
sendPayload(); sendPayload();
// reset watchdog
vTaskDelay(1 / portTICK_PERIOD_MS);
} // loop() } // loop()
} }

View File

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

View File

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

View File

@ -1,13 +1,6 @@
#ifndef _SENDDATA_H #ifndef _SENDDATA_H
#define _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 SendData(uint8_t port);
void sendPayload(void); void sendPayload(void);
void SendCycleIRQ(void); void SendCycleIRQ(void);