简体   繁体   English

通过蓝牙LE发送数据的两种方法

[英]Two methods to send data via Bluetooth LE

I'm studying an Android app to which sends data through Bluetooth LE. 我正在研究一个通过蓝牙LE向其发送数据的Android应用。 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. BLE使用GATT协议。 In simple words, the GATT protocol is composed of services which in turn are composed of characteristics. 简而言之,GATT协议由服务组成,而服务又由特征组成。 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. 通常,每个设备都有一个特定的UUID,您可以使用它连接到该设备。 For example, if you look at the TI SensorTag you will use F0000000-0451-4000-B000-00000000AA01 to connect to its temperature sensor. 例如,如果您查看TI SensorTag,则将使用F0000000-0451-4000-B000-00000000AA01连接到其温度传感器。 http://processors.wiki.ti.com/index.php/SensorTag_User_Guide 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. 正在尝试获取在远程设备上由常量CC2540_SERVICE定义的服务。

This line 这条线

BluetoothGattCharacteristic mHRMcharac = mCC2540.getCharacteristic(CC2540_CHARACTERISTIC);

is trying to access the characteristic inside service mCC2540 referenced by CC2540_CHARACTERISTIC 正在尝试访问CC2540_CHARACTERISTIC引用的服务mCC2540内部的特征

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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