Merge branch 'master' into mapReport

This commit is contained in:
Thomas Göttgens 2024-03-10 20:54:48 +01:00 committed by GitHub
commit 70df36b5db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 9 deletions

View File

@ -7,9 +7,19 @@
PaxcounterModule *paxcounterModule; PaxcounterModule *paxcounterModule;
void NullFunc(){}; /**
* Callback function for libpax.
// paxcounterModule->sendInfo(NODENUM_BROADCAST); * 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.
LOG_INFO("PaxcounterModule: libpax reported new data: wifi=%d; ble=%d; uptime=%lu\n",
paxcounterModule->count_from_libpax.wifi_count, paxcounterModule->count_from_libpax.ble_count, millis() / 1000);
paxcounterModule->reportedDataSent = false;
paxcounterModule->setIntervalFromNow(0);
}
PaxcounterModule::PaxcounterModule() PaxcounterModule::PaxcounterModule()
: concurrency::OSThread("PaxcounterModule"), : concurrency::OSThread("PaxcounterModule"),
@ -17,11 +27,20 @@ PaxcounterModule::PaxcounterModule()
{ {
} }
/**
* 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
*/
bool PaxcounterModule::sendInfo(NodeNum dest) bool PaxcounterModule::sendInfo(NodeNum dest)
{ {
libpax_counter_count(&count_from_libpax); if (paxcounterModule->reportedDataSent)
LOG_INFO("(Sending): pax: wifi=%d; ble=%d; uptime=%d\n", count_from_libpax.wifi_count, count_from_libpax.ble_count, return false;
millis() / 1000);
LOG_INFO("PaxcounterModule: sending pax info wifi=%d; ble=%d; uptime=%lu\n", count_from_libpax.wifi_count,
count_from_libpax.ble_count, millis() / 1000);
meshtastic_Paxcount pl = meshtastic_Paxcount_init_default; meshtastic_Paxcount pl = meshtastic_Paxcount_init_default;
pl.wifi = count_from_libpax.wifi_count; pl.wifi = count_from_libpax.wifi_count;
@ -34,6 +53,9 @@ bool PaxcounterModule::sendInfo(NodeNum dest)
p->priority = meshtastic_MeshPacket_Priority_MIN; p->priority = meshtastic_MeshPacket_Priority_MIN;
service.sendToMesh(p, RX_SRC_LOCAL, true); service.sendToMesh(p, RX_SRC_LOCAL, true);
paxcounterModule->reportedDataSent = true;
return true; return true;
} }
@ -67,7 +89,7 @@ int32_t PaxcounterModule::runOnce()
libpax_default_config(&configuration); libpax_default_config(&configuration);
configuration.blecounter = 1; configuration.blecounter = 1;
configuration.blescantime = 0; // infinit configuration.blescantime = 0; // infinite
configuration.wificounter = 1; configuration.wificounter = 1;
configuration.wifi_channel_map = WIFI_CHANNEL_ALL; configuration.wifi_channel_map = WIFI_CHANNEL_ALL;
configuration.wifi_channel_switch_interval = 50; configuration.wifi_channel_switch_interval = 50;
@ -76,7 +98,8 @@ int32_t PaxcounterModule::runOnce()
libpax_update_config(&configuration); libpax_update_config(&configuration);
// internal processing initialization // internal processing initialization
libpax_counter_init(NullFunc, &count_from_libpax, UINT16_MAX, 1); libpax_counter_init(handlePaxCounterReportRequest, &count_from_libpax,
moduleConfig.paxcounter.paxcounter_update_interval, 0);
libpax_counter_start(); libpax_counter_start();
} else { } else {
sendInfo(NODENUM_BROADCAST); sendInfo(NODENUM_BROADCAST);

View File

@ -8,11 +8,15 @@
#include <libpax_api.h> #include <libpax_api.h>
/** /**
* A simple example module that just replies with "Message received" to any message it receives. * Wrapper module for the estimate passenger (PAX) count library (https://github.com/dbinfrago/libpax) which
* implements the core functionality of the ESP32 Paxcounter project (https://github.com/cyberman54/ESP32-Paxcounter)
*/ */
class PaxcounterModule : private concurrency::OSThread, public ProtobufModule<meshtastic_Paxcount> class PaxcounterModule : private concurrency::OSThread, public ProtobufModule<meshtastic_Paxcount>
{ {
bool firstTime = true; bool firstTime = true;
bool reportedDataSent = true;
static void handlePaxCounterReportRequest();
public: public:
PaxcounterModule(); PaxcounterModule();