Merge pull request #1026 from mc-hamster/wifi

Apply formatting to wifi related sections
1.2-legacy
Jm Casler 2021-12-26 15:53:42 -08:00 zatwierdzone przez GitHub
commit 4a3bdb284d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 37 dodań i 44 usunięć

Wyświetl plik

@ -27,20 +27,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "NodeDB.h" #include "NodeDB.h"
#include "Screen.h" #include "Screen.h"
#include "fonts.h" #include "fonts.h"
#include "gps/GeoCoord.h"
#include "gps/RTC.h" #include "gps/RTC.h"
#include "graphics/images.h" #include "graphics/images.h"
#include "main.h" #include "main.h"
#include "mesh-pb-constants.h" #include "mesh-pb-constants.h"
#include "mesh/Channels.h" #include "mesh/Channels.h"
#include "plugins/TextMessagePlugin.h" #include "plugins/TextMessagePlugin.h"
#include "sleep.h"
#include "target_specific.h" #include "target_specific.h"
#include "utils.h" #include "utils.h"
#include "gps/GeoCoord.h"
#include "sleep.h"
#ifndef NO_ESP32 #ifndef NO_ESP32
#include "mesh/http/WiFiAPClient.h"
#include "esp_task_wdt.h" #include "esp_task_wdt.h"
#include "mesh/http/WiFiAPClient.h"
#endif #endif
using namespace meshtastic; /** @todo remove */ using namespace meshtastic; /** @todo remove */
@ -253,10 +253,10 @@ static void drawCriticalFaultFrame(OLEDDisplay *display, OLEDDisplayUiState *sta
} }
// Ignore messages orginating from phone (from the current node 0x0) unless range test or store and forward plugin are enabled // Ignore messages orginating from phone (from the current node 0x0) unless range test or store and forward plugin are enabled
static bool shouldDrawMessage(const MeshPacket *packet) { static bool shouldDrawMessage(const MeshPacket *packet)
return packet->from != 0 && {
!radioConfig.preferences.range_test_plugin_enabled && return packet->from != 0 && !radioConfig.preferences.range_test_plugin_enabled &&
!radioConfig.preferences.store_forward_plugin_enabled; !radioConfig.preferences.store_forward_plugin_enabled;
} }
/// Draw the last text message we received /// Draw the last text message we received
@ -445,18 +445,19 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
sprintf(coordinateLine, "%2i%1c %06i %07i", geoCoord.getUTMZone(), geoCoord.getUTMBand(), sprintf(coordinateLine, "%2i%1c %06i %07i", geoCoord.getUTMZone(), geoCoord.getUTMBand(),
geoCoord.getUTMEasting(), geoCoord.getUTMNorthing()); geoCoord.getUTMEasting(), geoCoord.getUTMNorthing());
} else if (gpsFormat == GpsCoordinateFormat_GpsFormatMGRS) { // Military Grid Reference System } else if (gpsFormat == GpsCoordinateFormat_GpsFormatMGRS) { // Military Grid Reference System
sprintf(coordinateLine, "%2i%1c %1c%1c %05i %05i", geoCoord.getMGRSZone(), geoCoord.getMGRSBand(), geoCoord.getMGRSEast100k(), sprintf(coordinateLine, "%2i%1c %1c%1c %05i %05i", geoCoord.getMGRSZone(), geoCoord.getMGRSBand(),
geoCoord.getMGRSNorth100k(), geoCoord.getMGRSEasting(), geoCoord.getMGRSNorthing()); geoCoord.getMGRSEast100k(), geoCoord.getMGRSNorth100k(), geoCoord.getMGRSEasting(),
geoCoord.getMGRSNorthing());
} else if (gpsFormat == GpsCoordinateFormat_GpsFormatOLC) { // Open Location Code } else if (gpsFormat == GpsCoordinateFormat_GpsFormatOLC) { // Open Location Code
geoCoord.getOLCCode(coordinateLine); geoCoord.getOLCCode(coordinateLine);
} else if (gpsFormat == GpsCoordinateFormat_GpsFormatOSGR) { // Ordnance Survey Grid Reference } else if (gpsFormat == GpsCoordinateFormat_GpsFormatOSGR) { // Ordnance Survey Grid Reference
if (geoCoord.getOSGRE100k() == 'I' || geoCoord.getOSGRN100k() == 'I') // OSGR is only valid around the UK region if (geoCoord.getOSGRE100k() == 'I' || geoCoord.getOSGRN100k() == 'I') // OSGR is only valid around the UK region
sprintf(coordinateLine, "%s", "Out of Boundary"); sprintf(coordinateLine, "%s", "Out of Boundary");
else else
sprintf(coordinateLine, "%1c%1c %05i %05i", geoCoord.getOSGRE100k(),geoCoord.getOSGRN100k(), sprintf(coordinateLine, "%1c%1c %05i %05i", geoCoord.getOSGRE100k(), geoCoord.getOSGRN100k(),
geoCoord.getOSGREasting(), geoCoord.getOSGRNorthing()); geoCoord.getOSGREasting(), geoCoord.getOSGRNorthing());
} }
// If fixed position, display text "Fixed GPS" alternating with the coordinates. // If fixed position, display text "Fixed GPS" alternating with the coordinates.
if (radioConfig.preferences.fixed_position) { if (radioConfig.preferences.fixed_position) {
if ((millis() / 10000) % 2) { if ((millis() / 10000) % 2) {
@ -473,7 +474,7 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
char lonLine[22]; char lonLine[22];
sprintf(latLine, "%2i° %2i' %2.4f\" %1c", geoCoord.getDMSLatDeg(), geoCoord.getDMSLatMin(), geoCoord.getDMSLatSec(), sprintf(latLine, "%2i° %2i' %2.4f\" %1c", geoCoord.getDMSLatDeg(), geoCoord.getDMSLatMin(), geoCoord.getDMSLatSec(),
geoCoord.getDMSLatCP()); geoCoord.getDMSLatCP());
sprintf(lonLine, "%3i° %2i' %2.4f\" %1c", geoCoord.getDMSLonDeg(), geoCoord.getDMSLonMin(), geoCoord.getDMSLonSec(), sprintf(lonLine, "%3i° %2i' %2.4f\" %1c", geoCoord.getDMSLonDeg(), geoCoord.getDMSLonMin(), geoCoord.getDMSLonSec(),
geoCoord.getDMSLonCP()); geoCoord.getDMSLonCP());
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(latLine))) / 2, y - FONT_HEIGHT_SMALL * 1, latLine); display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(latLine))) / 2, y - FONT_HEIGHT_SMALL * 1, latLine);
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(lonLine))) / 2, y, lonLine); display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(lonLine))) / 2, y, lonLine);
@ -665,7 +666,8 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
// display direction toward node // display direction toward node
hasNodeHeading = true; hasNodeHeading = true;
Position &p = node->position; Position &p = node->position;
float d = GeoCoord::latLongToMeter(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i)); float d =
GeoCoord::latLongToMeter(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i));
if (d < 2000) if (d < 2000)
snprintf(distStr, sizeof(distStr), "%.0f m", d); snprintf(distStr, sizeof(distStr), "%.0f m", d);
else else
@ -673,7 +675,8 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
// FIXME, also keep the guess at the operators heading and add/substract // FIXME, also keep the guess at the operators heading and add/substract
// it. currently we don't do this and instead draw north up only. // it. currently we don't do this and instead draw north up only.
float bearingToOther = GeoCoord::bearing(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i)); float bearingToOther =
GeoCoord::bearing(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i));
headingRadian = bearingToOther - myHeading; headingRadian = bearingToOther - myHeading;
drawNodeHeading(display, compassX, compassY, headingRadian); drawNodeHeading(display, compassX, compassY, headingRadian);
} }
@ -915,13 +918,13 @@ int32_t Screen::runOnce()
// standard screen switching is stopped. // standard screen switching is stopped.
if (showingNormalScreen) { if (showingNormalScreen) {
// standard screen loop handling here // standard screen loop handling here
if (radioConfig.preferences.auto_screen_carousel_secs > 0 && if (radioConfig.preferences.auto_screen_carousel_secs > 0 &&
(millis() - lastScreenTransition) > (radioConfig.preferences.auto_screen_carousel_secs * 1000)) { (millis() - lastScreenTransition) > (radioConfig.preferences.auto_screen_carousel_secs * 1000)) {
DEBUG_MSG("LastScreenTransition exceeded %ums transitioning to next frame\n", (millis() - lastScreenTransition)); DEBUG_MSG("LastScreenTransition exceeded %ums transitioning to next frame\n", (millis() - lastScreenTransition));
handleOnPress(); handleOnPress();
} }
} }
// DEBUG_MSG("want fps %d, fixed=%d\n", targetFramerate, // DEBUG_MSG("want fps %d, fixed=%d\n", targetFramerate,
// ui.getUiState()->frameState); If we are scrolling we need to be called // ui.getUiState()->frameState); If we are scrolling we need to be called
// soon, otherwise just 1 fps (to save CPU) We also ask to be called twice // soon, otherwise just 1 fps (to save CPU) We also ask to be called twice
@ -1087,7 +1090,7 @@ void Screen::handlePrint(const char *text)
} }
void Screen::handleOnPress() void Screen::handleOnPress()
{ {
// If screen was off, just wake it, otherwise advance to next frame // If screen was off, just wake it, otherwise advance to next frame
// If we are in a transition, the press must have bounced, drop it. // If we are in a transition, the press must have bounced, drop it.
if (ui.getUiState()->frameState == FIXED) { if (ui.getUiState()->frameState == FIXED) {
@ -1450,7 +1453,8 @@ int Screen::handleStatusUpdate(const meshtastic::Status *arg)
return 0; return 0;
} }
int Screen::handleTextMessage(const MeshPacket *packet) { int Screen::handleTextMessage(const MeshPacket *packet)
{
if (showingNormalScreen) { if (showingNormalScreen) {
setFrames(); // Regen the list of screens (will show new text message) setFrames(); // Regen the list of screens (will show new text message)
} }

Wyświetl plik

@ -74,7 +74,7 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer)
ResourceNode *nodeJsonReport = new ResourceNode("/json/report", "GET", &handleReport); ResourceNode *nodeJsonReport = new ResourceNode("/json/report", "GET", &handleReport);
ResourceNode *nodeJsonSpiffsBrowseStatic = new ResourceNode("/json/spiffs/browse/static", "GET", &handleSpiffsBrowseStatic); ResourceNode *nodeJsonSpiffsBrowseStatic = new ResourceNode("/json/spiffs/browse/static", "GET", &handleSpiffsBrowseStatic);
ResourceNode *nodeJsonDelete = new ResourceNode("/json/spiffs/delete/static", "DELETE", &handleSpiffsDeleteStatic); ResourceNode *nodeJsonDelete = new ResourceNode("/json/spiffs/delete/static", "DELETE", &handleSpiffsDeleteStatic);
ResourceNode *nodeRoot = new ResourceNode("/*", "GET", &handleStatic); ResourceNode *nodeRoot = new ResourceNode("/*", "GET", &handleStatic);
// Secure nodes // Secure nodes
@ -106,7 +106,6 @@ void registerHandlers(HTTPServer *insecureServer, HTTPSServer *secureServer)
insecureServer->registerNode(nodeJsonDelete); insecureServer->registerNode(nodeJsonDelete);
insecureServer->registerNode(nodeJsonReport); insecureServer->registerNode(nodeJsonReport);
insecureServer->registerNode(nodeRoot); insecureServer->registerNode(nodeRoot);
} }
void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res) void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res)
@ -176,7 +175,6 @@ void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res)
res->setHeader("Access-Control-Allow-Methods", "PUT, OPTIONS"); res->setHeader("Access-Control-Allow-Methods", "PUT, OPTIONS");
res->setHeader("X-Protobuf-Schema", "https://raw.githubusercontent.com/meshtastic/Meshtastic-protobufs/master/mesh.proto"); res->setHeader("X-Protobuf-Schema", "https://raw.githubusercontent.com/meshtastic/Meshtastic-protobufs/master/mesh.proto");
if (req->getMethod() == "OPTIONS") { if (req->getMethod() == "OPTIONS") {
res->setStatusCode(204); // Success with no content res->setStatusCode(204); // Success with no content
// res->print(""); @todo remove // res->print(""); @todo remove
@ -285,7 +283,6 @@ void handleStatic(HTTPRequest *req, HTTPResponse *res)
std::string filename = "/static/" + parameter1; std::string filename = "/static/" + parameter1;
std::string filenameGzip = "/static/" + parameter1 + ".gz"; std::string filenameGzip = "/static/" + parameter1 + ".gz";
// Try to open the file from SPIFFS // Try to open the file from SPIFFS
File file; File file;

Wyświetl plik

@ -3,6 +3,4 @@
#define BoolToString(x) ((x) ? "true" : "false") #define BoolToString(x) ((x) ? "true" : "false")
void replaceAll(std::string &str, const std::string &from, const std::string &to); void replaceAll(std::string &str, const std::string &from, const std::string &to);

Wyświetl plik

@ -1,13 +1,12 @@
#include "main.h"
#include "mesh/http/WebServer.h" #include "mesh/http/WebServer.h"
#include "NodeDB.h" #include "NodeDB.h"
#include "graphics/Screen.h"
#include "main.h"
#include "mesh/http/WiFiAPClient.h" #include "mesh/http/WiFiAPClient.h"
#include "sleep.h"
#include <HTTPBodyParser.hpp> #include <HTTPBodyParser.hpp>
#include <HTTPMultipartBodyParser.hpp> #include <HTTPMultipartBodyParser.hpp>
#include <HTTPURLEncodedBodyParser.hpp> #include <HTTPURLEncodedBodyParser.hpp>
#include "sleep.h"
#include "graphics/Screen.h"
#include <WebServer.h> #include <WebServer.h>
#include <WiFi.h> #include <WiFi.h>
@ -60,10 +59,9 @@ static void handleWebResponse()
// will be ignored by the NRF boards. // will be ignored by the NRF boards.
handleDNSResponse(); handleDNSResponse();
if(secureServer) if (secureServer)
secureServer->loop(); secureServer->loop();
insecureServer->loop(); insecureServer->loop();
} }
} }
} }
@ -72,7 +70,6 @@ static void taskCreateCert(void *parameter)
{ {
prefs.begin("MeshtasticHTTPS", false); prefs.begin("MeshtasticHTTPS", false);
#if 0 #if 0
// Delete the saved certs (used in debugging) // Delete the saved certs (used in debugging)
DEBUG_MSG("Deleting any saved SSL keys ...\n"); DEBUG_MSG("Deleting any saved SSL keys ...\n");
@ -81,7 +78,6 @@ static void taskCreateCert(void *parameter)
prefs.remove("cert"); prefs.remove("cert");
#endif #endif
DEBUG_MSG("Checking if we have a previously saved SSL Certificate.\n"); DEBUG_MSG("Checking if we have a previously saved SSL Certificate.\n");
size_t pkLen = prefs.getBytesLength("PK"); size_t pkLen = prefs.getBytesLength("PK");
@ -152,11 +148,11 @@ void createSSLCert()
// jm@casler.org (Oct 2020) // jm@casler.org (Oct 2020)
xTaskCreate(taskCreateCert, /* Task function. */ xTaskCreate(taskCreateCert, /* Task function. */
"createCert", /* String with name of task. */ "createCert", /* String with name of task. */
//16384, /* Stack size in bytes. */ // 16384, /* Stack size in bytes. */
8192, /* Stack size in bytes. */ 8192, /* Stack size in bytes. */
NULL, /* Parameter passed as input of the task */ NULL, /* Parameter passed as input of the task */
16, /* Priority of the task. */ 16, /* Priority of the task. */
NULL); /* Task handle. */ NULL); /* Task handle. */
DEBUG_MSG("Waiting for SSL Cert to be generated.\n"); DEBUG_MSG("Waiting for SSL Cert to be generated.\n");
while (!isCertReady) { while (!isCertReady) {
@ -167,8 +163,8 @@ void createSSLCert()
yield(); yield();
esp_task_wdt_reset(); esp_task_wdt_reset();
if (millis() / 1000 >= 3) { if (millis() / 1000 >= 3) {
screen->setSSLFrames(); screen->setSSLFrames();
} }
} }
runLoop = false; runLoop = false;
@ -203,11 +199,11 @@ void initWebServer()
registerHandlers(insecureServer, secureServer); registerHandlers(insecureServer, secureServer);
if(secureServer) { if (secureServer) {
DEBUG_MSG("Starting Secure Web Server...\n"); DEBUG_MSG("Starting Secure Web Server...\n");
secureServer->start(); secureServer->start();
} }
DEBUG_MSG("Starting Insecure Web Server...\n"); DEBUG_MSG("Starting Insecure Web Server...\n");
insecureServer->start(); insecureServer->start();
if (insecureServer->isRunning()) { if (insecureServer->isRunning()) {
DEBUG_MSG("Web Servers Ready! :-) \n"); DEBUG_MSG("Web Servers Ready! :-) \n");

Wyświetl plik

@ -15,7 +15,6 @@ class WebServerThread : private concurrency::OSThread
WebServerThread(); WebServerThread();
protected: protected:
virtual int32_t runOnce(); virtual int32_t runOnce();
}; };

Wyświetl plik

@ -21,4 +21,3 @@ void handleDNSResponse();
bool isSoftAPForced(); bool isSoftAPForced();
uint8_t getWifiDisconnectReason(); uint8_t getWifiDisconnectReason();