ESP32-PaxCounter/src/senddata.cpp

74 lines
2.3 KiB
C++
Raw Normal View History

2018-07-14 19:12:20 +02:00
// Basic Config
#include "globals.h"
void senddata(uint8_t port) {
#ifdef HAS_LORA
// Check if there is a pending TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
2018-07-14 20:07:33 +02:00
ESP_LOGI(TAG, "LoRa busy, data not sent");
sprintf(display_line7, "LORA BUSY");
2018-07-14 19:12:20 +02:00
} else {
2018-07-22 18:13:21 +02:00
LMIC_setTxData2(
PAYLOAD_ENCODER <= 2 ? port
: (PAYLOAD_ENCODER == 4 ? LPP2PORT : LPP1PORT),
payload.getBuffer(), payload.getSize(), (cfg.countermode & 0x02));
2018-07-21 13:36:49 +02:00
2018-07-14 19:12:20 +02:00
ESP_LOGI(TAG, "%d bytes queued to send on LoRa", payload.getSize());
2018-07-14 20:07:33 +02:00
sprintf(display_line7, "PACKET QUEUED");
2018-07-14 19:12:20 +02:00
}
#endif
#ifdef HAS_SPI
2018-07-14 23:58:41 +02:00
// to come here: code for sending payload to a local master via SPI
2018-07-14 20:07:33 +02:00
ESP_LOGI(TAG, "%d bytes sent on SPI", payload.getSize());
2018-07-14 19:12:20 +02:00
#endif
// clear counter if not in cumulative counter mode
2018-07-21 18:25:03 +02:00
if ((port == COUNTERPORT) && (cfg.countermode != 1)) {
2018-07-14 19:12:20 +02:00
reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes
2018-07-21 18:25:03 +02:00
ESP_LOGI(TAG, "Counter cleared");
2018-07-14 19:12:20 +02:00
}
2018-07-22 20:27:58 +02:00
} // senddata
void sendPayload() {
if (SendCycleTimerIRQ) {
portENTER_CRITICAL(&timerMux);
SendCycleTimerIRQ = 0;
portEXIT_CRITICAL(&timerMux);
// append counter data to payload
payload.reset();
payload.addCount(macs_wifi, cfg.blescan ? macs_ble : 0);
// append GPS data, if present
#ifdef HAS_GPS
// 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");
}
#endif
senddata(COUNTERPORT);
}
2018-07-23 08:25:23 +02:00
} // sendpayload();
void IRAM_ATTR SendCycleIRQ() {
portENTER_CRITICAL(&timerMux);
SendCycleTimerIRQ++;
portEXIT_CRITICAL(&timerMux);
}