From 7e056ad3f91ac33db253107edca7bb6eaa4b159f Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Wed, 9 Apr 2025 18:33:47 +0200 Subject: [PATCH] Use the right format string on a lot of locations This helps for a future support of arduino framework 3 --- lib/CpuTemperature/src/CpuTemperature.cpp | 4 ++-- lib/Hoymiles/src/Hoymiles.cpp | 2 +- lib/Hoymiles/src/HoymilesRadio_CMT.cpp | 4 ++-- lib/Hoymiles/src/HoymilesRadio_NRF.cpp | 4 ++-- .../src/commands/RealTimeRunDataCommand.cpp | 2 +- .../src/commands/SystemConfigParaCommand.cpp | 2 +- .../src/inverters/InverterAbstract.cpp | 4 ++-- src/Display_Graphic_Diagram.cpp | 2 +- src/NetworkSettings.cpp | 2 +- src/Utils.cpp | 2 +- src/WebApi.cpp | 2 +- src/WebApi_prometheus.cpp | 22 +++++++++---------- src/WebApi_ws_live.cpp | 4 ++-- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/CpuTemperature/src/CpuTemperature.cpp b/lib/CpuTemperature/src/CpuTemperature.cpp index 55f5d2ad..30c0d561 100644 --- a/lib/CpuTemperature/src/CpuTemperature.cpp +++ b/lib/CpuTemperature/src/CpuTemperature.cpp @@ -33,7 +33,7 @@ float CpuTemperatureClass::read() #if defined(CONFIG_IDF_TARGET_ESP32) uint8_t raw = temprature_sens_read(); - ESP_LOGV(TAG, "Raw temperature value: %d", raw); + ESP_LOGV(TAG, "Raw temperature value: %" PRIu8, raw); temperature = (raw - 32) / 1.8f; success = (raw != 128); #elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) @@ -52,7 +52,7 @@ float CpuTemperatureClass::read() if (success && std::isfinite(temperature)) { return temperature; } else { - ESP_LOGD(TAG, "Ignoring invalid temperature (success=%d, value=%.1f)", success, temperature); + ESP_LOGD(TAG, "Ignoring invalid temperature (success=%" PRId8 ", value=%.1f)", success, temperature); return NAN; } } diff --git a/lib/Hoymiles/src/Hoymiles.cpp b/lib/Hoymiles/src/Hoymiles.cpp index 87b37cce..a8de9a04 100644 --- a/lib/Hoymiles/src/Hoymiles.cpp +++ b/lib/Hoymiles/src/Hoymiles.cpp @@ -121,7 +121,7 @@ void HoymilesClass::loop() iv->resendPowerControlRequest(); } - _messageOutput->printf("Queue size - NRF: %" PRId32 " CMT: %" PRId32 "\r\n", _radioNrf->getQueueSize(), _radioCmt->getQueueSize()); + _messageOutput->printf("Queue size - NRF: %" PRIu32 " CMT: %" PRIu32 "\r\n", _radioNrf->getQueueSize(), _radioCmt->getQueueSize()); _lastPoll = millis(); } diff --git a/lib/Hoymiles/src/HoymilesRadio_CMT.cpp b/lib/Hoymiles/src/HoymilesRadio_CMT.cpp index 1ba991b2..4463527f 100644 --- a/lib/Hoymiles/src/HoymilesRadio_CMT.cpp +++ b/lib/Hoymiles/src/HoymilesRadio_CMT.cpp @@ -34,7 +34,7 @@ uint32_t HoymilesRadio_CMT::getFrequencyFromChannel(const uint8_t channel) const uint8_t HoymilesRadio_CMT::getChannelFromFrequency(const uint32_t frequency) const { if ((frequency % getChannelWidth()) != 0) { - Hoymiles.getMessageOutput()->printf("%.3f MHz is not divisible by %" PRId32 " kHz!\r\n", frequency / 1000000.0, getChannelWidth()); + Hoymiles.getMessageOutput()->printf("%.3f MHz is not divisible by %" PRIu32 " kHz!\r\n", frequency / 1000000.0, getChannelWidth()); return 0xFF; // ERROR } if (frequency < getMinFrequency() || frequency > getMaxFrequency()) { @@ -43,7 +43,7 @@ uint8_t HoymilesRadio_CMT::getChannelFromFrequency(const uint32_t frequency) con return 0xFF; // ERROR } if (frequency < countryDefinition.at(_countryMode).Freq_Legal_Min || frequency > countryDefinition.at(_countryMode).Freq_Legal_Max) { - Hoymiles.getMessageOutput()->printf("!!! caution: %.2f MHz is out of region legal range! (%" PRId32 " - %" PRId32 " MHz)\r\n", + Hoymiles.getMessageOutput()->printf("!!! caution: %.2f MHz is out of region legal range! (%" PRIu32 " - %" PRIu32 " MHz)\r\n", frequency / 1000000.0, static_cast(countryDefinition.at(_countryMode).Freq_Legal_Min / 1e6), static_cast(countryDefinition.at(_countryMode).Freq_Legal_Max / 1e6)); diff --git a/lib/Hoymiles/src/HoymilesRadio_NRF.cpp b/lib/Hoymiles/src/HoymilesRadio_NRF.cpp index 4531aa18..a0115512 100644 --- a/lib/Hoymiles/src/HoymilesRadio_NRF.cpp +++ b/lib/Hoymiles/src/HoymilesRadio_NRF.cpp @@ -75,7 +75,7 @@ void HoymilesRadio_NRF::loop() if (nullptr != inv) { // Save packet in inverter rx buffer - Hoymiles.getMessageOutput()->printf("RX Channel: %" PRId8 " --> ", f.channel); + Hoymiles.getMessageOutput()->printf("RX Channel: %" PRIu8 " --> ", f.channel); dumpBuf(f.fragment, f.len, false); Hoymiles.getMessageOutput()->printf("| %" PRId8 " dBm\r\n", f.rssi); @@ -182,7 +182,7 @@ void HoymilesRadio_NRF::sendEsbPacket(CommandAbstract& cmd) openWritingPipe(s); _radio->setRetries(3, 15); - Hoymiles.getMessageOutput()->printf("TX %s Channel: %" PRId8 " --> ", + Hoymiles.getMessageOutput()->printf("TX %s Channel: %" PRIu8 " --> ", cmd.getCommandName().c_str(), _radio->getChannel()); cmd.dumpDataPayload(Hoymiles.getMessageOutput()); _radio->write(cmd.getDataPayload(), cmd.getDataSize()); diff --git a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp index 9f5563bf..b83fc4e9 100644 --- a/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp +++ b/lib/Hoymiles/src/commands/RealTimeRunDataCommand.cpp @@ -48,7 +48,7 @@ bool RealTimeRunDataCommand::handleResponse(const fragment_t fragment[], const u const uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id); const uint8_t expectedSize = _inv->Statistics()->getExpectedByteCount(); if (fragmentsSize < expectedSize) { - Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %" PRId8 ", min expected size: %" PRId8 "\r\n", + Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %" PRIu8 ", min expected size: %" PRIu8 "\r\n", getCommandName().c_str(), fragmentsSize, expectedSize); return false; diff --git a/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp b/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp index 70dcffa9..9df65361 100644 --- a/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp +++ b/lib/Hoymiles/src/commands/SystemConfigParaCommand.cpp @@ -48,7 +48,7 @@ bool SystemConfigParaCommand::handleResponse(const fragment_t fragment[], const const uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id); const uint8_t expectedSize = _inv->SystemConfigPara()->getExpectedByteCount(); if (fragmentsSize < expectedSize) { - Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %" PRId8 ", min expected size: %" PRId8 "\r\n", + Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %" PRIu8 ", min expected size: %" PRIu8 "\r\n", getCommandName().c_str(), fragmentsSize, expectedSize); return false; diff --git a/lib/Hoymiles/src/inverters/InverterAbstract.cpp b/lib/Hoymiles/src/inverters/InverterAbstract.cpp index 26a89c13..e02ce318 100644 --- a/lib/Hoymiles/src/inverters/InverterAbstract.cpp +++ b/lib/Hoymiles/src/inverters/InverterAbstract.cpp @@ -13,7 +13,7 @@ InverterAbstract::InverterAbstract(HoymilesRadio* radio, const uint64_t serial) _radio = radio; char serial_buff[sizeof(uint64_t) * 8 + 1]; - snprintf(serial_buff, sizeof(serial_buff), "%0x%08x", + snprintf(serial_buff, sizeof(serial_buff), "%0" PRIx32 "%08" PRIx32, static_cast((serial >> 32) & 0xFFFFFFFF), static_cast(serial & 0xFFFFFFFF)); _serialString = serial_buff; @@ -215,7 +215,7 @@ void InverterAbstract::addRxFragment(const uint8_t fragment[], const uint8_t len } if (fragmentId >= MAX_RF_FRAGMENT_COUNT) { - Hoymiles.getMessageOutput()->printf("ERROR: fragment id %" PRId8 " is too large for buffer and ignored\r\n", fragmentId); + Hoymiles.getMessageOutput()->printf("ERROR: fragment id %" PRIu8 " is too large for buffer and ignored\r\n", fragmentId); return; } diff --git a/src/Display_Graphic_Diagram.cpp b/src/Display_Graphic_Diagram.cpp index fb0b68fe..0902852f 100644 --- a/src/Display_Graphic_Diagram.cpp +++ b/src/Display_Graphic_Diagram.cpp @@ -87,7 +87,7 @@ void DisplayGraphicDiagramClass::redraw(uint8_t screenSaverOffsetX, uint8_t xPos if (maxWatts > 999) { snprintf(fmtText, sizeof(fmtText), "%2.1fkW", maxWatts / 1000); } else { - snprintf(fmtText, sizeof(fmtText), "%" PRId16 "W", static_cast(maxWatts)); + snprintf(fmtText, sizeof(fmtText), "%" PRIu16 "W", static_cast(maxWatts)); } if (isFullscreen) { diff --git a/src/NetworkSettings.cpp b/src/NetworkSettings.cpp index c8a49ec8..90eeded9 100644 --- a/src/NetworkSettings.cpp +++ b/src/NetworkSettings.cpp @@ -226,7 +226,7 @@ void NetworkSettingsClass::loop() if (_adminEnabled && _adminTimeoutCounterMax > 0) { _adminTimeoutCounter++; if (_adminTimeoutCounter % 10 == 0) { - MessageOutput.printf("Admin AP remaining seconds: %" PRId32 " / %" PRId32 "\r\n", _adminTimeoutCounter, _adminTimeoutCounterMax); + MessageOutput.printf("Admin AP remaining seconds: %" PRIu32 " / %" PRIu32 "\r\n", _adminTimeoutCounter, _adminTimeoutCounterMax); } } _connectTimeoutTimer++; diff --git a/src/Utils.cpp b/src/Utils.cpp index c567ec11..f43e8e38 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -61,7 +61,7 @@ int Utils::getTimezoneOffset() bool Utils::checkJsonAlloc(const JsonDocument& doc, const char* function, const uint16_t line) { if (doc.overflowed()) { - MessageOutput.printf("Alloc failed: %s, %" PRId16 "\r\n", function, line); + MessageOutput.printf("Alloc failed: %s, %" PRIu16 "\r\n", function, line); return false; } diff --git a/src/WebApi.cpp b/src/WebApi.cpp index 835a98dc..23bfa3e9 100644 --- a/src/WebApi.cpp +++ b/src/WebApi.cpp @@ -138,7 +138,7 @@ bool WebApiClass::sendJsonResponse(AsyncWebServerRequest* request, AsyncJsonResp root["code"] = WebApiError::GenericInternalServerError; root["type"] = "danger"; response->setCode(500); - MessageOutput.printf("WebResponse failed: %s, %" PRId16 "\r\n", function, line); + MessageOutput.printf("WebResponse failed: %s, %" PRIu16 "\r\n", function, line); ret_val = false; } diff --git a/src/WebApi_prometheus.cpp b/src/WebApi_prometheus.cpp index 198ecaec..1d785b49 100644 --- a/src/WebApi_prometheus.cpp +++ b/src/WebApi_prometheus.cpp @@ -44,19 +44,19 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques stream->print("# HELP opendtu_heap_size System memory size\n"); stream->print("# TYPE opendtu_heap_size gauge\n"); - stream->printf("opendtu_heap_size %" PRId32 "\n", ESP.getHeapSize()); + stream->printf("opendtu_heap_size %" PRIu32 "\n", ESP.getHeapSize()); stream->print("# HELP opendtu_free_heap_size System free memory\n"); stream->print("# TYPE opendtu_free_heap_size gauge\n"); - stream->printf("opendtu_free_heap_size %" PRId32 "\n", ESP.getFreeHeap()); + stream->printf("opendtu_free_heap_size %" PRIu32 "\n", ESP.getFreeHeap()); stream->print("# HELP opendtu_biggest_heap_block Biggest free heap block\n"); stream->print("# TYPE opendtu_biggest_heap_block gauge\n"); - stream->printf("opendtu_biggest_heap_block %" PRId32 "\n", ESP.getMaxAllocHeap()); + stream->printf("opendtu_biggest_heap_block %" PRIu32 "\n", ESP.getMaxAllocHeap()); stream->print("# HELP opendtu_heap_min_free Minimum free memory since boot\n"); stream->print("# TYPE opendtu_heap_min_free gauge\n"); - stream->printf("opendtu_heap_min_free %" PRId32 "\n", ESP.getMinFreeHeap()); + stream->printf("opendtu_heap_min_free %" PRIu32 "\n", ESP.getMinFreeHeap()); stream->print("# HELP wifi_rssi WiFi RSSI\n"); stream->print("# TYPE wifi_rssi gauge\n"); @@ -75,14 +75,14 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques stream->print("# HELP opendtu_last_update last update from inverter in s\n"); stream->print("# TYPE opendtu_last_update gauge\n"); } - stream->printf("opendtu_last_update{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\"} %" PRId32 "\n", + stream->printf("opendtu_last_update{serial=\"%s\",unit=\"%" PRIu8 "\",name=\"%s\"} %" PRIu32 "\n", serial.c_str(), i, name, inv->Statistics()->getLastUpdate() / 1000); if (i == 0) { stream->print("# HELP opendtu_inverter_limit_relative current relative limit of the inverter\n"); stream->print("# TYPE opendtu_inverter_limit_relative gauge\n"); } - stream->printf("opendtu_inverter_limit_relative{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\"} %f\n", + stream->printf("opendtu_inverter_limit_relative{serial=\"%s\",unit=\"%" PRIu8 "\",name=\"%s\"} %f\n", serial.c_str(), i, name, inv->SystemConfigPara()->getLimitPercent() / 100.0); if (inv->DevInfo()->getMaxPower() > 0) { @@ -90,7 +90,7 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques stream->print("# HELP opendtu_inverter_limit_absolute current relative limit of the inverter\n"); stream->print("# TYPE opendtu_inverter_limit_absolute gauge\n"); } - stream->printf("opendtu_inverter_limit_absolute{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\"} %f\n", + stream->printf("opendtu_inverter_limit_absolute{serial=\"%s\",unit=\"%" PRIu8 "\",name=\"%s\"} %f\n", serial.c_str(), i, name, inv->SystemConfigPara()->getLimitPercent() * inv->DevInfo()->getMaxPower() / 100.0); } @@ -132,7 +132,7 @@ void WebApiPrometheusClass::addField(AsyncResponseStream* stream, const String& stream->printf("# HELP opendtu_%s in %s\n", chanName, inv->Statistics()->getChannelFieldUnit(type, channel, fieldId)); stream->printf("# TYPE opendtu_%s %s\n", chanName, metricName); } - stream->printf("opendtu_%s{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\",type=\"%s\",channel=\"%d\"} %s\n", + stream->printf("opendtu_%s{serial=\"%s\",unit=\"%" PRIu8 "\",name=\"%s\",type=\"%s\",channel=\"%d\"} %s\n", chanName, serial.c_str(), idx, @@ -156,7 +156,7 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri stream->print("# HELP opendtu_PanelInfo panel information\n"); stream->print("# TYPE opendtu_PanelInfo gauge\n"); } - stream->printf("opendtu_PanelInfo{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\",channel=\"%d\",panelname=\"%s\"} 1\n", + stream->printf("opendtu_PanelInfo{serial=\"%s\",unit=\"%" PRIu8 "\",name=\"%s\",channel=\"%" PRIu8 "\",panelname=\"%s\"} 1\n", serial.c_str(), idx, inv->name(), @@ -167,7 +167,7 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri stream->print("# HELP opendtu_MaxPower panel maximum output power\n"); stream->print("# TYPE opendtu_MaxPower gauge\n"); } - stream->printf("opendtu_MaxPower{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\",channel=\"%d\"} %d\n", + stream->printf("opendtu_MaxPower{serial=\"%s\",unit=\"%" PRIu8 "\",name=\"%s\",channel=\"%" PRIu8 "\"} %" PRIu16 "\n", serial.c_str(), idx, inv->name(), @@ -178,7 +178,7 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri stream->print("# HELP opendtu_YieldTotalOffset panel yield offset (for used inverters)\n"); stream->print("# TYPE opendtu_YieldTotalOffset gauge\n"); } - stream->printf("opendtu_YieldTotalOffset{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\",channel=\"%" PRId16 "\"} %f\n", + stream->printf("opendtu_YieldTotalOffset{serial=\"%s\",unit=\"%" PRIu8 "\",name=\"%s\",channel=\"%" PRIu16 "\"} %f\n", serial.c_str(), idx, inv->name(), diff --git a/src/WebApi_ws_live.cpp b/src/WebApi_ws_live.cpp index d3e2a12d..56c8e21c 100644 --- a/src/WebApi_ws_live.cpp +++ b/src/WebApi_ws_live.cpp @@ -237,9 +237,9 @@ void WebApiWsLiveClass::addTotalField(JsonObject& root, const String& name, cons void WebApiWsLiveClass::onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) { if (type == WS_EVT_CONNECT) { - MessageOutput.printf("Websocket: [%s][%u] connect\r\n", server->url(), client->id()); + MessageOutput.printf("Websocket: [%s][%" PRIu32 "] connect\r\n", server->url(), client->id()); } else if (type == WS_EVT_DISCONNECT) { - MessageOutput.printf("Websocket: [%s][%u] disconnect\r\n", server->url(), client->id()); + MessageOutput.printf("Websocket: [%s][%" PRIu32 "] disconnect\r\n", server->url(), client->id()); } }