Merge pull request #2272 from GUVWAF/portduinoDeviceTelemetry

Enable DeviceTelemetry on Portduino
This commit is contained in:
GUVWAF 2023-02-11 15:21:24 +01:00 committed by GitHub
commit 40d98b9d8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 49 additions and 42 deletions

View File

@ -12,7 +12,9 @@ build_src_filter =
-<mesh/http/> -<mesh/http/>
-<mesh/eth/> -<mesh/eth/>
-<modules/esp32> -<modules/esp32>
-<modules/Telemetry> -<modules/Telemetry/EnvironmentTelemetry.cpp>
-<modules/Telemetry/AirQualityTelemetry.cpp>
-<modules/Telemetry/Sensor>
+<../variants/portduino> +<../variants/portduino>
lib_deps = lib_deps =
${env.lib_deps} ${env.lib_deps}

View File

@ -103,7 +103,7 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...)
} }
r += vprintf(format, arg); r += vprintf(format, arg);
#if HAS_WIFI || HAS_ETHERNET #if (HAS_WIFI || HAS_ETHERNET) && !defined(ARCH_PORTDUINO)
// if syslog is in use, collect the log messages and send them to syslog // if syslog is in use, collect the log messages and send them to syslog
if (syslog.isEnabled()) { if (syslog.isEnabled()) {
int ll = 0; int ll = 0;

View File

@ -394,6 +394,19 @@ void setup()
// radio init MUST BE AFTER service.init, so we have our radio config settings (from nodedb init) // radio init MUST BE AFTER service.init, so we have our radio config settings (from nodedb init)
#if !HAS_RADIO && defined(ARCH_PORTDUINO)
if (!rIf) {
rIf = new SimRadio;
if (!rIf->init()) {
LOG_WARN("Failed to find simulated radio\n");
delete rIf;
rIf = NULL;
} else {
LOG_INFO("Using SIMULATED radio!\n");
}
}
#endif
#if defined(RF95_IRQ) #if defined(RF95_IRQ)
if (!rIf) { if (!rIf) {
rIf = new RF95Interface(RF95_NSS, RF95_IRQ, RF95_RESET, SPI); rIf = new RF95Interface(RF95_NSS, RF95_IRQ, RF95_RESET, SPI);
@ -459,19 +472,6 @@ void setup()
} }
#endif #endif
#ifdef ARCH_PORTDUINO
if (!rIf) {
rIf = new SimRadio;
if (!rIf->init()) {
LOG_WARN("Failed to find simulated radio\n");
delete rIf;
rIf = NULL;
} else {
LOG_INFO("Using SIMULATED radio!\n");
}
}
#endif
// check if the radio chip matches the selected region // check if the radio chip matches the selected region
if ((config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24) && (!rIf->wideLora())) { if ((config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24) && (!rIf->wideLora())) {

View File

@ -132,7 +132,7 @@ void MeshService::reloadOwner(bool shouldSave)
*/ */
void MeshService::handleToRadio(meshtastic_MeshPacket &p) void MeshService::handleToRadio(meshtastic_MeshPacket &p)
{ {
#ifdef ARCH_PORTDUINO #if defined(ARCH_PORTDUINO) && !HAS_RADIO
// Simulates device is receiving a packet via the LoRa chip // Simulates device is receiving a packet via the LoRa chip
if (p.decoded.portnum == meshtastic_PortNum_SIMULATOR_APP) { if (p.decoded.portnum == meshtastic_PortNum_SIMULATOR_APP) {
// Simulator packet (=Compressed packet) is encapsulated in a MeshPacket, so need to unwrap first // Simulator packet (=Compressed packet) is encapsulated in a MeshPacket, so need to unwrap first

View File

@ -10,7 +10,7 @@
#include "MeshTypes.h" #include "MeshTypes.h"
#include "Observer.h" #include "Observer.h"
#include "PointerQueue.h" #include "PointerQueue.h"
#ifdef ARCH_PORTDUINO #if defined(ARCH_PORTDUINO) && !HAS_RADIO
#include "../platform/portduino/SimRadio.h" #include "../platform/portduino/SimRadio.h"
#endif #endif

View File

@ -14,8 +14,10 @@
#include "modules/TraceRouteModule.h" #include "modules/TraceRouteModule.h"
#include "modules/WaypointModule.h" #include "modules/WaypointModule.h"
#if HAS_TELEMETRY #if HAS_TELEMETRY
#include "modules/Telemetry/AirQualityTelemetry.h"
#include "modules/Telemetry/DeviceTelemetry.h" #include "modules/Telemetry/DeviceTelemetry.h"
#endif
#if HAS_SENSOR
#include "modules/Telemetry/AirQualityTelemetry.h"
#include "modules/Telemetry/EnvironmentTelemetry.h" #include "modules/Telemetry/EnvironmentTelemetry.h"
#endif #endif
#ifdef ARCH_ESP32 #ifdef ARCH_ESP32
@ -63,6 +65,8 @@ void setupModules()
#endif #endif
#if HAS_TELEMETRY #if HAS_TELEMETRY
new DeviceTelemetryModule(); new DeviceTelemetryModule();
#endif
#if HAS_SENSOR
new EnvironmentTelemetryModule(); new EnvironmentTelemetryModule();
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I] > 0) { if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I] > 0) {
new AirQualityTelemetryModule(); new AirQualityTelemetryModule();

View File

@ -10,7 +10,6 @@
int32_t AirQualityTelemetryModule::runOnce() int32_t AirQualityTelemetryModule::runOnce()
{ {
#ifndef ARCH_PORTDUINO
int32_t result = INT32_MAX; int32_t result = INT32_MAX;
/* /*
Uncomment the preferences below if you want to use the module Uncomment the preferences below if you want to use the module
@ -55,7 +54,6 @@ int32_t AirQualityTelemetryModule::runOnce()
} }
} }
return sendToPhoneIntervalMs; return sendToPhoneIntervalMs;
#endif
} }
bool AirQualityTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) bool AirQualityTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t)

View File

@ -52,7 +52,6 @@ SHT31Sensor sht31Sensor;
int32_t EnvironmentTelemetryModule::runOnce() int32_t EnvironmentTelemetryModule::runOnce()
{ {
#ifndef ARCH_PORTDUINO
int32_t result = INT32_MAX; int32_t result = INT32_MAX;
/* /*
Uncomment the preferences below if you want to use the module Uncomment the preferences below if you want to use the module
@ -115,7 +114,6 @@ int32_t EnvironmentTelemetryModule::runOnce()
} }
} }
return sendToPhoneIntervalMs; return sendToPhoneIntervalMs;
#endif
} }
bool EnvironmentTelemetryModule::wantUIFrame() bool EnvironmentTelemetryModule::wantUIFrame()

View File

@ -27,6 +27,9 @@
#ifndef HAS_TELEMETRY #ifndef HAS_TELEMETRY
#define HAS_TELEMETRY 1 #define HAS_TELEMETRY 1
#endif #endif
#ifndef HAS_SENSOR
#define HAS_SENSOR 1
#endif
#ifndef HAS_RADIO #ifndef HAS_RADIO
#define HAS_RADIO 1 #define HAS_RADIO 1
#endif #endif

View File

@ -23,6 +23,9 @@
#ifndef HAS_TELEMETRY #ifndef HAS_TELEMETRY
#define HAS_TELEMETRY 1 #define HAS_TELEMETRY 1
#endif #endif
#ifndef HAS_SENSOR
#define HAS_SENSOR 1
#endif
#ifndef HAS_RADIO #ifndef HAS_RADIO
#define HAS_RADIO 1 #define HAS_RADIO 1
#endif #endif

View File

@ -2,7 +2,7 @@
#include "MeshService.h" #include "MeshService.h"
#include "Router.h" #include "Router.h"
SimRadio::SimRadio() SimRadio::SimRadio() : NotifiedWorkerThread("SimRadio")
{ {
instance = this; instance = this;
} }
@ -53,10 +53,7 @@ void SimRadio::startTransmitTimer(bool withDelay)
if (!txQueue.empty()) { if (!txQueue.empty()) {
uint32_t delayMsec = !withDelay ? 1 : getTxDelayMsec(); uint32_t delayMsec = !withDelay ? 1 : getTxDelayMsec();
// LOG_DEBUG("xmit timer %d\n", delay); // LOG_DEBUG("xmit timer %d\n", delay);
delay(delayMsec); notifyLater(delayMsec, TRANSMIT_DELAY_COMPLETED, false);
onNotify(TRANSMIT_DELAY_COMPLETED);
} else {
LOG_DEBUG("TX QUEUE EMPTY!\n");
} }
} }
@ -66,8 +63,7 @@ void SimRadio::startTransmitTimerSNR(float snr)
if (!txQueue.empty()) { if (!txQueue.empty()) {
uint32_t delayMsec = getTxDelayMsecWeighted(snr); uint32_t delayMsec = getTxDelayMsecWeighted(snr);
// LOG_DEBUG("xmit timer %d\n", delay); // LOG_DEBUG("xmit timer %d\n", delay);
delay(delayMsec); notifyLater(delayMsec, TRANSMIT_DELAY_COMPLETED, false);
onNotify(TRANSMIT_DELAY_COMPLETED);
} }
} }
@ -142,11 +138,12 @@ void SimRadio::onNotify(uint32_t notification)
switch (notification) { switch (notification) {
case ISR_TX: case ISR_TX:
handleTransmitInterrupt(); handleTransmitInterrupt();
LOG_DEBUG("tx complete - starting timer\n"); // LOG_DEBUG("tx complete - starting timer\n");
startTransmitTimer(); startTransmitTimer();
break; break;
case ISR_RX: case ISR_RX:
LOG_DEBUG("rx complete - starting timer\n"); // LOG_DEBUG("rx complete - starting timer\n");
startTransmitTimer();
break; break;
case TRANSMIT_DELAY_COMPLETED: case TRANSMIT_DELAY_COMPLETED:
LOG_DEBUG("delay done\n"); LOG_DEBUG("delay done\n");
@ -170,8 +167,7 @@ void SimRadio::onNotify(uint32_t notification)
uint32_t xmitMsec = getPacketTime(txp); uint32_t xmitMsec = getPacketTime(txp);
airTime->logAirtime(TX_LOG, xmitMsec); airTime->logAirtime(TX_LOG, xmitMsec);
delay(xmitMsec); // Model the time it is busy sending notifyLater(xmitMsec, ISR_TX, false); // Model the time it is busy sending
completeSending();
} }
} }
} else { } else {
@ -242,8 +238,7 @@ void SimRadio::handleReceiveInterrupt(meshtastic_MeshPacket *p)
xmitMsec = getPacketTime(length); xmitMsec = getPacketTime(length);
// LOG_DEBUG("Payload size %d vs length (includes header) %d\n", p->decoded.payload.size, length); // LOG_DEBUG("Payload size %d vs length (includes header) %d\n", p->decoded.payload.size, length);
meshtastic_MeshPacket *mp = packetPool.allocCopy(*p); // keep a copy in packtPool meshtastic_MeshPacket *mp = packetPool.allocCopy(*p); // keep a copy in packetPool
mp->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // Mark that the payload is already decoded
printPacket("Lora RX", mp); printPacket("Lora RX", mp);

View File

@ -3,10 +3,11 @@
#include "MeshPacketQueue.h" #include "MeshPacketQueue.h"
#include "RadioInterface.h" #include "RadioInterface.h"
#include "api/WiFiServerAPI.h" #include "api/WiFiServerAPI.h"
#include "concurrency/NotifiedWorkerThread.h"
#include <RadioLib.h> #include <RadioLib.h>
class SimRadio : public RadioInterface class SimRadio : public RadioInterface, protected concurrency::NotifiedWorkerThread
{ {
enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED }; enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED };

View File

@ -2,15 +2,18 @@
#define ARCH_PORTDUINO #define ARCH_PORTDUINO
//
// defaults for NRF52 architecture
//
// //
// set HW_VENDOR // set HW_VENDOR
// //
#define HW_VENDOR meshtastic_HardwareModel_PORTDUINO #define HW_VENDOR meshtastic_HardwareModel_PORTDUINO
#define HAS_RTC 1 #ifndef HAS_WIFI
#define HAS_WIFI 1 #define HAS_WIFI 1
#endif
#ifndef HAS_RTC
#define HAS_RTC 1
#endif
#ifndef HAS_TELEMETRY
#define HAS_TELEMETRY 1
#endif