Example #1
0
  /**
   * Returns the current stream connection that is opened.
   *
   * @return a stream connection, can be a cached one, never <code>null</code>.
   * @throws IOException in case of I/O problems creating the stream connection.
   */
  private StreamConnection getStreamConnection() throws IOException {
    if (this.connection == null) {
      final String uri = this.config.getConnectionURI();

      if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Connecting to " + uri);
      }

      this.connection = createStreamConnection(uri);
    }
    return this.connection;
  }
Example #2
0
 /**
  * Sets the (average) bit length for this data set.
  *
  * <p>A bit length is used to determine the baudrate of this data set. If there is already a bit
  * length available from an earlier call to this method, it will be used to average the resulting
  * bit length if both the current and the given bit length are "close". This allows you to use the
  * bit lengths of both the RxD- and TxD-lines to get a good approximation of the actual baudrate.
  *
  * @param aBitLength the bit length to set/add, should be >= 0.
  */
 public void setSampledBitLength(final int aBitLength) {
   // If the given bit length is "much" smaller (smaller bit length means
   // higher baudrate) than the current one, switch to that one instead; this
   // way we can recover from bad values...
   if ((this.bitLength <= 0) || ((10.0 * aBitLength) < this.bitLength)) {
     // First time being called, take the given bit length as our "truth"...
     this.bitLength = aBitLength;
   } else {
     // Take the average as the current and the given bit lengths are "close"
     // to each other; ignore the given bit length otherwise, as it clobbers
     // our earlier results...
     final int diff = Math.abs(aBitLength - this.bitLength);
     if ((diff >= 0) && (diff < 50)) {
       this.bitLength = (int) ((aBitLength + this.bitLength) / 2.0);
     } else {
       LOG.log(
           Level.INFO,
           "Ignoring sampled bit length ({0}) as it deviates "
               + "too much from current bit length ({1}).",
           new Object[] {Integer.valueOf(aBitLength), Integer.valueOf(this.bitLength)});
     }
   }
 }
Example #3
0
/** @author jajans */
public final class UARTDataSet extends BaseDataSet<UARTData> {
  // CONSTANTS

  public static final String UART_RXD = "RxD";
  public static final String UART_TXD = "TxD";
  public static final String UART_CTS = "CTS";
  public static final String UART_RTS = "RTS";
  public static final String UART_DCD = "DCD";
  public static final String UART_RI = "RI";
  public static final String UART_DSR = "DSR";
  public static final String UART_DTR = "DTR";

  private static final Logger LOG = Logger.getLogger(UARTDataSet.class.getName());

  // VARIABLES

  private int decodedSymbols;
  private int bitLength;
  private int detectedErrors;

  private int baudRateExact;
  private int baudRate;

  // CONSTRUCTORS

  /** Creates a new UARTDataSet instance. */
  public UARTDataSet(
      final int aStartSampleIdx, final int aEndSampleIdx, final AcquisitionResult aData) {
    super(aStartSampleIdx, aEndSampleIdx, aData);

    this.decodedSymbols = 0;
    this.detectedErrors = 0;
    this.bitLength = -1;
  }

  // METHODS

  /**
   * Returns the "normalized" baudrate most people can recognize.
   *
   * @return a baudrate, >= 0.
   */
  public int getBaudRate() {
    return this.baudRate;
  }

  /**
   * Returns the (calculated, exact) baudrate.
   *
   * @return a baudrate, >= 0.
   */
  public int getBaudRateExact() {
    return this.baudRateExact;
  }

  /**
   * Returns the "average" bit length found in the data.
   *
   * @return an average bit length, >= 0.
   */
  public int getBitLength() {
    return this.bitLength;
  }

  /**
   * Returns the number of decoded (data) symbols.
   *
   * @return a number of decoded (data) symbols, >= 0.
   */
  public int getDecodedSymbols() {
    return this.decodedSymbols;
  }

  /**
   * Returns the number of errors.
   *
   * @return an error count, >= 0.
   */
  public int getDetectedErrors() {
    return this.detectedErrors;
  }

  /**
   * Returns whether or not the bitlength is usable.
   *
   * @return <code>true</code> if a usable bitlength has been decoded, <code>false</code> otherwise.
   */
  public boolean isBitLengthUsable() {
    // TODO where does the 15 come from?!
    return getBitLength() > 15;
  }

  /**
   * @param aTime
   * @param aName
   */
  public void reportControlHigh(final int aChannelIdx, final int aSampleIdx, final String aName) {
    final int idx = size();
    addData(new UARTData(idx, aChannelIdx, aSampleIdx, aName.toUpperCase() + "_HIGH"));
  }

  /**
   * @param aTime
   * @param aName
   */
  public void reportControlLow(final int aChannelIdx, final int aSampleIdx, final String aName) {
    final int idx = size();
    addData(new UARTData(idx, aChannelIdx, aSampleIdx, aName.toUpperCase() + "_LOW"));
  }

  /**
   * @param aTime
   * @param aValue
   * @param aEventType
   */
  public void reportData(
      final int aChannelIdx,
      final int aStartSampleIdx,
      final int aEndSampleIdx,
      final int aValue,
      final int aEventType) {
    final int idx = size();
    this.decodedSymbols++;
    addData(new UARTData(idx, aChannelIdx, aStartSampleIdx, aEndSampleIdx, aValue, aEventType));
  }

  /**
   * @param aTime
   * @param aEventType
   */
  public void reportError(
      final ErrorType aType, final int aChannelIdx, final int aSampleIdx, final int aEventType) {
    final int idx = size();
    this.detectedErrors++;
    addData(new UARTData(idx, aChannelIdx, aSampleIdx, aType.name(), aEventType));
  }

  /**
   * Sets the baudRate.
   *
   * @param aBaudRate the baudRate to set
   */
  public void setBaudRate(final int aBaudRate) {
    this.baudRate = aBaudRate;
  }

  /**
   * Sets the baudRateExact.
   *
   * @param aBaudRateExact the baudRateExact to set
   */
  public void setBaudRateExact(final int aBaudRateExact) {
    this.baudRateExact = aBaudRateExact;
  }

  /**
   * Sets the (average) bit length for this data set.
   *
   * <p>A bit length is used to determine the baudrate of this data set. If there is already a bit
   * length available from an earlier call to this method, it will be used to average the resulting
   * bit length if both the current and the given bit length are "close". This allows you to use the
   * bit lengths of both the RxD- and TxD-lines to get a good approximation of the actual baudrate.
   *
   * @param aBitLength the bit length to set/add, should be >= 0.
   */
  public void setSampledBitLength(final int aBitLength) {
    // If the given bit length is "much" smaller (smaller bit length means
    // higher baudrate) than the current one, switch to that one instead; this
    // way we can recover from bad values...
    if ((this.bitLength <= 0) || ((10.0 * aBitLength) < this.bitLength)) {
      // First time being called, take the given bit length as our "truth"...
      this.bitLength = aBitLength;
    } else {
      // Take the average as the current and the given bit lengths are "close"
      // to each other; ignore the given bit length otherwise, as it clobbers
      // our earlier results...
      final int diff = Math.abs(aBitLength - this.bitLength);
      if ((diff >= 0) && (diff < 50)) {
        this.bitLength = (int) ((aBitLength + this.bitLength) / 2.0);
      } else {
        LOG.log(
            Level.INFO,
            "Ignoring sampled bit length ({0}) as it deviates "
                + "too much from current bit length ({1}).",
            new Object[] {Integer.valueOf(aBitLength), Integer.valueOf(this.bitLength)});
      }
    }
  }

  /** @see nl.lxtreme.ols.api.data.BaseDataSet#sort() */
  @Override
  public void sort() {
    super.sort();
  }
}
Example #4
0
/**
 * A representation of the LogicSniffer device.
 *
 * @author J.W. Janssen
 */
public class LogicSnifferDevice implements Device {
  // CONSTANTS

  private static final String NAME = "OpenBench LogicSniffer";

  private static final Logger LOG = Logger.getLogger(LogicSnifferDevice.class.getName());

  // VARIABLES

  private LogicSnifferConfig config;

  private volatile DependencyManager dependencyManager;
  private volatile ManagedServiceFactory deviceProfileManagerServiceFactory;
  private volatile ConnectorService connectorService;
  private volatile StreamConnection connection;
  private volatile LogicSnifferConfigDialog configDialog;

  // METHODS

  public LogicSnifferConfig getConfig() {
    return config;
  }

  /** {@inheritDoc} */
  @Override
  public void close() throws IOException {
    if (this.connection != null) {
      this.connection.close();
      this.connection = null;
    }
  }

  /** {@inheritDoc} */
  @Override
  public AcquisitionTask createAcquisitionTask(final AcquisitionProgressListener aProgressListener)
      throws IOException {
    return new LogicSnifferAcquisitionTask(
        this.config, getStreamConnection(), getDeviceProfileManager(), aProgressListener);
  }

  /** {@inheritDoc} */
  @Override
  public CancelTask createCancelTask() throws IOException {
    if (this.config.isRleEnabled()) {
      return new LogicSnifferCancelTask(getStreamConnection());
    }
    // Simply use the default behaviour...
    return null;
  }

  /** @see nl.lxtreme.ols.api.devices.Device#getName() */
  public String getName() {
    return NAME;
  }

  /** @see nl.lxtreme.ols.api.devices.Device#isSetup() */
  @Override
  public boolean isSetup() {
    return this.config != null;
  }

  /**
   * Displays the device controller dialog with enabled configuration portion and waits for user
   * input.
   *
   * @see nl.lxtreme.ols.api.devices.Device#setupCapture()
   */
  @Override
  public boolean setupCapture(final Window aOwner) {
    // Just to be sure...
    disposeConfigDialog();

    this.configDialog = new LogicSnifferConfigDialog(aOwner, this);

    try {
      boolean configConfirmed = this.configDialog.showDialog();
      if (configConfirmed) {
        this.config = this.configDialog.getConfiguration();
      }
      return configConfirmed;
    } finally {
      this.configDialog.dispose();
      this.configDialog = null;
    }
  }

  /**
   * @param uri
   * @return
   * @throws IOException
   */
  final StreamConnection createStreamConnection(final String uri) throws IOException {
    return (StreamConnection)
        this.connectorService.open(uri, ConnectorService.READ_WRITE, true /* timeouts */);
  }

  /**
   * Returns the default device profile.
   *
   * @return a default profile, never <code>null</code>.
   */
  final DeviceProfile getDefaultProfile() {
    return getDeviceProfileManager().getDefaultProfile();
  }

  /**
   * Returns the current device profile manager.
   *
   * @return a device profile manager, never <code>null</code>.
   */
  final DeviceProfileManager getDeviceProfileManager() {
    return (DeviceProfileManager) this.deviceProfileManagerServiceFactory;
  }

  /** Called when this class is unregistered as OSGi service. */
  protected void destroy(final Component aComponent) {
    disposeConfigDialog();
  }

  /**
   * Called when this class is registered as OSGi service.
   *
   * @param aComponent the bundle context to use, cannot be <code>null</code>.
   */
  protected void init(final Component aComponent) {
    final String pmFilter =
        String.format("(%s=%s)", Constants.SERVICE_PID, DeviceProfileManager.SERVICE_PID);

    aComponent //
        .add(
            this.dependencyManager
                .createServiceDependency() //
                .setService(ManagedServiceFactory.class, pmFilter) //
                .setAutoConfig("deviceProfileManagerServiceFactory") //
                .setInstanceBound(true) //
                .setRequired(true)) //
        .add(
            this.dependencyManager
                .createServiceDependency() //
                .setService(ConnectorService.class) //
                .setAutoConfig("connectorService") //
                .setInstanceBound(true) //
                .setRequired(true) //
            );
  }

  /**
   * Disposes the current configuration dialog, if one is still visible on screen. If no
   * configuration dialog is visible, this method does nothing.
   */
  private void disposeConfigDialog() {
    if (this.configDialog != null) {
      SwingComponentUtils.dispose(this.configDialog);
      this.configDialog = null;
    }
  }

  /**
   * Returns the current stream connection that is opened.
   *
   * @return a stream connection, can be a cached one, never <code>null</code>.
   * @throws IOException in case of I/O problems creating the stream connection.
   */
  private StreamConnection getStreamConnection() throws IOException {
    if (this.connection == null) {
      final String uri = this.config.getConnectionURI();

      if (LOG.isLoggable(Level.INFO)) {
        LOG.info("Connecting to " + uri);
      }

      this.connection = createStreamConnection(uri);
    }
    return this.connection;
  }
}