Search in sources :

Example 1 with TimeTx

use of com.eveningoutpost.dexdrip.cgm.medtrum.messages.TimeTx in project xDrip by NightscoutFoundation.

the class MedtrumCollectionService method automata.

public synchronized boolean automata() {
    if ((last_automata_state != state) || (JoH.ratelimit("jam-g5-dupe-auto", 2))) {
        last_automata_state = state;
        final PowerManager.WakeLock wl = JoH.getWakeLock("jam-g5-automata", 60000);
        try {
            switch(state) {
                case INIT:
                    initialize();
                    break;
                case SCAN:
                    scan_for_device();
                    break;
                case CONNECT:
                    connect_to_device();
                    break;
                case ENABLE:
                    // we have a connection
                    retry_backoff = 0;
                    enable_features_and_listen();
                    break;
                case DISCOVER:
                    changeState(state.next());
                    break;
                case CALIBRATE:
                    check_calibrate();
                    break;
                case GET_DATA:
                    get_data();
                    break;
                case SET_TIME:
                    if (JoH.pratelimit("medtrum-set-time-" + serial, 60)) {
                        sendTx(new TimeTx());
                    } else {
                        changeState(state.next());
                    }
                    break;
                case SET_CONN_PARAM:
                    sendTx(new ConnParamTx());
                    break;
                case CLOSE:
                    // prepareToWakeup(); // TODO this skips service wake up
                    stopConnect();
                    setRetryTimer();
                    state = CLOSED;
                    // changeState(INIT);
                    break;
                case CLOSED:
                    setRetryTimer();
                    break;
                case LISTEN:
                    status("Listening");
                    if (notificationSubscription == null || notificationSubscription.isUnsubscribed()) {
                        changeState(SCAN);
                    }
                    break;
            }
        } finally {
            JoH.releaseWakeLock(wl);
        }
    } else {
        UserError.Log.d(TAG, "Ignoring duplicate automata state within 2 seconds: " + state);
    }
    return true;
}
Also used : PowerManager(android.os.PowerManager) TimeTx(com.eveningoutpost.dexdrip.cgm.medtrum.messages.TimeTx) ConnParamTx(com.eveningoutpost.dexdrip.cgm.medtrum.messages.ConnParamTx)

Example 2 with TimeTx

use of com.eveningoutpost.dexdrip.cgm.medtrum.messages.TimeTx in project xDrip-plus by jamorham.

the class MedtrumCollectionService method automata.

public synchronized boolean automata() {
    if ((last_automata_state != state) || (JoH.ratelimit("jam-g5-dupe-auto", 2))) {
        last_automata_state = state;
        final PowerManager.WakeLock wl = JoH.getWakeLock("jam-g5-automata", 60000);
        try {
            switch(state) {
                case INIT:
                    initialize();
                    break;
                case SCAN:
                    scan_for_device();
                    break;
                case CONNECT:
                    connect_to_device();
                    break;
                case ENABLE:
                    // we have a connection
                    retry_backoff = 0;
                    enable_features_and_listen();
                    break;
                case DISCOVER:
                    changeState(state.next());
                    break;
                case CALIBRATE:
                    check_calibrate();
                    break;
                case GET_DATA:
                    get_data();
                    break;
                case SET_TIME:
                    if (JoH.pratelimit("medtrum-set-time-" + serial, 60)) {
                        sendTx(new TimeTx());
                    } else {
                        changeState(state.next());
                    }
                    break;
                case SET_CONN_PARAM:
                    sendTx(new ConnParamTx());
                    break;
                case CLOSE:
                    // prepareToWakeup(); // TODO this skips service wake up
                    stopConnect();
                    setRetryTimer();
                    state = CLOSED;
                    // changeState(INIT);
                    break;
                case CLOSED:
                    setRetryTimer();
                    break;
                case LISTEN:
                    status("Listening");
                    if (notificationSubscription == null || notificationSubscription.isUnsubscribed()) {
                        changeState(SCAN);
                    }
                    break;
            }
        } finally {
            JoH.releaseWakeLock(wl);
        }
    } else {
        UserError.Log.d(TAG, "Ignoring duplicate automata state within 2 seconds: " + state);
    }
    return true;
}
Also used : PowerManager(android.os.PowerManager) TimeTx(com.eveningoutpost.dexdrip.cgm.medtrum.messages.TimeTx) ConnParamTx(com.eveningoutpost.dexdrip.cgm.medtrum.messages.ConnParamTx)

Aggregations

PowerManager (android.os.PowerManager)2 ConnParamTx (com.eveningoutpost.dexdrip.cgm.medtrum.messages.ConnParamTx)2 TimeTx (com.eveningoutpost.dexdrip.cgm.medtrum.messages.TimeTx)2