Search in sources :

Example 31 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method dataMap.

// sending to watch - beware we munge the calculated value and replace with display glucose
private DataMap dataMap(BgReading bg, SharedPreferences sPrefs, BgGraphBuilder bgGraphBuilder, int battery) {
    Double highMark = Double.parseDouble(sPrefs.getString("highValue", "170"));
    Double lowMark = Double.parseDouble(sPrefs.getString("lowValue", "70"));
    DataMap dataMap = new DataMap();
    // int battery = BgSendQueue.getBatteryLevel(getApplicationContext());
    // TODO this is inefficent when we are called in a loop instead should be passed in or already stored in bgreading
    // current best
    final BestGlucose.DisplayGlucose dg = BestGlucose.getDisplayGlucose();
    dataMap.putString("sgvString", dg != null && bg.dg_mgdl > 0 ? dg.unitized : bgGraphBuilder.unitized_string(bg.calculated_value));
    dataMap.putString("slopeArrow", bg.slopeArrow());
    // TODO: change that to long (was like that in NW)
    dataMap.putDouble("timestamp", bg.timestamp);
    // This delta string only applies to the last reading even if we are processing historical data here
    if (dg != null) {
        dataMap.putString("delta", dg.unitized_delta);
    } else {
        dataMap.putString("delta", bgGraphBuilder.unitizedDeltaString(true, true, true));
    }
    dataMap.putString("battery", "" + battery);
    dataMap.putLong("sgvLevel", sgvLevel(bg.dg_mgdl > 0 ? bg.dg_mgdl : bg.calculated_value, sPrefs, bgGraphBuilder));
    dataMap.putInt("batteryLevel", (battery >= 30) ? 1 : 0);
    dataMap.putDouble("sgvDouble", bg.dg_mgdl > 0 ? bg.dg_mgdl : bg.calculated_value);
    dataMap.putDouble("high", inMgdl(highMark, sPrefs));
    dataMap.putDouble("low", inMgdl(lowMark, sPrefs));
    // Used in DexCollectionService
    dataMap.putInt("bridge_battery", mPrefs.getInt("bridge_battery", -1));
    // dataMap.putString("rawString", threeRaw((prefs.getString("units", "mgdl").equals("mgdl"))));
    return dataMap;
}
Also used : BestGlucose(com.eveningoutpost.dexdrip.BestGlucose) DataMap(com.google.android.gms.wearable.DataMap)

Example 32 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method syncTreatmentsData.

private synchronized void syncTreatmentsData(DataMap dataMap, boolean bBenchmark) {
    Log.d(TAG, "syncTreatmentsData");
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    if (entries != null) {
        Log.d(TAG, "syncTreatmentsData count=" + entries.size());
        for (DataMap entry : entries) {
            if (entry != null) {
                Log.d(TAG, "syncTreatmentsData entry=" + entry);
                String record = entry.getString("entry");
                if (record != null && record.length() > 1) {
                    Log.d(TAG, "Received wearable 2: voice payload: " + record);
                    long timestamp = entry.getLong("timestamp");
                    if (timestamp <= PersistentStore.getLong(LAST_RECORD_TIMESTAMP)) {
                        Log.e(TAG, "Ignoring repeated or older sync timestamp");
                        continue;
                    }
                    final long since = JoH.msSince(timestamp);
                    if ((since < -(Constants.SECOND_IN_MS * 5)) || (since > Constants.HOUR_IN_MS * 72)) {
                        JoH.static_toast_long("Rejecting wear treatment as time out of range!");
                        UserError.Log.e(TAG, "Rejecting wear treatment due to time: " + record + " since: " + since);
                    } else {
                        if (record.contains("uuid null")) {
                            Log.e(TAG, "Skipping xx uuid null record!");
                            continue;
                        }
                        receivedText(getApplicationContext(), record);
                        PersistentStore.setLong(LAST_RECORD_TIMESTAMP, timestamp);
                    }
                    Log.d(TAG, "syncTreatmentsData add Table record=" + record);
                    timeOfLastEntry = (long) timestamp + 1;
                    Log.d(TAG, "syncTreatmentsData WATCH treatments timestamp=" + JoH.dateTimeText(timestamp));
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "TREATMENTS", -1);
    }
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Example 33 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method syncStepSensorData.

private synchronized void syncStepSensorData(DataMap dataMap, boolean bBenchmark) {
    Log.d(TAG, "syncStepSensorData");
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    Log.d(TAG, "syncStepSensorData add to Table");
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        StepCounter pm = StepCounter.last();
        Log.d(TAG, "syncStepSensorData add Table entries count=" + entries.size());
        for (DataMap entry : entries) {
            if (entry != null) {
                Log.d(TAG, "syncStepSensorData add Table entry=" + entry);
                String record = entry.getString("entry");
                if (record != null) {
                    Log.d(TAG, "syncStepSensorData add Table record=" + record);
                    StepCounter data = gson.fromJson(record, StepCounter.class);
                    if (data != null) {
                        timeOfLastEntry = (long) data.timestamp + 1;
                        Log.d(TAG, "syncStepSensorData add Entry Wear=" + data.toString());
                        Log.d(TAG, "syncStepSensorData WATCH data.metric=" + data.metric + " timestamp=" + JoH.dateTimeText((long) data.timestamp));
                        if (!bBenchmark)
                            data.saveit();
                    }
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "STEP", -1);
    }
}
Also used : StepCounter(com.eveningoutpost.dexdrip.Models.StepCounter) DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) DataMap(com.google.android.gms.wearable.DataMap)

Example 34 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method syncHeartSensorData.

private synchronized void syncHeartSensorData(DataMap dataMap, boolean bBenchmark) {
    Log.d(TAG, "syncHeartSensorData");
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    Log.d(TAG, "syncHeartSensorData add to Table");
    if (entries != null) {
        final Gson gson = JoH.defaultGsonInstance();
        // final HeartRate pm = HeartRate.last();
        Log.d(TAG, "syncHeartSensorData add Table entries count=" + entries.size());
        for (DataMap entry : entries) {
            if (entry != null) {
                Log.d(TAG, "syncHeartSensorData add Table entry=" + entry);
                String record = entry.getString("entry");
                if (record != null) {
                    Log.d(TAG, "syncHeartSensorData add Table record=" + record);
                    final HeartRate data = gson.fromJson(record, HeartRate.class);
                    if (data != null) {
                        timeOfLastEntry = (long) data.timestamp + 1;
                        Log.d(TAG, "syncHeartSensorData add Entry Wear=" + data.toString() + " " + record);
                        Log.d(TAG, "syncHeartSensorData WATCH data.metric=" + data.bpm + " timestamp=" + JoH.dateTimeText((long) data.timestamp));
                        if (!bBenchmark)
                            data.saveit();
                    }
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "HEART", -1);
    }
}
Also used : HeartRate(com.eveningoutpost.dexdrip.Models.HeartRate) Gson(com.google.gson.Gson) DataMap(com.google.android.gms.wearable.DataMap)

Example 35 with DataMap

use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method dataMap.

private static DataMap dataMap(BloodTest data) {
    DataMap dataMap = new DataMap();
    String json = data.toS();
    Log.d(TAG, "dataMap BG GSON: " + json);
    dataMap.putString("data", json);
    return dataMap;
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Aggregations

DataMap (com.google.android.gms.wearable.DataMap)157 Date (java.util.Date)42 ArrayList (java.util.ArrayList)38 Gson (com.google.gson.Gson)20 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)18 GsonBuilder (com.google.gson.GsonBuilder)18 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)18 Intent (android.content.Intent)17 Sensor (com.eveningoutpost.dexdrip.Models.Sensor)14 SuppressLint (android.annotation.SuppressLint)12 PendingIntent (android.app.PendingIntent)11 Context (android.content.Context)8 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)8 Treatments (com.eveningoutpost.dexdrip.Models.Treatments)8 Bundle (android.os.Bundle)6 HeartRate (com.eveningoutpost.dexdrip.Models.HeartRate)6 Paint (android.graphics.Paint)5 BloodTest (com.eveningoutpost.dexdrip.Models.BloodTest)5 BroadcastReceiver (android.content.BroadcastReceiver)4 SharedPreferences (android.content.SharedPreferences)4