Example #1
0
  /** Synchronizes the state of the actions to the current state of this host. */
  private void updateActions() {
    final DeviceController currentDeviceController = getDeviceController();

    final boolean deviceControllerSet = currentDeviceController != null;
    final boolean deviceCapturing = deviceControllerSet && currentDeviceController.isCapturing();
    final boolean deviceSetup =
        deviceControllerSet && !deviceCapturing && currentDeviceController.isSetup();

    getAction(CaptureAction.ID).setEnabled(deviceControllerSet);
    getAction(CancelCaptureAction.ID).setEnabled(deviceCapturing);
    getAction(RepeatCaptureAction.ID).setEnabled(deviceSetup);

    final boolean projectChanged = this.projectManager.getCurrentProject().isChanged();
    final boolean projectSavedBefore =
        this.projectManager.getCurrentProject().getFilename() != null;
    final boolean dataAvailable = this.dataContainer.hasCapturedData();

    getAction(SaveProjectAction.ID).setEnabled(projectChanged);
    getAction(SaveProjectAsAction.ID).setEnabled(projectSavedBefore && projectChanged);
    getAction(SaveDataFileAction.ID).setEnabled(dataAvailable);

    getAction(ZoomInAction.ID).setEnabled(dataAvailable);
    getAction(ZoomOutAction.ID).setEnabled(dataAvailable);
    getAction(ZoomDefaultAction.ID).setEnabled(dataAvailable);
    getAction(ZoomFitAction.ID).setEnabled(dataAvailable);

    final boolean triggerEnable = dataAvailable && this.dataContainer.hasTriggerData();
    getAction(GotoTriggerAction.ID).setEnabled(triggerEnable);

    // Update the cursor actions accordingly...
    final boolean enableCursors = dataAvailable && this.dataContainer.isCursorsEnabled();

    for (int c = 0; c < CapturedData.MAX_CURSORS; c++) {
      final boolean enabled = enableCursors && this.dataContainer.isCursorPositionSet(c);
      getAction(GotoNthCursorAction.getID(c)).setEnabled(enabled);
    }

    getAction(GotoFirstCursorAction.ID).setEnabled(enableCursors);
    getAction(GotoLastCursorAction.ID).setEnabled(enableCursors);

    getAction(SetCursorModeAction.ID).setEnabled(dataAvailable);
    getAction(SetCursorModeAction.ID)
        .putValue(Action.SELECTED_KEY, Boolean.valueOf(this.dataContainer.isCursorsEnabled()));

    boolean anyCursorSet = false;
    for (int c = 0; c < CapturedData.MAX_CURSORS; c++) {
      final boolean cursorPositionSet = this.dataContainer.isCursorPositionSet(c);
      anyCursorSet |= cursorPositionSet;

      final Action action = getAction(SetCursorAction.getCursorId(c));
      action.setEnabled(dataAvailable);
      action.putValue(Action.SELECTED_KEY, Boolean.valueOf(cursorPositionSet));
    }

    getAction(ClearCursors.ID).setEnabled(enableCursors && anyCursorSet);
  }
  /**
   * exports the data to a CSV file
   *
   * @param aFile File object
   */
  private void storeToCsvFile(final File aFile, final UARTDataSet aDataSet) {
    try {
      final CsvExporter exporter = ExportUtils.createCsvExporter(aFile);

      exporter.setHeaders(
          "index",
          "start-time",
          "end-time",
          "event?",
          "event-type",
          "RxD event",
          "TxD event",
          "RxD data",
          "TxD data");

      final List<UARTData> decodedData = aDataSet.getData();
      for (int i = 0; i < decodedData.size(); i++) {
        final UARTData ds = decodedData.get(i);

        final String startTime = Unit.Time.format(aDataSet.getTime(ds.getStartSampleIndex()));
        final String endTime = Unit.Time.format(aDataSet.getTime(ds.getEndSampleIndex()));

        String eventType = null;
        String rxdEvent = null;
        String txdEvent = null;
        String rxdData = null;
        String txdData = null;

        switch (ds.getType()) {
          case UARTData.UART_TYPE_EVENT:
            eventType = ds.getEventName();
            break;

          case UARTData.UART_TYPE_RXEVENT:
            rxdEvent = ds.getEventName();
            break;

          case UARTData.UART_TYPE_TXEVENT:
            txdEvent = ds.getEventName();
            break;

          case UARTData.UART_TYPE_RXDATA:
            rxdData = Integer.toString(ds.getData());
            break;

          case UARTData.UART_TYPE_TXDATA:
            txdData = Integer.toString(ds.getData());
            break;

          default:
            break;
        }

        exporter.addRow(
            Integer.valueOf(i),
            startTime,
            endTime,
            Boolean.valueOf(ds.isEvent()),
            eventType,
            rxdEvent,
            txdEvent,
            rxdData,
            txdData);
      }

      exporter.close();
    } catch (final IOException exception) {
      // Make sure to handle IO-interrupted exceptions properly!
      if (!HostUtils.handleInterruptedException(exception)) {
        LOG.log(Level.WARNING, "CSV export failed!", exception);
      }
    }
  }
Example #3
0
 /**
  * Returns whether or not the device supports triggers.
  *
  * @return <code>true</code> if the device supports triggers, <code>false</code> otherwise.
  */
 public boolean isTriggerSupported() {
   final String value = this.properties.get(DEVICE_FEATURE_TRIGGERS);
   return Boolean.parseBoolean(value);
 }
Example #4
0
 /**
  * Returns whether or not the device supports a testing mode.
  *
  * @return <code>true</code> if testing mode is supported by the device, <code>false</code>
  *     otherwise.
  */
 public boolean isTestModeSupported() {
   final String value = this.properties.get(DEVICE_FEATURE_TEST_MODE);
   return Boolean.parseBoolean(value);
 }
Example #5
0
 /**
  * Returns whether the device send its samples in "reverse" order.
  *
  * @return <code>true</code> if samples are send in reverse order (= last sample first), <code>
  *     false</code> otherwise.
  */
 public boolean isSamplesInReverseOrder() {
   final String rawValue = this.properties.get(DEVICE_SAMPLE_REVERSE_ORDER);
   return Boolean.parseBoolean(rawValue);
 }
Example #6
0
 /**
  * Returns whether or not the device supports RLE (Run-Length Encoding).
  *
  * @return <code>true</code> if a RLE encoder is present in the device, <code>false</code>
  *     otherwise.
  */
 public boolean isRleSupported() {
   final String value = this.properties.get(DEVICE_FEATURE_RLE);
   return Boolean.parseBoolean(value);
 }
Example #7
0
 /**
  * Returns whether upon opening the DTR line needs to be high (= <code>true</code>) or low (=
  * <code>false</code>).
  *
  * <p>This method has no meaning if the used interface is <em>not</em> {@link
  * DeviceInterface#SERIAL}.
  *
  * @return <code>true</code> if the DTR line needs to be set upon opening the serial port, <code>
  *     false</code> if the DTR line needs to be reset upon opening the serial port.
  */
 public boolean isOpenPortDtr() {
   final String value = this.properties.get(DEVICE_OPEN_PORT_DTR);
   return Boolean.parseBoolean(value);
 }
Example #8
0
 /**
  * Returns whether or not the device supports a noise filter.
  *
  * @return <code>true</code> if a noise filter is present in the device, <code>false</code>
  *     otherwise.
  */
 public boolean isNoiseFilterSupported() {
   final String value = this.properties.get(DEVICE_FEATURE_NOISEFILTER);
   return Boolean.parseBoolean(value);
 }
Example #9
0
 /**
  * Returns whether or not the device supports "double-data rate" sampling, also known as
  * "demux"-sampling.
  *
  * @return <code>true</code> if DDR is supported by the device, <code>false</code> otherwise.
  */
 public boolean isDoubleDataRateSupported() {
   final String value = this.properties.get(DEVICE_SUPPORTS_DDR);
   return Boolean.parseBoolean(value);
 }
Example #10
0
 /**
  * Returns whether or not the device supports "complex" triggers.
  *
  * @return <code>true</code> if complex triggers are supported by the device, <code>false</code>
  *     otherwise.
  */
 public boolean isComplexTriggersSupported() {
   final String value = this.properties.get(DEVICE_TRIGGER_COMPLEX);
   return Boolean.parseBoolean(value);
 }
Example #11
0
 /**
  * Returns whether or not the capture size is bound to the number of channels.
  *
  * @return <code>true</code> if the capture size is bound to the number of channels, <code>false
  *     </code> otherwise.
  */
 public boolean isCaptureSizeBoundToEnabledChannels() {
   final String value = this.properties.get(DEVICE_CAPTURESIZE_BOUND);
   return Boolean.parseBoolean(value);
 }
Example #12
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));
  }
Example #13
0
  /**
   * Writes the data to the given writer.
   *
   * @param aDataSet the project to write the settings for, cannot be <code>null</code> ;
   * @param aWriter the writer to write the data to, cannot be <code>null</code>.
   * @throws IOException in case of I/O problems.
   */
  public static void write(final StubDataSet aDataSet, final Writer aWriter) throws IOException {
    final BufferedWriter bw = new BufferedWriter(aWriter);

    final AcquisitionResult capturedData = aDataSet.getCapturedData();

    final Cursor[] cursors = aDataSet.getCursors();
    final boolean cursorsEnabled = aDataSet.isCursorsEnabled();

    try {
      final int[] values = capturedData.getValues();
      final long[] timestamps = capturedData.getTimestamps();

      bw.write(";Size: ");
      bw.write(Integer.toString(values.length));
      bw.newLine();

      bw.write(";Rate: ");
      bw.write(Integer.toString(capturedData.getSampleRate()));
      bw.newLine();

      bw.write(";Channels: ");
      bw.write(Integer.toString(capturedData.getChannels()));
      bw.newLine();

      bw.write(";EnabledChannels: ");
      bw.write(Integer.toString(capturedData.getEnabledChannels()));
      bw.newLine();

      if (capturedData.hasTriggerData()) {
        bw.write(";TriggerPosition: ");
        bw.write(Long.toString(capturedData.getTriggerPosition()));
        bw.newLine();
      }

      bw.write(";Compressed: ");
      bw.write(Boolean.toString(true));
      bw.newLine();

      bw.write(";AbsoluteLength: ");
      bw.write(Long.toString(capturedData.getAbsoluteLength()));
      bw.newLine();

      bw.write(";CursorEnabled: ");
      bw.write(Boolean.toString(cursorsEnabled));
      bw.newLine();

      for (int i = 0; cursorsEnabled && (i < cursors.length); i++) {
        if (cursors[i].isDefined()) {
          bw.write(String.format(";Cursor%d: ", Integer.valueOf(i)));
          bw.write(Long.toString(cursors[i].getTimestamp()));
          bw.newLine();
        }
      }
      for (int i = 0; i < values.length; i++) {
        bw.write(formatSample(values[i], timestamps[i]));
        bw.newLine();
      }
    } finally {
      bw.flush();
    }
  }
Example #14
0
 /**
  * Returns whether or not we're running in debug mode.
  *
  * @return <code>true</code> if debug mode is enabled, <code>false</code> otherwise.
  */
 public static boolean isDebugMode() {
   return Boolean.parseBoolean(System.getProperty("nl.lxtreme.ols.client.debug", "false"));
 }