简体   繁体   中英

Two methods to send data via Bluetooth LE

I'm studying an Android app to which sends data through Bluetooth LE. There are two methods here i'm confused about. Can someone please explain the the two methods and their relation to each other:

private String localmessage = null;
public void Send_Oe_Ef(BluetoothDevice device,String message) 
{
    localmessage= message;
    Send_Oe_Ef(device);
}

public void Send_Oe_Ef(BluetoothDevice device) 
{
    boolean result = false;
    Log.i(TAG, "Send_Oe_Ef ");
    isNoti = true;
    BluetoothGattService mCC2540 = mBluetoothGatt.getService(device, CC2540_SERVICE);
    if (mCC2540 == null) 
    {
        Log.e(TAG, "CC2540 service not found!");
        return;
    }
    BluetoothGattCharacteristic mHRMcharac = mCC2540.getCharacteristic(CC2540_CHARACTERISTIC);
    if (mHRMcharac == null) {
        Log.e(TAG, "CC2540 charateristic not found!");
        return;
    }
    byte[] value = new byte[14];
    value[0] = (byte) 1;
    value[1] = (byte) 2;
    value[2] = (byte) 3;
    value[3] = (byte) 4;
    value[4] = (byte) 5;
    value[5] = (byte) 6;
    value[6] = (byte) 7;
    value[7] = (byte) 8;
    value[8] = (byte) 9;
    value[9] = (byte) 10;
    value[10] = (byte) 11;
    value[11] = (byte) 12;
    value[12] = (byte) 13;
    value[13] = (byte) 14;

    try 
    {           
        value = localmessage.getBytes("UTF-8");

    } catch (UnsupportedEncodingException e) 
    {
        e.printStackTrace();
    }


    mHRMcharac.setValue(value);
    mBluetoothGatt.writeCharacteristic(mHRMcharac);

    Log.e(TAG, "SetValue");

}

Thanks in advance

The first method is calling the second method. For a second I thought they where constructors for the class, but of course they are not.

BLE uses the GATT protocol. In simple words, the GATT protocol is composed of services which in turn are composed of characteristics. A characteristic describes the measured entity you want to access on the remote device. Typically each device has a specific UUID with which you can connect to it. For example, if you look at the TI SensorTag you will use F0000000-0451-4000-B000-00000000AA01 to connect to its temperature sensor. http://processors.wiki.ti.com/index.php/SensorTag_User_Guide

From what I can tell

BluetoothGattService mCC2540 = mBluetoothGatt.getService(device, CC2540_SERVICE);

is trying to get the service, on the remote device, that is defined on the constant CC2540_SERVICE.

This line

BluetoothGattCharacteristic mHRMcharac = mCC2540.getCharacteristic(CC2540_CHARACTERISTIC);

is trying to access the characteristic inside service mCC2540 referenced by CC2540_CHARACTERISTIC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM