當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothGattCharacteristic.getIntValue方法代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothGattCharacteristic.getIntValue方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattCharacteristic.getIntValue方法的具體用法?Java BluetoothGattCharacteristic.getIntValue怎麽用?Java BluetoothGattCharacteristic.getIntValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.bluetooth.BluetoothGattCharacteristic的用法示例。


在下文中一共展示了BluetoothGattCharacteristic.getIntValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readVersion

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
 * Reads the DFU Version characteristic if such exists. Otherwise it returns 0.
 *
 * @param gatt           the GATT device
 * @param characteristic the characteristic to read
 * @return a version number or 0 if not present on the bootloader
 * @throws DeviceDisconnectedException
 * @throws DfuException
 * @throws UploadAbortedException
 */
private int readVersion(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) throws DeviceDisconnectedException, DfuException, UploadAbortedException {
    if (mConnectionState != STATE_CONNECTED_AND_READY)
        throw new DeviceDisconnectedException("Unable to read version number", mConnectionState);
    // If the DFU Version characteristic is not available we return 0.
    if (characteristic == null)
        return 0;

    mReceivedData = null;
    mError = 0;

    logi("Reading DFU version number...");
    sendLogBroadcast(LOG_LEVEL_VERBOSE, "Reading DFU version number...");

    gatt.readCharacteristic(characteristic);

    // We have to wait until device receives a response or an error occur
    try {
        synchronized (mLock) {
            while ((!mRequestCompleted && mConnectionState == STATE_CONNECTED_AND_READY && mError == 0 && !mAborted) || mPaused)
                mLock.wait();
        }
    } catch (final InterruptedException e) {
        loge("Sleeping interrupted", e);
    }

    if (mAborted)
        throw new UploadAbortedException();

    if (mError != 0)
        throw new DfuException("Unable to read version number", mError);

    if (mConnectionState != STATE_CONNECTED_AND_READY)
        throw new DeviceDisconnectedException("Unable to read version number", mConnectionState);

    // The version is a 16-bit unsigned int
    return characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 0);
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:48,代碼來源:DfuBaseService.java

示例2: onCharacteristicChanged

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
public final void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
	final String data = ParserUtils.parse(characteristic);

	if (isBatteryLevelCharacteristic(characteristic)) {
		Logger.i(mLogSession, "Notification received from " + characteristic.getUuid() + ", value: " + data);
		final int batteryValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
		Logger.a(mLogSession, "Battery level received: " + batteryValue + "%");
		mCallbacks.onBatteryValueReceived(batteryValue);
	} else {
		final BluetoothGattDescriptor cccd = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
		final boolean notifications = cccd == null || cccd.getValue() == null || cccd.getValue().length != 2 || cccd.getValue()[0] == 0x01;

		if (notifications) {
			Logger.i(mLogSession, "Notification received from " + characteristic.getUuid() + ", value: " + data);
			onCharacteristicNotified(gatt, characteristic);
		} else { // indications
			Logger.i(mLogSession, "Indication received from " + characteristic.getUuid() + ", value: " + data);
			onCharacteristicIndicated(gatt, characteristic);
		}
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:23,代碼來源:BleManager.java

示例3: broadcastUpdate

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
private void broadcastUpdate(final String action,
                             final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // This is special handling for the Heart Rate Measurement profile.  Data parsing is
    // carried out as per profile specifications:
    // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
        int flag = characteristic.getProperties();
        int format = -1;
        if ((flag & 0x01) != 0) {
            format = BluetoothGattCharacteristic.FORMAT_UINT16;
            Log.d(TAG, "Heart rate format UINT16.");
        } else {
            format = BluetoothGattCharacteristic.FORMAT_UINT8;
            Log.d(TAG, "Heart rate format UINT8.");
        }
        final int heartRate = characteristic.getIntValue(format, 1);
        Log.d(TAG, String.format("Received heart rate: %d", heartRate));
        intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));
    } else {
        // For all other profiles, writes the data formatted in HEX.
        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for(byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));
            intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString());
        }
    }
    sendBroadcast(intent);
}
 
開發者ID:richhowley,項目名稱:Android-BLE-to-Arduino,代碼行數:33,代碼來源:BluetoothLeService.java

示例4: handleCharacteristicChanged

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
private void handleCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    String UUID = characteristic.getUuid().toString();

    Integer integerValue = characteristic.getIntValue(GattFormats.FORMAT_UINT32, 0);

    if(integerValue == null) {
        return;
    }
    int value = integerValue;
    int eventSrc = value & 0x0ffff;
    if(eventSrc < 1001) {
        return;
    }
    logi("Characteristic UUID = " + UUID);
    logi("Characteristic Value = " + value);
    logi("eventSrc = " + eventSrc);

    int event = (value >> 16) & 0x0ffff;
    logi("event = " + event);
    sendMessage(eventSrc, event);
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:22,代碼來源:BLEService.java

示例5: parse

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
 * This method converts the value of the characteristic to the String. The String is then logged in the nRF logger log session
 * @param characteristic the characteristic to be parsed
 * @return human readable value of the characteristic
 */
public static String parse(final BluetoothGattCharacteristic characteristic) {
	int offset = 0;
	final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);

	/*
	 * In the template we are using the HRM values as an example.
	 * false 	Heart Rate Value Format is set to UINT8. Units: beats per minute (bpm) 
	 * true 	Heart Rate Value Format is set to UINT16. Units: beats per minute (bpm)
	 */
	final boolean value16bit = (flags & HEART_RATE_VALUE_FORMAT) > 0;

	// heart rate value is 8 or 16 bit long
	int value = characteristic.getIntValue(value16bit ? BluetoothGattCharacteristic.FORMAT_UINT16 : BluetoothGattCharacteristic.FORMAT_UINT8, offset++); // bits per minute
	if (value16bit)
		offset++;

	// TODO parse more data

	final StringBuilder builder = new StringBuilder();
	builder.append("Template Measurement: ").append(value).append(" bpm");
	return builder.toString();
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:28,代碼來源:TemplateParser.java

示例6: onCharacteristicNotified

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
protected void onCharacteristicNotified(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
	// TODO this method is called when a notification has been received
	// This method may be removed from this class if not required

	if (mLogSession != null)
		Logger.a(mLogSession, TemplateParser.parse(characteristic));

	int value;
	final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
	if ((flags & 0x01) > 0) {
		value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 1);
	} else {
		value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1);
	}
	//This will send callback to the Activity when new value is received from HR device
	mCallbacks.onSampleValueReceived(value);
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:19,代碼來源:TemplateManager.java

示例7: processRidingMode

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
private void processRidingMode(byte[] incomingValue, DeviceCharacteristic dc, BluetoothGattCharacteristic incomingCharacteristic) {

        int ridemode = incomingCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1);
        String rideMode1 = Integer.toString(ridemode);
        Timber.d("rideMode1 = " + rideMode1);

        dc.value.set(rideMode1);
    }
 
開發者ID:ponewheel,項目名稱:android-ponewheel,代碼行數:9,代碼來源:OWDevice.java

示例8: broadcastUpdate

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
private void broadcastUpdate(final String action,
                             final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // This is special handling for the Environmental Sensing profile.  Data parsing is
    // carried out as per profile specifications:
    // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml
    if (IGrowGattAttributes.TEMPERATURE.equals(characteristic.getUuid())) {

        int format = BluetoothGattCharacteristic.FORMAT_SINT16;
        Log.d(TAG, "Temperature format SINT16.");

        final int temperature = characteristic.getIntValue(format, 1);
        Log.d(TAG, String.format("Received temperature: %d", temperature));
        intent.putExtra(BluetoothLeService.EXTRA_DATA, String.valueOf(temperature));
    } else {
        // For all other profiles, writes the data formatted in HEX.
        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for (byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));
            intent.putExtra(BluetoothLeService.EXTRA_DATA, new String(data)
                    + "\n" + stringBuilder.toString());
        }
    }
    sendBroadcast(intent);
}
 
開發者ID:igrow-systems,項目名稱:igrow-android,代碼行數:29,代碼來源:BluetoothLeScanService.java

示例9: getCharacteristicValueInt

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public int getCharacteristicValueInt(UUID serviceUuid, UUID characteristicUuid, int format, int ofst){
	BluetoothGattService service = gattConnection.getService(serviceUuid);
	if(service == null)
		return -1;
	BluetoothGattCharacteristic ch = service.getCharacteristic(characteristicUuid);
	if(ch == null)
		return -1;
	return ch.getIntValue(format, ofst);
}
 
開發者ID:MB3hel,項目名稱:Quick-Bluetooth-LE,代碼行數:10,代碼來源:BLEClient.java

示例10: parse

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
	int offset = 0;
	final int flags = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset++);

	/*
	 * false 	Temperature is in Celsius degrees 
	 * true 	Temperature is in Fahrenheit degrees 
	 */
	final boolean fahrenheit = (flags & TEMPERATURE_UNIT_FLAG) > 0;

	/*
	 * false 	No Timestamp in the packet
	 * true 	There is a timestamp information
	 */
	final boolean timestampIncluded = (flags & TIMESTAMP_FLAG) > 0;

	/*
	 * false 	Temperature type is not included
	 * true 	Temperature type included in the packet
	 */
	final boolean temperatureTypeIncluded = (flags & TEMPERATURE_TYPE_FLAG) > 0;

	final float tempValue = characteristic.getFloatValue(BluetoothGattCharacteristic.FORMAT_FLOAT, offset);
	offset += 4;

	String dateTime = null;
	if (timestampIncluded) {
		dateTime = DateTimeParser.parse(characteristic, offset);
		offset += 7;
	}

	String type = null;
	if (temperatureTypeIncluded) {
		type = TemperatureTypeParser.parse(characteristic, offset);
		// offset++;
	}

	final StringBuilder builder = new StringBuilder();
	builder.append(String.format("%.02f", tempValue));

	if (fahrenheit)
		builder.append("°F");
	else
		builder.append("°C");

	if (timestampIncluded)
		builder.append("\nTime: ").append(dateTime);
	if (temperatureTypeIncluded)
		builder.append("\nType: ").append(type);
	return builder.toString();
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:52,代碼來源:TemperatureMeasurementParser.java

示例11: parse

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
 * Parses the alert level.
 * 
 * @param characteristic
 * @return alert level in human readable format
 */
public static String parse(final BluetoothGattCharacteristic characteristic) {
	final int value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);

	switch (value) {
	case 0:
		return "No Alert";
	case 1:
		return "Mild Alert";
	case 2:
		return "High Alert";
	default:
		return "Reserved value (" + value + ")";
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:21,代碼來源:AlertLevelParser.java

示例12: onCharacteristicRead

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
public final void onCharacteristicRead(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic, final int status) {
	if (status == BluetoothGatt.GATT_SUCCESS) {
		Logger.i(mLogSession, "Read Response received from " + characteristic.getUuid() + ", value: " + ParserUtils.parse(characteristic));

		if (isBatteryLevelCharacteristic(characteristic)) {
			final int batteryValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);
			Logger.a(mLogSession, "Battery level received: " + batteryValue + "%");
			mCallbacks.onBatteryValueReceived(batteryValue);

			// The Battery Level value has been read. Let's try to enable Battery Level notifications.
			// If the Battery Level characteristic does not have the NOTIFY property, proceed with the initialization queue.
			if (!setBatteryNotifications(true))
				nextRequest();
		} else {
			// The value has been read. Notify the manager and proceed with the initialization queue.
			onCharacteristicRead(gatt, characteristic);
			nextRequest();
		}
	} else if (status == BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION) {
		if (gatt.getDevice().getBondState() != BluetoothDevice.BOND_NONE) {
			DebugLogger.w(TAG, ERROR_AUTH_ERROR_WHILE_BONDED);
			mCallbacks.onError(ERROR_AUTH_ERROR_WHILE_BONDED, status);
		}
	} else {
		DebugLogger.e(TAG, "onCharacteristicRead error " + status);
		onError(ERROR_READ_CHARACTERISTIC, status);
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:30,代碼來源:BleManager.java

示例13: onCharacteristicNotified

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
@Override
public void onCharacteristicNotified(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) {
	if (mLogSession != null)
		Logger.a(mLogSession, HeartRateMeasurementParser.parse(characteristic));

	int hrValue;
	if (isHeartRateInUINT16(characteristic.getValue()[0])) {
		hrValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, 1);
	} else {
		hrValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 1);
	}
	//This will send callback to HRSActivity when new HR value is received from HR device
	mCallbacks.onHRValueReceived(hrValue);
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:15,代碼來源:HRSManager.java

示例14: parse

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
public static String parse(final BluetoothGattCharacteristic characteristic) {
	int offset = 0;
	final int flags = characteristic.getValue()[offset]; // 1 byte
	offset += 1;

	final boolean islmPresent = (flags & INSTANTANEOUS_STRIDE_LENGTH_PRESENT) > 0;
	final boolean tdPreset = (flags & TOTAL_DISTANCE_PRESENT) > 0;
	final boolean running = (flags & WALKING_OR_RUNNING_STATUS_BITS) > 0;
	final boolean walking = !running;

	final float instantaneousSpeed = (float) characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset) / 256.0f; // 1/256 m/s
	offset += 2;

	final int instantaneousCadence = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset);
	offset += 1;

	float instantaneousStrideLength = 0;
	if (islmPresent) {
		instantaneousStrideLength = (float) characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset) / 100.0f; // 1/100 m
		offset += 2;
	}

	float totalDistance = 0;
	if (tdPreset) {
		totalDistance = (float) characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, offset) / 10.0f;
		// offset += 4;
	}

	final StringBuilder builder = new StringBuilder();
	builder.append(String.format("Speed: %.2f m/s, Cadence: %d RPM,\n", instantaneousSpeed, instantaneousCadence));
	if (islmPresent)
		builder.append(String.format("Instantaneous Stride Length: %.2f m,\n", instantaneousStrideLength));
	if (tdPreset)
		builder.append(String.format("Total Distance: %.1f m,\n", totalDistance));
	if (walking)
		builder.append("Status: WALKING");
	else
		builder.append("Status: RUNNING");
	return builder.toString();
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:41,代碼來源:RSCMeasurementParser.java

示例15:

import android.bluetooth.BluetoothGattCharacteristic; //導入方法依賴的package包/類
/**
 * Parses the date and time info. This data has 7 bytes
 * 
 * @param characteristic
 * @param offset
 *            offset to start reading the time
 * @return time in human readable format
 */
/* package */static String parse(final BluetoothGattCharacteristic characteristic, final int offset) {
	final int year = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT16, offset);
	final int month = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 2);
	final int day = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 3);
	final int hours = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 4);
	final int minutes = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 5);
	final int seconds = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, offset + 6);

	final Calendar calendar = Calendar.getInstance();
	calendar.set(year, month - 1, day, hours, minutes, seconds);

	return String.format(Locale.US, "%1$te %1$tb %1$tY, %1$tH:%1$tM:%1$tS", calendar);
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:22,代碼來源:DateTimeParser.java


注:本文中的android.bluetooth.BluetoothGattCharacteristic.getIntValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。