26 package jau.direct_bt;
28 import java.lang.ref.WeakReference;
29 import java.util.List;
46 final WeakReference<DBTGattService> wbr_service;
54 private final short handle;
59 private final String value_type_uuid;
67 private final short value_handle;
70 private final int clientCharacteristicsConfigIndex;
72 final List<BTGattDesc> descriptorList;
74 boolean enabledNotifyState =
false;
75 boolean enabledIndicateState =
false;
79 final String value_type_uuid,
final short value_handle,
80 final int clientCharacteristicsConfigIndex)
82 super(nativeInstance, handle );
83 this.wbr_service =
new WeakReference<DBTGattService>(service);
86 this.properties = properties;
87 this.value_type_uuid = value_type_uuid;
88 this.value_handle = value_handle;
89 this.clientCharacteristicsConfigIndex = clientCharacteristicsConfigIndex;
90 this.descriptorList = getDescriptorsImpl();
96 if( hasNotify || hasIndicate ) {
99 public void notificationReceived(
final BTGattChar charDecl,
final byte[] value,
final long timestamp) {
100 System.err.println(
"GATTCharacteristicListener.notificationReceived: "+charDecl+
104 public void indicationReceived(
final BTGattChar charDecl,
final byte[] value,
final long timestamp,
105 final boolean confirmationSent) {
106 System.err.println(
"GATTCharacteristicListener.indicationReceived: "+charDecl+
108 "], confirmationSent "+confirmationSent);
128 if (obj ==
null || !(obj instanceof
DBTGattChar)) {
132 return handle == other.handle;
136 public String
getUUID() {
return value_type_uuid; }
145 {
throw new UnsupportedOperationException(); }
149 if( !checkServiceCache() ) {
157 return find(UUID, 0);
165 enabledState[0] = enabledNotifyState;
166 enabledState[1] = enabledIndicateState;
167 return enabledNotifyState || enabledIndicateState;
175 return readValueImpl();
180 return writeValueImpl(value, withResponse);
187 public final synchronized boolean configNotificationIndication(
final boolean enableNotification,
final boolean enableIndication,
final boolean enabledState[])
188 throws IllegalStateException
193 if( hasNotify || hasIndicate ) {
194 final boolean resEnableNotification = hasNotify && enableNotification;
195 final boolean resEnableIndication = hasIndicate && enableIndication;
197 if( resEnableNotification == enabledNotifyState &&
198 resEnableIndication == enabledIndicateState )
200 enabledState[0] = resEnableNotification;
201 enabledState[1] = resEnableIndication;
203 System.err.printf(
"GATTCharacteristic.configNotificationIndication: Unchanged: notification[shall %b, has %b: %b == %b], indication[shall %b, has %b: %b == %b]\n",
204 enableNotification, hasNotify, enabledNotifyState, resEnableNotification,
205 enableIndication, hasIndicate, enabledIndicateState, resEnableIndication);
210 final boolean res = configNotificationIndicationImpl(enableNotification, enableIndication, enabledState);
212 enabledState[0] =
false;
213 enabledState[1] =
false;
216 System.err.printf(
"GATTCharacteristic.configNotificationIndication: res %b, notification[shall %b, has %b: %b -> %b], indication[shall %b, has %b: %b -> %b]\n",
218 enableNotification, hasNotify, enabledNotifyState, enabledState[0],
219 enableIndication, hasIndicate, enabledIndicateState, enabledState[1]);
221 enabledNotifyState = enabledState[0];
222 enabledIndicateState = enabledState[1];
225 enabledState[0] =
false;
226 enabledState[1] =
false;
228 System.err.println(
"GATTCharacteristic.configNotificationIndication: FALSE*: hasNotify "+hasNotify+
", hasIndicate "+hasIndicate);
233 private native
boolean configNotificationIndicationImpl(
boolean enableNotification,
boolean enableIndication,
final boolean enabledState[])
234 throws IllegalStateException;
238 throws IllegalStateException
247 private final Listener delegate;
249 public DelegatedBTGattCharListener(
final BTGattChar characteristicMatch,
final Listener l) {
250 super(characteristicMatch);
255 public void notificationReceived(
final BTGattChar charDecl,
256 final byte[] value,
final long timestamp) {
257 delegate.notificationReceived(charDecl, value, timestamp);
261 public void indicationReceived(
final BTGattChar charDecl,
262 final byte[] value,
final long timestamp,
263 final boolean confirmationSent) {
264 delegate.indicationReceived(charDecl, value, timestamp, confirmationSent);
283 if( disableIndicationNotification ) {
316 return "Characteristic" +
"\u271D" +
"[uuid "+
getUUID()+
", handle 0x"+Integer.toHexString(handle)+
"]";
318 return toStringImpl();
323 private native String toStringImpl();
325 private native
byte[] readValueImpl() throws
BTException;
327 private native
boolean writeValueImpl(
byte[] argValue,
boolean withResponse) throws
BTException;
329 private native List<
BTGattDesc> getDescriptorsImpl();
336 boolean checkServiceCache() {
338 if(
null == service ) {
341 final DBTDevice device = service.wbr_device.get();
342 return null != device && device.checkServiceCache(
false);
368 if( !anyType && !descType ) {
371 final int size = descriptorList.size();
372 for(
int i = 0; i < size; i++ ) {
373 final DBTGattDesc descr = (DBTGattDesc) descriptorList.get(i);
374 if(
null == uuid || descr.getUUID().equals(uuid) ) {