82 lines
3.4 KiB
YAML
82 lines
3.4 KiB
YAML
project_name: ble_simulator_real_go
|
|
context:
|
|
role: Senior Go Developer & BLE Protocol Engineer
|
|
goal: Create a CLI application in Go that acts as a real BLE Peripheral (GATT Server).
|
|
target_hardware: The Go app runs on a PC (Windows/Linux/macOS) with a Bluetooth adapter.
|
|
client: A Flutter mobile app (running on a physical device) will connect to this simulator.
|
|
inputs:
|
|
protocol_docs: "./docs.toon" # Contains commands and expected logic.
|
|
|
|
tasks:
|
|
- id: 1_setup_dependencies
|
|
title: Initialize Project and BLE Library
|
|
description: |
|
|
Initialize a Go module.
|
|
Add dependency: 'tinygo.org/x/bluetooth'.
|
|
Ensure the code structure supports OS-specific threads (required for Bluetooth adapters).
|
|
validation:
|
|
- "go.mod contains tinygo.org/x/bluetooth"
|
|
|
|
- id: 2_define_ble_structure
|
|
title: Define UUIDs and Service Architecture
|
|
description: |
|
|
Based on the nature of 'docs.toon', define the GATT structure constants:
|
|
- SERVICE_UUID: Generate a random 128-bit or 16-bit UUID.
|
|
- COMMAND_CHAR_UUID: A writable characteristic (for receiving commands from App).
|
|
- NOTIFY_CHAR_UUID: A notifiable characteristic (for sending data to App).
|
|
Output these UUIDs clearly so they can be copied into the Flutter app code.
|
|
validation:
|
|
- "Valid UUIDs are defined as constants."
|
|
|
|
- id: 3_parse_logic_docs
|
|
title: Map Protocol Docs to Go Logic
|
|
description: |
|
|
Read 'docs.toon'.
|
|
Create a 'DeviceLogic' struct that holds the internal state (simulated values).
|
|
Map every command in the docs to a specific action.
|
|
Example:
|
|
- If docs says "CMD_RESET", the Go code should reset internal variables.
|
|
- If docs says "SET_COLOR_RED", update internal state to 'Red'.
|
|
validation:
|
|
- "Switch/Case logic exists handling commands found in docs.toon."
|
|
|
|
- id: 4_implement_gatt_server
|
|
title: Configure GATT Server and Advertising
|
|
description: |
|
|
Implement the main function to:
|
|
1. Enable the Bluetooth adapter (`adapter.Enable()`).
|
|
2. configure the Advertisement (use a local name like "GO_SIMULATOR" so it's easy to find).
|
|
3. Add the Service and Characteristics defined in Task 2.
|
|
validation:
|
|
- "Code calls adapter.AddService and adv.Start()."
|
|
|
|
- id: 5_handle_write_requests
|
|
title: Implement Write Event Handler
|
|
description: |
|
|
Inside the COMMAND_CHAR_UUID configuration, implement the `WriteEvent` callback.
|
|
When the App writes bytes to this characteristic:
|
|
1. Convert bytes to string/command.
|
|
2. Pass it to the 'DeviceLogic' (Task 3).
|
|
3. Log the received command to the console ("[RX] Command: ...").
|
|
validation:
|
|
- "Console logs incoming Bluetooth writes in real-time."
|
|
|
|
- id: 6_handle_notifications
|
|
title: Implement Notification Loop
|
|
description: |
|
|
Create a Goroutine that simulates data generation based on 'docs.toon'.
|
|
Every X milliseconds (simulate sensor frequency):
|
|
1. Update the value of NOTIFY_CHAR_UUID.
|
|
2. Trigger a notification sending the new bytes to the connected device.
|
|
3. Log the sent data ("[TX] Sending: ...").
|
|
validation:
|
|
- "Code simulates data flow and updates the characteristic value periodically."
|
|
|
|
- id: 7_run_and_monitor
|
|
title: CLI Dashboard
|
|
description: |
|
|
Provide a clean CLI output indicating:
|
|
- "Advertising as [Name]..."
|
|
- "Client Connected / Disconnected"
|
|
- Real-time log of traffic.
|