1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-24 19:42:27 +03:00

- Make each mesh backend use a unique NetworkInfo class and separate connectionQueue and latestTransmissionOutcomes vectors.

- Deprecate NetworkInfo and TransmissionResult classes.

- Add single recipient transmission methods.

- Add a getCurrentMessage method to TcpIpMeshBackend to maintain feature parity when using single recipient transmission methods.

- Increase code abstraction level in transmission methods.

- Remove use of networkIndex except for in constructors, since it can change after each scan.

- Make Espnow backend require at least BSSID to connect, and the TcpIp backend require at least SSID.

- Make printAPInfo method take NetworkInfo as argument.

- Add new TransmissionOutcome class to replace obsolete TransmissionResult.

- Add _scanMutex.

- Improve code abstraction in HelloEspnow.ino.

- Update HelloEspnow.ino example to demonstrate the new features.

- Update and improve comments.
This commit is contained in:
Anders
2019-09-18 22:26:37 +02:00
parent 2576a0912b
commit 86025c7884
19 changed files with 998 additions and 255 deletions

View File

@ -17,13 +17,14 @@
*/
#include "MeshBackendBase.h"
#include "TypeConversionFunctions.h"
#include "MutexTracker.h"
#include <assert.h>
MeshBackendBase *MeshBackendBase::apController = nullptr;
std::vector<NetworkInfo> MeshBackendBase::connectionQueue = {};
std::vector<TransmissionResult> MeshBackendBase::latestTransmissionOutcomes = {};
bool MeshBackendBase::_scanMutex = false;
bool MeshBackendBase::_printWarnings = true;
@ -231,22 +232,28 @@ bool MeshBackendBase::getAPHidden() {return _apHidden;}
bool MeshBackendBase::latestTransmissionSuccessful()
{
if(MeshBackendBase::latestTransmissionOutcomes.empty())
if(latestTransmissionOutcomes().empty())
return false;
else
for(TransmissionResult &transmissionResult : MeshBackendBase::latestTransmissionOutcomes)
if(transmissionResult.transmissionStatus != TS_TRANSMISSION_COMPLETE)
for(TransmissionOutcome &transmissionOutcome : latestTransmissionOutcomes())
if(transmissionOutcome.transmissionStatus() != TS_TRANSMISSION_COMPLETE)
return false;
return true;
}
void MeshBackendBase::scanForNetworks(bool scanAllWiFiChannels)
{
{
MutexTracker mutexTracker(_scanMutex);
if(!mutexTracker.mutexCaptured())
{
assert(false && "ERROR! Scan already in progress. Don't call scanForNetworks from callbacks as this may corrupt program state! Aborting.");
return;
}
verboseModePrint(F("Scanning... "), false);
/* Scan for APs */
connectionQueue.clear();
// If scanAllWiFiChannels is true, scanning will cause the WiFi radio to cycle through all WiFi channels.
// This means existing WiFi connections are likely to break or work poorly if done frequently.
@ -264,14 +271,20 @@ void MeshBackendBase::scanForNetworks(bool scanAllWiFiChannels)
getNetworkFilter()(n, *this); // Update the connectionQueue.
}
void MeshBackendBase::printAPInfo(const int apNetworkIndex, const String &apSSID, const int apWiFiChannel)
void MeshBackendBase::printAPInfo(const NetworkInfoBase &apNetworkInfo)
{
verboseModePrint(String(F("AP acquired: ")) + apSSID + String(F(", Ch:")) + String(apWiFiChannel) + " ", false);
if(apNetworkIndex != NETWORK_INFO_DEFAULT_INT)
String mainNetworkIdentifier = apNetworkInfo.SSID();
if(mainNetworkIdentifier == NetworkInfoBase::defaultSSID) // If SSID not provided, use BSSID instead
{
verboseModePrint("(" + String(WiFi.RSSI(apNetworkIndex)) + String(F("dBm) ")) +
(WiFi.encryptionType(apNetworkIndex) == ENC_TYPE_NONE ? String(F("open")) : ""), false);
mainNetworkIdentifier = macToString(apNetworkInfo.BSSID());
}
verboseModePrint(String(F("AP acquired: ")) + mainNetworkIdentifier + String(F(", Ch:")) + String(apNetworkInfo.wifiChannel()) + " ", false);
if(apNetworkInfo.RSSI() != NetworkInfoBase::defaultRSSI)
{
verboseModePrint("(" + String(apNetworkInfo.RSSI()) + String(F("dBm) ")) +
(apNetworkInfo.encryptionType() == ENC_TYPE_NONE ? String(F("open")) : ""), false);
}
verboseModePrint(F("... "), false);