Java Code Examples for android.bluetooth.BluetoothGattCharacteristic#PROPERTY_SIGNED_WRITE

The following examples show how to use android.bluetooth.BluetoothGattCharacteristic#PROPERTY_SIGNED_WRITE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From easyble-x with Apache License 2.0 6 votes vote down vote up
private String getPropertiesString(Item node) {
    StringBuilder sb = new StringBuilder();
    int[] properties = new int[]{BluetoothGattCharacteristic.PROPERTY_WRITE, BluetoothGattCharacteristic.PROPERTY_INDICATE,
            BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PROPERTY_READ,
            BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE};
    String[] propertyStrs = new String[]{"WRITE", "INDICATE", "NOTIFY", "READ", "SIGNED_WRITE", "WRITE_NO_RESPONSE"};
    for (int i = 0; i < properties.length; i++) {
        int property = properties[i];
        if ((node.characteristic.getProperties() & property) != 0) {
            if (sb.length() != 0) {
                sb.append(", ");
            }
            sb.append(propertyStrs[i]);
            if (property == BluetoothGattCharacteristic.PROPERTY_NOTIFY || property == BluetoothGattCharacteristic.PROPERTY_INDICATE) {
                node.hasNotifyProperty = true;
            }
            if (property == BluetoothGattCharacteristic.PROPERTY_WRITE || property == BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) {
                node.hasWriteProperty = true;
            }
            if (property == BluetoothGattCharacteristic.PROPERTY_READ) {
                node.hasReadProperty = true;
            }
        }
    }
    return sb.toString();
}
 
Example 2
Source File: P_DeviceServiceManager.java    From AsteroidOSSync with GNU General Public License v3.0 6 votes vote down vote up
private static int getProperty(BleDevice.ReadWriteListener.Type type)
{
	switch(type)
	{
		case READ:
		case POLL:
		case PSUEDO_NOTIFICATION:	return		BluetoothGattCharacteristic.PROPERTY_READ;
		
           case WRITE_NO_RESPONSE:     return      BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE;
           case WRITE_SIGNED:          return      BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE;
           case WRITE:					return		BluetoothGattCharacteristic.PROPERTY_WRITE;
   
		case ENABLING_NOTIFICATION:
		case DISABLING_NOTIFICATION:
		case NOTIFICATION:
		case INDICATION:			return		BluetoothGattCharacteristic.PROPERTY_INDICATE			|
												BluetoothGattCharacteristic.PROPERTY_NOTIFY				;
	}
	
	return 0x0;
}
 
Example 3
Source File: P_DeviceServiceManager.java    From SweetBlue with GNU General Public License v3.0 6 votes vote down vote up
private static int getProperty(BleDevice.ReadWriteListener.Type type)
{
	switch(type)
	{
		case READ:
		case POLL:
		case PSUEDO_NOTIFICATION:	return		BluetoothGattCharacteristic.PROPERTY_READ;
		
           case WRITE_NO_RESPONSE:     return      BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE;
           case WRITE_SIGNED:          return      BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE;
           case WRITE:					return		BluetoothGattCharacteristic.PROPERTY_WRITE;
   
		case ENABLING_NOTIFICATION:
		case DISABLING_NOTIFICATION:
		case NOTIFICATION:
		case INDICATION:			return		BluetoothGattCharacteristic.PROPERTY_INDICATE			|
												BluetoothGattCharacteristic.PROPERTY_NOTIFY				;
	}
	
	return 0x0;
}
 
Example 4
Source File: BleGattCallback.java    From attach with GNU General Public License v3.0 5 votes vote down vote up
private String getProperties(int bitmask) {
    String properties = "";

    if ((bitmask & BluetoothGattCharacteristic.PROPERTY_BROADCAST) != 0) {
        properties += "broadcast, ";
    }
    if ((bitmask & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) != 0) {
        properties += "extended props, ";
    }
    if ((bitmask & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) {
        properties += "indicate, ";
    }
    if ((bitmask & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) {
        properties += "notify, ";
    }
    if ((bitmask & BluetoothGattCharacteristic.PROPERTY_READ) != 0) {
        properties += "read, ";
    }
    if ((bitmask & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0) {
        properties += "signed write, ";
    }
    if ((bitmask & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0) {
        properties += "write, ";
    }
    if ((bitmask & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0) {
        properties += "write no response, ";
    }

    return properties.isEmpty() ? "" : properties.substring(0, properties.length() - 2);
}
 
Example 5
Source File: ParserUtils.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String getProperties(final BluetoothGattCharacteristic characteristic) {
    final int properties = characteristic.getProperties();
    final StringBuilder builder = new StringBuilder();
    if ((properties & BluetoothGattCharacteristic.PROPERTY_BROADCAST) > 0)
        builder.append("B ");
    if ((properties & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) > 0)
        builder.append("E ");
    if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0)
        builder.append("I ");
    if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0)
        builder.append("N ");
    if ((properties & BluetoothGattCharacteristic.PROPERTY_READ) > 0)
        builder.append("R ");
    if ((properties & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) > 0)
        builder.append("SW ");
    if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0)
        builder.append("W ");
    if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) > 0)
        builder.append("WNR ");

    if (builder.length() > 0) {
        builder.setLength(builder.length() - 1);
        builder.insert(0, "[");
        builder.append("]");
    }
    return builder.toString();
}
 
Example 6
Source File: ConnectionModule.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Provides
static CharacteristicPropertiesParser provideCharacteristicPropertiesParser() {
    return new CharacteristicPropertiesParser(BluetoothGattCharacteristic.PROPERTY_BROADCAST,
            BluetoothGattCharacteristic.PROPERTY_READ,
            BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE,
            BluetoothGattCharacteristic.PROPERTY_WRITE,
            BluetoothGattCharacteristic.PROPERTY_NOTIFY,
            BluetoothGattCharacteristic.PROPERTY_INDICATE,
            BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE);
}
 
Example 7
Source File: BluetoothDebug.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
private boolean isWriteType(int property, int writeType) {
    switch (property) {
        case BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE:
            return writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE;
        case BluetoothGattCharacteristic.PROPERTY_WRITE:
            return writeType == BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT;
        case BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE:
            return writeType == BluetoothGattCharacteristic.WRITE_TYPE_SIGNED;
    }
    return false;
}
 
Example 8
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 4 votes vote down vote up
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
String getStringRepresentationOfPropertiesForCharacteristic(BluetoothGattCharacteristic characteristic) {
    StringBuilder propertyBuilder = new StringBuilder();
    ArrayList<Integer> properties = new ArrayList<>(8);
    int characteristicProperties = characteristic.getProperties();
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_READ) == BluetoothGattCharacteristic.PROPERTY_READ) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_READ);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_WRITE) == BluetoothGattCharacteristic.PROPERTY_WRITE) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_WRITE);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_BROADCAST) == BluetoothGattCharacteristic.PROPERTY_BROADCAST) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_BROADCAST);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) == BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_INDICATE) == BluetoothGattCharacteristic.PROPERTY_INDICATE) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_INDICATE);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == BluetoothGattCharacteristic.PROPERTY_NOTIFY) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_NOTIFY);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) == BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE);
    }
    if ((characteristicProperties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) == BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) {
        properties.add(BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE);
    }
    for (int i = 0; i < properties.size(); i++) {
        int property = properties.get(i);
        switch (property) {
            case BluetoothGattCharacteristic.PROPERTY_READ:
                propertyBuilder.append("read");
                break;
            case BluetoothGattCharacteristic.PROPERTY_WRITE:
                propertyBuilder.append("write");
                break;
            case BluetoothGattCharacteristic.PROPERTY_BROADCAST:
                propertyBuilder.append("broadcast");
                break;
            case BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS:
                propertyBuilder.append("extended-props");
                break;
            case BluetoothGattCharacteristic.PROPERTY_NOTIFY:
                propertyBuilder.append("notify");
                break;
            case BluetoothGattCharacteristic.PROPERTY_INDICATE:
                propertyBuilder.append("indicate");
                break;
            case BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE:
                propertyBuilder.append("write-signed");
                break;
            case BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE:
                propertyBuilder.append("write-no-response");
                break;
            default:
                propertyBuilder.append("unknown");
        }
        if (i < properties.size() - 1) {
            propertyBuilder.append(", ");
        }
    }
    return propertyBuilder.toString();
}
 
Example 9
Source File: GattDatabase.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
public final Properties signed_write()
{
    m_properties |= BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE;
    return this;
}
 
Example 10
Source File: P_DeviceServiceManager.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
static BleDevice.ReadWriteListener.Type modifyResultType(BleCharacteristicWrapper char_native, BleDevice.ReadWriteListener.Type type)
{
	if( !char_native.isNull())
	{
		if( type == Type.NOTIFICATION )
		{
			if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0x0 )
			{
				if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 )
				{
					type = Type.INDICATION;
				}
			}
		}
		else if( type == Type.WRITE )
		{
			if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0x0 )
			{
				if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0 )
				{
					type = Type.WRITE_NO_RESPONSE;
				}
				else if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0 )
				{
					type = Type.WRITE_SIGNED;
				}
			}
			//--- RB > Check the write type on the characteristic, in case this char has multiple write types
			int writeType = char_native.getCharacteristic().getWriteType();
			if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE)
			{
				type = Type.WRITE_NO_RESPONSE;
			}
			else if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_SIGNED)
			{
				type = Type.WRITE_SIGNED;
			}
		}
	}
	
	return type;
}
 
Example 11
Source File: Helper.java    From react-native-ble-manager with Apache License 2.0 4 votes vote down vote up
public static WritableMap decodeProperties(BluetoothGattCharacteristic characteristic) {

		// NOTE: props strings need to be consistent across iOS and Android
		WritableMap props = Arguments.createMap();
		int properties = characteristic.getProperties();

		if ((properties & BluetoothGattCharacteristic.PROPERTY_BROADCAST) != 0x0 ) {
			props.putString("Broadcast", "Broadcast");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_READ) != 0x0 ) {
			props.putString("Read", "Read");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0 ) {
			props.putString("WriteWithoutResponse", "WriteWithoutResponse");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0x0 ) {
			props.putString("Write", "Write");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0x0 ) {
			props.putString("Notify", "Notify");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 ) {
			props.putString("Indicate", "Indicate");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0 ) {
			// Android calls this "write with signature", using iOS name for now
			props.putString("AuthenticateSignedWrites", "AuthenticateSignedWrites");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) != 0x0 ) {
			props.putString("ExtendedProperties", "ExtendedProperties");
		}

//      iOS only?
//
//            if ((p & CBCharacteristicPropertyNotifyEncryptionRequired) != 0x0) {  // 0x100
//                [props addObject:@"NotifyEncryptionRequired"];
//            }
//
//            if ((p & CBCharacteristicPropertyIndicateEncryptionRequired) != 0x0) { // 0x200
//                [props addObject:@"IndicateEncryptionRequired"];
//            }

		return props;
	}
 
Example 12
Source File: GattDatabase.java    From SweetBlue with GNU General Public License v3.0 4 votes vote down vote up
public final Properties signed_write()
{
    m_properties |= BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE;
    return this;
}
 
Example 13
Source File: GattDatabase.java    From SweetBlue with GNU General Public License v3.0 4 votes vote down vote up
public final Properties signed_write()
{
    m_properties |= BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE;
    return this;
}
 
Example 14
Source File: P_DeviceServiceManager.java    From SweetBlue with GNU General Public License v3.0 4 votes vote down vote up
static BleDevice.ReadWriteListener.Type modifyResultType(BleCharacteristicWrapper char_native, BleDevice.ReadWriteListener.Type type)
{
	if( !char_native.isNull())
	{
		if( type == Type.NOTIFICATION )
		{
			if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0x0 )
			{
				if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 )
				{
					type = Type.INDICATION;
				}
			}
		}
		else if( type == Type.WRITE )
		{
			if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0x0 )
			{
				if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0 )
				{
					type = Type.WRITE_NO_RESPONSE;
				}
				else if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0 )
				{
					type = Type.WRITE_SIGNED;
				}
			}
			//--- RB > Check the write type on the characteristic, in case this char has multiple write types
			int writeType = char_native.getCharacteristic().getWriteType();
			if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE)
			{
				type = Type.WRITE_NO_RESPONSE;
			}
			else if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_SIGNED)
			{
				type = Type.WRITE_SIGNED;
			}
		}
	}
	
	return type;
}