Build option to disable remote debug

This commit is contained in:
Gunnar Skjold
2024-06-07 18:48:26 +02:00
parent 93e55f457a
commit 59bf0ce066
36 changed files with 784 additions and 169 deletions

View File

@@ -9,13 +9,19 @@
#include "ConnectionHandler.h"
#include <Arduino.h>
#if defined(AMS_REMOTE_DEBUG)
#include "RemoteDebug.h"
#endif
#define CONNECTION_TIMEOUT 30000
class EthernetConnectionHandler : public ConnectionHandler {
public:
#if defined(AMS_REMOTE_DEBUG)
EthernetConnectionHandler(RemoteDebug* debugger);
#else
EthernetConnectionHandler(Stream* debugger);
#endif
bool connect(NetworkConfig config, SystemConfig sys);
void disconnect(unsigned long reconnectDelay);
@@ -33,7 +39,11 @@ public:
#endif
private:
#if defined(AMS_REMOTE_DEBUG)
RemoteDebug* debugger;
#else
Stream* debugger;
#endif
NetworkConfig config;
bool connected = false;

View File

@@ -9,12 +9,18 @@
#include "ConnectionHandler.h"
#include <Arduino.h>
#if defined(AMS_REMOTE_DEBUG)
#include "RemoteDebug.h"
#endif
#include <DNSServer.h>
class WiFiAccessPointConnectionHandler : public ConnectionHandler {
public:
#if defined(AMS_REMOTE_DEBUG)
WiFiAccessPointConnectionHandler(RemoteDebug* debugger);
#else
WiFiAccessPointConnectionHandler(Stream* debugger);
#endif
bool connect(NetworkConfig config, SystemConfig sys);
void disconnect(unsigned long reconnectDelay);
@@ -32,7 +38,11 @@ public:
#endif
private:
#if defined(AMS_REMOTE_DEBUG)
RemoteDebug* debugger;
#else
Stream* debugger;
#endif
NetworkConfig config;
DNSServer dnsServer;

View File

@@ -9,7 +9,9 @@
#include "ConnectionHandler.h"
#include <Arduino.h>
#if defined(AMS_REMOTE_DEBUG)
#include "RemoteDebug.h"
#endif
#define CONNECTION_TIMEOUT 30000
#define RECONNECT_TIMEOUT 5000
@@ -20,7 +22,11 @@ esp_err_t set_esp_interface_ip(esp_interface_t interface, IPAddress local_ip=INA
class WiFiClientConnectionHandler : public ConnectionHandler {
public:
#if defined(AMS_REMOTE_DEBUG)
WiFiClientConnectionHandler(RemoteDebug* debugger);
#else
WiFiClientConnectionHandler(Stream* debugger);
#endif
bool connect(NetworkConfig config, SystemConfig sys);
void disconnect(unsigned long reconnectDelay);
@@ -38,7 +44,11 @@ public:
#endif
private:
#if defined(AMS_REMOTE_DEBUG)
RemoteDebug* debugger;
#else
Stream* debugger;
#endif
NetworkConfig config;
bool busPowered = false;
bool firstConnect = true;

View File

@@ -12,7 +12,11 @@
#include <lwip/dns.h>
#endif
#if defined(AMS_REMOTE_DEBUG)
EthernetConnectionHandler::EthernetConnectionHandler(RemoteDebug* debugger) {
#else
EthernetConnectionHandler::EthernetConnectionHandler(Stream* debugger) {
#endif
this->debugger = debugger;
this->mode = NETWORK_MODE_ETH_CLIENT;
}
@@ -59,7 +63,10 @@ bool EthernetConnectionHandler::connect(NetworkConfig config, SystemConfig sys)
} else if(sys.boardType == 244) {
return false; // TODO
} else {
if (debugger->isActive(RemoteDebug::ERROR)) debugger->printf_P(PSTR("Board type %d incompatible with ETH\n"), sys.boardType);
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::ERROR))
#endif
debugger->printf_P(PSTR("Board type %d incompatible with ETH\n"), sys.boardType);
return false;
}
@@ -68,7 +75,10 @@ bool EthernetConnectionHandler::connect(NetworkConfig config, SystemConfig sys)
digitalWrite(ethEnablePin, 1);
}
if (debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Connecting to Ethernet\n"));
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("Connecting to Ethernet\n"));
if(ETH.begin(ethAddr, ethPowerPin, ethMdc, ethMdio, ethType, ethClkMode)) {
#if defined(ESP32)
@@ -97,7 +107,10 @@ bool EthernetConnectionHandler::connect(NetworkConfig config, SystemConfig sys)
}
}
} else {
if (debugger->isActive(RemoteDebug::ERROR)) debugger->printf_P(PSTR("Unable to start Ethernet\n"));
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::ERROR))
#endif
debugger->printf_P(PSTR("Unable to start Ethernet\n"));
}
}
#endif
@@ -105,7 +118,10 @@ bool EthernetConnectionHandler::connect(NetworkConfig config, SystemConfig sys)
}
void EthernetConnectionHandler::disconnect(unsigned long reconnectDelay) {
if(debugger->isActive(RemoteDebug::ERROR)) debugger->printf_P(PSTR("Disconnecting!\n"));
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::ERROR))
#endif
debugger->printf_P(PSTR("Disconnecting!\n"));
}
bool EthernetConnectionHandler::isConnected() {
@@ -117,12 +133,18 @@ void EthernetConnectionHandler::eventHandler(WiFiEvent_t event, WiFiEventInfo_t
switch(event) {
case ARDUINO_EVENT_ETH_CONNECTED:
connected = true;
if(debugger->isActive(RemoteDebug::INFO)) {
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
{
debugger->printf_P(PSTR("Successfully connected to Ethernet!\n"));
}
break;
case ARDUINO_EVENT_ETH_GOT_IP:
if(debugger->isActive(RemoteDebug::INFO)) {
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
{
debugger->printf_P(PSTR("IP: %s\n"), getIP().toString().c_str());
debugger->printf_P(PSTR("GW: %s\n"), getGateway().toString().c_str());
for(uint8_t i = 0; i < 3; i++) {
@@ -132,7 +154,10 @@ void EthernetConnectionHandler::eventHandler(WiFiEvent_t event, WiFiEventInfo_t
}
break;
case ARDUINO_EVENT_ETH_GOT_IP6: {
if(debugger->isActive(RemoteDebug::INFO)) {
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
{
IPv6Address ipv6 = getIPv6();
if(ipv6 == IPv6Address()) {
// No IP
@@ -153,7 +178,10 @@ void EthernetConnectionHandler::eventHandler(WiFiEvent_t event, WiFiEventInfo_t
}
case ARDUINO_EVENT_ETH_DISCONNECTED:
connected = false;
if(debugger->isActive(RemoteDebug::WARNING)) {
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::WARNING))
#endif
{
debugger->printf_P(PSTR("Ethernet was disconnected!\n"));
}
break;

View File

@@ -6,7 +6,11 @@
#include "WiFiAccessPointConnectionHandler.h"
#if defined(AMS_REMOTE_DEBUG)
WiFiAccessPointConnectionHandler::WiFiAccessPointConnectionHandler(RemoteDebug* debugger) {
#else
WiFiAccessPointConnectionHandler::WiFiAccessPointConnectionHandler(Stream* debugger) {
#endif
this->debugger = debugger;
this->mode = NETWORK_MODE_WIFI_AP;
}
@@ -42,22 +46,37 @@ void WiFiAccessPointConnectionHandler::eventHandler(WiFiEvent_t event, WiFiEvent
IPAddress stationIP;
switch(event) {
case ARDUINO_EVENT_WIFI_AP_START:
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("WiFi access point started with SSID %s\n"), config.ssid);
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("WiFi access point started with SSID %s\n"), config.ssid);
break;
case ARDUINO_EVENT_WIFI_AP_STOP:
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("WiFi access point stopped!\n"));
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("WiFi access point stopped!\n"));
break;
case ARDUINO_EVENT_WIFI_AP_STACONNECTED:
memcpy(mac, info.wifi_ap_staconnected.mac, 6);
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Client connected to AP, client MAC: %02x:%02x:%02x:%02x:%02x:%02x\n"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("Client connected to AP, client MAC: %02x:%02x:%02x:%02x:%02x:%02x\n"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
break;
case ARDUINO_EVENT_WIFI_AP_STADISCONNECTED:
memcpy(mac, info.wifi_ap_staconnected.mac, 6);
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Client disconnected from AP, client MAC: %02x:%02x:%02x:%02x:%02x:%02x\n"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("Client disconnected from AP, client MAC: %02x:%02x:%02x:%02x:%02x:%02x\n"), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
break;
case ARDUINO_EVENT_WIFI_AP_STAIPASSIGNED:
stationIP = info.wifi_ap_staipassigned.ip.addr;
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Client was assigned IP %s\n"), stationIP.toString().c_str());
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("Client was assigned IP %s\n"), stationIP.toString().c_str());
break;
}
}

View File

@@ -10,7 +10,11 @@
#include <lwip/dns.h>
#endif
#if defined(AMS_REMOTE_DEBUG)
WiFiClientConnectionHandler::WiFiClientConnectionHandler(RemoteDebug* debugger) {
#else
WiFiClientConnectionHandler::WiFiClientConnectionHandler(Stream* debugger) {
#endif
this->debugger = debugger;
this->mode = NETWORK_MODE_WIFI_CLIENT;
}
@@ -28,14 +32,20 @@ bool WiFiClientConnectionHandler::connect(NetworkConfig config, SystemConfig sys
}
if(WiFi.getMode() != WIFI_OFF) {
if (debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Not connected to WiFi, closing resources\n"));
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("Not connected to WiFi, closing resources\n"));
disconnect(RECONNECT_TIMEOUT);
return false;
}
timeout = CONNECTION_TIMEOUT;
if (debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Connecting to WiFi network: %s\n"), config.ssid);
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("Connecting to WiFi network: %s\n"), config.ssid);
switch(sys.boardType) {
case 2: // spenceme
case 3: // Pow-K UART0
@@ -111,7 +121,10 @@ bool WiFiClientConnectionHandler::connect(NetworkConfig config, SystemConfig sys
}
yield();
} else {
if (debugger->isActive(RemoteDebug::ERROR)) debugger->printf_P(PSTR("Unable to start WiFi\n"));
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::ERROR))
#endif
debugger->printf_P(PSTR("Unable to start WiFi\n"));
}
return true;
}
@@ -208,7 +221,10 @@ void WiFiClientConnectionHandler::wifi_sta_config(wifi_config_t * wifi_config, c
#endif
void WiFiClientConnectionHandler::disconnect(unsigned long reconnectDelay) {
if(debugger->isActive(RemoteDebug::ERROR)) debugger->printf_P(PSTR("Disconnecting!\n"));
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::ERROR))
#endif
debugger->printf_P(PSTR("Disconnecting!\n"));
#if defined(ESP8266)
WiFiClient::stopAll();
#endif
@@ -235,7 +251,10 @@ void WiFiClientConnectionHandler::eventHandler(WiFiEvent_t event, WiFiEventInfo_
}
break;
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
if(debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("Successfully connected to WiFi!\n"));
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("Successfully connected to WiFi!\n"));
if(config.ipv6 && !WiFi.enableIpV6()) {
debugger->printf_P(PSTR("Unable to enable IPv6\n"));
}
@@ -246,7 +265,10 @@ void WiFiClientConnectionHandler::eventHandler(WiFiEvent_t event, WiFiEventInfo_
wifi_phy_mode_t phyMode;
if(esp_wifi_sta_get_negotiated_phymode(&phyMode) == ESP_OK) {
if(phyMode > WIFI_PHY_MODE_11B) {
if (debugger->isActive(RemoteDebug::INFO)) debugger->printf_P(PSTR("WiFi supports better rates than 802.11b, disabling\n"));
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
debugger->printf_P(PSTR("WiFi supports better rates than 802.11b, disabling\n"));
config.use11b = false;
configChanged = true;
return;
@@ -284,7 +306,10 @@ void WiFiClientConnectionHandler::eventHandler(WiFiEvent_t event, WiFiEventInfo_
#endif
break;
case ARDUINO_EVENT_WIFI_STA_GOT_IP: {
if(debugger->isActive(RemoteDebug::INFO)) {
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
{
debugger->printf_P(PSTR("IP: %s\n"), getIP().toString().c_str());
debugger->printf_P(PSTR("GW: %s\n"), getGateway().toString().c_str());
for(uint8_t i = 0; i < 3; i++) {
@@ -295,7 +320,10 @@ void WiFiClientConnectionHandler::eventHandler(WiFiEvent_t event, WiFiEventInfo_
break;
}
case ARDUINO_EVENT_WIFI_STA_GOT_IP6: {
if(debugger->isActive(RemoteDebug::INFO)) {
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::INFO))
#endif
{
IPv6Address ipv6 = getIPv6();
if(ipv6 == IPv6Address()) {
// No IP
@@ -322,7 +350,10 @@ void WiFiClientConnectionHandler::eventHandler(WiFiEvent_t event, WiFiEventInfo_
break;
default:
if(strlen(descr) > 0) {
if(debugger->isActive(RemoteDebug::WARNING)) {
#if defined(AMS_REMOTE_DEBUG)
if (debugger->isActive(RemoteDebug::WARNING))
#endif
{
debugger->printf_P(PSTR("WiFi disconnected, reason %s\n"), descr);
}
disconnect(RECONNECT_TIMEOUT);