Search in sources :

Example 1 with AbstractUploaderDevice

use of com.nightscout.core.drivers.AbstractUploaderDevice in project android-uploader by nightscout.

the class MongoUploaderTest method testReturnFalseWithInvalidURI.

@Test
public void testReturnFalseWithInvalidURI() {
    mongoUploader = new MongoUploader(preferences, new MongoClientURI("mongodb://foobar/db"), "collection", "dsCollection");
    AbstractUploaderDevice deviceStatus = mockDeviceStatus();
    assertThat(mongoUploader.uploadDeviceStatus(deviceStatus), is(false));
}
Also used : MongoClientURI(com.mongodb.MongoClientURI) AbstractUploaderDevice(com.nightscout.core.drivers.AbstractUploaderDevice) Test(org.junit.Test)

Example 2 with AbstractUploaderDevice

use of com.nightscout.core.drivers.AbstractUploaderDevice in project android-uploader by nightscout.

the class RestLegacyUploaderTest method testDeviceStatus_Entity.

@Test
public void testDeviceStatus_Entity() throws Exception {
    AbstractUploaderDevice deviceStatus = mockDeviceStatus();
    restUploader.uploadDeviceStatus(deviceStatus);
    HttpPost post = (HttpPost) captor.getValue();
    String entity = CharStreams.toString(new InputStreamReader(post.getEntity().getContent()));
    verifyDeviceStatus(new JSONObject(entity), deviceStatus);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.JSONObject) AbstractUploaderDevice(com.nightscout.core.drivers.AbstractUploaderDevice) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 3 with AbstractUploaderDevice

use of com.nightscout.core.drivers.AbstractUploaderDevice in project android-uploader by nightscout.

the class Uploader method upload.

private boolean upload(List<GlucoseDataSet> glucoseDataSets, List<MeterEntry> meterRecords, List<CalibrationEntry> calRecords) {
    AbstractUploaderDevice deviceStatus = AndroidUploaderDevice.getUploaderDevice(context);
    boolean allSuccessful = true;
    for (BaseUploader uploader : uploaders) {
        // TODO(klee): capture any exceptions here so that all configured uploaders will attempt
        // to upload
        allSuccessful &= uploader.uploadRecords(glucoseDataSets, meterRecords, calRecords, deviceStatus);
    }
    // uploaders were executed.
    return allUploadersInitalized && allSuccessful && (uploaders.size() != 0);
}
Also used : AbstractUploaderDevice(com.nightscout.core.drivers.AbstractUploaderDevice) BaseUploader(com.nightscout.core.upload.BaseUploader)

Example 4 with AbstractUploaderDevice

use of com.nightscout.core.drivers.AbstractUploaderDevice in project android-uploader by nightscout.

the class SyncingService method handleActionSync.

/**
     * Handle action Sync in the provided background thread with the provided
     * parameters.
     */
protected void handleActionSync(int numOfPages, Context context, DeviceTransport serialDriver) {
    boolean broadcastSent = false;
    AndroidPreferences preferences = new AndroidPreferences(context);
    Tracker tracker = ((Nightscout) context).getTracker();
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NSDownload");
    wl.acquire();
    if (serialDriver != null) {
        AbstractUploaderDevice uploaderDevice = AndroidUploaderDevice.getUploaderDevice(context);
        AbstractDevice device = new DexcomG4(serialDriver, preferences, uploaderDevice);
        ((DexcomG4) device).setNumOfPages(numOfPages);
        ((CdcAcmSerialDriver) serialDriver).setPowerManagementEnabled(preferences.isRootEnabled());
        try {
            DownloadResults results = device.download();
            G4Download download = results.getDownload();
            Uploader uploader = new Uploader(context, preferences);
            boolean uploadStatus;
            if (numOfPages < 20) {
                uploadStatus = uploader.upload(results, 1);
            } else {
                uploadStatus = uploader.upload(results);
            }
            EGVRecord recentEGV;
            if (download.download_status == DownloadStatus.SUCCESS) {
                recentEGV = new EGVRecord(download.sgv.get(download.sgv.size() - 1));
            } else {
                recentEGV = new EGVRecord(-1, TrendArrow.NONE, new Date(), new Date(), G4Noise.NOISE_NONE);
            }
            broadcastSGVToUI(recentEGV, uploadStatus, results.getNextUploadTime() + TIME_SYNC_OFFSET, results.getDisplayTime(), results.getResultArray(), download.receiver_battery);
            broadcastSent = true;
        } catch (ArrayIndexOutOfBoundsException e) {
            Log.wtf("Unable to read from the dexcom, maybe it will work next time", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Array Index out of bounds").setFatal(false).build());
        } catch (NegativeArraySizeException e) {
            Log.wtf("Negative array exception from receiver", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Negative Array size").setFatal(false).build());
        } catch (IndexOutOfBoundsException e) {
            Log.wtf("IndexOutOfBounds exception from receiver", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("IndexOutOfBoundsException").setFatal(false).build());
        } catch (CRCFailError e) {
            // FIXME: may consider localizing this catch at a lower level (like ReadData) so that
            // if the CRC check fails on one type of record we can capture the values if it
            // doesn't fail on other types of records. This means we'd need to broadcast back
            // partial results to the UI. Adding it to a lower level could make the ReadData class
            // more difficult to maintain - needs discussion.
            Log.wtf("CRC failed", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("CRC Failed").setFatal(false).build());
        } catch (Exception e) {
            Log.wtf("Unhandled exception caught", e);
            tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Catch all exception in handleActionSync").setFatal(false).build());
        }
    }
    if (!broadcastSent)
        broadcastSGVToUI();
    wl.release();
}
Also used : AndroidPreferences(com.nightscout.android.preferences.AndroidPreferences) Tracker(com.google.android.gms.analytics.Tracker) HitBuilders(com.google.android.gms.analytics.HitBuilders) DownloadResults(com.nightscout.core.model.DownloadResults) DexcomG4(com.nightscout.core.drivers.DexcomG4) CdcAcmSerialDriver(com.nightscout.android.drivers.USB.CdcAcmSerialDriver) AbstractUploaderDevice(com.nightscout.core.drivers.AbstractUploaderDevice) CRCFailError(com.nightscout.core.dexcom.CRCFailError) EGVRecord(com.nightscout.core.dexcom.records.EGVRecord) Date(java.util.Date) G4Download(com.nightscout.core.model.G4Download) PowerManager(android.os.PowerManager) AbstractDevice(com.nightscout.core.drivers.AbstractDevice) Uploader(com.nightscout.android.upload.Uploader)

Example 5 with AbstractUploaderDevice

use of com.nightscout.core.drivers.AbstractUploaderDevice in project android-uploader by nightscout.

the class MongoUploaderTest method testUploadDeviceStatus.

@Test
public void testUploadDeviceStatus() {
    AbstractUploaderDevice deviceStatus = mockDeviceStatus();
    mongoUploader.uploadDeviceStatus(deviceStatus);
    verifyDeviceStatus(deviceStatus);
}
Also used : AbstractUploaderDevice(com.nightscout.core.drivers.AbstractUploaderDevice) Test(org.junit.Test)

Aggregations

AbstractUploaderDevice (com.nightscout.core.drivers.AbstractUploaderDevice)6 Test (org.junit.Test)4 InputStreamReader (java.io.InputStreamReader)2 HttpPost (org.apache.http.client.methods.HttpPost)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 JSONObject (org.json.JSONObject)2 PowerManager (android.os.PowerManager)1 HitBuilders (com.google.android.gms.analytics.HitBuilders)1 Tracker (com.google.android.gms.analytics.Tracker)1 MongoClientURI (com.mongodb.MongoClientURI)1 CdcAcmSerialDriver (com.nightscout.android.drivers.USB.CdcAcmSerialDriver)1 AndroidPreferences (com.nightscout.android.preferences.AndroidPreferences)1 Uploader (com.nightscout.android.upload.Uploader)1 CRCFailError (com.nightscout.core.dexcom.CRCFailError)1 EGVRecord (com.nightscout.core.dexcom.records.EGVRecord)1 AbstractDevice (com.nightscout.core.drivers.AbstractDevice)1 DexcomG4 (com.nightscout.core.drivers.DexcomG4)1 DownloadResults (com.nightscout.core.model.DownloadResults)1 G4Download (com.nightscout.core.model.G4Download)1 BaseUploader (com.nightscout.core.upload.BaseUploader)1