use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.
the class MiBand2Support method requestBatteryInfo.
private MiBand2Support requestBatteryInfo(TransactionBuilder builder) {
LOG.debug("Requesting Battery Info!");
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_6_BATTERY_INFO);
builder.read(characteristic);
return this;
}
use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.
the class AlertNotificationProfile method newAlert.
public void newAlert(TransactionBuilder builder, NewAlert alert, OverflowStrategy strategy) {
BluetoothGattCharacteristic characteristic = getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_NEW_ALERT);
if (characteristic != null) {
String message = StringUtils.ensureNotNull(alert.getMessage());
if (message.length() > MAX_MSG_LENGTH && strategy == OverflowStrategy.TRUNCATE) {
message = StringUtils.truncate(message, MAX_MSG_LENGTH);
}
int numChunks = message.length() / MAX_MSG_LENGTH;
if (message.length() % MAX_MSG_LENGTH > 0) {
numChunks++;
}
try {
boolean hasAlerted = false;
for (int i = 0; i < numChunks; i++) {
int offset = i * MAX_MSG_LENGTH;
int restLength = message.length() - offset;
message = message.substring(offset, offset + Math.min(MAX_MSG_LENGTH, restLength));
if (hasAlerted && message.length() == 0) {
// no need to do it again when there is no text content
break;
}
builder.write(characteristic, getAlertMessage(alert, message, 1));
hasAlerted = true;
}
if (!hasAlerted) {
builder.write(characteristic, getAlertMessage(alert, "", 1));
}
} catch (IOException ex) {
// ain't gonna happen
LOG.error("Error writing alert message to ByteArrayOutputStream");
}
} else {
LOG.warn("NEW_ALERT characteristic not available");
}
}
use of android.bluetooth.BluetoothGattCharacteristic in project Gadgetbridge by Freeyourgadget.
the class MiBandSupport method onEnableRealtimeSteps.
@Override
public void onEnableRealtimeSteps(boolean enable) {
try {
BluetoothGattCharacteristic controlPoint = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
if (enable) {
TransactionBuilder builder = performInitialized("Read realtime steps");
builder.read(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_REALTIME_STEPS)).queue(getQueue());
}
performInitialized(enable ? "Enabling realtime steps notifications" : "Disabling realtime steps notifications").write(getCharacteristic(MiBandService.UUID_CHARACTERISTIC_LE_PARAMS), enable ? getLowLatency() : getHighLatency()).write(controlPoint, enable ? startRealTimeStepsNotifications : stopRealTimeStepsNotifications).queue(getQueue());
enableRealtimeSamplesTimer(enable);
} catch (IOException e) {
LOG.error("Unable to change realtime steps notification to: " + enable, e);
}
}
use of android.bluetooth.BluetoothGattCharacteristic in project Android-Developers-Samples by johnjohndoe.
the class DeviceControlActivity method displayGattServices.
// Demonstrates how to iterate through the supported GATT Services/Characteristics.
// In this sample, we populate the data structure that is bound to the ExpandableListView
// on the UI.
private void displayGattServices(List<BluetoothGattService> gattServices) {
if (gattServices == null)
return;
String uuid = null;
String unknownServiceString = getResources().getString(R.string.unknown_service);
String unknownCharaString = getResources().getString(R.string.unknown_characteristic);
ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();
ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>();
mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>();
// Loops through available GATT Services.
for (BluetoothGattService gattService : gattServices) {
HashMap<String, String> currentServiceData = new HashMap<String, String>();
uuid = gattService.getUuid().toString();
currentServiceData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownServiceString));
currentServiceData.put(LIST_UUID, uuid);
gattServiceData.add(currentServiceData);
ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<HashMap<String, String>>();
List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>();
// Loops through available Characteristics.
for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
charas.add(gattCharacteristic);
HashMap<String, String> currentCharaData = new HashMap<String, String>();
uuid = gattCharacteristic.getUuid().toString();
currentCharaData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString));
currentCharaData.put(LIST_UUID, uuid);
gattCharacteristicGroupData.add(currentCharaData);
}
mGattCharacteristics.add(charas);
gattCharacteristicData.add(gattCharacteristicGroupData);
}
SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(this, gattServiceData, android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID }, new int[] { android.R.id.text1, android.R.id.text2 }, gattCharacteristicData, android.R.layout.simple_expandable_list_item_2, new String[] { LIST_NAME, LIST_UUID }, new int[] { android.R.id.text1, android.R.id.text2 });
mGattServicesList.setAdapter(gattServiceAdapter);
}
use of android.bluetooth.BluetoothGattCharacteristic in project nikeplus-fuelband-se-reversed by evilsocket.
the class MainActivity method dumpServices.
private void dumpServices(BluetoothGatt gatt) {
for (BluetoothGattService svc : gatt.getServices()) {
String svc_uuid = svc.getUuid().toString(), svc_name = GATTAttributes.lookup(svc_uuid, "");
Logger.d("SERVICE " + svc_name + " ( " + svc_uuid + " )");
for (BluetoothGattCharacteristic chara : svc.getCharacteristics()) {
String chr_uuid = chara.getUuid().toString(), chr_name = GATTAttributes.lookup(chr_uuid, "");
int chr_props = chara.getProperties();
String props = "";
Iterator it = propsMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
if ((chr_props & (Integer) pairs.getKey()) != 0) {
props += pairs.getValue().toString() + " ";
}
}
Logger.d(" " + chr_name + " ( " + chr_uuid + " ) [" + props + "] : " + Utils.bytesToHex(chara.getValue()));
for (BluetoothGattDescriptor desc : chara.getDescriptors()) {
Logger.d(" DESC: " + desc.getUuid());
}
}
}
Logger.d("---------------------------------------------------------------------------");
}
Aggregations