Replace format strings by platform independent macros

This commit is contained in:
Thomas Basler 2024-10-05 00:50:13 +02:00
parent 7dac96810f
commit 8f4b89a193
14 changed files with 32 additions and 32 deletions

View File

@ -34,7 +34,7 @@ uint32_t HoymilesRadio_CMT::getFrequencyFromChannel(const uint8_t channel) const
uint8_t HoymilesRadio_CMT::getChannelFromFrequency(const uint32_t frequency) const uint8_t HoymilesRadio_CMT::getChannelFromFrequency(const uint32_t frequency) const
{ {
if ((frequency % getChannelWidth()) != 0) { if ((frequency % getChannelWidth()) != 0) {
Hoymiles.getMessageOutput()->printf("%.3f MHz is not divisible by %d kHz!\r\n", frequency / 1000000.0, getChannelWidth()); Hoymiles.getMessageOutput()->printf("%.3f MHz is not divisible by %" PRId32 " kHz!\r\n", frequency / 1000000.0, getChannelWidth());
return 0xFF; // ERROR return 0xFF; // ERROR
} }
if (frequency < getMinFrequency() || frequency > getMaxFrequency()) { if (frequency < getMinFrequency() || frequency > getMaxFrequency()) {
@ -43,7 +43,7 @@ uint8_t HoymilesRadio_CMT::getChannelFromFrequency(const uint32_t frequency) con
return 0xFF; // ERROR return 0xFF; // ERROR
} }
if (frequency < countryDefinition.at(_countryMode).Freq_Legal_Min || frequency > countryDefinition.at(_countryMode).Freq_Legal_Max) { 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! (%d - %d MHz)\r\n", Hoymiles.getMessageOutput()->printf("!!! caution: %.2f MHz is out of region legal range! (%" PRId32 " - %" PRId32 " MHz)\r\n",
frequency / 1000000.0, frequency / 1000000.0,
static_cast<uint32_t>(countryDefinition.at(_countryMode).Freq_Legal_Min / 1e6), static_cast<uint32_t>(countryDefinition.at(_countryMode).Freq_Legal_Min / 1e6),
static_cast<uint32_t>(countryDefinition.at(_countryMode).Freq_Legal_Max / 1e6)); static_cast<uint32_t>(countryDefinition.at(_countryMode).Freq_Legal_Max / 1e6));
@ -167,7 +167,7 @@ void HoymilesRadio_CMT::loop()
// Save packet in inverter rx buffer // Save packet in inverter rx buffer
Hoymiles.getMessageOutput()->printf("RX %.2f MHz --> ", getFrequencyFromChannel(f.channel) / 1000000.0); Hoymiles.getMessageOutput()->printf("RX %.2f MHz --> ", getFrequencyFromChannel(f.channel) / 1000000.0);
dumpBuf(f.fragment, f.len, false); dumpBuf(f.fragment, f.len, false);
Hoymiles.getMessageOutput()->printf("| %d dBm\r\n", f.rssi); Hoymiles.getMessageOutput()->printf("| %" PRId8 " dBm\r\n", f.rssi);
inv->addRxFragment(f.fragment, f.len, f.rssi); inv->addRxFragment(f.fragment, f.len, f.rssi);
} else { } else {
@ -194,9 +194,9 @@ void HoymilesRadio_CMT::setPALevel(const int8_t paLevel)
} }
if (_radio->setPALevel(paLevel)) { if (_radio->setPALevel(paLevel)) {
Hoymiles.getMessageOutput()->printf("CMT TX power set to %d dBm\r\n", paLevel); Hoymiles.getMessageOutput()->printf("CMT TX power set to %" PRId8 " dBm\r\n", paLevel);
} else { } else {
Hoymiles.getMessageOutput()->printf("CMT TX power %d dBm is not defined! (min: -10 dBm, max: 20 dBm)\r\n", paLevel); Hoymiles.getMessageOutput()->printf("CMT TX power %" PRId8 " dBm is not defined! (min: -10 dBm, max: 20 dBm)\r\n", paLevel);
} }
} }

View File

@ -76,9 +76,9 @@ void HoymilesRadio_NRF::loop()
if (nullptr != inv) { if (nullptr != inv) {
// Save packet in inverter rx buffer // Save packet in inverter rx buffer
Hoymiles.getMessageOutput()->printf("RX Channel: %d --> ", f.channel); Hoymiles.getMessageOutput()->printf("RX Channel: %" PRId8 " --> ", f.channel);
dumpBuf(f.fragment, f.len, false); dumpBuf(f.fragment, f.len, false);
Hoymiles.getMessageOutput()->printf("| %d dBm\r\n", f.rssi); Hoymiles.getMessageOutput()->printf("| %" PRId8 " dBm\r\n", f.rssi);
inv->addRxFragment(f.fragment, f.len, f.rssi); inv->addRxFragment(f.fragment, f.len, f.rssi);
} else { } else {
@ -183,7 +183,7 @@ void HoymilesRadio_NRF::sendEsbPacket(CommandAbstract& cmd)
openWritingPipe(s); openWritingPipe(s);
_radio->setRetries(3, 15); _radio->setRetries(3, 15);
Hoymiles.getMessageOutput()->printf("TX %s Channel: %d --> ", Hoymiles.getMessageOutput()->printf("TX %s Channel: %" PRId8 " --> ",
cmd.getCommandName().c_str(), _radio->getChannel()); cmd.getCommandName().c_str(), _radio->getChannel());
cmd.dumpDataPayload(Hoymiles.getMessageOutput()); cmd.dumpDataPayload(Hoymiles.getMessageOutput());
_radio->write(cmd.getDataPayload(), cmd.getDataSize()); _radio->write(cmd.getDataPayload(), cmd.getDataSize());

View File

@ -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 fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id);
const uint8_t expectedSize = _inv->Statistics()->getExpectedByteCount(); const uint8_t expectedSize = _inv->Statistics()->getExpectedByteCount();
if (fragmentsSize < expectedSize) { if (fragmentsSize < expectedSize) {
Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d, min expected size: %d\r\n", Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %" PRId8 ", min expected size: %" PRId8 "\r\n",
getCommandName().c_str(), fragmentsSize, expectedSize); getCommandName().c_str(), fragmentsSize, expectedSize);
return false; return false;

View File

@ -48,7 +48,7 @@ bool SystemConfigParaCommand::handleResponse(const fragment_t fragment[], const
const uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id); const uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id);
const uint8_t expectedSize = _inv->SystemConfigPara()->getExpectedByteCount(); const uint8_t expectedSize = _inv->SystemConfigPara()->getExpectedByteCount();
if (fragmentsSize < expectedSize) { if (fragmentsSize < expectedSize) {
Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d, min expected size: %d\r\n", Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %" PRId8 ", min expected size: %" PRId8 "\r\n",
getCommandName().c_str(), fragmentsSize, expectedSize); getCommandName().c_str(), fragmentsSize, expectedSize);
return false; return false;

View File

@ -215,7 +215,7 @@ void InverterAbstract::addRxFragment(const uint8_t fragment[], const uint8_t len
} }
if (fragmentId >= MAX_RF_FRAGMENT_COUNT) { if (fragmentId >= MAX_RF_FRAGMENT_COUNT) {
Hoymiles.getMessageOutput()->printf("ERROR: fragment id %d is too large for buffer and ignored\r\n", fragmentId); Hoymiles.getMessageOutput()->printf("ERROR: fragment id %" PRId8 " is too large for buffer and ignored\r\n", fragmentId);
return; return;
} }

View File

@ -87,7 +87,7 @@ void DisplayGraphicDiagramClass::redraw(uint8_t screenSaverOffsetX, uint8_t xPos
if (maxWatts > 999) { if (maxWatts > 999) {
snprintf(fmtText, sizeof(fmtText), "%2.1fkW", maxWatts / 1000); snprintf(fmtText, sizeof(fmtText), "%2.1fkW", maxWatts / 1000);
} else { } else {
snprintf(fmtText, sizeof(fmtText), "%dW", static_cast<uint16_t>(maxWatts)); snprintf(fmtText, sizeof(fmtText), "%" PRId16 "W", static_cast<uint16_t>(maxWatts));
} }
if (isFullscreen) { if (isFullscreen) {

View File

@ -218,7 +218,7 @@ void MqttHandleInverterClass::onMqttMessage(Topic t, const espMqttClientTypes::M
case Topic::Power: case Topic::Power:
// Turn inverter on or off // Turn inverter on or off
MessageOutput.printf("Set inverter power to: %d\r\n", static_cast<int32_t>(payload_val)); MessageOutput.printf("Set inverter power to: %" PRId32 "\r\n", static_cast<int32_t>(payload_val));
inv->sendPowerControlRequest(static_cast<int32_t>(payload_val) > 0); inv->sendPowerControlRequest(static_cast<int32_t>(payload_val) > 0);
break; break;

View File

@ -95,7 +95,7 @@ void NetworkSettingsClass::NetworkEvent(const WiFiEvent_t event, WiFiEventInfo_t
break; break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
// Reason codes can be found here: https://github.com/espressif/esp-idf/blob/5454d37d496a8c58542eb450467471404c606501/components/esp_wifi/include/esp_wifi_types_generic.h#L79-L141 // Reason codes can be found here: https://github.com/espressif/esp-idf/blob/5454d37d496a8c58542eb450467471404c606501/components/esp_wifi/include/esp_wifi_types_generic.h#L79-L141
MessageOutput.printf("WiFi disconnected: %d\r\n", info.wifi_sta_disconnected.reason); MessageOutput.printf("WiFi disconnected: %" PRId8 "\r\n", info.wifi_sta_disconnected.reason);
if (_networkMode == network_mode::WiFi) { if (_networkMode == network_mode::WiFi) {
MessageOutput.println("Try reconnecting"); MessageOutput.println("Try reconnecting");
WiFi.disconnect(true, false); WiFi.disconnect(true, false);
@ -223,7 +223,7 @@ void NetworkSettingsClass::loop()
if (_adminEnabled && _adminTimeoutCounterMax > 0) { if (_adminEnabled && _adminTimeoutCounterMax > 0) {
_adminTimeoutCounter++; _adminTimeoutCounter++;
if (_adminTimeoutCounter % 10 == 0) { if (_adminTimeoutCounter % 10 == 0) {
MessageOutput.printf("Admin AP remaining seconds: %d / %d\r\n", _adminTimeoutCounter, _adminTimeoutCounterMax); MessageOutput.printf("Admin AP remaining seconds: %" PRId32 " / %" PRId32 "\r\n", _adminTimeoutCounter, _adminTimeoutCounterMax);
} }
} }
_connectTimeoutTimer++; _connectTimeoutTimer++;

View File

@ -60,7 +60,7 @@ int Utils::getTimezoneOffset()
bool Utils::checkJsonAlloc(const JsonDocument& doc, const char* function, const uint16_t line) bool Utils::checkJsonAlloc(const JsonDocument& doc, const char* function, const uint16_t line)
{ {
if (doc.overflowed()) { if (doc.overflowed()) {
MessageOutput.printf("Alloc failed: %s, %d\r\n", function, line); MessageOutput.printf("Alloc failed: %s, %" PRId16 "\r\n", function, line);
return false; return false;
} }

View File

@ -137,7 +137,7 @@ bool WebApiClass::sendJsonResponse(AsyncWebServerRequest* request, AsyncJsonResp
root["code"] = WebApiError::GenericInternalServerError; root["code"] = WebApiError::GenericInternalServerError;
root["type"] = "danger"; root["type"] = "danger";
response->setCode(500); response->setCode(500);
MessageOutput.printf("WebResponse failed: %s, %d\r\n", function, line); MessageOutput.printf("WebResponse failed: %s, %" PRId16 "\r\n", function, line);
ret_val = false; ret_val = false;
} }

View File

@ -49,7 +49,7 @@ void WebApiDtuClass::onDtuAdminGet(AsyncWebServerRequest* request)
// DTU Serial is read as HEX // DTU Serial is read as HEX
char buffer[sizeof(uint64_t) * 8 + 1]; char buffer[sizeof(uint64_t) * 8 + 1];
snprintf(buffer, sizeof(buffer), "%0x%08x", snprintf(buffer, sizeof(buffer), "%0" PRIx32 "%08" PRIx32,
((uint32_t)((config.Dtu.Serial >> 32) & 0xFFFFFFFF)), ((uint32_t)((config.Dtu.Serial >> 32) & 0xFFFFFFFF)),
((uint32_t)(config.Dtu.Serial & 0xFFFFFFFF))); ((uint32_t)(config.Dtu.Serial & 0xFFFFFFFF)));
root["serial"] = buffer; root["serial"] = buffer;

View File

@ -45,7 +45,7 @@ void WebApiInverterClass::onInverterList(AsyncWebServerRequest* request)
// Inverter Serial is read as HEX // Inverter Serial is read as HEX
char buffer[sizeof(uint64_t) * 8 + 1]; char buffer[sizeof(uint64_t) * 8 + 1];
snprintf(buffer, sizeof(buffer), "%0x%08x", snprintf(buffer, sizeof(buffer), "%0" PRIx32 "%08" PRIx32,
((uint32_t)((config.Inverter[i].Serial >> 32) & 0xFFFFFFFF)), ((uint32_t)((config.Inverter[i].Serial >> 32) & 0xFFFFFFFF)),
((uint32_t)(config.Inverter[i].Serial & 0xFFFFFFFF))); ((uint32_t)(config.Inverter[i].Serial & 0xFFFFFFFF)));
obj["serial"] = buffer; obj["serial"] = buffer;

View File

@ -42,23 +42,23 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques
stream->print("# HELP opendtu_heap_size System memory size\n"); stream->print("# HELP opendtu_heap_size System memory size\n");
stream->print("# TYPE opendtu_heap_size gauge\n"); stream->print("# TYPE opendtu_heap_size gauge\n");
stream->printf("opendtu_heap_size %zu\n", ESP.getHeapSize()); stream->printf("opendtu_heap_size %" PRId32 "\n", ESP.getHeapSize());
stream->print("# HELP opendtu_free_heap_size System free memory\n"); stream->print("# HELP opendtu_free_heap_size System free memory\n");
stream->print("# TYPE opendtu_free_heap_size gauge\n"); stream->print("# TYPE opendtu_free_heap_size gauge\n");
stream->printf("opendtu_free_heap_size %zu\n", ESP.getFreeHeap()); stream->printf("opendtu_free_heap_size %" PRId32 "\n", ESP.getFreeHeap());
stream->print("# HELP opendtu_biggest_heap_block Biggest free heap block\n"); stream->print("# HELP opendtu_biggest_heap_block Biggest free heap block\n");
stream->print("# TYPE opendtu_biggest_heap_block gauge\n"); stream->print("# TYPE opendtu_biggest_heap_block gauge\n");
stream->printf("opendtu_biggest_heap_block %zu\n", ESP.getMaxAllocHeap()); stream->printf("opendtu_biggest_heap_block %" PRId32 "\n", ESP.getMaxAllocHeap());
stream->print("# HELP opendtu_heap_min_free Minimum free memory since boot\n"); stream->print("# HELP opendtu_heap_min_free Minimum free memory since boot\n");
stream->print("# TYPE opendtu_heap_min_free gauge\n"); stream->print("# TYPE opendtu_heap_min_free gauge\n");
stream->printf("opendtu_heap_min_free %zu\n", ESP.getMinFreeHeap()); stream->printf("opendtu_heap_min_free %" PRId32 "\n", ESP.getMinFreeHeap());
stream->print("# HELP wifi_rssi WiFi RSSI\n"); stream->print("# HELP wifi_rssi WiFi RSSI\n");
stream->print("# TYPE wifi_rssi gauge\n"); stream->print("# TYPE wifi_rssi gauge\n");
stream->printf("wifi_rssi %d\n", WiFi.RSSI()); stream->printf("wifi_rssi %" PRId8 "\n", WiFi.RSSI());
stream->print("# HELP wifi_station WiFi Station info\n"); stream->print("# HELP wifi_station WiFi Station info\n");
stream->print("# TYPE wifi_station gauge\n"); stream->print("# TYPE wifi_station gauge\n");
@ -73,14 +73,14 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques
stream->print("# HELP opendtu_last_update last update from inverter in s\n"); stream->print("# HELP opendtu_last_update last update from inverter in s\n");
stream->print("# TYPE opendtu_last_update gauge\n"); stream->print("# TYPE opendtu_last_update gauge\n");
} }
stream->printf("opendtu_last_update{serial=\"%s\",unit=\"%d\",name=\"%s\"} %d\n", stream->printf("opendtu_last_update{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\"} %" PRId32 "\n",
serial.c_str(), i, name, inv->Statistics()->getLastUpdate() / 1000); serial.c_str(), i, name, inv->Statistics()->getLastUpdate() / 1000);
if (i == 0) { if (i == 0) {
stream->print("# HELP opendtu_inverter_limit_relative current relative limit of the inverter\n"); stream->print("# HELP opendtu_inverter_limit_relative current relative limit of the inverter\n");
stream->print("# TYPE opendtu_inverter_limit_relative gauge\n"); stream->print("# TYPE opendtu_inverter_limit_relative gauge\n");
} }
stream->printf("opendtu_inverter_limit_relative{serial=\"%s\",unit=\"%d\",name=\"%s\"} %f\n", stream->printf("opendtu_inverter_limit_relative{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\"} %f\n",
serial.c_str(), i, name, inv->SystemConfigPara()->getLimitPercent() / 100.0); serial.c_str(), i, name, inv->SystemConfigPara()->getLimitPercent() / 100.0);
if (inv->DevInfo()->getMaxPower() > 0) { if (inv->DevInfo()->getMaxPower() > 0) {
@ -88,7 +88,7 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques
stream->print("# HELP opendtu_inverter_limit_absolute current relative limit of the inverter\n"); stream->print("# HELP opendtu_inverter_limit_absolute current relative limit of the inverter\n");
stream->print("# TYPE opendtu_inverter_limit_absolute gauge\n"); stream->print("# TYPE opendtu_inverter_limit_absolute gauge\n");
} }
stream->printf("opendtu_inverter_limit_absolute{serial=\"%s\",unit=\"%d\",name=\"%s\"} %f\n", stream->printf("opendtu_inverter_limit_absolute{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\"} %f\n",
serial.c_str(), i, name, inv->SystemConfigPara()->getLimitPercent() * inv->DevInfo()->getMaxPower() / 100.0); serial.c_str(), i, name, inv->SystemConfigPara()->getLimitPercent() * inv->DevInfo()->getMaxPower() / 100.0);
} }
@ -126,7 +126,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("# HELP opendtu_%s in %s\n", chanName, inv->Statistics()->getChannelFieldUnit(type, channel, fieldId));
stream->printf("# TYPE opendtu_%s %s\n", chanName, metricName); stream->printf("# TYPE opendtu_%s %s\n", chanName, metricName);
} }
stream->printf("opendtu_%s{serial=\"%s\",unit=\"%d\",name=\"%s\",type=\"%s\",channel=\"%d\"} %s\n", stream->printf("opendtu_%s{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\",type=\"%s\",channel=\"%d\"} %s\n",
chanName, chanName,
serial.c_str(), serial.c_str(),
idx, idx,
@ -150,7 +150,7 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri
stream->print("# HELP opendtu_PanelInfo panel information\n"); stream->print("# HELP opendtu_PanelInfo panel information\n");
stream->print("# TYPE opendtu_PanelInfo gauge\n"); stream->print("# TYPE opendtu_PanelInfo gauge\n");
} }
stream->printf("opendtu_PanelInfo{serial=\"%s\",unit=\"%d\",name=\"%s\",channel=\"%d\",panelname=\"%s\"} 1\n", stream->printf("opendtu_PanelInfo{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\",channel=\"%d\",panelname=\"%s\"} 1\n",
serial.c_str(), serial.c_str(),
idx, idx,
inv->name(), inv->name(),
@ -161,7 +161,7 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri
stream->print("# HELP opendtu_MaxPower panel maximum output power\n"); stream->print("# HELP opendtu_MaxPower panel maximum output power\n");
stream->print("# TYPE opendtu_MaxPower gauge\n"); stream->print("# TYPE opendtu_MaxPower gauge\n");
} }
stream->printf("opendtu_MaxPower{serial=\"%s\",unit=\"%d\",name=\"%s\",channel=\"%d\"} %d\n", stream->printf("opendtu_MaxPower{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\",channel=\"%d\"} %d\n",
serial.c_str(), serial.c_str(),
idx, idx,
inv->name(), inv->name(),
@ -172,7 +172,7 @@ void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, const Stri
stream->print("# HELP opendtu_YieldTotalOffset panel yield offset (for used inverters)\n"); stream->print("# HELP opendtu_YieldTotalOffset panel yield offset (for used inverters)\n");
stream->print("# TYPE opendtu_YieldTotalOffset gauge\n"); stream->print("# TYPE opendtu_YieldTotalOffset gauge\n");
} }
stream->printf("opendtu_YieldTotalOffset{serial=\"%s\",unit=\"%d\",name=\"%s\",channel=\"%d\"} %f\n", stream->printf("opendtu_YieldTotalOffset{serial=\"%s\",unit=\"%" PRId8 "\",name=\"%s\",channel=\"%" PRId16 "\"} %f\n",
serial.c_str(), serial.c_str(),
idx, idx,
inv->name(), inv->name(),

View File

@ -153,7 +153,7 @@ void setup()
if (config.Dtu.Serial == DTU_SERIAL) { if (config.Dtu.Serial == DTU_SERIAL) {
MessageOutput.print("generate serial based on ESP chip id: "); MessageOutput.print("generate serial based on ESP chip id: ");
const uint64_t dtuId = Utils::generateDtuSerial(); const uint64_t dtuId = Utils::generateDtuSerial();
MessageOutput.printf("%0x%08x... ", MessageOutput.printf("%0" PRIx32 "%08" PRIx32 "... ",
((uint32_t)((dtuId >> 32) & 0xFFFFFFFF)), ((uint32_t)((dtuId >> 32) & 0xFFFFFFFF)),
((uint32_t)(dtuId & 0xFFFFFFFF))); ((uint32_t)(dtuId & 0xFFFFFFFF)));
config.Dtu.Serial = dtuId; config.Dtu.Serial = dtuId;