extractFromScanResult static method

String? extractFromScanResult(
  1. Map<int, List<int>> manufacturerData
)

Implementation

static String? extractFromScanResult(Map<int, List<int>> manufacturerData) {
  try {
    if (manufacturerData.isEmpty) {
      return null;
    }

    // Get the first manufacturer data entry
    // Assuming the MAC address is in the first manufacturer data
    final data = manufacturerData.values.first;

    // Check if we have enough bytes (need at least 8 bytes, indices 2-7)
    if (data.length < 8) {
      return null;
    }

    // Extract bytes 2-8 (indices 2, 3, 4, 5, 6, 7)
    final macBytes = data.sublist(2, 8);

    // Reverse the order
    final reversedBytes = macBytes.reversed.toList();

    // Format as MAC address string (AA:BB:CC:DD:EE:FF)
    final macAddress = reversedBytes
        .map((byte) => byte.toRadixString(16).padLeft(2, '0').toUpperCase())
        .join(':');

    return macAddress;
  } catch (e) {
    return null;
  }
}