// Path: wear/src/main/java/com/eveningoutpost/dexdrip/Models/GlucoseData.java
// public class GlucoseData implements Comparable<GlucoseData> {
// 
//     public long realDate;
//     public String sensorId;
//     public long sensorTime;
//     public int glucoseLevel = -1;
//     public int glucoseLevelRaw = -1;
//     public long phoneDatabaseId;
//     public int glucoseLevelRawSmoothed;
// 
//     public GlucoseData(){}
// 
//     // jamorham added constructor
//     public GlucoseData(int glucoseLevelRaw, long timestamp) {
//         this.glucoseLevelRaw = glucoseLevelRaw;
//         this.realDate = timestamp;
//     }
// 
//     public String glucose(boolean mmol) {
//         return glucose(glucoseLevel, mmol);
//     }
// 
//     public static String glucose(int mgdl, boolean mmol) {
//         return mmol ? new DecimalFormat("##.0").format(mgdl/18f) : String.valueOf(mgdl);
//     }
// 
//     @Override
//     public int compareTo(GlucoseData another) {
//         return (int) (realDate - another.realDate);
//     }
// }


import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;
import android.nfc.Tag;
import android.nfc.tech.NfcV;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.os.Vibrator;
import android.view.View;
import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump;
import com.eveningoutpost.dexdrip.Models.GlucoseData;
import com.eveningoutpost.dexdrip.Models.JoH;
import com.eveningoutpost.dexdrip.Models.LibreBlock;
import com.eveningoutpost.dexdrip.Models.LibreOOPAlgorithm;
import com.eveningoutpost.dexdrip.Models.ReadingData;
import com.eveningoutpost.dexdrip.Models.UserError.Log;
import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils;
import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore;
import com.eveningoutpost.dexdrip.UtilityModels.Pref;
import com.eveningoutpost.dexdrip.utils.DexCollectionType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.eveningoutpost.dexdrip.xdrip.gs;
                    }
                    if (d) Log.d(TAG, "Tag data reader exiting");
                    return tag;
                } finally {
                    read_lock.unlock();
                    Home.staticBlockUI(context, false);
                }
            } else {
                Log.d(TAG, "Already read_locked! - skipping");
                return null;
            }

        }

    }

    public static ReadingData parseData(int attempt, String tagId, byte[] data, Long CaptureDateTime) {

        int indexTrend = data[26] & 0xFF;

        int indexHistory = data[27] & 0xFF; // double check this bitmask? should be lower?

        final int sensorTime = 256 * (data[317] & 0xFF) + (data[316] & 0xFF);

        long sensorStartTime = CaptureDateTime - sensorTime * MINUTE;

        // option to use 13 bit mask
        //final boolean thirteen_bit_mask = Pref.getBooleanDefaultFalse("testing_use_thirteen_bit_mask");
        final boolean thirteen_bit_mask = true;

// Path: wear/src/main/java/com/eveningoutpost/dexdrip/Models/GlucoseData.java
// public class GlucoseData implements Comparable<GlucoseData> {
// 
//     public long realDate;
//     public String sensorId;
//     public long sensorTime;
//     public int glucoseLevel = -1;
//     public int glucoseLevelRaw = -1;
//     public long phoneDatabaseId;
//     public int glucoseLevelRawSmoothed;
// 
//     public GlucoseData(){}
// 
//     // jamorham added constructor
//     public GlucoseData(int glucoseLevelRaw, long timestamp) {
//         this.glucoseLevelRaw = glucoseLevelRaw;
//         this.realDate = timestamp;
//     }
// 
//     public String glucose(boolean mmol) {
//         return glucose(glucoseLevel, mmol);
//     }
// 
//     public static String glucose(int mgdl, boolean mmol) {
//         return mmol ? new DecimalFormat("##.0").format(mgdl/18f) : String.valueOf(mgdl);
//     }
// 
//     @Override
//     public int compareTo(GlucoseData another) {
//         return (int) (realDate - another.realDate);
//     }
// }


// Path: wear/src/main/java/com/eveningoutpost/dexdrip/NFCReaderX.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;
import android.nfc.Tag;
import android.nfc.tech.NfcV;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.os.Vibrator;
import android.view.View;
import com.eveningoutpost.dexdrip.ImportedLibraries.usbserial.util.HexDump;
import com.eveningoutpost.dexdrip.Models.GlucoseData;
import com.eveningoutpost.dexdrip.Models.JoH;
import com.eveningoutpost.dexdrip.Models.LibreBlock;
import com.eveningoutpost.dexdrip.Models.LibreOOPAlgorithm;
import com.eveningoutpost.dexdrip.Models.ReadingData;
import com.eveningoutpost.dexdrip.Models.UserError.Log;
import com.eveningoutpost.dexdrip.UtilityModels.LibreUtils;
import com.eveningoutpost.dexdrip.UtilityModels.PersistentStore;
import com.eveningoutpost.dexdrip.UtilityModels.Pref;
import com.eveningoutpost.dexdrip.utils.DexCollectionType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.eveningoutpost.dexdrip.xdrip.gs;

                    }
                    if (d) Log.d(TAG, "Tag data reader exiting");
                    return tag;
                } finally {
                    read_lock.unlock();
                    Home.staticBlockUI(context, false);
                }
            } else {
                Log.d(TAG, "Already read_locked! - skipping");
                return null;
            }

        }

    }

    public static ReadingData parseData(int attempt, String tagId, byte[] data, Long CaptureDateTime) {

        int indexTrend = data[26] & 0xFF;

        int indexHistory = data[27] & 0xFF; // double check this bitmask? should be lower?

        final int sensorTime = 256 * (data[317] & 0xFF) + (data[316] & 0xFF);

        long sensorStartTime = CaptureDateTime - sensorTime * MINUTE;

        // option to use 13 bit mask
        //final boolean thirteen_bit_mask = Pref.getBooleanDefaultFalse("testing_use_thirteen_bit_mask");
        final boolean thirteen_bit_mask = true;

        ArrayList<GlucoseData> historyList = new ArrayList<>();