Exemplo n.º 1
0
  /** {@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));
  }
Exemplo n.º 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()]);
 }
Exemplo n.º 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()]);
  }
Exemplo n.º 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();
  }
Exemplo n.º 5
0
  /**
   * @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));
  }
Exemplo n.º 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));
  }
Exemplo n.º 7
0
 public static int min(int[] values) {
   return NumberUtils.min(values);
 }
Exemplo n.º 8
0
 public static int max(int[] values) {
   return NumberUtils.max(values);
 }
Exemplo n.º 9
0
 public static String format(short value, String format) {
   return NumberUtils.format(Short.valueOf(value), format);
 }
Exemplo n.º 10
0
 // ---- math -------------------------------------------------------
 public static int sum(int[] values) {
   return NumberUtils.sum(values);
 }
Exemplo n.º 11
0
 public static String format(Number value) {
   return NumberUtils.format(value);
 }
Exemplo n.º 12
0
 public static String format(double value, String format) {
   return NumberUtils.format(Double.valueOf(value), format);
 }
Exemplo n.º 13
0
 public static String format(float value, String format) {
   return NumberUtils.format(Float.valueOf(value), format);
 }
Exemplo n.º 14
0
 public static String format(long value, String format) {
   return NumberUtils.format(Long.valueOf(value), format);
 }
Exemplo n.º 15
0
 public static String format(int value, String format) {
   return NumberUtils.format(Integer.valueOf(value), format);
 }
Exemplo n.º 16
0
 public static int avg(int[] values) {
   return NumberUtils.avg(values);
 }
Exemplo n.º 17
0
 // ---- format -------------------------------------------------------
 public static String format(byte value, String format) {
   return NumberUtils.format(Byte.valueOf(value), format);
 }