Java Code Examples for com.eveningoutpost.dexdrip.UtilityModels.Constants#SECOND_IN_MS

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.Constants#SECOND_IN_MS . 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: LeFunService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private long whenToRetryNext() {
    I.retry_backoff += Constants.SECOND_IN_MS;
    if (I.retry_backoff > MAX_RETRY_BACKOFF_MS) {
        I.retry_backoff = MAX_RETRY_BACKOFF_MS;
    }
    return Constants.SECOND_IN_MS * 10 + I.retry_backoff;
}
 
Example 2
Source File: ShareFollowService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
static void scheduleWakeUp() {
    final BgReading lastBg = BgReading.lastNoSenssor();
    final long last = lastBg != null ? lastBg.timestamp : 0;

    final long grace = Constants.SECOND_IN_MS * 10;
    final long next = Anticipate.next(JoH.tsl(), last, SAMPLE_PERIOD, grace) + grace;
    wakeup_time = next;
    UserError.Log.d(TAG, "Anticipate next: " + JoH.dateTimeText(next) + "  last: " + JoH.dateTimeText(last));

    JoH.wakeUpIntent(xdrip.getAppContext(), JoH.msTill(next), WakeLockTrampoline.getPendingIntent(ShareFollowService.class, Constants.SHFOLLOW_SERVICE_FAILOVER_ID));
}
 
Example 3
Source File: BlueJayInfo.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public long getTimestamp() {
    if (lastReadingTime != 0) {
        return lastStatus2 - (lastReadingTime * Constants.SECOND_IN_MS);
    } else {
        return -1;
    }
}
 
Example 4
Source File: NightscoutFollowService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
static void scheduleWakeUp() {
    final BgReading lastBg = BgReading.lastNoSenssor();
    final long last = lastBg != null ? lastBg.timestamp : 0;

    final long grace = Constants.SECOND_IN_MS * 10;
    final long next = Anticipate.next(JoH.tsl(), last, SAMPLE_PERIOD, grace) + grace;
    wakeup_time = next;
    UserError.Log.d(TAG, "Anticipate next: " + JoH.dateTimeText(next) + "  last: " + JoH.dateTimeText(last));

    JoH.wakeUpIntent(xdrip.getAppContext(), JoH.msTill(next), WakeLockTrampoline.getPendingIntent(NightscoutFollowService.class, Constants.NSFOLLOW_SERVICE_FAILOVER_ID));

}
 
Example 5
Source File: ShareFollowService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
static void scheduleWakeUp() {
    final BgReading lastBg = BgReading.lastNoSenssor();
    final long last = lastBg != null ? lastBg.timestamp : 0;

    final long grace = Constants.SECOND_IN_MS * 10;
    final long next = Anticipate.next(JoH.tsl(), last, SAMPLE_PERIOD, grace) + grace;
    wakeup_time = next;
    UserError.Log.d(TAG, "Anticipate next: " + JoH.dateTimeText(next) + "  last: " + JoH.dateTimeText(last));

    JoH.wakeUpIntent(xdrip.getAppContext(), JoH.msTill(next), WakeLockTrampoline.getPendingIntent(ShareFollowService.class, Constants.SHFOLLOW_SERVICE_FAILOVER_ID));
}
 
Example 6
Source File: MedtrumCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static long whenToRetryNext() {
    retry_backoff += Constants.SECOND_IN_MS;
    if (retry_backoff > MAX_RETRY_BACKOFF_MS) {
        retry_backoff = MAX_RETRY_BACKOFF_MS;
    }
    return Constants.SECOND_IN_MS * 10 + retry_backoff;
}
 
Example 7
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private long whenToPollNext() {
    final long poll_time = Math.max((Constants.SECOND_IN_MS * 5) + poll_backoff, POLLING_PERIOD - JoH.msSince(lastPacketTime));
    if (poll_backoff < (Constants.MINUTE_IN_MS * 6)) {
        poll_backoff += Constants.SECOND_IN_MS;
    }
    Log.d(TAG, "Scheduling next poll in: " + JoH.niceTimeScalar(poll_time) + " @ " + JoH.dateTimeText(poll_time + JoH.tsl()) + " period diff: " + (POLLING_PERIOD - JoH.msSince(lastPacketTime)));
    return poll_time;
}
 
Example 8
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private long whenToRetryNext() {
    final long poll_time = Math.max((Constants.SECOND_IN_MS * 10) + retry_backoff, RETRY_PERIOD - JoH.msSince(lastPacketTime));
    if (retry_backoff < (Constants.MINUTE_IN_MS)) {
        retry_backoff += Constants.SECOND_IN_MS;
    }
    Log.d(TAG, "Scheduling next retry in: " + JoH.niceTimeScalar(poll_time) + " @ " + JoH.dateTimeText(poll_time + JoH.tsl()) + " period diff: " + (RETRY_PERIOD - JoH.msSince(lastPacketTime)));
    return poll_time;
}
 
Example 9
Source File: Ob1G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void onConnectionStateChange(RxBleConnection.RxBleConnectionState newState) {
    String connection_state = "Unknown";
    switch (newState) {
        case CONNECTING:
            connection_state = "Connecting";
            connecting_time = tsl();
            break;
        case CONNECTED:
            connection_state = "Connected";
            JoH.releaseWakeLock(floatingWakeLock);
            floatingWakeLock = JoH.getWakeLock("floating-connected", 40000);
            final long since_connecting = JoH.msSince(connecting_time);
            if ((connecting_time > static_last_timestamp) && (since_connecting > Constants.SECOND_IN_MS * 310) && (since_connecting < Constants.SECOND_IN_MS * 620)) {
                if (!always_scan) {
                    UserError.Log.e(TAG, "Connection time shows missed reading, switching to always scan, metric: " + niceTimeScalar(since_connecting));
                    always_scan = true;
                } else {
                    UserError.Log.e(TAG, "Connection time shows missed reading, despite always scan, metric: " + niceTimeScalar(since_connecting));
                }
            }
            break;
        case DISCONNECTING:
            connection_state = "Disconnecting";
            break;
        case DISCONNECTED:
            connection_state = "Disconnected";
            JoH.releaseWakeLock(floatingWakeLock);
            break;
    }
    static_connection_state = connection_state;
    UserError.Log.d(TAG, "Bluetooth connection: " + static_connection_state);
    if (connection_state.equals("Disconnecting")) {
        //tryGattRefresh();
    }
}
 
Example 10
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void syncTreatmentsData(DataMap dataMap, boolean bBenchmark) {
    Log.d(TAG, "syncTreatmentsData");

    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    if (entries != null) {
        Log.d(TAG, "syncTreatmentsData count=" + entries.size());
        for (DataMap entry : entries) {
            if (entry != null) {
                Log.d(TAG, "syncTreatmentsData entry=" + entry);
                String record = entry.getString("entry");
                if (record != null && record.length() > 1) {
                    Log.d(TAG, "Received wearable 2: voice payload: " + record);
                    long timestamp = entry.getLong("timestamp");
                    if (timestamp <= PersistentStore.getLong(LAST_RECORD_TIMESTAMP)) {
                        Log.e(TAG, "Ignoring repeated or older sync timestamp");
                        continue;
                    }
                    final long since = JoH.msSince(timestamp);
                    if ((since < -(Constants.SECOND_IN_MS * 5)) || (since > Constants.HOUR_IN_MS * 72)) {
                        JoH.static_toast_long("Rejecting wear treatment as time out of range!");
                        UserError.Log.e(TAG, "Rejecting wear treatment due to time: " + record + " since: " + since);
                    } else {
                        if (record.contains("uuid null")) {
                            Log.e(TAG, "Skipping xx uuid null record!");
                            continue;
                        }
                        receivedText(getApplicationContext(), record);
                        PersistentStore.setLong(LAST_RECORD_TIMESTAMP, timestamp);
                    }
                    Log.d(TAG, "syncTreatmentsData add Table record=" + record);
                    timeOfLastEntry = (long) timestamp + 1;
                    Log.d(TAG, "syncTreatmentsData WATCH treatments timestamp=" + JoH.dateTimeText(timestamp));
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "TREATMENTS", -1);
    }
}
 
Example 11
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private long whenToRetryNext() {
    final long poll_time = Math.max((Constants.SECOND_IN_MS * 10) + retry_backoff, RETRY_PERIOD - JoH.msSince(lastPacketTime));
    if (retry_backoff < (Constants.MINUTE_IN_MS)) {
        retry_backoff += Constants.SECOND_IN_MS;
    }
    Log.d(TAG, "Scheduling next retry in: " + JoH.niceTimeScalar(poll_time) + " @ " + JoH.dateTimeText(poll_time + JoH.tsl()) + " period diff: " + (RETRY_PERIOD - JoH.msSince(lastPacketTime)));
    return poll_time;
}
 
Example 12
Source File: Ob1G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private synchronized void onConnectionStateChange(RxBleConnection.RxBleConnectionState newState) {
    String connection_state = "Unknown";
    switch (newState) {
        case CONNECTING:
            connection_state = "Connecting";
            connecting_time = JoH.tsl();
            break;
        case CONNECTED:
            connection_state = "Connected";
            JoH.releaseWakeLock(floatingWakeLock);
            floatingWakeLock = JoH.getWakeLock("floating-connected", 40000);
            final long since_connecting = JoH.msSince(connecting_time);
            if ((connecting_time > static_last_timestamp) && (since_connecting > Constants.SECOND_IN_MS * 310) && (since_connecting < Constants.SECOND_IN_MS * 620)) {
                if (!always_scan) {
                    UserError.Log.e(TAG, "Connection time shows missed reading, switching to always scan, metric: " + JoH.niceTimeScalar(since_connecting));
                    always_scan = true;
                } else {
                    UserError.Log.e(TAG, "Connection time shows missed reading, despite always scan, metric: " + JoH.niceTimeScalar(since_connecting));
                }
            }
            break;
        case DISCONNECTING:
            connection_state = "Disconnecting";
            break;
        case DISCONNECTED:
            connection_state = "Disconnected";
            JoH.releaseWakeLock(floatingWakeLock);
            break;
    }
    static_connection_state = connection_state;
    UserError.Log.d(TAG, "Bluetooth connection: " + static_connection_state);
    if (connection_state.equals("Disconnecting")) {
        //tryGattRefresh();
    }
}
 
Example 13
Source File: JamBaseBluetoothSequencer.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public QueueMe expireInSeconds(final int timeout) {
    this.expireAt = JoH.tsl() + (Constants.SECOND_IN_MS * timeout);
    return this;
}
 
Example 14
Source File: PendiqService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    xdrip.checkAppContext(getApplicationContext());
    if (Pendiq.enabled()) {
        final PowerManager.WakeLock wl = JoH.getWakeLock("pendiq-start-service", 600000);
        try {
            UserError.Log.d(TAG, "WAKE UP WAKE UP WAKE UP WAKE UP @ " + JoH.dateTimeText(JoH.tsl()));
            if (intent != null) {
                final String action = intent.getAction();
                if (action != null && action.equals(PENDIQ_ACTION)) {
                    final String command = intent.getStringExtra(PENDIQ_INSTRUCTION);
                    UserError.Log.d(TAG, "Processing remote command: " + command);
                    if (JoH.msSince(intent.getLongExtra(PENDIQ_TIMESTAMP, 0)) < Constants.SECOND_IN_MS * 10) {

                        switch (command) {
                            case PENDIQ_COMMAND_DOSE_PREP:
                                try {
                                    dose_prep_waiting = Double.parseDouble(intent.getStringExtra(PENDIQ_PARAMETER));
                                    decideServiceStartStateChange();
                                } catch (NumberFormatException e) {
                                    UserError.Log.wtf(TAG, "Could not process dosage prep: " + intent.getStringExtra(PENDIQ_PARAMETER));
                                }
                                break;
                            default:
                                UserError.Log.e(TAG, "Unknown remote command: " + command);

                        }
                    } else {
                        UserError.Log.wtf(TAG, "Received service start request out of time: " + action);
                    }
                } else {
                    decideServiceStartStateChange();
                }
            }
        } finally {
            // TODO wrong place for release here?
            JoH.releaseWakeLock(wl);
        }
        return START_STICKY;
    } else {
        UserError.Log.d(TAG, "Should not be running so shutting down");
        stopSelf();
        return START_NOT_STICKY;
    }
}
 
Example 15
Source File: DexCollectionService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
synchronized void checkConnection() {
    status("Attempting connection");
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (bluetoothManager == null) {
        status("No bluetooth manager");
        setRetryTimer();
        return;
    }

    mBluetoothAdapter = bluetoothManager.getAdapter();
    if (mBluetoothAdapter == null) {
        status("No bluetooth adapter");
        setRetryTimer();
        return;
    }

    if (!mBluetoothAdapter.isEnabled()) {
        mConnectionState = STATE_DISCONNECTED; // can't be connected if BT is disabled
        if (Pref.getBoolean("automatically_turn_bluetooth_on", true)) {
            Log.i(TAG, "Turning bluetooth on as appears disabled");
            status("Turning bluetooth on");
            JoH.setBluetoothEnabled(getApplicationContext(), true);
        } else {
            Log.d(TAG, "Not automatically turning on bluetooth due to preferences");
        }
    }

    if (device != null) {
        boolean found = false;
        for (BluetoothDevice bluetoothDevice : bluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
            if (bluetoothDevice.getAddress().equals(device.getAddress())) {
                found = true;
                if (mConnectionState != STATE_CONNECTED) {
                    UserError.Log.d(TAG, "Detected state change by checking connected devices");
                    handleConnectedStateChange();
                }
                break;
            }
        }
        if (!found) {
            if (mConnectionState == STATE_CONNECTED) {
                UserError.Log.d(TAG, "Marking disconnected as not in list of connected devices");
                mConnectionState = STATE_DISCONNECTED; // not in connected list so should be disconnected we think
            }

        }
    } else {
        UserError.Log.d(TAG, "Device is null in checkConnection");
        mConnectionState = STATE_DISCONNECTED; // can't be connected if we don't know the device
    }

    Log.i(TAG, "checkConnection: Connection state: " + getStateStr(mConnectionState));
    if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
        final ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
        if (btDevice != null) {
            final String deviceAddress = btDevice.address;
            mDeviceAddress = deviceAddress;
            try {
                if (mBluetoothAdapter.isEnabled() && mBluetoothAdapter.getRemoteDevice(deviceAddress) != null) {
                    if (useScanning()) {
                        status(gs(R.string.scanning) + (Home.get_engineering_mode() ? ": " + deviceAddress : ""));
                        scanMeister.setAddress(deviceAddress).addCallBack(this, TAG).scan();
                    } else {
                        status("Connecting" + (Home.get_engineering_mode() ? ": " + deviceAddress : ""));
                        connect(deviceAddress);
                    }
                    mStaticState = mConnectionState;
                    return;
                }
            } catch (IllegalArgumentException e) {
                Log.e(TAG, "IllegalArgumentException: " + e);
            }
        }
    } else if (mConnectionState == STATE_CONNECTING) {
        mStaticState = mConnectionState;
        if (JoH.msSince(last_connect_request) > (getTrustAutoConnect() ? Constants.SECOND_IN_MS * 3600 : Constants.SECOND_IN_MS * 30)) {
            Log.i(TAG, "Connecting for too long, shutting down");
            retry_backoff = 0;
            close();
        }
    } else if (mConnectionState == STATE_CONNECTED) { //WOOO, we are good to go, nothing to do here!
        status("Last Connected");
        Log.i(TAG, "checkConnection: Looks like we are already connected, ready to receive");
        retry_backoff = 0;
        mStaticState = mConnectionState;
        if (use_polling && (JoH.msSince(lastPacketTime) >= POLLING_PERIOD)) {
            pollForData();
        }

        return;
    }
    setRetryTimer();
}
 
Example 16
Source File: BlueJayInfo.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public long getUptimeTimeStamp() {
    return uptime * Constants.SECOND_IN_MS;
}
 
Example 17
Source File: JamBaseBluetoothSequencer.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public QueueMe expireInSeconds(final int timeout) {
    this.expireAt = JoH.tsl() + (Constants.SECOND_IN_MS * timeout);
    return this;
}
 
Example 18
Source File: BluetoothGlucoseMeter.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void processGlucoseReadingRx(GlucoseReadingRx gtb) {
    if ((!ignore_control_solution_tests) || (gtb.sampleType != 10)) {

        if (ct.sequenceNotReliable) {
            // sequence numbers on some meters are reversed so instead invent one using timestamp with 5 second resolution
            gtb.sequence = (int) ((gtb.time / 5000) - (1496755620 / 5));
        } else {
            setHighestSequence(gtb.sequence);
        }

        if (ct.noClockAccess && Pref.getBooleanDefaultFalse("meter_recent_reading_as_now")) {
            // for diamond mini we don't know if the clock is correct but if it is within the threshold period then we treat it as if the reading
            // has just happened. We only do this when we have received at least one synced reading so the first one after pairing isn't munged.
            if (JoH.absMsSince(gtb.time) < NO_CLOCK_THRESHOLD
                    && PersistentStore.getBoolean(GLUCOSE_READING_MARKER + mLastConnectedDeviceAddress)) {
                final long saved_time = gtb.time;
                gtb.time = JoH.tsl() - Constants.SECOND_IN_MS * 30; // when the reading was most likely taken
                UserError.Log.e(TAG, "Munged meter reading time from: " + JoH.dateTimeText(saved_time) + " to " + JoH.dateTimeText(gtb.time));
            }
            if (JoH.quietratelimit(GLUCOSE_READING_MARKER, 10)) {
                PersistentStore.setBoolean(GLUCOSE_READING_MARKER + mLastConnectedDeviceAddress, true);
            }
        }


        final BloodTest bt = BloodTest.create((gtb.time - ct.timediff) + gtb.offsetMs(), gtb.mgdl, BLUETOOTH_GLUCOSE_METER_TAG + ":\n" + mLastManufacturer + "   " + mLastConnectedDeviceAddress, gtb.getUuid().toString());
        if (bt != null) {
            UserError.Log.d(TAG, "Successfully created new BloodTest: " + bt.toS());
            bt.glucoseReadingRx = gtb; // add reference
            lastBloodTest = bt;
            UserError.Log.uel(TAG, "New blood test data: " + BgGraphBuilder.unitized_string_static(bt.mgdl) + " @ " + JoH.dateTimeText(bt.timestamp) + " " + bt.source);

            Inevitable.task("evaluate-meter-records", 2000, this::evaluateLastRecords);

        } else {
            if (d) UserError.Log.d(TAG, "Failed to create BloodTest record");
        }
    } else {
        UserError.Log.d(TAG, "Ignoring control solution test");
    }
}
 
Example 19
Source File: PendiqService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    xdrip.checkAppContext(getApplicationContext());
    if (Pendiq.enabled()) {
        final PowerManager.WakeLock wl = JoH.getWakeLock("pendiq-start-service", 600000);
        try {
            UserError.Log.d(TAG, "WAKE UP WAKE UP WAKE UP WAKE UP @ " + JoH.dateTimeText(JoH.tsl()));
            if (intent != null) {
                final String action = intent.getAction();
                if (action != null && action.equals(PENDIQ_ACTION)) {
                    final String command = intent.getStringExtra(PENDIQ_INSTRUCTION);
                    UserError.Log.d(TAG, "Processing remote command: " + command);
                    if (JoH.msSince(intent.getLongExtra(PENDIQ_TIMESTAMP, 0)) < Constants.SECOND_IN_MS * 10) {

                        switch (command) {
                            case PENDIQ_COMMAND_DOSE_PREP:
                                try {
                                    dose_prep_waiting = Double.parseDouble(intent.getStringExtra(PENDIQ_PARAMETER));
                                    decideServiceStartStateChange();
                                } catch (NumberFormatException e) {
                                    UserError.Log.wtf(TAG, "Could not process dosage prep: " + intent.getStringExtra(PENDIQ_PARAMETER));
                                }
                                break;
                            default:
                                UserError.Log.e(TAG, "Unknown remote command: " + command);

                        }
                    } else {
                        UserError.Log.wtf(TAG, "Received service start request out of time: " + action);
                    }
                } else {
                    decideServiceStartStateChange();
                }
            }
        } finally {
            // TODO wrong place for release here?
            JoH.releaseWakeLock(wl);
        }
        return START_STICKY;
    } else {
        UserError.Log.d(TAG, "Should not be running so shutting down");
        stopSelf();
        return START_NOT_STICKY;
    }
}
 
Example 20
Source File: PushRx.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
BackFillRecord(final int secondsSince, final int mgdl, final int trend) {
    this.timestamp = JoH.tsl() - (secondsSince * Constants.SECOND_IN_MS);
    this.mgdl = mgdl;
    this.trend = trend;
}