Skip to content

Commit

Permalink
Rename filterMfdList to manufacturerDataFilters and replace mfd with msd
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitsangwan01 committed Oct 3, 2024
1 parent b77d0aa commit d368b86
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class UniversalBleFilterUtil {
val filters = scanFilter.withManufacturerData.filterNotNull()
if (filters.isEmpty()) return true
if (manufacturerDataList.isEmpty()) return false
return manufacturerDataList.any { mfd ->
return manufacturerDataList.any { msd ->
filters.any { filter ->
mfd.companyIdentifier == filter.companyIdentifier &&
isDataMatching(filter.data, mfd.data, filter.mask)
msd.companyIdentifier == filter.companyIdentifier &&
isDataMatching(filter.data, msd.data, filter.mask)
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions lib/src/universal_ble_filter_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,31 @@ class UniversalBleFilterUtil {
ScanFilter scanFilter,
BleDevice device,
) {
final filterMfdList = scanFilter.withManufacturerData;
if (filterMfdList.isEmpty) return true;
final manufacturerDataFilters = scanFilter.withManufacturerData;
if (manufacturerDataFilters.isEmpty) return true;

List<ManufacturerData> manufacturerDataList = device.manufacturerDataList;
if (manufacturerDataList.isEmpty) return false;

return manufacturerDataList.any((deviceMfd) => filterMfdList.any(
(filterMfd) => _isManufacturerDataMatch(filterMfd, deviceMfd),
return manufacturerDataList.any((deviceMsd) => manufacturerDataFilters.any(
(filterMsd) => _isManufacturerDataMatch(filterMsd, deviceMsd),
));
}

bool _isManufacturerDataMatch(
ManufacturerDataFilter filterMfd,
ManufacturerData deviceMfd,
ManufacturerDataFilter filterMsd,
ManufacturerData deviceMsd,
) {
if (filterMfd.companyIdentifier != deviceMfd.companyId) return false;
if (filterMsd.companyIdentifier != deviceMsd.companyId) return false;

Uint8List? filterPayload = filterMfd.payload;
Uint8List devicePayload = deviceMfd.payload;
Uint8List? filterPayload = filterMsd.payload;
Uint8List devicePayload = deviceMsd.payload;

if (filterPayload == null || filterPayload.isEmpty) return true;
if (devicePayload.isEmpty) return false;
if (filterPayload.length > devicePayload.length) return false;

Uint8List? filterMask = filterMfd.mask;
Uint8List? filterMask = filterMsd.mask;

if (filterMask != null && filterMask.length == filterPayload.length) {
for (int i = 0; i < filterPayload.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions windows/src/universal_ble_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,9 @@ namespace universal_ble
flutter::EncodableList manufacturerDataEncodableList = flutter::EncodableList();
if (args.Advertisement() != nullptr)
{
for (BluetoothLEManufacturerData mfd : args.Advertisement().ManufacturerData())
for (BluetoothLEManufacturerData msd : args.Advertisement().ManufacturerData())
{
UniversalManufacturerData universalManufacturerData = UniversalManufacturerData(static_cast<int64_t>(mfd.CompanyId()), to_bytevc(mfd.Data()));
UniversalManufacturerData universalManufacturerData = UniversalManufacturerData(static_cast<int64_t>(msd.CompanyId()), to_bytevc(msd.Data()));
manufacturerDataEncodableList.push_back(flutter::CustomEncodableValue(universalManufacturerData));
}
}
Expand Down

0 comments on commit d368b86

Please sign in to comment.