Search in sources :

Example 1 with PageHeader

use of com.nightscout.core.dexcom.records.PageHeader in project android-uploader by nightscout.

the class ReadData method parsePage.

private <T extends GenericTimestampRecord> List<T> parsePage(byte[] data, Class<T> clazz) {
    PageHeader pageHeader = new PageHeader(data);
    List<T> records = new ArrayList<>();
    try {
        for (int i = 0; i < pageHeader.getNumOfRecords(); i++) {
            int startIdx;
            switch(pageHeader.getRecordType()) {
                case EGV_DATA:
                    startIdx = PageHeader.HEADER_SIZE + (EGVRecord.RECORD_SIZE + 1) * i;
                    records.add(clazz.cast(new EGVRecord(Arrays.copyOfRange(data, startIdx, startIdx + EGVRecord.RECORD_SIZE))));
                    break;
                case CAL_SET:
                    int recordLength = (pageHeader.getRevision() <= 2) ? CalRecord.RECORD_SIZE : CalRecord.RECORD_V2_SIZE;
                    startIdx = PageHeader.HEADER_SIZE + (recordLength + 1) * i;
                    records.add(clazz.cast(new CalRecord(Arrays.copyOfRange(data, startIdx, startIdx + recordLength))));
                    break;
                case METER_DATA:
                    startIdx = PageHeader.HEADER_SIZE + (MeterRecord.RECORD_SIZE + 1) * i;
                    records.add(clazz.cast(new MeterRecord(Arrays.copyOfRange(data, startIdx, startIdx + MeterRecord.RECORD_SIZE))));
                    break;
                case SENSOR_DATA:
                    startIdx = PageHeader.HEADER_SIZE + (SensorRecord.RECORD_SIZE + 1) * i;
                    records.add(clazz.cast(new SensorRecord(Arrays.copyOfRange(data, startIdx, startIdx + SensorRecord.RECORD_SIZE))));
                    break;
                default:
                    throw new IllegalArgumentException(String.format("Unknown record type: %s", pageHeader.getRecordType().name()));
            }
        }
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    }
    return records;
}
Also used : MeterRecord(com.nightscout.core.dexcom.records.MeterRecord) PageHeader(com.nightscout.core.dexcom.records.PageHeader) ArrayList(java.util.ArrayList) CalRecord(com.nightscout.core.dexcom.records.CalRecord) SensorRecord(com.nightscout.core.dexcom.records.SensorRecord) EGVRecord(com.nightscout.core.dexcom.records.EGVRecord)

Example 2 with PageHeader

use of com.nightscout.core.dexcom.records.PageHeader in project android-uploader by nightscout.

the class PageHeaderTest method testPageHeaderParse.

@Test
public void testPageHeaderParse() throws Exception {
    PageHeader header = new PageHeader(pageHeader);
    assertThat(header.getFirstRecordIndex(), is(5130));
    assertThat(header.getNumOfRecords(), is(38));
    assertThat(header.getRecordType().ordinal(), is(4));
    assertThat(header.getRevision(), is((byte) 2));
    assertThat(header.getPageNumber(), is(135));
    assertThat(header.getReserved2(), is(0));
    assertThat(header.getReserved3(), is(0));
    assertThat(header.getReserved4(), is(0));
}
Also used : PageHeader(com.nightscout.core.dexcom.records.PageHeader) Test(org.junit.Test)

Aggregations

PageHeader (com.nightscout.core.dexcom.records.PageHeader)2 CalRecord (com.nightscout.core.dexcom.records.CalRecord)1 EGVRecord (com.nightscout.core.dexcom.records.EGVRecord)1 MeterRecord (com.nightscout.core.dexcom.records.MeterRecord)1 SensorRecord (com.nightscout.core.dexcom.records.SensorRecord)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1