Search in sources :

Example 36 with DataMap

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

the class WatchUpdaterService method sendWearBgData.

private static boolean sendWearBgData(Integer count, long startTime, List<BgReading> list) {
    try {
        if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
            // googleApiConnect();
            googleApiClient.connect();
        }
        if (googleApiClient != null) {
            Log.d(TAG, "sendWearBgData");
            final BgReading last = BgReading.last();
            List<BgReading> latest;
            if (list != null)
                latest = list;
            else if (startTime != 0)
                latest = BgReading.latestForGraphSensor(count, startTime, Long.MAX_VALUE);
            else
                latest = BgReading.latest(count);
            if ((last != null) && (latest != null && !latest.isEmpty())) {
                final int battery = PowerStateReceiver.getBatteryLevel(xdrip.getAppContext());
                Log.d(TAG, "sendWearBgData latest count = " + latest.size() + " battery=" + battery);
                final DataMap entries = dataMap(last);
                final ArrayList<DataMap> dataMaps = new ArrayList<>(latest.size());
                final Sensor sensor = Sensor.currentSensor();
                if ((sensor != null) && (sensor.uuid != null)) {
                    for (BgReading bg : latest) {
                        // if we have no sensor data, typically follower then add one in to pass tests.
                        if (bg != null && bg.sensor_uuid == null) {
                            bg.sensor_uuid = sensor.uuid;
                        }
                        if ((bg != null) && (bg.sensor_uuid != null) && (bg.sensor_uuid.equals(sensor.uuid) && (bg.calibration_uuid != null))) {
                            dataMaps.add(dataMap(bg));
                        } else {
                            if (bg.sensor_uuid == null) {
                                Log.d(TAG, "sendWearBgData: sensor uuid is null on record to send");
                            }
                            if (bg.calibration_uuid == null) {
                                Log.d(TAG, "sendWearBgData: calibration uuid is null on record to send");
                            }
                        }
                    }
                } else {
                    Log.d(TAG, "sendWearBgData Not queueing data due to sensor: " + (sensor != null ? sensor.uuid : "null sensor object"));
                }
                // MOST IMPORTANT LINE FOR TIMESTAMP
                entries.putLong("time", new Date().getTime());
                entries.putInt("battery", battery);
                entries.putDataMapArrayList("entries", dataMaps);
                new SendToDataLayerThread(WEARABLE_BG_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
            } else
                Log.d(TAG, "sendWearBgData lastest count = 0");
        } else {
            Log.e(TAG, "sendWearBgData No connection to wearable available for send BG!");
            return false;
        }
    } catch (NullPointerException e) {
        Log.e(TAG, "Nullpointer exception in sendWearBgData: " + e);
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) SuppressLint(android.annotation.SuppressLint) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 37 with DataMap

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

the class WatchUpdaterService method syncLogData.

private synchronized void syncLogData(DataMap dataMap, boolean bBenchmark) {
    // KS
    Log.d(TAG, "syncLogData");
    long watch_syncLogsRequested = dataMap.getLong("syncLogsRequested", -1);
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    int saved = 0;
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        Log.d(TAG, "syncLogData add Table entries count=" + entries.size() + " watch_syncLogsRequested=" + watch_syncLogsRequested);
        for (DataMap entry : entries) {
            if (entry != null) {
                String record = entry.getString("entry");
                if (record != null) {
                    UserError data = gson.fromJson(record, UserError.class);
                    if (data != null) {
                        timeOfLastEntry = (long) data.timestamp + 1;
                        if (data.shortError != null && !data.shortError.isEmpty()) {
                            // add wear prefix
                            if (!data.shortError.startsWith("wear")) {
                                data.shortError = mPrefs.getString("wear_logs_prefix", "wear") + data.shortError;
                            }
                        }
                        UserError exists = UserError.getForTimestamp(data);
                        if (exists == null && !bBenchmark) {
                            data.save();
                            saved++;
                        } else {
                        // Log.d(TAG, "syncLogData Log entry already exists with shortError=" + data.shortError + " timestamp=" + JoH.dateTimeText((long)data.timestamp));
                        }
                    }
                }
            }
        }
        if (saved > 0) {
            Log.d(TAG, "syncLogData Saved timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " saved=" + saved);
        } else {
            Log.d(TAG, "syncLogData No records saved due to being duplicates! timeOfLastEntry=" + JoH.dateTimeText(timeOfLastEntry) + " count=" + entries.size());
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "LOG", watch_syncLogsRequested);
    }
}
Also used : UserError(com.eveningoutpost.dexdrip.Models.UserError) DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) SuppressLint(android.annotation.SuppressLint) DataMap(com.google.android.gms.wearable.DataMap)

Example 38 with DataMap

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

the class WatchUpdaterService method sendPrefSettings.

// These are the settings which get sent to Wear device
private void sendPrefSettings() {
    // KS
    forceGoogleApiConnect();
    DataMap dataMap = new DataMap();
    String dexCollector = "None";
    boolean enable_wearG5 = false;
    boolean force_wearG5 = false;
    String node_wearG5 = "";
    // add booleans that default to false to this list
    final List<String> defaultFalseBooleansToSend = WearSyncBooleans.getBooleansToSync();
    // add persistent store strings that default to ""
    final List<String> defaultBlankPersistentStringsToSend = WearSyncPersistentStrings.getPersistentStrings();
    wear_integration = mPrefs.getBoolean("wear_sync", false);
    if (wear_integration) {
        Log.d(TAG, "sendPrefSettings wear_sync=true");
        dexCollector = mPrefs.getString(DexCollectionType.DEX_COLLECTION_METHOD, "DexcomG5");
        enable_wearG5 = mPrefs.getBoolean("enable_wearG5", false);
        force_wearG5 = mPrefs.getBoolean("force_wearG5", false);
        node_wearG5 = mPrefs.getString("node_wearG5", "");
        dataMap.putString("dex_collection_method", dexCollector);
        dataMap.putBoolean("rewrite_history", mPrefs.getBoolean("rewrite_history", false));
        dataMap.putBoolean("enable_wearG5", enable_wearG5);
        dataMap.putBoolean("force_wearG5", force_wearG5);
        dataMap.putString("node_wearG5", node_wearG5);
        // Used by DexShareCollectionService
        dataMap.putString("share_key", mPrefs.getString("share_key", "SM00000000"));
        // Advanced Bluetooth Settings used by G4+xBridge DexCollectionService - temporarily just use the Phone's settings
        dataMap.putBoolean("use_transmiter_pl_bluetooth", mPrefs.getBoolean("use_transmiter_pl_bluetooth", false));
        dataMap.putBoolean("use_rfduino_bluetooth", mPrefs.getBoolean("use_rfduino_bluetooth", false));
        dataMap.putBoolean("automatically_turn_bluetooth_on", mPrefs.getBoolean("automatically_turn_bluetooth_on", true));
        dataMap.putBoolean("bluetooth_excessive_wakelocks", mPrefs.getBoolean("bluetooth_excessive_wakelocks", true));
        dataMap.putBoolean("close_gatt_on_ble_disconnect", mPrefs.getBoolean("close_gatt_on_ble_disconnect", true));
        dataMap.putBoolean("bluetooth_frequent_reset", mPrefs.getBoolean("bluetooth_frequent_reset", false));
        dataMap.putBoolean("bluetooth_watchdog", mPrefs.getBoolean("bluetooth_watchdog", false));
        dataMap.putString("bluetooth_watchdog_timer", mPrefs.getString("bluetooth_watchdog_timer", "20"));
        dataMap.putInt("bridge_battery", mPrefs.getInt("bridge_battery", -1));
        dataMap.putInt("nfc_sensor_age", mPrefs.getInt("nfc_sensor_age", -1));
        dataMap.putBoolean("sync_wear_logs", mPrefs.getBoolean("sync_wear_logs", false));
        // Alerts:
        dataMap.putString("persistent_high_repeat_mins", mPrefs.getString("persistent_high_repeat_mins", "20"));
        dataMap.putString("persistent_high_threshold_mins", mPrefs.getString("persistent_high_threshold_mins", "60"));
        dataMap.putBoolean("falling_alert", mPrefs.getBoolean("falling_alert", false));
        dataMap.putString("falling_bg_val", mPrefs.getString("falling_bg_val", "2"));
        dataMap.putBoolean("rising_alert", mPrefs.getBoolean("rising_alert", false));
        dataMap.putString("rising_bg_val", mPrefs.getString("rising_bg_val", "2"));
        dataMap.putBoolean("aggressive_service_restart", mPrefs.getBoolean("aggressive_service_restart", false));
        // Extra Status Line
        dataMap.putBoolean("extra_status_line", mPrefs.getBoolean("extra_status_line", false));
        dataMap.putBoolean("extra_status_stats_24h", Pref.getBooleanDefaultFalse("extra_status_stats_24h"));
        dataMap.putBoolean("status_line_calibration_long", mPrefs.getBoolean("status_line_calibration_long", false));
        dataMap.putBoolean("status_line_calibration_short", mPrefs.getBoolean("status_line_calibration_short", false));
        dataMap.putBoolean("status_line_avg", mPrefs.getBoolean("status_line_avg", false));
        dataMap.putBoolean("status_line_a1c_dcct", mPrefs.getBoolean("status_line_a1c_dcct", false));
        dataMap.putBoolean("status_line_a1c_ifcc", mPrefs.getBoolean("status_line_a1c_ifcc", false));
        dataMap.putBoolean("status_line_in", mPrefs.getBoolean("status_line_in", false));
        dataMap.putBoolean("status_line_high", mPrefs.getBoolean("status_line_high", false));
        dataMap.putBoolean("status_line_low", mPrefs.getBoolean("status_line_low", false));
        dataMap.putBoolean("status_line_carbs", mPrefs.getBoolean("status_line_carbs", false));
        dataMap.putBoolean("status_line_insulin", mPrefs.getBoolean("status_line_insulin", false));
        dataMap.putBoolean("status_line_stdev", mPrefs.getBoolean("status_line_stdev", false));
        dataMap.putBoolean("status_line_royce_ratio", mPrefs.getBoolean("status_line_royce_ratio", false));
        dataMap.putBoolean("status_line_capture_percentage", mPrefs.getBoolean("status_line_capture_percentage", false));
        dataMap.putBoolean("status_line_realtime_capture_percentage", mPrefs.getBoolean("status_line_realtime_capture_percentage", false));
        // Calibration plugin
        dataMap.putBoolean("extra_status_calibration_plugin", mPrefs.getBoolean("extra_status_calibration_plugin", false));
        dataMap.putBoolean("display_glucose_from_plugin", Pref.getBooleanDefaultFalse("display_glucose_from_plugin"));
        dataMap.putBoolean("use_pluggable_alg_as_primary", Pref.getBooleanDefaultFalse("use_pluggable_alg_as_primary"));
        if (Pref.getBooleanDefaultFalse("engineering_mode")) {
            dataMap.putBoolean("old_school_calibration_mode", Pref.getBooleanDefaultFalse("old_school_calibration_mode"));
        }
        dataMap.putBoolean("show_wear_treatments", Pref.getBooleanDefaultFalse("show_wear_treatments"));
        dataMap.putBoolean("use_ob1_g5_collector_service", Pref.getBooleanDefaultFalse("use_ob1_g5_collector_service"));
        dataMap.putString(Blukon.BLUKON_PIN_PREF, Pref.getStringDefaultBlank(Blukon.BLUKON_PIN_PREF));
        final String dex_time_keeper = Ob1G5StateMachine.extractDexTime();
        if (dex_time_keeper != null) {
            dataMap.putString("dex-timekeeping", dex_time_keeper);
        }
    }
    // Step Counter
    // note transmutes use_pebble_health -> use_wear_health
    dataMap.putBoolean("use_wear_health", mPrefs.getBoolean("use_pebble_health", true));
    is_using_bt = DexCollectionType.hasBluetooth();
    Double highMark = Double.parseDouble(mPrefs.getString("highValue", "170"));
    Double lowMark = Double.parseDouble(mPrefs.getString("lowValue", "70"));
    Log.d(TAG, "sendPrefSettings enable_wearG5: " + enable_wearG5 + " force_wearG5:" + force_wearG5 + " node_wearG5:" + node_wearG5 + " dex_collection_method:" + dexCollector);
    // MOST IMPORTANT LINE FOR TIMESTAMP
    dataMap.putLong("time", new Date().getTime());
    dataMap.putString("dex_txid", mPrefs.getString("dex_txid", "ABCDEF"));
    dataMap.putString("units", mPrefs.getString("units", "mgdl"));
    // inMgdl(highMark, mPrefs));//KS Fix for mmol on graph Y-axis in wear standalone mode
    dataMap.putDouble("high", highMark);
    // inMgdl(lowMark, mPrefs));//KS Fix for mmol on graph Y-axis in wear standalone mode
    dataMap.putDouble("low", lowMark);
    dataMap.putBoolean("g5_non_raw_method", mPrefs.getBoolean("g5_non_raw_method", false));
    dataMap.putString("extra_tags_for_logging", Pref.getStringDefaultBlank("extra_tags_for_logging"));
    // dataMap.putBoolean("engineering_mode",  Pref.getBooleanDefaultFalse("engineering_mode"));
    dataMap.putBoolean("bridge_battery_alerts", Pref.getBooleanDefaultFalse("bridge_battery_alerts"));
    dataMap.putString("bridge_battery_alert_level", Pref.getString("bridge_battery_alert_level", "30"));
    final Locale locale = Locale.getDefault();
    String country = locale.getCountry();
    dataMap.putString("locale", locale.getLanguage() + (country != null && !country.isEmpty() ? "_" + country : ""));
    dataMap.putString("build-version-name", getVersionID());
    for (String pref : defaultFalseBooleansToSend) {
        dataMap.putBoolean(pref, Pref.getBooleanDefaultFalse(pref));
    }
    for (String str : defaultBlankPersistentStringsToSend) {
        dataMap.putString(str, PersistentStore.getString(str));
    }
    new SendToDataLayerThread(WEARABLE_PREF_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
}
Also used : Locale(java.util.Locale) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap)

Example 39 with DataMap

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

the class WatchUpdaterService method sendWearTreatmentsDataDelete.

public static boolean sendWearTreatmentsDataDelete(List<String> list) {
    if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
        googleApiClient.connect();
    }
    if (googleApiClient != null) {
        if (!list.isEmpty()) {
            Log.d(TAG, "sendWearTreatmentsDataDelete graph size=" + list.size());
            DataMap entries = new DataMap();
            // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putLong("time", new Date().getTime());
            entries.putString("action", "delete");
            entries.putStringArrayList("entries", (new ArrayList<String>(list)));
            new SendToDataLayerThread(WEARABLE_TREATMENTS_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
        } else
            Log.d(TAG, "sendWearTreatmentsDataDelete treatments count = 0");
    } else {
        Log.e(TAG, "sendWearTreatmentsData No connection to wearable available for send treatment!");
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap)

Example 40 with DataMap

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

the class WatchUpdaterService method dataMap.

private DataMap dataMap(String key, String value) {
    final DataMap dataMap = new DataMap();
    dataMap.putString(key, value);
    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