From 882c35dcd8a49a674d231dfa7c6bb5da984b2d6f Mon Sep 17 00:00:00 2001 From: JaWi Date: Mon, 27 Jun 2011 21:41:47 +0200 Subject: [PATCH] Minor cleanups. --- api/pom.xml | 36 ++++- client/pom.xml | 1 - .../ols/client/diagram/laf/DiagramUI.java | 23 ++- .../logicsniffer/LogicSnifferDevice.java | 136 ++++++------------ .../LogicSnifferDeviceController.java | 2 +- test.util/pom.xml | 35 +++++ tool.base/pom.xml | 35 +++++ util/pom.xml | 35 +++++ 8 files changed, 198 insertions(+), 105 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index fc90a25f..9c98ebb1 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,6 @@ parent 1.0.0 - nl.lxtreme.ols api bundle 1.0.5-SNAPSHOT @@ -69,5 +68,40 @@ + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-javadoc-plugin + + + [2.7,) + + + jar + + + + + + + + + + + + diff --git a/client/pom.xml b/client/pom.xml index d4d180a3..d3019d31 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -6,7 +6,6 @@ parent 1.0.0 - nl.lxtreme.ols client bundle 1.2.0-SNAPSHOT diff --git a/client/src/main/java/nl/lxtreme/ols/client/diagram/laf/DiagramUI.java b/client/src/main/java/nl/lxtreme/ols/client/diagram/laf/DiagramUI.java index 5efde33d..eb3e2919 100644 --- a/client/src/main/java/nl/lxtreme/ols/client/diagram/laf/DiagramUI.java +++ b/client/src/main/java/nl/lxtreme/ols/client/diagram/laf/DiagramUI.java @@ -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 @@ -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(); @@ -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 ); @@ -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; } @@ -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 ); @@ -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 ); } @@ -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; } @@ -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; @@ -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 ) ); diff --git a/device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferDevice.java b/device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferDevice.java index 470947f1..88775382 100644 --- a/device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferDevice.java +++ b/device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferDevice.java @@ -23,7 +23,6 @@ import java.io.*; import java.util.*; -import java.util.concurrent.*; import java.util.logging.*; import javax.microedition.io.*; @@ -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..." ); } } @@ -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 { @@ -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. *

* This method will take the enabled channel groups into consideration, making * it possible that the returned value contains "gaps". @@ -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; } @@ -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!" ); } @@ -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 ) diff --git a/device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferDeviceController.java b/device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferDeviceController.java index f4a6ad86..ea686375 100644 --- a/device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferDeviceController.java +++ b/device.logicsniffer/src/main/java/org/sump/device/logicsniffer/LogicSnifferDeviceController.java @@ -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 { diff --git a/test.util/pom.xml b/test.util/pom.xml index e9a13b8e..9f3cc46f 100644 --- a/test.util/pom.xml +++ b/test.util/pom.xml @@ -43,5 +43,40 @@ + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-javadoc-plugin + + + [2.7,) + + + jar + + + + + + + + + + + + diff --git a/tool.base/pom.xml b/tool.base/pom.xml index 8d20f146..4e7389cf 100644 --- a/tool.base/pom.xml +++ b/tool.base/pom.xml @@ -58,5 +58,40 @@ + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-javadoc-plugin + + + [2.7,) + + + jar + + + + + + + + + + + + diff --git a/util/pom.xml b/util/pom.xml index b08c03f0..810282f0 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -70,5 +70,40 @@ + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-javadoc-plugin + + + [2.7,) + + + jar + + + + + + + + + + + +