use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.
the class WatchUpdaterService method dataMap.
private DataMap dataMap(AlertType alert, String type) {
// KS
DataMap dataMap = new DataMap();
String json = alert.toS();
Log.d(TAG, "dataMap BG GSON: " + json);
dataMap.putString(type, json);
return dataMap;
}
use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.
the class WatchUpdaterService method sendSensorData.
private boolean sendSensorData() {
// KS
try {
if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
googleApiClient.connect();
}
if (googleApiClient != null) {
Sensor sensor = Sensor.currentSensor();
if (sensor != null) {
if (wear_integration) {
DataMap dataMap = new DataMap();
Log.d(TAG, "Sensor sendSensorData uuid=" + sensor.uuid + " started_at=" + sensor.started_at + " active=" + Sensor.isActive() + " battery=" + sensor.latest_battery_level + " location=" + sensor.sensor_location + " stopped_at=" + sensor.stopped_at);
String json = sensor.toS();
Log.d(TAG, "dataMap sendSensorData GSON: " + json);
// MOST IMPORTANT LINE FOR TIMESTAMP
dataMap.putLong("time", new Date().getTime());
// KS
dataMap.putString("dex_txid", mPrefs.getString("dex_txid", "ABCDEF"));
dataMap.putLong("started_at", sensor.started_at);
dataMap.putString("uuid", sensor.uuid);
dataMap.putInt("latest_battery_level", sensor.latest_battery_level);
dataMap.putString("sensor_location", sensor.sensor_location);
new SendToDataLayerThread(WEARABLE_SENSOR_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
return true;
}
} else
Log.e(TAG, "sendSensorData current sensor is null!");
} else {
Log.e(TAG, "sendSensorData No connection to wearable available for send Sensor!");
return false;
}
} catch (NullPointerException e) {
Log.e(TAG, "Nullpointer exception in sendWearCalibrationData: " + e);
return false;
}
return true;
}
use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.
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: 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 < 0) || (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);
}
}
use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.
the class SystemStatusFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
// Injectors.getMicroStatusComponent().inject(this);
requestWearCollectorStatus();
serviceDataReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context ctx, Intent intent) {
final String action = intent.getAction();
// final String msg = intent.getStringExtra("data");
Bundle bundle = intent.getBundleExtra("data");
if (bundle != null) {
DataMap dataMap = DataMap.fromBundle(bundle);
String lastState = dataMap.getString("lastState", "");
long last_timestamp = dataMap.getLong("timestamp", 0);
UserError.Log.d(TAG, "serviceDataReceiver onReceive:" + action + " :: " + lastState + " last_timestamp :: " + last_timestamp);
switch(action) {
case WatchUpdaterService.ACTION_BLUETOOTH_COLLECTION_SERVICE_UPDATE:
switch(DexCollectionType.getDexCollectionType()) {
case DexcomG5:
// msg, last_timestamp
G5CollectionService.setWatchStatus(dataMap);
break;
case DexcomShare:
if (lastState != null && !lastState.isEmpty()) {
// TODO getLastState() in non-G5 Services
setConnectionStatus(lastState);
}
break;
default:
// msg, last_timestamp
DexCollectionService.setWatchStatus(dataMap);
if (lastState != null && !lastState.isEmpty()) {
setConnectionStatus(lastState);
}
break;
}
break;
}
}
}
};
final ActivitySystemStatusBinding binding = DataBindingUtil.inflate(inflater, R.layout.activity_system_status, container, false);
microStatus = new MicroStatusImpl();
binding.setMs(microStatus);
return binding.getRoot();
}
use of com.google.android.gms.wearable.DataMap in project xDrip-plus by jamorham.
the class ListenerService method sendPersistentStore.
private synchronized void sendPersistentStore() {
if (DexCollectionType.getDexCollectionType().equals(DexCollectionType.DexcomG5)) {
DataMap dataMap = new DataMap();
String dex_txid = mPrefs.getString("dex_txid", "ABCDEF");
dataMap.putByteArray(G5_BATTERY_MARKER, PersistentStore.getBytes(G5_BATTERY_MARKER + dex_txid));
dataMap.putLong(G5_BATTERY_FROM_MARKER, PersistentStore.getLong(G5_BATTERY_FROM_MARKER + dex_txid));
dataMap.putString("dex_txid", dex_txid);
dataMap.putByteArray(G5_FIRMWARE_MARKER, PersistentStore.getBytes(G5_FIRMWARE_MARKER + dex_txid));
dataMap.putString("dex_txid", dex_txid);
sendData(WEARABLE_G5BATTERY_PAYLOAD, dataMap.toByteArray());
}
}
Aggregations