Skip to content

Commit

Permalink
Minor cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawi committed Jun 27, 2011
1 parent 522b9b4 commit 882c35d
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 105 deletions.
36 changes: 35 additions & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>nl.lxtreme.ols</groupId>
<artifactId>api</artifactId>
<packaging>bundle</packaging>
<version>1.0.5-SNAPSHOT</version>
Expand Down Expand Up @@ -69,5 +68,40 @@
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-javadoc-plugin
</artifactId>
<versionRange>
[2.7,)
</versionRange>
<goals>
<goal>jar</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
1 change: 0 additions & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>nl.lxtreme.ols</groupId>
<artifactId>client</artifactId>
<packaging>bundle</packaging>
<version>1.2.0-SNAPSHOT</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ public void paint( final Graphics aCanvas, final JComponent aComponent )
}

final long start = System.currentTimeMillis();
LOG.log( Level.FINE, "Start diagram rendering = {0}ms.", Long.valueOf( start ) );
final Graphics2D canvas = ( Graphics2D )aCanvas;

// obtain portion of graphics that needs to be drawn
Expand Down Expand Up @@ -683,7 +682,7 @@ else if ( SignalAlignment.CENTER.equals( settings.getSignalAlignment() ) )
signalOffset = 1;
}

final double scopeScaleFactor = ( 256.0 / ( scopeHeight - 2 * PADDING_Y ) );
final double scopeScaleFactor = ( 256.0 / ( scopeHeight - ( 2 * PADDING_Y ) ) );

final double scale = aDiagram.getScale();

Expand Down Expand Up @@ -754,7 +753,7 @@ else if ( SignalAlignment.CENTER.equals( settings.getSignalAlignment() ) )
final Color newBrighterColor = signalColor.brighter();
final Color newDarkerColor = signalColor.darker().darker().darker();

final int py1 = channelHeight * bit + yofs;
final int py1 = ( channelHeight * bit ) + yofs;
// Paint the (optional) channel background...
paintChannelBackground( aCanvas, settings, aClipArea, channelIdx, py1 );

Expand All @@ -779,7 +778,7 @@ else if ( SignalAlignment.CENTER.equals( settings.getSignalAlignment() ) )
final long nextSample;

final int currentValue = ( values[dataIndex] >> channelIdx ) & 0x01;
if ( dataIndex >= values.length - 1 )
if ( dataIndex >= ( values.length - 1 ) )
{
nextSample = aToIndex + 1;
}
Expand Down Expand Up @@ -826,7 +825,7 @@ else if ( SignalAlignment.CENTER.equals( settings.getSignalAlignment() ) )

final int x1 = ( int )( scale * startIdx );
final int x2 = ( int )( scale * endIdx );
final int y1 = yofs + channelHeight * channelIdx;
final int y1 = yofs + ( channelHeight * channelIdx );

final int textWidth = fm.stringWidth( data );

Expand Down Expand Up @@ -859,7 +858,7 @@ else if ( SignalAlignment.CENTER.equals( settings.getSignalAlignment() ) )
}
}

paintGridLine( aCanvas, aDiagram, aClipArea, channelHeight * bit + yofs + ( channelHeight - 1 ) );
paintGridLine( aCanvas, aDiagram, aClipArea, ( channelHeight * bit ) + yofs + ( channelHeight - 1 ) );
}
yofs += ( channelHeight * Ols.CHANNELS_PER_BLOCK );
}
Expand Down Expand Up @@ -919,7 +918,7 @@ else if ( SignalAlignment.CENTER.equals( settings.getSignalAlignment() ) )
final long nextSample;

final int currentValue = ( values[dataIndex] >> channelsOffset ) & 0xff;
if ( dataIndex >= values.length - 1 )
if ( dataIndex >= ( values.length - 1 ) )
{
nextSample = aToIndex + 1;
}
Expand All @@ -929,12 +928,12 @@ else if ( SignalAlignment.CENTER.equals( settings.getSignalAlignment() ) )
}

// Calculate display coordinates...
final int x1 = ( int )( scale * currentSample - edgeX );
final int x2 = ( int )( scale * ( nextSample - 1 ) + edgeX );
final int x1 = ( int )( ( scale * currentSample ) - edgeX );
final int x2 = ( int )( ( scale * ( nextSample - 1 ) ) + edgeX );

final int bit = ( dataIndex % 2 );
final int y1 = yofs + signalHeight * ( 1 - bit ) + signalOffset;
final int y2 = yofs + signalHeight * bit + signalOffset;
final int y1 = yofs + ( signalHeight * ( 1 - bit ) ) + signalOffset;
final int y2 = yofs + ( signalHeight * bit ) + signalOffset;

bytePolyline.x[pIdx] = x1;
bytePolyline.y1[pIdx] = y1;
Expand All @@ -950,7 +949,7 @@ else if ( SignalAlignment.CENTER.equals( settings.getSignalAlignment() ) )

if ( ( x2 - x1 ) > labelWidth )
{
final int labelXpos = ( int )( ( x1 + x2 - labelWidth ) / 2.0 );
final int labelXpos = ( int )( ( ( x1 + x2 ) - labelWidth ) / 2.0 );

aCanvas.setColor( settings.getTextColor() );
aCanvas.drawString( byteValue, labelXpos, yofs + ( fontHeight + signalOffset ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.io.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.logging.*;

import javax.microedition.io.*;
Expand Down Expand Up @@ -471,70 +470,36 @@ public void selfTest() throws IOException
public void stop()
{
final boolean isRleEnabled = this.config.isRleEnabled();

Runnable stopTask = new Runnable()
try
{
@Override
public void run()
if ( !isCancelledOrStopped() )
{
try
if ( isRleEnabled )
{
if ( !isCancelledOrStopped() )
{
if ( isRleEnabled )
{
LOG.info( "Prematurely finishing RLE-enabled capture ..." );
sendCommand( CMD_RLE_FINISH_NOW );
}
else
{
LOG.info( "Prematurely finishing normal capture ..." );
resetDevice();
}
}
else
{
// Hmm, really abort this upon request of the user...
cancel( true );
}

// Flag we're being cancelled...
LogicSnifferDevice.this.stopped = true;
LOG.info( "Prematurely finishing RLE-enabled capture ..." );
sendCommand( CMD_RLE_FINISH_NOW );
}
catch ( IOException exception )
else
{
if ( !HostUtils.handleInterruptedException( exception ) )
{
LOG.log( Level.WARNING, "Stopping capture failed?!", exception );
}
LOG.info( "Prematurely finishing normal capture ..." );
resetDevice();
}
}
};

// Invoke this *asynchronously* otherwise we're blocking ourselves...
final ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute( stopTask );

try
{
executor.awaitTermination( 500L, TimeUnit.MILLISECONDS );
}
catch ( InterruptedException exception )
{
if ( !HostUtils.handleInterruptedException( exception ) )
else
{
Thread.currentThread().interrupt();
exception.printStackTrace();
// Hmm, really abort this upon request of the user...
cancel( true );
}

// Flag we're being cancelled...
this.stopped = true;
}
finally
catch ( IOException exception )
{
executor.shutdown();
while ( !executor.isTerminated() )
if ( !HostUtils.handleInterruptedException( exception ) )
{

LOG.log( Level.WARNING, "Stopping capture failed?!", exception );
}
LOG.info( "Shutting down stop-executor..." );
}
}

Expand Down Expand Up @@ -795,7 +760,7 @@ synchronized void detach()
}
catch ( IOException exception )
{
LOG.log( Level.FINE, "Closing connection failed!", exception );
LOG.log( Level.WARNING, "Closing connection failed!", exception );
}
finally
{
Expand All @@ -808,7 +773,7 @@ synchronized void detach()
}

/**
* Reads a single sample from the serial input stream.
* Reads a single sample (= 1..4 bytes) from the serial input stream.
* <p>
* This method will take the enabled channel groups into consideration, making
* it possible that the returned value contains "gaps".
Expand All @@ -821,50 +786,41 @@ synchronized void detach()
*/
final int readSample() throws IOException, InterruptedException
{
final int baseTimeout = 1000; // 1 second

int v, value = 0;
int timeout = 4 * baseTimeout;
final int groupCount = this.config.getGroupCount();
byte[] buf = new byte[groupCount];

// if data not available here, client will stall until stop button pressed
final int enabledGroupCount = this.config.getEnabledGroupCount();
while ( !isCancelled() && ( this.inputStream.available() < enabledGroupCount ) && ( timeout-- >= 0 ) )
{
// Wait until there's data available, otherwise we could get 'false'
// timeouts; do not make the sleep too long, otherwise we might overflow
// our
// receiver buffers...
TimeUnit.MICROSECONDS.sleep( 25L );
}
if ( timeout < 0 )
assert enabledGroupCount > 0 : "Internal error: enabled group count should be at least 1!";
assert enabledGroupCount <= groupCount : "Internal error: enabled group count be at most " + groupCount;

int read, offset = 0;
do
{
// Flag this read as incomplete...
LOG.log( Level.INFO,
"Read sample timeout occurred (no response within {0} milliseconds)! Capture will continue...",
Integer.valueOf( baseTimeout ) );
throw new InterruptedException();
read = this.inputStream.read( buf, offset, enabledGroupCount );
if ( read < 0 )
{
throw new IOException( "Data readout interrupted: EOF." );
}
if ( Thread.interrupted() )
{
throw new InterruptedException( "Data readout interrupted." );
}
offset += read;
}
while ( offset < enabledGroupCount );

final int groupCount = this.config.getGroupCount();
for ( int i = 0; !isCancelled() && ( i < groupCount ); i++ )
{
v = 0; // in case the group is disabled, simply set it to zero...
// "Expand" the read sample-bytes into a single sample value...
int value = 0;

for ( int i = 0, j = 0; i < groupCount; i++ )
{
// in case the group is disabled, simply set it to zero...
if ( this.config.isGroupEnabled( i ) )
{
v = this.inputStream.read();
// Any timeouts/interrupts occurred?
if ( v < 0 )
{
throw new InterruptedException( "Data readout interrupted: EOF." );
}
else if ( Thread.interrupted() )
{
throw new InterruptedException( "Data readout interrupted." );
}
value |= ( ( buf[j++] & 0xff ) << ( 8 * i ) );
}
value |= v << ( 8 * i );
}

return value;
}

Expand All @@ -891,7 +847,7 @@ final String readString() throws IOException, InterruptedException
// set is a subset of UTF-8...
sb.append( ( char )read );
}
else if ( Thread.interrupted() )
if ( Thread.interrupted() )
{
throw new InterruptedException( "Data readout interrupted!" );
}
Expand Down Expand Up @@ -1052,7 +1008,7 @@ protected AcquisitionResult doInBackground() throws Exception
for ( ; ( sampleIdx >= 0 ) && !isCancelled(); sampleIdx-- )
{
buffer[sampleIdx] = readSample();
setProgress( 100 - ( 100 * sampleIdx ) / buffer.length );
setProgress( 100 - ( ( 100 * sampleIdx ) / buffer.length ) );
}
}
catch ( InterruptedException exception )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected synchronized StreamConnection getConnection( final String aPortName, f
"comm:%s;baudrate=%d;bitsperchar=8;parity=none;stopbits=1;flowcontrol=xon_xoff;dtr=%s", aPortName,
Integer.valueOf( aPortRate ), ( aDtrValue ? "on" : "off" ) );

return ( StreamConnection )connectorService.open( portUri, ConnectorService.READ_WRITE, false /* timeouts */);
return ( StreamConnection )connectorService.open( portUri, ConnectorService.READ_WRITE, true /* timeouts */);
}
finally
{
Expand Down
Loading

0 comments on commit 882c35d

Please sign in to comment.