/** * Returns the (absolute) time value for the cursor indicated by the given * index. * * @param aCursorIdx * the index of the cursor to return as time, should be >= 0 and < * 10. * @return the time value (in seconds), or -1.0 if the cursor is not * available. */ public Double getCursorTimeValue( final int aCursorIdx ) { if ( !isCursorPositionSet( aCursorIdx ) ) { return null; } Long cursorPos = getCursorPosition( aCursorIdx ); return Double.valueOf( calculateTimeOffset( cursorPos.longValue() ) / ( double )getAcquisitionData().getSampleRate() ); }
/** * Returns the number of channel blocks that are available in the data. * * @return a block count, >= 0 && < {@value nl.lxtreme.ols.api.Ols#MAX_BLOCKS} * . */ public int getBlockCount() { return ( int )Math.min( Ols.MAX_BLOCKS, Math.ceil( getChannels() / ( double )Ols.CHANNELS_PER_BLOCK ) ); }
/** * Calculates the time value corresponding to the given sample index. * * @param aSampleIndex * the sample index to get the time value for, >= 0. * @return the time value, in seconds. */ public double calculateTime( final int aSampleIndex ) { double timestamp = calculateTimeOffset( getTimestamps()[aSampleIndex] ); return ( timestamp / getSampleRate() ); }
/** * @see nl.lxtreme.ols.api.data.CapturedData#getTriggerPosition() */ @Override public long getTriggerPosition() { return hasCapturedData() && hasTriggerData() ? getAcquisitionData().getTriggerPosition() : Ols.NOT_AVAILABLE; }
/** * @see nl.lxtreme.ols.api.data.CapturedData#getSampleIndex(long) */ @Override public int getSampleIndex( final long aAbs ) { return hasCapturedData() ? getAcquisitionData().getSampleIndex( aAbs ) : Ols.NOT_AVAILABLE; }
final int blockCount = getBlockCount(); if ( ( aBlockNr < 0 ) || ( aBlockNr >= blockCount ) ) if ( aBlockNr == ( blockCount - 1 ) ) final int remainder = getChannels() % Ols.CHANNELS_PER_BLOCK; if ( remainder != 0 )
/** * Sets the channel label. * * @param aChannelIdx * the index of the channel to set the label for, >= 0 && < 32; * @param aLabel * the label to set, may be <code>null</code>. */ public void setChannelLabel( final int aChannelIdx, final String aLabel ) { if ( ( aChannelIdx < 0 ) || ( aChannelIdx > ( Ols.MAX_CHANNELS - 1 ) ) ) { throw new IllegalArgumentException( "Invalid channel index: " + aChannelIdx + "! Should be between 0 and " + Ols.MAX_CHANNELS ); } getAllChannels()[aChannelIdx].setLabel( aLabel ); }
/** * Returns all channel labels. * * @return an array of all channel's label, never <code>null</code>. */ public Channel[] getAllChannels() { return getCurrentDataSet().getChannels(); }
/** * Get position of a cursor. * * @param aCursorIdx * the index of the cursor to set, should be >= 0 and < 10. * @return a cursor position, or Long.MIN_VALUE if not set. * @throws IllegalArgumentException * in case an invalid cursor index was given. */ public Long getCursorPosition( final int aCursorIdx ) throws IllegalArgumentException { if ( ( aCursorIdx < 0 ) || ( aCursorIdx > ( Ols.MAX_CURSORS - 1 ) ) ) { throw new IllegalArgumentException( "Invalid cursor index: " + aCursorIdx + "! Should be between 0 and " + Ols.MAX_CURSORS ); } final Cursor[] cursorPositions = getCursors(); if ( ( cursorPositions == null ) || ( cursorPositions[aCursorIdx] == null ) ) { return null; } return Long.valueOf( cursorPositions[aCursorIdx].getTimestamp() ); }
/** * Returns whether any captured data is available. * * @return <code>true</code> if there is captured data, <code>false</code> * otherwise. */ public boolean hasCapturedData() { return getAcquisitionData() != null; }
/** * @see nl.lxtreme.ols.api.data.CapturedData#getValues() */ @Override public int[] getValues() { return hasCapturedData() ? getAcquisitionData().getValues() : new int[0]; }
/** * Sets all channel labels directly. * * @param aLabels * the array of labels to set, cannot be <code>null</code>. */ public void setChannelLabels( final String[] aLabels ) { if ( aLabels.length != Ols.MAX_CHANNELS ) { throw new IllegalArgumentException( "Invalid channel labels! Should have exact " + Ols.MAX_CHANNELS + " items!" ); } for ( int i = 0; i < aLabels.length; i++ ) { getAllChannels()[i].setLabel( aLabels[i] ); } }
/** * Returns the current acquisition results. * * @return the captured data, never <code>null</code>. */ private AcquisitionResult getAcquisitionData() { return getCurrentDataSet().getCapturedData(); }
/** * Returns whether or not the cursor with the given index is set. * * @param aCursorIdx * the index of the cursor to check, should be >= 0 and < 10. * @return <code>true</code> if the cursor with the given index is set, * <code>false</code> otherwise. */ public boolean isCursorPositionSet( final int aCursorIdx ) { if ( ( aCursorIdx < 0 ) || ( aCursorIdx > ( Ols.MAX_CURSORS - 1 ) ) ) { throw new IllegalArgumentException( "Invalid cursor index: " + aCursorIdx + "! Should be between 0 and " + Ols.MAX_CURSORS ); } final Cursor[] cursorPositions = getCursors(); if ( cursorPositions == null ) { return false; } return ( cursorPositions[aCursorIdx] != null ) && ( cursorPositions[aCursorIdx].isDefined() ); }
/** * Calculates the time offset * * @param aTime * the absolute sample number, >= 0. * @return time relative to data */ protected long calculateTimeOffset( final long aTime ) { final AcquisitionResult capturedData = getAcquisitionData(); if ( capturedData.hasTriggerData() ) { return aTime - capturedData.getTriggerPosition(); } return aTime; }
/** * @see nl.lxtreme.ols.api.data.CapturedData#getSampleRate() */ @Override public int getSampleRate() { return hasCapturedData() ? getAcquisitionData().getSampleRate() : Ols.NOT_AVAILABLE; }
/** * Returns the channel label. * * @param aChannelIdx * the index of the channel to retrieve the label for, >= 0 && < * {@value nl.lxtreme.ols.api.Ols#MAX_CHANNELS}. * @return the channel's label, can be <code>null</code>. */ public String getChannelLabel( final int aChannelIdx ) { if ( ( aChannelIdx < 0 ) || ( aChannelIdx > ( Ols.MAX_CHANNELS - 1 ) ) ) { throw new IllegalArgumentException( "Invalid channel index: " + aChannelIdx + "! Should be between 0 and " + Ols.MAX_CHANNELS ); } return getAllChannels()[aChannelIdx].getLabel(); }
/** * @return the cursorPositions */ private Cursor[] getCursors() { return getCurrentDataSet().getCursors(); } }
/** * Sets a cursor position. * * @param aCursorIdx * the index of the cursor to set, should be >= 0 and < 10; * @param aCursorPosition * the actual cursor position to set. * @throws IllegalArgumentException * in case an invalid cursor index was given. */ public void setCursorPosition( final int aCursorIdx, final Long aCursorPosition ) throws IllegalArgumentException { if ( ( aCursorIdx < 0 ) || ( aCursorIdx > ( Ols.MAX_CURSORS - 1 ) ) ) { throw new IllegalArgumentException( "Invalid cursor index! Should be between 0 and " + Ols.MAX_CURSORS ); } final Cursor[] cursorPositions = getCursors(); if ( cursorPositions != null ) { if ( ( aCursorPosition == null ) || ( aCursorPosition.longValue() == Long.MIN_VALUE ) ) { cursorPositions[aCursorIdx].clear(); } else { cursorPositions[aCursorIdx].setTimestamp( aCursorPosition.longValue() ); } } }
/** * @see nl.lxtreme.ols.api.data.CapturedData#getTimestamps() */ @Override public long[] getTimestamps() { return hasCapturedData() ? getAcquisitionData().getTimestamps() : new long[0]; }