com.eveningoutpost.dexdrip.Models.Sensor Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.Models.Sensor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CalibrationCheckInActivity.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public void addListenerOnButton() {

        button = (Button) findViewById(R.id.check_in_calibrations);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                if (Sensor.isActive()) {
                    SyncingService.startActionCalibrationCheckin(getApplicationContext());
                    Toast.makeText(getApplicationContext(), "Checked in all calibrations", Toast.LENGTH_LONG).show();
                    Intent tableIntent = new Intent(v.getContext(), Home.class);
                    startActivity(tableIntent);
                    finish();
                } else {
                    Log.d("CALIBRATION", "ERROR, sensor not active");
                }
            }
        });

    }
 
Example #2
Source File: Blukon.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static synchronized void processNewTransmitterData(TransmitterData transmitterData) {
    if (transmitterData == null) {
        Log.e(TAG, "Got duplicated data! Last BG at " + JoH.dateTimeText(m_timeLastBg));
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "processNewTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    DexCollectionService.last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
}
 
Example #3
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void processNewTransmitterData(TransmitterData transmitterData, long timestamp) {
    if (transmitterData == null) {
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    if (use_transmiter_pl_bluetooth && (transmitterData.raw_data == 100000)) {
        Log.wtf(TAG, "Ignoring probably erroneous Transmiter_PL data: " + transmitterData.raw_data);
        return;
    }


    //sensor.latest_battery_level = (sensor.latest_battery_level != 0) ? Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level) : transmitterData.sensor_battery_level;
    sensor.latest_battery_level = transmitterData.sensor_battery_level; // allow level to go up and down
    sensor.save();

    last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + timestamp + " with a timestamp of " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);
}
 
Example #4
Source File: G5CollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
private void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        TransmitterData transmitterData = TransmitterData.create(raw_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);
        android.util.Log.i("timestamp create", Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, filtered_data, this, transmitterData.timestamp);
    }
 
Example #5
Source File: StartNewSensor.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!Sensor.isActive()) {
        JoH.fixActionBar(this);
        setContentView(R.layout.activity_start_new_sensor);
        button = (Button) findViewById(R.id.startNewSensor);
        //dp = (DatePicker)findViewById(R.id.datePicker);
        //tp = (TimePicker)findViewById(R.id.timePicker);
        addListenerOnButton();
    } else {
        Intent intent = new Intent(this, StopSensor.class);
        startActivity(intent);
        finish();
    }
}
 
Example #6
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private boolean resetDataToLatest(DataMap dataMap, Context context) {//KS
    if (dataMap != null) {
        Double dmTimestamp = dataMap.getDouble("timestamp");
        Log.d(TAG, "resetDataToLatest dataMap.datetime=" + JoH.dateTimeText(dmTimestamp.longValue()) + " dataMap.sgvDouble=" + dataMap.getDouble("sgvDouble"));
        // todo ratelimit
        Sensor.InitDb(context);//ensure database has already been initialized
        final BgReading last = BgReading.last();
        if (last != null) {
            long bgTimestamp = last.timestamp;
            Log.d(TAG, "resetDataToLatest last.timestamp=" + JoH.dateTimeText(bgTimestamp) + " last.calculated_value=" + last.calculated_value);
            if (bgTimestamp > dmTimestamp) {
                dataMap(dataMap, last, mPrefs, new com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder(context));
                return true;
            }
        }
    }
    return false;
}
 
Example #7
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
    final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DexShareCollectionStart");
    wakeLock.acquire(40000);
    Log.d(TAG, "onStartCommand");
    try {

        if (shouldServiceRun(getApplicationContext())) {
            setFailoverTimer();
        } else {
            stopSelf();
            return START_NOT_STICKY;
        }
        if (Sensor.currentSensor() == null) {
            setRetryTimer();
            return START_NOT_STICKY;
        }
        Log.i(TAG, "STARTING SERVICE");
        attemptConnection();
    } finally {
        if(wakeLock != null && wakeLock.isHeld()) wakeLock.release();
    }
    return START_STICKY;
}
 
Example #8
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #9
Source File: Blukon.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static synchronized void processNewTransmitterData(TransmitterData transmitterData) {
    if (transmitterData == null) {
        Log.e(TAG, "Got duplicated data! Last BG at " + JoH.dateTimeText(m_timeLastBg));
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "processNewTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    DexCollectionService.last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
}
 
Example #10
Source File: LibreReceiver.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static List<StatusItem> megaStatus() {
    final List<StatusItem> l = new ArrayList<>();
    final Sensor sensor = Sensor.currentSensor();
    if (sensor != null) {
        l.add(new StatusItem("Libre2 Sensor", sensor.uuid + "\nStart: " + DateFormat.format("dd.MM.yyyy kk:mm", sensor.started_at)));
    }
    String lastReading ="";
    try {
        lastReading = DateFormat.format("dd.MM.yyyy kk:mm:ss", last_reading).toString();
        l.add(new StatusItem("Last Reading", lastReading));
    } catch (Exception e) {
        Log.e(TAG, "Error readlast: " + e);
    }
    if (get_engineering_mode()) {
        l.add(new StatusItem("Last Calc.", libre_calc_doku));
    }
    if (Pref.getBooleanDefaultFalse("Libre2_showSensors")) {
        l.add(new StatusItem("Sensors", Libre2Sensors()));
    }
    return l;
}
 
Example #11
Source File: LibreReceiver.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void saveSensorStartTime(Bundle sensor, String serial) {
    if (sensor != null && sensor.containsKey("sensorStartTime")) {
        long sensorStartTime = sensor.getLong("sensorStartTime");

        Sensor last = Sensor.currentSensor();
        if(last!=null) {
            if (!last.uuid.equals(serial)) {
                Sensor.stopSensor();
                last = null;
            }
        }

        if(last==null) {
            Sensor.create(sensorStartTime,serial);
        }
    }
}
 
Example #12
Source File: LibreReceiver.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static List<StatusItem> megaStatus() {
    final List<StatusItem> l = new ArrayList<>();
    final Sensor sensor = Sensor.currentSensor();
    if (sensor != null) {
        l.add(new StatusItem("Libre2 Sensor", sensor.uuid + "\nStart: " + DateFormat.format("dd.MM.yyyy kk:mm", sensor.started_at)));
    }
    String lastReading ="";
    try {
        lastReading = DateFormat.format("dd.MM.yyyy kk:mm:ss", last_reading).toString();
        l.add(new StatusItem("Last Reading", lastReading));
    } catch (Exception e) {
        Log.e(TAG, "Error readlast: " + e);
    }
    if (get_engineering_mode()) {
        l.add(new StatusItem("Last Calc.", libre_calc_doku));
    }
    if (Pref.getBooleanDefaultFalse("Libre2_showSensors")) {
        l.add(new StatusItem("Sensors", Libre2Sensors()));
    }
    return l;
}
 
Example #13
Source File: CalibrationCheckInActivity.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void addListenerOnButton() {

        button = (Button) findViewById(R.id.check_in_calibrations);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                if (Sensor.isActive()) {
                    SyncingService.startActionCalibrationCheckin(getApplicationContext());
                    Toast.makeText(getApplicationContext(), "Checked in all calibrations", Toast.LENGTH_LONG).show();
                    Intent tableIntent = new Intent(v.getContext(), Home.class);
                    startActivity(tableIntent);
                    finish();
                } else {
                    Log.d("CALIBRATION", "ERROR, sensor not active");
                }
            }
        });

    }
 
Example #14
Source File: StartNewSensor.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!Sensor.isActive()) {
        JoH.fixActionBar(this);
        setContentView(R.layout.activity_start_new_sensor);
        button = (Button) findViewById(R.id.startNewSensor);
        //dp = (DatePicker)findViewById(R.id.datePicker);
        //tp = (TimePicker)findViewById(R.id.timePicker);
        addListenerOnButton();
    } else {
        Intent intent = new Intent(this, StopSensor.class);
        startActivity(intent);
        finish();
    }
}
 
Example #15
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    final PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
    final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DexShareCollectionStart");
    wakeLock.acquire(40000);
    Log.d(TAG, "onStartCommand");
    try {

        if (shouldServiceRun(getApplicationContext())) {
            setFailoverTimer();
        } else {
            stopSelf();
            return START_NOT_STICKY;
        }
        if (Sensor.currentSensor() == null) {
            setRetryTimer();
            return START_NOT_STICKY;
        }
        Log.i(TAG, "STARTING SERVICE");
        attemptConnection();
    } finally {
        if(wakeLock != null && wakeLock.isHeld()) wakeLock.release();
    }
    return START_STICKY;
}
 
Example #16
Source File: WixelReader.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void setSerialDataToTransmitterRawData(int raw_data, int filtered_data, int sensor_battery_leve, Long CaptureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_leve, CaptureTime);
        if (transmitterData != null) {
            final Sensor sensor = Sensor.currentSensor();
            if (sensor != null) {
                BgReading bgReading = BgReading.create(transmitterData.raw_data, filtered_data, null, CaptureTime);

                //sensor.latest_battery_level = (sensor.latest_battery_level!=0)?Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level):transmitterData.sensor_battery_level;
                sensor.latest_battery_level = transmitterData.sensor_battery_level; // don't lock it only going downwards
                sensor.save();
            } else {
                Log.d(TAG, "No Active Sensor, Data only stored in Transmitter Data");
            }
        }
    }
 
Example #17
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void processNewTransmitterData(TransmitterData transmitterData, long timestamp) {
    if (transmitterData == null) {
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    if (use_transmiter_pl_bluetooth && (transmitterData.raw_data == 100000)) {
        Log.wtf(TAG, "Ignoring probably erroneous Transmiter_PL data: " + transmitterData.raw_data);
        return;
    }


    //sensor.latest_battery_level = (sensor.latest_battery_level != 0) ? Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level) : transmitterData.sensor_battery_level;
    sensor.latest_battery_level = transmitterData.sensor_battery_level; // allow level to go up and down
    sensor.save();

    last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + timestamp + " with a timestamp of " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);
}
 
Example #18
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void processNewTransmitterData(TransmitterData transmitterData, long timestamp) {
    if (transmitterData == null) {
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    if (use_transmiter_pl_bluetooth && (transmitterData.raw_data == 100000)) {
        Log.wtf(TAG, "Ignoring probably erroneous Transmiter_PL data: " + transmitterData.raw_data);
        return;
    }


    //sensor.latest_battery_level = (sensor.latest_battery_level != 0) ? Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level) : transmitterData.sensor_battery_level;
    sensor.latest_battery_level = transmitterData.sensor_battery_level; // allow level to go up and down
    sensor.save();

    last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + timestamp + " with a timestamp of " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);
}
 
Example #19
Source File: StopSensor.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public synchronized static void stop() {
    Sensor.stopSensor();
    Inevitable.task("stop-sensor",1000, Sensor::stopSensor);
    AlertPlayer.getPlayer().stopAlert(xdrip.getAppContext(), true, false);

    JoH.static_toast_long(gs(R.string.sensor_stopped));
    JoH.clearCache();
    LibreAlarmReceiver.clearSensorStats();
    PluggableCalibration.invalidateAllCaches();

    Ob1G5StateMachine.stopSensor();

    CollectionServiceStarter.restartCollectionServiceBackground();
    Home.staticRefreshBGCharts();
    NanoStatus.keepFollowerUpdated(false);
}
 
Example #20
Source File: Blukon.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static synchronized void processNewTransmitterData(TransmitterData transmitterData) {
    if (transmitterData == null) {
        Log.e(TAG, "Got duplicated data! Last BG at " + JoH.dateTimeText(m_timeLastBg));
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "processNewTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    DexCollectionService.last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
}
 
Example #21
Source File: SensorStatus.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static String status() {
    final StringBuilder sensor_status = new StringBuilder();
    if (Sensor.isActive()) {
        final Sensor sensor = Sensor.currentSensor();
        final Date date = new Date(sensor.started_at);
        DateFormat df = new SimpleDateFormat();
        sensor_status.append(df.format(date));
        sensor_status.append(" (");
        sensor_status.append((tsl() - sensor.started_at) / Constants.DAY_IN_MS);
        sensor_status.append("d ");
        sensor_status.append(((tsl() - sensor.started_at) % Constants.DAY_IN_MS) / Constants.HOUR_IN_MS);
        sensor_status.append("h)");
    } else {
        sensor_status.append("not available");
    }
    return sensor_status.toString();
}
 
Example #22
Source File: Blukon.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static synchronized void processNewTransmitterData(TransmitterData transmitterData) {
    if (transmitterData == null) {
        Log.e(TAG, "Got duplicated data! Last BG at " + JoH.dateTimeText(m_timeLastBg));
        return;
    }

    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "processNewTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }

    DexCollectionService.last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
}
 
Example #23
Source File: WixelReader.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void setSerialDataToTransmitterRawData(int raw_data, int filtered_data, int sensor_battery_leve, Long CaptureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_leve, CaptureTime);
        if (transmitterData != null) {
            final Sensor sensor = Sensor.currentSensor();
            if (sensor != null) {
                BgReading bgReading = BgReading.create(transmitterData.raw_data, filtered_data, null, CaptureTime);

                //sensor.latest_battery_level = (sensor.latest_battery_level!=0)?Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level):transmitterData.sensor_battery_level;
                sensor.latest_battery_level = transmitterData.sensor_battery_level; // don't lock it only going downwards
                sensor.save();
            } else {
                Log.d(TAG, "No Active Sensor, Data only stored in Transmitter Data");
            }
        }
    }
 
Example #24
Source File: LibreReceiver.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void saveSensorStartTime(Bundle sensor, String serial) {
    if (sensor != null && sensor.containsKey("sensorStartTime")) {
        long sensorStartTime = sensor.getLong("sensorStartTime");

        Sensor last = Sensor.currentSensor();
        if(last!=null) {
            if (!last.uuid.equals(serial)) {
                Sensor.stopSensor();
                last = null;
            }
        }

        if(last==null) {
            Sensor.create(sensorStartTime,serial);
        }
    }
}
 
Example #25
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private boolean resetDataToLatest(DataMap dataMap, Context context) {//KS
    if (dataMap != null) {
        Double dmTimestamp = dataMap.getDouble("timestamp");
        Log.d(TAG, "resetDataToLatest dataMap.datetime=" + JoH.dateTimeText(dmTimestamp.longValue()) + " dataMap.sgvDouble=" + dataMap.getDouble("sgvDouble"));
        // todo ratelimit
        Sensor.InitDb(context);//ensure database has already been initialized
        final BgReading last = BgReading.last();
        if (last != null) {
            long bgTimestamp = last.timestamp;
            Log.d(TAG, "resetDataToLatest last.timestamp=" + JoH.dateTimeText(bgTimestamp) + " last.calculated_value=" + last.calculated_value);
            if (bgTimestamp > dmTimestamp) {
                dataMap(dataMap, last, mPrefs, new com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder(context));
                return true;
            }
        }
    }
    return false;
}
 
Example #26
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #27
Source File: SensorStatus.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static String status() {
    final StringBuilder sensor_status = new StringBuilder();
    if (Sensor.isActive()) {
        final Sensor sensor = Sensor.currentSensor();
        final Date date = new Date(sensor.started_at);
        DateFormat df = new SimpleDateFormat();
        sensor_status.append(df.format(date));
        sensor_status.append(" (");
        sensor_status.append((tsl() - sensor.started_at) / Constants.DAY_IN_MS);
        sensor_status.append("d ");
        sensor_status.append(((tsl() - sensor.started_at) % Constants.DAY_IN_MS) / Constants.HOUR_IN_MS);
        sensor_status.append("h)");
    } else {
        sensor_status.append("not available");
    }
    return sensor_status.toString();
}
 
Example #28
Source File: NightscoutUploader.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private void populateV1APISensorEntry(JSONArray array, Sensor record) throws Exception {
    JSONObject json = new JSONObject();
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
    format.setTimeZone(TimeZone.getDefault());
    json.put("type", "sensor");
    json.put("date", record.started_at);
    json.put("xDrip_started_at", record.started_at);
    json.put("xDrip_stopped_at", record.stopped_at);
    json.put("xDrip_latest_battery_level", record.latest_battery_level);
    json.put("xDrip_uuid", record.uuid);
    json.put("sysTime", format.format(record.started_at));
    array.put(json);
}
 
Example #29
Source File: SensorSendQueue.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public static void addToQueue(Sensor sensor) {
    SensorSendQueue sensorSendQueue = new SensorSendQueue();
    sensorSendQueue.sensor = sensor;
    sensorSendQueue.success = false;
    sensorSendQueue.save();
    Log.d("SensorQueue", "New value added to queue!");
}
 
Example #30
Source File: SensorSendQueue.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void addToQueue(Sensor sensor) {
    SendToFollower(sensor);
    SensorSendQueue sensorSendQueue = new SensorSendQueue();
    sensorSendQueue.sensor = sensor;
    sensorSendQueue.success = false;
    sensorSendQueue.save();
}