Ejemplo n.º 1
0
  private void processSegmentDataEvent(InvokeIDType id, EventReportArgumentSimple event) {
    PM_Store pmstore = this.state_handler.getMDS().getPM_Store(event.getObj_handle());
    if (pmstore == null) return;

    RelativeTime rt = event.getEvent_time();
    Logging.debug("Relative Time: " + rt.getValue().getValue().intValue());

    try {
      SegmentDataEvent sde =
          ASN1_Tools.decodeData(
              event.getEvent_info(),
              SegmentDataEvent.class,
              this.state_handler.getMDS().getDeviceConf().getEncondigRules());
      SegmentDataResult sdr = pmstore.Segment_Data_Event(sde);

      EventReportResultSimple errs =
          MessageFactory.genEventReportResultSimple(
              event, sdr, state_handler.getMDS().getDeviceConf().getEncondigRules());
      DataApdu data = new DataApdu();
      MessageChoiceType mct = new MessageChoiceType();
      mct.selectRors_cmip_confirmed_event_report(errs);
      data.setInvoke_id(id);
      data.setMessage(mct);

      state_handler.send(MessageFactory.composeApdu(data, state_handler.getMDS().getDeviceConf()));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
 private void mdc_noti_scan_report_MP_var(byte[] einfo) {
   try {
     ScanReportInfoMPVar srimpv =
         ASN1_Tools.decodeData(
             einfo,
             ScanReportInfoMPVar.class,
             this.state_handler.getMDS().getDeviceConf().getEncondigRules());
     this.state_handler.getMDS().MDS_Dynamic_Data_Update_MP_Var(srimpv);
   } catch (Exception e) {
     Logging.debug("Error decoding mdc_noti_scan_report_var");
     e.printStackTrace();
   }
 }
Ejemplo n.º 3
0
 private void process_20601_PrstApdu(PrstApdu prst) {
   try {
     /*
      * The DataApdu and the related structures in A.10 shall use encoding rules
      * as negotiated during the association procedure as described in 8.7.3.1.
      */
     processDataApdu(
         ASN1_Tools.decodeData(
             prst.getValue(),
             DataApdu.class,
             this.state_handler.getMDS().getDeviceConf().getEncondigRules()));
   } catch (Exception e) {
     e.printStackTrace();
     Logging.error(
         "Error getting DataApdu encoded with "
             + this.state_handler.getMDS().getDeviceConf().getEncondigRules()
             + ". The connection will be released.");
     state_handler.send(MessageFactory.RlrqApdu_NORMAL());
     state_handler.changeState(new MDisassociating(state_handler));
   }
 }
Ejemplo n.º 4
0
  @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);
  }
Ejemplo n.º 5
0
  @SuppressWarnings("unchecked")
  @Override
  public synchronized boolean processEvent(Event event) {
    switch (event.getTypeOfEvent()) {
      case EventType.REQ_GET_PM_STORE:
        ExternalEvent<Boolean, GetPmStoreEventData> pmEvent =
            (ExternalEvent<Boolean, GetPmStoreEventData>) event;
        PM_Store pm_store =
            this.state_handler.getMDS().getPM_Store(pmEvent.getPrivData().getHandle());
        pm_store.GET(pmEvent);
        return true;

      case EventType.REQ_SET:
        ExternalEvent<Boolean, SetEventData> setEvent =
            (ExternalEvent<Boolean, SetEventData>) event;
        DIM obj = state_handler.getMDS().getObject(setEvent.getPrivData().getObjectHandle());
        try {
          SET_Service serv = (SET_Service) obj;
          serv.SET(setEvent, setEvent.getPrivData().getAttribute());
        } catch (ClassCastException e) {
          Logging.error(
              "Set cannot be done in object: "
                  + setEvent.getPrivData().getObjectHandle().getValue().getValue()
                  + " it does not implement a SET service");
        }
        return true;

      case EventType.REQ_MDS:
        state_handler.getMDS().GET(event);
        return true;

      case EventType.REQ_GET_SEGMENT_INFO:
        ExternalEvent<List<PM_Segment>, GetPmSegmentEventData> pmSegEvent =
            (ExternalEvent<List<PM_Segment>, GetPmSegmentEventData>) event;
        PM_Store store =
            this.state_handler.getMDS().getPM_Store(pmSegEvent.getPrivData().getHandle());
        store.Get_Segment_Info(pmSegEvent, pmSegEvent.getPrivData().getSegmSelection());
        return true;

      case EventType.REQ_TRIG_SEGMENT_DATA_XFER:
        ExternalEvent<Boolean, TrigPMSegmentXferEventData> xferEvent =
            (ExternalEvent<Boolean, TrigPMSegmentXferEventData>) event;
        PM_Store s =
            this.state_handler.getMDS().getPM_Store(xferEvent.getPrivData().getStoreHandle());

        TrigSegmDataXferReq tsdxr = new TrigSegmDataXferReq();
        tsdxr.setSeg_inst_no(xferEvent.getPrivData().getInsNumber());
        s.Trig_Segment_Data_Xfer(xferEvent, tsdxr);
        return true;

      case EventType.REQ_SET_TIME:
        state_handler.getMDS().Set_Time(event);
        return true;

      case EventType.IND_TRANS_DESC:
        Logging.error("2.2) IND Transport disconnect. Should indicate to application layer...");
        state_handler.changeState(new MDisconnected(state_handler));
        return true;

      case EventType.IND_TIMEOUT:
        state_handler.send(MessageFactory.AbrtApdu(event.getReason()));
        state_handler.changeState(new MUnassociated(state_handler));
        return true;

      case EventType.REQ_ASSOC_REL:
        state_handler.send(MessageFactory.RlrqApdu_NORMAL());
        state_handler.changeState(new MDisassociating(state_handler));
        try {
          ExternalEvent<Boolean, Object> eevent = (ExternalEvent<Boolean, Object>) event;
          eevent.processed(true, ErrorCodes.NO_ERROR);
        } catch (ClassCastException e) {

        }
        return true;

      case EventType.REQ_ASSOC_ABORT:
        state_handler.send(MessageFactory.AbrtApdu_UNDEFINED());
        state_handler.changeState(new MUnassociated(state_handler));
        return true;

      case EventType.REC_CORRUPTED_APDU:
        state_handler.send(MessageFactory.AbrtApdu_UNDEFINED());
        state_handler.changeState(new MUnassociated(state_handler));
        return true;

      case EventType.REC_APDU_OVERFLOW:
        EventAPDUOverflow eao = (EventAPDUOverflow) event;

        if (!eao.getApduType().isPrstSelected()) {
          Logging.error("APDU exceeded maximum length is non PrstApdu");
          state_handler.send(MessageFactory.AbrtApdu_UNDEFINED());
          state_handler.changeState(new MUnassociated(state_handler));
        }

        try {
          DataApdu data =
              ASN1_Tools.decodeData(
                  eao.getApduType().getPrst().getValue(),
                  DataApdu.class,
                  this.state_handler.getMDS().getDeviceConf().getEncondigRules());
          state_handler.send(
              MessageFactory.ROER_PROTOCOL_VIOLATION_Apdu(
                  data, state_handler.getMDS().getDeviceConf()));
        } catch (Exception e) {
          e.printStackTrace();
          state_handler.send(MessageFactory.AbrtApdu_UNDEFINED());
          state_handler.changeState(new MUnassociated(state_handler));
        }

        return true;
      case EventType.NOTI_MEASURE:
        System.out.println("sending measure");
        state_handler.send(generateMeasureApdu());
        return true;

      default:
        return false;
    }
  }