Exemplo n.º 1
0
  private void sendGetRequest() {
    try {
      pdu = new BlockPdu(context);
      pdu.setPduType(BlockPdu.GET);
      pdu.addOid(ifNumber);
      AsnObject res = pdu.getResponseVariable();

      if (res != null) {
        int ifCount = ((AsnInteger) res).getValue();
        System.out.println("ifCount " + ifCount);

        pdu = new BlockPdu(context);
        pdu.setPduType(BlockPdu.GETNEXT);
        for (int no = 0; no < ifCount; no++) {
          for (int i = 1; i <= noIfEntry; i++) {
            String oid = ifEntry + "." + i + "." + no;
            pdu.addOid(oid);
          }
        }
        sendRequest(pdu);
      } else {
        System.out.println("Received no answer");
      }
    } catch (Exception exc) {
      exc.printStackTrace();
    }
  }
Exemplo n.º 2
0
 private void sendRequest(BlockPdu pdu) {
   setButton.setEnabled(false);
   getButton.setEnabled(false);
   getNextButton.setEnabled(false);
   lmessage.setText("Sending request ..");
   lmessage.setBackground(Color.white);
   try {
     varbind var = pdu.getResponseVariableBinding();
     AsnObjectId oid = var.getOid();
     AsnObject res = var.getValue();
     if (res != null) {
       toid.setText(oid.toString());
       tvalue.setText(res.toString());
       lmessage.setText("Received aswer ");
       lmessage.setBackground(Color.white);
     } else {
       lmessage.setText("Received no aswer ");
       lmessage.setBackground(Color.red);
     }
   } catch (PduException exc) {
     lmessage.setText("PduException: " + exc.getMessage());
     lmessage.setBackground(Color.red);
     exc.printStackTrace();
   } catch (java.io.IOException exc) {
     lmessage.setText("IOException: " + exc.getMessage());
     lmessage.setBackground(Color.red);
     exc.printStackTrace();
   }
   setButton.setEnabled(true);
   getButton.setEnabled(true);
   getNextButton.setEnabled(true);
 }
Exemplo n.º 3
0
  public void actionPerformed(ActionEvent evt) {
    Object src = evt.getSource();

    try {
      if (src == propDialog) {
        propDialog_actionPerformed(evt);
      } else {
        pdu = new BlockPdu(context);
        if (src == setButton) {
          pdu.setPduType(BlockPdu.SET);
          pdu.addOid(toid.getText(), new AsnOctets(tvalue.getText()));
        } else if (src == getButton) {
          pdu.setPduType(BlockPdu.GET);
          pdu.addOid(toid.getText());
        } else if (src == getNextButton) {
          pdu.setPduType(BlockPdu.GETNEXT);
          pdu.addOid(toid.getText());
        }
        sendRequest(pdu);
      }
    } catch (Exception exc) {
      exc.printStackTrace();
      lmessage.setText("Exception: " + exc.getMessage());
      lmessage.setBackground(Color.red);
    }
  }
Exemplo n.º 4
0
 private void sendRequest(BlockPdu pdu) throws PduException, IOException {
   varbind[] var = pdu.getResponseVariableBindings();
   if (var != null) {
     int sz = var.length;
     System.out.println("Received answer " + sz);
     for (int i = 0; i < sz; i++) {
       AsnObjectId oid = var[i].getOid();
       AsnObject res = var[i].getValue();
       System.out.println(oid.toString() + ": " + res.toString());
     }
   } else {
     System.out.println("Received no answer");
   }
 }
Exemplo n.º 5
0
 private void sendGetRequest(String oid) {
   pdu = new BlockPdu(context);
   pdu.setPduType(BlockPdu.GET);
   pdu.addOid(oid);
   sendRequest(pdu);
 }