-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3c1ccb
commit 3b1eefd
Showing
36 changed files
with
374 additions
and
1,800 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// SILManufacturerData.swift | ||
// BlueGecko | ||
// | ||
// Created by Grzegorz Janosz on 10/01/2022. | ||
// Copyright © 2022 SiliconLabs. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Data { | ||
func checkManufacturerData(manufacturerIdentifier: Int, manufacturerData expected: [UInt8], manufacturerDataMask mask: [UInt8]? = nil) -> Bool { | ||
let length = self.bytes.count | ||
guard length > 2 else { | ||
return false | ||
} | ||
let idBytes = Data(bytes: self.bytes[0...1]) | ||
guard idBytes.integerValueFromData() == manufacturerIdentifier else { | ||
return false | ||
} | ||
|
||
let data = Data(bytes: self.bytes[2...(length - 1)]) | ||
guard data.bytes.count == expected.count else { | ||
return false | ||
} | ||
|
||
let mask = mask ?? Array(repeating: 1, count: expected.count) | ||
let zipped = Array(zip(expected, mask)) | ||
for (ind, (expectedByte, maskByte)) in zipped.enumerated() { | ||
if maskByte != 0 && data.bytes[ind] != expectedByte { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.