Files
docker-voltronic-homeassistant/sources/inverter-cli/tools.cpp
T
Pi Developer 6af9fcad7e
Build Docker Image for Raspberry Pi / build-and-push (push) Failing after 4m42s
feat(v2.0): Auto-discovery, correzione bug critici, e documentazione completa
🆕 Funzionalità Auto-Discovery
- Aggiunto metodo AutoDiscoverBufferSizes() per rilevamento automatico QPIGS/QPIRI/QMOD/QPIWS
- Supporto variabili d'ambiente (INVERTER_DEVICE, MQTT_SERVER, etc.)
- Caching persistente buffer sizes in /cache/inverter.conf.cache
- Flag -a/--auto-discover per modalità auto-detection

🐛 Bug Fixes Critici
- **Parsing interi**: Aggiunta attemptAddSettingInt() con stoi() invece di stof()
  - Fix: stof('98') = 98.0f → 97 (int), ora stoi('98') = 98 direttamente
  - Applicato a: qpiri, qpiws, qmod, qpigs
- **Thread sync**: Aggiunto ups_qpiws_changed a main loop e condizione exit poll()
  - Fix: loop principale controllava solo 3 flag su 4, causava hang
  - Fix: thread poll() non usciva in runOnce perché mancava controllo QPIWS
- **Config accuracy**: Corretti buffer sizes (qpiri: 98→103, qpiws: 36→40)
  - Rimosso sources/inverter-cli/inverter.conf che sovrascriveva config globale
  - Validato con test: inverter_poller -1 completa in 6s con JSON completo

📚 Documentazione Completa
- Creato documentation/CODE_ARCHITECTURE.md (38KB)
  - Mappa logica variabili globali
  - Flusso esecuzione main() con diagrammi ASCII
  - Sequence diagram classe cInverter (poll, query, auto-discovery)
  - Thread synchronization diagrams
  - MQTT integration bash scripts flow
  - Mappa concettuale 5-layer system architecture
  - Error handling e performance optimizations
- Organizzati file .md in documentation/ (AUTO_DISCOVERY, IMPLEMENTATION, QUICKSTART, DEBUG)
- Aggiornato README.md con sezione v2.0 e indice documentazione
- Aggiornato .github/copilot-instructions.md con novità v2.0

🔧 Miglioramenti Build & CI/CD
- Gitea Actions per build multi-arch (arm/v6, arm/v7, arm64, amd64, 386)
- Configurazione VS Code completa (tasks, launch, debug GDB)
- Script test-autodiscovery.sh e test-device.sh

 Testing Validato
- inverter_poller -1 completa in 6 secondi
- Output JSON completo con tutte le metriche
- Exit pulito senza timeout (exit code 0)
- Tutte le 4 query QMOD/QPIGS/QPIRI/QPIWS funzionanti
2026-01-25 15:00:48 +01:00

75 lines
2.6 KiB
C++

#include <mutex>
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <sys/time.h>
#include <string>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "main.h"
#include "tools.h"
std::mutex log_mutex;
void lprintf(const char *format, ...) {
// Only print if debug flag is set, else do nothing
if (debugFlag) {
va_list ap;
char fmt[2048];
//actual time
time_t rawtime;
struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
char buf[256];
strcpy(buf, asctime(timeinfo));
buf[strlen(buf)-1] = 0;
//connect with args
snprintf(fmt, sizeof(fmt), "%s %s\n", buf, format);
//put on screen:
va_start(ap, format);
vprintf(fmt, ap);
va_end(ap);
//to the logfile:
static FILE *log;
log_mutex.lock();
log = fopen(LOG_FILE, "a");
va_start(ap, format);
vfprintf(log, fmt, ap);
va_end(ap);
fclose(log);
log_mutex.unlock();
}
}
int print_help() {
printf("\nUSAGE: ./inverter_poller <args> [-r <command>], [-h | --help], [-1 | --run-once]\n\n");
printf("SUPPORTED ARGUMENTS:\n");
printf(" -r <raw-command> TX 'raw' command to the inverter\n");
printf(" -h | --help This Help Message\n");
printf(" -1 | --run-once Runs one iteration on the inverter, and then exits\n");
printf(" -d Additional debugging\n");
printf(" -a | --auto-discover Auto-detect correct buffer sizes for your inverter\n\n");
printf("RAW COMMAND EXAMPLES (see protocol manual for complete list):\n");
printf("Set output source priority POP00 (Utility first)\n");
printf(" POP01 (Solar first)\n");
printf(" POP02 (SBU)\n");
printf("Set charger priority PCP00 (Utility first)\n");
printf(" PCP01 (Solar first)\n");
printf(" PCP02 (Solar and utility)\n");
printf(" PCP03 (Solar only)\n");
printf("Set other commands PEa / PDa (Enable/disable buzzer)\n");
printf(" PEb / PDb (Enable/disable overload bypass)\n");
printf(" PEj / PDj (Enable/disable power saving)\n");
printf(" PEu / PDu (Enable/disable overload restart)\n");
printf(" PEx / PDx (Enable/disable backlight)\n\n");
return 1;
}