-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
18 changed files
with
830 additions
and
105 deletions.
There are no files selected for viewing
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
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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/no/seime/openhab/binding/esphome/internal/bluetooth/BluetoothAddressUtil.java
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,33 @@ | ||
package no.seime.openhab.binding.esphome.internal.bluetooth; | ||
|
||
import java.util.HexFormat; | ||
|
||
import org.openhab.binding.bluetooth.BluetoothAddress; | ||
|
||
public class BluetoothAddressUtil { | ||
public static BluetoothAddress createAddress(long address) { | ||
String hexDigits = HexFormat.of().toHexDigits(address); | ||
|
||
StringBuilder addressBuilder = new StringBuilder(); | ||
|
||
// Skip first 2 bytes as addresses are 48 bits and not 64 bits | ||
for (int i = 4; i < hexDigits.length(); i += 2) { | ||
addressBuilder.append(hexDigits.substring(i, i + 2)); | ||
if (i < hexDigits.length() - 2) { | ||
addressBuilder.append(":"); | ||
} | ||
} | ||
|
||
return new BluetoothAddress(addressBuilder.toString().toUpperCase()); | ||
} | ||
|
||
public static long convertAddressToLong(BluetoothAddress address) { | ||
String[] parts = address.toString().split(":"); | ||
long result = 0; | ||
for (int i = 0; i < parts.length; i++) { | ||
result = result << 8; | ||
result |= Integer.parseInt(parts[i], 16); | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.