Skip to content

Restructure: flatten libs into src/, decoder into src/decoder/, UI into ui/ - #1200

Merged
gskjold merged 11 commits into
mainfrom
restructure_4_first_run
Jun 12, 2026
Merged

gskjold merged 11 commits into
mainfrom
restructure_4_first_run

Conversation

@gskjold

@gskjold gskjold commented Jun 12, 2026

Copy link
Copy Markdown
Member

Project restructure that flattens the lib/* PlatformIO libraries into a single src/ tree, isolates the Arduino-free decoder into src/decoder/, and moves the Svelte app from lib/SvelteUi/app/ to ui/. This is primarily a move + build-system change; behavioral changes are limited to a few small commits noted below.

Highlights

  • lib/*/{src,include} → src/ (flat), MQTT handlers → src/mqtt/, cloud → src/cloud/, web/json → src/webserver/json/.
  • Decoder module → src/decoder/, made Arduino-free so it compiles on native (pio test -e native). Portable shims for ntohl/ntohs, Print/Stream, etc.
  • Svelte app → ui/; ui/dist is built at compile time (no longer committed) and embedded via the unified scripts/generate_includes.py.
  • CI updated: build.yml / pr-build-env.yml / release-deploy-env.yml run cd ui && npm ci && npm run build before the firmware build.

Merge / reconciliation with current main

Brought fully up to date with main (which since gained #1136, #1199, #1175, #1161, #1179):

  • C++ merged cleanly via git rename-following — the tariff counters, Iskra format, and volt-label fix all carried into src/ automatically (zero C++ conflicts).
  • UI reconciled to main's canonical Svelte 5 (Migrated user interface to Svelte 5 #1161) relocated into ui/ (build config was identical). UI rebuilt with 0 npm audit vulnerabilities.

Verification

  • esp32 build: 70.9% flash, 14.5% RAM.
  • esp8266 build: 97.3% flash (within budget), 53.6% RAM.
  • UI builds clean.

Deferred to follow-up PRs (kept out to keep this a focused structural change)

The branch's mixed-in features will land as separate PRs on the new layout, each with its own release-note line:

  • Services status tile + header indicator (+ Localazy source pipeline)
  • esp32s2psram dev target
  • Compile-time custom-MQTT connector (custom/ overlay)
  • Non-blocking LED error codes + meter-LED suppression
  • ADC fix

History note: WolfSSL / Tasmota-platform / "fix ssl" experiment commits (all net-zero add+revert pairs) were dropped during integration.

gskjold and others added 11 commits April 16, 2026 09:54
…nto ui/

- lib/AmsDecoder/ → src/decoder/ (kept isolated for testing)
- lib/MeterCommunicators/{IEC6205675,IEC6205621} → src/decoder/ (parser layer)
- Remaining lib/MeterCommunicators/ → src/
- All other flat libs → src/
- MQTT handlers → src/mqtt/
- CloudConnector, ZmartCharge → src/cloud/
- lib/SvelteUi/app → ui/
- lib/SvelteUi/{src,include} → src/
- lib/SvelteUi/json → src/webserver/json/
- Old generate_includes.py scripts renamed with _old suffix (history preserved)

No code changes in this commit — pure renames only.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Decoder headers (Arduino-free):
- Replace #include "Arduino.h" with <stdint.h>/<stddef.h> in all decoder
  headers that only needed integer types
- New byteorder.h: portable ntohl/ntohs (#if ESP8266/32 → lwip, else arpa/inet.h)
- New DebugPrint.h: portable Print/Stream interface (#if ARDUINO → real class,
  else minimal native implementation)
- DsmrParser.h: use DebugPrint.h instead of Arduino.h
- ntohll.h, Cosem.h: use byteorder.h instead of lwip/def.h

Decoder source fixes:
- Cosem.cpp: replace TimeLib.h/makeTime() with standard <time.h>/mktime()
- GcmParser.cpp: add #else return GCM_DECRYPT_FAILED stub for native builds
- DsmrParser.cpp: replace printf_P/PSTR with printf; use const char* fromHex
  overload instead of constructing Arduino String

hexutils:
- Add fromHex(uint8_t*, const char*, uint16_t) overload (no Arduino String needed)
- debugPrint: use printf("%02X") instead of print(v, HEX); guard yield() with
  #if defined(ARDUINO)

PassiveMeterCommunicator ODR fix:
- Move AUTO_BAUD_RATES definition from header to .cpp; header now declares extern
- Add AUTO_BAUD_RATES_COUNT constant

Build system:
- platformio.ini: remove all internal lib_deps; add -I flags for src subdirs;
  add [env:native] for host-based testing; add build_src_filter for esp8266
  to exclude src/cloud/ (mbedtls not available on ESP8266)
- scripts/addversion.py: output to src/generated_version.h
- scripts/generate_includes.py: new unified script replacing the three old ones;
  checks custom/ui/dist first, falls back to ui/dist
- CI workflows: update lib/SvelteUi/app → ui

Test infrastructure:
- Delete old broken test stubs (were gitignored, never tracked)
- test/stubs/lwip/def.h: redirect to <arpa/inet.h> for native builds
- test/stubs/Timezone.h: minimal stub for IEC6205675 constructor
- test/test_decoder/test_main.cpp: two real HDLC parser tests as starting point
- .gitignore: remove /test; add generated header paths and /custom/

Customization:
- custom-example/: committed template showing all overridable settings

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
All source files have been moved to src/, src/decoder/, src/mqtt/,
src/cloud/, and ui/ in the previous commits. The lib/ tree is now empty
and no longer needed.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Arduino.h was transitively pulling in <time.h>, <string.h>, <stdlib.h>,
and <stddef.h>. Now that it is removed from the decoder module, each file
must include what it uses directly:

- DataParser.h: add <stdint.h> and <time.h> (time_t in DataParserContext)
- GbtParser.h, MbusParser.h: add <stddef.h> (NULL in member initializers)
- HdlcParser.cpp: add <string.h> and <stdlib.h> (memcpy, malloc, free)
- GbtParser.cpp: fix remaining lwip/def.h → byteorder.h; add <string.h>
- MbusParser.cpp: add <string.h> and <stdlib.h> (memcpy, malloc)
- IEC6205675.cpp: fix remaining lwip/def.h → byteorder.h

Also recover firmware.html (missed in .json-only git mv) → src/webserver/json/

platformio-user.ini (not committed — gitignored):
- Added ${common.build_flags} to all dev envs so new -I flags are applied
- Removed SvelteUi and CloudConnector from lib_deps (now in src/)
- Added build_src_filter = +<*> -<cloud/> to esp8266dev

All 6 targets now build successfully.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
esbuild stripped parens from e(l) → el in 103 places of the minified
JS bundle, causing 'ReferenceError: el is not defined' at page load.
Patched all 103 occurrences of ,el, → ,e(l), in place since the
project cannot rebuild the UI without Node.js available locally.
build.yml ran a bare `pio run` which also built [env:native] (a unity test
env) as firmware, failing on EEPROM.h. Build the 6 device envs explicitly,
matching the PR matrix and release.yml. The native decoder test runs via
`pio test -e native` and is finished in a follow-up PR.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@gskjold
gskjold force-pushed the restructure_4_first_run branch from 07b3b89 to 3ca07cf Compare June 12, 2026 09:45
@github-actions

Copy link
Copy Markdown

🔧 PR Build Artifacts

Version: 3ca07cf

All environments built successfully. Download the zip files:

Artifacts expire after 7 days. View workflow run

@gskjold
gskjold merged commit c9fd6ce into main Jun 12, 2026
8 checks passed
@gskjold
gskjold deleted the restructure_4_first_run branch June 12, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant