msg prios removed, (not needed with buffer queues)
This commit is contained in:
parent
36afe66df9
commit
8db24bfa8e
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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[]) {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user