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

The following examples show how to use com.eveningoutpost.dexdrip.Models.TransmitterData#last() . 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: ListenerService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private boolean isSafeToDeleteDB() {//TODO remove once confirm not needed
    TransmitterData last_bg = TransmitterData.last();
    if (last_bg != null && last_send_previous <= last_bg.timestamp) {
        Log.d(TAG, "onDataChanged SYNC_DB_PATH requestData for last_send_previous < last_bg.timestamp:" + JoH.dateTimeText(last_send_previous) + "<="+ JoH.dateTimeText(last_bg.timestamp));
        requestData();
        return false;
    }
    if (mPrefs.getBoolean("sync_wear_logs", false)) {
        UserError last_log = UserError.last();
        if (last_log != null && last_send_previous_log <= last_log.timestamp) {
            Log.d(TAG, "onDataChanged SYNC_DB_PATH requestData for last_send_previous_log < last_log.timestamp:" + JoH.dateTimeText(last_send_previous_log) + "<=" + JoH.dateTimeText((long) last_log.timestamp));
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: Amazfitservice.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private String gettransmitterbattery() {
    TransmitterData td = TransmitterData.last();
    String returntext;
    if (td == null || td.sensor_battery_level == 0) {
        returntext = "not available";

    } else if ((System.currentTimeMillis() - td.timestamp) > 1000 * 60 * 60 * 24) {
        returntext = "no data in 24 hours";

    } else {
        returntext = "" + td.sensor_battery_level;

        if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_EMPTY) {
            returntext = returntext + " - very low";
        } else if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW) {
            returntext = returntext + " - low";
            returntext = returntext + "\n(experimental interpretation)";
        } else {
            returntext = returntext + " - ok";
        }
    }
    return returntext;
}
 
Example 3
Source File: Amazfitservice.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private String gettransmitterbattery() {
    TransmitterData td = TransmitterData.last();
    String returntext;
    if (td == null || td.sensor_battery_level == 0) {
        returntext = "not available";

    } else if ((System.currentTimeMillis() - td.timestamp) > 1000 * 60 * 60 * 24) {
        returntext = "no data in 24 hours";

    } else {
        returntext = "" + td.sensor_battery_level;

        if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_EMPTY) {
            returntext = returntext + " - very low";
        } else if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW) {
            returntext = returntext + " - low";
            returntext = returntext + "\n(experimental interpretation)";
        } else {
            returntext = returntext + " - ok";
        }
    }
    return returntext;
}
 
Example 4
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private boolean isSafeToDeleteDB() {//TODO remove once confirm not needed
    TransmitterData last_bg = TransmitterData.last();
    if (last_bg != null && last_send_previous <= last_bg.timestamp) {
        Log.d(TAG, "onDataChanged SYNC_DB_PATH requestData for last_send_previous < last_bg.timestamp:" + JoH.dateTimeText(last_send_previous) + "<="+ JoH.dateTimeText(last_bg.timestamp));
        requestData();
        return false;
    }
    if (mPrefs.getBoolean("sync_wear_logs", false)) {
        UserError last_log = UserError.last();
        if (last_log != null && last_send_previous_log <= last_log.timestamp) {
            Log.d(TAG, "onDataChanged SYNC_DB_PATH requestData for last_send_previous_log < last_log.timestamp:" + JoH.dateTimeText(last_send_previous_log) + "<=" + JoH.dateTimeText((long) last_log.timestamp));
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: SystemStatus.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private void setTransmitterStatus() {

        if(prefs.getString("dex_collection_method", "BluetoothWixel").equals("DexcomShare")){
            transmitter_status_view.setText("See Share Receiver");
            return;
        }

        TransmitterData td = TransmitterData.last();

        if (td== null || td.sensor_battery_level == 0){
            transmitter_status_view.setText("not available");
        } else if((System.currentTimeMillis() - td.timestamp) > 1000*60*60*24){
            transmitter_status_view.setText("no data in 24 hours");
        } else {
            transmitter_status_view.setText("" + td.sensor_battery_level);

            if (td.sensor_battery_level <= Constants.TRANSMITTER_BATTERY_EMPTY) {
                transmitter_status_view.append(" - very low");
            } else if (td.sensor_battery_level <= Constants.TRANSMITTER_BATTERY_LOW) {
                transmitter_status_view.append(" - low");
                transmitter_status_view.append("\n(experimental interpretation)");
            } else {
                transmitter_status_view.append(" - ok");
            }
        }

    }
 
Example 6
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized DataMap getWearTransmitterData(int count, long last_send_time, int min_count) {//KS
    forceGoogleApiConnect();

    Log.d(TAG, "getWearTransmitterData last_send_time:" + JoH.dateTimeText(last_send_time));

    TransmitterData last_bg = TransmitterData.last();
    if (last_bg != null) {
        Log.d(TAG, "getWearTransmitterData last_bg.timestamp:" + JoH.dateTimeText(last_bg.timestamp));
    }

    if (last_bg != null && last_send_time <= last_bg.timestamp) {//startTime
        long last_send_success = last_send_time;
        Log.d(TAG, "getWearTransmitterData last_send_time < last_bg.timestamp:" + JoH.dateTimeText(last_bg.timestamp));
        List<TransmitterData> graph_bgs = TransmitterData.latestForGraphAsc(count, last_send_time);
        if (!graph_bgs.isEmpty() && graph_bgs.size() > min_count) {
            //Log.d(TAG, "getWearTransmitterData count = " + graph_bgs.size());
            DataMap entries = dataMap(last_bg);
            final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
            for (TransmitterData bg : graph_bgs) {
                dataMaps.add(dataMap(bg));
                last_send_success = bg.timestamp;
                //Log.d(TAG, "getWearTransmitterData bg getId:" + bg.getId() + " raw_data:" + bg.raw_data + " filtered_data:" + bg.filtered_data + " timestamp:" + bg.timestamp + " uuid:" + bg.uuid);
            }
            entries.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putDataMapArrayList("entries", dataMaps);
            Log.i(TAG, "getWearTransmitterData SYNCED BGs up to " + JoH.dateTimeText(last_send_success) + " count = " + graph_bgs.size());
            return entries;
        } else
            Log.i(TAG, "getWearTransmitterData SYNCED BGs up to " + JoH.dateTimeText(last_send_success) + " count = 0");
    }
    return null;
}
 
Example 7
Source File: WixelReader.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
static Long timeForNextRead() {

        TransmitterData lastTransmitterData = TransmitterData.last();
        if(lastTransmitterData == null) {
            // We did not receive a packet, well someone hopefully is looking at data, return relatively fast
            Log.e(TAG, "lastTransmitterData == null returning 60000");
            return 60*1000L;
        }
        Long gapTime = new Date().getTime() - lastTransmitterData.timestamp;
        Log.e(TAG, "gapTime = " + gapTime);
        if(gapTime < 0) {
            // There is some confusion here (clock was readjusted?)
            Log.e(TAG, "gapTime <= null returning 60000");
            return 60*1000L;
        }

        if(gapTime < DEXCOM_PERIOD) {
            // We have received the last packet...
            // 300000 - gaptime is when we expect to have the next packet.
            return (DEXCOM_PERIOD - gapTime) + 2000;
        }

        gapTime = gapTime % DEXCOM_PERIOD;
        Log.e(TAG, "gapTime = " + gapTime);
        if(gapTime < 10000) {
            // A new packet should arrive any second now
            return 10000L;
        }
        if(gapTime < 60000) {
            // A new packet should arrive but chance is we have missed it...
            return 30000L;
        }

        if (httpClient == null) {
            return (DEXCOM_PERIOD - gapTime) + 2000;
        } else {
            // compensate for parakeet gprs lag
            return (DEXCOM_PERIOD - gapTime) + 12000;
        }
    }
 
Example 8
Source File: SystemStatusFragment.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void setTransmitterStatus() {

        if (prefs.getString("dex_collection_method", "BluetoothWixel").equals("DexcomShare")) {
            transmitter_status_view.setText("See Share Receiver");
            return;
        }

        TransmitterData td = TransmitterData.last();

        if (td == null || td.sensor_battery_level == 0) {
            transmitter_status_view.setText("not available");
            GcmActivity.requestSensorBatteryUpdate();
        } else if ((System.currentTimeMillis() - td.timestamp) > 1000 * 60 * 60 * 24) {
            transmitter_status_view.setText("no data in 24 hours");
            GcmActivity.requestSensorBatteryUpdate();
        } else {
            transmitter_status_view.setText("" + td.sensor_battery_level);
            GcmActivity.requestSensorBatteryUpdate(); // always ask
            if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_EMPTY) {
                transmitter_status_view.append(" - very low");
            } else if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW) {
                transmitter_status_view.append(" - low");
                transmitter_status_view.append("\n(experimental interpretation)");
            } else {
                transmitter_status_view.append(" - ok");
            }
        }

    }
 
Example 9
Source File: SystemStatus.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void setTransmitterStatus() {

        if(prefs.getString("dex_collection_method", "BluetoothWixel").equals("DexcomShare")){
            transmitter_status_view.setText("See Share Receiver");
            return;
        }

        TransmitterData td = TransmitterData.last();

        if (td== null || td.sensor_battery_level == 0){
            transmitter_status_view.setText("not available");
            GcmActivity.requestSensorBatteryUpdate();
        } else if((System.currentTimeMillis() - td.timestamp) > 1000*60*60*24){
            transmitter_status_view.setText("no data in 24 hours");
            GcmActivity.requestSensorBatteryUpdate();
        } else {
            transmitter_status_view.setText("" + td.sensor_battery_level);
            GcmActivity.requestSensorBatteryUpdate(); // always ask
            if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_EMPTY) {
                transmitter_status_view.append(" - very low");
            } else if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW) {
                transmitter_status_view.append(" - low");
                transmitter_status_view.append("\n(experimental interpretation)");
            } else {
                transmitter_status_view.append(" - ok");
            }
        }

    }
 
Example 10
Source File: WixelReader.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
static Long timeForNextRead() {

        TransmitterData lastTransmitterData = TransmitterData.last();
        if (lastTransmitterData == null) {
            // We did not receive a packet, well someone hopefully is looking at data, return relatively fast
            Log.e(TAG, "lastTransmitterData == null returning 60000");
            return 60 * 1000L;
        }
        Long gapTime = new Date().getTime() - lastTransmitterData.timestamp;
        Log.d(TAG, "gapTime = " + gapTime);
        if (gapTime < 0) {
            // There is some confusion here (clock was readjusted?)
            Log.e(TAG, "gapTime <= null returning 60000");
            return 60 * 1000L;
        }

        if (gapTime < DEXCOM_PERIOD) {
            // We have received the last packet...
            // 300000 - gaptime is when we expect to have the next packet.
            return (DEXCOM_PERIOD - gapTime) + 2000;
        }

        gapTime = gapTime % DEXCOM_PERIOD;
        Log.d(TAG, "modulus gapTime = " + gapTime);
        if (gapTime < 10000) {
            // A new packet should arrive any second now
            return 10000L;
        }
        if (gapTime < 60000) {
            // A new packet should arrive but chance is we have missed it...
            return 30000L;
        }

        if (httpClient == null) {
            return (DEXCOM_PERIOD - gapTime) + 2000;
        } else {
            // compensate for parakeet gprs lag
            return (DEXCOM_PERIOD - gapTime) + 12000;
        }
    }
 
Example 11
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private synchronized DataMap getWearTransmitterData(int count, long last_send_time, int min_count) {//KS
    forceGoogleApiConnect();

    Log.d(TAG, "getWearTransmitterData last_send_time:" + JoH.dateTimeText(last_send_time));

    TransmitterData last_bg = TransmitterData.last();
    if (last_bg != null) {
        Log.d(TAG, "getWearTransmitterData last_bg.timestamp:" + JoH.dateTimeText(last_bg.timestamp));
    }

    if (last_bg != null && last_send_time <= last_bg.timestamp) {//startTime
        long last_send_success = last_send_time;
        Log.d(TAG, "getWearTransmitterData last_send_time < last_bg.timestamp:" + JoH.dateTimeText(last_bg.timestamp));
        List<TransmitterData> graph_bgs = TransmitterData.latestForGraphAsc(count, last_send_time);
        if (!graph_bgs.isEmpty() && graph_bgs.size() > min_count) {
            //Log.d(TAG, "getWearTransmitterData count = " + graph_bgs.size());
            DataMap entries = dataMap(last_bg);
            final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
            for (TransmitterData bg : graph_bgs) {
                dataMaps.add(dataMap(bg));
                last_send_success = bg.timestamp;
                //Log.d(TAG, "getWearTransmitterData bg getId:" + bg.getId() + " raw_data:" + bg.raw_data + " filtered_data:" + bg.filtered_data + " timestamp:" + bg.timestamp + " uuid:" + bg.uuid);
            }
            entries.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putDataMapArrayList("entries", dataMaps);
            Log.i(TAG, "getWearTransmitterData SYNCED BGs up to " + JoH.dateTimeText(last_send_success) + " count = " + graph_bgs.size());
            return entries;
        } else
            Log.i(TAG, "getWearTransmitterData SYNCED BGs up to " + JoH.dateTimeText(last_send_success) + " count = 0");
    }
    return null;
}
 
Example 12
Source File: SystemStatusFragment.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void setTransmitterStatus() {

        if (prefs.getString("dex_collection_method", "BluetoothWixel").equals("DexcomShare")) {
            transmitter_status_view.setText("See Share Receiver");
            return;
        }

        TransmitterData td = TransmitterData.last();

        if (td == null || td.sensor_battery_level == 0) {
            transmitter_status_view.setText("not available");
            GcmActivity.requestSensorBatteryUpdate();
        } else if ((System.currentTimeMillis() - td.timestamp) > 1000 * 60 * 60 * 24) {
            transmitter_status_view.setText("no data in 24 hours");
            GcmActivity.requestSensorBatteryUpdate();
        } else {
            transmitter_status_view.setText("" + td.sensor_battery_level);
            GcmActivity.requestSensorBatteryUpdate(); // always ask
            if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_EMPTY) {
                transmitter_status_view.append(" - very low");
            } else if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW) {
                transmitter_status_view.append(" - low");
                transmitter_status_view.append("\n(experimental interpretation)");
            } else {
                transmitter_status_view.append(" - ok");
            }
        }

    }
 
Example 13
Source File: SystemStatus.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void setTransmitterStatus() {

        if(prefs.getString("dex_collection_method", "BluetoothWixel").equals("DexcomShare")){
            transmitter_status_view.setText("See Share Receiver");
            return;
        }

        TransmitterData td = TransmitterData.last();

        if (td== null || td.sensor_battery_level == 0){
            transmitter_status_view.setText("not available");
            GcmActivity.requestSensorBatteryUpdate();
        } else if((System.currentTimeMillis() - td.timestamp) > 1000*60*60*24){
            transmitter_status_view.setText("no data in 24 hours");
            GcmActivity.requestSensorBatteryUpdate();
        } else {
            transmitter_status_view.setText("" + td.sensor_battery_level);
            GcmActivity.requestSensorBatteryUpdate(); // always ask
            if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_EMPTY) {
                transmitter_status_view.append(" - very low");
            } else if (td.sensor_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW) {
                transmitter_status_view.append(" - low");
                transmitter_status_view.append("\n(experimental interpretation)");
            } else {
                transmitter_status_view.append(" - ok");
            }
        }

    }
 
Example 14
Source File: WixelReader.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
static Long timeForNextRead() {

        TransmitterData lastTransmitterData = TransmitterData.last();
        if (lastTransmitterData == null) {
            // We did not receive a packet, well someone hopefully is looking at data, return relatively fast
            Log.e(TAG, "lastTransmitterData == null returning 60000");
            return 60 * 1000L;
        }
        Long gapTime = new Date().getTime() - lastTransmitterData.timestamp;
        Log.d(TAG, "gapTime = " + gapTime);
        if (gapTime < 0) {
            // There is some confusion here (clock was readjusted?)
            Log.e(TAG, "gapTime <= null returning 60000");
            return 60 * 1000L;
        }

        if (gapTime < DEXCOM_PERIOD) {
            // We have received the last packet...
            // 300000 - gaptime is when we expect to have the next packet.
            return (DEXCOM_PERIOD - gapTime) + 2000;
        }

        gapTime = gapTime % DEXCOM_PERIOD;
        Log.d(TAG, "modulus gapTime = " + gapTime);
        if (gapTime < 10000) {
            // A new packet should arrive any second now
            return 10000L;
        }
        if (gapTime < 60000) {
            // A new packet should arrive but chance is we have missed it...
            return 30000L;
        }

        if (httpClient == null) {
            return (DEXCOM_PERIOD - gapTime) + 2000;
        } else {
            // compensate for parakeet gprs lag
            return (DEXCOM_PERIOD - gapTime) + 12000;
        }
    }
 
Example 15
Source File: WixelReader.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void readData() {
    Long LastReportedTime = 0L;
    TransmitterData lastTransmitterData = TransmitterData.last();
    if (lastTransmitterData != null) {
        LastReportedTime = lastTransmitterData.timestamp;

        // jamorham fix to avoid going twice to network when we just got a packet
        if ((new Date().getTime() - LastReportedTime) < DEXCOM_PERIOD - 2000) {
            Log.d(TAG, "Already have a recent packet - returning");
            if (JoH.ratelimit("deferred-msg", 60)) {
                statusLog(" Deferred", "Already have recent reading");
            }
            return;
        } else {
            statusLog(" Deferred", "");
        }


    }
    Long startReadTime = LastReportedTime;

    TransmitterRawData LastReportedReading = null;
    Log.d(TAG, "Starting... LastReportedReading " + LastReportedReading);
    // try to read one object...
    TransmitterRawData[] LastReadingArr = null;

    String recieversIpAddresses;

    if (!WixelReader.IsConfigured()) {
        return;
    }

    if ((DexCollectionType.getDexCollectionType() == DexCollectionType.Mock) && Home.get_engineering_mode()) {
        recieversIpAddresses = "fake://FAKE_DATA";
    } else {
        recieversIpAddresses = Pref.getString("wifi_recievers_addresses", "");
    }

    // How many packets should we read? we look at the maximum time between last calibration and last reading time
    // and calculate how much are needed.

    final Calibration lastCalibration = Calibration.lastValid();
    if (lastCalibration != null) {
        startReadTime = Math.max(startReadTime, lastCalibration.timestamp);
    }
    Long gapTime = new Date().getTime() - startReadTime + 120000;
    int packetsToRead = (int) (gapTime / (5 * 60000));
    packetsToRead = Math.min(packetsToRead, 200); // don't read too much, but always read 1.
    packetsToRead = Math.max(packetsToRead, 1);


    Log.d(TAG, "reading " + packetsToRead + " packets");
    LastReadingArr = Read(recieversIpAddresses, packetsToRead);

    if (LastReadingArr == null || LastReadingArr.length == 0) {
        return;
    }

    for (TransmitterRawData LastReading : LastReadingArr) {
        // Last in the array is the most updated reading we have.
        //TransmitterRawData LastReading = LastReadingArr[LastReadingArr.length -1];


        //if (LastReading.CaptureDateTime > LastReportedReading + 5000) {
        // Make sure we do not report packets from the far future...
        if ((LastReading.CaptureDateTime > LastReportedTime + 120000) &&
                (!almostEquals(LastReading, LastReportedReading)) &&
                LastReading.CaptureDateTime < new Date().getTime() + 120000) {
            // We have a real new reading...
            Log.d(TAG, "calling setSerialDataToTransmitterRawData " + LastReading.RawValue +
                    " LastReading.CaptureDateTime " + LastReading.CaptureDateTime + " " + LastReading.TransmissionId);
            setSerialDataToTransmitterRawData(LastReading.RawValue, LastReading.FilteredValue, LastReading.BatteryLife, LastReading.CaptureDateTime);
            LastReportedReading = LastReading;
            LastReportedTime = LastReading.CaptureDateTime;


            if (LastReading.UploaderBatteryLife > 0) {
                Pref.setInt("parakeet_battery", LastReading.UploaderBatteryLife);
                CheckBridgeBattery.checkParakeetBattery();
                if (Home.get_master()) {
                    GcmActivity.sendParakeetBattery(LastReading.UploaderBatteryLife);
                }
            }

        }
    }
}
 
Example 16
Source File: WixelReader.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private void readData() {
    Long LastReportedTime = 0L;
    TransmitterData lastTransmitterData = TransmitterData.last();
    if (lastTransmitterData != null) {
        LastReportedTime = lastTransmitterData.timestamp;

        // jamorham fix to avoid going twice to network when we just got a packet
        if ((new Date().getTime() - LastReportedTime) < DEXCOM_PERIOD - 2000) {
            Log.d(TAG, "Already have a recent packet - returning");
            if (JoH.ratelimit("deferred-msg", 60)) {
                statusLog(" Deferred", "Already have recent reading");
            }
            return;
        } else {
            statusLog(" Deferred", "");
        }


    }
    Long startReadTime = LastReportedTime;

    TransmitterRawData LastReportedReading = null;
    Log.d(TAG, "Starting... LastReportedReading " + LastReportedReading);
    // try to read one object...
    TransmitterRawData[] LastReadingArr = null;

    String recieversIpAddresses;

    if (!WixelReader.IsConfigured()) {
        return;
    }

    if ((DexCollectionType.getDexCollectionType() == DexCollectionType.Mock) && Home.get_engineering_mode()) {
        recieversIpAddresses = "fake://FAKE_DATA";
    } else {
        recieversIpAddresses = Pref.getString("wifi_recievers_addresses", "");
    }

    // How many packets should we read? we look at the maximum time between last calibration and last reading time
    // and calculate how much are needed.

    final Calibration lastCalibration = Calibration.lastValid();
    if (lastCalibration != null) {
        startReadTime = Math.max(startReadTime, lastCalibration.timestamp);
    }
    Long gapTime = new Date().getTime() - startReadTime + 120000;
    int packetsToRead = (int) (gapTime / (5 * 60000));
    packetsToRead = Math.min(packetsToRead, 200); // don't read too much, but always read 1.
    packetsToRead = Math.max(packetsToRead, 1);


    Log.d(TAG, "reading " + packetsToRead + " packets");
    LastReadingArr = Read(recieversIpAddresses, packetsToRead);

    if (LastReadingArr == null || LastReadingArr.length == 0) {
        return;
    }

    for (TransmitterRawData LastReading : LastReadingArr) {
        // Last in the array is the most updated reading we have.
        //TransmitterRawData LastReading = LastReadingArr[LastReadingArr.length -1];


        //if (LastReading.CaptureDateTime > LastReportedReading + 5000) {
        // Make sure we do not report packets from the far future...
        if ((LastReading.CaptureDateTime > LastReportedTime + 120000) &&
                (!almostEquals(LastReading, LastReportedReading)) &&
                LastReading.CaptureDateTime < new Date().getTime() + 120000) {
            // We have a real new reading...
            Log.d(TAG, "calling setSerialDataToTransmitterRawData " + LastReading.RawValue +
                    " LastReading.CaptureDateTime " + LastReading.CaptureDateTime + " " + LastReading.TransmissionId);
            setSerialDataToTransmitterRawData(LastReading.RawValue, LastReading.FilteredValue, LastReading.BatteryLife, LastReading.CaptureDateTime);
            LastReportedReading = LastReading;
            LastReportedTime = LastReading.CaptureDateTime;


            if (LastReading.UploaderBatteryLife > 0) {
                Pref.setInt("parakeet_battery", LastReading.UploaderBatteryLife);
                CheckBridgeBattery.checkParakeetBattery();
                if (Home.get_master()) {
                    GcmActivity.sendParakeetBattery(LastReading.UploaderBatteryLife);
                }
            }

        }
    }
}
 
Example 17
Source File: WixelReader.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
@Override
  public void readData()
  {
      if(!WixelReader.IsConfigured(mContext)) {
          return;
      }
      Long LastReportedTime = 0L;
  	TransmitterData lastTransmitterData = TransmitterData.last();
  	if(lastTransmitterData != null) {
  	    LastReportedTime = lastTransmitterData.timestamp;

          // jamorham fix to avoid going twice to network when we just got a packet
          if ((new Date().getTime() - LastReportedTime) < DEXCOM_PERIOD-2000) {
          Log.d(TAG, "Already have a recent packet - returning");
          return;
          }


      }
  	Long startReadTime = LastReportedTime;

  	TransmitterRawData LastReportedReading = null;
  	Log.d(TAG, "Starting... LastReportedReading " + LastReportedReading);
  	// try to read one object...
      TransmitterRawData[] LastReadingArr = null;

      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
      String recieversIpAddresses = prefs.getString("wifi_recievers_addresses", "");
      
      // How many packets should we read? we look at the maximum time between last calibration and last reading time
      // and calculate how much are needed.
      
      Calibration lastCalibration = Calibration.last();
      if(lastCalibration != null) {
          startReadTime = Math.max(startReadTime, (long)(lastCalibration.timestamp));
      }
      Long gapTime = new Date().getTime() - startReadTime + 120000;
      int packetsToRead = (int) (gapTime / (5 * 60000));
      packetsToRead = Math.min(packetsToRead, 200); // don't read too much, but always read 1.
      packetsToRead = Math.max(packetsToRead, 1); 
      
      Log.d(TAG,"reading " + packetsToRead + " packets");
LastReadingArr = Read(recieversIpAddresses ,packetsToRead);

if (LastReadingArr == null || LastReadingArr.length  == 0) {
    return;
}

for(TransmitterRawData LastReading : LastReadingArr ) {
  		// Last in the array is the most updated reading we have.
  		//TransmitterRawData LastReading = LastReadingArr[LastReadingArr.length -1];
    

  		//if (LastReading.CaptureDateTime > LastReportedReading + 5000) {
  		// Make sure we do not report packets from the far future...
  		if ((LastReading.CaptureDateTime > LastReportedTime + 120000 ) &&
  		        (!almostEquals(LastReading, LastReportedReading)) &&
  		        LastReading.CaptureDateTime < new Date().getTime() + 120000) {
  			// We have a real new reading...
  			Log.d(TAG, "calling setSerialDataToTransmitterRawData " + LastReading.RawValue +
  			        " LastReading.CaptureDateTime " + LastReading.CaptureDateTime + " " + LastReading.TransmissionId);
  			setSerialDataToTransmitterRawData(LastReading.RawValue,  LastReading.FilteredValue, LastReading.BatteryLife, LastReading.CaptureDateTime);
  			LastReportedReading = LastReading;
  			LastReportedTime = LastReading.CaptureDateTime;
  		}
  	}
  }
 
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));
    }
}