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
|
|
|
|
2018-08-03 23:50:04 +02:00
|
|
|
// put data to send in RTos Queues used for transmit over channels Lora and SPI
|
2018-11-18 15:50:57 +01:00
|
|
|
void SendPayload(uint8_t port) {
|
2018-08-04 14:37:41 +02:00
|
|
|
|
2018-11-18 12:09:18 +01:00
|
|
|
MessageBuffer_t SendBuffer; // contains MessageSize, MessagePort, Message[]
|
2018-08-10 16:33:47 +02:00
|
|
|
|
2018-08-07 21:10:34 +02:00
|
|
|
SendBuffer.MessageSize = payload.getSize();
|
2018-11-25 23:39:12 +01:00
|
|
|
switch (PAYLOAD_ENCODER) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
SendBuffer.MessagePort = port;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
SendBuffer.MessagePort = LPP1PORT;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
SendBuffer.MessagePort = LPP2PORT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SendBuffer.MessagePort = port;
|
|
|
|
}
|
2018-08-07 21:10:34 +02:00
|
|
|
memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize());
|
2018-08-04 14:37:41 +02:00
|
|
|
|
2018-11-03 20:29:02 +01:00
|
|
|
// enqueue message in device's send queues
|
2018-11-17 22:49:14 +01:00
|
|
|
lora_enqueuedata(&SendBuffer);
|
|
|
|
spi_enqueuedata(&SendBuffer);
|
2018-08-04 14:37:41 +02:00
|
|
|
|
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
|
2018-11-18 15:50:57 +01:00
|
|
|
void sendCounter() {
|
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;
|
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
|
|
|
|
2018-11-19 00:41:15 +01:00
|
|
|
case COUNT_DATA:
|
2018-11-20 15:02:37 +01:00
|
|
|
payload.reset();
|
2018-12-02 14:08:50 +01:00
|
|
|
payload.addCount(macs_wifi, MAC_SNIFF_WIFI);
|
|
|
|
if (cfg.blescan)
|
|
|
|
payload.addCount(macs_ble, MAC_SNIFF_BLE);
|
2018-12-28 20:23:17 +01:00
|
|
|
|
|
|
|
#ifdef HAS_GPS
|
|
|
|
if (gps.location.isValid()) { // send GPS position only if we have a fix
|
|
|
|
gps_read();
|
|
|
|
payload.addGPS(gps_status);
|
|
|
|
} else {
|
|
|
|
ESP_LOGD(
|
|
|
|
TAG,
|
|
|
|
"No valid GPS position. GPS data not appended to counter data.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-19 00:41:15 +01:00
|
|
|
SendPayload(COUNTERPORT);
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-11-18 16:45:33 +01:00
|
|
|
#ifdef 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);
|
|
|
|
SendPayload(BMEPORT);
|
|
|
|
break;
|
2018-11-20 15:02:37 +01:00
|
|
|
#endif
|
2018-11-19 00:41:15 +01:00
|
|
|
|
|
|
|
#ifdef HAS_GPS
|
2018-11-20 15:02:37 +01:00
|
|
|
case GPS_DATA:
|
2018-11-19 00:41:15 +01:00
|
|
|
// send GPS position only if we have a fix
|
|
|
|
if (gps.location.isValid()) {
|
|
|
|
gps_read();
|
2018-11-20 15:02:37 +01:00
|
|
|
payload.reset();
|
2018-11-19 00:41:15 +01:00
|
|
|
payload.addGPS(gps_status);
|
|
|
|
SendPayload(GPSPORT);
|
|
|
|
} 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
|
|
|
|
|
|
|
#ifdef HAS_SENSORS
|
|
|
|
case SENSOR1_DATA:
|
|
|
|
payload.reset();
|
|
|
|
payload.addSensor(sensor_read(1));
|
|
|
|
SendPayload(SENSOR1PORT);
|
|
|
|
break;
|
|
|
|
case SENSOR2_DATA:
|
|
|
|
payload.reset();
|
|
|
|
payload.addSensor(sensor_read(2));
|
|
|
|
SendPayload(SENSOR2PORT);
|
|
|
|
break;
|
|
|
|
case SENSOR3_DATA:
|
|
|
|
payload.reset();
|
|
|
|
payload.addSensor(sensor_read(3));
|
|
|
|
SendPayload(SENSOR3PORT);
|
2018-11-19 00:41:15 +01:00
|
|
|
break;
|
2018-11-27 11:21:20 +01:00
|
|
|
#endif
|
2018-11-19 00:41:15 +01:00
|
|
|
|
2018-11-27 11:21:20 +01:00
|
|
|
#ifdef HAS_BATTERY_PROBE
|
|
|
|
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());
|
|
|
|
SendPayload(BATTPORT);
|
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
|
|
|
|
2018-11-18 15:50:57 +01:00
|
|
|
} // sendCounter()
|
2018-08-04 14:37:41 +02:00
|
|
|
|
2018-08-05 12:16:54 +02:00
|
|
|
void flushQueues() {
|
2018-11-03 20:29:02 +01:00
|
|
|
lora_queuereset();
|
2018-09-11 16:15:39 +02:00
|
|
|
spi_queuereset();
|
2018-08-05 12:16:54 +02:00
|
|
|
}
|