mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-23 09:06:02 +00:00
Include Libpax - WIP
This commit is contained in:
parent
f1b380882d
commit
add78a459b
@ -31,6 +31,9 @@ build_flags =
|
||||
-DCONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=5120
|
||||
-DESP_OPENSSL_SUPPRESS_LEGACY_WARNING
|
||||
-DSERIAL_BUFFER_SIZE=4096
|
||||
-DLIBPAX_ARDUINO
|
||||
-DLIBPAX_WIFI
|
||||
-DLIBPAX_BLE
|
||||
;-DDEBUG_HEAP
|
||||
|
||||
lib_deps =
|
||||
@ -39,6 +42,7 @@ lib_deps =
|
||||
${environmental_base.lib_deps}
|
||||
https://github.com/meshtastic/esp32_https_server.git#23665b3adc080a311dcbb586ed5941b5f94d6ea2
|
||||
h2zero/NimBLE-Arduino@^1.4.1
|
||||
https://github.com/dbSuS/libpax.git#7bcd3fcab75037505be9b122ab2b24cc5176b587
|
||||
https://github.com/lewisxhe/XPowersLib.git#84b7373faea3118b6c37954d52f98b8a337148d6
|
||||
https://github.com/meshtastic/ESP32_Codec2.git#633326c78ac251c059ab3a8c430fcdf25b41672f
|
||||
|
||||
|
@ -31,7 +31,10 @@
|
||||
#include "modules/Telemetry/PowerTelemetry.h"
|
||||
#endif
|
||||
#ifdef ARCH_ESP32
|
||||
#ifdef USE_SX1280
|
||||
#include "modules/esp32/AudioModule.h"
|
||||
#endif
|
||||
#include "modules/esp32/PaxcounterModule.h"
|
||||
#include "modules/esp32/StoreForwardModule.h"
|
||||
#endif
|
||||
#if defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_RP2040)
|
||||
@ -111,9 +114,11 @@ void setupModules()
|
||||
#endif
|
||||
#ifdef ARCH_ESP32
|
||||
// Only run on an esp32 based device.
|
||||
#ifdef USE_SX1280
|
||||
audioModule = new AudioModule();
|
||||
|
||||
#endif
|
||||
storeForwardModule = new StoreForwardModule();
|
||||
paxcounterModule = new PaxcounterModule();
|
||||
#endif
|
||||
#if defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_RP2040)
|
||||
externalNotificationModule = new ExternalNotificationModule();
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
#include "configuration.h"
|
||||
#if defined(ARCH_ESP32)
|
||||
#if defined(ARCH_ESP32) && defined(USE_SX1280)
|
||||
#include "AudioModule.h"
|
||||
#include "FSCommon.h"
|
||||
#include "MeshService.h"
|
||||
@ -145,7 +145,7 @@ AudioModule::AudioModule() : SinglePortModule("AudioModule", meshtastic_PortNum_
|
||||
encode_frame_num = (meshtastic_Constants_DATA_PAYLOAD_LEN - sizeof(tx_header)) / encode_codec_size;
|
||||
encode_frame_size = encode_frame_num * encode_codec_size; // max 233 bytes + 4 header bytes
|
||||
adc_buffer_size = codec2_samples_per_frame(codec2);
|
||||
LOG_INFO(" using %d frames of %d bytes for a total payload length of %d bytes\n", encode_frame_num, encode_codec_size,
|
||||
LOG_INFO("using %d frames of %d bytes for a total payload length of %d bytes\n", encode_frame_num, encode_codec_size,
|
||||
encode_frame_size);
|
||||
xTaskCreate(&run_codec2, "codec2_task", 30000, NULL, 5, &codec2HandlerTask);
|
||||
} else {
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "SinglePortModule.h"
|
||||
#include "concurrency/NotifiedWorkerThread.h"
|
||||
#include "configuration.h"
|
||||
#if defined(ARCH_ESP32)
|
||||
#if defined(ARCH_ESP32) && defined(USE_SX1280)
|
||||
#include "NodeDB.h"
|
||||
#include <Arduino.h>
|
||||
#include <ButterworthFilter.h>
|
||||
|
91
src/modules/esp32/PaxcounterModule.cpp
Normal file
91
src/modules/esp32/PaxcounterModule.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
#include "configuration.h"
|
||||
#if defined(ARCH_ESP32)
|
||||
#include "MeshService.h"
|
||||
#include "PaxcounterModule.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
PaxcounterModule *paxcounterModule;
|
||||
|
||||
void NullFunc(){};
|
||||
|
||||
// paxcounterModule->sendInfo(NODENUM_BROADCAST);
|
||||
|
||||
PaxcounterModule::PaxcounterModule()
|
||||
: concurrency::OSThread("PaxcounterModule"),
|
||||
ProtobufModule("paxcounter", meshtastic_PortNum_PAXCOUNTER_APP, &meshtastic_Paxcount_msg),
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
p->priority = meshtastic_MeshPacket_Priority_MIN;
|
||||
|
||||
service.sendToMesh(p, RX_SRC_LOCAL, true);
|
||||
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()
|
||||
{
|
||||
if (ignoreRequest) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
if (moduleConfig.paxcounter.enabled && !config.bluetooth.enabled && !config.network.wifi_enabled) {
|
||||
if (firstTime) {
|
||||
firstTime = false;
|
||||
LOG_DEBUG(
|
||||
"Paxcounter starting up with interval of %d seconds\n",
|
||||
getConfiguredOrDefault(moduleConfig.paxcounter.paxcounter_update_interval, default_broadcast_interval_secs));
|
||||
struct libpax_config_t configuration;
|
||||
libpax_default_config(&configuration);
|
||||
|
||||
configuration.blecounter = 1;
|
||||
configuration.blescantime = 0; // infinit
|
||||
configuration.wificounter = 1;
|
||||
configuration.wifi_channel_map = WIFI_CHANNEL_ALL;
|
||||
configuration.wifi_channel_switch_interval = 50;
|
||||
configuration.wifi_rssi_threshold = -80;
|
||||
configuration.ble_rssi_threshold = -80;
|
||||
libpax_update_config(&configuration);
|
||||
|
||||
// internal processing initialization
|
||||
libpax_counter_init(NullFunc, &count_from_libpax, UINT16_MAX, 1);
|
||||
libpax_counter_start();
|
||||
} else {
|
||||
sendInfo(NODENUM_BROADCAST);
|
||||
}
|
||||
return getConfiguredOrDefaultMs(moduleConfig.paxcounter.paxcounter_update_interval, default_broadcast_interval_secs);
|
||||
} else {
|
||||
return disable();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
29
src/modules/esp32/PaxcounterModule.h
Normal file
29
src/modules/esp32/PaxcounterModule.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "ProtobufModule.h"
|
||||
#include "configuration.h"
|
||||
#if defined(ARCH_ESP32)
|
||||
#include "../mesh/generated/meshtastic/paxcount.pb.h"
|
||||
#include "NodeDB.h"
|
||||
#include <libpax_api.h>
|
||||
|
||||
/**
|
||||
* A simple example module that just replies with "Message received" to any message it receives.
|
||||
*/
|
||||
class PaxcounterModule : private concurrency::OSThread, public ProtobufModule<meshtastic_Paxcount>
|
||||
{
|
||||
bool firstTime = true;
|
||||
|
||||
public:
|
||||
PaxcounterModule();
|
||||
|
||||
protected:
|
||||
struct count_payload_t count_from_libpax;
|
||||
virtual int32_t runOnce() override;
|
||||
bool sendInfo(NodeNum dest = NODENUM_BROADCAST);
|
||||
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Paxcount *p) override;
|
||||
virtual meshtastic_MeshPacket *allocReply() override;
|
||||
};
|
||||
|
||||
extern PaxcounterModule *paxcounterModule;
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user