コード例 #1
0
ファイル: MPM_Store.java プロジェクト: WD3/BluetoothHDP
  private SegmentDataResult createSegmentDataResult(byte[] val, SegmentDataEvent sde) {
    SegmentDataResult sdr = new SegmentDataResult();
    SegmDataEventDescr sded = new SegmDataEventDescr();
    SegmEvtStatus ses = new SegmEvtStatus();
    BitString bs = new BitString();

    sded.setSegm_instance(sde.getSegm_data_event_descr().getSegm_instance());
    sded.setSegm_evt_entry_index(sde.getSegm_data_event_descr().getSegm_evt_entry_index());
    sded.setSegm_evt_entry_count(sde.getSegm_data_event_descr().getSegm_evt_entry_count());

    bs.setValue(val);
    ses.setValue(bs);
    sded.setSegm_evt_status(ses);
    sdr.setSegm_data_event_descr(sded);

    return sdr;
  }
コード例 #2
0
ファイル: MPM_Store.java プロジェクト: WD3/BluetoothHDP
  @Override
  public SegmentDataResult Segment_Data_Event(SegmentDataEvent sde) {
    SegmDataEventDescr sded = sde.getSegm_data_event_descr();
    byte[] status = new byte[2];
    byte mask = 0;

    mask |= ASN1_Values.SEVTSTA_FIRST_ENTRY | ASN1_Values.SEVTSTA_LAST_ENTRY;
    status[0] =
        (byte)
            (mask | sde.getSegm_data_event_descr().getSegm_evt_status().getValue().getValue()[0]);
    status[1] = 0;

    // Logging.debug("Segment Number: " + sded.getSegm_instance().getValue().intValue());

    MPM_Segment pmseg = (MPM_Segment) getPM_Segment(sded.getSegm_instance());
    if (pmseg == null) {
      Logging.error("Error: Can't get PM_Segment " + sded.getSegm_instance().getValue());
      /* TODO :Send error reply */
      return null;
    }

    Attribute attr = pmseg.getAttribute(Nomenclature.MDC_ATTR_PM_SEG_MAP);
    if (attr == null) {
      Logging.error(
          "Error: Attribute "
              + DIM_Tools.getAttributeName(Nomenclature.MDC_ATTR_PM_SEG_MAP)
              + " not defined");
      status[1] = 0 | ASN1_Values.SEVTSTA_MANAGER_ABORT;
      return createSegmentDataResult(status, sde);
    }

    int first = sded.getSegm_evt_entry_index().getValue().intValue();
    int count = sded.getSegm_evt_entry_count().getValue().intValue();
    // Logging.debug("Count of entries in this event: " + count);
    // Logging.debug("Index of the first entry in this event: " + first);

    try {
      SegmEvtStatus ses = sded.getSegm_evt_status();
      String bitstring = ASN1_Tools.getHexString(ses.getValue().getValue());
      // Logging.debug("Segment event status: " + bitstring);

      PmSegmentEntryMap psem = (PmSegmentEntryMap) attr.getAttributeType();

      int bytes = 0x000000FF & psem.getSegm_entry_header().getValue().getValue()[0];
      bytes = (bytes << 8) | psem.getSegm_entry_header().getValue().getValue()[1];
      boolean hasEntries = (bytes != 0);
      int attrId = 0;
      int len = 0;

      if (hasEntries) {
        if ((bytes & ASN1_Values.SEG_ELEM_HDR_ABSOLUTE_TIME) != 0) {
          attrId = Nomenclature.MDC_ATTR_TIME_ABS;
          len = 8; /* AbsoluteTime */
        } else if ((bytes & ASN1_Values.SEG_ELEM_HDR_RELATIVE_TIME) != 0) {
          attrId = Nomenclature.MDC_ATTR_TIME_REL;
          len = 4; /* INT-U32 */
        } else if ((bytes & ASN1_Values.SEG_ELEM_HDR_HIRES_RELATIVE_TIME) != 0) {
          attrId = Nomenclature.MDC_ATTR_TIME_REL_HI_RES;
          len = 8; /* HighResRelativeTime */
        } else {
          Logging.error("Bad entry value: " + bytes);
          status[1] = 0 | ASN1_Values.SEVTSTA_MANAGER_ABORT;
          return createSegmentDataResult(status, sde);
        }
      }

      String eRules = getMDS().getDeviceConf().getEncondigRules();
      RawDataExtractor rde = new RawDataExtractor(sde.getSegm_data_event_entries());
      int j = 0;

      /* Get raw data */
      while (rde.hasMoreData() && (j < count)) {
        SegmEntryElemList seel = psem.getSegm_entry_elem_list();
        Iterator<SegmEntryElem> i = seel.getValue().iterator();
        j++;

        if (hasEntries) {
          RawDataExtractor.decodeRawData(attrId, rde.getData(len), eRules);
        }

        while (i.hasNext()) {
          SegmEntryElem see = i.next();
          OID_Type oid = see.getClass_id();
          TYPE type = see.getMetric_type();
          HANDLE handle = see.getHandle();

          if (type.getCode().getValue().getValue().intValue()
              == Nomenclature.MDC_CONC_GLU_CAPILLARY_WHOLEBLOOD)
            Logging.debug("*Glucose Capillary Whole Blood*");

          /* We can check also type.Nompartition to see if it is set to 2 for metric */
          if (oid.getValue().getValue().intValue() != Nomenclature.MDC_MOC_VMO_METRIC_NU) {
            Logging.error("Error: No metric object received.");
            status[1] = 0 | ASN1_Values.SEVTSTA_MANAGER_ABORT;
            return createSegmentDataResult(status, sde);
          }

          Numeric num = getMDS().getNumeric(handle);
          if (num == null) {
            Logging.error("Error: Invalid numeric received.");
            status[1] = 0 | ASN1_Values.SEVTSTA_MANAGER_ABORT;
            return createSegmentDataResult(status, sde);
          }

          OID_Type unitCode =
              (OID_Type) num.getAttribute(Nomenclature.MDC_ATTR_UNIT_CODE).getAttributeType();
          if (unitCode == null) {
            Logging.error("Can't get unit code");
          } else {
            switch (unitCode.getValue().getValue().intValue()) {
              case Nomenclature.MDC_DIM_MILLI_G_PER_DL:
                Logging.debug("Units: mg/dl");
                break;
              case Nomenclature.MDC_DIM_MILLI_MOLE_PER_L:
                Logging.debug("Units: mmol/L");
                break;
              default:
                Logging.error(
                    "Unknown unit code for the measure "
                        + unitCode.getValue().getValue().intValue());
            }
          }

          AttrValMap avmnum =
              (AttrValMap)
                  num.getAttribute(Nomenclature.MDC_ATTR_ATTRIBUTE_VAL_MAP).getAttributeType();
          Iterator<AttrValMapEntry> ii = avmnum.getValue().iterator();
          while (ii.hasNext()) {
            AttrValMapEntry avme = ii.next();
            int id = avme.getAttribute_id().getValue().getValue().intValue();
            int length = avme.getAttribute_len().intValue();
            RawDataExtractor.decodeRawData(id, rde.getData(length), eRules);
          }
        }
      }

      status[1] = 0 | ASN1_Values.SEVTSTA_MANAGER_CONFIRM;

    } catch (Exception e) {
      e.printStackTrace();
    }

    return createSegmentDataResult(status, sde);
  }