Fixed problem with programming Sky nodes using the Java interface under Linux

This commit is contained in:
nifi 2008-09-03 13:35:21 +00:00
parent cad6109cf4
commit 4206ff28a2
6 changed files with 76 additions and 61 deletions

View file

@ -15,7 +15,7 @@
</target> </target>
<target name="compile" depends="init"> <target name="compile" depends="init">
<javac srcdir="${java}" destdir="${build}"> <javac srcdir="${java}" destdir="${build}" debug="true">
<classpath> <classpath>
<fileset dir="${lib}"> <fileset dir="${lib}">
<include name="**/*.jar"/> <include name="**/*.jar"/>
@ -45,6 +45,7 @@
<fileset dir="${contiki}/tools/sky"/> <fileset dir="${contiki}/tools/sky"/>
</copy> </copy>
<copy file="${contiki}/tools/cygwin/cygwin1.dll" todir="${dist}/tools"/> <copy file="${contiki}/tools/cygwin/cygwin1.dll" todir="${dist}/tools"/>
<chmod dir="${dist}/tools" perm="a+x" includes="**/*"/>
</target> </target>
<target name="run" depends="dist"> <target name="run" depends="dist">

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: CollectServer.java,v 1.7 2008/08/29 10:00:23 nifi Exp $ * $Id: CollectServer.java,v 1.8 2008/09/03 13:35:21 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2008/08/29 10:00:23 $ * Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.7 $ * $Revision: 1.8 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -999,7 +999,7 @@ public class CollectServer {
mp.setParentComponent(window); mp.setParentComponent(window);
mp.setFirmwareFile(FIRMWARE_FILE); mp.setFirmwareFile(FIRMWARE_FILE);
mp.searchForMotes(); mp.searchForMotes();
int[] motes = mp.getMotes(); String[] motes = mp.getMotes();
if (motes == null || motes.length == 0) { if (motes == null || motes.length == 0) {
JOptionPane.showMessageDialog(window, "Could not find any connected Sky nodes", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(window, "Could not find any connected Sky nodes", "Error", JOptionPane.ERROR_MESSAGE);
return; return;

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MoteFinder.java,v 1.1 2008/07/09 23:18:06 nifi Exp $ * $Id: MoteFinder.java,v 1.2 2008/09/03 13:35:21 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 4 jul 2008 * Created : 4 jul 2008
* Updated : $Date: 2008/07/09 23:18:06 $ * Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.1 $ * $Revision: 1.2 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -57,17 +57,19 @@ public class MoteFinder {
public static final String MOTELIST_LINUX = "./tools/motelist-linux"; public static final String MOTELIST_LINUX = "./tools/motelist-linux";
private final Pattern motePattern; private final Pattern motePattern;
private final boolean isWindows;
private Process moteListProcess; private Process moteListProcess;
// private boolean hasVerifiedProcess; // private boolean hasVerifiedProcess;
private ArrayList<String> comList = new ArrayList<String>(); private ArrayList<String> comList = new ArrayList<String>();
private int[] moteList = new int[10]; private ArrayList<String> moteList = new ArrayList<String>();
private int moteCount = 0;
public MoteFinder() { public MoteFinder() {
String osName = System.getProperty("os.name", "").toLowerCase();
isWindows = osName.startsWith("win");
motePattern = Pattern.compile("\\s(COM|/dev/[a-zA-Z]+)(\\d+)\\s"); motePattern = Pattern.compile("\\s(COM|/dev/[a-zA-Z]+)(\\d+)\\s");
} }
public int[] getMotes() throws IOException { public String[] getMotes() throws IOException {
searchForMotes(); searchForMotes();
return getMoteList(); return getMoteList();
} }
@ -79,13 +81,12 @@ public class MoteFinder {
private void searchForMotes() throws IOException { private void searchForMotes() throws IOException {
comList.clear(); comList.clear();
moteCount = 0; moteList.clear();
// hasVerifiedProcess = false; // hasVerifiedProcess = false;
/* Connect to COM using external serialdump application */ /* Connect to COM using external serialdump application */
String osName = System.getProperty("os.name").toLowerCase();
String fullCommand; String fullCommand;
if (osName.startsWith("win")) { if (isWindows) {
fullCommand = MOTELIST_WINDOWS; fullCommand = MOTELIST_WINDOWS;
} else { } else {
fullCommand = MOTELIST_LINUX; fullCommand = MOTELIST_LINUX;
@ -123,8 +124,7 @@ public class MoteFinder {
} }
err.close(); err.close();
} catch (IOException e) { } catch (IOException e) {
System.err.println("Exception when reading from motelist"); System.err.println("Exception when reading from motelist error stream: " + e);
e.printStackTrace();
} }
} }
}, "read motelist error stream thread"); }, "read motelist error stream thread");
@ -143,13 +143,8 @@ public class MoteFinder {
return comList.toArray(new String[comList.size()]); return comList.toArray(new String[comList.size()]);
} }
private int[] getMoteList() { private String[] getMoteList() {
if (moteCount < moteList.length) { return moteList.toArray(new String[moteList.size()]);
int[] tmp = new int[moteCount];
System.arraycopy(moteList, 0, tmp, 0, tmp.length);
moteList = tmp;
}
return moteList;
} }
public void close() { public void close() {
@ -168,13 +163,17 @@ public class MoteFinder {
} else { } else {
Matcher matcher = motePattern.matcher(line); Matcher matcher = motePattern.matcher(line);
if (matcher.find()) { if (matcher.find()) {
if (moteCount == moteList.length) { String dev = matcher.group(1);
int[] tmp = new int[moteCount + 10]; String no = matcher.group(2);
System.arraycopy(moteList, 0, tmp, 0, moteCount); String comPort = dev + no;
moteList = tmp; String moteID = comPort;
if (isWindows) {
// Special handling of mote id under Windows
int moteNumber = Integer.parseInt(no);
moteID = Integer.toString(moteNumber - 1);
} }
comList.add(matcher.group(1) + matcher.group(2)); comList.add(comPort);
moteList[moteCount++] = Integer.parseInt(matcher.group(2)); moteList.add(moteID);
} else { } else {
System.err.println("Motelist> " + line); System.err.println("Motelist> " + line);
} }
@ -208,12 +207,13 @@ public class MoteFinder {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
MoteFinder finder = new MoteFinder(); MoteFinder finder = new MoteFinder();
String[] motes = finder.getComPorts(); String[] comPorts = args.length > 0 && "-v".equals(args[0]) ?
finder.getMotes() : finder.getComPorts();
finder.close(); finder.close();
if (motes == null || motes.length == 0) { if (comPorts == null || comPorts.length == 0) {
System.out.println("No motes connected"); System.out.println("No motes connected");
} else { } else {
for(String port: motes) { for(String port: comPorts) {
System.out.println("Found Sky at " + port); System.out.println("Found Sky at " + port);
} }
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MoteProgrammer.java,v 1.1 2008/07/10 14:52:59 nifi Exp $ * $Id: MoteProgrammer.java,v 1.2 2008/09/03 13:35:21 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 10 jul 2008 * Created : 10 jul 2008
* Updated : $Date: 2008/07/10 14:52:59 $ * Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.1 $ * $Revision: 1.2 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -48,6 +48,7 @@ import java.io.IOException;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -58,10 +59,11 @@ import javax.swing.SwingUtilities;
public class MoteProgrammer { public class MoteProgrammer {
private MoteProgrammerProcess[] processes; private MoteProgrammerProcess[] processes;
private int[] motes; private String[] motes;
private String firmwareFile; private String firmwareFile;
private Window parent; private Window parent;
private JProgressBar progressBar;
protected JTextArea logTextArea; protected JTextArea logTextArea;
protected JDialog dialog; protected JDialog dialog;
protected JButton closeButton; protected JButton closeButton;
@ -82,11 +84,11 @@ public class MoteProgrammer {
return motes != null && motes.length > 0; return motes != null && motes.length > 0;
} }
public int[] getMotes() { public String[] getMotes() {
return motes; return motes;
} }
public void setMotes(int[] motes) { public void setMotes(String[] motes) {
this.motes = motes; this.motes = motes;
} }
@ -118,6 +120,13 @@ public class MoteProgrammer {
if (parent != null) { if (parent != null) {
// Use GUI // Use GUI
dialog = new JDialog(parent, "Mote Programmer"); dialog = new JDialog(parent, "Mote Programmer");
progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setString("Programming...");
progressBar.setStringPainted(true);
progressBar.setIndeterminate(true);
dialog.getContentPane().add(progressBar, BorderLayout.NORTH);
logTextArea = new JTextArea(28, 80); logTextArea = new JTextArea(28, 80);
logTextArea.setEditable(false); logTextArea.setEditable(false);
logTextArea.setLineWrap(true); logTextArea.setLineWrap(true);
@ -190,7 +199,7 @@ public class MoteProgrammer {
protected void handleProcessEnded(MoteProgrammerProcess process) { protected void handleProcessEnded(MoteProgrammerProcess process) {
// Another process has finished // Another process has finished
log("Mote@" + process.getMote() + "> finished" + (process.hasError() ? " with errors": ""), null); log("Mote@" + process.getMoteID() + "> finished" + (process.hasError() ? " with errors": ""), null);
MoteProgrammerProcess[] processes = this.processes; MoteProgrammerProcess[] processes = this.processes;
if (processes != null) { if (processes != null) {
int running = 0; int running = 0;
@ -205,11 +214,14 @@ public class MoteProgrammer {
if (running == 0) { if (running == 0) {
// All processes has finished // All processes has finished
isDone = true; isDone = true;
final String doneMessage = "Programming finished with " + errors + " errors.";
log("Programming finished with " + errors + " errors.", null); log(doneMessage, null);
if (closeButton != null) { if (closeButton != null) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
progressBar.setValue(100);
progressBar.setIndeterminate(false);
progressBar.setString(doneMessage);
closeButton.setText("Close"); closeButton.setText("Close");
}}); }});
} }
@ -222,7 +234,7 @@ public class MoteProgrammer {
protected boolean handleLogLine(MoteProgrammerProcess moteProgrammerProcess, protected boolean handleLogLine(MoteProgrammerProcess moteProgrammerProcess,
String line, boolean stderr, final Throwable e) { String line, boolean stderr, final Throwable e) {
log("Mote@" + moteProgrammerProcess.getMote() + "> " + line, e); log("Mote@" + moteProgrammerProcess.getMoteID() + "> " + line, e);
return true; return true;
} }
@ -255,7 +267,7 @@ public class MoteProgrammer {
} }
mp.setFirmwareFile(args[0]); mp.setFirmwareFile(args[0]);
if (args.length == 2) { if (args.length == 2) {
mp.setMotes(new int[] { Integer.parseInt(args[1]) }); mp.setMotes(new String[] { args[1] });
} else { } else {
mp.searchForMotes(); mp.searchForMotes();
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MoteProgrammerProcess.java,v 1.1 2008/07/10 14:52:59 nifi Exp $ * $Id: MoteProgrammerProcess.java,v 1.2 2008/09/03 13:35:21 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 10 jul 2008 * Created : 10 jul 2008
* Updated : $Date: 2008/07/10 14:52:59 $ * Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.1 $ * $Revision: 1.2 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -51,7 +51,6 @@ public class MoteProgrammerProcess {
public static final String BSL_WINDOWS = "./tools/msp430-bsl-windows.exe"; public static final String BSL_WINDOWS = "./tools/msp430-bsl-windows.exe";
public static final String BSL_LINUX = "./tools/msp430-bsl-linux"; public static final String BSL_LINUX = "./tools/msp430-bsl-linux";
private final int mote;
private final String moteID; private final String moteID;
private final String firmwareFile; private final String firmwareFile;
private final String[][] commandSet; private final String[][] commandSet;
@ -62,9 +61,8 @@ public class MoteProgrammerProcess {
private boolean isRunning; private boolean isRunning;
private boolean hasError; private boolean hasError;
public MoteProgrammerProcess(int mote, String firmwareFile) { public MoteProgrammerProcess(String moteID, String firmwareFile) {
this.mote = mote; this.moteID = moteID;
this.moteID = "" + (mote - 1);
this.firmwareFile = firmwareFile; this.firmwareFile = firmwareFile;
String osName = System.getProperty("os.name").toLowerCase(); String osName = System.getProperty("os.name").toLowerCase();
String bslCommand; String bslCommand;
@ -80,8 +78,8 @@ public class MoteProgrammerProcess {
}; };
} }
public int getMote() { public String getMoteID() {
return mote; return moteID;
} }
public String getFirmwareFile() { public String getFirmwareFile() {
@ -208,9 +206,9 @@ public class MoteProgrammerProcess {
protected void logLine(String line, boolean stderr, Throwable e) { protected void logLine(String line, boolean stderr, Throwable e) {
if (stderr) { if (stderr) {
System.err.println("Programmer@" + mote + "> " + line); System.err.println("Programmer@" + moteID + "> " + line);
} else { } else {
System.out.println("Programmer@" + mote + "> " + line); System.out.println("Programmer@" + moteID + "> " + line);
} }
if (e != null) { if (e != null) {
e.printStackTrace(); e.printStackTrace();

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: SerialConnection.java,v 1.2 2008/07/10 14:52:59 nifi Exp $ * $Id: SerialConnection.java,v 1.3 2008/09/03 13:35:21 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 5 jul 2008 * Created : 5 jul 2008
* Updated : $Date: 2008/07/10 14:52:59 $ * Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.2 $ * $Revision: 1.3 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -115,10 +115,12 @@ public abstract class SerialConnection {
} catch (IOException e) { } catch (IOException e) {
lastError = "Error when reading from serialdump process: " + e; lastError = "Error when reading from serialdump process: " + e;
System.err.println(lastError); System.err.println(lastError);
if (!isClosed) {
e.printStackTrace(); e.printStackTrace();
closeConnection(); closeConnection();
} }
} }
}
}, "read input stream thread"); }, "read input stream thread");
/* Start thread listening on stderr */ /* Start thread listening on stderr */
@ -136,10 +138,12 @@ public abstract class SerialConnection {
} }
err.close(); err.close();
} catch (IOException e) { } catch (IOException e) {
if (!isClosed) {
System.err.println("Error when reading from serialdump process: " + e); System.err.println("Error when reading from serialdump process: " + e);
e.printStackTrace(); e.printStackTrace();
} }
} }
}
}, "read error stream thread"); }, "read error stream thread");
readInput.start(); readInput.start();