use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip by NightscoutFoundation.
the class WebLibre2ConnectCode method request.
// process the request and produce a response object
public WebResponse request(String query) {
final JSONObject reply = new JSONObject();
boolean readOnly = true;
final Map<String, String> cgi = getQueryParameters(query);
if (cgi.containsKey("ReadOnly")) {
try {
readOnly = Boolean.valueOf(cgi.get("ReadOnly"));
} catch (Exception e) {
UserError.Log.e(TAG, "Error parsing ReadOnly val, continuing as read only");
}
}
// populate json structures
try {
final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
if (btDevice == null || btDevice.address == null) {
UserError.Log.e(TAG, "ActiveBluetoothDevice has no valid bt device");
// I wonder how this will work with the recieving side???
return new WebResponse(reply.toString());
}
final String deviceAddress = btDevice.address;
byte[] btUnlockBuffer = LibreOOPAlgorithm.btSendgetBluetoothEnablePayload(!readOnly);
if (btUnlockBuffer == null) {
UserError.Log.e(TAG, "btSendgetBluetoothEnablePayload returned null");
// I wonder how this will work with the recieving side???
return new WebResponse(reply.toString());
}
reply.put(Intents.BT_UNLOCK_BUFFER, Base64.encodeToString(btUnlockBuffer, Base64.NO_WRAP));
reply.put(Intents.DEVICE_MAC_ADDRESS, btDevice.address);
Log.d(TAG, "Output: " + reply.toString());
} catch (JSONException e) {
UserError.Log.wtf(TAG, "Got json exception: " + e);
}
return new WebResponse(reply.toString());
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip by NightscoutFoundation.
the class Amazfitservice method getCurrentDevice.
// TODO what does this do? Use DexCollectionType and make as unified as possible
public String getCurrentDevice() {
activeBluetoothDevice = ActiveBluetoothDevice.first();
mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
String currentdevice;
if (activeBluetoothDevice != null) {
currentdevice = activeBluetoothDevice.name;
} else {
currentdevice = "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"));
if (Build.VERSION.SDK_INT >= 18) {
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)) {
currentdevice = defaultTransmitter.transmitterId;
}
}
}
}
} else {
currentdevice = "No Bluetooth";
}
}
return currentdevice;
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip by NightscoutFoundation.
the class Blukon method unBondIfBlukonAtInit.
public static void unBondIfBlukonAtInit() {
try {
if (Blukon.expectingBlukonDevice() && Pref.getBooleanDefaultFalse("blukon_unbonding")) {
final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
if (btDevice != null) {
UserError.Log.d(TAG, "Unbonding blukon at initialization");
JoH.unBond(btDevice.address);
}
}
} catch (Exception e) {
UserError.Log.e(TAG, "Got exception trying to unbond blukon at init");
}
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class BluetoothScan method onListItemClick.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Log.d(TAG, "Item Clicked");
final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
if (device == null || device.getName() == null)
return;
Toast.makeText(this, R.string.connecting_to_device, Toast.LENGTH_LONG).show();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
synchronized (ActiveBluetoothDevice.table_lock) {
ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class).orderBy("_ID desc").executeSingle();
prefs.edit().putString("last_connected_device_address", device.getAddress()).apply();
Blukon.clearPin();
if (btDevice == null) {
ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice();
newBtDevice.name = device.getName();
newBtDevice.address = device.getAddress();
newBtDevice.save();
} else {
btDevice.name = device.getName();
btDevice.address = device.getAddress();
btDevice.save();
}
startWatchUpdaterService(this, WatchUpdaterService.ACTION_SYNC_ACTIVEBTDEVICE, TAG);
}
// automatically set or unset the option for "Transmiter" device
boolean using_transmiter = false;
// Experimental support for rfduino from Tomasz Stachowicz
// automatically set or unset the option for "RFDuino" device
boolean using_rfduino = false;
try {
if (device.getName().toLowerCase().contains("limitter") && (adverts.containsKey(device.getAddress()) && ((new String(adverts.get(device.getAddress()), "UTF-8").contains("eLeR")) || (new String(adverts.get(device.getAddress()), "UTF-8").contains("data")))) || device.getName().toLowerCase().contains("limitterd")) {
String msg = "Auto-detected transmiter_pl device!";
Log.e(TAG, msg);
JoH.static_toast_long(msg);
using_transmiter = true;
}
prefs.edit().putBoolean("use_transmiter_pl_bluetooth", using_transmiter).apply();
// Experimental support for rfduino from Tomasz Stachowicz
if (device.getName().toLowerCase().contains("xbridge") && (adverts.containsKey(device.getAddress()) && (new String(adverts.get(device.getAddress()), "UTF-8").contains("rfduino")))) {
String msg = "Auto-detected rfduino device!";
Log.e(TAG, msg);
JoH.static_toast_long(msg);
using_rfduino = true;
}
prefs.edit().putBoolean("use_rfduino_bluetooth", using_rfduino).apply();
if (device.getName().toLowerCase().contains("dexcom")) {
if (!CollectionServiceStarter.isBTShare(getApplicationContext())) {
prefs.edit().putString("dex_collection_method", "DexcomShare").apply();
prefs.edit().putBoolean("calibration_notifications", false).apply();
}
if (prefs.getString("share_key", "SM00000000").compareTo("SM00000000") == 0 || prefs.getString("share_key", "SM00000000").length() < 10) {
requestSerialNumber(prefs);
} else
returnToHome();
} else if (device.getName().toLowerCase().contains("bridge")) {
if (!CollectionServiceStarter.isDexBridgeOrWifiandDexBridge())
prefs.edit().putString("dex_collection_method", "DexbridgeWixel").apply();
if (prefs.getString("dex_txid", "00000").compareTo("00000") == 0 || prefs.getString("dex_txid", "00000").length() < 5) {
requestTransmitterId(prefs);
} else
returnToHome();
} else if (device.getName().toLowerCase().contains("drip")) {
if (!(CollectionServiceStarter.isBTWixelOrLimiTTer(getApplicationContext()) || CollectionServiceStarter.isWifiandBTWixel(getApplicationContext())) || CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "BluetoothWixel").apply();
}
returnToHome();
} else if (device.getName().toLowerCase().contains("limitter")) {
if (!CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
} else if (device.getName().toLowerCase().contains("bluereader")) {
if (!CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
} else if ((device.getName().toLowerCase().contains("miaomiao")) || (device.getName().toLowerCase().startsWith("watlaa"))) {
if (!(CollectionServiceStarter.isLimitter() || CollectionServiceStarter.isWifiandBTLibre())) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
} else if (device.getName().toLowerCase().contains("sweetreader")) {
if (!CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
} else if (device.getName().matches("^BLU[0-9][0-9][0-9][0-9][0-9].*$")) {
Blukon.doPinDialog(this, new Runnable() {
@Override
public void run() {
if (!CollectionServiceStarter.isLimitter()) {
prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
}
returnToHome();
}
});
} else if (device.getName().matches("MT")) {
if (Medtrum.saveSerialFromLegacy(adverts.get(device.getAddress()))) {
JoH.static_toast_long("Set Medtrum serial number");
CollectionServiceStarter.restartCollectionServiceBackground();
returnToHome();
} else {
JoH.static_toast_long("Failed to find Medtrum serial number");
}
} else {
returnToHome();
}
} catch (UnsupportedEncodingException | NullPointerException e) {
Log.d(TAG, "Got exception in listitemclick: " + Arrays.toString(e.getStackTrace()));
}
}
use of com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice in project xDrip-plus by jamorham.
the class WatchUpdaterService method sendActiveBtDeviceData.
private void sendActiveBtDeviceData() {
// KS
if (is_using_bt) {
// only required for Collector running on watch
forceGoogleApiConnect();
ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
if (btDevice != null) {
if (wear_integration) {
DataMap dataMap = new DataMap();
Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected);
// MOST IMPORTANT LINE FOR TIMESTAMP
dataMap.putLong("time", new Date().getTime());
dataMap.putString("name", btDevice.name);
dataMap.putString("address", btDevice.address);
dataMap.putBoolean("connected", btDevice.connected);
new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
}
}
} else {
Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt");
}
}
Aggregations