public class BluetoothBytesParser
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
FORMAT_FLOAT
Characteristic value format type float (32-bit float)
|
static int |
FORMAT_SFLOAT
Characteristic value format type sfloat (16-bit float)
|
static int |
FORMAT_SINT16
Characteristic value format type sint16
|
static int |
FORMAT_SINT32
Characteristic value format type sint32
|
static int |
FORMAT_SINT8
Characteristic value format type sint8
|
static int |
FORMAT_UINT16
Characteristic value format type uint16
|
static int |
FORMAT_UINT32
Characteristic value format type uint32
|
static int |
FORMAT_UINT8
Characteristic value format type uint8
|
Constructor and Description |
---|
BluetoothBytesParser()
Create a BluetoothBytesParser that does not contain a byte array and sets the byteOrder to LITTLE_ENDIAN.
|
BluetoothBytesParser(byte[] value)
Create a BluetoothBytesParser and set the byte array and sets the byteOrder to LITTLE_ENDIAN.
|
BluetoothBytesParser(byte[] value,
java.nio.ByteOrder byteOrder)
Create a BluetoothBytesParser and set the byte array and byteOrder.
|
BluetoothBytesParser(byte[] value,
int offset)
Create a BluetoothBytesParser, set the byte array, the internal offset and the byteOrder to LITTLE_ENDIAN.
|
BluetoothBytesParser(byte[] value,
int offset,
java.nio.ByteOrder byteOrder)
Create a BluetoothBytesParser, set the byte array, the internal offset and the byteOrder.
|
BluetoothBytesParser(java.nio.ByteOrder byteOrder)
Create a BluetoothBytesParser that does not contain a byte array and sets the byteOrder.
|
Modifier and Type | Method and Description |
---|---|
static @NotNull java.lang.String |
bytes2String(@Nullable byte[] bytes)
Convert a byte array to a string
|
byte[] |
getByteArray(int length) |
java.nio.ByteOrder |
getByteOrder()
Get the set byte order
|
java.util.Date |
getDateTime()
Return a the date represented by the byte array.
|
java.util.Date |
getDateTime(int offset)
Get Date from characteristic with offset
|
java.lang.Float |
getFloatValue(int formatType)
Return a float value of the specified format.
|
java.lang.Float |
getFloatValue(int formatType,
java.nio.ByteOrder byteOrder)
Return a float value of the specified format and byte order.
|
java.lang.Float |
getFloatValue(int formatType,
int offset,
java.nio.ByteOrder byteOrder)
Return a float value of the specified format, offset and byte order.
|
java.lang.Integer |
getIntValue(int formatType)
Return an Integer value of the specified type.
|
java.lang.Integer |
getIntValue(int formatType,
java.nio.ByteOrder byteOrder)
Return an Integer value of the specified type and specified byte order.
|
java.lang.Integer |
getIntValue(int formatType,
int offset,
java.nio.ByteOrder byteOrder)
Return an Integer value of the specified type.
|
long |
getLongValue()
Return a Long value.
|
long |
getLongValue(java.nio.ByteOrder byteOrder)
Return a Long value using the specified byte order.
|
long |
getLongValue(int offset,
java.nio.ByteOrder byteOrder)
Return a Long value using the specified byte order and offset position.
|
int |
getOffset()
Get the value of the internal offset
|
java.lang.String |
getStringValue()
Return a String from this byte array.
|
java.lang.String |
getStringValue(int offset)
Return a String from this byte array.
|
byte[] |
getValue()
Get the byte array
|
static byte[] |
mergeArrays(byte[]... arrays)
Merge multiple arrays intro one array
|
boolean |
setCurrentTime(java.util.Calendar calendar)
Sets the byte array to represent the current date in CurrentTime format
|
boolean |
setDateTime(java.util.Calendar calendar)
Sets the byte array to represent the current date in CurrentTime format
|
boolean |
setFloatValue(float value,
int precision)
Create byte[] value from Float usingg a given precision, i.e.
|
boolean |
setFloatValue(int mantissa,
int exponent,
int formatType,
int offset)
Set byte array to a float of the specified type.
|
boolean |
setIntValue(int value,
int formatType)
Set byte array to an Integer with specified format.
|
boolean |
setIntValue(int value,
int formatType,
int offset)
Set the locally stored value of this byte array
|
boolean |
setLong(long value)
Set byte array to a long
|
boolean |
setLong(long value,
int offset)
Set byte array to a long
|
void |
setOffset(int offset)
Set the value of the internal offset
|
boolean |
setString(java.lang.String value)
Set byte array to a string at current offset
|
boolean |
setString(java.lang.String value,
int offset)
Set byte array to a string at specified offset position
|
void |
setValue(byte[] value)
Set the locally stored value of this byte array.
|
static @NotNull byte[] |
string2bytes(@Nullable java.lang.String hexString)
Convert a hex string to byte array
|
java.lang.String |
toString() |
public static final int FORMAT_UINT8
public static final int FORMAT_UINT16
public static final int FORMAT_UINT32
public static final int FORMAT_SINT8
public static final int FORMAT_SINT16
public static final int FORMAT_SINT32
public static final int FORMAT_SFLOAT
public static final int FORMAT_FLOAT
public BluetoothBytesParser()
public BluetoothBytesParser(java.nio.ByteOrder byteOrder)
public BluetoothBytesParser(byte[] value)
value
- byte arraypublic BluetoothBytesParser(byte[] value, java.nio.ByteOrder byteOrder)
value
- byte arraybyteOrder
- the byte order to use (either LITTLE_ENDIAN or BIG_ENDIAN)public BluetoothBytesParser(byte[] value, int offset)
value
- the byte arrayoffset
- the offset from which parsing will startpublic BluetoothBytesParser(byte[] value, int offset, java.nio.ByteOrder byteOrder)
value
- the byte arrayoffset
- the offset from which parsing will startbyteOrder
- the byte order, either LITTLE_ENDIAN or BIG_ENDIANpublic java.lang.Integer getIntValue(int formatType)
formatType
- The format type used to interpret the byte(s) valuepublic java.lang.Integer getIntValue(int formatType, java.nio.ByteOrder byteOrder)
formatType
- the format type used to interpret the byte(s) valuepublic long getLongValue()
public long getLongValue(java.nio.ByteOrder byteOrder)
public long getLongValue(int offset, java.nio.ByteOrder byteOrder)
public java.lang.Integer getIntValue(int formatType, int offset, java.nio.ByteOrder byteOrder)
The formatType parameter determines how the byte array
is to be interpreted. For example, settting formatType to
FORMAT_UINT16
specifies that the first two bytes of the
byte array at the given offset are interpreted to generate the
return value.
formatType
- The format type used to interpret the byte array.offset
- Offset at which the integer value can be found.byteOrder
- the byte order, either LITTLE_ENDIAN or BIG_ENDIANpublic java.lang.Float getFloatValue(int formatType)
formatType
- The format type used to interpret the byte arraypublic java.lang.Float getFloatValue(int formatType, java.nio.ByteOrder byteOrder)
formatType
- The format type used to interpret the byte arraybyteOrder
- the byte order, either LITTLE_ENDIAN or BIG_ENDIANpublic java.lang.Float getFloatValue(int formatType, int offset, java.nio.ByteOrder byteOrder)
formatType
- The format type used to interpret the byte arraybyteOrder
- the byte order, either LITTLE_ENDIAN or BIG_ENDIANpublic java.lang.String getStringValue()
public java.lang.String getStringValue(int offset)
offset
- Offset at which the string value can be found.public java.util.Date getDateTime()
The byte array must conform to the DateTime specification (year, month, day, hour, min, sec)
public java.util.Date getDateTime(int offset)
offset
- Offset of valuepublic byte[] getValue()
public byte[] getByteArray(int length)
public boolean setIntValue(int value, int formatType, int offset)
value
- New value for this byte arrayformatType
- Integer format type used to transform the value parameteroffset
- Offset at which the value should be placedpublic boolean setIntValue(int value, int formatType)
value
- New value for this byte arrayformatType
- Integer format type used to transform the value parameterpublic boolean setLong(long value)
value
- New long value for this byte arraypublic boolean setLong(long value, int offset)
value
- New long value for this byte arrayoffset
- Offset at which the value should be placedpublic boolean setFloatValue(int mantissa, int exponent, int formatType, int offset)
mantissa
- Mantissa for this float valueexponent
- exponent value for this float valueformatType
- Float format type used to transform the value parameteroffset
- Offset at which the value should be placedpublic boolean setFloatValue(float value, int precision)
value
- Float value to create byte[] fromprecision
- number of digits after the comma to usepublic boolean setString(java.lang.String value)
value
- String to be added to byte arraypublic boolean setString(java.lang.String value, int offset)
value
- String to be added to byte arrayoffset
- the offset to place the string atpublic void setValue(byte[] value)
value
- New value for this byte arraypublic boolean setCurrentTime(java.util.Calendar calendar)
calendar
- the calendar object representing the current datepublic boolean setDateTime(java.util.Calendar calendar)
calendar
- the calendar object representing the current date@NotNull public static @NotNull java.lang.String bytes2String(@Nullable @Nullable byte[] bytes)
bytes
- the bytes to convert@NotNull public static @NotNull byte[] string2bytes(@Nullable @Nullable java.lang.String hexString)
public static byte[] mergeArrays(byte[]... arrays)
arrays
- Arrays to mergepublic int getOffset()
public void setOffset(int offset)
public java.nio.ByteOrder getByteOrder()
public java.lang.String toString()
toString
in class java.lang.Object