Refactor to unified firmware architecture with modular configuration system

BREAKING CHANGE: Replace separate anchor/tag firmware with single configurable codebase

## Major Changes
- **Unified Firmware**: Single main.cpp replaces main_anchor.cpp and main_tag.cpp
- **Modular Config**: Organized configuration system in src/config/ directory
- **Dynamic Behavior**: Device behavior determined by build flags at compile time
- **Simplified Builds**: Reduced from 8+ environments to 3 core environments

## New Architecture
- src/main.cpp - Single firmware with config-driven behavior
- src/config/device_config.h - Device role detection and unified behavior
- src/config/anchor_config.h - Anchor-specific settings (positioning, communication)
- src/config/tag_config.h - Tag-specific settings (USB streaming, coordinate collection)
- src/config/positioning_config.h - Distributed positioning algorithm framework

## Build System Improvements
- Simplified platformio.ini (anchor/tag/debug environments)
- Support for custom device ID and network via PLATFORMIO_BUILD_FLAGS
- Same firmware for all devices, behavior configured at compile time
- Easy device configuration: set PLATFORMIO_BUILD_FLAGS=-DUWB_INDEX=5 -DNETWORK_ID=2000

## Technical Benefits
- Reduced code duplication from ~350 lines to unified ~200 lines
- Consistent behavior across device types
- Easier maintenance with single codebase
- Framework ready for distributed positioning algorithm implementation
- Modular configuration system for future algorithm expansion

## Positioning Framework Ready
- Anchor discovery protocol framework established
- Inter-anchor communication configuration ready
- Position calculation algorithm structure in place
- Coordinate storage and validation system configured
- Tag coordinate collection and USB streaming framework prepared

## Testing
-  Anchor build successful (325KB flash usage)
-  Tag build successful (325KB flash usage)
-  Custom device ID/network configuration working
-  UWB initialization sequence fixed for active networks
This commit is contained in:
martin 2025-08-21 21:24:38 +02:00
commit a2e404ec0f
11 changed files with 589 additions and 387 deletions

View file

@ -19,16 +19,22 @@ Ultra-wideband (UWB) positioning system using ESP32-S3 and Makerfabs UWB modules
**Hardware:** [Makerfabs MaUWB ESP32-S3 UWB Module](https://www.makerfabs.com/mauwb-esp32s3-uwb-module.html) with SSD1306 OLED displays
## Environments
- `anchor`: Base station for positioning
- `tag`: Mobile device for tracking (ID 1)
- `tag2`: Mobile device for tracking (ID 2)
## Unified Architecture
**Single Firmware** - All devices use the same `main.cpp` with config-driven behavior:
- `anchor`: Base station with distributed positioning framework (default: ID=0, Network=1234)
- `tag`: Mobile tracker with coordinate collection (default: ID=1, Network=1234)
- `debug`: Development build with debug output enabled
## Build & Upload
```bash
# Build specific environment
pio run -e anchor
pio run -e tag
# Build with default settings
pio run -e anchor # Anchor ID=0, Network=1234
pio run -e tag # Tag ID=1, Network=1234
# Build with custom device ID and network
set PLATFORMIO_BUILD_FLAGS=-DUWB_INDEX=5 -DNETWORK_ID=2000
pio run -e anchor # Anchor ID=5, Network=2000
# Upload to device
pio run -e tag -t upload
@ -37,6 +43,19 @@ pio run -e tag -t upload
pio device monitor
```
## Project Structure
### Modular Configuration System
- `src/main.cpp` - Single unified firmware for all device types
- `src/config/` - Device behavior configuration
- `config.h` - Hardware pins and system settings
- `device_config.h` - Device role detection and unified behavior
- `anchor_config.h` - Anchor-specific settings (positioning, inter-anchor communication)
- `tag_config.h` - Tag-specific settings (USB streaming, coordinate collection)
- `positioning_config.h` - Distributed positioning algorithm parameters
- `lib/UWBHelper/` - Complete UWB AT command library with positioning support
- `platformio.ini` - Simplified build environments (3 instead of 8+)
## AT Command Support
Complete implementation of all AT commands from the official manual: