/* * Ecg */ public static FeMessage createEcg(Ecg ecg, int idx) { byte body[] = new byte[2 + 50]; System.arraycopy(MessageUtils.shortToBytes(idx), 0, body, 0, 2); int data[] = ecg.getData(); for (int m = 0; m < data.length; m++) { System.arraycopy(MessageUtils.shortToBytes(data[m]), 0, body, 2 + 2 * m, 2); } return new FeMessage(TYPE_STREAM_ECG_1, body); }
public Ecg extractEcg(User user) { int stamp; int data[]; if (type == FeMessage.TYPE_STREAM_ECG_1 || type == FeMessage.TYPE_STREAM_ECG_3 || type == FeMessage.TYPE_STREAM_ECG_12 || type == FeMessage.TYPE_STREAM_ECG_2) { stamp = MessageUtils.bytesToUnsignedShort(body, 0); if (user.getConnectedDevice().getModel() == Device.MODEL_20_3_HI) { // For 24 bit high resolution data = new int[(body.length - 2) / 3]; for (int m = 0; m < data.length; m++) { data[m] = MessageUtils.bytesToDemiInt(body, 2 + 3 * m); } } else if (user.getConnectedDevice().getModel() == Device.MODEL_20_3 || user.getConnectedDevice().getModel() == Device.MODEL_20_1) { // For 16 bit regular resolution data = new int[(body.length - 2) / 2]; for (int m = 0; m < data.length; m++) { data[m] = MessageUtils.bytesToShort(body, 2 + 2 * m); } /* * debug code */ // data = new int[(body.length-2)/2]; // for (int m = 0; m < data.length/3; m +=3) { // int dval = MessageUtils.bytesToShort(body,2+2*m); // data[m] = user.getLastEcgVal()[0] + dval; // dval = MessageUtils.bytesToShort(body,2+2*(m+1)); // data[m+1] = user.getLastEcgVal()[1] + dval; // dval = MessageUtils.bytesToShort(body,2+2*(m+2)); // data[m+2] = user.getLastEcgVal()[2] + dval; // // L.i("<TEST> dval = " + Integer.toString(dval)); // user.setLastEcgVal(data[m], data[m+1], data[m+2]); // } } else if (user.getConnectedDevice().getModel() == Device.MODEL_20_2_HI) { // For 24 bit regular resolution data = new int[(body.length - 2) / 2]; for (int m = 0; m < data.length / 3; m++) { data[3 * m] = MessageUtils.bytesToDemiInt(body, 2 + 3 * (2 * m)); data[3 * m + 1] = MessageUtils.bytesToDemiInt(body, 2 + 3 * (2 * m + 1)); data[3 * m + 2] = data[3 * m + 1] - data[3 * m]; } } else { return null; } int ecgType; if (type == FeMessage.TYPE_STREAM_ECG_1) { ecgType = Ecg.TYPE_SINGLE; } else if (type == FeMessage.TYPE_STREAM_ECG_3) { ecgType = Ecg.TYPE_THREE; } else if (type == FeMessage.TYPE_STREAM_ECG_12) { ecgType = Ecg.TYPE_FULL; } else if (type == FeMessage.TYPE_STREAM_ECG_2) { ecgType = Ecg.TYPE_THREE; } else { ecgType = Ecg.TYPE_SINGLE; } // L.i("<FECODER> ecg type = " + Integer.toString(ecgType)); Ecg ecg = new Ecg(ecgType, -1, -1, -1, data); int stampPrev = user.getStampStreamPrev(); long timePrev = user.getTimeStreamPrev(); Device dev = user.getConnectedDevice(); int sps = dev.getSps(); int streamLen = dev.getStreamLen(); long timediff = streamLen * 1000 / sps; int stampDiff = stampPrev < stamp ? stamp - stampPrev : 65535 - stampPrev + stamp; long timeNow = timePrev + stampDiff * timediff; user.setTimeStreamPrev(timeNow); user.setStampStreamPrev(stamp); ecg.setSps(sps); ecg.setStartTime(timeNow); ecg.setStopTime(timeNow + timediff); // L.i("<DATA> sps = " + Integer.toString(sps) + " startT = " + // Long.toString(timeNow) + " stopT = " + Long.toString(timeNow + timediff)); return ecg; } else { return null; } }