Java Code Examples for com.eveningoutpost.dexdrip.Models.BgReading#create()

The following examples show how to use com.eveningoutpost.dexdrip.Models.BgReading#create() . 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: XbridgePlus.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void process15minData(byte[] buffer, int src_offset, int min_offset, int count) {
    long timestamp = JoH.tsl();
    for (int i = src_offset; i < (src_offset + (count * 2)); i = i + 2) {
        double val = LIBRE_MULTIPLIER * (unsignedBytesToInt(buffer[i], buffer[i + 1]) & 0xFFF);
        UserError.Log.d(TAG, "Received 15 min value: " + JoH.qs(val, 4) + " for minute: " + min_offset);

        final long this_timestamp = timestamp - (min_offset * Constants.MINUTE_IN_MS);
        // TODO we may want to use getForPreciseTimestamp instead..
        if (BgReading.readingNearTimeStamp(this_timestamp) == null) {
            UserError.Log.d(TAG, "Creating a new reading at: " + JoH.dateTimeText(this_timestamp));
            BgReading.create(val, val, xdrip.getAppContext(), this_timestamp, min_offset != 0);
        } else {
            UserError.Log.d(TAG, "Already a reading for minute offset: " + min_offset);
        }

        min_offset++;
    }
}
 
Example 2
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 3
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 4
Source File: XbridgePlus.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void process15minData(byte[] buffer, int src_offset, int min_offset, int count) {
    long timestamp = JoH.tsl();
    for (int i = src_offset; i < (src_offset + (count * 2)); i = i + 2) {
        double val = LIBRE_MULTIPLIER * (unsignedBytesToInt(buffer[i], buffer[i + 1]) & 0xFFF);
        UserError.Log.d(TAG, "Received 15 min value: " + JoH.qs(val, 4) + " for minute: " + min_offset);

        final long this_timestamp = timestamp - (min_offset * Constants.MINUTE_IN_MS);
        // TODO we may want to use getForPreciseTimestamp instead..
        if (BgReading.readingNearTimeStamp(this_timestamp) == null) {
            UserError.Log.d(TAG, "Creating a new reading at: " + JoH.dateTimeText(this_timestamp));
            BgReading.create(val, val, xdrip.getAppContext(), this_timestamp, min_offset != 0);
        } else {
            UserError.Log.d(TAG, "Already a reading for minute offset: " + min_offset);
        }

        min_offset++;
    }
}
 
Example 5
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void setSerialDataToTransmitterRawData(byte[] buffer, int len) {
    Log.w(TAG, "received some data!");
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "ReceivedReading");
    wakeLock.acquire();


    Long timestamp = new Date().getTime();
    TransmitterData transmitterData = TransmitterData.create(buffer, len, timestamp);
    if (transmitterData != null) {
        Sensor sensor = Sensor.currentSensor();
        if (sensor != null) {
            sensor.latest_battery_level = transmitterData.sensor_battery_level;
            sensor.save();

            BgReading.create(transmitterData.raw_data, this, timestamp);
        } else {
            Log.w(TAG, "No Active Sensor, Data only stored in Transmitter Data");
        }
    }
    wakeLock.release();
}
 
Example 6
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 7
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 8
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 9
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 10
Source File: DexCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private void processNewTransmitterData(TransmitterData transmitterData, long timestamp) {
    if (transmitterData == null) {
        return;
    }

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

    Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, timestamp);
}
 
Example 11
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_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);
        Log.i(TAG,"timestamp create: "+ Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);

        Log.d(TAG,"Dex raw_data "+ Double.toString(transmitterData.raw_data));//KS
        Log.d(TAG,"Dex filtered_data "+ Double.toString(transmitterData.filtered_data));//KS
        Log.d(TAG,"Dex sensor_battery_level "+ Double.toString(transmitterData.sensor_battery_level));//KS
        Log.d(TAG,"Dex timestamp "+ JoH.dateTimeText(transmitterData.timestamp));//KS

        static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 12
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_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);
        Log.i(TAG,"timestamp create: "+ Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);

        Log.d(TAG,"Dex raw_data "+ Double.toString(transmitterData.raw_data));//KS
        Log.d(TAG,"Dex filtered_data "+ Double.toString(transmitterData.filtered_data));//KS
        Log.d(TAG,"Dex sensor_battery_level "+ Double.toString(transmitterData.sensor_battery_level));//KS
        Log.d(TAG,"Dex timestamp "+ JoH.dateTimeText(transmitterData.timestamp));//KS

        static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 13
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_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);
        Log.i(TAG,"timestamp create: "+ Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);

        Log.d(TAG,"Dex raw_data "+ Double.toString(transmitterData.raw_data));//KS
        Log.d(TAG,"Dex filtered_data "+ Double.toString(transmitterData.filtered_data));//KS
        Log.d(TAG,"Dex sensor_battery_level "+ Double.toString(transmitterData.sensor_battery_level));//KS
        Log.d(TAG,"Dex timestamp "+ JoH.dateTimeText(transmitterData.timestamp));//KS

        static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 14
Source File: LibreAlarmReceiver.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void createBGfromGD(GlucoseData gd, boolean use_smoothed_data, boolean quick) {
    final double converted;
    if (gd.glucoseLevelRaw > 0) {
        if(use_smoothed_data) {
            converted = convert_for_dex(gd.glucoseLevelRawSmoothed);
            Log.e(TAG,"Using smoothed value " + converted + " instead of " + convert_for_dex(gd.glucoseLevelRaw) );
        } else {
            converted = convert_for_dex(gd.glucoseLevelRaw);
        }
    } else {
        converted = 12; // RF error message - might be something else like unconstrained spline
    }
    if (gd.realDate > 0) {
        //   Log.d(TAG, "Raw debug: " + JoH.dateTimeText(gd.realDate) + " raw: " + gd.glucoseLevelRaw + " converted: " + converted);
        if ((newest_cmp == -1) || (oldest_cmp == -1) || (gd.realDate < oldest_cmp) || (gd.realDate > newest_cmp)) {
            // if (BgReading.readingNearTimeStamp(gd.realDate) == null) {
            if ((gd.realDate < oldest) || (oldest == -1)) oldest = gd.realDate;
            if ((gd.realDate > newest) || (newest == -1)) newest = gd.realDate;

            if (BgReading.getForPreciseTimestamp(gd.realDate, segmentation_timeslice, false) == null) {
                Log.d(TAG, "Creating bgreading at: " + JoH.dateTimeText(gd.realDate));
                BgReading.create(converted, converted, xdrip.getAppContext(), gd.realDate, quick); // quick lite insert
            } else {
                if (d)
                    Log.d(TAG, "Ignoring duplicate timestamp for: " + JoH.dateTimeText(gd.realDate));
            }
        } else {
            if (d)
                Log.d(TAG, "Already processed from date range: " + JoH.dateTimeText(gd.realDate));
        }
    } else {
        Log.e(TAG, "Fed a zero or negative date");
    }
    if (d)
        Log.d(TAG, "Oldest : " + JoH.dateTimeText(oldest_cmp) + " Newest : " + JoH.dateTimeText(newest_cmp));
}
 
Example 15
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void processNewTransmitterData(int raw_data , int filtered_data,int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_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);
        Log.i(TAG,"timestamp create: "+ Long.toString(transmitterData.timestamp));

        BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, this, transmitterData.timestamp);

        Log.d(TAG,"Dex raw_data "+ Double.toString(transmitterData.raw_data));//KS
        Log.d(TAG,"Dex filtered_data "+ Double.toString(transmitterData.filtered_data));//KS
        Log.d(TAG,"Dex sensor_battery_level "+ Double.toString(transmitterData.sensor_battery_level));//KS
        Log.d(TAG,"Dex timestamp "+ JoH.dateTimeText(transmitterData.timestamp));//KS

        static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 16
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void syncTransmitterData(DataMap dataMap, boolean bBenchmark) {//KS
    Log.d(TAG, "syncTransmitterData");

    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastBG = 0;
    Log.d(TAG, "syncTransmitterData add BgReading Table");
    if (entries != null) {

        Gson gson = new GsonBuilder()
                .excludeFieldsWithoutExposeAnnotation()
                .registerTypeAdapter(Date.class, new DateTypeAdapter())
                .serializeSpecialFloatingPointValues()
                .create();

        int idx = 0;
        int count = entries.size();
        Log.d(TAG, "syncTransmitterData add BgReading Table entries count=" + count);
        for (DataMap entry : entries) {
            if (entry != null) {
                //Log.d(TAG, "syncTransmitterData add BgReading Table entry=" + entry);
                idx++;
                String bgrecord = entry.getString("bgs");
                if (bgrecord != null) {//for (TransmitterData bgData : bgs) {
                    //Log.d(TAG, "syncTransmitterData add TransmitterData Table bgrecord=" + bgrecord);
                    TransmitterData bgData = gson.fromJson(bgrecord, TransmitterData.class);
                    //TransmitterData bgData = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().fromJson(bgrecord, TransmitterData.class);
                    TransmitterData exists = TransmitterData.getForTimestamp(bgData.timestamp);
                    TransmitterData uuidexists = TransmitterData.findByUuid(bgData.uuid);
                    timeOfLastBG = bgData.timestamp + 1;
                    if (exists != null || uuidexists != null) {
                        Log.d(TAG, "syncTransmitterData BG already exists for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
                    } else {
                        Log.d(TAG, "syncTransmitterData add BG; does NOT exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
                        if (!bBenchmark) {
                            bgData.save();

                            //Check
                            if (TransmitterData.findByUuid(bgData.uuid) != null)
                                Log.d(TAG, "syncTransmitterData: TransmitterData was saved for uuid:" + bgData.uuid);
                            else {
                                Log.e(TAG, "syncTransmitterData: TransmitterData was NOT saved for uuid:" + bgData.uuid);
                                return;
                            }

                            //KS the following is from G5CollectionService processNewTransmitterData()
                            Sensor sensor = Sensor.currentSensor();
                            if (sensor == null) {
                                Log.e(TAG, "syncTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
                                return;
                            }
                            //TODO : LOG if unfiltered or filtered values are zero
                            Sensor.updateBatteryLevel(sensor, bgData.sensor_battery_level);
                            Log.i(TAG, "syncTransmitterData: BG timestamp create " + Long.toString(bgData.timestamp));//android.util.Log.i
                            BgReading bgExists;

                            //KS TODO wear implements limited alerts, therefore continue to process all alerts on phone for last entry
                            if (count > 1 && idx < count) {
                                bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp, true);//Disable Notifications for bulk insert
                            } else {
                                bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp);
                            }
                            if (bgExists != null)
                                Log.d(TAG, "syncTransmitterData BG GSON saved BG: " + bgExists.toS());
                            else
                                Log.e(TAG, "syncTransmitterData BG GSON NOT saved");
                        }
                    }
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_BGS count=" + entries.size(), timeOfLastBG, bBenchmark ? "BM" : "BG", -1);
    }
}
 
Example 17
Source File: Ob1G5StateMachine.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static synchronized void processNewTransmitterData(int raw_data, int filtered_data, int sensor_battery_level, long captureTime) {

        final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
        if (transmitterData == null) {
            UserError.Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
            return;
        } else {
            UserError.Log.d(TAG, "Created transmitter data " + transmitterData.uuid + " " + JoH.dateTimeText(transmitterData.timestamp));
            // TODO timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
        }

        if (transmitterData.unchangedRaw() && !SensorSanity.allowTestingWithDeadSensor()) {
            UserError.Log.wtf(TAG, "Raw values are not changing - blocking further processing: " + raw_data + " " + filtered_data);
            return;
        }

        final Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            UserError.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);
        if (d)
            UserError.Log.i(TAG, "timestamp create: " + Long.toString(transmitterData.timestamp));

        if ((lastGlucoseBgReading != null) && (msSince(lastUsableGlucosePacket) < Constants.SECOND_IN_MS * 30)) {
            UserError.Log.d(TAG, "Updating BgReading provided by transmitter");
            // use sensor data to update previous record instead of trying to calculate with it
            lastGlucoseBgReading.raw_data = transmitterData.raw_data / 1000;
            lastGlucoseBgReading.filtered_data = transmitterData.filtered_data / 1000;
            // TODO calculate filtered calculated value from internal alg??
            lastGlucoseBgReading.calculateAgeAdjustedRawValue();
            lastGlucoseBgReading.save();
        } else {
            if (!Ob1G5CollectionService.usingNativeMode() || Ob1G5CollectionService.fallbackToXdripAlgorithm() || BgReading.latest(3).size() < 3) {
                final BgReading bgreading = BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
                UserError.Log.d(TAG, "BgReading created: " + bgreading.uuid + " " + JoH.dateTimeText(bgreading.timestamp));
            }
        }

        //   UserError.Log.d(TAG, "Dex raw_data " + Double.toString(transmitterData.raw_data));//KS
        //   UserError.Log.d(TAG, "Dex filtered_data " + Double.toString(transmitterData.filtered_data));//KS
        //   UserError.Log.d(TAG, "Dex sensor_battery_level " + Double.toString(transmitterData.sensor_battery_level));//KS
        //   UserError.Log.d(TAG, "Dex timestamp " + JoH.dateTimeText(transmitterData.timestamp));//KS


        // TODO static_last_timestamp =  transmitterData.timestamp;

    }
 
Example 18
Source File: XDripViewer.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
private void readBgData(String baseUrl, String key) {
    
    NsRestApiReader nsRestApiReader = new NsRestApiReader();
    Long LastReportedTime = 0L;
    TransmitterData lastTransmitterData = TransmitterData.last();
    if(lastTransmitterData != null) {
        LastReportedTime = lastTransmitterData.timestamp;
    }
    Log.e(TAG, "readBgData  LastReportedTime = " + LastReportedTime);
    
    List<NightscoutBg> nightscoutBgs = nsRestApiReader.readBgDataFromNs(baseUrl,key, LastReportedTime, 12 * 36 );
    if(nightscoutBgs == null) {
        Log.e(TAG, "readBgDataFromNs returned null");
        return;
    }
    Log.e(TAG, "readBgData  finished reading from ns");
    
    ListIterator<NightscoutBg> li = nightscoutBgs.listIterator(nightscoutBgs.size());
    long lastInserted = 0;
    while(li.hasPrevious()) {
        // also load to other table !!!
        NightscoutBg nightscoutBg = li.previous();
        Log.e(TAG, "nightscoutBg " + nightscoutBg.sgv + " " + nightscoutBg.xDrip_raw + " " + mContext);
        if(nightscoutBg.date == lastInserted) {
          Log.w(TAG, "not inserting packet, since it seems duplicate ");
          continue;
        }
        if(nightscoutBg.date < lastInserted) {
          Log.e(TAG, "not inserting packet, since order is wrong. ");
          continue;
        }
        
        verifyViewerNightscoutMode(mContext, nightscoutBg);
        
        TransmitterData.create((int)nightscoutBg.xDrip_raw, 100 /* ??????? */, nightscoutBg.date);
        BgReading.create(mContext, 
                nightscoutBg.xDrip_raw != 0 ? nightscoutBg.xDrip_raw * 1000 : nightscoutBg.unfiltered,
                nightscoutBg.xDrip_age_adjusted_raw_value,
                nightscoutBg.xDrip_raw != 0 ? nightscoutBg.xDrip_filtered * 1000 : nightscoutBg.filtered,
                nightscoutBg.date, 
                nightscoutBg.xDrip_calculated_value != 0 ? nightscoutBg.xDrip_calculated_value : nightscoutBg.sgv,
                nightscoutBg.xDrip_calculated_current_slope,
                nightscoutBg.xDrip_hide_slope,
                nightscoutBg.xDrip_filtered_calculated_value);
        
        lastInserted = nightscoutBg.date;
    }
    
    Log.e(TAG, "readBgData  finished with BgReading.create ");
    if(nightscoutBgs.size() > 0) {
        // Call the notification service only if we have new data...
        mContext.startService(new Intent(mContext, Notifications.class));
    }
}
 
Example 19
Source File: MedtrumCollectionService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void processBackFillPacket(final byte[] packet) {
    final BackFillRx backFillRx = new BackFillRx(packet);
    UserError.Log.d(TAG, backFillRx.toS());
    if (backFillRx.isOk()) {
        boolean changed = false;
        final List<Integer> backsies = backFillRx.getRawList();
        if (backsies != null) {
            for (int index = 0; index < backsies.size(); index++) {
                final long timestamp = timeStampFromTickCounter(serial, backFillRx.sequenceStart + index);
                UserError.Log.d(TAG, "Backsie:  id:" + (backFillRx.sequenceStart + index) + " raw:" + backsies.get(index) + " @ " + JoH.dateTimeText(timestamp));
                final long since = msSince(timestamp);
                if ((since > HOUR_IN_MS * 6) || (since < 0)) {
                    UserError.Log.wtf(TAG, "Backfill timestamp unrealistic: " + JoH.dateTimeText(timestamp) + " (ignored)");
                } else {

                    final double glucose = backFillRx.getGlucose(backsies.get(index));
                    final int scaled_raw_data = backFillRx.getSensorRawEmulateDex(backsies.get(index));
                    if (BgReading.getForPreciseTimestamp(timestamp, (long)(Constants.MINUTE_IN_MS * 2.5)) == null) {

                        if (isNative()) {
                            // Native version
                            if (glucose > 0) {
                                BgReading.bgReadingInsertMedtrum(glucose, timestamp, "Backfill", scaled_raw_data);
                                UserError.Log.d(TAG, "Adding native backfilled reading: " + JoH.dateTimeText(timestamp) + " " + BgGraphBuilder.unitized_string_static(glucose));

                            }
                            final BgReading bgReadingTemp = BgReading.createFromRawNoSave(null, null, scaled_raw_data, scaled_raw_data, timestamp);
                            if (bgReadingTemp.calculated_value > 0) {
                                Prediction.create(bgReadingTemp.timestamp, (int) bgReadingTemp.calculated_value, "Medtrum2nd").save();
                            }
                        } else {
                            if (glucose > 0) {
                                Prediction.create(timestamp, (int) glucose, "Medtrum2nd").save();
                            }
                            // xDrip as primary
                            final BgReading bgreading = BgReading.create(scaled_raw_data, scaled_raw_data, xdrip.getAppContext(), timestamp);
                            if (bgreading != null) {
                                UserError.Log.d(TAG, "Backfilled BgReading created: " + bgreading.uuid + " " + JoH.dateTimeText(bgreading.timestamp));
                            } else {
                                UserError.Log.d(TAG, "BgReading null!");
                            }
                        }

                        Inevitable.task("backfill-ui-update", 3000, Home::staticRefreshBGChartsOnIdle);
                        changed = true;
                    }
                }
            }
            if (!changed && backsies.size() < requestedBackfillSize) {
                if (JoH.ratelimit("mt-backfill-repeat", 60)) {
                    UserError.Log.d(TAG, "Requesting additional backfill with offset: " + backsies.size());
                    backFillIfNeeded(lastAnnex, backsies.size());
                }
            }
        }
    } else {
        UserError.Log.e(TAG, "Backfill data reports not ok");
    }
}
 
Example 20
Source File: ShareTest.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
public void attemptRead() {
    final ReadDataShare readData = new ReadDataShare(this);
    final Action1<Long> systemTimeListener = new Action1<Long>() {
        @Override
        public void call(Long s) {

            Log.d(TAG, "Made the full round trip, got " + s + " as the system time");
            Log.d("SYSTTIME", "Made the full round trip, got " + s + " as the system time");
            final long addativeSystemTimeOffset = new Date().getTime() - s;
            Log.d(TAG, "Made the full round trip, got " + addativeSystemTimeOffset + " offset");
            Log.d("SYSTTIME", "Made the full round trip, got " + addativeSystemTimeOffset + " offset");

            final Action1<CalRecord[]> calRecordListener = new Action1<CalRecord[]>() {
                @Override
                public void call(CalRecord[] calRecords) {
                    Log.d(TAG, "Made the full round trip, got " + calRecords.length + " Cal Records");
                    Calibration.create(calRecords, addativeSystemTimeOffset, getApplicationContext());

                    final Action1<SensorRecord[]> sensorRecordListener = new Action1<SensorRecord[]>() {
                        @Override
                        public void call(SensorRecord[] sensorRecords) {
                            Log.d(TAG, "Made the full round trip, got " + sensorRecords.length + " Sensor Records");
                            BgReading.create(sensorRecords, addativeSystemTimeOffset, getApplicationContext());

                            final Action1<EGVRecord[]> evgRecordListener = new Action1<EGVRecord[]>() {
                                @Override
                                public void call(EGVRecord[] egvRecords) {
                                    Log.d(TAG, "Made the full round trip, got " + egvRecords.length + " EVG Records");
                                    BgReading.create(egvRecords, addativeSystemTimeOffset, getApplicationContext());
                                }
                            };
                            readData.getRecentEGVs(evgRecordListener);
                        }
                    };
                    readData.getRecentSensorRecords(sensorRecordListener);
                }
            };
            readData.getRecentCalRecords(calRecordListener);
        }
    };
    readData.readSystemTime(systemTimeListener);
}