Skip to content

Commit 1b05676

Browse files
refactor(lx200): modernize API with string_view and simplify RACoordinate
Major API improvements to the LX200 C++20 implementation: **API Modernization:** - Replace C-style const char* with std::string_view in all parsing functions - parse_ra_coordinate() - parse_dec_coordinate() - parse_latitude_coordinate() - parse_longitude_coordinate() - parse_time_value() - parse_date_value() - Remove operator!(ParseResult) - use explicit comparisons instead - Update all tests to use zassert_equal() with ParseResult::Success **Structure Optimization:** - Remove redundant 'tenths' field from RACoordinate (4 bytes → 3 bytes) - Unify low/high precision: both now use hours/minutes/seconds - Convert low precision tenths to seconds: tenths * 6 = seconds (0.1 arcminute = 6 arcseconds) - Add conversion table documentation **Implementation Improvements:** - Replace C pointer arithmetic with string_view methods - Use string_view::find() instead of custom find_char() helper - Use string_view::substr() for parsing instead of pointer manipulation - Better error handling: separate format vs range validation - Remove obsolete find_char() helper function **Benefits:** - More idiomatic modern C++ (C++17+ style) - Better type safety with string_view - Reduced memory footprint (3 bytes vs 4 bytes per RA coordinate) - Cleaner, more maintainable code - No performance regression All 56 tests passing (100% pass rate). Closes #T031 test verification phase.
1 parent f3dc591 commit 1b05676

File tree

10 files changed

+1025
-1465
lines changed

10 files changed

+1025
-1465
lines changed

OpenAstroFirmware.code-workspace

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
],
1010
"settings": {
1111
"cmake.configureOnOpen": false,
12+
"C_Cpp.default.compileCommands": [
13+
"build/compile_commands.json"
14+
],
1215
"terminal.integrated.cwd": "${workspaceFolder:OpenAstroFirmware}",
13-
"terminal.integrated.defaultProfile.linux": "zsh"
16+
"terminal.integrated.defaultProfile.linux": "zsh",
17+
"files.associations": {
18+
"string_view": "cpp"
19+
}
1420
}
1521
}

include/lx200/lx200.hpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,14 @@ enum class PrecisionMode : uint8_t {
8383
* Success = 0 for zassert_ok compatibility
8484
*/
8585
enum class ParseResult : uint8_t {
86-
Success = 0, ///< Parsing succeeded (0 for zassert_ok)
86+
Success = 0, ///< Parsing succeeded (0 for compatibility)
8787
Incomplete, ///< Need more characters
8888
ErrorInvalidFormat, ///< Format doesn't match expected pattern
8989
ErrorOutOfRange, ///< Numeric value out of valid range
9090
ErrorBufferFull, ///< Command exceeds buffer capacity
9191
ErrorGeneral ///< Other parsing error
9292
};
9393

94-
/// Enable operator! for zassert_ok
95-
constexpr bool operator!(ParseResult result) noexcept {
96-
return result == ParseResult::Success;
97-
}
98-
9994
/* ========================================================================
10095
* Coordinate Structures
10196
* ======================================================================== */
@@ -105,12 +100,18 @@ constexpr bool operator!(ParseResult result) noexcept {
105100
*
106101
* Represents celestial longitude (0h to 24h).
107102
* Format: HH:MM:SS (high) or HH:MM.T (low precision)
103+
*
104+
* Note: In low precision mode, tenths of arcminutes are converted to seconds.
105+
* Conversion: 0.1 arcminute = 6 arcseconds (1 arcmin = 60 arcsec)
106+
*
107+
* Low precision conversion table:
108+
* .0 → 0 sec .1 → 6 sec .2 → 12 sec .3 → 18 sec .4 → 24 sec
109+
* .5 → 30 sec .6 → 36 sec .7 → 42 sec .8 → 48 sec .9 → 54 sec
108110
*/
109111
struct RACoordinate {
110112
uint8_t hours; ///< 0-23 hours
111113
uint8_t minutes; ///< 0-59 minutes
112-
uint8_t seconds; ///< 0-59 seconds (or 0 in low precision)
113-
uint8_t tenths; ///< 0-9 tenths of minute (low precision only)
114+
uint8_t seconds; ///< 0-59 arcseconds (HH:MM:SS in high precision, or tenths*6 in low precision)
114115

115116
/// Compile-time validation
116117
static constexpr bool is_valid(uint8_t h, uint8_t m, uint8_t s) noexcept {
@@ -343,7 +344,7 @@ class ParserState {
343344
* @return ParseResult::Success or error code
344345
*/
345346
ParseResult parse_ra_coordinate(
346-
const char* str,
347+
std::string_view str,
347348
PrecisionMode mode,
348349
RACoordinate& coord
349350
) noexcept;
@@ -357,7 +358,7 @@ ParseResult parse_ra_coordinate(
357358
* @return ParseResult::Success or error code
358359
*/
359360
ParseResult parse_dec_coordinate(
360-
const char* str,
361+
std::string_view str,
361362
PrecisionMode mode,
362363
DECCoordinate& coord
363364
) noexcept;
@@ -370,7 +371,7 @@ ParseResult parse_dec_coordinate(
370371
* @return ParseResult::Success or error code
371372
*/
372373
ParseResult parse_latitude_coordinate(
373-
const char* str,
374+
std::string_view str,
374375
LatitudeCoordinate& coord
375376
) noexcept;
376377

@@ -382,7 +383,7 @@ ParseResult parse_latitude_coordinate(
382383
* @return ParseResult::Success or error code
383384
*/
384385
ParseResult parse_longitude_coordinate(
385-
const char* str,
386+
std::string_view str,
386387
LongitudeCoordinate& coord
387388
) noexcept;
388389

@@ -394,7 +395,7 @@ ParseResult parse_longitude_coordinate(
394395
* @return ParseResult::Success or error code
395396
*/
396397
ParseResult parse_time_value(
397-
const char* str,
398+
std::string_view str,
398399
TimeValue& time
399400
) noexcept;
400401

@@ -406,7 +407,7 @@ ParseResult parse_time_value(
406407
* @return ParseResult::Success or error code
407408
*/
408409
ParseResult parse_date_value(
409-
const char* str,
410+
std::string_view str,
410411
DateValue& date
411412
) noexcept;
412413

0 commit comments

Comments
 (0)