/** {@inheritDoc} */
  @Override
  protected void prepareToolTask(final ToolTask<UARTDataSet> aToolTask) {
    final UARTAnalyserTask toolTask = (UARTAnalyserTask) aToolTask;

    // The value at index zero is "Unused", so extracting one of all items
    // causes all "unused" values to be equivalent to -1, which is interpreted
    // as not used...
    toolTask.setRxdIndex(this.rxd.getSelectedIndex() - 1);
    toolTask.setTxdIndex(this.txd.getSelectedIndex() - 1);
    toolTask.setCtsIndex(this.cts.getSelectedIndex() - 1);
    toolTask.setRtsIndex(this.rts.getSelectedIndex() - 1);
    toolTask.setDcdIndex(this.dcd.getSelectedIndex() - 1);
    toolTask.setRiIndex(this.ri.getSelectedIndex() - 1);
    toolTask.setDsrIndex(this.dsr.getSelectedIndex() - 1);
    toolTask.setDtrIndex(this.dtr.getSelectedIndex() - 1);
    // Handle the auto detect option for baudrates...
    if (this.autoDetectBaudRate.isSelected()) {
      toolTask.setBaudRate(UARTAnalyserTask.AUTO_DETECT_BAUDRATE);
    } else {
      toolTask.setBaudRate(((Integer) this.baudrate.getSelectedItem()).intValue());
    }

    // Other properties...
    toolTask.setIdleLevel((BitLevel) this.idleLevel.getSelectedItem());
    toolTask.setBitEncoding((BitEncoding) this.bitEncoding.getSelectedItem());
    toolTask.setBitOrder((BitOrder) this.bitOrder.getSelectedItem());
    toolTask.setParity((Parity) this.parity.getSelectedItem());
    toolTask.setStopBits((StopBits) this.stop.getSelectedItem());
    toolTask.setBitCount(NumberUtils.smartParseInt((String) this.bits.getSelectedItem(), 8));
  }
示例#2
0
 /**
  * Returns all supported capture sizes.
  *
  * @return an array of capture sizes, in bytes, never <code>null</code>.
  */
 public Integer[] getCaptureSizes() {
   final String rawValue = this.properties.get(DEVICE_CAPTURESIZES);
   final String[] values = rawValue.split(",\\s*");
   final List<Integer> result = new ArrayList<Integer>();
   for (String value : values) {
     result.add(Integer.valueOf(value.trim()));
   }
   Collections.sort(
       result, NumberUtils.<Integer>createNumberComparator(false /* aSortAscending */));
   return result.toArray(new Integer[result.size()]);
 }
示例#3
0
  /**
   * Returns all supported sample rates.
   *
   * @return an array of sample rates, in Hertz, never <code>null</code>.
   */
  public Integer[] getSampleRates() {
    final String rawValue = this.properties.get(DEVICE_SAMPLERATES);
    final String[] values = rawValue.split(",\\s*");
    final SortedSet<Integer> result =
        new TreeSet<Integer>(
            NumberUtils.<Integer>createNumberComparator(false /* aSortAscending */));
    for (String value : values) {
      result.add(Integer.valueOf(value.trim()));
    }

    return result.toArray(new Integer[result.size()]);
  }
示例#4
0
  /**
   * Encode a Human Readable Resource Identifier to a URI. Leading and trailing spaces are removed
   * first.
   *
   * <p>NOTE: See more recent W3C note: http://www.w3.org/TR/2008/NOTE-leiri-20081103/
   *
   * @param uriString URI to encode
   * @param processSpace whether to process the space character or leave it unchanged
   * @return encoded URI, or null if uriString was null
   */
  public static String encodeHRRI(String uriString, boolean processSpace) {

    if (uriString == null) return null;

    // Note that the XML Schema spec says "Spaces are, in principle, allowed in the ·lexical space·
    // of anyURI,
    // however, their use is highly discouraged (unless they are encoded by %20).".

    // We assume that we never want leading or trailing spaces. You can use %20 if you really want
    // this.
    uriString = uriString.trim();

    // We try below to follow the "Human Readable Resource Identifiers" RFC, in draft as of
    // 2007-06-06.
    // * the control characters #x0 to #x1F and #x7F to #x9F
    // * space #x20
    // * the delimiters "<" #x3C, ">" #x3E, and """ #x22
    // * the unwise characters "{" #x7B, "}" #x7D, "|" #x7C, "\" #x5C, "^" #x5E, and "`" #x60
    final StringBuilder sb = new StringBuilder(uriString.length() * 2);
    for (int i = 0; i < uriString.length(); i++) {
      final char currentChar = uriString.charAt(i);

      if (currentChar >= 0
          && (currentChar <= 0x1f
              || (processSpace && currentChar == 0x20)
              || currentChar == 0x22
              || currentChar == 0x3c
              || currentChar == 0x3e
              || currentChar == 0x5c
              || currentChar == 0x5e
              || currentChar == 0x60
              || (currentChar >= 0x7b && currentChar <= 0x7d)
              || (currentChar >= 0x7f && currentChar <= 0x9f))) {
        sb.append('%');
        sb.append(NumberUtils.toHexString((byte) currentChar).toUpperCase());
      } else {
        sb.append(currentChar);
      }
    }

    return sb.toString();
  }
  /**
   * @see
   *     nl.lxtreme.ols.tool.base.BaseAsyncToolDialog#setupToolWorker(nl.lxtreme.ols.tool.base.BaseAsyncToolWorker)
   */
  @Override
  protected void setupToolWorker(final UARTAnalyserWorker aToolWorker) {
    // The value at index zero is "Unused", so extracting one of all items
    // causes all "unused" values to be equivalent to -1, which is interpreted
    // as not used...
    aToolWorker.setRxdIndex(this.rxd.getSelectedIndex() - 1);
    aToolWorker.setTxdIndex(this.txd.getSelectedIndex() - 1);
    aToolWorker.setCtsIndex(this.cts.getSelectedIndex() - 1);
    aToolWorker.setRtsIndex(this.rts.getSelectedIndex() - 1);
    aToolWorker.setDcdIndex(this.dcd.getSelectedIndex() - 1);
    aToolWorker.setRiIndex(this.ri.getSelectedIndex() - 1);
    aToolWorker.setDsrIndex(this.dsr.getSelectedIndex() - 1);
    aToolWorker.setDtrIndex(this.dtr.getSelectedIndex() - 1);

    // Other properties...
    aToolWorker.setInverted(this.inv.isSelected());
    aToolWorker.setParity((UARTParity) this.parity.getSelectedItem());
    aToolWorker.setStopBits((UARTStopBits) this.stop.getSelectedItem());
    aToolWorker.setBitCount(NumberUtils.smartParseInt((String) this.bits.getSelectedItem(), 8));
  }
示例#6
0
  /**
   * Reads the data from a given reader.
   *
   * @param aProject the project to read the settings to;
   * @param aReader the reader to read the data from, cannot be <code>null</code>.
   * @throws IOException in case of I/O problems.
   */
  @SuppressWarnings("boxing")
  public static void read(final StubDataSet aDataSet, final Reader aReader) throws IOException {
    int size = -1;
    Integer rate = null, channels = null, enabledChannels = null;
    long triggerPos = -1L;
    long absLen = -1L;

    // assume 'new' file format is in use, don't support uncompressed ones...
    boolean compressed = true;

    final BufferedReader br = new BufferedReader(aReader);

    final List<String[]> dataValues = new ArrayList<String[]>();

    String line;
    while ((line = br.readLine()) != null) {
      // Determine whether the line is an instruction, or data...
      final Matcher instructionMatcher = OLS_INSTRUCTION_PATTERN.matcher(line);
      final Matcher dataMatcher = OLS_DATA_PATTERN.matcher(line);

      if (dataMatcher.matches()) {
        final String[] dataPair = new String[] {dataMatcher.group(1), dataMatcher.group(2)};
        dataValues.add(dataPair);
      } else if (instructionMatcher.matches()) {
        // Ok; found an instruction...
        final String instrKey = instructionMatcher.group(1);
        final String instrValue = instructionMatcher.group(2);

        if ("Size".equals(instrKey)) {
          size = safeParseInt(instrValue);
        } else if ("Rate".equals(instrKey)) {
          rate = safeParseInt(instrValue);
        } else if ("Channels".equals(instrKey)) {
          channels = safeParseInt(instrValue);
        } else if ("TriggerPosition".equals(instrKey)) {
          triggerPos = Long.parseLong(instrValue);
        } else if ("EnabledChannels".equals(instrKey)) {
          enabledChannels = safeParseInt(instrValue);
        } else if ("CursorEnabled".equals(instrKey)) {
          aDataSet.setCursorsEnabled(Boolean.parseBoolean(instrValue));
        } else if ("Compressed".equals(instrKey)) {
          compressed = Boolean.parseBoolean(instrValue);
        } else if ("AbsoluteLength".equals(instrKey)) {
          absLen = Long.parseLong(instrValue);
        } else if ("CursorA".equals(instrKey)) {
          final long value = safeParseLong(instrValue);
          if (value > Long.MIN_VALUE) {
            aDataSet.getCursor(0).setTimestamp(value);
          }
        } else if ("CursorB".equals(instrKey)) {
          final long value = safeParseLong(instrValue);
          if (value > Long.MIN_VALUE) {
            aDataSet.getCursor(1).setTimestamp(value);
          }
        } else if (instrKey.startsWith("Cursor")) {
          final int idx = safeParseInt(instrKey.substring(6));
          final long pos = Long.parseLong(instrValue);
          if (pos > Long.MIN_VALUE) {
            aDataSet.getCursor(idx).setTimestamp(pos);
          }
        }
      }
    }

    // Perform some sanity checks, make it not possible to import invalid
    // data...
    if (dataValues.isEmpty()) {
      throw new IOException("Data file does not contain any sample data!");
    }
    if (!compressed) {
      throw new IOException(
          "Uncompressed data file found! Please send this file to the OLS developers!");
    }
    // In case the size is not provided (as of 0.9.4 no longer mandatory),
    // take the length of the data values as size indicator...
    if (size < 0) {
      size = dataValues.size();
    }
    if (size != dataValues.size()) {
      throw new IOException("Data file is corrupt?! Data size does not match sample count!");
    }
    if (rate == null) {
      throw new IOException("Data file is corrupt?! Sample rate is not provided!");
    }
    if ((channels == null) || (channels <= 0) || (channels > 32)) {
      throw new IOException("Data file is corrupt?! Channel count is not provided!");
    }
    // Make sure the enabled channels are defined...
    if (enabledChannels == null) {
      enabledChannels = NumberUtils.getBitMask(channels);
    }

    int[] values = new int[size];
    long[] timestamps = new long[size];

    try {
      for (int i = 0; i < size; i++) {
        final String[] dataPair = dataValues.get(i);

        values[i] = (int) Long.parseLong(dataPair[0], 16);
        timestamps[i] = Long.parseLong(dataPair[1], 10) & Long.MAX_VALUE;
      }
    } catch (final NumberFormatException exception) {
      throw new IOException("Invalid data encountered.", exception);
    }

    // Allow the absolute length to be undefined, in which case the last
    // time stamp is used (+ some margin to be able to see the last
    // sample)...
    long absoluteLength = Math.max(absLen, timestamps[size - 1]);

    // Finally set the captured data, and notify all event listeners...
    aDataSet.setCapturedData(
        new CapturedData(
            values, timestamps, triggerPos, rate, channels, enabledChannels, absoluteLength));
  }