Java Code Examples for com.eveningoutpost.dexdrip.Models.UserError.Log#w()
The following examples show how to use
com.eveningoutpost.dexdrip.Models.UserError.Log#w() .
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: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 6 votes |
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { Log.d(TAG, "services discovered " + status); if (status == BluetoothGatt.GATT_SUCCESS && mBluetoothGatt != null) { mShareService = mBluetoothGatt.getService(DexShareAttributes.CradleService); if(mShareService == null) { mShareService = mBluetoothGatt.getService(DexShareAttributes.CradleService2); share2 = true; } else { share2 = false; } assignCharacteristics(); authenticateConnection(); gattSetupStep(); } else { Log.w(TAG, "No Services Discovered!"); } }
Example 2
Source File: DexShareCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { Log.d(TAG, "services discovered " + status); if (status == BluetoothGatt.GATT_SUCCESS && mBluetoothGatt != null) { mShareService = mBluetoothGatt.getService(DexShareAttributes.CradleService); if(mShareService == null) { mShareService = mBluetoothGatt.getService(DexShareAttributes.CradleService2); share2 = true; } else { share2 = false; } assignCharacteristics(); authenticateConnection(); gattSetupStep(); } else { Log.w(TAG, "No Services Discovered!"); } }
Example 3
Source File: Notifications.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private long calcuatleArmTimeBg(long now) { Long wakeTimeBg = Long.MAX_VALUE; ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly(); if (activeBgAlert != null) { AlertType alert = AlertType.get_alert(activeBgAlert.alert_uuid); if (alert != null) { wakeTimeBg = activeBgAlert.next_alert_at ; Log.d(TAG , "ArmTimer BG alert -waking at: "+ new Date(wakeTimeBg) +" in " + (wakeTimeBg - now)/60000d + " minutes"); if (wakeTimeBg < now) { // next alert should be at least one minute from now. wakeTimeBg = now + 60000; Log.w(TAG , "setting next alert to 1 minute from now (no problem right now, but needs a fix someplace else)"); } } } Log.d("Notifications" , "calcuatleArmTimeBg returning: "+ new Date(wakeTimeBg) +" in " + (wakeTimeBg - now)/60000d + " minutes"); return wakeTimeBg; }
Example 4
Source File: SerialInputOutputManager.java From xDrip with GNU General Public License v3.0 | 5 votes |
/** * Continuously services the read and write buffers until {@link #stop()} is * called, or until a driver exception is raised. * * NOTE(mikey): Uses inefficient read/write-with-timeout. * TODO(mikey): Read asynchronously with {@link UsbRequest#queue(ByteBuffer, int)} */ @Override public void run() { synchronized (this) { if (getState() != State.STOPPED) { throw new IllegalStateException("Already running."); } mState = State.RUNNING; } Log.i(TAG, "Running .."); try { while (true) { if (getState() != State.RUNNING) { Log.i(TAG, "Stopping mState=" + getState()); break; } step(); } } catch (Exception e) { Log.w(TAG, "Run ending due to exception: " + e.getMessage(), e); final Listener listener = getListener(); if (listener != null) { listener.onRunError(e); } } finally { synchronized (this) { mState = State.STOPPED; Log.i(TAG, "Stopped."); } } }
Example 5
Source File: LibreTrendGraph.java From xDrip with GNU General Public License v3.0 | 5 votes |
private static ArrayList<Float> getLatestBgForXMinutes(int NumberOfMinutes) { Log.i(TAG, "getLatestBgForXMinutes number of minutes = " + NumberOfMinutes); List<LibreTrendPoint> LibreTrendPoints = LibreTrendUtil.getInstance().getData(JoH.tsl() - NumberOfMinutes * 60 * 1000, JoH.tsl()); if(LibreTrendPoints == null || LibreTrendPoints.size() == 0) { Log.e(TAG, "Error getting data from getLatestBgForXMinutes"); return null; } LibreTrendLatest libreTrendLatest = LibreTrendUtil.getInstance().getLibreTrendLatest(); if(libreTrendLatest.glucoseLevelRaw == 0) { Log.e(TAG, "libreBlock exists but libreTrendLatest.glucoseLevelRaw is zero "); return null; } ArrayList<Float> ret = new ArrayList<Float>(); double factor = libreTrendLatest.bg / libreTrendLatest.glucoseLevelRaw; if(factor == 0) { // We don't have the calculated value, but we do have the raw value. (No calibration exists) // I want to show raw data. Log.w(TAG, "Bg data was not calculated, working on raw data"); List<BgReading> latestReading = BgReading.latestForGraph (1, libreTrendLatest.timestamp - 1000, libreTrendLatest.timestamp + 1000); if(latestReading == null || latestReading.size() == 0) { Log.e(TAG, "libreBlock exists but no matching bg record exists"); return null; } factor = latestReading.get(0).raw_data / libreTrendLatest.glucoseLevelRaw; } int count = 0; for(int i = libreTrendLatest.id ; i >= 0 && count < NumberOfMinutes; i--) { count ++; ret.add(new Float(factor * LibreTrendPoints.get(i).rawSensorValue)); } return ret; }
Example 6
Source File: BgReading.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static synchronized BgReading bgReadingInsertFromG5(double calculated_value, long timestamp, String sourceInfoAppend) { final Sensor sensor = Sensor.currentSensor(); if (sensor == null) { Log.w(TAG, "No sensor, ignoring this bg reading"); return null; } // TODO slope!! final BgReading existing = getForPreciseTimestamp(timestamp, Constants.MINUTE_IN_MS); if (existing == null) { final BgReading bgr = new BgReading(); bgr.sensor = sensor; bgr.sensor_uuid = sensor.uuid; bgr.time_since_sensor_started = JoH.msSince(sensor.started_at); // is there a helper for this? bgr.timestamp = timestamp; bgr.uuid = UUID.randomUUID().toString(); bgr.calculated_value = calculated_value; bgr.raw_data = SPECIAL_G5_PLACEHOLDER; // placeholder bgr.appendSourceInfo("G5 Native"); if (sourceInfoAppend != null && sourceInfoAppend.length() > 0) { bgr.appendSourceInfo(sourceInfoAppend); } bgr.save(); if (JoH.ratelimit("sync wakelock", 15)) { final PowerManager.WakeLock linger = JoH.getWakeLock("G5 Insert", 4000); } Inevitable.stackableTask("NotifySyncBgr", 3000, () -> notifyAndSync(bgr)); return bgr; } else { return existing; } }
Example 7
Source File: ShareTest.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
public boolean connect(final String address) { details.append("\nConnecting to device"); Log.i(TAG, "CONNECTING TO DEVICE"); if (mBluetoothAdapter == null || address == null) { details.append("\nBT adapter is null"); Log.w(TAG, "BluetoothAdapter not initialized or unspecified address."); return false; } if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress) && mBluetoothGatt != null) { details.append("\nTrying to use an existing mBluetoothGatt for connection."); if (mBluetoothGatt.connect()) { mConnectionState = STATE_CONNECTING; return true; } else { return false; } } else { device = mBluetoothAdapter.getRemoteDevice(address); device.setPin("000000".getBytes()); if (device == null) { Log.w(TAG, "Device not found. Unable to connect."); details.append("\nDevice not found. Unable to connect."); return false; } mBluetoothGatt = device.connectGatt(getApplicationContext(), true, mGattCallback); Log.i(TAG, "Trying to create a new connection."); details.append("\nTrying to create a new connection to device"); mConnectionState = STATE_CONNECTING; return true; } }
Example 8
Source File: DexShareCollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { Log.i(TAG, "Gatt state change status: " + status + " new state: " + newState); if (status == 133) { Log.e(TAG, "Got the status 133 bug, bad news! Might require devices to forget each other"); } if (newState == BluetoothProfile.STATE_CONNECTED) { mBluetoothGatt = gatt; device = mBluetoothGatt.getDevice(); mConnectionState = STATE_CONNECTED; ActiveBluetoothDevice.connected(); Log.i(TAG, "Connected to GATT server."); Log.i(TAG, "discovering services"); currentGattTask = GATT_SETUP; if (mBluetoothGatt == null || !mBluetoothGatt.discoverServices()) { Log.w(TAG, "discovering failed"); if(shouldDisconnect) { stopSelf(); } else { setRetryTimer(); } } } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { mConnectionState = STATE_DISCONNECTED; ActiveBluetoothDevice.disconnected(); if(shouldDisconnect) { stopSelf(); } else { setRetryTimer(); } Log.d(TAG, "Disconnected from GATT server."); } else { Log.d(TAG, "Gatt callback... strange state."); } }
Example 9
Source File: Notifications.java From xDrip with GNU General Public License v3.0 | 5 votes |
private long calcuatleArmTimeUnclearalert(Context ctx, long now, boolean unclearAlert) { if (!unclearAlert) { return Long.MAX_VALUE; } Long wakeTimeUnclear = Long.MAX_VALUE; UserNotification userNotification = UserNotification.GetNotificationByType("bg_unclear_readings_alert"); if (userNotification == null) { // This is the case, that we are in unclear sensor reading, but for small time, so there is no call Log.i(TAG, "No active alert exists. returning Long.MAX_VALUE"); return Long.MAX_VALUE; } else { // This alert is snoozed // reminder - userNotification.timestamp is the time that the alert should be played again wakeTimeUnclear = (long)userNotification.timestamp; } if(wakeTimeUnclear < now ) { // we should alert now, wakeTimeUnclear = now; } if( wakeTimeUnclear == Long.MAX_VALUE) { // Should not happen Log.e(TAG ,"calcuatleArmTimeUnclearalert wakeTimeUnclear bad value setting it to one minute from now " + new Date(wakeTimeUnclear) + " in " + ((wakeTimeUnclear - now)/60000d) + " minutes" ); return now + 60 * 1000; } Log.w(TAG ,"calcuatleArmTimeUnclearalert returning " + new Date(wakeTimeUnclear) + " in " + ((wakeTimeUnclear - now)/60000d) + " minutes" ); return wakeTimeUnclear; }
Example 10
Source File: DexShareCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void authenticateConnection() { Log.i(TAG, "Trying to auth"); String receiverSn = prefs.getString("share_key", "SM00000000").toUpperCase() + "000000"; if(receiverSn.compareTo("SM00000000000000") == 0) { // They havnt set their serial number, dont bond! setRetryTimer(); return; } byte[] bondkey = (receiverSn).getBytes(StandardCharsets.US_ASCII); if (mBluetoothGatt != null) { if (mShareService != null) { if(!share2) { mAuthenticationCharacteristic = mShareService.getCharacteristic(DexShareAttributes.AuthenticationCode); } else { mAuthenticationCharacteristic = mShareService.getCharacteristic(DexShareAttributes.AuthenticationCode2); } if (mAuthenticationCharacteristic != null) { Log.v(TAG, "Auth Characteristic found: " + mAuthenticationCharacteristic.toString()); if (mAuthenticationCharacteristic.setValue(bondkey)) { mBluetoothGatt.writeCharacteristic(mAuthenticationCharacteristic); } else { setRetryTimer(); } } else { Log.w(TAG, "Authentication Characteristic IS NULL"); setRetryTimer(); } } else { Log.w(TAG, "CRADLE SERVICE IS NULL"); } } else { setRetryTimer(); } }
Example 11
Source File: LibreTrendGraph.java From xDrip with GNU General Public License v3.0 | 5 votes |
private static ArrayList<Float> getLatestBg(LibreBlock libreBlock) { ReadingData readingData = NFCReaderX.getTrend(libreBlock); if(readingData == null) { Log.e(TAG, "NFCReaderX.getTrend returned null"); return null; } if(readingData.trend.size() == 0 || readingData.trend.get(0).glucoseLevelRaw == 0) { Log.e(TAG, "libreBlock exists but no trend data exists, or first value is zero "); return null; } ArrayList<Float> ret = new ArrayList<Float>(); double factor = libreBlock.calculated_bg / readingData.trend.get(0).glucoseLevelRaw; if(factor == 0) { // We don't have the calculated value, but we do have the raw value. (No calibration exists) // I want to show raw data. Log.w(TAG, "Bg data was not calculated, working on raw data"); List<BgReading> latestReading = BgReading.latestForGraph (1, libreBlock.timestamp - 1000, libreBlock.timestamp + 1000); if(latestReading == null || latestReading.size() == 0) { Log.e(TAG, "libreBlock exists but no matching bg record exists"); return null; } factor = latestReading.get(0).raw_data / readingData.trend.get(0).glucoseLevelRaw; } for (GlucoseData data : readingData.trend) { ret.add(new Float(factor * data.glucoseLevelRaw)); } return ret; }
Example 12
Source File: BgReading.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static synchronized BgReading bgReadingInsertMedtrum(double calculated_value, long timestamp, String sourceInfoAppend, double raw_data) { final Sensor sensor = Sensor.currentSensor(); if (sensor == null) { Log.w(TAG, "No sensor, ignoring this bg reading"); return null; } // TODO slope!! final BgReading existing = getForPreciseTimestamp(timestamp, Constants.MINUTE_IN_MS); if (existing == null) { final BgReading bgr = new BgReading(); bgr.sensor = sensor; bgr.sensor_uuid = sensor.uuid; bgr.time_since_sensor_started = JoH.msSince(sensor.started_at); // is there a helper for this? bgr.timestamp = timestamp; bgr.uuid = UUID.randomUUID().toString(); bgr.calculated_value = calculated_value; bgr.raw_data = raw_data / 1000d; bgr.filtered_data = bgr.raw_data; if (sourceInfoAppend != null && sourceInfoAppend.equals("Backfill")) { bgr.raw_data = BgReading.SPECIAL_G5_PLACEHOLDER; } else { bgr.calculateAgeAdjustedRawValue(); } bgr.appendSourceInfo("Medtrum Native"); if (sourceInfoAppend != null && sourceInfoAppend.length() > 0) { bgr.appendSourceInfo(sourceInfoAppend); } bgr.save(); if (JoH.ratelimit("sync wakelock", 15)) { final PowerManager.WakeLock linger = JoH.getWakeLock("Medtrum Insert", 4000); } Inevitable.task("NotifySyncBgr" + bgr.timestamp, 3000, () -> notifyAndSync(bgr)); if (bgr.isBackfilled()) { handleResyncWearAfterBackfill(bgr.timestamp); } return bgr; } else { return existing; } }
Example 13
Source File: BgReading.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public static void create(Context context, double raw_data, double age_adjusted_raw_value, double filtered_data, Long timestamp, double calculated_bg, double calculated_current_slope, boolean hide_slope) { BgReading bgReading = new BgReading(); Sensor sensor = Sensor.currentSensor(); if (sensor == null) { Log.w(TAG, "No sensor, ignoring this bg reading"); return; } Calibration calibration = Calibration.lastValid(); if (calibration == null) { Log.d(TAG, "create: No calibration yet"); bgReading.sensor = sensor; bgReading.sensor_uuid = sensor.uuid; bgReading.raw_data = (raw_data / 1000); bgReading.age_adjusted_raw_value = age_adjusted_raw_value; bgReading.filtered_data = (filtered_data / 1000); bgReading.timestamp = timestamp; bgReading.uuid = UUID.randomUUID().toString(); bgReading.calculated_value = calculated_bg; bgReading.calculated_value_slope = calculated_current_slope; bgReading.hide_slope = hide_slope; bgReading.save(); bgReading.perform_calculations(); } else { Log.d(TAG, "Calibrations, so doing everything bgReading = " + bgReading); bgReading.sensor = sensor; bgReading.sensor_uuid = sensor.uuid; bgReading.calibration = calibration; bgReading.calibration_uuid = calibration.uuid; bgReading.raw_data = (raw_data / 1000); bgReading.age_adjusted_raw_value = age_adjusted_raw_value; bgReading.filtered_data = (filtered_data / 1000); bgReading.timestamp = timestamp; bgReading.uuid = UUID.randomUUID().toString(); bgReading.calculated_value = calculated_bg; bgReading.calculated_value_slope = calculated_current_slope; bgReading.hide_slope = hide_slope; bgReading.save(); } BgSendQueue.handleNewBgReading(bgReading, "create", context); Log.i("BG GSON: ", bgReading.toS()); }
Example 14
Source File: BgReading.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static void create(Context context, double raw_data, double age_adjusted_raw_value, double filtered_data, Long timestamp, double calculated_bg, double calculated_current_slope, boolean hide_slope) { BgReading bgReading = new BgReading(); Sensor sensor = Sensor.currentSensor(); if (sensor == null) { Log.w(TAG, "No sensor, ignoring this bg reading"); return; } Calibration calibration = Calibration.lastValid(); if (calibration == null) { Log.d(TAG, "create: No calibration yet"); bgReading.sensor = sensor; bgReading.sensor_uuid = sensor.uuid; bgReading.raw_data = (raw_data / 1000); bgReading.age_adjusted_raw_value = age_adjusted_raw_value; bgReading.filtered_data = (filtered_data / 1000); bgReading.timestamp = timestamp; bgReading.uuid = UUID.randomUUID().toString(); bgReading.calculated_value = calculated_bg; bgReading.calculated_value_slope = calculated_current_slope; bgReading.hide_slope = hide_slope; bgReading.save(); bgReading.perform_calculations(); } else { Log.d(TAG, "Calibrations, so doing everything bgReading = " + bgReading); bgReading.sensor = sensor; bgReading.sensor_uuid = sensor.uuid; bgReading.calibration = calibration; bgReading.calibration_uuid = calibration.uuid; bgReading.raw_data = (raw_data / 1000); bgReading.age_adjusted_raw_value = age_adjusted_raw_value; bgReading.filtered_data = (filtered_data / 1000); bgReading.timestamp = timestamp; bgReading.uuid = UUID.randomUUID().toString(); bgReading.calculated_value = calculated_bg; bgReading.calculated_value_slope = calculated_current_slope; bgReading.hide_slope = hide_slope; bgReading.save(); } BgSendQueue.handleNewBgReading(bgReading, "create", context); Log.i("BG GSON: ", bgReading.toS()); }
Example 15
Source File: DexShareCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public synchronized boolean connect(final String address) { PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DexShareCollectionStart"); wakeLock.acquire(30000); Log.i(TAG, "going to connect to device at address" + address); if (mBluetoothAdapter == null || address == null) { Log.w(TAG, "BluetoothAdapter not initialized or unspecified address."); setRetryTimer(); return false; } if (mBluetoothGatt != null) { Log.i(TAG, "BGatt isnt null, Closing."); try { mBluetoothGatt.close(); } catch (NullPointerException e) { Log.d(TAG, "concurrency related null pointer exception in connect"); } mBluetoothGatt = null; } for (BluetoothDevice bluetoothDevice : mBluetoothAdapter.getBondedDevices()) { if (bluetoothDevice.getAddress().compareTo(address) == 0) { Log.v(TAG, "Device found, already bonded, going to connect"); if(mBluetoothAdapter.getRemoteDevice(bluetoothDevice.getAddress()) != null) { device = bluetoothDevice; mBluetoothGatt = device.connectGatt(getApplicationContext(), false, mGattCallback); return true; } } } device = mBluetoothAdapter.getRemoteDevice(address); if (device == null) { Log.w(TAG, "Device not found. Unable to connect."); setRetryTimer(); return false; } Log.i(TAG, "Trying to create a new connection."); mBluetoothGatt = device.connectGatt(getApplicationContext(), false, mGattCallback); mConnectionState = STATE_CONNECTING; return true; }
Example 16
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 4 votes |
public synchronized boolean connect(final String address) { PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DexShareCollectionStart"); wakeLock.acquire(30000); Log.i(TAG, "going to connect to device at address" + address); if (mBluetoothAdapter == null || address == null) { Log.w(TAG, "BluetoothAdapter not initialized or unspecified address."); setRetryTimer(); return false; } if (mBluetoothGatt != null) { Log.i(TAG, "BGatt isnt null, Closing."); try { mBluetoothGatt.close(); } catch (NullPointerException e) { Log.d(TAG, "concurrency related null pointer exception in connect"); } mBluetoothGatt = null; } for (BluetoothDevice bluetoothDevice : mBluetoothAdapter.getBondedDevices()) { if (bluetoothDevice.getAddress().compareTo(address) == 0) { Log.v(TAG, "Device found, already bonded, going to connect"); if(mBluetoothAdapter.getRemoteDevice(bluetoothDevice.getAddress()) != null) { device = bluetoothDevice; mBluetoothGatt = device.connectGatt(getApplicationContext(), false, mGattCallback); return true; } } } device = mBluetoothAdapter.getRemoteDevice(address); if (device == null) { Log.w(TAG, "Device not found. Unable to connect."); setRetryTimer(); return false; } Log.i(TAG, "Trying to create a new connection."); mBluetoothGatt = device.connectGatt(getApplicationContext(), false, mGattCallback); mConnectionState = STATE_CONNECTING; return true; }
Example 17
Source File: DexCollectionService.java From xDrip with GNU General Public License v3.0 | 4 votes |
private synchronized boolean sendBtMessage(final ByteBuffer message) { // TODO affirm send happened //check mBluetoothGatt is available Log.i(TAG, "sendBtMessage: entered"); if (mBluetoothGatt == null) { Log.w(TAG, "sendBtMessage: lost connection"); if (JoH.ratelimit("sendbtmessagelost", 60)) { mConnectionState = STATE_DISCONNECTED; setRetryTimer(); } return false; } final byte[] value = message.array(); static_last_sent_hexdump = HexDump.dumpHexString(value); Log.i(TAG, "sendBtMessage: sending message: " + static_last_sent_hexdump); // Experimental support for rfduino from Tomasz Stachowicz if (use_rfduino_bluetooth) { Log.w(TAG, "sendBtMessage: use_rfduino_bluetooth"); if (mCharacteristicSend == null) { status("Error: mCharacteristicSend was null in sendBtMessage"); Log.e(TAG, lastState); servicesDiscovered = DISCOVERED.NULL; return false; } return writeChar(mCharacteristicSend, value); } // BLUCON NULL HERE? HOW TO RESOLVE? if (mCharacteristic == null) { status("Error: mCharacteristic was null in sendBtMessage"); Log.e(TAG, lastState); servicesDiscovered = DISCOVERED.NULL; return false; } if (mCharacteristicSend != null && mCharacteristicSend != mCharacteristic) { return writeChar(mCharacteristicSend, value); } return writeChar(mCharacteristic, value); }
Example 18
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 4 votes |
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { Log.i(TAG, "Gatt state change status: " + status + " new state: " + newState); if (status == 133) { statusErrors++; Log.e(TAG, "Got the status 133 bug, bad news! count:"+statusErrors+" - Might require devices to forget each other: instance uptime: "+JoH.qs((JoH.ts()-instance)/1000,0)); if (statusErrors>4) { Log.wtf(TAG,"Forcing bluetooth reset to try to combat errors"); statusErrors=0; JoH.niceRestartBluetooth(getApplicationContext()); setRetryTimer(); close(); stopSelf(); return; } } if (newState == BluetoothProfile.STATE_CONNECTED) { mBluetoothGatt = gatt; device = mBluetoothGatt.getDevice(); mConnectionState = STATE_CONNECTED; ActiveBluetoothDevice.connected(); Log.i(TAG, "Connected to GATT server."); Log.i(TAG, "discovering services"); currentGattTask = GATT_SETUP; if (mBluetoothGatt == null || !mBluetoothGatt.discoverServices()) { Log.w(TAG, "discovering failed"); if(shouldDisconnect) { stopSelf(); } else { setRetryTimer(); } } } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { mConnectionState = STATE_DISCONNECTED; ActiveBluetoothDevice.disconnected(); if(shouldDisconnect) { stopSelf(); } else { setRetryTimer(); } Log.d(TAG, "Disconnected from GATT server."); } else { Log.d(TAG, "Gatt callback... strange state."); } }
Example 19
Source File: BgReading.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static synchronized BgReading bgReadingInsertLibre2(double calculated_value, long timestamp, double raw_data) { final Sensor sensor = Sensor.currentSensor(); if (sensor == null) { Log.w(TAG, "No sensor, ignoring this bg reading"); return null; } // TODO slope!! final BgReading existing = getForPreciseTimestamp(timestamp, Constants.MINUTE_IN_MS); if (existing == null) { Calibration calibration = Calibration.lastValid(); final BgReading bgReading = new BgReading(); if (calibration == null) { Log.d(TAG, "create: No calibration yet"); bgReading.sensor = sensor; bgReading.sensor_uuid = sensor.uuid; bgReading.raw_data = raw_data; bgReading.age_adjusted_raw_value = raw_data; bgReading.filtered_data = raw_data; bgReading.timestamp = timestamp; bgReading.uuid = UUID.randomUUID().toString(); bgReading.calculated_value = calculated_value; bgReading.calculated_value_slope = 0; bgReading.hide_slope = false; bgReading.appendSourceInfo("Libre2 Native"); bgReading.find_slope(); bgReading.save(); bgReading.perform_calculations(); bgReading.postProcess(false); } else { Log.d(TAG, "Calibrations, so doing everything bgReading = " + bgReading); bgReading.sensor = sensor; bgReading.sensor_uuid = sensor.uuid; bgReading.calibration = calibration; bgReading.calibration_uuid = calibration.uuid; bgReading.raw_data = raw_data ; bgReading.age_adjusted_raw_value = raw_data; bgReading.filtered_data = raw_data; bgReading.timestamp = timestamp; bgReading.uuid = UUID.randomUUID().toString(); bgReading.calculated_value = ((calibration.slope * calculated_value) + calibration.intercept); bgReading.filtered_calculated_value = ((calibration.slope * bgReading.ageAdjustedFiltered()) + calibration.intercept); bgReading.calculated_value_slope = 0; bgReading.hide_slope = false; bgReading.appendSourceInfo("Libre2 Native"); BgReading.updateCalculatedValueToWithinMinMax(bgReading); bgReading.find_slope(); bgReading.save(); bgReading.postProcess(false); } return bgReading; } else { return existing; } }
Example 20
Source File: blueReader.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public static byte[] decodeblueReaderPacket(byte[] buffer, int len) { int cmdFound = 0; long timestamp = new Date().getTime(); String bufferstring; //Log.w(TAG, "Packet: " + bufferstring); if (buffer == null) { Log.e(TAG, "null buffer passed to decodeblueReaderPacket"); return null; } else { bufferstring=new String(buffer); } if (bufferstring.startsWith("not ready for") ) { //delete the trans_failed, because its normal only if the bluereader could not read the sensor. counterHibernated++; Log.e(TAG, "Found blueReader in a ugly State (" + counterHibernated + "/3), send hibernate to reset! If this does not help in the next 5 Minutes, then turn the bluereader manually off and on!"); if (counterHibernated > 2) { Log.wtf(TAG, "Ugly state not resolveable. Bluereader will be shut down! Please restart it!"); Home.toaststatic("BlueReader ugly state not resolveable, bluereader will be shut down. Please restart it!"); if (!Pref.getBooleanDefaultFalse("blueReader_suppressuglystatemsg")) { Notifications.RiseDropAlert(xdrip.getAppContext(),true,"BlueReader Alarm", xdrip.getAppContext().getString(R.string.bluereaderuglystate),1); } return shutdown; } else { Home.toaststatic("Found blueReader in a ugly State, send hibernate to reset!"); return goHybernate; //send hard hibernate, because blueReader is in a ugly state } } else if (bufferstring.startsWith("IDR")){ Log.i(TAG, bufferstring); PersistentStore.setString("blueReaderFirmware", bufferstring ); tempVers=Pattern.compile(".*\\|blue(.*)-.*").matcher(bufferstring); tempVers.find(); PersistentStore.setDouble("blueReaderFirmwareValue",Double.parseDouble(tempVers.group(1))); Log.i(TAG, "bluereader-Firmware-Version: " + tempVers); if (BgReading.last() == null || BgReading.last().timestamp + (4 * 60 * 1000) < System.currentTimeMillis()) { return requestValue; } else { return null; } } else if (bufferstring.startsWith("WAKE")) { Log.d (TAG, "blueReader was set to wakeup-mode manually..."); return null; } else if (bufferstring.startsWith("ECHO")) { Log.d (TAG, "blueReader was set to Echo-Mode manually..."); return null; } else if (bufferstring.startsWith("NFC READY")) { Log.d (TAG, "blueReader notice that NFC is active..."); return null; } else if (bufferstring.startsWith("NFC_DISABLED")) { Log.d (TAG, "blueReader notice that NFC is now hibernated..."); return null; } else if (bufferstring.startsWith("HYBERNATE SUCCESS")) { Log.i (TAG, "blueReader notice that NFC is now really hibernated..."); if (counterHibernated > 0) { Log.w (TAG,"Found hibernation after wrong read. Resend read-command..."); return requestValue; } else { return null; } } else if (bufferstring.startsWith("-r 0:")) { Log.d (TAG, "blueReader sends an unknown reaction: '" + bufferstring + "'"); return null; } else if (bufferstring.startsWith("TRANS_FAILED")) { Log.w (TAG, "Attention: check position of blueReader on the sensor, as it was not able to read!"); Home.toaststatic(xdrip.getAppContext().getString(R.string.bluereader_position)); return null; } else if (bufferstring.startsWith("battery: ")) { if (BgReading.last() == null || BgReading.last().timestamp + (4 * 60 * 1000) < System.currentTimeMillis()) { return requestValue; } } else { counterHibernated = 0; processNewTransmitterData(TransmitterData.create(buffer, len, timestamp), timestamp); // check for shutdown blueReader if Battery is too low if (Pref.getBooleanDefaultFalse("blueReader_turn_off")) { if (Pref.getInt("blueReader_turn_off_value",5) > Pref.getInt("bridge_battery",100)) { Log.w (TAG, "blueReader will be turn off, as the battery is lower then " + Pref.getInt("blueReader_turn_off_value",5) +"%"); Home.toaststatic(xdrip.getAppContext().getString(R.string.bluereaderoff) + Pref.getInt("blueReader_turn_off_value",5) +"%"); return shutdown; } } } return null; }