minor cleanup proposal (#4169)

* MESHTASTIC_EXCLUDE_WIFI and HAS_WIFI cleanup...
Our code was checking HAS_WIFI and the new MESHTASTIC_EXCLUDE_WIFI
flags in various places (even though EXCLUDE_WIFI forces HAS_WIFI
to 0).  Instead just check HAS_WIFI, only use EXCLUDE_WIFI inside
configuration.h

* cleanup: use HAS_NETWORKING instead of HAS_WIFI || HAS_ETHERNET
We already had HAS_NETWORKING as flag in MQTT to mean 'we have
tcpip'.  Generallize that and move it into configuration.h so that
we can use it elsewhere.

* Use #pragma once, because supported by gcc and all modern compilers
instead of #ifdef DOTHFILE_H etc...

---------

Co-authored-by: Jonathan Bennett <jbennett@incomsystems.biz>
pull/4147/head
geeksville 2024-07-03 15:39:09 -07:00 zatwierdzone przez GitHub
rodzic 9c46bdad1a
commit 8785adf6e4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
13 zmienionych plików z 47 dodań i 48 usunięć

Wyświetl plik

@ -26,7 +26,7 @@ SOFTWARE.*/
#include "DebugConfiguration.h" #include "DebugConfiguration.h"
#if HAS_WIFI || HAS_ETHERNET #if HAS_NETWORKING
Syslog::Syslog(UDP &client) Syslog::Syslog(UDP &client)
{ {

Wyświetl plik

@ -1,5 +1,6 @@
#ifndef SYSLOG_H #pragma once
#define SYSLOG_H
#include "configuration.h"
// DEBUG LED // DEBUG LED
#ifndef LED_INVERTED #ifndef LED_INVERTED
@ -125,7 +126,7 @@
#include <WiFi.h> #include <WiFi.h>
#endif // HAS_WIFI #endif // HAS_WIFI
#if HAS_WIFI || HAS_ETHERNET #if HAS_NETWORKING
class Syslog class Syslog
{ {
@ -160,6 +161,4 @@ class Syslog
bool vlogf(uint16_t pri, const char *appName, const char *fmt, va_list args) __attribute__((format(printf, 3, 0))); bool vlogf(uint16_t pri, const char *appName, const char *fmt, va_list args) __attribute__((format(printf, 3, 0)));
}; };
#endif // HAS_ETHERNET || HAS_WIFI #endif // HAS_ETHERNET || HAS_WIFI
#endif // SYSLOG_H

Wyświetl plik

@ -27,7 +27,7 @@
#if defined(DEBUG_HEAP_MQTT) && !MESHTASTIC_EXCLUDE_MQTT #if defined(DEBUG_HEAP_MQTT) && !MESHTASTIC_EXCLUDE_MQTT
#include "mqtt/MQTT.h" #include "mqtt/MQTT.h"
#include "target_specific.h" #include "target_specific.h"
#if !MESTASTIC_EXCLUDE_WIFI #if HAS_WIFI
#include <WiFi.h> #include <WiFi.h>
#endif #endif
#endif #endif

Wyświetl plik

@ -16,7 +16,7 @@
#include "platform/portduino/PortduinoGlue.h" #include "platform/portduino/PortduinoGlue.h"
#endif #endif
#if HAS_WIFI || HAS_ETHERNET #if HAS_NETWORKING
extern Syslog syslog; extern Syslog syslog;
#endif #endif
void RedirectablePrint::rpInit() void RedirectablePrint::rpInit()
@ -138,7 +138,7 @@ void RedirectablePrint::log_to_serial(const char *logLevel, const char *format,
void RedirectablePrint::log_to_syslog(const char *logLevel, const char *format, va_list arg) void RedirectablePrint::log_to_syslog(const char *logLevel, const char *format, va_list arg)
{ {
#if (HAS_WIFI || HAS_ETHERNET) && !defined(ARCH_PORTDUINO) #if HAS_NETWORKING && !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;

Wyświetl plik

@ -242,9 +242,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define HAS_BLUETOOTH 0 #define HAS_BLUETOOTH 0
#endif #endif
#include "DebugConfiguration.h"
#include "RF95Configuration.h"
#ifndef HW_VENDOR #ifndef HW_VENDOR
#error HW_VENDOR must be defined #error HW_VENDOR must be defined
#endif #endif
@ -290,6 +287,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define HAS_WIFI 0 #define HAS_WIFI 0
#endif #endif
// Allow code that needs internet to just check HAS_NETWORKING rather than HAS_WIFI || HAS_ETHERNET
#define HAS_NETWORKING (HAS_WIFI || HAS_ETHERNET)
// // Turn off Bluetooth // // Turn off Bluetooth
#ifdef MESHTASTIC_EXCLUDE_BLUETOOTH #ifdef MESHTASTIC_EXCLUDE_BLUETOOTH
#undef HAS_BLUETOOTH #undef HAS_BLUETOOTH
@ -308,4 +308,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef MESHTASTIC_EXCLUDE_SCREEN #ifdef MESHTASTIC_EXCLUDE_SCREEN
#undef HAS_SCREEN #undef HAS_SCREEN
#define HAS_SCREEN 0 #define HAS_SCREEN 0
#endif #endif
#include "DebugConfiguration.h"
#include "RF95Configuration.h"

Wyświetl plik

@ -26,7 +26,7 @@
#include <vector> #include <vector>
#ifdef ARCH_ESP32 #ifdef ARCH_ESP32
#if !MESHTASTIC_EXCLUDE_WIFI #if HAS_WIFI
#include "mesh/wifi/WiFiAPClient.h" #include "mesh/wifi/WiFiAPClient.h"
#endif #endif
#include "modules/esp32/StoreForwardModule.h" #include "modules/esp32/StoreForwardModule.h"

Wyświetl plik

@ -6,7 +6,7 @@
#include "main.h" #include "main.h"
#include "mesh/http/ContentHelper.h" #include "mesh/http/ContentHelper.h"
#include "mesh/http/WebServer.h" #include "mesh/http/WebServer.h"
#if !MESHTASTIC_EXCLUDE_WIFI #if HAS_WIFI
#include "mesh/wifi/WiFiAPClient.h" #include "mesh/wifi/WiFiAPClient.h"
#endif #endif
#include "mqtt/JSON.h" #include "mqtt/JSON.h"

Wyświetl plik

@ -1,5 +1,5 @@
#include "configuration.h" #include "configuration.h"
#if !MESHTASTIC_EXCLUDE_WIFI #if HAS_WIFI
#include "NodeDB.h" #include "NodeDB.h"
#include "RTC.h" #include "RTC.h"
#include "concurrency/Periodic.h" #include "concurrency/Periodic.h"

Wyświetl plik

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "ProtobufModule.h" #include "ProtobufModule.h"
#if HAS_WIFI && !MESHTASTIC_EXCLUDE_WIFI #if HAS_WIFI
#include "mesh/wifi/WiFiAPClient.h" #include "mesh/wifi/WiFiAPClient.h"
#endif #endif

Wyświetl plik

@ -14,7 +14,7 @@
#endif #endif
#include "mesh/generated/meshtastic/remote_hardware.pb.h" #include "mesh/generated/meshtastic/remote_hardware.pb.h"
#include "sleep.h" #include "sleep.h"
#if HAS_WIFI && !MESHTASTIC_EXCLUDE_WIFI #if HAS_WIFI
#include "mesh/wifi/WiFiAPClient.h" #include "mesh/wifi/WiFiAPClient.h"
#include <WiFi.h> #include <WiFi.h>
#endif #endif
@ -175,7 +175,7 @@ void mqttInit()
new MQTT(); new MQTT();
} }
#ifdef HAS_NETWORKING #if HAS_NETWORKING
MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_MQTT_QUEUE) MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_MQTT_QUEUE)
#else #else
MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE) MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
@ -206,7 +206,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
moduleConfig.mqtt.map_report_settings.publish_interval_secs, default_map_publish_interval_secs); moduleConfig.mqtt.map_report_settings.publish_interval_secs, default_map_publish_interval_secs);
} }
#ifdef HAS_NETWORKING #if HAS_NETWORKING
if (!moduleConfig.mqtt.proxy_to_client_enabled) if (!moduleConfig.mqtt.proxy_to_client_enabled)
pubSub.setCallback(mqttCallback); pubSub.setCallback(mqttCallback);
#endif #endif
@ -226,7 +226,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
bool MQTT::isConnectedDirectly() bool MQTT::isConnectedDirectly()
{ {
#ifdef HAS_NETWORKING #if HAS_NETWORKING
return pubSub.connected(); return pubSub.connected();
#else #else
return false; return false;
@ -244,7 +244,7 @@ bool MQTT::publish(const char *topic, const char *payload, bool retained)
service.sendMqttMessageToClientProxy(msg); service.sendMqttMessageToClientProxy(msg);
return true; return true;
} }
#ifdef HAS_NETWORKING #if HAS_NETWORKING
else if (isConnectedDirectly()) { else if (isConnectedDirectly()) {
return pubSub.publish(topic, payload, retained); return pubSub.publish(topic, payload, retained);
} }
@ -264,7 +264,7 @@ bool MQTT::publish(const char *topic, const uint8_t *payload, size_t length, boo
service.sendMqttMessageToClientProxy(msg); service.sendMqttMessageToClientProxy(msg);
return true; return true;
} }
#ifdef HAS_NETWORKING #if HAS_NETWORKING
else if (isConnectedDirectly()) { else if (isConnectedDirectly()) {
return pubSub.publish(topic, payload, length, retained); return pubSub.publish(topic, payload, length, retained);
} }
@ -284,7 +284,7 @@ void MQTT::reconnect()
publishStatus(); publishStatus();
return; // Don't try to connect directly to the server return; // Don't try to connect directly to the server
} }
#ifdef HAS_NETWORKING #if HAS_NETWORKING
// Defaults // Defaults
int serverPort = 1883; int serverPort = 1883;
const char *serverAddr = default_mqtt_address; const char *serverAddr = default_mqtt_address;
@ -357,7 +357,7 @@ void MQTT::reconnect()
void MQTT::sendSubscriptions() void MQTT::sendSubscriptions()
{ {
#ifdef HAS_NETWORKING #if HAS_NETWORKING
size_t numChan = channels.getNumChannels(); size_t numChan = channels.getNumChannels();
for (size_t i = 0; i < numChan; i++) { for (size_t i = 0; i < numChan; i++) {
const auto &ch = channels.getByIndex(i); const auto &ch = channels.getByIndex(i);
@ -396,7 +396,7 @@ bool MQTT::wantsLink() const
int32_t MQTT::runOnce() int32_t MQTT::runOnce()
{ {
#ifdef HAS_NETWORKING #if HAS_NETWORKING
if (!moduleConfig.mqtt.enabled || !(moduleConfig.mqtt.map_reporting_enabled || channels.anyMqttEnabled())) if (!moduleConfig.mqtt.enabled || !(moduleConfig.mqtt.map_reporting_enabled || channels.anyMqttEnabled()))
return disable(); return disable();

Wyświetl plik

@ -8,17 +8,15 @@
#include "mqtt/JSON.h" #include "mqtt/JSON.h"
#if HAS_WIFI #if HAS_WIFI
#include <WiFiClient.h> #include <WiFiClient.h>
#define HAS_NETWORKING 1
#if !defined(ARCH_PORTDUINO) #if !defined(ARCH_PORTDUINO)
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
#endif #endif
#endif #endif
#if HAS_ETHERNET #if HAS_ETHERNET
#include <EthernetClient.h> #include <EthernetClient.h>
#define HAS_NETWORKING 1
#endif #endif
#ifdef HAS_NETWORKING #if HAS_NETWORKING
#include <PubSubClient.h> #include <PubSubClient.h>
#endif #endif
@ -43,7 +41,7 @@ class MQTT : private concurrency::OSThread
#endif #endif
public: public:
#ifdef HAS_NETWORKING #if HAS_NETWORKING
PubSubClient pubSub; PubSubClient pubSub;
#endif #endif
MQTT(); MQTT();

Wyświetl plik

@ -8,7 +8,7 @@
#include "nimble/NimbleBluetooth.h" #include "nimble/NimbleBluetooth.h"
#endif #endif
#if !MESHTASTIC_EXCLUDE_WIFI #if HAS_WIFI
#include "mesh/wifi/WiFiAPClient.h" #include "mesh/wifi/WiFiAPClient.h"
#endif #endif
@ -24,23 +24,22 @@
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_BLUETOOTH #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_BLUETOOTH
void setBluetoothEnable(bool enable) void setBluetoothEnable(bool enable)
{ {
#ifndef MESHTASTIC_EXCLUDE_WIFI #if HAS_WIFI
if (!isWifiAvailable() && config.bluetooth.enabled == true) if (!isWifiAvailable() && config.bluetooth.enabled == true)
#else
if (config.bluetooth.enabled == true)
#endif #endif
#ifdef MESHTASTIC_EXCLUDE_WIFI {
if (config.bluetooth.enabled == true) if (!nimbleBluetooth) {
#endif nimbleBluetooth = new NimbleBluetooth();
{
if (!nimbleBluetooth) {
nimbleBluetooth = new NimbleBluetooth();
}
if (enable && !nimbleBluetooth->isActive()) {
nimbleBluetooth->setup();
}
// For ESP32, no way to recover from bluetooth shutdown without reboot
// BLE advertising automatically stops when MCU enters light-sleep(?)
// For deep-sleep, shutdown hardware with nimbleBluetooth->deinit(). Requires reboot to reverse
} }
if (enable && !nimbleBluetooth->isActive()) {
nimbleBluetooth->setup();
}
// For ESP32, no way to recover from bluetooth shutdown without reboot
// BLE advertising automatically stops when MCU enters light-sleep(?)
// For deep-sleep, shutdown hardware with nimbleBluetooth->deinit(). Requires reboot to reverse
}
} }
#else #else
void setBluetoothEnable(bool enable) {} void setBluetoothEnable(bool enable) {}

Wyświetl plik

@ -17,7 +17,7 @@
#ifdef ARCH_ESP32 #ifdef ARCH_ESP32
#include "esp32/pm.h" #include "esp32/pm.h"
#include "esp_pm.h" #include "esp_pm.h"
#if !MESHTASTIC_EXCLUDE_WIFI #if HAS_WIFI
#include "mesh/wifi/WiFiAPClient.h" #include "mesh/wifi/WiFiAPClient.h"
#endif #endif
#include "rom/rtc.h" #include "rom/rtc.h"
@ -56,7 +56,7 @@ RTC_DATA_ATTR int bootCount = 0;
*/ */
void setCPUFast(bool on) void setCPUFast(bool on)
{ {
#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_WIFI #if defined(ARCH_ESP32) && HAS_WIFI
if (isWifiAvailable()) { if (isWifiAvailable()) {
/* /*