public static void createUpdate(long started_at, long stopped_at, int latest_battery_level, String sensor_location, String uuid) {//KS Sensor sensor = currentSensor(); if (sensor != null) { Log.d("SENSOR", "updating an existing sensor"); } else { Log.d("SENSOR", "creating a new sensor"); sensor = new Sensor(); } sensor.started_at = started_at; sensor.stopped_at = stopped_at; sensor.latest_battery_level = latest_battery_level; sensor.sensor_location = sensor_location; sensor.uuid = uuid; sensor.save(); }
public static Sensor createDefaultIfMissing() { final Sensor sensor = currentSensor(); if (sensor == null) { Sensor.create(JoH.tsl()); } return currentSensor(); }
public static void createUpdate(long started_at, long stopped_at, int latest_battery_level, String uuid) { Sensor sensor = getByTimestamp(started_at); if (sensor != null) { Log.d("SENSOR", "updating an existing sensor"); } else { Log.d("SENSOR", "creating a new sensor"); sensor = new Sensor(); } sensor.started_at = started_at; sensor.stopped_at = stopped_at; sensor.latest_battery_level = latest_battery_level; sensor.uuid = uuid; sensor.save(); }
public static void updateSensorLocation(String sensor_location) { Sensor sensor = currentSensor(); if (sensor == null) { Log.e("SENSOR MODEL:", "updateSensorLocation called but sensor is null"); return; } sensor.sensor_location = sensor_location; sensor.save(); }
public static void updateBatteryLevel(int sensorBatteryLevel, boolean from_sync) { Sensor sensor = Sensor.currentSensor(); if (sensor == null) { Log.d("Sensor","Cant sync battery level from master as sensor data is null"); return; } updateBatteryLevel(sensor, sensorBatteryLevel, from_sync); }
public static Calibration last() { Sensor sensor = Sensor.currentSensor(); if (sensor == null) { return null; } return new Select() .from(Calibration.class) .where("Sensor = ? ", sensor.getId()) .orderBy("timestamp desc") .executeSingle(); }
alreadyDisplayedBgInfoCommon = true; boolean isSensorActive = Sensor.isActive(); Sensor.create(JoH.tsl() - HOUR_IN_MS * 3); isSensorActive = Sensor.isActive(); if (Sensor.currentSensor().started_at + 60000 * 60 * 2 >= now) { double waitTime = (Sensor.currentSensor().started_at + 60000 * 60 * 2 - now) / 60000.0; notificationText.setText(getString(R.string.please_wait_while_sensor_warms_up) + JoH.qs(waitTime, 0) + getString(R.string.minutes_with_bracket)); showUncalibratedSlope();
private void setSensorStatus(){ StringBuilder sensor_status= new StringBuilder(); if(Sensor.isActive()){ Sensor sens = Sensor.currentSensor(); Date date = new Date(sens.started_at); DateFormat df = new SimpleDateFormat(); sensor_status.append(df.format(date)); sensor_status.append(" ("); sensor_status.append((System.currentTimeMillis() - sens.started_at) / (1000 * 60 * 60 * 24)); sensor_status.append("d "); sensor_status.append(((System.currentTimeMillis() - sens.started_at) % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); sensor_status.append("h)"); } else { sensor_status.append("not available"); } sensor_status_view.setText(sensor_status.toString()); }
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);
public String toS() {//KS Gson gson = new GsonBuilder() .excludeFieldsWithoutExposeAnnotation() .registerTypeAdapter(Date.class, new DateTypeAdapter()) .serializeSpecialFloatingPointValues() .create(); Log.d("SENSOR", "Sensor toS uuid=" + this.uuid + " started_at=" + this.started_at + " active=" + this.isActive() + " battery=" + this.latest_battery_level + " location=" + this.sensor_location + " stopped_at=" + this.stopped_at); return gson.toJson(this); }
private void syncSensorData(DataMap dataMap, Context context) {//KS Log.d(TAG, "syncSensorData"); if (dataMap != null) { String uuid = dataMap.getString("uuid"); Log.d(TAG, "syncSensorData add Sensor for uuid=" + uuid); long started_at = dataMap.getLong("started_at"); Integer latest_battery_level = dataMap.getInt("latest_battery_level"); String sensor_location = dataMap.getString("sensor_location"); Sensor.InitDb(context);//ensure database has already been initialized if (uuid != null && !uuid.isEmpty()) { Log.d(TAG, "syncSensorData add Sensor for uuid=" + uuid + " timestamp=" + started_at + " timeString=" + JoH.dateTimeText(started_at)); Sensor sensor = Sensor.getByUuid(uuid); if (sensor == null) { Log.d(TAG, "syncSensorData createUpdate new Sensor..."); Sensor.createUpdate(started_at, 0, latest_battery_level, sensor_location, uuid); Sensor newsensor = Sensor.currentSensor(); if (newsensor != null) { Log.d(TAG, "syncSensorData createUpdate Sensor with uuid=" + uuid + " started at=" + started_at); } else Log.d(TAG, "syncSensorData Failed to createUpdate new Sensor for uuid=" + uuid); } else Log.d(TAG, "syncSensorData Sensor already exists with uuid=" + uuid); } } }
public static void upsertFromMaster(Sensor jsonSensor) { if (jsonSensor == null) { Log.wtf(TAG,"Got null sensor from json"); return; } try { Sensor existingSensor = getByUuid(jsonSensor.uuid); if (existingSensor == null) { Log.d(TAG, "saving new sensor record."); jsonSensor.save(); } else { Log.d(TAG, "updating existing sensor record."); existingSensor.started_at = jsonSensor.started_at; existingSensor.stopped_at = jsonSensor.stopped_at; existingSensor.latest_battery_level = jsonSensor.latest_battery_level; existingSensor.sensor_location = jsonSensor.sensor_location; existingSensor.save(); } } catch (Exception e) { Log.e(TAG, "Could not save Sensor: " + e.toString()); } }
public static void startSensorForTime(long startTime) { Sensor.create(startTime); UserError.Log.ueh("NEW SENSOR", "Sensor started at " + JoH.dateTimeText(startTime)); JoH.static_toast_long(gs(R.string.new_sensor_started)); startWatchUpdaterService(xdrip.getAppContext(), WatchUpdaterService.ACTION_SYNC_SENSOR, TAG); LibreAlarmReceiver.clearSensorStats(); // TODO this is just a timer and could be confusing - consider removing this notification // JoH.scheduleNotification(xdrip.getAppContext(), "Sensor should be ready", xdrip.getAppContext().getString(R.string.please_enter_two_calibrations_to_get_started), 60 * 130, Home.SENSOR_READY_ID); // reverse libre hacky workaround Treatments.SensorStart((DexCollectionType.hasLibre() ? startTime + (3600000) : startTime)); CollectionServiceStarter.restartCollectionServiceBackground(); Ob1G5StateMachine.startSensor(startTime); JoH.clearCache(); Home.staticRefreshBGCharts(); }
public static void updateBatteryLevel(Sensor sensor, int sensorBatteryLevel, boolean from_sync) { if(sensorBatteryLevel < 120) { // This must be a wrong battery level. Some transmitter send those every couple of readings // even if the battery is ok. return; } int startBatteryLevel = sensor.latest_battery_level; if(sensor.latest_battery_level == 0) { sensor.latest_battery_level = sensorBatteryLevel; } else { sensor.latest_battery_level = Math.min(sensor.latest_battery_level, sensorBatteryLevel); } if(startBatteryLevel == sensor.latest_battery_level) { // no need to update anything if nothing has changed. return; } sensor.save(); SensorSendQueue.addToQueue(sensor); //KS if ((!from_sync) && (Home.get_master())) { GcmActivity.sendSensorBattery(sensor.latest_battery_level); } }
public static void addToQueue(Calibration calibration, Context context) { // TODO support for various insert/update/delete functions // CalibrationSendQueue calibrationSendQueue = new CalibrationSendQueue(); // calibrationSendQueue.calibration = calibration; // calibrationSendQueue.success = false; // calibrationSendQueue.mongo_success = false; // calibrationSendQueue.save(); UploaderQueue.newEntry("create", calibration); Log.i(TAG, "calling SensorSendQueue.SendToFollower"); SensorSendQueue.SendToFollower(Sensor.getByUuid(calibration.sensor_uuid)); }
Sensor.createDefaultIfMissing(); CollectionServiceStarter.restartCollectionServiceBackground(); break;
private static List<Calibration> calibrations_for_sensor(Sensor sensor) { return new Select() .from(Calibration.class) .where("Sensor = ?", sensor.getId()) .where("slope_confidence != 0") .where("sensor_confidence != 0") .orderBy("timestamp desc") .execute(); }
public static Calibration getByTimestamp(double timestamp) {//KS Sensor sensor = Sensor.currentSensor(); if(sensor == null) { return null; } return new Select() .from(Calibration.class) .where("Sensor = ? ", sensor.getId()) .where("timestamp = ?", timestamp) .executeSingle(); }