aboutsummaryrefslogtreecommitdiffstats
path: root/examples/java/DBTPeripheral00.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-01-28 04:19:47 +0100
committerSven Gothel <[email protected]>2022-01-28 04:19:47 +0100
commit68e8dc229c0344c900740c9c2706d0face0cc47f (patch)
treecca530e0c13fd82b1d5c25f2bb86f8197a84aeb9 /examples/java/DBTPeripheral00.java
parentd26240eb2c8aca0a4027a1fb0b86a656436d59c7 (diff)
DBGatt[Char|Desc] (Server): Add setValue(..), allowing user to safely overwrite (initial) value server side.
Also refine getValue() API doc. Implemented on C++ and Java side. Peripheral00 example uses this facility to set the DEVICE_NAME GATT value using the current adapter name.
Diffstat (limited to 'examples/java/DBTPeripheral00.java')
-rw-r--r--examples/java/DBTPeripheral00.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/examples/java/DBTPeripheral00.java b/examples/java/DBTPeripheral00.java
index 6cde923a..21a92ddb 100644
--- a/examples/java/DBTPeripheral00.java
+++ b/examples/java/DBTPeripheral00.java
@@ -121,6 +121,10 @@ public class DBTPeripheral00 {
final byte[] p = name.getBytes(StandardCharsets.UTF_8);
return new DBGattValue(p, p.length);
}
+ static DBGattValue make_gvalue(final String name, final int capacity) {
+ final byte[] p = name.getBytes(StandardCharsets.UTF_8);
+ return new DBGattValue(p, Math.max(capacity, p.length), capacity > p.length/* variable_length */);
+ }
static DBGattValue make_gvalue(final short v) {
final byte[] p = { (byte)0, (byte)0 };
p[0] = (byte)(v);
@@ -148,7 +152,7 @@ public class DBTPeripheral00 {
new DBGattChar( DBGattChar.UUID16.DEVICE_NAME /* value_type_ */,
new GattCharPropertySet(GattCharPropertySet.Type.Read),
new ArrayList<DBGattDesc>(/* intentionally w/o Desc */ ),
- make_gvalue(adapter_name) /* value */ ),
+ make_gvalue(adapter_name, 128) /* value */ ),
new DBGattChar( DBGattChar.UUID16.APPEARANCE /* value_type_ */,
new GattCharPropertySet(GattCharPropertySet.Type.Read),
new ArrayList<DBGattDesc>(/* intentionally w/o Desc */ ),
@@ -583,6 +587,12 @@ public class DBTPeripheral00 {
eir.setName(adapter.getName());
eir.setConnInterval((short)10, (short)24);
+ final DBGattChar gattDevNameChar = dbGattServer.findGattChar(DBGattService.UUID16.GENERIC_ACCESS, DBGattChar.UUID16.DEVICE_NAME);
+ if( null != gattDevNameChar ) {
+ final byte[] aname_bytes = adapter.getName().getBytes(StandardCharsets.UTF_8);
+ gattDevNameChar.setValue(aname_bytes, 0, aname_bytes.length, 0);
+ }
+
BTUtils.println(System.err, "****** Start advertising ("+msg+"): EIR "+eir.toString());
BTUtils.println(System.err, "****** Start advertising ("+msg+"): adv "+adv_mask.toString()+", scanrsp "+scanrsp_mask.toString());