Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable DeviceTelemetry on Portduino #2272

Merged
merged 8 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion arch/portduino/portduino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ build_src_filter =
-<mesh/http/>
-<mesh/eth/>
-<modules/esp32>
-<modules/Telemetry>
-<modules/Telemetry/EnvironmentTelemetry.cpp>
-<modules/Telemetry/AirQualityTelemetry.cpp>
-<modules/Telemetry/Sensor>
+<../variants/portduino>
lib_deps =
${env.lib_deps}
Expand Down
2 changes: 1 addition & 1 deletion src/RedirectablePrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...)
}
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.isEnabled()) {
int ll = 0;
Expand Down
26 changes: 13 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,19 @@ void setup()

// 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 (!rIf) {
rIf = new RF95Interface(RF95_NSS, RF95_IRQ, RF95_RESET, SPI);
Expand Down Expand Up @@ -459,19 +472,6 @@ void setup()
}
#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

if ((config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24) && (!rIf->wideLora())) {
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/MeshService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void MeshService::reloadOwner(bool shouldSave)
*/
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
if (p.decoded.portnum == meshtastic_PortNum_SIMULATOR_APP) {
// Simulator packet (=Compressed packet) is encapsulated in a MeshPacket, so need to unwrap first
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/MeshService.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "MeshTypes.h"
#include "Observer.h"
#include "PointerQueue.h"
#ifdef ARCH_PORTDUINO
#if defined(ARCH_PORTDUINO) && !HAS_RADIO
#include "../platform/portduino/SimRadio.h"
#endif

Expand Down
6 changes: 5 additions & 1 deletion src/modules/Modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#include "modules/TraceRouteModule.h"
#include "modules/WaypointModule.h"
#if HAS_TELEMETRY
#include "modules/Telemetry/AirQualityTelemetry.h"
#include "modules/Telemetry/DeviceTelemetry.h"
#endif
#if HAS_SENSOR
#include "modules/Telemetry/AirQualityTelemetry.h"
#include "modules/Telemetry/EnvironmentTelemetry.h"
#endif
#ifdef ARCH_ESP32
Expand Down Expand Up @@ -63,6 +65,8 @@ void setupModules()
#endif
#if HAS_TELEMETRY
new DeviceTelemetryModule();
#endif
#if HAS_SENSOR
new EnvironmentTelemetryModule();
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_PMSA003I] > 0) {
new AirQualityTelemetryModule();
Expand Down
2 changes: 0 additions & 2 deletions src/modules/Telemetry/AirQualityTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

int32_t AirQualityTelemetryModule::runOnce()
{
#ifndef ARCH_PORTDUINO
int32_t result = INT32_MAX;
/*
Uncomment the preferences below if you want to use the module
Expand Down Expand Up @@ -55,7 +54,6 @@ int32_t AirQualityTelemetryModule::runOnce()
}
}
return sendToPhoneIntervalMs;
#endif
}

bool AirQualityTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t)
Expand Down
2 changes: 0 additions & 2 deletions src/modules/Telemetry/EnvironmentTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ SHT31Sensor sht31Sensor;

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

bool EnvironmentTelemetryModule::wantUIFrame()
Expand Down
3 changes: 3 additions & 0 deletions src/platform/esp32/architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#ifndef HAS_TELEMETRY
#define HAS_TELEMETRY 1
#endif
#ifndef HAS_SENSOR
#define HAS_SENSOR 1
#endif
#ifndef HAS_RADIO
#define HAS_RADIO 1
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/platform/nrf52/architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#ifndef HAS_TELEMETRY
#define HAS_TELEMETRY 1
#endif
#ifndef HAS_SENSOR
#define HAS_SENSOR 1
#endif
#ifndef HAS_RADIO
#define HAS_RADIO 1
#endif
Expand Down
23 changes: 9 additions & 14 deletions src/platform/portduino/SimRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "MeshService.h"
#include "Router.h"

SimRadio::SimRadio()
SimRadio::SimRadio() : NotifiedWorkerThread("SimRadio")
{
instance = this;
}
Expand Down Expand Up @@ -53,10 +53,7 @@ void SimRadio::startTransmitTimer(bool withDelay)
if (!txQueue.empty()) {
uint32_t delayMsec = !withDelay ? 1 : getTxDelayMsec();
// LOG_DEBUG("xmit timer %d\n", delay);
delay(delayMsec);
onNotify(TRANSMIT_DELAY_COMPLETED);
} else {
LOG_DEBUG("TX QUEUE EMPTY!\n");
notifyLater(delayMsec, TRANSMIT_DELAY_COMPLETED, false);
}
}

Expand All @@ -66,8 +63,7 @@ void SimRadio::startTransmitTimerSNR(float snr)
if (!txQueue.empty()) {
uint32_t delayMsec = getTxDelayMsecWeighted(snr);
// LOG_DEBUG("xmit timer %d\n", delay);
delay(delayMsec);
onNotify(TRANSMIT_DELAY_COMPLETED);
notifyLater(delayMsec, TRANSMIT_DELAY_COMPLETED, false);
}
}

Expand Down Expand Up @@ -142,11 +138,12 @@ void SimRadio::onNotify(uint32_t notification)
switch (notification) {
case ISR_TX:
handleTransmitInterrupt();
LOG_DEBUG("tx complete - starting timer\n");
// LOG_DEBUG("tx complete - starting timer\n");
startTransmitTimer();
break;
case ISR_RX:
LOG_DEBUG("rx complete - starting timer\n");
// LOG_DEBUG("rx complete - starting timer\n");
startTransmitTimer();
break;
case TRANSMIT_DELAY_COMPLETED:
LOG_DEBUG("delay done\n");
Expand All @@ -170,8 +167,7 @@ void SimRadio::onNotify(uint32_t notification)
uint32_t xmitMsec = getPacketTime(txp);
airTime->logAirtime(TX_LOG, xmitMsec);

delay(xmitMsec); // Model the time it is busy sending
completeSending();
notifyLater(xmitMsec, ISR_TX, false); // Model the time it is busy sending
}
}
} else {
Expand Down Expand Up @@ -242,8 +238,7 @@ void SimRadio::handleReceiveInterrupt(meshtastic_MeshPacket *p)
xmitMsec = getPacketTime(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
mp->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // Mark that the payload is already decoded
meshtastic_MeshPacket *mp = packetPool.allocCopy(*p); // keep a copy in packetPool

printPacket("Lora RX", mp);

Expand All @@ -268,4 +263,4 @@ int16_t SimRadio::readData(uint8_t *data, size_t len)
}

return state;
}
}
3 changes: 2 additions & 1 deletion src/platform/portduino/SimRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#include "MeshPacketQueue.h"
#include "RadioInterface.h"
#include "api/WiFiServerAPI.h"
#include "concurrency/NotifiedWorkerThread.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 };

Expand Down
13 changes: 8 additions & 5 deletions src/platform/portduino/architecture.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

#define ARCH_PORTDUINO

//
// defaults for NRF52 architecture
//

//
// set HW_VENDOR
//

#define HW_VENDOR meshtastic_HardwareModel_PORTDUINO

#define HAS_RTC 1
#ifndef HAS_WIFI
#define HAS_WIFI 1
#endif
#ifndef HAS_RTC
#define HAS_RTC 1
#endif
#ifndef HAS_TELEMETRY
#define HAS_TELEMETRY 1
#endif