Search in sources :

Example 1 with PageHeader

use of com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader in project xDrip by NightscoutFoundation.

the class ReadDataShare method ParsePage.

private <T> T ParsePage(byte[] data, int recordType, Action1<T> parsedPageReceiver) {
    int HEADER_LEN = 28;
    PageHeader pageHeader = new PageHeader(data);
    int NUM_REC_OFFSET = 4;
    int numRec = data[NUM_REC_OFFSET];
    int rec_len;
    switch(Constants.RECORD_TYPES.values()[recordType]) {
        case MANUFACTURING_DATA:
            GenericXMLRecord xmlRecord = new GenericXMLRecord(Arrays.copyOfRange(data, HEADER_LEN, data.length - 1));
            if (parsedPageReceiver != null) {
                Observable.just((T) xmlRecord).subscribe(parsedPageReceiver);
            } else {
                return (T) xmlRecord;
            }
            break;
        case SENSOR_DATA:
            rec_len = 20;
            SensorRecord[] sensorRecords = new SensorRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                sensorRecords[i] = new SensorRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            if (parsedPageReceiver != null) {
                Observable.just((T) sensorRecords).subscribe(parsedPageReceiver);
            } else {
                return (T) sensorRecords;
            }
            break;
        case EGV_DATA:
            rec_len = 13;
            EGVRecord[] egvRecords = new EGVRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                egvRecords[i] = new EGVRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            if (parsedPageReceiver != null) {
                Observable.just((T) egvRecords).subscribe(parsedPageReceiver);
            } else {
                return (T) egvRecords;
            }
            break;
        case METER_DATA:
            rec_len = 16;
            MeterRecord[] meterRecords = new MeterRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                meterRecords[i] = new MeterRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            if (parsedPageReceiver != null) {
                Observable.just((T) meterRecords).subscribe(parsedPageReceiver);
            } else {
                return (T) meterRecords;
            }
            break;
        case CAL_SET:
            rec_len = 249;
            if (pageHeader.getRevision() <= 2) {
                rec_len = 148;
            }
            CalRecord[] calRecords = new CalRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                calRecords[i] = new CalRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            if (parsedPageReceiver != null) {
                Observable.just((T) calRecords).subscribe(parsedPageReceiver);
            } else {
                return (T) calRecords;
            }
            break;
        default:
            break;
    }
    Observable.just((T) null).subscribe(parsedPageReceiver);
    return (T) null;
}
Also used : MeterRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.MeterRecord) PageHeader(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader) SensorRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord) CalRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord) GenericXMLRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.GenericXMLRecord) EGVRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord)

Example 2 with PageHeader

use of com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader in project xDrip by NightscoutFoundation.

the class ReadData method ParsePage.

private <T> T ParsePage(byte[] data, int recordType) {
    int HEADER_LEN = 28;
    PageHeader pageHeader = new PageHeader(data);
    int NUM_REC_OFFSET = 4;
    int numRec = data[NUM_REC_OFFSET];
    int rec_len;
    switch(Dex_Constants.RECORD_TYPES.values()[recordType]) {
        case MANUFACTURING_DATA:
            GenericXMLRecord xmlRecord = new GenericXMLRecord(Arrays.copyOfRange(data, HEADER_LEN, data.length - 1));
            return (T) xmlRecord;
        case SENSOR_DATA:
            rec_len = 20;
            SensorRecord[] sensorRecords = new SensorRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                sensorRecords[i] = new SensorRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            return (T) sensorRecords;
        case EGV_DATA:
            rec_len = 13;
            EGVRecord[] egvRecords = new EGVRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                egvRecords[i] = new EGVRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            return (T) egvRecords;
        case METER_DATA:
            rec_len = 16;
            MeterRecord[] meterRecords = new MeterRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                meterRecords[i] = new MeterRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            return (T) meterRecords;
        case CAL_SET:
            rec_len = 249;
            if (pageHeader.getRevision() <= 2) {
                rec_len = 148;
            }
            CalRecord[] calRecords = new CalRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                calRecords[i] = new CalRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            return (T) calRecords;
        default:
            // Throw error "Database record not supported"
            break;
    }
    return (T) null;
}
Also used : MeterRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.MeterRecord) PageHeader(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader) SensorRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord) CalRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord) GenericXMLRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.GenericXMLRecord) EGVRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord)

Example 3 with PageHeader

use of com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader in project xDrip-plus by jamorham.

the class ReadData method ParsePage.

private <T> T ParsePage(byte[] data, int recordType) {
    int HEADER_LEN = 28;
    PageHeader pageHeader = new PageHeader(data);
    int NUM_REC_OFFSET = 4;
    int numRec = data[NUM_REC_OFFSET];
    int rec_len;
    switch(Dex_Constants.RECORD_TYPES.values()[recordType]) {
        case MANUFACTURING_DATA:
            GenericXMLRecord xmlRecord = new GenericXMLRecord(Arrays.copyOfRange(data, HEADER_LEN, data.length - 1));
            return (T) xmlRecord;
        case SENSOR_DATA:
            rec_len = 20;
            SensorRecord[] sensorRecords = new SensorRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                sensorRecords[i] = new SensorRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            return (T) sensorRecords;
        case EGV_DATA:
            rec_len = 13;
            EGVRecord[] egvRecords = new EGVRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                egvRecords[i] = new EGVRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            return (T) egvRecords;
        case METER_DATA:
            rec_len = 16;
            MeterRecord[] meterRecords = new MeterRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                meterRecords[i] = new MeterRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            return (T) meterRecords;
        case CAL_SET:
            rec_len = 249;
            if (pageHeader.getRevision() <= 2) {
                rec_len = 148;
            }
            CalRecord[] calRecords = new CalRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                calRecords[i] = new CalRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            return (T) calRecords;
        default:
            // Throw error "Database record not supported"
            break;
    }
    return (T) null;
}
Also used : MeterRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.MeterRecord) PageHeader(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader) SensorRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord) CalRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord) GenericXMLRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.GenericXMLRecord) EGVRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord)

Example 4 with PageHeader

use of com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader in project xDrip-plus by jamorham.

the class ReadDataShare method ParsePage.

private <T> T ParsePage(byte[] data, int recordType, Action1<T> parsedPageReceiver) {
    int HEADER_LEN = 28;
    PageHeader pageHeader = new PageHeader(data);
    int NUM_REC_OFFSET = 4;
    int numRec = data[NUM_REC_OFFSET];
    int rec_len;
    switch(Constants.RECORD_TYPES.values()[recordType]) {
        case MANUFACTURING_DATA:
            GenericXMLRecord xmlRecord = new GenericXMLRecord(Arrays.copyOfRange(data, HEADER_LEN, data.length - 1));
            if (parsedPageReceiver != null) {
                Observable.just((T) xmlRecord).subscribe(parsedPageReceiver);
            } else {
                return (T) xmlRecord;
            }
            break;
        case SENSOR_DATA:
            rec_len = 20;
            SensorRecord[] sensorRecords = new SensorRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                sensorRecords[i] = new SensorRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            if (parsedPageReceiver != null) {
                Observable.just((T) sensorRecords).subscribe(parsedPageReceiver);
            } else {
                return (T) sensorRecords;
            }
            break;
        case EGV_DATA:
            rec_len = 13;
            EGVRecord[] egvRecords = new EGVRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                egvRecords[i] = new EGVRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            if (parsedPageReceiver != null) {
                Observable.just((T) egvRecords).subscribe(parsedPageReceiver);
            } else {
                return (T) egvRecords;
            }
            break;
        case METER_DATA:
            rec_len = 16;
            MeterRecord[] meterRecords = new MeterRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                meterRecords[i] = new MeterRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            if (parsedPageReceiver != null) {
                Observable.just((T) meterRecords).subscribe(parsedPageReceiver);
            } else {
                return (T) meterRecords;
            }
            break;
        case CAL_SET:
            rec_len = 249;
            if (pageHeader.getRevision() <= 2) {
                rec_len = 148;
            }
            CalRecord[] calRecords = new CalRecord[numRec];
            for (int i = 0; i < numRec; i++) {
                int startIdx = HEADER_LEN + rec_len * i;
                calRecords[i] = new CalRecord(Arrays.copyOfRange(data, startIdx, startIdx + rec_len - 1));
            }
            if (parsedPageReceiver != null) {
                Observable.just((T) calRecords).subscribe(parsedPageReceiver);
            } else {
                return (T) calRecords;
            }
            break;
        default:
            break;
    }
    Observable.just((T) null).subscribe(parsedPageReceiver);
    return (T) null;
}
Also used : MeterRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.MeterRecord) PageHeader(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader) SensorRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord) CalRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord) GenericXMLRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.GenericXMLRecord) EGVRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord)

Aggregations

CalRecord (com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord)4 EGVRecord (com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord)4 GenericXMLRecord (com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.GenericXMLRecord)4 MeterRecord (com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.MeterRecord)4 PageHeader (com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.PageHeader)4 SensorRecord (com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord)4