package com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records; import android.util.Log; import com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Constants; import org.json.JSONException; import org.json.JSONObject; import java.io.Serializable; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Arrays; import java.util.Date; // This code and this particular library are from the NightScout android uploader // Check them out here: https://github.com/nightscout/android-uploader // Some of this code may have been modified for use in this project public class EGVRecord extends GenericTimestampRecord { private int bGValue; private int noise; private Constants.TREND_ARROW_VALUES trend; public EGVRecord(byte[] packet) { // system_time (UInt), display_time (UInt), glucose (UShort), trend_arrow (Byte), crc (UShort)) super(packet); bGValue = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN).getShort(8) & Constants.EGV_VALUE_MASK; byte trendAndNoise = ByteBuffer.wrap(packet).order(ByteOrder.LITTLE_ENDIAN).get(10); int trendValue = trendAndNoise & Constants.EGV_TREND_ARROW_MASK; byte noiseValue = (byte) ((trendAndNoise & Constants.EGV_NOISE_MASK) >> 4); trend = Constants.TREND_ARROW_VALUES.values()[trendValue]; noise = noiseValue; } public EGVRecord(int bGValue,Constants.TREND_ARROW_VALUES trend,Date displayTime, Date systemTime){ super(displayTime, systemTime); this.bGValue=bGValue; this.trend=trend; } public String noiseValue() { return String.valueOf(noise); } public int getBGValue() { return bGValue; } public Constants.TREND_ARROW_VALUES getTrend() { return trend; } public JSONObject toJSON() { JSONObject obj = new JSONObject(); try { obj.put("sgv", getBGValue()); obj.put("date", getDisplayTimeSeconds()); } catch (JSONException e) { e.printStackTrace(); } return obj; } }