All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.hypfvieh.bluetooth.wrapper.BluetoothGattDescriptor Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package com.github.hypfvieh.bluetooth.wrapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.bluez.GattDescriptor1;
import org.bluez.exceptions.BluezFailedException;
import org.bluez.exceptions.BluezInProgressException;
import org.bluez.exceptions.BluezInvalidValueLengthException;
import org.bluez.exceptions.BluezNotAuthorizedException;
import org.bluez.exceptions.BluezNotPermittedException;
import org.bluez.exceptions.BluezNotSupportedException;
import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.interfaces.DBusInterface;

/**
 * Wrapper class which represents a GATT descriptor on a remote device.
 *
 * @author hypfvieh
 *
 */
public class BluetoothGattDescriptor extends AbstractBluetoothObject {

    private final GattDescriptor1 descriptor;
    private final BluetoothGattCharacteristic characteristicWrapper;

    public BluetoothGattDescriptor(GattDescriptor1 _descriptor, BluetoothGattCharacteristic _characteristicWrapper, String _dbusPath, DBusConnection _dbusConnection) {
        super(BluetoothDeviceType.GATT_DESCRIPTOR, _dbusConnection, _dbusPath);
        characteristicWrapper = _characteristicWrapper;
        descriptor = _descriptor;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Class getInterfaceClass() {
        return GattDescriptor1.class;
    }

    /**
     * Write value to the GATT descriptor register.
* Supported options:
*
     * "offset": uint16 offset
     * "device": Object Device (Server only)
     * 
* @param _value value to write * @param _options options to use * @throws BluezFailedException on failure if anything failed * @throws BluezInProgressException when operation already in progress if operation in progress * @throws BluezNotPermittedException if operation not permitted * @throws BluezNotAuthorizedException when not authorized if not authorized * @throws BluezNotSupportedException when operation not supported if not supported * @throws BluezInvalidValueLengthException if length is invalid */ public void writeValue(byte[] _value, Map _options) throws BluezFailedException, BluezInProgressException, BluezNotPermittedException, BluezNotAuthorizedException, BluezNotSupportedException, BluezInvalidValueLengthException { descriptor.WriteValue(_value, optionsToVariantMap(_options)); } /** * Read a value from the GATT descriptor register.
* Supported options:
*
     * "offset": uint16 offset
     * "device": Object Device (Server only)
     * 
* @param _options options to use * @return byte array, maybe null * @throws BluezFailedException on failure if anything failed * @throws BluezInProgressException when operation already in progress if operation in progress * @throws BluezNotPermittedException if operation not permitted * @throws BluezNotAuthorizedException when not authorized if not authorized * @throws BluezNotSupportedException when operation not supported if not supported */ public byte[] readValue(Map _options) throws BluezFailedException, BluezInProgressException, BluezNotPermittedException, BluezNotAuthorizedException, BluezNotSupportedException { return descriptor.ReadValue(optionsToVariantMap(_options)); } /** * From bluez Documentation: *

* 128-bit descriptor UUID. *

* @return uuid, maybe null */ public String getUuid() { return getTyped("UUID", String.class); } /** * Get the {@link BluetoothGattCharacteristic} instance behind this {@link BluetoothGattDescriptor} object. * @return {@link BluetoothGattCharacteristic}, maybe null */ public BluetoothGattCharacteristic getCharacteristic() { return characteristicWrapper; } /** * Get the raw {@link GattDescriptor1} object behind this wrapper. * @return {@link GattDescriptor1}, maybe null */ public GattDescriptor1 getRawCharacteric() { return descriptor; } /** * From bluez Documentation: *

* The cached value of the descriptor. This property
* gets updated only after a successful read request, upon
* which a PropertiesChanged signal will be emitted. *

* @return byte array, maybe null */ public byte[] getValue() { List typed = getTyped("Value", ArrayList.class); if (typed != null) { return byteListToByteArray(typed); } return null; } /** * From bluez Documentation: *

* Defines how the descriptor value can be used.
*

* Possible values: *
     *      "read"
     *      "write"
     *      "encrypt-read"
     *      "encrypt-write"
     *      "encrypt-authenticated-read"
     *      "encrypt-authenticated-write"
     *      "secure-read" (Server Only)
     *      "secure-write" (Server Only)
     * 
* @return List of String, maybe null */ @SuppressWarnings("unchecked") public List getFlags() { List typed = getTyped("Flags", ArrayList.class); if (typed != null) { return (List) typed; } return null; } @Override public String toString() { return getClass().getSimpleName() + " [descriptor=" + descriptor + ", characteristicWrapper=" + characteristicWrapper.getDbusPath() + ", getBluetoothType()=" + getBluetoothType().name() + ", getDbusPath()=" + getDbusPath() + "]"; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy