updateCharacteristicValue method

void updateCharacteristicValue(
  1. String deviceId,
  2. String characteristicId,
  3. Uint8List value,
  4. int? timestamp,
)

Implementation

void updateCharacteristicValue(
  String deviceId,
  String characteristicId,
  Uint8List value,
  int? timestamp,
) {
  deviceId = _deviceId(deviceId).canonical;
  characteristicId = BleUuidParser.string(characteristicId);
  // StandardMessageCodec decodes typed data as a view into the complete
  // platform-message buffer. Normalize that view before exposing it so
  // consumers which pass `value.buffer` to another binary API cannot
  // accidentally include Pigeon envelope bytes.
  final normalizedValue = value.offsetInBytes == 0 &&
          value.lengthInBytes == value.buffer.lengthInBytes
      ? value
      : Uint8List.fromList(value);
  final update = BleCharacteristicValue(
    deviceId: deviceId,
    characteristicId: characteristicId,
    value: normalizedValue,
    timestamp: timestamp,
  );
  _valueStreamController.add(update);
  try {
    onValueChange?.call(update);
  } catch (_) {}
}