Skip to content

Commit 3d76004

Browse files
Feature/lx200 (#3)
* Add AI agent instructions for OpenAstroFirmware project * Add .clang-format file for consistent code formatting * Refactor LX200 command documentation and add parser structures and functions * Refactor LX200 Library Test Suite - Updated CMakeLists.txt to rename project to lx200_lib_test and include additional test source files. - Added README.md to document the LX200 Library Test Suite, including test structure, categories, running instructions, and known limitations. - Enhanced prj.conf to enable logging, assertions, and increased stack size for complex tests. - Expanded main.c with comprehensive test cases for parser initialization, command parsing, and error handling. - Created test_coordinates.c to outline specifications for unimplemented coordinate parsing functions, including RA, Dec, Alt/Az, and time/date parsing. - Updated testcase.yaml to include relevant tags and platform allowances for the LX200 tests. * Enhance command parsing to support symbol suffixes and numeric parameters * Update documentation for OpenAstroFirmware: enhance AI agent instructions and README with setup, configuration, and build details * Fix GitHub Actions build failure: add robin_nano to platform_allow list in LX200 tests - The LX200 test configuration had robin_nano in integration_platforms but not in platform_allow - This caused Twister to error when trying to run integration tests on robin_nano platform - Added robin_nano to platform_allow list to resolve the build failure
1 parent 5f373fe commit 3d76004

File tree

15 files changed

+2651
-34
lines changed

15 files changed

+2651
-34
lines changed

.clang-format

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Note: The list of ForEachMacros can be obtained using:
4+
#
5+
# git grep -h '^#define [^[:space:]]*FOR_EACH[^[:space:]]*(' include/ \
6+
# | sed "s,^#define \([^[:space:]]*FOR_EACH[^[:space:]]*\)(.*$, - '\1'," \
7+
# | sort | uniq
8+
#
9+
# References:
10+
# - https://clang.llvm.org/docs/ClangFormatStyleOptions.html
11+
12+
---
13+
BasedOnStyle: LLVM
14+
AlignConsecutiveMacros: AcrossComments
15+
AllowShortBlocksOnASingleLine: Never
16+
AllowShortCaseLabelsOnASingleLine: false
17+
AllowShortEnumsOnASingleLine: false
18+
AllowShortFunctionsOnASingleLine: None
19+
AllowShortIfStatementsOnASingleLine: false
20+
AllowShortLoopsOnASingleLine: false
21+
AttributeMacros:
22+
- __aligned
23+
- __deprecated
24+
- __packed
25+
- __printf_like
26+
- __syscall
27+
- __syscall_always_inline
28+
- __subsystem
29+
BitFieldColonSpacing: After
30+
BreakBeforeBraces: Linux
31+
ColumnLimit: 100
32+
ConstructorInitializerIndentWidth: 8
33+
ContinuationIndentWidth: 8
34+
ForEachMacros:
35+
- 'ARRAY_FOR_EACH'
36+
- 'ARRAY_FOR_EACH_PTR'
37+
- 'FOR_EACH'
38+
- 'FOR_EACH_FIXED_ARG'
39+
- 'FOR_EACH_IDX'
40+
- 'FOR_EACH_IDX_FIXED_ARG'
41+
- 'FOR_EACH_NONEMPTY_TERM'
42+
- 'FOR_EACH_FIXED_ARG_NONEMPTY_TERM'
43+
- 'RB_FOR_EACH'
44+
- 'RB_FOR_EACH_CONTAINER'
45+
- 'SYS_DLIST_FOR_EACH_CONTAINER'
46+
- 'SYS_DLIST_FOR_EACH_CONTAINER_SAFE'
47+
- 'SYS_DLIST_FOR_EACH_NODE'
48+
- 'SYS_DLIST_FOR_EACH_NODE_SAFE'
49+
- 'SYS_SEM_LOCK'
50+
- 'SYS_SFLIST_FOR_EACH_CONTAINER'
51+
- 'SYS_SFLIST_FOR_EACH_CONTAINER_SAFE'
52+
- 'SYS_SFLIST_FOR_EACH_NODE'
53+
- 'SYS_SFLIST_FOR_EACH_NODE_SAFE'
54+
- 'SYS_SLIST_FOR_EACH_CONTAINER'
55+
- 'SYS_SLIST_FOR_EACH_CONTAINER_SAFE'
56+
- 'SYS_SLIST_FOR_EACH_NODE'
57+
- 'SYS_SLIST_FOR_EACH_NODE_SAFE'
58+
- '_WAIT_Q_FOR_EACH'
59+
- 'Z_FOR_EACH'
60+
- 'Z_FOR_EACH_ENGINE'
61+
- 'Z_FOR_EACH_EXEC'
62+
- 'Z_FOR_EACH_FIXED_ARG'
63+
- 'Z_FOR_EACH_FIXED_ARG_EXEC'
64+
- 'Z_FOR_EACH_IDX'
65+
- 'Z_FOR_EACH_IDX_EXEC'
66+
- 'Z_FOR_EACH_IDX_FIXED_ARG'
67+
- 'Z_FOR_EACH_IDX_FIXED_ARG_EXEC'
68+
- 'Z_GENLIST_FOR_EACH_CONTAINER'
69+
- 'Z_GENLIST_FOR_EACH_CONTAINER_SAFE'
70+
- 'Z_GENLIST_FOR_EACH_NODE'
71+
- 'Z_GENLIST_FOR_EACH_NODE_SAFE'
72+
- 'STRUCT_SECTION_FOREACH'
73+
- 'STRUCT_SECTION_FOREACH_ALTERNATE'
74+
- 'TYPE_SECTION_FOREACH'
75+
- 'K_SPINLOCK'
76+
- 'COAP_RESOURCE_FOREACH'
77+
- 'COAP_SERVICE_FOREACH'
78+
- 'COAP_SERVICE_FOREACH_RESOURCE'
79+
- 'HTTP_RESOURCE_FOREACH'
80+
- 'HTTP_SERVER_CONTENT_TYPE_FOREACH'
81+
- 'HTTP_SERVICE_FOREACH'
82+
- 'HTTP_SERVICE_FOREACH_RESOURCE'
83+
- 'I3C_BUS_FOR_EACH_I3CDEV'
84+
- 'I3C_BUS_FOR_EACH_I2CDEV'
85+
IfMacros:
86+
- 'CHECKIF'
87+
# Disabled for now, see bug https://github.com/zephyrproject-rtos/zephyr/issues/48520
88+
#IncludeBlocks: Regroup
89+
IncludeCategories:
90+
- Regex: '^".*\.h"$'
91+
Priority: 0
92+
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|wchar|wctype)\.h>$'
93+
Priority: 1
94+
- Regex: '^\<zephyr/.*\.h\>$'
95+
Priority: 2
96+
- Regex: '.*'
97+
Priority: 3
98+
IndentCaseLabels: false
99+
IndentGotoLabels: false
100+
IndentWidth: 8
101+
InsertBraces: true
102+
SpaceBeforeInheritanceColon: False
103+
SpaceBeforeParens: ControlStatementsExceptControlMacros
104+
SortIncludes: Never
105+
UseTab: ForContinuationAndIndentation
106+
WhitespaceSensitiveMacros:
107+
- COND_CODE_0
108+
- COND_CODE_1
109+
- IF_DISABLED
110+
- IF_ENABLED
111+
- LISTIFY
112+
- STRINGIFY
113+
- Z_STRINGIFY
114+
- DT_FOREACH_PROP_ELEM_SEP

.github/copilot-instructions.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
````instructions
2+
# OpenAstroFirmware AI Agent Instructions
3+
4+
This is firmware for DIY astronomical telescope mounts, built on Zephyr RTOS. It's a modern C++20 rewrite of the successful OpenAstroTracker v1 firmware, emphasizing maintainability and advanced features.
5+
6+
## Architecture Overview
7+
8+
**Build System**: Zephyr RTOS v4.1.0 with west build tool
9+
**Target Hardware**: MKS Robin Nano (STM32F407-based) boards
10+
**Languages**: C++20 primary, with C for low-level protocol implementations
11+
**Structure**: Dual-app architecture - `app/` (main firmware) + `lib/` (reusable components)
12+
13+
Key directories:
14+
- `app/` - Main Zephyr application with mount control logic
15+
- `lib/lx200/` - LX200 telescope protocol implementation (C)
16+
- `boards/mks/robin_nano/` - Custom board definition and device tree
17+
- `tests/` - Comprehensive test suites using Zephyr Twister
18+
- `zephyr/module.yml` - Zephyr module configuration
19+
20+
## Development Workflow
21+
22+
### Building & Testing
23+
```bash
24+
west build -b robin_nano # Standard build
25+
west build -b robin_nano -- -DEXTRA_CONF_FILE=debug.conf # Debug build
26+
west twister -T . -p robin_nano # Run all tests
27+
west twister -T tests/lib/lx200/ # Run specific test suite
28+
```
29+
30+
### Configuration Layers
31+
- **Kconfig**: `prj.conf` (base) + `debug.conf` (debug overlay)
32+
- **Device Tree**: Custom STM32F407 board in `boards/mks/robin_nano/`
33+
- **Build Configs**: Use `-DEXTRA_CONF_FILE=debug.conf` for development
34+
35+
## Code Patterns & Conventions
36+
37+
### Language Split Pattern
38+
**C++20 Application Layer** (`app/src/`):
39+
```cpp
40+
#include <mount/Mount.hpp>
41+
Mount mount; // Main astronomical mount controller
42+
```
43+
44+
**C Protocol Layer** (`lib/lx200/`):
45+
```c
46+
lx200_parser_state_t parser_state;
47+
lx200_parse_command_string(cmd_string, &command);
48+
```
49+
50+
### Logging Infrastructure
51+
Every module uses Zephyr structured logging:
52+
```cpp
53+
LOG_MODULE_REGISTER(ModuleName, CONFIG_APP_LOG_LEVEL);
54+
// Available: LOG_DBG(), LOG_INF(), LOG_WRN(), LOG_ERR()
55+
```
56+
57+
### LX200 Protocol Implementation
58+
Commands follow `:COMMAND[params]#` format. Current implementation status:
59+
- ✅ **Parser Framework**: Command parsing, family classification
60+
- ⏳ **Coordinate Functions**: All `lx200_parse_*_coordinate()` are stubs
61+
- ⏳ **Formatting Functions**: All `lx200_format_*()` are stubs
62+
63+
Example of incomplete implementation pattern:
64+
```c
65+
lx200_parse_result_t lx200_parse_ra_coordinate(const char *str, lx200_coordinate_t *coord) {
66+
LOG_WRN("Function not implemented yet");
67+
return LX200_PARSE_ERROR; // All coordinate functions are stubs
68+
}
69+
```
70+
71+
## Testing Strategy
72+
73+
### Test-Driven Development Pattern
74+
Tests serve as specifications for unimplemented features in `tests/lib/lx200/`:
75+
76+
**Working Tests** (verify current functionality):
77+
- Parser state management
78+
- Command family identification (A,B,C,D,F,G,g,H,I,L,M,P,Q,R,S,T,U)
79+
- Basic command/parameter separation
80+
81+
**Specification Tests** (currently failing, define requirements):
82+
- Coordinate parsing (RA: `HH:MM:SS`, Dec: `sDD*MM:SS`)
83+
- Time/date parsing (`HH:MM:SS`, `MM/DD/YY`)
84+
- Response formatting functions
85+
86+
Run with: `west twister -T tests/lib/lx200/`
87+
88+
### Configuration Testing
89+
Two build configurations tested via `sample.yaml`:
90+
- `app.default`: Production configuration
91+
- `app.debug`: Debug configuration with `CONFIG_APP_LOG_LEVEL_DBG=y`
92+
93+
## Project-Specific Context
94+
95+
### Astronomical Domain Knowledge
96+
- **Coordinate Systems**: RA/Dec (celestial), Alt/Az (horizontal)
97+
- **Precision Modes**: High (`HH:MM:SS`) vs Low (`HH:MM.T`) coordinate formats
98+
- **LX200 Compatibility**: Industry standard for telescope communication
99+
- **Mount Types**: Equatorial tracking, Alt-azimuth positioning
100+
101+
### Critical Implementation Details
102+
**Parameter Detection Logic** (needs improvement):
103+
```c
104+
// Current: oversimplified - only checks 'S' commands
105+
bool lx200_command_has_parameter(const char *command) {
106+
return (command[0] == 'S'); // Missing many parameter commands
107+
}
108+
```
109+
110+
**Command Parsing Edge Cases**:
111+
- Special commands: `B+`, `B-`, `F+`, `F-`, `T+`, `T-`
112+
- Rate commands: `R0` through `R9`
113+
- Library commands and GPS commands also take parameters
114+
115+
### Development Status
116+
Early development phase. Focus on:
117+
1. Implementing coordinate parsing stubs in `lib/lx200/`
118+
2. Following existing test specifications in `tests/lib/lx200/`
119+
3. Using C for protocol layer, C++20 for application layer
120+
4. Maintaining Zephyr module structure for reusability
121+
122+
When implementing new features, always check corresponding tests first to understand expected behavior and formats.
123+
124+
````

0 commit comments

Comments
 (0)