getElinkBleData static method

ElinkBleData getElinkBleData(
  1. List<int> manufacturerData, {
  2. bool isBroadcastDevice = false,
})

解析蓝牙广播数据获取cid,vid,pid和mac Parse Bluetooth broadcast data to obtain cid, vid, pid and mac

Implementation

static ElinkBleData getElinkBleData(
  List<int> manufacturerData, {
  bool isBroadcastDevice = false,
}) {
  final cid = List.filled(2, 0);
  final vid = List.filled(2, 0);
  final pid = List.filled(2, 0);
  final mac = List.filled(6, 0);
  final length = manufacturerData.length;
  if (manufacturerData.isEmpty) return ElinkBleData(cid, vid, pid, mac);
  if (isBroadcastDevice && length >= 3) {
    int start = 0;
    cid.setRange(1, cid.length, manufacturerData.sublist(start, start += 1));
    vid.setRange(1, vid.length, manufacturerData.sublist(start, start += 1));
    pid.setRange(1, pid.length, manufacturerData.sublist(start, start += 1));
    if (length >= 10) {
      mac.setRange(0, mac.length, manufacturerData.sublist(start, start + mac.length));
    }
  } else if (manufacturerData[0] == 0x6E && manufacturerData[1] == 0x49 && length >= 14) {
    int start = 2;
    cid.setRange(0, cid.length, manufacturerData.sublist(start, start += cid.length));
    vid.setRange(0, vid.length, manufacturerData.sublist(start, start += vid.length));
    pid.setRange(0, pid.length, manufacturerData.sublist(start, start += pid.length));
    mac.setRange(0, mac.length, manufacturerData.sublist(start, start + mac.length));
  }
  return ElinkBleData(cid, vid, pid, mac);
}