Skip to content

Commit 3a52819

Browse files
committed
Refactor device model handling: Update documentation and comments for clarity on identification and reporting without modifying TX power settings
1 parent 5d8ac86 commit 3a52819

File tree

8 files changed

+36
-32
lines changed

8 files changed

+36
-32
lines changed

CLAUDE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The app uses a layered service architecture with clear separation of concerns:
7777
- `PingService`: TX/RX ping orchestration, coordinates with TxTracker/RxLogger
7878
- `ApiQueueService`: Hive-based persistent upload queue with batch POST and retry logic
7979
- `ApiService`: HTTP client for MeshMapper API endpoints
80-
- `DeviceModelService`: Loads `assets/device-models.json` and auto-configures TX power
80+
- `DeviceModelService`: Loads `assets/device-models.json` for device identification and power reporting
8181

8282
**State Management** (`lib/providers/`):
8383
- `AppStateProvider`: Single ChangeNotifier for all app state using Provider pattern
@@ -90,15 +90,15 @@ Critical safety: The connection sequence MUST complete in order. See `docs/CONNE
9090
1. **BLE GATT Connect**: Platform-specific BLE connection
9191
2. **Protocol Handshake**: `deviceQuery()` with protocol version
9292
3. **Device Info**: `getDeviceName()`, `getPublicKey()`, `getDeviceSettings()`
93-
4. **Auto-Power Configuration**: Parse manufacturer string, match against `device-models.json`, set power level
93+
4. **Device Identification**: Parse manufacturer string, match against `device-models.json` (does NOT modify radio settings)
9494
5. **Time Sync**: `sendTime()` syncs device clock
9595
6. **API Slot Acquisition**: POST to `/capacitycheck.php` to reserve API slot
9696
7. **Channel Setup**: Create or use existing `#wardriving` channel
9797
8. **GPS Init**: Acquire GPS lock
9898
9. **Start Unified RX Handler**: Begin processing ALL incoming packets
9999
10. **Connected State**: Ready for wardriving
100100

101-
**Critical Power Safety**: PA amplifier devices (30dBm, 33dBm) require specific input power levels. Incorrect values can damage hardware. Auto-power selection from device-models.json is MANDATORY for these devices.
101+
**Important**: The app does NOT modify the radio's TX power settings. It only identifies the device model to determine what power level to report in API calls. Users configure their radio's actual TX power through the device firmware.
102102

103103
### Unified RX Handler Architecture
104104

@@ -282,7 +282,7 @@ Contains 30+ MeshCore device variants with manufacturer strings, TX power levels
282282
- `lib/services/ping_service.dart` - TX/RX ping orchestration
283283
- `lib/services/gps_service.dart` - GPS tracking and geofencing
284284
- `lib/services/api_queue_service.dart` - Persistent upload queue
285-
- `lib/services/device_model_service.dart` - Auto-power configuration
285+
- `lib/services/device_model_service.dart` - Device model identification
286286
- `assets/device-models.json` - Device database (30+ models)
287287
- `docs/CONNECTION_WORKFLOW.md` - Connection sequence documentation
288288
- `docs/PING_WORKFLOW.md` - Ping lifecycle documentation

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Cross-platform wardriving app for MeshCore devices. A Flutter port of the [MeshM
88
- **BLE Connectivity**: Connect to MeshCore devices via Bluetooth Low Energy
99
- **GPS Tracking**: High-accuracy location tracking with 25m distance filter
1010
- **Geofencing**: Enforces 150km boundary from Ottawa (service area)
11-
- **Auto-Power Selection**: Automatically configures TX power based on device model
11+
- **Device Recognition**: Automatically identifies device model for accurate power reporting
1212
- **Real-time Map**: View TX/RX ping markers on OpenStreetMap
1313
- **API Queue**: Persistent queue with batch upload and retry logic
1414
- **Dark Mode**: System theme support

docs/ARCHITECTURE.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ lib/
3434
│ ├── gps_service.dart # GPS tracking and geofencing
3535
│ ├── api_service.dart # HTTP API client
3636
│ ├── api_queue_service.dart # Persistent upload queue
37-
│ ├── device_model_service.dart # Device database and auto-power
37+
│ ├── device_model_service.dart # Device database and model identification
3838
│ └── ping_service.dart # TX/RX orchestration
3939
├── providers/
4040
│ └── app_state_provider.dart # Main app state
@@ -76,7 +76,7 @@ The `MeshCoreConnection` class handles the 10-step connection workflow:
7676
1. BLE GATT Connect
7777
2. Protocol Handshake
7878
3. Device Info Query
79-
4. Auto-Power Configuration
79+
4. Device Identification (for display/reporting only - does NOT modify radio settings)
8080
5. Time Sync
8181
6. API Slot Acquisition
8282
7. Channel Setup
@@ -155,13 +155,13 @@ class AppStateProvider extends ChangeNotifier {
155155
- RX Characteristic: `6E400002-B5A3-F393-E0A9-E50E24DCCA9E`
156156
- TX Characteristic: `6E400003-B5A3-F393-E0A9-E50E24DCCA9E`
157157

158-
### Power Configuration Safety
159-
PA amplifier devices require specific power values:
160-
- 33dBm models: txPower=9, power=2.0
161-
- 30dBm models: txPower=20, power=1.0
162-
- Standard: txPower=22, power=0.3
158+
### Power Level Reporting
159+
The app identifies device models to determine what power level to report in API calls:
160+
- 33dBm models: 2.0W
161+
- 30dBm models: 1.0W
162+
- Standard (22dBm): 0.3W
163163

164-
**WARNING**: Incorrect power settings can damage PA amplifier hardware.
164+
**Important**: The app does NOT modify the radio's TX power settings. It only reads device information and reports the appropriate power level to the API. Users configure their radio's actual TX power through the device firmware.
165165

166166
## Dependencies
167167

docs/DEVELOPMENT_REQUIREMENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ All debug log messages **MUST** include a descriptive tag in square brackets at
4747
| `[AUTH]` | Authentication API operations |
4848
| `[HEARTBEAT]` | Session heartbeat operations |
4949
| `[API]` | General API operations |
50-
| `[MODEL]` | Device model detection and auto-power |
50+
| `[MODEL]` | Device model identification and power reporting |
5151
| `[MAP]` | Map widget operations |
5252

5353
**Examples:**

lib/models/connection_state.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum ConnectionStep {
3131
/// Step 3: Device info query
3232
deviceQuery,
3333

34-
/// Step 4: Auto-power configuration based on device model
34+
/// Step 4: Device identification (match device model for display/reporting)
3535
powerConfiguration,
3636

3737
/// Step 5: Time synchronization
@@ -87,7 +87,7 @@ extension ConnectionStepExtension on ConnectionStep {
8787
case ConnectionStep.deviceQuery:
8888
return 'Querying device info...';
8989
case ConnectionStep.powerConfiguration:
90-
return 'Configuring power...';
90+
return 'Identifying device...';
9191
case ConnectionStep.timeSync:
9292
return 'Syncing time...';
9393
case ConnectionStep.slotAcquisition:

lib/providers/app_state_provider.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,18 @@ class AppStateProvider extends ChangeNotifier {
591591
_deviceModelService.models,
592592
);
593593

594-
// Update preferences if auto-power was configured
595-
if (connectionResult.autoPowerConfigured && connectionResult.deviceModel != null) {
594+
// Update preferences if device model was recognized (for display/API reporting)
595+
// Note: This does NOT change the radio's TX power - it only sets what power level to REPORT
596+
if (connectionResult.deviceModelMatched && connectionResult.deviceModel != null) {
596597
final device = connectionResult.deviceModel!;
597598
_preferences = _preferences.copyWith(
598599
powerLevel: device.power,
599600
txPower: device.txPower,
600-
autoPowerSet: true,
601+
autoPowerSet: true, // Indicates power was auto-detected from device model
601602
);
602603
// TODO: Persist to SharedPreferences when implemented
603604
notifyListeners();
604-
debugLog('[MODEL] Power auto-configured: ${device.power}W (${device.shortName})');
605+
debugLog('[MODEL] Device recognized: ${device.shortName} - reporting ${device.power}W in API calls');
605606
}
606607

607608
// Note: API session acquisition is now handled by the auth callback

lib/screens/connection_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ class _ConnectionScreenState extends State<ConnectionScreen> with WidgetsBinding
7575
final appState = context.watch<AppStateProvider>();
7676
final isLandscape = MediaQuery.of(context).orientation == Orientation.landscape;
7777

78-
// Build FAB for scanning
78+
// Build FAB for scanning - only show when fully disconnected and idle
7979
Widget? fab;
80-
if (!appState.isScanning && !appState.isConnected) {
80+
if (appState.connectionStep == ConnectionStep.disconnected) {
8181
final canScan = appState.inZone == true || appState.offlineMode;
8282
fab = isLandscape
8383
? FloatingActionButton.small(

lib/services/meshcore/connection.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ class SelfInfo {
4848

4949
/// MeshCore connection manager
5050
/// Ported from content/mc/connection/connection.js in WebClient repo
51-
///
51+
///
5252
/// Implements the 10-step connection workflow:
5353
/// 1. BLE GATT Connect
5454
/// 2. Protocol Handshake
5555
/// 3. Device Info Query
56-
/// 4. Device Model Auto-Power Selection
56+
/// 4. Device Identification (match device model for display/reporting)
5757
/// 5. Time Sync
5858
/// 6. API Capacity Check (slot acquisition)
5959
/// 7. Channel Setup
@@ -171,9 +171,10 @@ class MeshCoreConnection {
171171
}
172172

173173
/// Execute the full connection workflow
174-
/// Returns (deviceModel, autoPowerConfigured) for preferences update
175-
Future<({DeviceModel? deviceModel, bool autoPowerConfigured})> connect(String deviceId, List<DeviceModel> deviceModels) async {
176-
bool autoPowerConfigured = false;
174+
/// Returns (deviceModel, deviceModelMatched) for display/reporting purposes
175+
/// Note: This method does NOT modify radio TX power settings - it only reads device info
176+
Future<({DeviceModel? deviceModel, bool deviceModelMatched})> connect(String deviceId, List<DeviceModel> deviceModels) async {
177+
bool deviceModelMatched = false;
177178

178179
try {
179180
// Step 1: BLE Connect
@@ -199,13 +200,15 @@ class MeshCoreConnection {
199200
throw Exception('Failed to acquire device public key: $e');
200201
}
201202

202-
// Step 4: Power Configuration (auto-select based on device model)
203+
// Step 4: Device Identification (match device model for display/reporting purposes)
204+
// Note: We do NOT modify the radio's TX power - we only read device info
203205
_updateStep(ConnectionStep.powerConfiguration);
204206
_deviceModel = _matchDeviceModel(_deviceInfo!.manufacturer, deviceModels);
205207
if (_deviceModel != null) {
206-
await setTxPower(_deviceModel!.txPower);
207-
autoPowerConfigured = true;
208-
debugLog('[CONN] Auto-configured power: ${_deviceModel!.power}W (${_deviceModel!.txPower}dBm) for ${_deviceModel!.shortName}');
208+
deviceModelMatched = true;
209+
debugLog('[CONN] Device identified: ${_deviceModel!.shortName} (reports ${_deviceModel!.power}W / ${_deviceModel!.txPower}dBm)');
210+
} else {
211+
debugLog('[CONN] Device model not recognized - user must manually select power level for reporting');
209212
}
210213

211214
// Step 5: Time Sync
@@ -253,7 +256,7 @@ class MeshCoreConnection {
253256
// This may fail on older firmware (< v1.11.0)
254257
_startNoiseFloorPolling();
255258

256-
return (deviceModel: _deviceModel, autoPowerConfigured: autoPowerConfigured);
259+
return (deviceModel: _deviceModel, deviceModelMatched: deviceModelMatched);
257260
} catch (e) {
258261
debugError('[CONN] Connection failed: $e');
259262
_updateStep(ConnectionStep.error);

0 commit comments

Comments
 (0)