Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion res/xml/device_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
limitations under the License.
-->
<resources>
<usb-device class="2" subclass="0" protocol="0" />
<usb-device vendor-id="8867" product-id="71" class="2" subclass="0" protocol="0" />
</resources>
7 changes: 7 additions & 0 deletions src/com/nightscout/android/dexcom/USB/UsbSerialProber.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.util.Log;

import java.util.Map;

Expand Down Expand Up @@ -86,6 +87,8 @@ public UsbSerialDriver getDevice(final UsbManager manager, final UsbDevice usbDe
}
};*/

private static final String TAG = UsbSerialProber.class.getSimpleName();

/**
* Builds a new {@link UsbSerialDriver} instance from the raw device, or
* returns <code>null</code> if it could not be built (for example, if the
Expand Down Expand Up @@ -128,6 +131,10 @@ public static UsbSerialDriver acquire(final UsbManager usbManager) {
* could be acquired
*/
public static UsbSerialDriver acquire(final UsbManager usbManager, final UsbDevice usbDevice) {
if (!usbManager.hasPermission(usbDevice)) {
Log.i(TAG, "No permission for " + usbDevice.getVendorId() + " " + usbDevice.getProductId());
return null;
}
for (final UsbSerialProber prober : values()) {
final UsbSerialDriver probedDevice = prober.getDevice(usbManager, usbDevice);
if (probedDevice != null) {
Expand Down
40 changes: 33 additions & 7 deletions src/com/nightscout/android/upload/UploadHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ protected void onPostExecute(Long result) {

private void doRESTUpload(SharedPreferences prefs, EGVRecord... records) {
try {
String baseURL = prefs.getString("API Base URL", "");
String postURL = baseURL + (baseURL.endsWith("/") ? "" : "/") + "entries";
String baseURLSetting = prefs.getString("API Base URL", "");
String baseURL = baseURLSetting + (baseURLSetting.endsWith("/") ? "" : "/");

int apiVersion = 0;
if (baseURL.endsWith("/v1/")) apiVersion = 1;

String postURL = baseURL + "entries";
Log.i(TAG, "postURL: " + postURL);

HttpParams params = new BasicHttpParams();
Expand All @@ -76,12 +81,17 @@ private void doRESTUpload(SharedPreferences prefs, EGVRecord... records) {
HttpPost post = new HttpPost(postURL);

for (EGVRecord record : records) {
Date date = DATE_FORMAT.parse(record.displayTime);
JSONObject json = new JSONObject();
json.put("device", "dexcom");
json.put("timestamp", date.getTime());
json.put("bg", Integer.parseInt(record.bGValue));
json.put("direction", record.trend);

try {
if (apiVersion >= 1)
populateV1APIEntry(json, record);
else
populateLegacyAPIEntry(json, record);
} catch (Exception e) {
Log.w(TAG, "Unable to populate entry, apiVersion: " + apiVersion, e);
continue;
}

String jsonString = json.toString();

Expand All @@ -104,6 +114,22 @@ private void doRESTUpload(SharedPreferences prefs, EGVRecord... records) {
}
}

private void populateV1APIEntry(JSONObject json, EGVRecord record) throws Exception {
Date date = DATE_FORMAT.parse(record.displayTime);
json.put("device", "dexcom");
json.put("timestamp", date.getTime());
json.put("sgv", Integer.parseInt(record.bGValue));
json.put("direction", record.trend);
}

private void populateLegacyAPIEntry(JSONObject json, EGVRecord record) throws Exception {
Date date = DATE_FORMAT.parse(record.displayTime);
json.put("device", "dexcom");
json.put("timestamp", date.getTime());
json.put("bg", Integer.parseInt(record.bGValue));
json.put("direction", record.trend);
}

private void doMongoUpload(SharedPreferences prefs, EGVRecord... records) {

String dbURI = prefs.getString("MongoDB URI", null);
Expand Down