示例#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();
    }
  }
示例#2
0
 private ApduType generateMeasureApdu() {
   Agent a = (Agent) state_handler.getMDS().getDevice();
   Specialization spec = a.getSpecialization();
   Collection<Map<HANDLE, Object>> measures = spec.getMeasures();
   ScanReportInfoMPFixed info = generateScanReportInfo(measures);
   HANDLE handle = new HANDLE();
   handle.setValue(new INT_U16(0));
   OID_Type eventtype = new OID_Type();
   eventtype.setValue(new INT_U16(Nomenclature.MDC_NOTI_SCAN_REPORT_MP_FIXED));
   DataApdu data =
       MessageFactory.PrstRoivCmpConfirmedEventReport(
           state_handler.getMDS(), info, handle, eventtype);
   return MessageFactory.composeApdu(data, state_handler.getMDS().getDeviceConf());
 }
示例#3
0
 @Override
 public synchronized void process(ApduType apdu) {
   if (apdu.isPrstSelected()) {
     process.processPrstApdu(apdu.getPrst());
   } else if (apdu.isRlrqSelected()) {
     state_handler.send(MessageFactory.RlreApdu_NORMAL());
     state_handler.changeState(new MUnassociated(state_handler));
   } else if (apdu.isAarqSelected() || apdu.isAareSelected() || apdu.isRlreSelected()) {
     state_handler.send(MessageFactory.AbrtApdu_UNDEFINED());
     state_handler.changeState(new MUnassociated(state_handler));
   } else if (apdu.isAbrtSelected()) {
     state_handler.changeState(new MUnassociated(state_handler));
   }
 }
示例#4
0
 private void process_event_report(DataApdu data, EventReportArgumentSimple event) {
   // (A.10.3 EVENT REPORT service)
   if (event.getObj_handle().getValue().getValue().intValue() == 0) {
     // obj-handle is 0 to represent the MDS
     process_MDS_Object_Event(event);
     this.state_handler.send(MessageFactory.PrstTypeResponse(data, state_handler.getMDS()));
   } else {
     switch (event.getEvent_type().getValue().getValue().intValue()) {
         // Episodic configurable scanner object events:
       case Nomenclature.MDC_NOTI_UNBUF_SCAN_REPORT_VAR:
       case Nomenclature.MDC_NOTI_UNBUF_SCAN_REPORT_FIXED:
       case Nomenclature.MDC_NOTI_UNBUF_SCAN_REPORT_GROUPED:
       case Nomenclature.MDC_NOTI_UNBUF_SCAN_REPORT_MP_VAR:
       case Nomenclature.MDC_NOTI_UNBUF_SCAN_REPORT_MP_FIXED:
       case Nomenclature.MDC_NOTI_UNBUF_SCAN_REPORT_MP_GROUPED:
         processUnbufScannerEvent(event);
         this.state_handler.send(MessageFactory.PrstTypeResponse(data, state_handler.getMDS()));
         break;
         // Periodic configurable scanner object events:
       case Nomenclature.MDC_NOTI_BUF_SCAN_REPORT_VAR:
       case Nomenclature.MDC_NOTI_BUF_SCAN_REPORT_FIXED:
       case Nomenclature.MDC_NOTI_BUF_SCAN_REPORT_GROUPED:
       case Nomenclature.MDC_NOTI_BUF_SCAN_REPORT_MP_VAR:
       case Nomenclature.MDC_NOTI_BUF_SCAN_REPORT_MP_FIXED:
       case Nomenclature.MDC_NOTI_BUF_SCAN_REPORT_MP_GROUPED:
         processBufScannerEvent(event);
         this.state_handler.send(MessageFactory.PrstTypeResponse(data, state_handler.getMDS()));
         break;
       default:
         // TODO: handle representing a scanner or PM-store object.
         Logging.error(
             "Warning: Received Handle="
                 + event.getObj_handle().getValue().getValue()
                 + " in Operating state. Ignore.");
     }
   }
 }
示例#5
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));
   }
 }
示例#6
0
  @Override
  public void Get_Segment_Info(
      ExternalEvent<List<PM_Segment>, GetPmSegmentEventData> event, SegmSelection ss) {
    try {
      DataApdu data = MessageFactory.PrstRoivCmipAction(this, ss);
      ApduType apdu = MessageFactory.composeApdu(data, getMDS().getDeviceConf());
      InvokeIDType invokeId = data.getInvoke_id();
      getMDS().getStateHandler().send(apdu);

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

            @SuppressWarnings("unchecked")
            @Override
            public void procResponse(DataApdu data) {

              ExternalEvent<List<PM_Segment>, GetPmSegmentEventData> event =
                  (ExternalEvent<List<PM_Segment>, GetPmSegmentEventData>) getEvent();

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

              ActionResultSimple ars = data.getMessage().getRors_cmip_confirmed_action();
              OID_Type oid = ars.getAction_type();
              if (Nomenclature.MDC_ACT_SEG_GET_INFO != oid.getValue().getValue().intValue()) {
                Logging.debug("Error: Unexpected response format");
                event.processed(null, ErrorCodes.UNEXPECTED_ERROR);
                return;
              }

              try {
                SegmentInfoList sil =
                    ASN1_Tools.decodeData(
                        ars.getAction_info_args(),
                        SegmentInfoList.class,
                        getMDS().getDeviceConf().getEncondigRules());
                Iterator<SegmentInfo> i = sil.getValue().iterator();
                while (i.hasNext()) {
                  SegmentInfo si = i.next();
                  InstNumber in = si.getSeg_inst_no();
                  AttributeList al = si.getSeg_info();

                  Hashtable<Integer, Attribute> attribs;
                  attribs = getAttributes(al, getMDS().getDeviceConf().getEncondigRules());
                  MPM_Segment pm_segment = new MPM_Segment(attribs);
                  addPM_Segment(pm_segment);
                  Logging.debug("Got PM_Segment " + in.getValue().intValue());
                }

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

              List<PM_Segment> segments = new ArrayList<PM_Segment>(MPM_Store.this.getSegments());
              event.processed(segments, ErrorCodes.NO_ERROR);
            }
          };

      to.setEvent(event);
      to.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#7
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();
    }
  }
示例#8
0
  @Override
  public void Trig_Segment_Data_Xfer(
      ExternalEvent<Boolean, TrigPMSegmentXferEventData> event, TrigSegmDataXferReq tsdx) {
    DataApdu data = MessageFactory.PrstRoivCmipConfirmedAction(this, tsdx);
    ApduType apdu = MessageFactory.composeApdu(data, getMDS().getDeviceConf());
    InvokeIDType invokeId = data.getInvoke_id();
    getMDS().getStateHandler().send(apdu);

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

          @SuppressWarnings("unchecked")
          @Override
          public void procResponse(DataApdu data) {

            ExternalEvent<Boolean, TrigPMSegmentXferEventData> event =
                (ExternalEvent<Boolean, TrigPMSegmentXferEventData>) getEvent();

            if (!data.getMessage().isRors_cmip_confirmed_actionSelected()) {
              Logging.error("Error: Unexpected response format");
              event.processed(false, ErrorCodes.UNEXPECTED_ERROR);
              return;
            }

            ActionResultSimple ars = data.getMessage().getRors_cmip_confirmed_action();
            OID_Type oid = ars.getAction_type();
            if (Nomenclature.MDC_ACT_SEG_TRIG_XFER != oid.getValue().getValue().intValue()) {
              Logging.error("Error: Unexpected response format");
              event.processed(false, ErrorCodes.UNEXPECTED_ERROR);
              return;
            }

            try {
              TrigSegmDataXferRsp rsp =
                  ASN1_Tools.decodeData(
                      ars.getAction_info_args(),
                      TrigSegmDataXferRsp.class,
                      getMDS().getDeviceConf().getEncondigRules());
              InstNumber in = rsp.getSeg_inst_no();
              TrigSegmXferRsp tsxr = rsp.getTrig_segm_xfer_rsp();
              int result = tsxr.getValue().intValue();
              if (result == 0) {
                event.processed(true, ErrorCodes.NO_ERROR);
                return;
              }

              // TODO: Create and set proper error using "result" variable
              event.processed(false, ErrorCodes.UNEXPECTED_ERROR);
              Logging.error("InstNumber " + in.getValue().intValue() + " error " + result);

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

    // TODO: Add a timeout for data transfer (see 8.9.5.6 and MDC_ATTR_TRANSFER_TIMEOUT att from
    // PMSegment)

    to.setEvent(event);
    to.start();
  }
示例#9
0
 private void roiv_cmip_get(DataApdu data) {
   state_handler.send(MessageFactory.PrstTypeResponse(data, state_handler.getMDS()));
 }
示例#10
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;
    }
  }