From 8db24bfa8e65bee69201554c10ee3ae99bf261dc Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Wed, 9 Dec 2020 11:01:54 +0100 Subject: [PATCH] msg prios removed, (not needed with buffer queues) --- include/globals.h | 2 -- include/senddata.h | 2 +- src/button.cpp | 2 +- src/lorawan.cpp | 24 +++--------------------- src/macsniff.cpp | 2 +- src/mqttclient.cpp | 19 +------------------ src/rcommand.cpp | 12 ++++++------ src/senddata.cpp | 21 ++++++++++----------- src/spislave.cpp | 21 ++------------------- src/timesync.cpp | 4 ++-- 10 files changed, 27 insertions(+), 82 deletions(-) diff --git a/include/globals.h b/include/globals.h index 5438fa3b..de59bac3 100644 --- a/include/globals.h +++ b/include/globals.h @@ -61,7 +61,6 @@ #define _micros() esp_timer_get_time() #define _seconds() _millis() / 1000.0 -enum sendprio_t { prio_low, prio_normal, prio_high }; enum timesource_t { _gps, _rtc, _lora, _unsynced }; enum snifftype_t { MAC_SNIFF_WIFI, MAC_SNIFF_BLE, MAC_SNIFF_BLE_ENS }; enum runmode_t { @@ -107,7 +106,6 @@ typedef struct __attribute__((packed)) { typedef struct { uint8_t MessageSize; uint8_t MessagePort; - sendprio_t MessagePrio; uint8_t Message[PAYLOAD_BUFFER_SIZE]; } MessageBuffer_t; diff --git a/include/senddata.h b/include/senddata.h index 008e439c..c99b1f5a 100644 --- a/include/senddata.h +++ b/include/senddata.h @@ -15,7 +15,7 @@ extern Ticker sendTimer; -void SendPayload(uint8_t port, sendprio_t prio); +void SendPayload(uint8_t port); void sendData(void); void checkSendQueues(void); void flushQueues(void); diff --git a/src/button.cpp b/src/button.cpp index dbd34b07..7a64bd07 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -33,7 +33,7 @@ void button_init(int pin) { b->setOnHolding([]() { payload.reset(); payload.addButton(0x01); - SendPayload(BUTTONPORT, prio_normal); + SendPayload(BUTTONPORT); }); // attach interrupt to the button diff --git a/src/lorawan.cpp b/src/lorawan.cpp index f2c75a0f..23d3f612 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -230,7 +230,7 @@ void lora_send(void *pvParameters) { } // switch delay(2); // yield to CPU - } // while(1) + } // while(1) } esp_err_t lmic_init(void) { @@ -318,26 +318,8 @@ esp_err_t lmic_init(void) { void lora_enqueuedata(MessageBuffer_t *message) { // enqueue message in LORA send queue - BaseType_t ret = pdFALSE; - MessageBuffer_t DummyBuffer; - sendprio_t prio = message->MessagePrio; - - switch (prio) { - case prio_high: - // clear some space in queue if full, then fallthrough to prio_normal - if (uxQueueSpacesAvailable(LoraSendQueue) == 0) { - xQueueReceive(LoraSendQueue, &DummyBuffer, (TickType_t)0); - ESP_LOGW(TAG, "LORA sendqueue purged, data is lost"); - } - case prio_normal: - ret = xQueueSendToBack(LoraSendQueue, (void *)message, (TickType_t)0); - break; - case prio_low: - default: - ret = xQueueSendToFront(LoraSendQueue, (void *)message, (TickType_t)0); - break; - } - if (ret != pdTRUE) { + if (xQueueSendToBack(LoraSendQueue, (void *)message, (TickType_t)0) != + pdTRUE) { snprintf(lmic_event_msg + 14, LMIC_EVENTMSG_LEN - 14, "<>"); ESP_LOGW(TAG, "LORA sendqueue is full"); } else { diff --git a/src/macsniff.cpp b/src/macsniff.cpp index 7a5063c7..7d0e4bea 100644 --- a/src/macsniff.cpp +++ b/src/macsniff.cpp @@ -126,7 +126,7 @@ uint16_t mac_analyze(MacBuffer_t MacBuffer) { #endif payload.reset(); payload.addAlarm(MacBuffer.rssi, beaconID); - SendPayload(BEACONPORT, prio_high); + SendPayload(BEACONPORT); } }; diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index eb647c0c..3527e4c1 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -150,24 +150,7 @@ void mqtt_client_task(void *param) { void mqtt_enqueuedata(MessageBuffer_t *message) { // enqueue message in MQTT send queue - BaseType_t ret; - MessageBuffer_t DummyBuffer; - sendprio_t prio = message->MessagePrio; - - switch (prio) { - case prio_high: - // clear space in queue if full, then fallthrough to normal - if (!uxQueueSpacesAvailable(MQTTSendQueue)) - xQueueReceive(MQTTSendQueue, &DummyBuffer, (TickType_t)0); - case prio_normal: - ret = xQueueSendToBack(MQTTSendQueue, (void *)message, (TickType_t)0); - break; - case prio_low: - default: - ret = xQueueSendToFront(MQTTSendQueue, (void *)message, (TickType_t)0); - break; - } - if (ret != pdTRUE) + if (xQueueSendToBack(MQTTSendQueue, (void *)message, (TickType_t)0) != pdTRUE) ESP_LOGW(TAG, "MQTT sendqueue is full"); } diff --git a/src/rcommand.cpp b/src/rcommand.cpp index bd451d73..0295fab1 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -279,7 +279,7 @@ void get_config(uint8_t val[]) { ESP_LOGI(TAG, "Remote command: get device configuration"); payload.reset(); payload.addConfig(cfg); - SendPayload(CONFIGPORT, prio_high); + SendPayload(CONFIGPORT); }; void get_status(uint8_t val[]) { @@ -288,7 +288,7 @@ void get_status(uint8_t val[]) { payload.addStatus(read_voltage(), uptime() / 1000, temperatureRead(), getFreeRAM(), rtc_get_reset_reason(0), rtc_get_reset_reason(1)); - SendPayload(STATUSPORT, prio_high); + SendPayload(STATUSPORT); }; void get_gps(uint8_t val[]) { @@ -298,7 +298,7 @@ void get_gps(uint8_t val[]) { gps_storelocation(&gps_status); payload.reset(); payload.addGPS(gps_status); - SendPayload(GPSPORT, prio_high); + SendPayload(GPSPORT); #else ESP_LOGW(TAG, "GPS function not supported"); #endif @@ -309,7 +309,7 @@ void get_bme(uint8_t val[]) { #if (HAS_BME) payload.reset(); payload.addBME(bme_status); - SendPayload(BMEPORT, prio_high); + SendPayload(BMEPORT); #else ESP_LOGW(TAG, "BME sensor not supported"); #endif @@ -320,7 +320,7 @@ void get_batt(uint8_t val[]) { #if (defined BAT_MEASURE_ADC || defined HAS_PMU) payload.reset(); payload.addVoltage(read_voltage()); - SendPayload(BATTPORT, prio_normal); + SendPayload(BATTPORT); #else ESP_LOGW(TAG, "Battery voltage not supported"); #endif @@ -331,7 +331,7 @@ void get_time(uint8_t val[]) { payload.reset(); payload.addTime(now()); payload.addByte(timeStatus() << 4 | timeSource); - SendPayload(TIMEPORT, prio_high); + SendPayload(TIMEPORT); }; void set_time(uint8_t val[]) { diff --git a/src/senddata.cpp b/src/senddata.cpp index 31a1096c..6c10be82 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -8,15 +8,14 @@ void setSendIRQ() { } // put data to send in RTos Queues used for transmit over channels Lora and SPI -void SendPayload(uint8_t port, sendprio_t prio) { +void SendPayload(uint8_t port) { - ESP_LOGD(TAG, "sending Payload for Port %d (prio %d)", port, prio); + ESP_LOGD(TAG, "sending Payload for Port %d", port); MessageBuffer_t - SendBuffer; // contains MessageSize, MessagePort, MessagePrio, Message[] + SendBuffer; // contains MessageSize, MessagePort, Message[] SendBuffer.MessageSize = payload.getSize(); - SendBuffer.MessagePrio = prio; switch (PAYLOAD_ENCODER) { case 1: // plain -> no mapping @@ -112,7 +111,7 @@ void sendData() { sds011_store(&sds_status); payload.addSDS(sds_status); #endif - SendPayload(COUNTERPORT, prio_normal); + SendPayload(COUNTERPORT); // clear counter if not in cumulative counter mode if (cfg.countermode != 1) { reset_counters(); // clear macs container and reset all counters @@ -130,7 +129,7 @@ void sendData() { case MEMS_DATA: payload.reset(); payload.addBME(bme_status); - SendPayload(BMEPORT, prio_normal); + SendPayload(BMEPORT); break; #endif @@ -142,7 +141,7 @@ void sendData() { gps_storelocation(&gps_status); payload.reset(); payload.addGPS(gps_status); - SendPayload(GPSPORT, prio_high); + SendPayload(GPSPORT); } else ESP_LOGD(TAG, "No valid GPS position"); } @@ -154,7 +153,7 @@ void sendData() { case SENSOR1_DATA: payload.reset(); payload.addSensor(sensor_read(1)); - SendPayload(SENSOR1PORT, prio_normal); + SendPayload(SENSOR1PORT); #if (COUNT_ENS) if (cfg.countermode != 1) cwa_clear(); @@ -165,14 +164,14 @@ void sendData() { case SENSOR2_DATA: payload.reset(); payload.addSensor(sensor_read(2)); - SendPayload(SENSOR2PORT, prio_normal); + SendPayload(SENSOR2PORT); break; #endif #if (HAS_SENSOR_3) case SENSOR3_DATA: payload.reset(); payload.addSensor(sensor_read(3)); - SendPayload(SENSOR3PORT, prio_normal); + SendPayload(SENSOR3PORT); break; #endif #endif @@ -181,7 +180,7 @@ void sendData() { case BATT_DATA: payload.reset(); payload.addVoltage(read_voltage()); - SendPayload(BATTPORT, prio_normal); + SendPayload(BATTPORT); break; #endif diff --git a/src/spislave.cpp b/src/spislave.cpp index 1555b5ec..bee8497e 100644 --- a/src/spislave.cpp +++ b/src/spislave.cpp @@ -96,7 +96,7 @@ void spi_slave_task(void *param) { ESP_LOG_BUFFER_HEXDUMP(TAG, rxbuf, transaction_size, ESP_LOG_DEBUG); ESP_LOGI(TAG, "Transaction finished with size %zu bits", spi_transaction.trans_len); - + // delete sent item from queue xQueueReceive(SPISendQueue, &msg, (TickType_t)0); @@ -153,24 +153,7 @@ esp_err_t spi_init() { void spi_enqueuedata(MessageBuffer_t *message) { // enqueue message in SPI send queue - BaseType_t ret; - MessageBuffer_t DummyBuffer; - sendprio_t prio = message->MessagePrio; - - switch (prio) { - case prio_high: - // clear space in queue if full, then fallthrough to normal - if (!uxQueueSpacesAvailable(SPISendQueue)) - xQueueReceive(SPISendQueue, &DummyBuffer, (TickType_t)0); - case prio_normal: - ret = xQueueSendToBack(SPISendQueue, (void *)message, (TickType_t)0); - break; - case prio_low: - default: - ret = xQueueSendToFront(SPISendQueue, (void *)message, (TickType_t)0); - break; - } - if (ret != pdTRUE) + if (xQueueSendToBack(SPISendQueue, (void *)message, (TickType_t)0) != pdTRUE) ESP_LOGW(TAG, "SPI sendqueue is full"); } diff --git a/src/timesync.cpp b/src/timesync.cpp index bdeea67b..c97da655 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -88,7 +88,7 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) { #if (TIME_SYNC_LORASERVER) // ask user's timeserver (for LoRAWAN < 1.0.3) payload.reset(); payload.addByte(time_sync_seqNo); - SendPayload(TIMEPORT, prio_high); + SendPayload(TIMEPORT); #elif (TIME_SYNC_LORAWAN) // ask network (requires LoRAWAN >= 1.0.3) LMIC_requestNetworkTime(timesync_serverAnswer, &time_sync_seqNo); // trigger to immediately get DevTimeAns from class A device @@ -148,7 +148,7 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) { // send timesync end char to show timesync was successful payload.reset(); payload.addByte(TIME_SYNC_END_FLAG); - SendPayload(TIMEPORT, prio_high); + SendPayload(TIMEPORT); goto Finish; Fail: