Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Go to the documentation of this file.
26 package org.direct_bt;
39 public static final EUI48 ANY_DEVICE =
new EUI48(
new byte[] { (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00 } );
41 public static final EUI48 ALL_DEVICE =
new EUI48(
new byte[] { (byte)0xff, (
byte)0xff, (byte)0xff, (
byte)0xff, (byte)0xff, (
byte)0xff } );
43 public static final EUI48 LOCAL_DEVICE =
new EUI48(
new byte[] { (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0xff, (byte)0xff, (
byte)0xff } );
52 public final byte b[];
54 private volatile int hash;
60 static final int byte_size = 6;
74 public static boolean scanEUI48(
final String str,
final EUI48 dest,
final StringBuilder errmsg) {
75 if( 17 != str.length() ) {
76 errmsg.append(
"EUI48 string not of length 17 but "+str.length()+
": "+str);
80 for(
int i=0; i<byte_size; i++) {
81 dest.
b[byte_size-1-i] = Integer.valueOf(str.substring(i*2+i, i*2+i+2), 16).byteValue();
83 }
catch (
final NumberFormatException e) {
84 errmsg.append(
"EUI48 string not in format '01:02:03:0A:0B:0C' but "+str+
"; "+e.getMessage());
100 public EUI48(
final String str)
throws IllegalArgumentException {
101 final StringBuilder errmsg =
new StringBuilder();
102 b =
new byte[byte_size];
104 throw new IllegalArgumentException(errmsg.toString());
109 public EUI48(
final byte stream[],
final int pos) {
110 if( byte_size > ( stream.length - pos ) ) {
111 throw new IllegalArgumentException(
"EUI48 stream ( "+stream.length+
" - "+pos+
" ) < "+byte_size+
" bytes");
113 b =
new byte[byte_size];
114 System.arraycopy(stream, pos,
b, 0, byte_size);
118 public EUI48(
final byte address[]) {
119 if( byte_size != address.length ) {
120 throw new IllegalArgumentException(
"EUI48 stream "+address.length+
" != "+byte_size+
" bytes");
127 b =
new byte[byte_size];
131 public final boolean equals(
final Object obj) {
135 if (obj ==
null || !(obj instanceof
EUI48)) {
138 final byte[] b2 = ((
EUI48)obj).b;
139 return b[0] == b2[0] &&
170 h = ( ( h << 5 ) - h ) +
b[1];
171 h = ( ( h << 5 ) - h ) +
b[2];
172 h = ( ( h << 5 ) - h ) +
b[3];
173 h = ( ( h << 5 ) - h ) +
b[4];
174 h = ( ( h << 5 ) - h ) +
b[5];
192 b[0] = 0;
b[1] = 0;
b[2] = 0;
193 b[3] = 0;
b[4] = 0;
b[5] = 0;
207 public final void putStream(
final byte[] source,
final int pos) {
208 if( byte_size > ( source.length - pos ) ) {
209 throw new IllegalArgumentException(
"Stream ( "+source.length+
" - "+pos+
" ) < "+byte_size+
" bytes");
212 System.arraycopy(source, pos,
b, 0, byte_size);
225 public final void getStream(
final byte[] sink,
final int pos) {
226 if( byte_size > ( sink.length - pos ) ) {
227 throw new IllegalArgumentException(
"Stream ( "+sink.length+
" - "+pos+
" ) < "+byte_size+
" bytes");
229 System.arraycopy(
b, 0, sink, pos, byte_size);
248 final byte high2 = (byte) ( (
b[5] >> 6 ) & 0x03 );
279 final StringBuilder sb =
new StringBuilder(17);
280 for(
int i=byte_size-1; 0 <= i; i--) {
286 return sb.toString();
boolean contains(final EUI48Sub needle)
Returns true, if given EUI48Sub is contained in here.
EUI48(final String str)
Construct instance via given string representation.
static BLERandomAddressType get(final byte value)
Maps the specified byte value to a constant of BLERandomAddressType.
EUI48()
Construct empty unset instance.
A 48 bit EUI-48 sub-identifier, see EUI48.
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
final byte b[]
The EUI48 sub-address, always 6 bytes reserved.
final void putStream(final byte[] source, final int pos)
Method transfers all bytes representing a EUI48 from the given source array at the given position int...
static final EUI48 LOCAL_DEVICE
EUI48 MAC address matching local device, i.e.
void clear()
Method clears the underlying byte array b and cached hash value.
static StringBuilder byteHexString(final StringBuilder sb, final byte value, final boolean lowerCase)
Produce a hexadecimal string representation of the given byte value.
static final EUI48 ANY_DEVICE
EUI48 MAC address matching any device, i.e.
final byte b[]
The 6 byte EUI48 address.
static final EUI48 ALL_DEVICE
EUI48 MAC address matching all device, i.e.
EUI48(final byte address[])
Construct instance using the given address of the byte array.
int length
The actual length in bytes of the EUI48 sub-address, less or equal 6 bytes.
final void getStream(final byte[] sink, final int pos)
Method transfers all bytes representing this instance into the given destination array at the given p...
BDADDR_LE_RANDOM
Bluetooth LE random address, see BLERandomAddressType.
final boolean equals(final Object obj)
Bluetooth address type constants.
EUI48(final byte stream[], final int pos)
Construct instance via given source byte array.
Bluetooth LE random address type constants.
int indexOf(final EUI48Sub needle)
Finds the index of given EUI48Sub.
static int indexOf(final byte haystack_b[], final int haystack_length, final byte needle_b[], final int needle_length)
Find index of needle within haystack.
void clearHash()
Method clears the cached hash value.
static boolean scanEUI48(final String str, final EUI48 dest, final StringBuilder errmsg)
Fills given EUI48 instance via given string representation.
BLERandomAddressType getBLERandomAddressType(final BDAddressType addressType)
Returns the BLERandomAddressType.