diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index b6b17d391a..100f3538dd 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -12,7 +12,9 @@ build_src_filter = - - - - - + - + - + - +<../variants/portduino> lib_deps = ${env.lib_deps} diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 04dbcdd491..39ea76c007 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 89148c22bc..f2681bc192 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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); @@ -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())) { diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 85a6390c9e..a4d4114b63 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -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 diff --git a/src/mesh/MeshService.h b/src/mesh/MeshService.h index b8abac80d3..4314ea3621 100644 --- a/src/mesh/MeshService.h +++ b/src/mesh/MeshService.h @@ -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 diff --git a/src/modules/Modules.cpp b/src/modules/Modules.cpp index bc874a9a3d..3247d02c14 100644 --- a/src/modules/Modules.cpp +++ b/src/modules/Modules.cpp @@ -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 @@ -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(); diff --git a/src/modules/Telemetry/AirQualityTelemetry.cpp b/src/modules/Telemetry/AirQualityTelemetry.cpp index 2b744c4891..966e2d0ff7 100644 --- a/src/modules/Telemetry/AirQualityTelemetry.cpp +++ b/src/modules/Telemetry/AirQualityTelemetry.cpp @@ -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 @@ -55,7 +54,6 @@ int32_t AirQualityTelemetryModule::runOnce() } } return sendToPhoneIntervalMs; -#endif } bool AirQualityTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index d9b129e70f..bd7ed539aa 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -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 @@ -115,7 +114,6 @@ int32_t EnvironmentTelemetryModule::runOnce() } } return sendToPhoneIntervalMs; -#endif } bool EnvironmentTelemetryModule::wantUIFrame() diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 09b754d0f8..90c016daeb 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -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 diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index 383a0da4ea..f21635560b 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -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 diff --git a/src/platform/portduino/SimRadio.cpp b/src/platform/portduino/SimRadio.cpp index fa42126694..f71113ab44 100644 --- a/src/platform/portduino/SimRadio.cpp +++ b/src/platform/portduino/SimRadio.cpp @@ -2,7 +2,7 @@ #include "MeshService.h" #include "Router.h" -SimRadio::SimRadio() +SimRadio::SimRadio() : NotifiedWorkerThread("SimRadio") { instance = this; } @@ -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); } } @@ -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); } } @@ -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"); @@ -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 { @@ -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); @@ -268,4 +263,4 @@ int16_t SimRadio::readData(uint8_t *data, size_t len) } return state; -} \ No newline at end of file +} diff --git a/src/platform/portduino/SimRadio.h b/src/platform/portduino/SimRadio.h index b78beb70a9..1edb4963b4 100644 --- a/src/platform/portduino/SimRadio.h +++ b/src/platform/portduino/SimRadio.h @@ -3,10 +3,11 @@ #include "MeshPacketQueue.h" #include "RadioInterface.h" #include "api/WiFiServerAPI.h" +#include "concurrency/NotifiedWorkerThread.h" #include -class SimRadio : public RadioInterface +class SimRadio : public RadioInterface, protected concurrency::NotifiedWorkerThread { enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED }; diff --git a/src/platform/portduino/architecture.h b/src/platform/portduino/architecture.h index 54df672d80..9408ad19c7 100644 --- a/src/platform/portduino/architecture.h +++ b/src/platform/portduino/architecture.h @@ -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