1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Migrate from astyle to clang-format (#8464)

This commit is contained in:
Maxim Prokhorov
2022-02-20 19:23:33 +03:00
committed by Max Prokhorov
parent 46190b61f1
commit 19b7a29720
241 changed files with 15925 additions and 16197 deletions

View File

@ -43,39 +43,38 @@
Global defines and vars
*/
#define TIMEZONE_OFFSET 1 // CET
#define DST_OFFSET 1 // CEST
#define UPDATE_CYCLE (1 * 1000) // every second
#define TIMEZONE_OFFSET 1 // CET
#define DST_OFFSET 1 // CEST
#define UPDATE_CYCLE (1 * 1000) // every second
#define SERVICE_PORT 80 // HTTP port
#define SERVICE_PORT 80 // HTTP port
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#define STAPSK "your-password"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
const char* ssid = STASSID;
const char* password = STAPSK;
char* pcHostDomain = 0; // Negotiated host domain
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain
MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the clock service in the MDNS responder
char* pcHostDomain = 0; // Negotiated host domain
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain
MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the clock service in the MDNS responder
// HTTP server at port 'SERVICE_PORT' will respond to HTTP requests
ESP8266WebServer server(SERVICE_PORT);
ESP8266WebServer server(SERVICE_PORT);
/*
getTimeString
*/
const char* getTimeString(void) {
static char acTimeString[32];
static char acTimeString[32];
time_t now = time(nullptr);
ctime_r(&now, acTimeString);
size_t stLength;
while (((stLength = strlen(acTimeString))) &&
('\n' == acTimeString[stLength - 1])) {
acTimeString[stLength - 1] = 0; // Remove trailing line break...
size_t stLength;
while (((stLength = strlen(acTimeString))) && ('\n' == acTimeString[stLength - 1])) {
acTimeString[stLength - 1] = 0; // Remove trailing line break...
}
return acTimeString;
}
@ -186,7 +185,8 @@ void handleHTTPRequest() {
Serial.println("HTTP Request");
// Get current time
time_t now = time(nullptr);;
time_t now = time(nullptr);
;
struct tm timeinfo;
gmtime_r(&now, &timeinfo);
@ -231,10 +231,9 @@ void setup(void) {
// Setup MDNS responder
MDNS.setHostProbeResultCallback(hostProbeResult);
// Init the (currently empty) host domain string with 'esp8266'
if ((!MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) ||
(!MDNS.begin(pcHostDomain))) {
if ((!MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) || (!MDNS.begin(pcHostDomain))) {
Serial.println("Error setting up MDNS responder!");
while (1) { // STOP
while (1) { // STOP
delay(1000);
}
}

View File

@ -39,26 +39,26 @@
Global defines and vars
*/
#define SERVICE_PORT 80 // HTTP port
#define SERVICE_PORT 80 // HTTP port
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#define STAPSK "your-password"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
const char* ssid = STASSID;
const char* password = STAPSK;
char* pcHostDomain = 0; // Negotiated host domain
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain
MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the http service in the MDNS responder
MDNSResponder::hMDNSServiceQuery hMDNSServiceQuery = 0; // The handle of the 'http.tcp' service query in the MDNS responder
char* pcHostDomain = 0; // Negotiated host domain
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain
MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the http service in the MDNS responder
MDNSResponder::hMDNSServiceQuery hMDNSServiceQuery = 0; // The handle of the 'http.tcp' service query in the MDNS responder
const String cstrNoHTTPServices = "Currently no 'http.tcp' services in the local network!<br/>";
String strHTTPServices = cstrNoHTTPServices;
const String cstrNoHTTPServices = "Currently no 'http.tcp' services in the local network!<br/>";
String strHTTPServices = cstrNoHTTPServices;
// HTTP server at port 'SERVICE_PORT' will respond to HTTP requests
ESP8266WebServer server(SERVICE_PORT);
ESP8266WebServer server(SERVICE_PORT);
/*
@ -80,26 +80,17 @@ bool setStationHostname(const char* p_pcHostname) {
void MDNSServiceQueryCallback(MDNSResponder::MDNSServiceInfo serviceInfo, MDNSResponder::AnswerType answerType, bool p_bSetContent) {
String answerInfo;
switch (answerType) {
case MDNSResponder::AnswerType::ServiceDomain :
answerInfo = "ServiceDomain " + String(serviceInfo.serviceDomain());
break;
case MDNSResponder::AnswerType::HostDomainAndPort :
answerInfo = "HostDomainAndPort " + String(serviceInfo.hostDomain()) + ":" + String(serviceInfo.hostPort());
break;
case MDNSResponder::AnswerType::IP4Address :
case MDNSResponder::AnswerType::ServiceDomain: answerInfo = "ServiceDomain " + String(serviceInfo.serviceDomain()); break;
case MDNSResponder::AnswerType::HostDomainAndPort: answerInfo = "HostDomainAndPort " + String(serviceInfo.hostDomain()) + ":" + String(serviceInfo.hostPort()); break;
case MDNSResponder::AnswerType::IP4Address:
answerInfo = "IP4Address ";
for (IPAddress ip : serviceInfo.IP4Adresses()) {
answerInfo += "- " + ip.toString();
};
for (IPAddress ip : serviceInfo.IP4Adresses()) { answerInfo += "- " + ip.toString(); };
break;
case MDNSResponder::AnswerType::Txt :
case MDNSResponder::AnswerType::Txt:
answerInfo = "TXT " + String(serviceInfo.strKeyValue());
for (auto kv : serviceInfo.keyValues()) {
answerInfo += "\nkv : " + String(kv.first) + " : " + String(kv.second);
}
for (auto kv : serviceInfo.keyValues()) { answerInfo += "\nkv : " + String(kv.first) + " : " + String(kv.second); }
break;
default :
answerInfo = "Unknown Answertype";
default: answerInfo = "Unknown Answertype";
}
Serial.printf("Answer %s %s\n", answerInfo.c_str(), p_bSetContent ? "Modified" : "Deleted");
}
@ -109,10 +100,8 @@ void MDNSServiceQueryCallback(MDNSResponder::MDNSServiceInfo serviceInfo, MDNSRe
Probe result callback for Services
*/
void serviceProbeResult(String p_pcServiceName,
const MDNSResponder::hMDNSService p_hMDNSService,
bool p_bProbeResult) {
(void) p_hMDNSService;
void serviceProbeResult(String p_pcServiceName, const MDNSResponder::hMDNSService p_hMDNSService, bool p_bProbeResult) {
(void)p_hMDNSService;
Serial.printf("MDNSServiceProbeResultCallback: Service %s probe %s\n", p_pcServiceName.c_str(), (p_bProbeResult ? "succeeded." : "failed!"));
}
@ -186,7 +175,7 @@ void handleHTTPRequest() {
s += WiFi.hostname() + ".local at " + WiFi.localIP().toString() + "</h3></head>";
s += "<br/><h4>Local HTTP services are :</h4>";
s += "<ol>";
for (auto info : MDNS.answerInfo(hMDNSServiceQuery)) {
for (auto info : MDNS.answerInfo(hMDNSServiceQuery)) {
s += "<li>";
s += info.serviceDomain();
if (info.hostDomainAvailable()) {
@ -196,15 +185,11 @@ void handleHTTPRequest() {
}
if (info.IP4AddressAvailable()) {
s += "<br/>IP4:";
for (auto ip : info.IP4Adresses()) {
s += " " + ip.toString();
}
for (auto ip : info.IP4Adresses()) { s += " " + ip.toString(); }
}
if (info.txtAvailable()) {
s += "<br/>TXT:<br/>";
for (auto kv : info.keyValues()) {
s += "\t" + String(kv.first) + " : " + String(kv.second) + "<br/>";
}
for (auto kv : info.keyValues()) { s += "\t" + String(kv.first) + " : " + String(kv.second) + "<br/>"; }
}
s += "</li>";
}
@ -245,10 +230,9 @@ void setup(void) {
MDNS.setHostProbeResultCallback(hostProbeResult);
// Init the (currently empty) host domain string with 'esp8266'
if ((!MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) ||
(!MDNS.begin(pcHostDomain))) {
if ((!MDNSResponder::indexDomain(pcHostDomain, 0, "esp8266")) || (!MDNS.begin(pcHostDomain))) {
Serial.println(" Error setting up MDNS responder!");
while (1) { // STOP
while (1) { // STOP
delay(1000);
}
}
@ -265,6 +249,3 @@ void loop(void) {
// Allow MDNS processing
MDNS.update();
}

View File

@ -14,12 +14,12 @@
#ifndef APSSID
#define APSSID "your-apssid"
#define APPSK "your-password"
#define APPSK "your-password"
#endif
#ifndef STASSID
#define STASSID "your-sta"
#define STAPSK "your-password"
#define STAPSK "your-password"
#endif
// includes
@ -35,15 +35,15 @@
@brief mDNS and OTA Constants
@{
*/
#define HOSTNAME "ESP8266-OTA-" ///< Hostname. The setup function adds the Chip ID at the end.
#define HOSTNAME "ESP8266-OTA-" ///< Hostname. The setup function adds the Chip ID at the end.
/// @}
/**
@brief Default WiFi connection information.
@{
*/
const char* ap_default_ssid = APSSID; ///< Default SSID.
const char* ap_default_psk = APPSK; ///< Default PSK.
const char *ap_default_ssid = APSSID; ///< Default SSID.
const char *ap_default_psk = APPSK; ///< Default PSK.
/// @}
/// Uncomment the next line for verbose output over UART.
@ -81,9 +81,7 @@ bool loadConfig(String *ssid, String *pass) {
if (pos == -1) {
le = 1;
pos = content.indexOf("\n");
if (pos == -1) {
pos = content.indexOf("\r");
}
if (pos == -1) { pos = content.indexOf("\r"); }
}
// If there is no second line: Some information is missing.
@ -110,7 +108,7 @@ bool loadConfig(String *ssid, String *pass) {
#endif
return true;
} // loadConfig
} // loadConfig
/**
@ -135,7 +133,7 @@ bool saveConfig(String *ssid, String *pass) {
configFile.close();
return true;
} // saveConfig
} // saveConfig
/**
@ -160,7 +158,7 @@ void setup() {
// Print hostname.
Serial.println("Hostname: " + hostname);
//Serial.println(WiFi.hostname());
// Serial.println(WiFi.hostname());
// Initialize file system.
@ -170,7 +168,7 @@ void setup() {
}
// Load wifi connection information.
if (! loadConfig(&station_ssid, &station_psk)) {
if (!loadConfig(&station_ssid, &station_psk)) {
station_ssid = STASSID;
station_psk = STAPSK;
@ -196,7 +194,7 @@ void setup() {
Serial.println(WiFi.SSID());
// ... Uncomment this for debugging output.
//WiFi.printDiag(Serial);
// WiFi.printDiag(Serial);
} else {
// ... Begin with sdk config.
WiFi.begin();
@ -208,7 +206,7 @@ void setup() {
unsigned long startTime = millis();
while (WiFi.status() != WL_CONNECTED && millis() - startTime < 10000) {
Serial.write('.');
//Serial.print(WiFi.status());
// Serial.print(WiFi.status());
delay(500);
}
Serial.println();
@ -245,4 +243,3 @@ void loop() {
// Handle OTA server.
ArduinoOTA.handle();
}

View File

@ -14,12 +14,12 @@
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#define STAPSK "your-password"
#endif
const char* ssid = STASSID;
const char* ssid = STASSID;
const char* password = STAPSK;
char hostString[16] = {0};
char hostString[16] = { 0 };
void setup() {
Serial.begin(115200);
@ -43,14 +43,12 @@ void setup() {
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (!MDNS.begin(hostString)) {
Serial.println("Error setting up MDNS responder!");
}
if (!MDNS.begin(hostString)) { Serial.println("Error setting up MDNS responder!"); }
Serial.println("mDNS responder started");
MDNS.addService("esp", "tcp", 8080); // Announce esp tcp service on port 8080
MDNS.addService("esp", "tcp", 8080); // Announce esp tcp service on port 8080
Serial.println("Sending mDNS query");
int n = MDNS.queryService("esp", "tcp"); // Send out query for esp tcp services
int n = MDNS.queryService("esp", "tcp"); // Send out query for esp tcp services
Serial.println("mDNS query done");
if (n == 0) {
Serial.println("no services found");

View File

@ -22,7 +22,7 @@
#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#define STAPSK "your-password"
#endif
const char* ssid = STASSID;
@ -57,9 +57,7 @@ void setup(void) {
// we send our IP address on the WiFi network
if (!MDNS.begin("esp8266")) {
Serial.println("Error setting up MDNS responder!");
while (1) {
delay(1000);
}
while (1) { delay(1000); }
}
Serial.println("mDNS responder started");
@ -77,16 +75,12 @@ void loop(void) {
// Check if a client has connected
WiFiClient client = server.accept();
if (!client) {
return;
}
if (!client) { return; }
Serial.println("");
Serial.println("New client");
// Wait for data from client to become available
while (client.connected() && !client.available()) {
delay(1);
}
while (client.connected() && !client.available()) { delay(1); }
// Read the first line of HTTP request
String req = client.readStringUntil('\r');
@ -121,4 +115,3 @@ void loop(void) {
Serial.println("Done with client");
}

View File

@ -30,4 +30,3 @@
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_MDNS)
MDNSResponder MDNS;
#endif

View File

@ -3,15 +3,19 @@
This file is part of the esp8266 core for Arduino environment.
mDNS implementation, that supports many mDNS features like:
- Presenting a DNS-SD service to interested observers, eg. a http server by presenting _http._tcp service
- Support for multi-level compressed names in input; in output only a very simple one-leven full-name compression is implemented
- Presenting a DNS-SD service to interested observers, eg. a http server by presenting
_http._tcp service
- Support for multi-level compressed names in input; in output only a very simple one-leven
full-name compression is implemented
- Probing host and service domains for uniqueness in the local network
- Tiebreaking while probing is supported in a very minimalistic way (the 'higher' IP address wins the tiebreak)
- Tiebreaking while probing is supported in a very minimalistic way (the 'higher' IP address
wins the tiebreak)
- Announcing available services after successful probing
- Using fixed service TXT items or
- Using dynamic service TXT items for presented services (via callback)
- Remove services (and un-announcing them to the observers by sending goodbye-messages)
- Static queries for DNS-SD services (creating a fixed answer set after a certain timeout period)
- Static queries for DNS-SD services (creating a fixed answer set after a certain timeout
period)
- Dynamic queries for DNS-SD services with cached and updated answers and user notifications
- Support for multi-homed client host domains
@ -41,13 +45,13 @@
#ifndef __ESP8266MDNS_H
#define __ESP8266MDNS_H
#include "LEAmDNS.h" // LEA
#include "LEAmDNS.h" // LEA
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_MDNS)
// Maps the implementation to use to the global namespace type
using MDNSResponder = esp8266::MDNSImplementation::MDNSResponder; // LEA
using MDNSResponder = esp8266::MDNSImplementation::MDNSResponder; // LEA
extern MDNSResponder MDNS;
#endif
#endif // __ESP8266MDNS_H
#endif // __ESP8266MDNS_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -37,7 +37,7 @@ namespace MDNSImplementation
// Enable class debug functions
#define ESP_8266_MDNS_INCLUDE
//#define DEBUG_ESP_MDNS_RESPONDER
//#define DEBUG_ESP_MDNS_RESPONDER
#if !defined(DEBUG_ESP_MDNS_RESPONDER) && defined(DEBUG_ESP_MDNS)
#define DEBUG_ESP_MDNS_RESPONDER
@ -48,8 +48,9 @@ namespace MDNSImplementation
#endif
//
// If ENABLE_ESP_MDNS_RESPONDER_PASSIV_MODE is defined, the mDNS responder ignores a successful probing
// This allows to drive the responder in a environment, where 'update()' isn't called in the loop
// If ENABLE_ESP_MDNS_RESPONDER_PASSIV_MODE is defined, the mDNS responder ignores a successful
// probing This allows to drive the responder in a environment, where 'update()' isn't called in the
// loop
//#define ENABLE_ESP_MDNS_RESPONDER_PASSIV_MODE
// Enable/disable debug trace macros
@ -62,7 +63,7 @@ namespace MDNSImplementation
#ifdef DEBUG_ESP_MDNS_RESPONDER
#ifdef DEBUG_ESP_MDNS_INFO
#define DEBUG_EX_INFO(A) A
#define DEBUG_EX_INFO(A) A
#else
#define DEBUG_EX_INFO(A)
#endif
@ -72,12 +73,12 @@ namespace MDNSImplementation
#define DEBUG_EX_ERR(A)
#endif
#ifdef DEBUG_ESP_MDNS_TX
#define DEBUG_EX_TX(A) A
#define DEBUG_EX_TX(A) A
#else
#define DEBUG_EX_TX(A)
#endif
#ifdef DEBUG_ESP_MDNS_RX
#define DEBUG_EX_RX(A) A
#define DEBUG_EX_RX(A) A
#else
#define DEBUG_EX_RX(A)
#endif
@ -88,19 +89,34 @@ namespace MDNSImplementation
#define DEBUG_OUTPUT Serial
#endif
#else
#define DEBUG_EX_INFO(A) do { (void)0; } while (0)
#define DEBUG_EX_ERR(A) do { (void)0; } while (0)
#define DEBUG_EX_TX(A) do { (void)0; } while (0)
#define DEBUG_EX_RX(A) do { (void)0; } while (0)
#define DEBUG_EX_INFO(A) \
do \
{ \
(void)0; \
} while (0)
#define DEBUG_EX_ERR(A) \
do \
{ \
(void)0; \
} while (0)
#define DEBUG_EX_TX(A) \
do \
{ \
(void)0; \
} while (0)
#define DEBUG_EX_RX(A) \
do \
{ \
(void)0; \
} while (0)
#endif
/* already defined in lwIP ('lwip/prot/dns.h')
#ifdef MDNS_IP4_SUPPORT
#define DNS_MQUERY_IPV4_GROUP_INIT (IPAddress(224, 0, 0, 251)) // ip_addr_t v4group = DNS_MQUERY_IPV4_GROUP_INIT
#endif
#ifdef MDNS_IP6_SUPPORT
#define DNS_MQUERY_IPV6_GROUP_INIT IPADDR6_INIT_HOST(0xFF020000,0,0,0xFB) // ip_addr_t v6group = DNS_MQUERY_IPV6_GROUP_INIT
#endif*/
#define DNS_MQUERY_IPV4_GROUP_INIT (IPAddress(224, 0, 0, 251)) // ip_addr_t
v4group = DNS_MQUERY_IPV4_GROUP_INIT #endif #ifdef MDNS_IP6_SUPPORT #define
DNS_MQUERY_IPV6_GROUP_INIT IPADDR6_INIT_HOST(0xFF020000,0,0,0xFB) // ip_addr_t v6group =
DNS_MQUERY_IPV6_GROUP_INIT #endif*/
//#define MDNS_MULTICAST_PORT 5353
/*
@ -111,44 +127,44 @@ namespace MDNSImplementation
However, RFC 3171 seems to force 255 instead
*/
#define MDNS_MULTICAST_TTL 255/*1*/
#define MDNS_MULTICAST_TTL 255 /*1*/
/*
This is the MDNS record TTL
Host level records are set to 2min (120s)
service level records are set to 75min (4500s)
*/
#define MDNS_HOST_TTL 120
#define MDNS_SERVICE_TTL 4500
#define MDNS_HOST_TTL 120
#define MDNS_SERVICE_TTL 4500
/*
Compressed labels are flagged by the two topmost bits of the length byte being set
*/
#define MDNS_DOMAIN_COMPRESS_MARK 0xC0
#define MDNS_DOMAIN_COMPRESS_MARK 0xC0
/*
Avoid endless recursion because of malformed compressed labels
*/
#define MDNS_DOMAIN_MAX_REDIRCTION 6
#define MDNS_DOMAIN_MAX_REDIRCTION 6
/*
Default service priority and weight in SRV answers
*/
#define MDNS_SRV_PRIORITY 0
#define MDNS_SRV_WEIGHT 0
#define MDNS_SRV_PRIORITY 0
#define MDNS_SRV_WEIGHT 0
/*
Delay between and number of probes for host and service domains
Delay between and number of announces for host and service domains
Delay between and number of service queries; the delay is multiplied by the resent number in '_checkServiceQueryCache'
Delay between and number of service queries; the delay is multiplied by the resent number in
'_checkServiceQueryCache'
*/
#define MDNS_PROBE_DELAY 250
#define MDNS_PROBE_COUNT 3
#define MDNS_ANNOUNCE_DELAY 1000
#define MDNS_ANNOUNCE_COUNT 8
#define MDNS_PROBE_DELAY 250
#define MDNS_PROBE_COUNT 3
#define MDNS_ANNOUNCE_DELAY 1000
#define MDNS_ANNOUNCE_COUNT 8
#define MDNS_DYNAMIC_QUERY_RESEND_COUNT 5
#define MDNS_DYNAMIC_QUERY_RESEND_DELAY 5000
/*
Force host domain to use only lowercase letters
*/
@ -167,15 +183,14 @@ namespace MDNSImplementation
#ifdef F
#undef F
#endif
#define F(A) A
#define F(A) A
#endif
} // namespace MDNSImplementation
} // namespace MDNSImplementation
} // namespace esp8266
} // namespace esp8266
// Include the main header, so the submodlues only need to include this header
#include "LEAmDNS.h"
#endif // MDNS_PRIV_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -27,4 +27,4 @@
#include <lwip/prot/dns.h> // DNS_RRTYPE_xxx, DNS_MQUERY_PORT
#endif // MDNS_LWIPDEFS_H
#endif // MDNS_LWIPDEFS_H