com.eveningoutpost.dexdrip.G5Model.BluetoothServices Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.G5Model.BluetoothServices. 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 File: Ob1G5CollectionService.java    From xDrip with 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 File: Ob1G5CollectionService.java    From xDrip with 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 File: G5CollectionService.java    From xDrip with 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
Source File: Ob1G5CollectionService.java    From xDrip-plus with 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 #5
Source File: Ob1G5CollectionService.java    From xDrip-plus with 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 #6
Source File: G5CollectionService.java    From xDrip-plus with 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 #7
Source File: G5CollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: G5CollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: G5CollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
@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;
        }
    }


}