2018-07-14 19:12:20 +02:00
|
|
|
// Basic Config
|
2018-11-03 20:44:54 +01:00
|
|
|
#include "senddata.h"
|
2018-07-14 19:12:20 +02:00
|
|
|
|
2019-03-03 00:30:57 +01:00
|
|
|
Ticker sendcycler;
|
|
|
|
|
2019-04-13 18:44:25 +02:00
|
|
|
void sendcycle() {
|
|
|
|
xTaskNotifyFromISR(irqHandlerTask, SENDCYCLE_IRQ, eSetBits, NULL);
|
|
|
|
}
|
2019-03-03 00:30:57 +01:00
|
|
|
|
2018-08-03 23:50:04 +02:00
|
|
|
// put data to send in RTos Queues used for transmit over channels Lora and SPI
|
2019-02-03 14:12:21 +01:00
|
|
|
void SendPayload(uint8_t port, sendprio_t prio) {
|
2018-08-04 14:37:41 +02:00
|
|
|
|
2019-09-09 20:02:21 +02:00
|
|
|
MessageBuffer_t
|
|
|
|
SendBuffer; // contains MessageSize, MessagePort, MessagePrio, Message[]
|
2018-08-10 16:33:47 +02:00
|
|
|
|
2018-08-07 21:10:34 +02:00
|
|
|
SendBuffer.MessageSize = payload.getSize();
|
2019-08-28 10:48:39 +02:00
|
|
|
SendBuffer.MessagePrio = prio;
|
|
|
|
|
2018-11-25 23:39:12 +01:00
|
|
|
switch (PAYLOAD_ENCODER) {
|
2019-02-24 13:35:22 +01:00
|
|
|
case 1: // plain -> no mapping
|
|
|
|
case 2: // packed -> no mapping
|
2018-11-25 23:39:12 +01:00
|
|
|
SendBuffer.MessagePort = port;
|
|
|
|
break;
|
2019-02-24 13:35:22 +01:00
|
|
|
case 3: // Cayenne LPP dynamic -> all payload goes out on same port
|
|
|
|
SendBuffer.MessagePort = CAYENNE_LPP1;
|
2018-11-25 23:39:12 +01:00
|
|
|
break;
|
2019-02-24 13:35:22 +01:00
|
|
|
case 4: // Cayenne LPP packed -> we need to map some paxcounter ports
|
|
|
|
SendBuffer.MessagePort = CAYENNE_LPP2;
|
|
|
|
switch (SendBuffer.MessagePort) {
|
|
|
|
case COUNTERPORT:
|
|
|
|
SendBuffer.MessagePort = CAYENNE_LPP2;
|
|
|
|
break;
|
|
|
|
case RCMDPORT:
|
|
|
|
SendBuffer.MessagePort = CAYENNE_ACTUATOR;
|
|
|
|
break;
|
|
|
|
case TIMEPORT:
|
|
|
|
SendBuffer.MessagePort = CAYENNE_DEVICECONFIG;
|
|
|
|
break;
|
|
|
|
}
|
2018-11-25 23:39:12 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SendBuffer.MessagePort = port;
|
|
|
|
}
|
2019-08-28 21:55:50 +02:00
|
|
|
memcpy(SendBuffer.Message, payload.getBuffer(), SendBuffer.MessageSize);
|
2018-08-04 14:37:41 +02:00
|
|
|
|
2019-02-27 00:49:32 +01:00
|
|
|
// enqueue message in device's send queues
|
2019-03-15 20:20:21 +01:00
|
|
|
#if (HAS_LORA)
|
2019-08-28 10:48:39 +02:00
|
|
|
lora_enqueuedata(&SendBuffer);
|
2019-02-27 00:49:32 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAS_SPI
|
2019-08-28 10:48:39 +02:00
|
|
|
spi_enqueuedata(&SendBuffer);
|
2019-02-27 00:49:32 +01:00
|
|
|
#endif
|
2020-05-16 23:49:34 +02:00
|
|
|
#ifdef HAS_MQTT
|
|
|
|
mqtt_enqueuedata(&SendBuffer);
|
|
|
|
#endif
|
2018-08-04 14:37:41 +02:00
|
|
|
|
2019-12-25 23:07:34 +01:00
|
|
|
// write data to sdcard, if present
|
2020-09-01 11:57:45 +02:00
|
|
|
#if (HAS_SDCARD)
|
|
|
|
if ( port == COUNTERPORT ) {
|
|
|
|
sdcardWriteData(macs_wifi, macs_ble
|
2020-09-02 11:21:56 +02:00
|
|
|
#if (COUNT_ENS)
|
2020-09-01 11:57:45 +02:00
|
|
|
, cwa_report()
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
2019-12-25 23:07:34 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-18 15:50:57 +01:00
|
|
|
} // SendPayload
|
2018-08-04 14:37:41 +02:00
|
|
|
|
2018-09-21 18:23:34 +02:00
|
|
|
// interrupt triggered function to prepare payload to send
|
2019-08-30 18:54:53 +02:00
|
|
|
void sendData() {
|
2018-08-10 16:33:47 +02:00
|
|
|
|
2018-11-19 00:41:15 +01:00
|
|
|
uint8_t bitmask = cfg.payloadmask;
|
|
|
|
uint8_t mask = 1;
|
2020-02-25 22:18:20 +01:00
|
|
|
#if (HAS_GPS)
|
2019-11-24 18:13:42 +01:00
|
|
|
gpsStatus_t gps_status;
|
2020-02-25 22:18:20 +01:00
|
|
|
#endif
|
|
|
|
#if (HAS_SDS011)
|
|
|
|
sdsStatus_t sds_status;
|
|
|
|
#endif
|
2018-08-04 14:37:41 +02:00
|
|
|
|
2018-11-19 00:41:15 +01:00
|
|
|
while (bitmask) {
|
|
|
|
switch (bitmask & mask) {
|
2018-11-17 22:49:14 +01:00
|
|
|
|
2019-04-13 18:44:25 +02:00
|
|
|
#if ((WIFICOUNTER) || (BLECOUNTER))
|
2018-11-19 00:41:15 +01:00
|
|
|
case COUNT_DATA:
|
2018-11-20 15:02:37 +01:00
|
|
|
payload.reset();
|
2019-11-19 23:27:12 +01:00
|
|
|
#if !(PAYLOAD_OPENSENSEBOX)
|
2019-11-21 21:34:54 +01:00
|
|
|
if (cfg.wifiscan)
|
2019-11-27 21:26:03 +01:00
|
|
|
payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
|
2018-12-02 14:08:50 +01:00
|
|
|
if (cfg.blescan)
|
|
|
|
payload.addCount(macs_ble, MAC_SNIFF_BLE);
|
2019-11-19 23:27:12 +01:00
|
|
|
#endif
|
2019-12-25 23:07:34 +01:00
|
|
|
#if (HAS_GPS)
|
2019-11-24 18:13:42 +01:00
|
|
|
if (GPSPORT == COUNTERPORT) {
|
|
|
|
// send GPS position only if we have a fix
|
2020-01-03 09:59:10 +01:00
|
|
|
if (gps_hasfix()) {
|
2019-11-27 21:26:03 +01:00
|
|
|
gps_storelocation(&gps_status);
|
|
|
|
payload.addGPS(gps_status);
|
2019-11-24 18:13:42 +01:00
|
|
|
} else
|
|
|
|
ESP_LOGD(TAG, "No valid GPS position");
|
|
|
|
}
|
2019-11-19 23:27:12 +01:00
|
|
|
#endif
|
2019-12-25 23:07:34 +01:00
|
|
|
#if (PAYLOAD_OPENSENSEBOX)
|
2019-11-21 21:34:54 +01:00
|
|
|
if (cfg.wifiscan)
|
2019-11-27 21:26:03 +01:00
|
|
|
payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
|
2019-11-19 23:27:12 +01:00
|
|
|
if (cfg.blescan)
|
|
|
|
payload.addCount(macs_ble, MAC_SNIFF_BLE);
|
2020-01-22 15:49:07 +01:00
|
|
|
#endif
|
|
|
|
#if (HAS_SDS011)
|
2020-02-25 22:18:20 +01:00
|
|
|
sds011_store(&sds_status);
|
|
|
|
payload.addSDS(sds_status);
|
2019-11-17 10:32:43 +01:00
|
|
|
#endif
|
2019-02-03 14:12:21 +01:00
|
|
|
SendPayload(COUNTERPORT, prio_normal);
|
2018-11-19 00:41:15 +01:00
|
|
|
// clear counter if not in cumulative counter mode
|
|
|
|
if (cfg.countermode != 1) {
|
|
|
|
reset_counters(); // clear macs container and reset all counters
|
|
|
|
get_salt(); // get new salt for salting hashes
|
|
|
|
ESP_LOGI(TAG, "Counter cleared");
|
|
|
|
}
|
2019-10-01 18:06:49 +02:00
|
|
|
#ifdef HAS_DISPLAY
|
|
|
|
else
|
2020-03-29 12:10:42 +02:00
|
|
|
dp_plotCurve(macs.size(), true);
|
2019-10-01 18:06:49 +02:00
|
|
|
#endif
|
2018-11-19 00:41:15 +01:00
|
|
|
break;
|
2019-04-13 18:44:25 +02:00
|
|
|
#endif
|
2018-11-19 00:41:15 +01:00
|
|
|
|
2019-03-15 20:20:21 +01:00
|
|
|
#if (HAS_BME)
|
2018-11-20 15:02:37 +01:00
|
|
|
case MEMS_DATA:
|
|
|
|
payload.reset();
|
2018-11-19 00:41:15 +01:00
|
|
|
payload.addBME(bme_status);
|
2019-02-03 14:12:21 +01:00
|
|
|
SendPayload(BMEPORT, prio_normal);
|
2018-11-19 00:41:15 +01:00
|
|
|
break;
|
2018-11-20 15:02:37 +01:00
|
|
|
#endif
|
2018-11-19 00:41:15 +01:00
|
|
|
|
2019-12-25 23:07:34 +01:00
|
|
|
#if (HAS_GPS)
|
2018-11-20 15:02:37 +01:00
|
|
|
case GPS_DATA:
|
2019-11-24 18:13:42 +01:00
|
|
|
if (GPSPORT != COUNTERPORT) {
|
|
|
|
// send GPS position only if we have a fix
|
2020-01-03 09:59:10 +01:00
|
|
|
if (gps_hasfix()) {
|
2019-11-24 18:13:42 +01:00
|
|
|
gps_storelocation(&gps_status);
|
|
|
|
payload.reset();
|
|
|
|
payload.addGPS(gps_status);
|
|
|
|
SendPayload(GPSPORT, prio_high);
|
|
|
|
} else
|
|
|
|
ESP_LOGD(TAG, "No valid GPS position");
|
|
|
|
}
|
2018-11-20 15:02:37 +01:00
|
|
|
break;
|
2018-11-19 00:41:15 +01:00
|
|
|
#endif
|
2018-11-20 15:02:37 +01:00
|
|
|
|
2019-03-15 20:20:21 +01:00
|
|
|
#if (HAS_SENSORS)
|
2020-09-01 11:57:45 +02:00
|
|
|
#if (HAS_SENSOR_1)
|
2018-11-20 15:02:37 +01:00
|
|
|
case SENSOR1_DATA:
|
|
|
|
payload.reset();
|
|
|
|
payload.addSensor(sensor_read(1));
|
2019-02-03 14:12:21 +01:00
|
|
|
SendPayload(SENSOR1PORT, prio_normal);
|
2020-09-02 11:21:56 +02:00
|
|
|
#if (COUNT_ENS)
|
2020-09-01 11:57:45 +02:00
|
|
|
cwa_clear();
|
|
|
|
#endif
|
2018-11-20 15:02:37 +01:00
|
|
|
break;
|
2020-09-01 11:57:45 +02:00
|
|
|
#endif
|
|
|
|
#if (HAS_SENSOR_2)
|
2018-11-20 15:02:37 +01:00
|
|
|
case SENSOR2_DATA:
|
|
|
|
payload.reset();
|
|
|
|
payload.addSensor(sensor_read(2));
|
2019-02-03 14:12:21 +01:00
|
|
|
SendPayload(SENSOR2PORT, prio_normal);
|
2018-11-20 15:02:37 +01:00
|
|
|
break;
|
2020-09-01 11:57:45 +02:00
|
|
|
#endif
|
|
|
|
#if (HAS_SENSOR_3)
|
2018-11-20 15:02:37 +01:00
|
|
|
case SENSOR3_DATA:
|
|
|
|
payload.reset();
|
|
|
|
payload.addSensor(sensor_read(3));
|
2019-02-03 14:12:21 +01:00
|
|
|
SendPayload(SENSOR3PORT, prio_normal);
|
2018-11-19 00:41:15 +01:00
|
|
|
break;
|
2018-11-27 11:21:20 +01:00
|
|
|
#endif
|
2020-09-01 11:57:45 +02:00
|
|
|
#endif
|
2018-11-19 00:41:15 +01:00
|
|
|
|
2019-09-09 20:02:21 +02:00
|
|
|
#if (defined BAT_MEASURE_ADC || defined HAS_PMU)
|
2018-11-27 11:21:20 +01:00
|
|
|
case BATT_DATA:
|
2018-11-20 15:02:37 +01:00
|
|
|
payload.reset();
|
2018-11-27 11:21:20 +01:00
|
|
|
payload.addVoltage(read_voltage());
|
2019-02-03 14:12:21 +01:00
|
|
|
SendPayload(BATTPORT, prio_normal);
|
2018-11-20 15:02:37 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2018-11-19 00:41:15 +01:00
|
|
|
} // switch
|
|
|
|
bitmask &= ~mask;
|
|
|
|
mask <<= 1;
|
|
|
|
} // while (bitmask)
|
2018-11-18 16:45:33 +01:00
|
|
|
|
2019-08-30 18:54:53 +02:00
|
|
|
} // sendData()
|
2018-08-04 14:37:41 +02:00
|
|
|
|
2018-08-05 12:16:54 +02:00
|
|
|
void flushQueues() {
|
2019-03-15 20:20:21 +01:00
|
|
|
#if (HAS_LORA)
|
2018-11-03 20:29:02 +01:00
|
|
|
lora_queuereset();
|
2019-02-27 00:49:32 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAS_SPI
|
2018-09-11 16:15:39 +02:00
|
|
|
spi_queuereset();
|
2019-02-27 00:49:32 +01:00
|
|
|
#endif
|
2020-05-16 23:49:34 +02:00
|
|
|
#ifdef HAS_MQTT
|
|
|
|
mqtt_queuereset();
|
|
|
|
#endif
|
2020-01-22 15:49:07 +01:00
|
|
|
}
|