use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.
the class DexCollectionService method processNewTransmitterData.
private synchronized void processNewTransmitterData(TransmitterData transmitterData, long timestamp) {
if (transmitterData == null) {
return;
}
final Sensor sensor = Sensor.currentSensor();
if (sensor == null) {
Log.i(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
return;
}
if (use_transmiter_pl_bluetooth && (transmitterData.raw_data == 100000)) {
Log.wtf(TAG, "Ignoring probably erroneous Transmiter_PL data: " + transmitterData.raw_data);
return;
}
// sensor.latest_battery_level = (sensor.latest_battery_level != 0) ? Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level) : transmitterData.sensor_battery_level;
// allow level to go up and down
sensor.latest_battery_level = transmitterData.sensor_battery_level;
sensor.save();
last_transmitter_Data = transmitterData;
Log.d(TAG, "BgReading.create: new BG reading at " + timestamp + " with a timestamp of " + transmitterData.timestamp);
BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);
}
use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.
the class G5CollectionService method processNewTransmitterData.
private synchronized void processNewTransmitterData(int raw_data, int filtered_data, int sensor_battery_level, long captureTime) {
final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
if (transmitterData == null) {
Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
return;
} else {
timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
}
Sensor sensor = Sensor.currentSensor();
if (sensor == null) {
Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
return;
}
// TODO : LOG if unfiltered or filtered values are zero
Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
Log.i(TAG, "timestamp create: " + Long.toString(transmitterData.timestamp));
BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);
// KS
Log.d(TAG, "Dex raw_data " + Double.toString(transmitterData.raw_data));
// KS
Log.d(TAG, "Dex filtered_data " + Double.toString(transmitterData.filtered_data));
// KS
Log.d(TAG, "Dex sensor_battery_level " + Double.toString(transmitterData.sensor_battery_level));
// KS
Log.d(TAG, "Dex timestamp " + JoH.dateTimeText(transmitterData.timestamp));
static_last_timestamp = transmitterData.timestamp;
}
use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.
the class ListenerService method syncCalibrationData.
private synchronized void syncCalibrationData(DataMap dataMap, Context context) {
// KS
Log.d(TAG, "syncCalibrationData");
boolean changed = false;
ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
if (entries != null) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
Log.d(TAG, "syncCalibrationData add Calibration Table entries count=" + entries.size());
// ensure database has already been initialized
Sensor.InitDb(context);
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
for (DataMap entry : entries) {
if (entry != null) {
String bgrecord = entry.getString("bgs");
if (bgrecord != null) {
Calibration bgData = gson.fromJson(bgrecord, Calibration.class);
Calibration exists = Calibration.findByUuid(bgData.uuid);
bgData.sensor = sensor;
if (exists != null) {
Log.d(TAG, "syncCalibrationData Calibration exists for uuid=" + bgData.uuid + " bg=" + bgData.bg + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
if (exists.slope != bgData.slope || exists.slope_confidence != bgData.slope_confidence || exists.timestamp != bgData.timestamp || exists.bg != bgData.bg) {
// slope* indicates if shown on graph
changed = true;
}
exists.adjusted_raw_value = bgData.adjusted_raw_value;
exists.bg = bgData.bg;
exists.check_in = bgData.check_in;
exists.distance_from_estimate = bgData.distance_from_estimate;
exists.estimate_bg_at_time_of_calibration = bgData.estimate_bg_at_time_of_calibration;
exists.estimate_raw_at_time_of_calibration = bgData.estimate_raw_at_time_of_calibration;
exists.first_decay = bgData.first_decay;
exists.first_intercept = bgData.first_intercept;
exists.first_scale = bgData.first_scale;
exists.first_slope = bgData.first_slope;
exists.intercept = bgData.intercept;
exists.possible_bad = bgData.possible_bad;
exists.raw_timestamp = bgData.raw_timestamp;
exists.raw_value = bgData.raw_value;
exists.second_decay = bgData.second_decay;
exists.second_intercept = bgData.second_intercept;
exists.second_scale = bgData.second_scale;
exists.second_slope = bgData.second_slope;
exists.sensor = sensor;
exists.sensor_age_at_time_of_estimation = bgData.sensor_age_at_time_of_estimation;
exists.sensor_confidence = bgData.sensor_confidence;
exists.sensor_uuid = bgData.sensor_uuid;
exists.slope = bgData.slope;
exists.slope_confidence = bgData.slope_confidence;
exists.timestamp = bgData.timestamp;
exists.save();
} else {
changed = true;
bgData.save();
// final boolean adjustPast = mPrefs.getBoolean("rewrite_history", true);
Log.d(TAG, "syncCalibrationData Calibration does not exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp));
// Calibration.adjustRecentBgReadings(adjustPast ? 30 : 2);
}
exists = Calibration.findByUuid(bgData.uuid);
if (exists != null)
Log.d(TAG, "syncCalibrationData Calibration GSON saved BG: " + exists.toS());
else
Log.d(TAG, "syncCalibrationData Calibration GSON NOT saved");
}
}
}
} else {
Log.d(TAG, "syncCalibrationData No Active Sensor!! Request WEARABLE_INITDB_PATH");
sendData(WEARABLE_INITDB_PATH, null);
}
if (changed) {
showTreatments(context, "cals");
}
}
}
use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.
the class Ob1G5StateMachine method processNewTransmitterData.
// Save/process the data in xDrip style
private static synchronized void processNewTransmitterData(int raw_data, int filtered_data, int sensor_battery_level, long captureTime) {
final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
if (transmitterData == null) {
UserError.Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
return;
} else {
UserError.Log.d(TAG, "Created transmitter data " + transmitterData.uuid + " " + JoH.dateTimeText(transmitterData.timestamp));
// TODO timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
}
Sensor sensor = Sensor.currentSensor();
if (sensor == null) {
UserError.Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
return;
}
// TODO : LOG if unfiltered or filtered values are zero
Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
if (d)
UserError.Log.i(TAG, "timestamp create: " + Long.toString(transmitterData.timestamp));
BgReading bgreading = BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
// KS
UserError.Log.d(TAG, "Dex raw_data " + Double.toString(transmitterData.raw_data));
// KS
UserError.Log.d(TAG, "Dex filtered_data " + Double.toString(transmitterData.filtered_data));
// KS
UserError.Log.d(TAG, "Dex sensor_battery_level " + Double.toString(transmitterData.sensor_battery_level));
// KS
UserError.Log.d(TAG, "Dex timestamp " + JoH.dateTimeText(transmitterData.timestamp));
UserError.Log.d(TAG, "BgReading created: " + bgreading.uuid + " " + JoH.dateTimeText(bgreading.timestamp));
// TODO static_last_timestamp = transmitterData.timestamp;
}
use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.
the class Notifications method notificationSetter.
/*
* *****************************************************************************************************************
*/
// returns weather unclear bg reading was detected
private boolean notificationSetter(Context context) {
ReadPerfs(context);
final long end = System.currentTimeMillis() + (60000 * 5);
final long start = end - (60000 * 60 * 3) - (60000 * 10);
BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context, start, end);
// BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context);
if (bg_ongoing && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)) {
bgOngoingNotification(bgGraphBuilder);
}
if (prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()) {
Log.d("NOTIFICATIONS", "Notifications are currently disabled!!");
return false;
}
boolean unclearReading = BgReading.getAndRaiseUnclearReading(context);
if (unclearReading) {
AlertPlayer.getPlayer().stopAlert(context, false, true);
} else {
FileBasedNotifications(context);
BgReading.checkForDropAllert(context);
BgReading.checkForRisingAllert(context);
}
// TODO: Add this alerts as well to depend on unclear sensor reading.
BgReading.checkForPersistentHigh();
// KS evaluateLowPredictionAlarm();
// KS reportNoiseChanges();
Sensor sensor = Sensor.currentSensor();
// TODO need to check performance of rest of this method when in follower mode
final List<BgReading> bgReadings = BgReading.latest(3);
final List<Calibration> calibrations = Calibration.allForSensorLimited(3);
if (bgReadings == null || bgReadings.size() < 3) {
return unclearReading;
}
if (calibrations == null || calibrations.size() < 2) {
return unclearReading;
}
BgReading bgReading = bgReadings.get(0);
if (calibration_notifications) {
// TODO this should only clear double calibration once after calibrations are achieved
if (bgReadings.size() >= 3) {
if (calibrations.size() == 0 && (new Date().getTime() - bgReadings.get(2).timestamp <= (60000 * 30)) && sensor != null) {
if ((sensor.started_at + (60000 * 60 * 2)) < new Date().getTime()) {
doubleCalibrationRequest();
} else {
// TODO should be aware of state
clearDoubleCalibrationRequest();
}
} else {
clearDoubleCalibrationRequest();
}
} else {
clearDoubleCalibrationRequest();
}
// bgreadings criteria possibly needs a review
if (CalibrationRequest.shouldRequestCalibration(bgReading) && (new Date().getTime() - bgReadings.get(2).timestamp <= (60000 * 24))) {
if ((!PowerStateReceiver.is_power_connected()) || (Pref.getBooleanDefaultFalse("calibration_alerts_while_charging"))) {
if (JoH.pratelimit("calibration-request-notification", CALIBRATION_REQUEST_MAX_FREQUENCY)) {
extraCalibrationRequest();
}
}
} else {
// TODO should be aware of state
clearExtraCalibrationRequest();
}
if (calibrations.size() >= 1 && (Math.abs((new Date().getTime() - calibrations.get(0).timestamp)) / (1000 * 60 * 60) > 12) && (CalibrationRequest.isSlopeFlatEnough(BgReading.last(true)))) {
Log.d("NOTIFICATIONS", "Calibration difference in hours: " + ((new Date().getTime() - calibrations.get(0).timestamp)) / (1000 * 60 * 60));
if ((!PowerStateReceiver.is_power_connected()) || (Pref.getBooleanDefaultFalse("calibration_alerts_while_charging"))) {
// TODO check slope
if (JoH.pratelimit("calibration-request-notification", CALIBRATION_REQUEST_MIN_FREQUENCY) || Pref.getBooleanDefaultFalse("calibration_alerts_repeat")) {
calibrationRequest();
}
}
} else {
// TODO should be aware of state
clearCalibrationRequest();
}
} else {
clearAllCalibrationNotifications();
}
return unclearReading;
}
Aggregations