2023-12-17 16:00:57 +01:00
|
|
|
#include "configuration.h"
|
2024-04-22 10:47:11 +02:00
|
|
|
#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_PAXCOUNTER
|
2024-03-17 08:18:30 -05:00
|
|
|
#include "Default.h"
|
2023-12-17 16:00:57 +01:00
|
|
|
#include "MeshService.h"
|
|
|
|
|
#include "PaxcounterModule.h"
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
PaxcounterModule *paxcounterModule;
|
|
|
|
|
|
2024-03-06 19:15:04 +01:00
|
|
|
/**
|
|
|
|
|
* Callback function for libpax.
|
|
|
|
|
* We only clear our sent flag here, since this function is called from another thread, so we
|
|
|
|
|
* cannot send to the mesh directly.
|
|
|
|
|
*/
|
|
|
|
|
void PaxcounterModule::handlePaxCounterReportRequest()
|
|
|
|
|
{
|
|
|
|
|
// The libpax library already updated our data structure, just before invoking this callback.
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("PaxcounterModule: libpax reported new data: wifi=%d; ble=%d; uptime=%lu",
|
2024-03-06 19:15:04 +01:00
|
|
|
paxcounterModule->count_from_libpax.wifi_count, paxcounterModule->count_from_libpax.ble_count, millis() / 1000);
|
|
|
|
|
paxcounterModule->reportedDataSent = false;
|
2024-03-08 23:48:56 +01:00
|
|
|
paxcounterModule->setIntervalFromNow(0);
|
2024-03-06 19:15:04 +01:00
|
|
|
}
|
2023-12-17 16:00:57 +01:00
|
|
|
|
|
|
|
|
PaxcounterModule::PaxcounterModule()
|
2024-11-04 12:16:25 -06:00
|
|
|
: concurrency::OSThread("Paxcounter"),
|
2023-12-17 16:10:26 +01:00
|
|
|
ProtobufModule("paxcounter", meshtastic_PortNum_PAXCOUNTER_APP, &meshtastic_Paxcount_msg)
|
2023-12-17 16:00:57 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 19:15:04 +01:00
|
|
|
/**
|
|
|
|
|
* Send the Pax information to the mesh if we got new data from libpax.
|
|
|
|
|
* This is called periodically from our runOnce() method and will actually send the data to the mesh
|
|
|
|
|
* if libpax updated it since the last transmission through the callback.
|
|
|
|
|
* @param dest - destination node (usually NODENUM_BROADCAST)
|
|
|
|
|
* @return false if sending is unnecessary, true if information was sent
|
|
|
|
|
*/
|
2023-12-17 16:00:57 +01:00
|
|
|
bool PaxcounterModule::sendInfo(NodeNum dest)
|
|
|
|
|
{
|
2024-03-05 23:39:43 +01:00
|
|
|
if (paxcounterModule->reportedDataSent)
|
|
|
|
|
return false;
|
|
|
|
|
|
2024-11-04 19:15:59 -06:00
|
|
|
LOG_INFO("PaxcounterModule: send pax info wifi=%d; ble=%d; uptime=%lu", count_from_libpax.wifi_count,
|
2024-03-06 19:15:04 +01:00
|
|
|
count_from_libpax.ble_count, millis() / 1000);
|
2024-03-05 23:39:43 +01:00
|
|
|
|
2023-12-17 16:00:57 +01:00
|
|
|
meshtastic_Paxcount pl = meshtastic_Paxcount_init_default;
|
|
|
|
|
pl.wifi = count_from_libpax.wifi_count;
|
|
|
|
|
pl.ble = count_from_libpax.ble_count;
|
|
|
|
|
pl.uptime = millis() / 1000;
|
|
|
|
|
|
|
|
|
|
meshtastic_MeshPacket *p = allocDataProtobuf(pl);
|
|
|
|
|
p->to = dest;
|
|
|
|
|
p->decoded.want_response = false;
|
2024-03-12 18:21:09 +01:00
|
|
|
p->priority = meshtastic_MeshPacket_Priority_BACKGROUND;
|
2023-12-17 16:00:57 +01:00
|
|
|
|
2024-08-01 19:29:49 -05:00
|
|
|
service->sendToMesh(p, RX_SRC_LOCAL, true);
|
2024-03-06 19:15:04 +01:00
|
|
|
|
|
|
|
|
paxcounterModule->reportedDataSent = true;
|
|
|
|
|
|
2023-12-17 16:00:57 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PaxcounterModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Paxcount *p)
|
|
|
|
|
{
|
|
|
|
|
return false; // Let others look at this message also if they want. We don't do anything with received packets.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
meshtastic_MeshPacket *PaxcounterModule::allocReply()
|
|
|
|
|
{
|
|
|
|
|
meshtastic_Paxcount pl = meshtastic_Paxcount_init_default;
|
|
|
|
|
pl.wifi = count_from_libpax.wifi_count;
|
|
|
|
|
pl.ble = count_from_libpax.ble_count;
|
|
|
|
|
pl.uptime = millis() / 1000;
|
|
|
|
|
return allocDataProtobuf(pl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t PaxcounterModule::runOnce()
|
|
|
|
|
{
|
2024-02-25 20:03:54 +01:00
|
|
|
if (isActive()) {
|
2023-12-17 16:00:57 +01:00
|
|
|
if (firstTime) {
|
|
|
|
|
firstTime = false;
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_DEBUG("Paxcounter starting up with interval of %d seconds",
|
2024-03-17 08:18:30 -05:00
|
|
|
Default::getConfiguredOrDefault(moduleConfig.paxcounter.paxcounter_update_interval,
|
2024-07-14 06:27:16 -05:00
|
|
|
default_telemetry_broadcast_interval_secs));
|
2023-12-17 16:00:57 +01:00
|
|
|
struct libpax_config_t configuration;
|
|
|
|
|
libpax_default_config(&configuration);
|
|
|
|
|
|
|
|
|
|
configuration.blecounter = 1;
|
2024-03-05 23:48:52 +01:00
|
|
|
configuration.blescantime = 0; // infinite
|
2023-12-17 16:00:57 +01:00
|
|
|
configuration.wificounter = 1;
|
|
|
|
|
configuration.wifi_channel_map = WIFI_CHANNEL_ALL;
|
|
|
|
|
configuration.wifi_channel_switch_interval = 50;
|
2024-05-16 15:52:22 +02:00
|
|
|
configuration.wifi_rssi_threshold = Default::getConfiguredOrDefault(moduleConfig.paxcounter.wifi_threshold, -80);
|
|
|
|
|
configuration.ble_rssi_threshold = Default::getConfiguredOrDefault(moduleConfig.paxcounter.ble_threshold, -80);
|
2023-12-17 16:00:57 +01:00
|
|
|
libpax_update_config(&configuration);
|
|
|
|
|
|
|
|
|
|
// internal processing initialization
|
2024-03-05 23:39:43 +01:00
|
|
|
libpax_counter_init(handlePaxCounterReportRequest, &count_from_libpax,
|
2024-11-24 14:28:36 +01:00
|
|
|
Default::getConfiguredOrDefault(moduleConfig.paxcounter.paxcounter_update_interval,
|
|
|
|
|
default_telemetry_broadcast_interval_secs),
|
|
|
|
|
0);
|
2023-12-17 16:00:57 +01:00
|
|
|
libpax_counter_start();
|
|
|
|
|
} else {
|
|
|
|
|
sendInfo(NODENUM_BROADCAST);
|
|
|
|
|
}
|
2024-07-13 05:59:19 -05:00
|
|
|
return Default::getConfiguredOrDefaultMsScaled(moduleConfig.paxcounter.paxcounter_update_interval,
|
|
|
|
|
default_telemetry_broadcast_interval_secs, numOnlineNodes);
|
2023-12-17 16:00:57 +01:00
|
|
|
} else {
|
|
|
|
|
return disable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-25 20:03:54 +01:00
|
|
|
#if HAS_SCREEN
|
|
|
|
|
|
2024-02-27 19:49:46 +01:00
|
|
|
#include "graphics/ScreenFonts.h"
|
2024-02-25 20:03:54 +01:00
|
|
|
|
|
|
|
|
void PaxcounterModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
|
|
|
|
{
|
|
|
|
|
char buffer[50];
|
|
|
|
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
|
|
|
|
display->setFont(FONT_SMALL);
|
|
|
|
|
display->drawString(x + 0, y + 0, "PAX");
|
|
|
|
|
|
|
|
|
|
libpax_counter_count(&count_from_libpax);
|
|
|
|
|
|
|
|
|
|
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
|
|
|
|
display->setFont(FONT_SMALL);
|
|
|
|
|
display->drawStringf(display->getWidth() / 2 + x, 0 + y + 12, buffer, "WiFi: %d\nBLE: %d\nuptime: %ds",
|
|
|
|
|
count_from_libpax.wifi_count, count_from_libpax.ble_count, millis() / 1000);
|
|
|
|
|
}
|
|
|
|
|
#endif // HAS_SCREEN
|
|
|
|
|
|
2024-06-23 14:13:59 +02:00
|
|
|
#endif
|