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

The following examples show how to use com.eveningoutpost.dexdrip.Models.TransmitterData#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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: WixelReader.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public void setSerialDataToTransmitterRawData(int raw_data, int filtered_data ,int sensor_battery_leve, Long CaptureTime) {

        TransmitterData transmitterData = TransmitterData.create(raw_data, sensor_battery_leve, CaptureTime);
        if (transmitterData != null) {
            Sensor sensor = Sensor.currentSensor();
            if (sensor != null) {
                Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
                BgReading bgReading = BgReading.create(transmitterData.raw_data, filtered_data, mContext, CaptureTime);
            } else {
                Log.d(TAG, "No Active Sensor, Data only stored in Transmitter Data");
            }
        }
    }
 
Example 10
Source File: WixelReader.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void setSerialDataToTransmitterRawData(int raw_data ,int sensor_battery_leve, Long CaptureTime) {

        TransmitterData transmitterData = TransmitterData.create(raw_data, sensor_battery_leve, CaptureTime);
        if (transmitterData != null) {
            Sensor sensor = Sensor.currentSensor();
            if (sensor != null) {
                BgReading bgReading = BgReading.create(transmitterData.raw_data, mContext, CaptureTime);
                sensor.latest_battery_level = transmitterData.sensor_battery_level;
                sensor.save();
            } else {
                Log.w(TAG, "No Active Sensor, Data only stored in Transmitter Data");
            }
        }
    }
 
Example 11
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 12
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 13
Source File: Ob1G5StateMachine.java    From xDrip-plus 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 14
Source File: Ob1G5StateMachine.java    From xDrip-plus 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 15
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));
    }
}