fetchProgressStream method
Stream of fetch progress events for the given device.
Subscribe to this stream before calling fetchMeasurement to receive progress updates and completion/failure notifications.
The stream emits:
- FetchProgress.idle when no fetch is active
- FetchProgress.inProgress with receivedBytes/totalBytes during transfer
- FetchProgress.completed when all data is received and CRC verified
- FetchProgress.failed if an error occurs
Implementation
@override
Stream<FetchProgress> fetchProgressStream(BluetoothDevice device) {
final deviceId = device.remoteId.str;
// Transform the stream to process raw data on completion
return _fetchRegistry.getFetchProgressStream(device).map((progress) {
return progress.when(
idle: () => progress,
inProgress: (_) => progress,
completed: (rawData, totalBytes, _) {
// Process the raw data: extract measurement data and validate CRC
// Pass config for decompression if data was stored compressed
final expectedCrc = _expectedCrcByDevice[deviceId] ?? 0;
final config = _measurementConfigByDevice[deviceId];
final result = MeasurementDataProcessor.processRawData(
rawData,
expectedCrc,
config: config,
);
return FetchProgress.completed(
data: result.data,
totalBytes: result.data.length,
crcValid: result.crcValid,
);
},
failed: (_, __, ___) => progress,
);
});
}