Ejemplo n.º 1
0
  /**
   * Read the search parameter, if it matches "Search 50" then we've "got" data. Let the Loop Actor
   * know it can stop searching
   */
  public void fire() throws IllegalActionException {
    super.fire();

    if (search.getWidth() > 0 && search.hasToken(0)) {
      String searchStr = ((StringToken) search.get(0)).stringValue();
      if (searchStr.equals("Search 50")) {
        System.out.println("Found DATA!");
        resultsOutput.broadcast(new StringToken("Results Found"));

      } else {
        System.out.println("Didn't Match! " + searchStr);
        resultsOutput.broadcast(new StringToken("No Data"));
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Walks through the DDS, converts DAP data to ptII data, and broadcasts the data onto the
   * appropriate ports.
   *
   * @param dds The DDS from which to get the data to send
   * @throws IllegalActionException When bad things happen.
   */
  private void broadcastDapData(DDS dds) throws IllegalActionException {

    // log.debug("broadcastDapData(): DataDDS prior to broadcast:");
    // dds.print(System.out);

    Enumeration e = dds.getVariables();
    while (e.hasMoreElements()) {
      opendap.dap.BaseType bt = (opendap.dap.BaseType) e.nextElement();

      String columnName = bt.getLongName().trim();
      // Get the port associated with this DDS variable.
      TypedIOPort port = (TypedIOPort) this.getPort(columnName);
      if (port == null) {
        throw new IllegalActionException("Request Output Port Missing: " + columnName);
      }

      log.debug("Translating data.");
      // bt.printDecl(System.out);

      // Map the DAP data for this variable into the ptII Token model.
      ptolemy.data.Token token = TokenMapper.mapDapObjectToToken(bt, false);
      log.debug("Data Translated :");
      // bt.printDecl(System.out);

      // Send the data.
      log.debug("Sending data.");
      port.broadcast(token);
      log.debug("Sent data.");
    }
  }
Ejemplo n.º 3
0
  /**
   * Does up to three things, in this order: Set new remote address value, Set new remote socket
   * number, transmit data as a UDP packet over the ethernet. The first two can, of course, affect
   * where the datagram goes. Any remote address/socket values supplied are saved and become the
   * defaults for next time.
   */
  public void fire() throws IllegalActionException {
    super.fire();
    String address = null;

    for (int jj = 0; jj < remoteAddress.getWidth(); jj++) {
      if (remoteAddress.hasToken(jj)) {
        address = ((StringToken) (remoteAddress.get(jj))).stringValue();
      }
    }

    if (address != null) {
      try {
        _address = InetAddress.getByName(address);
      } catch (UnknownHostException ex) {
        throw new IllegalActionException(
            this, ex, "The input remote " + "address specifies an unknown host");
      }
    }

    for (int jj = 0; jj < remoteSocketNumber.getWidth(); jj++) {
      if (remoteSocketNumber.hasToken(jj)) {
        // Valid socket numbers are 0..65535,
        // so keep only lower 16 bits.
        _remoteSocketNumber = 65535 & ((IntToken) remoteSocketNumber.get(jj)).intValue();
      }
    }

    if (data.hasToken(0)) {
      ArrayToken dataArrayToken = (ArrayToken) data.get(0);

      byte[] dataBytes = new byte[dataArrayToken.length()];

      for (int j = 0; j < dataArrayToken.length(); j++) {
        UnsignedByteToken token = (UnsignedByteToken) dataArrayToken.getElement(j);
        dataBytes[j] = token.byteValue();
      }

      DatagramPacket packet =
          new DatagramPacket(dataBytes, dataBytes.length, _address, _remoteSocketNumber);

      try {
        _socket.send(packet);
      } catch (IOException ex) {
        // ignore, UDP does not guarantee success
        // throw new InternalErrorException("socket.send failed");
        // FIXME  I don't believe that!  I think send guarantees that
        // it will send!!  Just not that anyone is listening.
        //    (yet when I ran it with 'throw...' uncommented
        //     then it threw it right away!? )
        // Would TCP stall here awaiting reply??  I doubt it!
      }

      triggerOutput.broadcast(new Token());
    }
  }
Ejemplo n.º 4
0
  /**
   * Add the key to the keystore.
   *
   * @exception IllegalActionException If there's no director, if there are problems setting the
   *     key.
   */
  public boolean postfire() throws IllegalActionException {
    // See io.LineWriter for an example of an actor that writes to a file.
    if (input.hasToken(0)) {
      KeyToken keyToken = (KeyToken) input.get(0);
      java.security.Key key = keyToken.getValue();

      if (key instanceof java.security.PrivateKey) {
        throw new IllegalActionException(
            this,
            "Key is a PrivateKey, which is not supported because " + "it requires a certificate");
      }

      // Now we add the key to the keystore, protected
      // by the password.
      try {
        _keyStore.setKeyEntry(_alias, key, _keyPassword.toCharArray(), null /* No certificate */);
      } catch (Exception ex) {
        throw new IllegalActionException(
            this, ex, "Failed to set key '" + key + "' to alias '" + alias + "'");
      }

      try {
        FileOutputStream keyStoreOutputStream = null;

        try {
          keyStoreOutputStream = new FileOutputStream(fileOrURL.asFile());
          _keyStore.store(keyStoreOutputStream, _storePassword.toCharArray());
          keyStoreOutputStream.close();
        } finally {
          try {
            if (keyStoreOutputStream != null) {
              keyStoreOutputStream.close();
            }
          } catch (Throwable throwable) {
            System.out.println("Ignoring failure to close stream " + "on " + fileOrURL.asFile());
            throwable.printStackTrace();
          }
        }

        output.broadcast(BooleanToken.TRUE);
      } catch (Throwable throwable) {
        throw new IllegalActionException(
            this, throwable, "Failed to store " + fileOrURLDescription());
      }
    }

    return super.postfire();
  }
Ejemplo n.º 5
0
  public void fire() throws IllegalActionException {
    ObjectToken obj = (ObjectToken) lsp_old.get(0);
    Short[] arg1 = (Short[]) obj.getValue();

    obj = (ObjectToken) lsp_mid.get(0);
    Short[] arg2 = (Short[]) obj.getValue();

    obj = (ObjectToken) lsp_new.get(0);
    Short[] arg3 = (Short[]) obj.getValue();

    Short[] arg4 = new Short[Cnst.MP1 * 4];

    _int_lpc2(arg1, arg2, arg3, arg4);

    obj = new ObjectToken(arg4);
    A.broadcast(obj);
  }
Ejemplo n.º 6
0
  public void fire() throws IllegalActionException {

    ObjectToken ot = (ObjectToken) input.get(0);
    MuxDataFrame mf = (MuxDataFrame) ot.getValue();
    int b;

    if (_frameCounter == 0) {
      b = _processFast(mf.getFastByte());
      mf.setFastByte(b);

      if (!_LS0Map) {
        for (int i = 0; i < _LS0Bytes; i++) {
          b = _processFast(mf.getLS0Byte(i));
          mf.setLS0Byte(b, i);
        }
      }

      if (mf.hasLEX()) {
        b = _processFast(mf.getLEXByte());
        mf.setLEXByte(b);
      }
    } else {
      b = _processInter(mf.getFastByte());
      mf.setFastByte(b);

      if (_LS0Map) {
        for (int i = 0; i < _LS0Bytes; i++) {
          b = _processInter(mf.getLS0Byte(i));
          mf.setLS0Byte(b, i);
        }
      }

      if (mf.hasLEX()) {
        b = _processInter(mf.getLEXByte());
        mf.setLEXByte(b);
      }
    }
    _frameCounter++;
    if (_frameCounter == 1 + _S) _frameCounter = 0;

    ot = new ObjectToken(mf);
    output.broadcast(ot);
  }
Ejemplo n.º 7
0
  // NOTE: No clone() method, so don't clone this.
  public void fire() throws IllegalActionException {
    super.fire();
    double increment = 0.0;

    if ((input.getWidth() > 0) && input.hasToken(0)) {
      DoubleToken in = (DoubleToken) input.get(0);
      increment = in.doubleValue();
    }

    output.broadcast(new DoubleToken(value + increment));
    value += 1.0;

    Director director = getDirector();
    Time time = director.getModelTime();
    count++;

    if (count >= 5) {
      director.fireAt(this, time.add(1.0));
      count = 0;
    } else {
      director.fireAt(this, time);
    }
  }
Ejemplo n.º 8
0
  /**
   * If the value at the <i>derivative</i> port is known, and the current step size is bigger than
   * 0, perform an integration. If the <i>impulse</i> port is known and has data, then add the value
   * provided to the state; if the <i>initialState</i> port is known and has data, then reset the
   * state to the provided value. If both <i>impulse</i> and <i>initialState</i> have data, then
   * <i>initialState</i> dominates. If either is unknown, then simply return, leaving the output
   * unknown. Note that the signals provided at these two ports are required to be purely discrete.
   * This is enforced by throwing an exception if the current microstep is zero when they have input
   * data.
   *
   * @exception IllegalActionException If the input is infinite or not a number, or if thrown by the
   *     solver, or if data is present at either <i>impulse</i> or <i>initialState</i> and the step
   *     size is greater than zero.
   */
  public void fire() throws IllegalActionException {
    ContinuousDirector dir = (ContinuousDirector) getDirector();
    double stepSize = dir.getCurrentStepSize();
    int microstep = dir.getIndex();

    if (_debugging) {
      Time currentTime = dir.getModelTime();
      _debug(
          "Fire at time "
              + currentTime
              + " and microstep "
              + microstep
              + " with step size "
              + stepSize);
    }
    // First handle the impulse input.
    if (impulse.getWidth() > 0 && impulse.hasToken(0)) {
      double impulseValue = ((DoubleToken) impulse.get(0)).doubleValue();
      if (_debugging) {
        _debug("-- impulse input received with value " + impulseValue);
      }
      if (impulseValue != 0.0) {
        if (microstep == 0) {
          throw new IllegalActionException(
              this, "Signal at the impulse port is not purely discrete.");
        }
        double currentState = getState() + impulseValue;
        setTentativeState(currentState);
        if (_debugging) {
          _debug("-- Due to impulse input, set state to " + currentState);
        }
      }
    }
    // Next handle the initialState port.
    ParameterPort initialStatePort = initialState.getPort();
    if (initialStatePort.getWidth() > 0 && initialStatePort.hasToken(0)) {
      double initialValue = ((DoubleToken) initialStatePort.get(0)).doubleValue();
      if (_debugging) {
        _debug("-- initialState input received with value " + initialValue);
      }
      if (microstep == 0.0) {
        throw new IllegalActionException(
            this, "Signal at the initialState port is not purely discrete.");
      }
      setTentativeState(initialValue);
      if (_debugging) {
        _debug("-- Due to initialState input, set state to " + initialValue);
      }
    }

    // Produce the current _tentativeState as output, if it
    // has not already been produced.
    if (!state.isKnown()) {
      double tentativeOutput = getTentativeState();
      // If the round has not updated since the last output, then
      // just produce the same output as last time.
      int currentRound = dir._getODESolver()._getRound();
      if (_lastRound == currentRound) {
        tentativeOutput = _lastOutput;
      }

      if (_debugging) {
        _debug("** Sending output " + tentativeOutput);
      }
      _lastOutput = tentativeOutput;
      state.broadcast(new DoubleToken(tentativeOutput));
    }

    // The _tentativeSate is committed only in postfire(),
    // but multiple rounds will occur before postfire() is called.
    // At each round, this fire() method may be called multiple
    // times, and we want to make sure that the integration step
    // only runs once in the step.
    if (derivative.isKnown() && derivative.hasToken(0)) {
      int currentRound = dir._getODESolver()._getRound();
      if (_lastRound < currentRound) {
        // This is the first fire() in a new round
        // where the derivative input is known and present.
        // Update the tentative state. Note that we will
        // have already produced an output, and so we
        // will not read the updated _tentativeState
        // again in subsequent invocations of fire()
        // in this round. So it is safe to update
        // _tentativeState.
        _lastRound = currentRound;
        double currentDerivative = getDerivative();
        if (Double.isNaN(currentDerivative) || Double.isInfinite(currentDerivative)) {
          throw new IllegalActionException(
              this, "The provided derivative input is invalid: " + currentDerivative);
        }
        if (stepSize > 0.0) {
          // The following method changes the tentative state.
          dir._getODESolver().integratorIntegrate(this);
        }
      }
    }
  }
Ejemplo n.º 9
0
  public void fire() throws IllegalActionException {

    if (_state == RUNNING) {
      if (alfa.isKnown() && !emmode.isKnown()) {
        // if(alfa.isKnown()) {
        if (alfa.hasToken(0)) {
          double _alfa = ((DoubleToken) alfa.get(0)).doubleValue();

          /*
          if(_count > 0) {   // so atualiza se um evento true deu inicio
              _count++;
          }*/

          if (Math.abs(_alfa) >= 0.10) { // tem um evento
            // _sensorCount++;
            // if(_count == 0) {
            //    _count = 1;
            // }
            _count++;
          } else {
            _count = 0;
          }

          if (_count == 25) {
            emmode.broadcast(new Token());
            System.out.println("Entering Emergency Mode");
            _reset(); // uma vez setado o emmode, so na proxima....
          }

          /*
          if(_count == 50) {   // deu os 100ms
              if(_maxSensorCount >= 25 ||
                 _sensorCount >= 25) {
                  emmode.broadcast(new Token());
                  System.out.println("Entering Emergency Mode");

                  _reset(); // uma vez setado o emmode, so na proxima....
              }
              else {
                  _count = 0;
                  _sensorCount = 0;
                  _maxSensorCount = 0;
              }
          }
          else {
              if(Math.abs(_alfa) >= 0.10) {      // tem um evento
                  _sensorCount++;
                  if(_count == 0) {
                      _count = 1;
                  }
              }
              if((Math.abs(_alfa) < 0.1) && _count > 0) {    // nao tem mais , e estava contando
                  if(_sensorCount > _maxSensorCount) {
                      _maxSensorCount = _sensorCount;
                  }
                  _sensorCount = 0;
              }
          } */
        }
      }
    }

    if (alfa.isKnown() && !emmode.isKnown()) {
      emmode.broadcastClear();
    }
  }