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;
}
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));
}
Aggregations