Skip to content

Complete raspberry pi cpp implementation#25

Merged
sparesparrow merged 28 commits intomainfrom
cursor/complete-raspberry-pi-cpp-implementation-gemini-3-pro-preview-5626
Dec 2, 2025
Merged

Complete raspberry pi cpp implementation#25
sparesparrow merged 28 commits intomainfrom
cursor/complete-raspberry-pi-cpp-implementation-gemini-3-pro-preview-5626

Conversation

@sparesparrow
Copy link
Owner

@sparesparrow sparesparrow commented Dec 1, 2025

Completes pending C++ features for Raspberry Pi, implementing HTTP client, FlatBuffers I/O, MQTT, TTS/STT, and a basic HTTP server to finalize platform functionality.


Open in Cursor Open in Web


Note

Finalizes Raspberry Pi C++ platform (HTTP, FlatBuffers, GPIO/MQTT, TTS/STT, web server), adds hardware bridge with Arduino LED control, introduces build/deploy scripts and docs, updates Dockerfiles, and consolidates CI into a main workflow.

  • C++ Platform (Raspberry Pi):
    • Implement CoreOrchestrator HTTP calls (libcurl), robust FlatBuffers I/O, and fixed TcpSocket/TcpListener.
    • Add HardwareControlServer using libgpiod C API and MQTT (mosquitto) with status/cleanup.
    • Extend UI adapters: voice (TTS via espeak; STT via vosk/pocketsphinx), basic HTTP web server, and mobile API.
    • New main_raspberry_pi entrypoint and comprehensive unit tests.
  • Hardware Bridge & Arduino:
    • New Python hardware bridge with Arduino LED controller + MCP server; MQTT topics and test utility.
    • Add Arduino LED firmware and deployment/usage docs.
  • Build/Deploy Tooling:
    • Bootstrap/zero-copy env, Raspberry Pi build/test/deploy scripts, and system deps installer.
    • .tool-versions, .gitignore updates.
  • Docker:
    • Module Dockerfiles (core-orchestrator, ai-audio-assistant, hardware-bridge, ai-security), edge image.
  • CI/CD:
    • Replace many workflows with unified .github/workflows/main.yml; enhance docker-multiplatform tagging/context.
  • Docs:
    • Raspberry Pi setup/quick start, deployment checklist, build summaries, error handling, and workflow refactor notes.

Written by Cursor Bugbot for commit 9c03f93. This will update automatically on new commits. Configure here.

This commit introduces several key features:
- A robust HTTP client using libcurl for network communication.
- MQTT integration for hardware control and status updates.
- Enhanced UI adapters (Web, Mobile, Voice, Text) with basic functionality.
- Improved TCP socket handling and error management.

Co-authored-by: dallheimal <dallheimal@gmail.com>
@cursor
Copy link

cursor bot commented Dec 1, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 11 commits December 1, 2025 03:22
Co-authored-by: dallheimal <dallheimal@gmail.com>
Co-authored-by: dallheimal <dallheimal@gmail.com>
This commit consolidates multiple GitHub Actions workflows into a single `main.yml` file, simplifying the CI/CD process and improving maintainability. The new workflow includes comprehensive security scanning, code quality checks, multi-platform builds, testing, and deployment.

Co-authored-by: dallheimal <dallheimal@gmail.com>
Co-authored-by: dallheimal <dallheimal@gmail.com>
Update docker tag format to use short sha and upgrade upload-artifact to v4.

Co-authored-by: dallheimal <dallheimal@gmail.com>
Co-authored-by: dallheimal <dallheimal@gmail.com>
Co-authored-by: dallheimal <dallheimal@gmail.com>
Co-authored-by: dallheimal <dallheimal@gmail.com>
@sparesparrow sparesparrow marked this pull request as ready for review December 1, 2025 16:49
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

uses: aquasecurity/trivy-action@master
with:
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/core-orchestrator:latest'
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/core-orchestrator:sha-${{ github.sha }}'
Copy link

Choose a reason for hiding this comment

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

Bug: SHA format mismatch causes image scans to fail

The Trivy vulnerability scans reference images using sha-${{ github.sha }} (full 40-character SHA), but the docker/metadata-action creates tags with type=sha,prefix=sha-,format=short which produces only 7 characters (e.g., sha-a1b2c3d). This mismatch means the security scans will never find the images they're supposed to scan, silently defeating the purpose of vulnerability scanning.

Additional Locations (1)

Fix in Cursor Fix in Web

name: 📱 Android Build
runs-on: ubuntu-latest
needs: [security]
if: contains(github.event.head_commit.message, '[android]') || contains(join(github.event.commits.*.message), 'android/') || github.event_name == 'workflow_dispatch'
Copy link

Choose a reason for hiding this comment

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

Bug: Conditional builds check messages instead of modified files

The android-build and esp32-build jobs use contains(join(github.event.commits.*.message), 'android/') which checks commit messages for the string android/, not whether files in the android/ directory were modified. The documentation and the docs job pattern suggest the intent is to trigger on file changes using *.modified. As written, these builds will only trigger if developers literally write android/ or esp32/ in their commit message, not when they actually change files in those directories.

Additional Locations (1)

Fix in Cursor Fix in Web

@sparesparrow
Copy link
Owner Author

🔧 Comprehensive Fix for PR #25 Issues

I've analyzed the Cursor Bugbot findings and identified the following issues to fix:

1. ❌ .directory File - KDE Configuration Leaked

Issue: A KDE Dolphin file manager configuration file was accidentally committed.

Fix: This file should be removed and added to .gitignore.

git rm .directory

Add to .gitignore:

# IDE and file manager configs
.directory

2. 🐛 Android/ESP32 Build Trigger Logic Bug

Issue: The conditional build triggers check commit messages for strings like android/ instead of checking if files were actually modified.

Current problematic code (.github/workflows/main.yml lines 262 & 317):

if: contains(github.event.head_commit.message, '[android]') || contains(join(github.event.commits.*.message), 'android/') || github.event_name == 'workflow_dispatch'

Problem: contains(join(github.event.commits.*.message), 'android/') checks commit messages for the literal string android/, not file path changes.

Solution: Use GitHub's built-in path filtering or paths-filter action:

Option A: Use workflow path filters (recommended, simpler):

android-build:
  name: 📱 Android Build
  runs-on: ubuntu-latest
  needs: [security]
  # Remove the complex if condition, use path filters at workflow level instead
  
# Add separate workflow trigger at top of file:
on:
  push:
    paths:
      - 'android/**'
    branches: [ main, develop, feature/* ]

Option B: Use dorny/paths-filter action (more flexible):

- uses: dorny/paths-filter@v2
  id: filter
  with:
    filters: |
      android:
        - 'android/**'
      esp32:
        - 'esp32/**'

android-build:
  if: steps.filter.outputs.android == 'true' || contains(github.event.head_commit.message, '[android]')

Recommended fix for main.yml:

Replace lines 262-263:

# OLD (broken):
if: contains(github.event.head_commit.message, '[android]') || contains(join(github.event.commits.*.message), 'android/') || github.event_name == 'workflow_dispatch'

# NEW (fixed):
if: |
  contains(github.event.head_commit.message, '[android]') || 
  github.event_name == 'workflow_dispatch' ||
  (github.event_name == 'push' && contains(github.event.head_commit.modified, 'android/')) ||
  (github.event_name == 'pull_request' && github.event.pull_request.changed_files > 0)

Similar fix needed for ESP32 build (line 317).


3. 🔐 SHA Format Mismatch in Docker Security Scans

Issue: In docker-multiplatform.yml, Trivy scans reference images with full 40-character SHAs (sha-${{ github.sha }}), but Docker tags use short 7-character SHAs (format=short). This causes security scans to fail silently.

Problematic code (.github/workflows/docker-multiplatform.yml line 412):

- name: Extract metadata
  id: meta
  uses: docker/metadata-action@v5
  with:
    tags: |
      type=sha,prefix=sha-,format=short  # ← Creates 7-char SHA
      
# Later...
- name: Run Trivy vulnerability scanner
  with:
    image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/core-orchestrator:sha-${{ github.sha }}'
    # ↑ References full 40-char SHA - IMAGE NOT FOUND!

Solution: Use consistent SHA format. Two options:

Option A: Use short SHA everywhere (recommended):

- name: Run Trivy vulnerability scanner
  uses: aquasecurity/trivy-action@master
  with:
    # Use short SHA to match the tag
    image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/core-orchestrator:sha-${{ steps.meta.outputs.version }}'
    format: 'sarif'
    output: 'trivy-core-results.sarif'

Option B: Use full SHA in both places:

# In metadata action, remove format=short:
tags: |
  type=sha,prefix=sha-  # Will use full 40-char SHA

# Trivy will now find the image:
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/core-orchestrator:sha-${{ github.sha }}'

Recommended fix: Use Option A with tag from metadata action:

# Lines 412-435 in docker-multiplatform.yml
- name: Run Trivy on Core Orchestrator
  uses: aquasecurity/trivy-action@master
  with:
    image-ref: '${{ steps.meta.outputs.tags }}'  # Use actual built tag
    format: 'sarif'
    output: 'trivy-core-results.sarif'

This affects 4 scan jobs in the workflow (lines 412-435 for all components).


4. ⚠️ Additional Issues

CodeQL C++ Build - Masks Real Failures

Line 87 in main.yml:

- name: Build C++ for CodeQL
  continue-on-error: true  # ← Hides actual build failures

Recommendation: Remove continue-on-error: true or add explicit failure notification:

- name: Build C++ for CodeQL
  id: cpp_build
  continue-on-error: true
  run: |
    # build commands...

- name: Report build status
  if: steps.cpp_build.outcome == 'failure'
  run: |
    echo "::warning::C++ build failed but continuing CodeQL analysis"

Python Dependencies - Ignores Errors

Line 96 in main.yml:

pip install -r requirements.txt || echo "Requirements install completed with warnings"

Issue: Masks real dependency installation failures.

Fix: Make failures visible:

- name: Install Python dependencies
  run: |
    pip install -r requirements.txt || {
      echo "::error::Failed to install requirements"
      exit 1
    }

🛠️ Quick Fix Commands

To fix all issues at once:

# 1. Remove .directory file
git rm .directory

# 2. Update .gitignore
echo -e "\n# IDE and file manager configs\n.directory" >> .gitignore

# 3. Commit changes
git add .gitignore
git commit -m "fix: remove KDE .directory file and update .gitignore"

# 4. Apply workflow fixes (create patch files or edit manually)
# Then commit:
git commit -am "fix: correct Android/ESP32 build triggers and Docker SHA format in workflows"

📋 Summary of Changes Needed

Issue File(s) Priority Impact
.directory file .directory, .gitignore High Repository hygiene
Build trigger logic .github/workflows/main.yml Critical Builds not running correctly
SHA format mismatch .github/workflows/docker-multiplatform.yml Critical Security scans silently failing
Error masking .github/workflows/main.yml Medium Hidden failures

Would you like me to create a branch with all these fixes applied? I can prepare the exact changes needed for all workflow files.

@sparesparrow
Copy link
Owner Author

@cursor Please apply the following fixes to this PR:

  1. Remove .directory file and update .gitignore:

    • Delete the .directory file from the repository
    • Add .directory to .gitignore under a new section "# IDE and file manager configs"
  2. Fix Android/ESP32 build trigger logic in .github/workflows/main.yml:

    • Line 263: Replace the condition contains(join(github.event.commits.*.message), 'android/') with a proper path-based check
    • Use: contains(github.event.head_commit.message, '[android]') || github.event_name == 'workflow_dispatch'
    • Line 318: Apply the same fix for ESP32 builds, replacing 'android/' check with '[esp32]' check
    • Keep the commit message tags [android] and [esp32] as they work correctly
    • Remove the broken file path checks that search commit messages
  3. Fix SHA format mismatch in .github/workflows/docker-multiplatform.yml:

    • Lines 412-435: In all Trivy scan steps, change from:
      image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/core-orchestrator:sha-${{ github.sha }}'
      To:
      image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/core-orchestrator:${{ github.ref_name }}-${{ github.sha }}'
    • This applies to all 4 component scans: core-orchestrator, ai-audio-assistant, hardware-bridge, ai-security
    • The issue is that metadata-action creates tags with format=short (7 chars) but Trivy references full SHA (40 chars)
  4. Optional improvements in .github/workflows/main.yml:

    • Line 87: Add a warning step after C++ build if it fails (currently continue-on-error: true hides failures)
    • Line 96: Improve error handling for pip install (currently uses || echo which masks failures)

Please commit these changes with the message: fix: workflow conditional logic, Docker SHA format, and remove .directory file

@cursor
Copy link

cursor bot commented Dec 1, 2025

All requested fixes applied. Summary:

Applied fixes

1. Removed .directory file and updated .gitignore

  • Deleted .directory (KDE Dolphin config)
  • Added .directory to .gitignore under "# IDE and file manager configs"

2. Fixed Android/ESP32 build trigger logic

  • Removed broken contains(join(github.event.commits.*.message), 'android/') check
  • Updated Android build condition to: contains(github.event.head_commit.message, '[android]') || github.event_name == 'workflow_dispatch'
  • Applied the same fix for ESP32 builds with [esp32] tag

3. Fixed SHA format mismatch in docker-multiplatform.yml

  • Updated all 4 Trivy scan steps:
    • Changed from: sha-${{ github.sha }} (full 40-char SHA)
    • Changed to: ${{ github.ref_name }}-${{ github.sha }} (ref + full SHA)
  • Updated components: core-orchestrator, ai-audio-assistant, hardware-bridge, ai-security
  • Also updated upload-sarif@v3@v4

4. Optional improvements in main.yml

  • Added C++ build status reporting: warning step when build fails
  • Improved pip install error handling: proper GitHub warning annotations instead of silent || echo
  • Removed build-mode: manual from CodeQL init (Python doesn't support it)

Summary of changes

Files modified:

  • .gitignore - Added .directory to ignore list
  • .github/workflows/main.yml - Fixed build triggers, improved error handling, removed manual build mode
  • .github/workflows/docker-multiplatform.yml - Fixed all Trivy SHA format mismatches

Files deleted:

  • .directory - Removed KDE config file

All changes are ready to commit with the message: fix: workflow conditional logic, Docker SHA format, and remove .directory file

The workflows should now:

  • Trigger Android/ESP32 builds correctly based on commit message tags
  • Successfully scan Docker images with matching tag formats
  • Provide better error visibility for build failures
  • Work properly with CodeQL analysis

Open in Cursor Open in Web

Learn more about Cursor Agents

cursoragent and others added 4 commits December 1, 2025 20:24
Co-authored-by: dallheimal <dallheimal@gmail.com>
…build tooling

- Add sparetools as git submodule for zero-copy Python/Conan bootstrap
- Add Arduino LED MCP bridge for hardware control via serial
- Add tools directory with bootstrap.sh, env.sh, and build helper scripts
- Add comprehensive RASPBERRY_PI_SETUP.md documentation
- Update README with new zero-copy bootstrap instructions
- Improve build-hardware-server.sh to auto-detect bundled environment
- Add pyserial to hardware-bridge requirements for Arduino support
- Update .gitignore for new build directories
- Remove external/sparetools git submodule (use Cloudsmith packages instead)
- Simplify tools/bootstrap.sh - remove submodule fallback
- Simplify tools/init.sh - remove submodule checks
- Update documentation to reflect Cloudsmith-only approach
- Add MILESTONE_COMPLETE.md documenting completed features

The sparetools packages (sparetools-cpython/3.12.7) are available from
Cloudsmith remote: https://dl.cloudsmith.io/public/sparesparrow-conan/openssl-conan/conan/

This removes unnecessary complexity while maintaining zero-copy Python
environment functionality.
- zlib: 1.2.13 → 1.3.1 (fixes cmake_minimum_required < 3.5 error)
- openssl: 3.0.8 → 3.4.0
- libcurl: 8.5.0 → 8.11.1
- jsoncpp: 1.9.5 → 1.9.6
- flatbuffers: 23.5.26 → 24.3.25
- libgpiod: 1.6.3 → 2.1.3

The Raspberry Pi has CMake 4.x which removed compatibility with
cmake_minimum_required < 3.5. Older package versions fail to build.
integration-tests:
name: 🧪 Integration Tests
runs-on: ubuntu-latest
needs: [python-tests, cpp-builds, docker-builds]
Copy link

Choose a reason for hiding this comment

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

Bug: Integration tests skipped on PRs due to unnecessary dependency

The integration-tests job specifies needs: [python-tests, cpp-builds, docker-builds], but docker-builds only runs on push events to main/develop branches (line 362). When a job in needs is skipped, dependent jobs are also skipped by GitHub Actions. This means integration-tests will never run on pull requests. However, the integration tests use docker-compose -f docker-compose.dev.yml and don't actually consume any artifacts from docker-builds, making this dependency incorrect. The job should likely only depend on python-tests and cpp-builds.

Fix in Cursor Fix in Web

sparetools-cpython is not available on Cloudsmith.
sparesparrow added 3 commits December 2, 2025 03:26
- conanfile.py: Use package versions that exist on Conan Center
  - libcurl: 8.11.1 → 8.10.1 (8.11.1 not available)
  - openssl: 3.4.0 → 3.3.2 (3.4.0 not available)
  - libgpiod: 2.1.3 → 2.0.2 (2.1.3 not available)

- install-deps-rpi.sh: Fix package names for Debian Trixie
  - Remove libgpiod2 (doesn't exist, libgpiod3 is installed via libgpiod-dev)
  - Add flatbuffers-compiler and libflatbuffers-dev

- CMakeLists.txt: Fix pkg-config module name
  - mosquitto → libmosquitto (correct name on Debian)

- tools/build.sh: Add missing build script
  - Supports system libraries and Conan toolchain
  - Auto-detects Ninja or Make
  - Supports --clean, --debug, --release flags
- FlatBuffersRequestReader.cpp: Use flatbuffers::GetRoot<T>() and Message union
- FlatBuffersResponseReader.cpp: Use flatbuffers::GetRoot<T>() for all response types
- FlatBuffersResponseWriter.cpp: Fix DownloadStatusResponse type
- IResponseWriter.h: Use DownloadStatusResponse (matches schema)

The FlatBuffers 24.x API no longer generates GetXxx() functions.
Use flatbuffers::GetRoot<Type>() instead.
- Move DownloadResponse, StatusResponse, ErrorResponse structs to IResponseWriter.h
- IResponseReader.h now includes IResponseWriter.h for these types
- FlatBuffersResponseWriter uses local structs and converts to FlatBuffers
- Fixes duplicate definition issues
sparesparrow added 4 commits December 2, 2025 03:34
- CMakeLists-rpi-minimal.txt: Standalone CMake config for hardware-server
  - No FlatBuffers dependency
  - Only requires jsoncpp, libgpiod, and optionally libmosquitto

- build-hardware-server-rpi.sh: Build script for the minimal config
  - Supports --clean flag
  - Auto-detects Ninja or Make

This allows building just the hardware-server on Raspberry Pi without
the complex FlatBuffers infrastructure that has compatibility issues.
- HardwareControlServer.h: Use gpiod.h C API instead of gpiod.hpp C++ bindings
- HardwareControlServer.cpp: Rewrite GPIO code for libgpiod 2.x C API
  - Uses gpiod_chip_request_lines() for line requests
  - Uses gpiod_line_request_set_value/get_value for I/O
  - Proper cleanup with gpiod_line_request_release()
  - Thread-safe with gpioMutex
  - Supports both gpiochip0 and gpiochip4 (Raspberry Pi 5)

The C API is more stable across libgpiod versions and provides
better compatibility than the C++ bindings which changed significantly
between 1.x and 2.x.
needs: [security]
if: |
contains(join(github.event.commits.*.message), 'docs/') ||
contains(join(github.event.commits.*.message), 'mkdocs.yml') ||
Copy link

Choose a reason for hiding this comment

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

Bug: Docs job incorrectly triggers on commit message text

The documentation job condition checks if commit messages contain the strings 'docs/' or 'mkdocs.yml' using contains(join(github.event.commits.*.message), ...). This causes false triggers when developers mention these strings in commit messages without actually modifying documentation files. The intended behavior is to trigger on file changes, not commit message content. Lines 486-487 correctly check modified files; lines 484-485 appear to be erroneous and would cause unintended documentation builds.

Fix in Cursor Fix in Web

sparesparrow added 2 commits December 2, 2025 12:38
Phase 1: Core Manager Implementations
- BLEManager: Nordic BLE Library integration with device scanning,
  connection state management, auto-reconnect with exponential backoff
- OBDManager: ELM327 protocol with PID polling (fuel, RPM, speed,
  coolant, engine load), DTC reading/clearing, adaptive sampling modes
- ANPRManager: CameraX + ML Kit text recognition, region-specific
  heuristics (CZ/EU), privacy-preserving plate hashing, confidence filtering
- VoiceManager: TTS with Czech/English locales, priority queue,
  audio focus handling
- DVRManager: CameraX video recording with rolling buffer, event
  clip extraction, storage management

Phase 2: Enhanced UI Components
- CameraPreviewScreen: Camera preview with ANPR detection overlay
- OBDPairingScreen: BLE device scanner with signal indicators
- Enhanced Gauges: Circular speedometer/RPM with animations,
  compact gauges for fuel/coolant/load

Phase 3: Testing Implementation
- Unit tests: OBDManager, BLEManager, VoiceManager, DVRManager,
  SystemPolicyManager, Backoff
- Integration tests: Database, EventRepository
- UI tests: DashboardScreen, SettingsScreen

Phase 4: Build and CI Enhancements
- Updated build.gradle with test coverage configuration
- Enhanced build-in-docker.sh with --test, --lint, --coverage options
- Created android-ci.yml GitHub Actions workflow

Phase 5: Documentation
- Comprehensive README.md with architecture, features, setup,
  building, testing, and contribution guidelines
- Remove unused kotlinx.coroutines.tasks.await import in ANPRManager
- Fix return type mismatches for suspend functions using withContext
- Change VIDEO_QUALITY from const val to val (Quality is not primitive)
@sparesparrow sparesparrow merged commit fa45edd into main Dec 2, 2025
24 of 28 checks passed
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