doozScenarioEpochSet method

Future<DoozEpochStatusData?> doozScenarioEpochSet(
  1. int address,
  2. int tzData,
  3. int epoch,
  4. int correlation, {
  5. int command = 15,
  6. int io = 0,
  7. int unused = 0,
  8. int? extra,
  9. int keyIndex = 0,
})

Will send a DoozEpochSet message (0x8220).

(DooZ specific API)

Implementation

Future<DoozEpochStatusData?> doozScenarioEpochSet(
  int address,
  int tzData,
  int epoch,
  int correlation, {
  int command = 15,
  int io = 0,
  int unused = 0,
  int? extra,
  int keyIndex = 0,
}) async {
  if (Platform.isAndroid || Platform.isIOS) {
    final status = _onDoozEpochStatusController.stream.cast<DoozEpochStatusData?>().firstWhere(
          (element) => element!.source == address,
          orElse: () => null,
        );
    final uTz = tzData.toUnsigned(9);
    final packed = unused << 14 | io << 13 | command << 9 | ((uTz << 8) & 0x7) | uTz;
    _log('tzData = $uTz ($tzData) , tzData << 8 & 0x7 | tzData --> ${(((uTz << 8) & 0x7) | uTz).bitField(width: 9)}');
    _log('command = $command (${command.bitField(width: 4)})');
    _log('io = $io (${io.bitField(width: 1)})');
    _log('unused = $unused (${unused.bitField(width: 2)})');
    _log(
        '($unused << 15) | ($io << 13) | ($command << 9) |(($uTz << 8 & 0x7) | $uTz)\n\t==> ${(packed).bitField(width: 16)}, length : ${packed.bitLength}');
    await _methodChannel.invokeMethod('doozScenarioEpochSet', {
      'address': address,
      'packed': packed,
      'epoch': epoch,
      'extra': extra,
      'correlation': correlation,
      'keyIndex': keyIndex,
    });
    return status;
  } else {
    throw UnimplementedError('${Platform.environment} not supported');
  }
}