Send Queues (testing)

This commit is contained in:
Klaus K Wilting 2018-08-04 14:37:41 +02:00
parent 7b35c6a539
commit 03ca7d4a37
11 changed files with 185 additions and 43 deletions

View File

@ -6,6 +6,7 @@
<img src="img/Paxcounter-title.jpg">
<img src="img/Paxcounter-ttgo.jpg">
<img src="img/Paxcounter-lolin.gif">
<img src="img/Paxcounter-Screen.png">
# Use case

BIN
img/Paxcounter-Screen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -12,11 +12,11 @@
; ---> SELECT TARGET PLATFORM HERE! <---
[platformio]
;env_default = test
env_default = generic
;env_default = generic
;env_default = heltec
;env_default = ttgov1
;env_default = ttgov2
;env_default = ttgov21
env_default = ttgov21
;env_default = ttgobeam
;env_default = lopy
;env_default = lopy4

View File

@ -33,7 +33,7 @@ void doHomework() {
// check free memory
if (esp_get_minimum_free_heap_size() <= MEM_LOW) {
ESP_LOGW(TAG,
ESP_LOGI(TAG,
"Memory full, counter cleared (heap low water mark = %d Bytes / "
"free heap = %d bytes)",
esp_get_minimum_free_heap_size(), ESP.getFreeHeap());

View File

@ -91,6 +91,9 @@ void init_display(const char *Productname, const char *Version) {
void refreshtheDisplay() {
uint8_t msgWaiting = 0;
char buff[16];
// set display on/off according to current device configuration
if (DisplayState != cfg.screenon) {
DisplayState = cfg.screenon;
@ -102,7 +105,6 @@ void refreshtheDisplay() {
return;
// update counter (lines 0-1)
char buff[16];
snprintf(
buff, sizeof(buff), "PAX:%-4d",
(int)macs.size()); // convert 16-bit MAC counter to decimal counter value
@ -162,11 +164,23 @@ void refreshtheDisplay() {
#ifdef HAS_LORA
// update LoRa status display (line 6)
u8x8.setCursor(0, 6);
u8x8.printf("%-16s", display_line6);
u8x8.printf("%-14s", display_line6);
// update LMiC event display (line 7)
u8x8.setCursor(0, 7);
u8x8.printf("%-16s", display_line7);
u8x8.printf("%-14s", display_line7);
// update LoRa send queue display (line 7)
msgWaiting = uxQueueMessagesWaiting(LoraSendQueue);
if (msgWaiting) {
sprintf(buff, "%2d", msgWaiting);
u8x8.setCursor(14, 7);
u8x8.setInverseFont(1);
u8x8.printf("%-2s", msgWaiting == SEND_QUEUE_SIZE ? "<>" : buff);
u8x8.setInverseFont(0);
} else
u8x8.print(" "); // clear queue display
#endif // HAS_LORA
} // refreshDisplay()

View File

@ -47,6 +47,7 @@ extern hw_timer_t *channelSwitch, *sendCycle;
extern portMUX_TYPE timerMux;
extern volatile int SendCycleTimerIRQ, HomeCycleIRQ, DisplayTimerIRQ,
ChannelTimerIRQ, ButtonPressedIRQ;
extern QueueHandle_t LoraSendQueue, SPISendQueue;
extern std::array<uint64_t, 0xff>::iterator it;
extern std::array<uint64_t, 0xff> beacons;

View File

@ -100,7 +100,7 @@ bool mac_add(uint8_t *paddr, int8_t rssi, bool sniff_type) {
if (cfg.monitormode) {
beaconID = isBeacon(macConvert(paddr));
if (beaconID >= 0) {
ESP_LOGI(TAG, "Beacon ID#d detected", beaconID);
ESP_LOGI(TAG, "Beacon ID#%d detected", beaconID);
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
blink_LED(COLOR_WHITE, 2000);
#endif

View File

@ -41,9 +41,8 @@ hw_timer_t *channelSwitch = NULL, *displaytimer = NULL, *sendCycle = NULL,
volatile int ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0,
DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
// send queues
// RTos send queues for payload transmit
QueueHandle_t LoraSendQueue, SPISendQueue;
MessageBuffer_t SendBuffer;
portMUX_TYPE timerMux =
portMUX_INITIALIZER_UNLOCKED; // sync main loop and ISR when modifying IRQ
@ -110,7 +109,9 @@ void setup() {
// initialize send queues for transmit channels
#ifdef HAS_LORA
LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(struct SendBuffer *));
//--> LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(struct SendBuffer
//*));
LoraSendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
if (LoraSendQueue == 0) {
ESP_LOGE(TAG, "Could not create LORA send queue. Aborting.");
exit(0);
@ -119,7 +120,9 @@ void setup() {
SEND_QUEUE_SIZE * PAYLOAD_BUFFER_SIZE);
#endif
#ifdef HAS_SPI
SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(struct SendBuffer *));
//--> SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(struct SendBuffer
//*));
SPISendQueue = xQueueCreate(SEND_QUEUE_SIZE, sizeof(MessageBuffer_t));
if (SPISendQueue == 0) {
ESP_LOGE(TAG, "Could not create SPI send queue. Aborting.");
exit(0);
@ -330,6 +333,8 @@ void loop() {
// reset watchdog
vTaskDelay(1 / portTICK_PERIOD_MS);
//ESP_LOGI(TAG, "%d Bytes left", ESP.getFreeHeap());
} // loop()
}

View File

@ -9,10 +9,10 @@
// Payload send cycle and encoding
#define SEND_SECS 30 // payload send cycle [seconds/2] -> 60 sec.
#define PAYLOAD_ENCODER 1 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed
#define PAYLOAD_ENCODER 2 // payload encoder: 1=Plain, 2=Packed, 3=CayenneLPP dynamic, 4=CayenneLPP packed
// Set this to include BLE counting and vendor filter functions
#define VENDORFILTER 1 // comment out if you want to count things, not people
//#define VENDORFILTER 1 // comment out if you want to count things, not people
#define BLECOUNTER 1 // comment out if you don't want BLE count, saves power & memory
// BLE scan parameters

View File

@ -3,24 +3,24 @@
// put data to send in RTos Queues used for transmit over channels Lora and SPI
void EnqueueSendData(uint8_t port, uint8_t data[], uint8_t size) {
MessageBuffer_t *xMsg; // create pointer to struct which holds the sendbuffer
SendBuffer.MessageSize = size;
SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2
MessageBuffer_t MySendBuffer;
MySendBuffer.MessageSize = size;
MySendBuffer.MessagePort = PAYLOAD_ENCODER <= 2
? port
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT);
memcpy(SendBuffer.Message, data, size);
xMsg = &SendBuffer;
memcpy(MySendBuffer.Message, data, size);
// enqueue message in LoRa send queue
#ifdef HAS_LORA
xQueueSend(LoraSendQueue, (void *)&xMsg, (TickType_t)0);
if (xQueueSendToBack(LoraSendQueue, (void *)&MySendBuffer, (TickType_t)0))
ESP_LOGI(TAG, "%d bytes enqueued to send on LoRa", size);
#endif
// enqueue message in SPI send queue
#ifdef HAS_SPI
xQueueSend(SPISendQueue, (void *)&xMsg, (TickType_t)0);
if (xQueueSendToBack(SPISendQueue, (void *)&MySendBuffer, (TickType_t)0))
ESP_LOGI(TAG, "%d bytes enqueued to send on SPI", size);
#endif
@ -31,6 +31,8 @@ void EnqueueSendData(uint8_t port, uint8_t data[], uint8_t size) {
ESP_LOGI(TAG, "Counter cleared");
}
ESP_LOGI(TAG, "%d Bytes left", ESP.getFreeHeap());
} // senddata
// cyclic called function to prepare payload to send
@ -76,14 +78,130 @@ void IRAM_ATTR SendCycleIRQ() {
// cyclic called function to eat data from RTos send queues and transmit it
void processSendBuffer() {
MessageBuffer_t RcvBuf;
#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, &(RcvBuf), (TickType_t)10)) {
// xMsg now holds the struct MessageBuffer from queue
LMIC_setTxData2(RcvBuf.MessagePort, RcvBuf.Message, RcvBuf.MessageSize,
(cfg.countermode & 0x02));
ESP_LOGI(TAG, "%d bytes sent to LORA", RcvBuf.MessageSize);
sprintf(display_line7, "PACKET QUEUED");
}
}
#endif
#ifdef HAS_SPI
if (xQueueReceive(SPISendQueue, &(RcvBuf), (TickType_t)10)) {
ESP_LOGI(TAG, "%d bytes sent to SPI", RcvBuf.MessageSize);
}
#endif
ESP_LOGI(TAG, "%d Bytes left", ESP.getFreeHeap());
} // processSendBuffer
/* old version with pointers
// Basic Config
#include "globals.h"
// put data to send in RTos Queues used for transmit over channels Lora and SPI
void EnqueueSendData(uint8_t port, uint8_t data[], uint8_t size) {
MessageBuffer_t *xMsg = &SendBuffer;
SendBuffer.MessageSize = size;
SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2
? port
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT);
memcpy(SendBuffer.Message, data, size);
// enqueue message in LoRa send queue
#ifdef HAS_LORA
if (uxQueueSpacesAvailable(LoraSendQueue)) {
xQueueSend(LoraSendQueue, (void *)&xMsg, (TickType_t)0);
ESP_LOGI(TAG, "%d bytes enqueued to send on LoRa", size);
};
#endif
// enqueue message in SPI send queue
#ifdef HAS_SPI
if (uxQueueSpacesAvailable(SPISendQueue)) {
xQueueSend(SPISendQueue, (void *)&xMsg, (TickType_t)0);
ESP_LOGI(TAG, "%d bytes enqueued to send on SPI", size);
};
#endif
// clear counter if not in cumulative counter mode
if ((port == COUNTERPORT) && (cfg.countermode != 1)) {
reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes
ESP_LOGI(TAG, "Counter cleared");
}
ESP_LOGI(TAG, "%d Bytes left", ESP.getFreeHeap());
} // senddata
// cyclic called function to prepare payload to send
void sendPayload() {
if (SendCycleTimerIRQ) {
portENTER_CRITICAL(&timerMux);
SendCycleTimerIRQ = 0;
portEXIT_CRITICAL(&timerMux);
// append counter data to payload
payload.reset();
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0);
// append GPS data, if present
#ifdef HAS_GPS
// show NMEA data in debug mode, useful for debugging GPS on board
// connection
ESP_LOGD(TAG, "GPS NMEA data: passed %d / failed: %d / with fix: %d",
gps.passedChecksum(), gps.failedChecksum(),
gps.sentencesWithFix());
// log GPS position if we have a fix and gps data mode is enabled
if ((cfg.gpsmode) && (gps.location.isValid())) {
gps_read();
payload.addGPS(gps_status);
ESP_LOGD(TAG, "lat=%.6f | lon=%.6f | %u Sats | HDOP=%.1f | Altitude=%um",
gps_status.latitude / (float)1e6,
gps_status.longitude / (float)1e6, gps_status.satellites,
gps_status.hdop / (float)100, gps_status.altitude);
} else {
ESP_LOGD(TAG, "No valid GPS position or GPS data mode disabled");
}
#endif
EnqueueSendData(COUNTERPORT, payload.getBuffer(), payload.getSize());
}
} // sendpayload()
// interrupt handler used for payload send cycle timer
void IRAM_ATTR SendCycleIRQ() {
portENTER_CRITICAL(&timerMux);
SendCycleTimerIRQ++;
portEXIT_CRITICAL(&timerMux);
}
// cyclic called function to eat data from RTos send queues and transmit it
void processSendBuffer() {
MessageBuffer_t *xMsg;
#ifdef HAS_LORA
// Check if there is a pending TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
sprintf(display_line7, "LORA BUSY");
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, &(xMsg), (TickType_t)10)) {
if (uxQueueMessagesWaiting(LoraSendQueue)) // check if msg are waiting on
queue if (xQueueReceive(LoraSendQueue, &xMsg, (TickType_t)10)) {
// xMsg now holds the struct MessageBuffer from queue
LMIC_setTxData2(xMsg->MessagePort, xMsg->Message, xMsg->MessageSize,
(cfg.countermode & 0x02));
@ -94,7 +212,8 @@ void processSendBuffer() {
#endif
#ifdef HAS_SPI
if (xQueueReceive(SPISendQueue, &(xMsg), (TickType_t)10)) {
if (uxQueueMessagesWaiting(SPISendQueue)) // check if msg are waiting on queue
if (xQueueReceive(SPISendQueue, &xMsg, (TickType_t)10)) {
// to come here: send data over SPI
// use these pointers to the payload:
@ -105,4 +224,9 @@ void processSendBuffer() {
ESP_LOGI(TAG, "%d bytes sent to SPI", xMsg->MessageSize);
}
#endif
ESP_LOGI(TAG, "%d Bytes left", ESP.getFreeHeap());
} // processSendBuffer
*/

View File

@ -8,9 +8,6 @@ typedef struct {
uint8_t Message[PAYLOAD_BUFFER_SIZE];
} MessageBuffer_t;
extern QueueHandle_t LoraSendQueue, SPISendQueue;
extern MessageBuffer_t SendBuffer;
void EnqueueSendData(uint8_t port, uint8_t data[], uint8_t size);
void sendPayload(void);
void SendCycleIRQ(void);