feat(v2.0): Auto-discovery, correzione bug critici, e documentazione completa
Build Docker Image for Raspberry Pi / build-and-push (push) Failing after 4m42s

🆕 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
This commit is contained in:
Pi Developer
2026-01-25 15:00:48 +01:00
parent ac2642639f
commit 6af9fcad7e
30 changed files with 4503 additions and 139 deletions
+33 -9
View File
@@ -65,6 +65,15 @@ void attemptAddSetting(float *addTo, string addFrom) {
}
}
void attemptAddSettingInt(int *addTo, string addFrom) {
try {
*addTo = stoi(addFrom);
} catch (exception e) {
cout << e.what() << '\n';
cout << "There's probably a string in the settings file where an int should be.\n";
}
}
void getSettingsFile(string filename) {
try {
@@ -89,14 +98,22 @@ void getSettingsFile(string filename) {
attemptAddSetting(&ampfactor, linepart2);
else if(linepart1 == "watt_factor")
attemptAddSetting(&wattfactor, linepart2);
else if(linepart1 == "qpiri")
attemptAddSetting(&qpiri, linepart2);
else if(linepart1 == "qpiws")
attemptAddSetting(&qpiws, linepart2);
else if(linepart1 == "qmod")
attemptAddSetting(&qmod, linepart2);
else if(linepart1 == "qpigs")
attemptAddSetting(&qpigs, linepart2);
else if(linepart1 == "qpiri") {
attemptAddSettingInt(&qpiri, linepart2);
if(debugFlag) printf("Parsed qpiri=%d from '%s'\n", qpiri, linepart2.c_str());
}
else if(linepart1 == "qpiws") {
attemptAddSettingInt(&qpiws, linepart2);
if(debugFlag) printf("Parsed qpiws=%d from '%s'\n", qpiws, linepart2.c_str());
}
else if(linepart1 == "qmod") {
attemptAddSettingInt(&qmod, linepart2);
if(debugFlag) printf("Parsed qmod=%d from '%s'\n", qmod, linepart2.c_str());
}
else if(linepart1 == "qpigs") {
attemptAddSettingInt(&qpigs, linepart2);
if(debugFlag) printf("Parsed qpigs=%d from '%s'\n", qpigs, linepart2.c_str());
}
else
continue;
}
@@ -180,6 +197,12 @@ int main(int argc, char* argv[]) {
bool ups_status_changed(false);
ups = new cInverter(devicename,qpiri,qpiws,qmod,qpigs);
// Auto-discovery mode to find correct buffer sizes
if(cmdArgs.cmdOptionExists("-a") || cmdArgs.cmdOptionExists("--auto-discover")) {
ups->AutoDiscoverBufferSizes();
exit(0);
}
// Logic to send 'raw commands' to the inverter..
if (!rawcmd.empty()) {
ups->ExecuteCmd(rawcmd);
@@ -200,11 +223,12 @@ int main(int argc, char* argv[]) {
ups_status_changed = false;
}
if (ups_qmod_changed && ups_qpiri_changed && ups_qpigs_changed) {
if (ups_qmod_changed && ups_qpiri_changed && ups_qpigs_changed && ups_qpiws_changed) {
ups_qmod_changed = false;
ups_qpiri_changed = false;
ups_qpigs_changed = false;
ups_qpiws_changed = false;
int mode = ups->GetMode();
string *reply1 = ups->GetQpigsStatus();