use of com.eveningoutpost.dexdrip.Models.TransmitterData in project xDrip-plus by jamorham.
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.TransmitterData in project xDrip by NightscoutFoundation.
the class ListenerService method getWearTransmitterData.
private synchronized DataMap getWearTransmitterData(int count, long last_send_time, int min_count) {
// KS
forceGoogleApiConnect();
Log.d(TAG, "getWearTransmitterData last_send_time:" + JoH.dateTimeText(last_send_time));
TransmitterData last_bg = TransmitterData.last();
if (last_bg != null) {
Log.d(TAG, "getWearTransmitterData last_bg.timestamp:" + JoH.dateTimeText(last_bg.timestamp));
}
if (last_bg != null && last_send_time <= last_bg.timestamp) {
// startTime
long last_send_success = last_send_time;
Log.d(TAG, "getWearTransmitterData last_send_time < last_bg.timestamp:" + JoH.dateTimeText(last_bg.timestamp));
List<TransmitterData> graph_bgs = TransmitterData.latestForGraphAsc(count, last_send_time);
if (!graph_bgs.isEmpty() && graph_bgs.size() > min_count) {
// Log.d(TAG, "getWearTransmitterData count = " + graph_bgs.size());
DataMap entries = dataMap(last_bg);
final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
for (TransmitterData bg : graph_bgs) {
dataMaps.add(dataMap(bg));
last_send_success = bg.timestamp;
// Log.d(TAG, "getWearTransmitterData bg getId:" + bg.getId() + " raw_data:" + bg.raw_data + " filtered_data:" + bg.filtered_data + " timestamp:" + bg.timestamp + " uuid:" + bg.uuid);
}
// MOST IMPORTANT LINE FOR TIMESTAMP
entries.putLong("time", new Date().getTime());
entries.putDataMapArrayList("entries", dataMaps);
Log.i(TAG, "getWearTransmitterData SYNCED BGs up to " + JoH.dateTimeText(last_send_success) + " count = " + graph_bgs.size());
return entries;
} else
Log.i(TAG, "getWearTransmitterData SYNCED BGs up to " + JoH.dateTimeText(last_send_success) + " count = 0");
}
return null;
}
use of com.eveningoutpost.dexdrip.Models.TransmitterData in project xDrip by NightscoutFoundation.
the class ListenerService method isSafeToDeleteDB.
private boolean isSafeToDeleteDB() {
// TODO remove once confirm not needed
TransmitterData last_bg = TransmitterData.last();
if (last_bg != null && last_send_previous <= last_bg.timestamp) {
Log.d(TAG, "onDataChanged SYNC_DB_PATH requestData for last_send_previous < last_bg.timestamp:" + JoH.dateTimeText(last_send_previous) + "<=" + JoH.dateTimeText(last_bg.timestamp));
requestData();
return false;
}
if (mPrefs.getBoolean("sync_wear_logs", false)) {
UserError last_log = UserError.last();
if (last_log != null && last_send_previous_log <= last_log.timestamp) {
Log.d(TAG, "onDataChanged SYNC_DB_PATH requestData for last_send_previous_log < last_log.timestamp:" + JoH.dateTimeText(last_send_previous_log) + "<=" + JoH.dateTimeText((long) last_log.timestamp));
return false;
}
}
return true;
}
use of com.eveningoutpost.dexdrip.Models.TransmitterData in project xDrip by NightscoutFoundation.
the class WatchUpdaterService method syncTransmitterData.
private synchronized void syncTransmitterData(DataMap dataMap, boolean bBenchmark) {
// KS
Log.d(TAG, "syncTransmitterData");
ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
long timeOfLastBG = 0;
Log.d(TAG, "syncTransmitterData add BgReading Table");
if (entries != null) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
int idx = 0;
int count = entries.size();
Log.d(TAG, "syncTransmitterData add BgReading Table entries count=" + count);
for (DataMap entry : entries) {
if (entry != null) {
// Log.d(TAG, "syncTransmitterData add BgReading Table entry=" + entry);
idx++;
String bgrecord = entry.getString("bgs");
if (bgrecord != null) {
// for (TransmitterData bgData : bgs) {
// Log.d(TAG, "syncTransmitterData add TransmitterData Table bgrecord=" + bgrecord);
TransmitterData bgData = gson.fromJson(bgrecord, TransmitterData.class);
// TransmitterData bgData = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().fromJson(bgrecord, TransmitterData.class);
TransmitterData exists = TransmitterData.getForTimestamp(bgData.timestamp);
TransmitterData uuidexists = TransmitterData.findByUuid(bgData.uuid);
timeOfLastBG = bgData.timestamp + 1;
if (exists != null || uuidexists != null) {
Log.d(TAG, "syncTransmitterData BG already exists for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
} else {
Log.d(TAG, "syncTransmitterData add BG; does NOT exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
if (!bBenchmark) {
bgData.save();
// Check
if (TransmitterData.findByUuid(bgData.uuid) != null)
Log.d(TAG, "syncTransmitterData: TransmitterData was saved for uuid:" + bgData.uuid);
else {
Log.e(TAG, "syncTransmitterData: TransmitterData was NOT saved for uuid:" + bgData.uuid);
return;
}
// KS the following is from G5CollectionService processNewTransmitterData()
Sensor sensor = Sensor.currentSensor();
if (sensor == null) {
Log.e(TAG, "syncTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
return;
}
// TODO : LOG if unfiltered or filtered values are zero
Sensor.updateBatteryLevel(sensor, bgData.sensor_battery_level);
// android.util.Log.i
Log.i(TAG, "syncTransmitterData: BG timestamp create " + Long.toString(bgData.timestamp));
BgReading bgExists;
// KS TODO wear implements limited alerts, therefore continue to process all alerts on phone for last entry
if (count > 1 && idx < count) {
// Disable Notifications for bulk insert
bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp, true);
} else {
bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp);
}
if (bgExists != null)
Log.d(TAG, "syncTransmitterData BG GSON saved BG: " + bgExists.toS());
else
Log.e(TAG, "syncTransmitterData BG GSON NOT saved");
}
}
}
}
}
sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_BGS count=" + entries.size(), timeOfLastBG, bBenchmark ? "BM" : "BG", -1);
}
}
use of com.eveningoutpost.dexdrip.Models.TransmitterData in project xDrip by NightscoutFoundation.
the class SystemStatus method setTransmitterStatus.
private void setTransmitterStatus() {
if (prefs.getString("dex_collection_method", "BluetoothWixel").equals("DexcomShare")) {
transmitter_status_view.setText("See Share Receiver");
return;
}
TransmitterData td = TransmitterData.last();
if (td == null || td.sensor_battery_level == 0) {
transmitter_status_view.setText("not available");
GcmActivity.requestSensorBatteryUpdate();
} else if ((System.currentTimeMillis() - td.timestamp) > 1000 * 60 * 60 * 24) {
transmitter_status_view.setText("no data in 24 hours");
GcmActivity.requestSensorBatteryUpdate();
} else {
transmitter_status_view.setText("" + td.sensor_battery_level);
// always ask
GcmActivity.requestSensorBatteryUpdate();
if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_EMPTY) {
transmitter_status_view.append(" - very low");
} else if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW) {
transmitter_status_view.append(" - low");
transmitter_status_view.append("\n(experimental interpretation)");
} else {
transmitter_status_view.append(" - ok");
}
}
}
Aggregations