Search in sources :

Example 16 with Transmitter

use of com.eveningoutpost.dexdrip.G5Model.Transmitter in project xDrip-plus by jamorham.

the class SystemStatus method setCurrentDevice.

public void setCurrentDevice() {
    if (activeBluetoothDevice != null) {
        current_device.setText(activeBluetoothDevice.name);
    } else {
        current_device.setText("None Set");
    }
    String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
    if (collection_method.compareTo("DexcomG5") == 0) {
        Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
        mBluetoothAdapter = mBluetoothManager.getAdapter();
        if (mBluetoothAdapter != null) {
            Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
            if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
                for (BluetoothDevice device : pairedDevices) {
                    if (device.getName() != null) {
                        String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                        String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
                        if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
                            current_device.setText(defaultTransmitter.transmitterId);
                        }
                    }
                }
            }
        } else {
            current_device.setText("No Bluetooth");
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter)

Example 17 with Transmitter

use of com.eveningoutpost.dexdrip.G5Model.Transmitter in project xDrip-plus by jamorham.

the class SystemStatus method setConnectionStatus.

private void setConnectionStatus() {
    boolean connected = false;
    if (mBluetoothManager != null && activeBluetoothDevice != null) {
        for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
            if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
                connected = true;
            }
        }
    }
    if (connected) {
        connection_status.setText(getApplicationContext().getString(R.string.connected));
    } else {
        connection_status.setText(getApplicationContext().getString(R.string.not_connected));
    }
    String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
    if (collection_method.compareTo("DexcomG5") == 0) {
        Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
        mBluetoothAdapter = mBluetoothManager.getAdapter();
        if (mBluetoothAdapter != null) {
            Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
            if (pairedDevices.size() > 0) {
                for (BluetoothDevice device : pairedDevices) {
                    if (device.getName() != null) {
                        String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                        String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
                        if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
                            final String fw = G5CollectionService.getFirmwareVersionString(defaultTransmitter.transmitterId);
                            connection_status.setText(device.getName() + " Authed" + ((fw != null) ? ("\n" + fw) : ""));
                            break;
                        }
                    }
                }
            }
        } else {
            connection_status.setText(getApplicationContext().getString(R.string.no_bluetooth));
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter)

Example 18 with Transmitter

use of com.eveningoutpost.dexdrip.G5Model.Transmitter in project xDrip-plus by jamorham.

the class G5CollectionService method getTransmitterDetails.

private synchronized void getTransmitterDetails() {
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    Log.d(TAG, "Transmitter: " + prefs.getString("dex_txid", "ABCDEF"));
    defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
    final boolean previousBondedState = isBonded;
    isBondedOrBonding = false;
    isBonded = false;
    if (mBluetoothAdapter == null) {
        Log.wtf(TAG, "No bluetooth adapter");
        return;
    }
    final Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
        for (BluetoothDevice device : pairedDevices) {
            if (device.getName() != null) {
                final String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                final String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
                if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
                    isBondedOrBonding = true;
                    isBonded = true;
                    if (!previousBondedState)
                        Log.e(TAG, "Device is now detected as bonded!");
                // TODO should we break here for performance?
                } else {
                    isIntialScan = true;
                }
            }
        }
    }
    if (previousBondedState && !isBonded)
        Log.e(TAG, "Device is no longer detected as bonded!");
    Log.d(TAG, "getTransmitterDetails() result: Bonded? " + isBondedOrBonding.toString() + (isBonded ? " localed bonded" : " not locally bonded"));
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) Transmitter(com.eveningoutpost.dexdrip.G5Model.Transmitter)

Aggregations

BluetoothDevice (android.bluetooth.BluetoothDevice)18 Transmitter (com.eveningoutpost.dexdrip.G5Model.Transmitter)18 ActiveBluetoothDevice (com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)14 Method (java.lang.reflect.Method)6 BluetoothAdapter (android.bluetooth.BluetoothAdapter)4 View (android.view.View)4 TextView (android.widget.TextView)4 Set (java.util.Set)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 BadPaddingException (javax.crypto.BadPaddingException)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2