Пример #1
0
  public void GET(Event event) {
    try {
      HANDLE handle = (HANDLE) getAttribute(Nomenclature.MDC_ATTR_ID_HANDLE).getAttributeType();
      DataApdu data = MessageFactory.PrstRoivCmpGet(getMDS(), handle);
      ApduType apdu = MessageFactory.composeApdu(data, getMDS().getDeviceConf());
      InvokeIDType invokeId = data.getInvoke_id();
      getMDS().getStateHandler().send(apdu);

      DimTimeOut to =
          new DimTimeOut(TimeOut.PM_STORE_TO_GET, invokeId.getValue(), getMDS().getStateHandler()) {

            @SuppressWarnings("unchecked")
            @Override
            public void procResponse(DataApdu data) {
              Logging.debug("GOT_PMSOTRE invoke_id " + data.getInvoke_id().getValue().intValue());
              ExternalEvent<Boolean, GetPmStoreEventData> event = null;
              try {
                event = (ExternalEvent<Boolean, GetPmStoreEventData>) this.getEvent();
              } catch (ClassCastException e) {

              }

              if (!data.getMessage().isRors_cmip_getSelected()) {
                Logging.debug("TODO: Unexpected response format");
                if (event != null) event.processed(false, ErrorCodes.UNEXPECTED_ERROR);
                return;
              }

              GetResultSimple grs = data.getMessage().getRors_cmip_get();
              HANDLE handle =
                  (HANDLE) getAttribute(Nomenclature.MDC_ATTR_ID_HANDLE).getAttributeType();
              if (handle == null) {
                Logging.debug("Error: Can't get HANDLE attribute in PM_STORE object");
                if (event != null) event.processed(false, ErrorCodes.UNEXPECTED_ERROR);
                return;
              }

              if (grs.getObj_handle().getValue().getValue().intValue()
                  != handle.getValue().getValue().intValue()) {
                Logging.debug(
                    "TODO: Unexpected object handle, should be value "
                        + handle.getValue().getValue().intValue());
                if (event != null) event.processed(false, ErrorCodes.UNEXPECTED_ERROR);
                return;
              }

              try {
                Hashtable<Integer, Attribute> attribs;
                attribs =
                    getAttributes(
                        grs.getAttribute_list(), getMDS().getDeviceConf().getEncondigRules());
                Iterator<Integer> i = attribs.keySet().iterator();
                while (i.hasNext()) {
                  Attribute attr = attribs.get(i.next());
                  if (getAttribute(attr.getAttributeID()) != null) {
                    addAttribute(attr);
                  }
                }
              } catch (Exception e) {
                e.printStackTrace();
              }

              if (event != null) event.processed(true, ErrorCodes.NO_ERROR);
            }
          };

      to.setEvent(event);
      to.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }