msg prios removed, (not needed with buffer queues)

This commit is contained in:
Klaus K Wilting 2020-12-09 11:01:54 +01:00
parent 36afe66df9
commit 8db24bfa8e
10 changed files with 27 additions and 82 deletions

View File

@ -61,7 +61,6 @@
#define _micros() esp_timer_get_time() #define _micros() esp_timer_get_time()
#define _seconds() _millis() / 1000.0 #define _seconds() _millis() / 1000.0
enum sendprio_t { prio_low, prio_normal, prio_high };
enum timesource_t { _gps, _rtc, _lora, _unsynced }; enum timesource_t { _gps, _rtc, _lora, _unsynced };
enum snifftype_t { MAC_SNIFF_WIFI, MAC_SNIFF_BLE, MAC_SNIFF_BLE_ENS }; enum snifftype_t { MAC_SNIFF_WIFI, MAC_SNIFF_BLE, MAC_SNIFF_BLE_ENS };
enum runmode_t { enum runmode_t {
@ -107,7 +106,6 @@ typedef struct __attribute__((packed)) {
typedef struct { typedef struct {
uint8_t MessageSize; uint8_t MessageSize;
uint8_t MessagePort; uint8_t MessagePort;
sendprio_t MessagePrio;
uint8_t Message[PAYLOAD_BUFFER_SIZE]; uint8_t Message[PAYLOAD_BUFFER_SIZE];
} MessageBuffer_t; } MessageBuffer_t;

View File

@ -15,7 +15,7 @@
extern Ticker sendTimer; extern Ticker sendTimer;
void SendPayload(uint8_t port, sendprio_t prio); void SendPayload(uint8_t port);
void sendData(void); void sendData(void);
void checkSendQueues(void); void checkSendQueues(void);
void flushQueues(void); void flushQueues(void);

View File

@ -33,7 +33,7 @@ void button_init(int pin) {
b->setOnHolding([]() { b->setOnHolding([]() {
payload.reset(); payload.reset();
payload.addButton(0x01); payload.addButton(0x01);
SendPayload(BUTTONPORT, prio_normal); SendPayload(BUTTONPORT);
}); });
// attach interrupt to the button // attach interrupt to the button

View File

@ -230,7 +230,7 @@ void lora_send(void *pvParameters) {
} // switch } // switch
delay(2); // yield to CPU delay(2); // yield to CPU
} // while(1) } // while(1)
} }
esp_err_t lmic_init(void) { esp_err_t lmic_init(void) {
@ -318,26 +318,8 @@ esp_err_t lmic_init(void) {
void lora_enqueuedata(MessageBuffer_t *message) { void lora_enqueuedata(MessageBuffer_t *message) {
// enqueue message in LORA send queue // enqueue message in LORA send queue
BaseType_t ret = pdFALSE; if (xQueueSendToBack(LoraSendQueue, (void *)message, (TickType_t)0) !=
MessageBuffer_t DummyBuffer; pdTRUE) {
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) {
snprintf(lmic_event_msg + 14, LMIC_EVENTMSG_LEN - 14, "<>"); snprintf(lmic_event_msg + 14, LMIC_EVENTMSG_LEN - 14, "<>");
ESP_LOGW(TAG, "LORA sendqueue is full"); ESP_LOGW(TAG, "LORA sendqueue is full");
} else { } else {

View File

@ -126,7 +126,7 @@ uint16_t mac_analyze(MacBuffer_t MacBuffer) {
#endif #endif
payload.reset(); payload.reset();
payload.addAlarm(MacBuffer.rssi, beaconID); payload.addAlarm(MacBuffer.rssi, beaconID);
SendPayload(BEACONPORT, prio_high); SendPayload(BEACONPORT);
} }
}; };

View File

@ -150,24 +150,7 @@ void mqtt_client_task(void *param) {
void mqtt_enqueuedata(MessageBuffer_t *message) { void mqtt_enqueuedata(MessageBuffer_t *message) {
// enqueue message in MQTT send queue // enqueue message in MQTT send queue
BaseType_t ret; if (xQueueSendToBack(MQTTSendQueue, (void *)message, (TickType_t)0) != pdTRUE)
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)
ESP_LOGW(TAG, "MQTT sendqueue is full"); ESP_LOGW(TAG, "MQTT sendqueue is full");
} }

View File

@ -279,7 +279,7 @@ void get_config(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get device configuration"); ESP_LOGI(TAG, "Remote command: get device configuration");
payload.reset(); payload.reset();
payload.addConfig(cfg); payload.addConfig(cfg);
SendPayload(CONFIGPORT, prio_high); SendPayload(CONFIGPORT);
}; };
void get_status(uint8_t val[]) { void get_status(uint8_t val[]) {
@ -288,7 +288,7 @@ void get_status(uint8_t val[]) {
payload.addStatus(read_voltage(), uptime() / 1000, temperatureRead(), payload.addStatus(read_voltage(), uptime() / 1000, temperatureRead(),
getFreeRAM(), rtc_get_reset_reason(0), getFreeRAM(), rtc_get_reset_reason(0),
rtc_get_reset_reason(1)); rtc_get_reset_reason(1));
SendPayload(STATUSPORT, prio_high); SendPayload(STATUSPORT);
}; };
void get_gps(uint8_t val[]) { void get_gps(uint8_t val[]) {
@ -298,7 +298,7 @@ void get_gps(uint8_t val[]) {
gps_storelocation(&gps_status); gps_storelocation(&gps_status);
payload.reset(); payload.reset();
payload.addGPS(gps_status); payload.addGPS(gps_status);
SendPayload(GPSPORT, prio_high); SendPayload(GPSPORT);
#else #else
ESP_LOGW(TAG, "GPS function not supported"); ESP_LOGW(TAG, "GPS function not supported");
#endif #endif
@ -309,7 +309,7 @@ void get_bme(uint8_t val[]) {
#if (HAS_BME) #if (HAS_BME)
payload.reset(); payload.reset();
payload.addBME(bme_status); payload.addBME(bme_status);
SendPayload(BMEPORT, prio_high); SendPayload(BMEPORT);
#else #else
ESP_LOGW(TAG, "BME sensor not supported"); ESP_LOGW(TAG, "BME sensor not supported");
#endif #endif
@ -320,7 +320,7 @@ void get_batt(uint8_t val[]) {
#if (defined BAT_MEASURE_ADC || defined HAS_PMU) #if (defined BAT_MEASURE_ADC || defined HAS_PMU)
payload.reset(); payload.reset();
payload.addVoltage(read_voltage()); payload.addVoltage(read_voltage());
SendPayload(BATTPORT, prio_normal); SendPayload(BATTPORT);
#else #else
ESP_LOGW(TAG, "Battery voltage not supported"); ESP_LOGW(TAG, "Battery voltage not supported");
#endif #endif
@ -331,7 +331,7 @@ void get_time(uint8_t val[]) {
payload.reset(); payload.reset();
payload.addTime(now()); payload.addTime(now());
payload.addByte(timeStatus() << 4 | timeSource); payload.addByte(timeStatus() << 4 | timeSource);
SendPayload(TIMEPORT, prio_high); SendPayload(TIMEPORT);
}; };
void set_time(uint8_t val[]) { void set_time(uint8_t val[]) {

View File

@ -8,15 +8,14 @@ void setSendIRQ() {
} }
// 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 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 MessageBuffer_t
SendBuffer; // contains MessageSize, MessagePort, MessagePrio, Message[] SendBuffer; // contains MessageSize, MessagePort, Message[]
SendBuffer.MessageSize = payload.getSize(); SendBuffer.MessageSize = payload.getSize();
SendBuffer.MessagePrio = prio;
switch (PAYLOAD_ENCODER) { switch (PAYLOAD_ENCODER) {
case 1: // plain -> no mapping case 1: // plain -> no mapping
@ -112,7 +111,7 @@ void sendData() {
sds011_store(&sds_status); sds011_store(&sds_status);
payload.addSDS(sds_status); payload.addSDS(sds_status);
#endif #endif
SendPayload(COUNTERPORT, prio_normal); SendPayload(COUNTERPORT);
// clear counter if not in cumulative counter mode // clear counter if not in cumulative counter mode
if (cfg.countermode != 1) { if (cfg.countermode != 1) {
reset_counters(); // clear macs container and reset all counters reset_counters(); // clear macs container and reset all counters
@ -130,7 +129,7 @@ void sendData() {
case MEMS_DATA: case MEMS_DATA:
payload.reset(); payload.reset();
payload.addBME(bme_status); payload.addBME(bme_status);
SendPayload(BMEPORT, prio_normal); SendPayload(BMEPORT);
break; break;
#endif #endif
@ -142,7 +141,7 @@ void sendData() {
gps_storelocation(&gps_status); gps_storelocation(&gps_status);
payload.reset(); payload.reset();
payload.addGPS(gps_status); payload.addGPS(gps_status);
SendPayload(GPSPORT, prio_high); SendPayload(GPSPORT);
} else } else
ESP_LOGD(TAG, "No valid GPS position"); ESP_LOGD(TAG, "No valid GPS position");
} }
@ -154,7 +153,7 @@ void sendData() {
case SENSOR1_DATA: case SENSOR1_DATA:
payload.reset(); payload.reset();
payload.addSensor(sensor_read(1)); payload.addSensor(sensor_read(1));
SendPayload(SENSOR1PORT, prio_normal); SendPayload(SENSOR1PORT);
#if (COUNT_ENS) #if (COUNT_ENS)
if (cfg.countermode != 1) if (cfg.countermode != 1)
cwa_clear(); cwa_clear();
@ -165,14 +164,14 @@ void sendData() {
case SENSOR2_DATA: case SENSOR2_DATA:
payload.reset(); payload.reset();
payload.addSensor(sensor_read(2)); payload.addSensor(sensor_read(2));
SendPayload(SENSOR2PORT, prio_normal); SendPayload(SENSOR2PORT);
break; break;
#endif #endif
#if (HAS_SENSOR_3) #if (HAS_SENSOR_3)
case SENSOR3_DATA: case SENSOR3_DATA:
payload.reset(); payload.reset();
payload.addSensor(sensor_read(3)); payload.addSensor(sensor_read(3));
SendPayload(SENSOR3PORT, prio_normal); SendPayload(SENSOR3PORT);
break; break;
#endif #endif
#endif #endif
@ -181,7 +180,7 @@ void sendData() {
case BATT_DATA: case BATT_DATA:
payload.reset(); payload.reset();
payload.addVoltage(read_voltage()); payload.addVoltage(read_voltage());
SendPayload(BATTPORT, prio_normal); SendPayload(BATTPORT);
break; break;
#endif #endif

View File

@ -153,24 +153,7 @@ esp_err_t spi_init() {
void spi_enqueuedata(MessageBuffer_t *message) { void spi_enqueuedata(MessageBuffer_t *message) {
// enqueue message in SPI send queue // enqueue message in SPI send queue
BaseType_t ret; if (xQueueSendToBack(SPISendQueue, (void *)message, (TickType_t)0) != pdTRUE)
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)
ESP_LOGW(TAG, "SPI sendqueue is full"); ESP_LOGW(TAG, "SPI sendqueue is full");
} }

View File

@ -88,7 +88,7 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) {
#if (TIME_SYNC_LORASERVER) // ask user's timeserver (for LoRAWAN < 1.0.3) #if (TIME_SYNC_LORASERVER) // ask user's timeserver (for LoRAWAN < 1.0.3)
payload.reset(); payload.reset();
payload.addByte(time_sync_seqNo); payload.addByte(time_sync_seqNo);
SendPayload(TIMEPORT, prio_high); SendPayload(TIMEPORT);
#elif (TIME_SYNC_LORAWAN) // ask network (requires LoRAWAN >= 1.0.3) #elif (TIME_SYNC_LORAWAN) // ask network (requires LoRAWAN >= 1.0.3)
LMIC_requestNetworkTime(timesync_serverAnswer, &time_sync_seqNo); LMIC_requestNetworkTime(timesync_serverAnswer, &time_sync_seqNo);
// trigger to immediately get DevTimeAns from class A device // 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 // send timesync end char to show timesync was successful
payload.reset(); payload.reset();
payload.addByte(TIME_SYNC_END_FLAG); payload.addByte(TIME_SYNC_END_FLAG);
SendPayload(TIMEPORT, prio_high); SendPayload(TIMEPORT);
goto Finish; goto Finish;
Fail: Fail: