Skip to content

refactor: Refactor mount calculations, enhance documentation, and add tests - #314

Open
andre-stefanov wants to merge 4 commits into
developfrom
refactor/phase-1
Open

andre-stefanov wants to merge 4 commits into
developfrom
refactor/phase-1

Conversation

@andre-stefanov

Copy link
Copy Markdown
Member

No description provided.

- Updated Mount::calculateRAandDECSteppers to utilize a new core::calculateStepperPositions function for improved clarity and maintainability.
- Introduced core::SlewGeometry and core::SlewResult structures to encapsulate parameters and results related to slewing calculations.
- Replaced direct calculations of RA and DEC stepper positions with a switch-case structure based on the selected solution from the new SlewResult.
- Enhanced coordinate formatting functions in CoordinateFormatter to accept DayTime instead of RightAscension, ensuring better type safety and clarity.
- Added unit tests for coordinate formatting and coordinate math to validate the new implementations and ensure correctness.
- Updated EEPROM layout to reflect changes in data structure and added tests to verify the integrity of the EEPROM layout.

@ClutchplateDude ClutchplateDude left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed Phase 1 end-to-end. First: the risky transformations all check out as behavior-preserving — I verified the calculateRAandDECSteppers float-rounding, the getLocalDate day-count rewrite (including the off-by-one edges), the formatRA buffer-size/abs changes, the virtual formatString dispatch, and the EEPROM enum move is byte-identical (all flags, addresses, and EEPROM.begin() still see 74 on ESP32/RP2040). Consolidating the layout into one testable header instead of the mirrored copy is a clear win.

Findings below — one real (but CI-invisible) compile break worth fixing, the rest are suggestions and nits, none blocking the direction.

Housekeeping: the branch is a few commits behind develop (espressif32 pin #317, #318, #319, 1.14.0 release) — worth a rebase before merge so CI re-runs against current develop.

🤖 Posted with Claude Code

Comment thread src/EPROMStore.cpp
#if USE_DUMMY_EEPROM == true

static uint8_t dummyEepromStorage[EEPROMStore::STORE_SIZE];
static uint8_t dummyEepromStorage[STORE_SIZE];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EEPROMStore::STORE_SIZE two lines down no longer compiles when USE_DUMMY_EEPROM is enabled. Line 20 was de-qualified in this PR, but line 25 still reads EEPROMStore::STORE_SIZE. With the enums now being aliases of hal::eeprom::*, the class no longer has a STORE_SIZE member, so building with USE_DUMMY_EEPROM true (the supported knob in Configuration_adv.hpp) fails with 'STORE_SIZE' is not a member of 'EEPROMStore'. No CI configuration exercises the dummy path, which is why the matrix stays green. Fix: drop the EEPROMStore:: prefix on line 25 as well (matching line 20).

/// @param buf output buffer, which must be large enough for the result
/// @param dec DEC value
/// @param fmt formatString format (e.g. "{d}*{m}'{s}#")
void formatDEC(char *buf, const Declination &dec, const char *fmt);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatRA got a bufSize, but formatDEC still writes unbounded. formatDEC() forwards to Declination::formatString(char*, const char*), which takes no size, and Mount::DECString() hands it scratchBuffer (char[24], Mount.hpp:673). Today's longest DEC format (" {d}@ {m}' {s}\"" → ~17 bytes max) fits, so there is no live overflow — but this is the same exposure the new bufSize parameter on formatRA was added to close. Could the size be threaded through formatString/formatDEC too? Fine as a follow-up.


// Compose the two core primitives exactly as Sidereal::calculateByDateAndTime
// does in the firmware, and return local sidereal time in hours.
static double lstHours(int year, int month, int day, float utcHours, double longitude)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lstHours() re-implements the wrapper composition, so a regression in Sidereal::calculateByDateAndTime() keeps these tests green (wrong longitude sign, dropped /15.0, swapped args — the tests pin the core primitives plus this local copy, not the firmware path). I realize the wrapper itself can't compile in the native env since it sits behind Globals.hpp/Arduino — so a cheaper way to get real coverage: move the composition into core::SiderealClock (e.g. lstHours(year, month, day, utcHours, longitude)), make Sidereal::calculateByDateAndTime() delegate to it, and test that directly. The wrapper then shrinks to a DayTime conversion. Also fine as a follow-up phase item if that fits the plan better.

Comment thread src/hal/EepromLayout.hpp
MAGIC_MARKER_ADDR = 5, // Uint8
MAGIC_MARKER_AND_FLAGS_ADDR = 4, // Alias for Uint16 access
RA_STEPS_DEGREE_ADDR = 6,
_RA_STEPS_DEGREE_ADDR_1 = 7, // Int16

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: _RA_STEPS_DEGREE_ADDR_1 and the other leading-underscore names are reserved identifiers (underscore followed by uppercase, [lex.name]), so a toolchain or vendor header may legitimately #define them — and a collision here silently rewrites an address constant. The names predate this PR, but moving them into a public HAL header and pinning them in the new tests is the natural moment to drop the underscore (e.g. RA_STEPS_DEGREE_ADDR_1). Not blocking.

Comment thread PLAN.md
3. ✅ gcovr-based **coverage reporting** in `native` env — **Done.** `scripts/test-coverage.py` appends `--coverage` to `LINKFLAGS`; `build_src_flags` carries the compile-side flag. Reports (HTML + markdown) are produced by `./scripts/test-coverage.sh`. **There is no `coverage` PlatformIO target** — `pio run -e native -t coverage` fails with "unknown target". Current: 90.2% lines, 98.2% functions, 79.6% branches (366 test cases).
4. ✅ CI workflow — **Done.** `.github/workflows/ci.yml` runs `./scripts/test-coverage.sh` (which runs `pio test -e native`, then gcovr) and publishes `coverage.md` to the step summary. Threshold gating deferred to a later phase.
5. ⬜ **ArduinoFake** as `test_lib_deps` — **NOT done.** Absent from `platformio.ini` (no `test_lib_deps` key, no ArduinoFake/FakeIt dependency). `unit_tests/test_common/ArduinoFake/` holds only six `CMakeLists.txt` files — no headers or sources — and no test uses FakeIt; all host tests use plain googletest. Required before Phase 2 can add adapter tests that fake the Arduino API.
6. ✅ Folder structure — **Done.** `src/ports/`, `src/hal/`, `src/adapters/`, `src/app/` all exist with descriptive README files (they link to `specs/plan.md`, which does not exist in the repo).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Item 6 marks folder structure ✅ Done while recording that the layer READMEs link to specs/plan.md, which doesn't exist (src/ports/README.md:35 points at ../../specs/plan.md). Since the breakage is already diagnosed here, might be worth fixing the links in the same change — repoint to PLAN.md/ARCHITECTURE.md or drop them — rather than shipping known-dead links.

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.

2 participants