ESP32-PaxCounter/src/senddata.cpp

67 lines
2.1 KiB
C++
Raw Normal View History

2018-07-14 19:12:20 +02:00
// Basic Config
#include "globals.h"
#include "spislave.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-08-04 15:27:58 +02:00
void SendData(uint8_t port) {
2018-08-04 14:37:41 +02:00
MessageBuffer_t SendBuffer;
SendBuffer.MessageSize = payload.getSize();
SendBuffer.MessagePort = PAYLOAD_ENCODER <= 2
2018-08-11 19:31:42 +02:00
? port
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT);
memcpy(SendBuffer.Message, payload.getBuffer(), payload.getSize());
2018-08-04 14:37:41 +02:00
// enqueue message in LoRa send queue
#ifdef HAS_LORA
if (xQueueSendToBack(LoraSendQueue, (void *)&SendBuffer, (TickType_t)0) ==
pdTRUE)
2018-08-04 15:27:58 +02:00
ESP_LOGI(TAG, "%d bytes enqueued to send on LoRa", payload.getSize());
2018-08-04 14:37:41 +02:00
#endif
spi_enqueuedata(port, &SendBuffer);
2018-08-04 14:37:41 +02:00
// clear counter if not in cumulative counter mode
if ((port == COUNTERPORT) && (cfg.countermode != 1)) {
reset_counters(); // clear macs container and reset all counters
2018-09-23 22:12:10 +02:00
get_salt(); // get new salt for salting hashes
2018-08-04 14:37:41 +02:00
ESP_LOGI(TAG, "Counter cleared");
}
2018-08-04 15:27:58 +02:00
} // SendData
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-08-04 14:37:41 +02:00
void sendPayload() {
2018-09-21 18:23:34 +02:00
// append counter data to payload
payload.reset();
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0);
// append GPS data, if present
2018-08-04 14:37:41 +02:00
#ifdef HAS_GPS
2018-09-21 18:23:34 +02:00
// show NMEA data in debug mode, useful for debugging GPS on board
// connection
ESP_LOGD(TAG, "GPS NMEA data: passed %d / failed: %d / with fix: %d",
gps.passedChecksum(), gps.failedChecksum(), gps.sentencesWithFix());
// log GPS position if we have a fix and gps data mode is enabled
if ((cfg.gpsmode) && (gps.location.isValid())) {
gps_read();
payload.addGPS(gps_status);
ESP_LOGD(TAG, "lat=%.6f | lon=%.6f | %u Sats | HDOP=%.1f | Altitude=%um",
gps_status.latitude / (float)1e6,
gps_status.longitude / (float)1e6, gps_status.satellites,
gps_status.hdop / (float)100, gps_status.altitude);
} else {
ESP_LOGD(TAG, "No valid GPS position or GPS data mode disabled");
2018-08-04 14:37:41 +02:00
}
2018-09-21 18:23:34 +02:00
#endif
SendData(COUNTERPORT);
2018-08-04 14:37:41 +02:00
} // sendpayload()
2018-08-05 12:16:54 +02:00
void flushQueues() {
2018-08-03 23:50:04 +02:00
#ifdef HAS_LORA
2018-08-08 00:05:38 +02:00
xQueueReset(LoraSendQueue);
2018-08-03 23:50:04 +02:00
#endif
spi_queuereset();
2018-08-05 12:16:54 +02:00
}