Skip to content

Commit

Permalink
Merge branch 'master' into mapReport
Browse files Browse the repository at this point in the history
  • Loading branch information
caveman99 authored Mar 10, 2024
2 parents cb7407e + e33d014 commit 70df36b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
39 changes: 31 additions & 8 deletions src/modules/esp32/PaxcounterModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,40 @@

PaxcounterModule *paxcounterModule;

void NullFunc(){};

// paxcounterModule->sendInfo(NODENUM_BROADCAST);
/**
* 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.
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()
: concurrency::OSThread("PaxcounterModule"),
ProtobufModule("paxcounter", meshtastic_PortNum_PAXCOUNTER_APP, &meshtastic_Paxcount_msg)
{
}

/**
* 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)
{
libpax_counter_count(&count_from_libpax);
LOG_INFO("(Sending): pax: wifi=%d; ble=%d; uptime=%d\n", count_from_libpax.wifi_count, count_from_libpax.ble_count,
millis() / 1000);
if (paxcounterModule->reportedDataSent)
return false;

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;
pl.wifi = count_from_libpax.wifi_count;
Expand All @@ -34,6 +53,9 @@ bool PaxcounterModule::sendInfo(NodeNum dest)
p->priority = meshtastic_MeshPacket_Priority_MIN;

service.sendToMesh(p, RX_SRC_LOCAL, true);

paxcounterModule->reportedDataSent = true;

return true;
}

Expand Down Expand Up @@ -67,7 +89,7 @@ int32_t PaxcounterModule::runOnce()
libpax_default_config(&configuration);

configuration.blecounter = 1;
configuration.blescantime = 0; // infinit
configuration.blescantime = 0; // infinite
configuration.wificounter = 1;
configuration.wifi_channel_map = WIFI_CHANNEL_ALL;
configuration.wifi_channel_switch_interval = 50;
Expand All @@ -76,7 +98,8 @@ int32_t PaxcounterModule::runOnce()
libpax_update_config(&configuration);

// 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();
} else {
sendInfo(NODENUM_BROADCAST);
Expand Down
6 changes: 5 additions & 1 deletion src/modules/esp32/PaxcounterModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
#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>
{
bool firstTime = true;
bool reportedDataSent = true;

static void handlePaxCounterReportRequest();

public:
PaxcounterModule();
Expand Down

0 comments on commit 70df36b

Please sign in to comment.