Java Code Examples for com.eveningoutpost.dexdrip.G5Model.BluetoothServices

The following examples show how to use com.eveningoutpost.dexdrip.G5Model.BluetoothServices. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xDrip   Source File: Ob1G5CollectionService.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (d) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(BluetoothServices.CGMService)) {
            if (d) UserError.Log.i(TAG, "Found CGM Service!");
            if (!always_discover) {
                do_discovery = false;
            }
            changeState(STATE.CHECK_AUTH);
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate CGM service during discovery");
    incrementErrors();
}
 
Example 2
Source Project: xDrip   Source File: Ob1G5CollectionService.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (d) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(BluetoothServices.CGMService)) {
            if (d) UserError.Log.i(TAG, "Found CGM Service!");
            if (!always_discover) {
                do_discovery = false;
            }
            changeState(STATE.CHECK_AUTH);
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate CGM service during discovery");
    incrementErrors();
}
 
Example 3
Source Project: xDrip   Source File: G5CollectionService.java    License: GNU General Public License v3.0 5 votes vote down vote up
public synchronized void startScan() {
    UserError.Log.e(TAG, "Initial scan?" + isIntialScan);
    if (isScanning) {
        Log.d(TAG, "alreadyScanning");
        scan_interval_timer.cancel();
        Log.d(TAG,"startScan keep_running=" + keep_running);
        if (!keep_running) return;
        return;
    }

    Log.d(TAG,"startScan keep_running=" + keep_running);
    if (!keep_running) return;

    getTransmitterDetails();
    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        setupBluetooth();
    } else {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            setupLeScanCallback();
            mBluetoothAdapter.startLeScan(new UUID[]{BluetoothServices.Advertisement}, mLeScanCallback);
        } else {
            if (enforceMainThread()){
                Handler iHandler = new Handler(Looper.getMainLooper());
                iHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        startLogic();
                    }
                });
            } else {
                startLogic();
            }
            Log.e(TAG, "startScan normal");
        }
    }
}
 
Example 4
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (d) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(BluetoothServices.CGMService)) {
            if (d) UserError.Log.i(TAG, "Found CGM Service!");
            if (!always_discover) {
                do_discovery = false;
            }
            changeState(STATE.CHECK_AUTH);
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate CGM service during discovery");
    incrementErrors();
}
 
Example 5
private void onServicesDiscovered(RxBleDeviceServices services) {
    for (BluetoothGattService service : services.getBluetoothGattServices()) {
        if (d) UserError.Log.d(TAG, "Service: " + getUUIDName(service.getUuid()));
        if (service.getUuid().equals(BluetoothServices.CGMService)) {
            if (d) UserError.Log.i(TAG, "Found CGM Service!");
            if (!always_discover) {
                do_discovery = false;
            }
            changeState(STATE.CHECK_AUTH);
            return;
        }
    }
    UserError.Log.e(TAG, "Could not locate CGM service during discovery");
    incrementErrors();
}
 
Example 6
public synchronized void startScan() {
    UserError.Log.e(TAG, "Initial scan?" + isIntialScan);
    if (isScanning) {
        Log.d(TAG, "alreadyScanning");
        scan_interval_timer.cancel();
        Log.d(TAG,"startScan keep_running=" + keep_running);
        if (!keep_running) return;
        return;
    }

    Log.d(TAG,"startScan keep_running=" + keep_running);
    if (!keep_running) return;

    getTransmitterDetails();
    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        setupBluetooth();
    } else {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            setupLeScanCallback();
            mBluetoothAdapter.startLeScan(new UUID[]{BluetoothServices.Advertisement}, mLeScanCallback);
        } else {
            if (enforceMainThread()){
                Handler iHandler = new Handler(Looper.getMainLooper());
                iHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        startLogic();
                    }
                });
            } else {
                startLogic();
            }
            Log.e(TAG, "startScan normal");
        }
    }
}
 
Example 7
public void startScan() {
    android.util.Log.e(TAG, "Initial scan?" + isIntialScan);
    if (isScanning) {
        Log.d(TAG, "alreadyScanning");
        scan_interval_timer.cancel();
        return;
    }

    getTransmitterDetails();
    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        setupBluetooth();
    } else {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            setupLeScanCallback();
            mBluetoothAdapter.startLeScan(new UUID[]{BluetoothServices.Advertisement}, mLeScanCallback);
        } else {
            if (enforceMainThread()){
                Handler iHandler = new Handler(Looper.getMainLooper());
                iHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        startLogic();
                    }
                });
            } else {
                startLogic();
            }
            Log.e(TAG, "startScan normal");
        }
    }
}
 
Example 8
public void getSensorData() {
    android.util.Log.i(TAG, "Request Sensor Data");
    mGatt.setCharacteristicNotification(controlCharacteristic, true);
    BluetoothGattDescriptor descriptor = controlCharacteristic.getDescriptor(BluetoothServices.CharacteristicUpdateNotification);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
    SensorTxMessage sensorTx = new SensorTxMessage();
    controlCharacteristic.setValue(sensorTx.byteSequence);
    mGatt.writeDescriptor(descriptor);
}
 
Example 9
@Override
public void onServicesDiscovered(BluetoothGatt gatt, final int status) {
    if (enforceMainThread()) {
        Handler iHandler = new Handler(Looper.getMainLooper());
        iHandler.post(new Runnable() {
            @Override
            public void run() {
                android.util.Log.i(TAG, "onServicesDiscovered On Main Thread? " + isOnMainThread());
                Log.e(TAG, "onServicesDiscovered: " + status);
                if (status == BluetoothGatt.GATT_SUCCESS) {
                    cgmService = mGatt.getService(BluetoothServices.CGMService);
                    authCharacteristic = cgmService.getCharacteristic(BluetoothServices.Authentication);
                    controlCharacteristic = cgmService.getCharacteristic(BluetoothServices.Control);
                    commCharacteristic = cgmService.getCharacteristic(BluetoothServices.Communication);
                    mBluetoothAdapter.cancelDiscovery();

                    //TODO : ADD option in settings!
                    if (alwaysAuthenticate() || alwaysUnbond()) {
                        fullAuthenticate();
                    } else {
                        authenticate();
                    }

                } else {
                    Log.w(TAG, "onServicesDiscovered received: " + status);
                }

                if (status == 133) {
                    encountered133 = true;
                }
            }
        });
    } else {
        android.util.Log.i(TAG, "onServicesDiscovered On Main Thread? " + isOnMainThread());
        Log.e(TAG, "onServicesDiscovered: " + status);
        if (status == BluetoothGatt.GATT_SUCCESS) {
            cgmService = mGatt.getService(BluetoothServices.CGMService);
            authCharacteristic = cgmService.getCharacteristic(BluetoothServices.Authentication);
            controlCharacteristic = cgmService.getCharacteristic(BluetoothServices.Control);
            commCharacteristic = cgmService.getCharacteristic(BluetoothServices.Communication);
            mBluetoothAdapter.cancelDiscovery();

            //TODO : ADD option in settings!
            if (alwaysAuthenticate() || alwaysUnbond()) {
                fullAuthenticate();
            } else {
                authenticate();
            }

        } else {
            Log.w(TAG, "onServicesDiscovered received: " + status);
        }

        if (status == 133) {
            encountered133 = true;
        }
    }


}