1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2026-08-18 18:32:30 +02:00

Fix crash with reboot (GwWifi + PageNavigation)

This commit is contained in:
Norbert Walter
2026-03-01 14:52:53 +00:00
committed by norbert-walter
parent a4b99fb619
commit f3f20f40c7
3 changed files with 66 additions and 13 deletions
+28 -6
View File
@@ -132,18 +132,40 @@ void GwWifi::loop(){
{ {
LOG_DEBUG(GwLog::LOG,"wifiClient: retry connect to %s", wifiSSID->asCString()); LOG_DEBUG(GwLog::LOG,"wifiClient: retry connect to %s", wifiSSID->asCString());
// CRITICAL SECTION: WiFi-Operationen müssen serialisiert werden // Keep locked sections short to avoid cross-core stalls/WDT.
if (acquireMutex()){ if (acquireMutex()){
WiFi.disconnect(true); WiFi.disconnect(true);
delay(300);
esp_wifi_stop();
delay(100);
esp_wifi_start();
releaseMutex(); releaseMutex();
}
else{
LOG_DEBUG(GwLog::ERROR,"GwWifi: mutex timeout in loop (disconnect)");
}
delay(300);
if (acquireMutex()){
esp_err_t stopErr=esp_wifi_stop();
releaseMutex();
if (stopErr != ESP_OK){
LOG_DEBUG(GwLog::ERROR,"GwWifi: esp_wifi_stop failed: %d",(int)stopErr);
}
}
else{
LOG_DEBUG(GwLog::ERROR,"GwWifi: mutex timeout in loop (stop)");
}
delay(100);
if (acquireMutex()){
esp_err_t startErr=esp_wifi_start();
releaseMutex();
if (startErr != ESP_OK){
LOG_DEBUG(GwLog::ERROR,"GwWifi: esp_wifi_start failed: %d",(int)startErr);
}
connectInternal(); connectInternal();
} }
else{ else{
LOG_DEBUG(GwLog::ERROR,"GwWifi: mutex timeout in loop"); LOG_DEBUG(GwLog::ERROR,"GwWifi: mutex timeout in loop (start)");
} }
} }
} }
+3
View File
@@ -316,6 +316,9 @@ inline void drawMonochromeBitmap(
getdisplay().drawPixel(x + xx, y + yy, color); getdisplay().drawPixel(x + xx, y + yy, color);
} }
} }
if ((yy & 0x0F) == 0) {
yield();
}
} }
#else #else
// EPaper: just hand over to driver (expects MSBfirst horizontal) // EPaper: just hand over to driver (expects MSBfirst horizontal)
+34 -6
View File
@@ -394,8 +394,20 @@ bool showValues = false; // Show values HDT, SOG, DBT in navigation map
int numPix = json["number_pixels"] | 0; // Read number of pixels int numPix = json["number_pixels"] | 0; // Read number of pixels
imgWidth = json["width"] | 0; // Read width of image imgWidth = json["width"] | 0; // Read width of image
imgHeight = json["height"] | 0; // Read height og image imgHeight = json["height"] | 0; // Read height og image
size_t requiredBytes = 0;
if (imgWidth > 0 && imgHeight > 0){
requiredBytes = (size_t)((imgWidth + 7) / 8) * (size_t)imgHeight;
}
if (requiredBytes == 0){
LOG_DEBUG(GwLog::ERROR,"Error PageNavigation: invalid image geometry w=%d h=%d",imgWidth,imgHeight);
return PAGE_UPDATE;
}
const char* b64src = json["picture_base64"].as<const char*>(); // Read picture as Base64 content const char* b64src = json["picture_base64"].as<const char*>(); // Read picture as Base64 content
if (b64src == nullptr){
LOG_DEBUG(GwLog::ERROR,"Error PageNavigation: picture_base64 missing");
return PAGE_UPDATE;
}
size_t b64len = strlen(b64src); // Calculate length of Base64 content size_t b64len = strlen(b64src); // Calculate length of Base64 content
// Copy Base64 content in PSRAM // Copy Base64 content in PSRAM
char* b64 = (char*) heap_caps_malloc(b64len + 1, MALLOC_CAP_SPIRAM); // Allcate PSRAM for Base64 content char* b64 = (char*) heap_caps_malloc(b64len + 1, MALLOC_CAP_SPIRAM); // Allcate PSRAM for Base64 content
@@ -407,7 +419,10 @@ bool showValues = false; // Show values HDT, SOG, DBT in navigation map
// Set image buffer in PSRAM // Set image buffer in PSRAM
//size_t imgSize = getdisplay().width() * getdisplay().height(); //size_t imgSize = getdisplay().width() * getdisplay().height();
size_t imgSize = numPix; // Calculate image size size_t imgSize = (numPix > 0) ? (size_t)numPix : requiredBytes; // Calculate image size
if (imgSize < requiredBytes){
imgSize = requiredBytes;
}
uint8_t* imageData = (uint8_t*) heap_caps_malloc(imgSize, MALLOC_CAP_SPIRAM); // Allocate PSRAM for image uint8_t* imageData = (uint8_t*) heap_caps_malloc(imgSize, MALLOC_CAP_SPIRAM); // Allocate PSRAM for image
if (!imageData) { if (!imageData) {
LOG_DEBUG(GwLog::ERROR,"Error PageNavigation: PSRAM alloc image buffer failed"); LOG_DEBUG(GwLog::ERROR,"Error PageNavigation: PSRAM alloc image buffer failed");
@@ -417,17 +432,30 @@ bool showValues = false; // Show values HDT, SOG, DBT in navigation map
// Decode Base64 content to image // Decode Base64 content to image
size_t decodedSize = 0; size_t decodedSize = 0;
decoder.decodeBase64(b64, imageData, imgSize, decodedSize); bool decodeOk = decoder.decodeBase64(b64, imageData, imgSize, decodedSize);
if (!decodeOk || decodedSize < requiredBytes){
LOG_DEBUG(GwLog::ERROR,
"Error PageNavigation: decode failed (ok=%d, decoded=%u, required=%u)",
decodeOk ? 1 : 0,
(unsigned int)decodedSize,
(unsigned int)requiredBytes
);
free(b64);
free(imageData);
return PAGE_UPDATE;
}
// Copy actual navigation man to ackup map // Copy actual navigation man to ackup map
imageBackupWidth = imgWidth; imageBackupWidth = imgWidth;
imageBackupHeight = imgHeight; imageBackupHeight = imgHeight;
imageBackupSize = imgSize; imageBackupSize = imgSize;
if (decodedSize > 0) { if (decodedSize > 0 && imageBackupData != nullptr) {
memcpy(imageBackupData, imageData, decodedSize); size_t backupCapacity = (size_t)GxEPD_WIDTH * (size_t)GxEPD_HEIGHT;
imageBackupSize = decodedSize; size_t copySize = (decodedSize > backupCapacity) ? backupCapacity : decodedSize;
memcpy(imageBackupData, imageData, copySize);
imageBackupSize = copySize;
} }
hasImageBackup = true; hasImageBackup = (imageBackupData != nullptr);
lostCounter = 0; lostCounter = 0;
// Show image (navigation map) // Show image (navigation map)