sendDataRaw method

Future<void> sendDataRaw(
  1. Uint8List data
)

Same as sendData but user includes the 0x01 header byte to avoid extra memory allocation

Implementation

Future<void> sendDataRaw(Uint8List data) async {
  try {
    _log.finer(() => "Sending ${data.length - 1} bytes of plain data");
    _log.finest(data);

    if (state != BrilliantConnectionState.connected) {
      throw ("Device is not connected");
    }

    if (data.length > maxDataLength! + 1) {
      throw ("Payload exceeds allowed length of ${maxDataLength! + 1}");
    }

    if (data[0] != 0x01) {
      throw ("Data packet missing 0x01 header");
    }

    // TODO check throughput difference using withoutResponse: false
    await _txChannel!.write(data, withoutResponse: false);
  } catch (error) {
    _log.warning("Couldn't send data. $error");
    return Future.error(BrilliantBluetoothException(error.toString()));
  }
}