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 name="compile" depends="init">
<javac srcdir="${java}" destdir="${build}">
<javac srcdir="${java}" destdir="${build}" debug="true">
<classpath>
<fileset dir="${lib}">
<include name="**/*.jar"/>
@ -45,6 +45,7 @@
<fileset dir="${contiki}/tools/sky"/>
</copy>
<copy file="${contiki}/tools/cygwin/cygwin1.dll" todir="${dist}/tools"/>
<chmod dir="${dist}/tools" perm="a+x" includes="**/*"/>
</target>
<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
* 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
* Created : 3 jul 2008
* Updated : $Date: 2008/08/29 10:00:23 $
* $Revision: 1.7 $
* Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.8 $
*/
package se.sics.contiki.collect;
@ -999,7 +999,7 @@ public class CollectServer {
mp.setParentComponent(window);
mp.setFirmwareFile(FIRMWARE_FILE);
mp.searchForMotes();
int[] motes = mp.getMotes();
String[] motes = mp.getMotes();
if (motes == null || motes.length == 0) {
JOptionPane.showMessageDialog(window, "Could not find any connected Sky nodes", "Error", JOptionPane.ERROR_MESSAGE);
return;

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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
* Created : 4 jul 2008
* Updated : $Date: 2008/07/09 23:18:06 $
* $Revision: 1.1 $
* Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.2 $
*/
package se.sics.contiki.collect;
@ -57,17 +57,19 @@ public class MoteFinder {
public static final String MOTELIST_LINUX = "./tools/motelist-linux";
private final Pattern motePattern;
private final boolean isWindows;
private Process moteListProcess;
// private boolean hasVerifiedProcess;
private ArrayList<String> comList = new ArrayList<String>();
private int[] moteList = new int[10];
private int moteCount = 0;
private ArrayList<String> moteList = new ArrayList<String>();
public MoteFinder() {
String osName = System.getProperty("os.name", "").toLowerCase();
isWindows = osName.startsWith("win");
motePattern = Pattern.compile("\\s(COM|/dev/[a-zA-Z]+)(\\d+)\\s");
}
public int[] getMotes() throws IOException {
public String[] getMotes() throws IOException {
searchForMotes();
return getMoteList();
}
@ -79,13 +81,12 @@ public class MoteFinder {
private void searchForMotes() throws IOException {
comList.clear();
moteCount = 0;
moteList.clear();
// hasVerifiedProcess = false;
/* Connect to COM using external serialdump application */
String osName = System.getProperty("os.name").toLowerCase();
String fullCommand;
if (osName.startsWith("win")) {
if (isWindows) {
fullCommand = MOTELIST_WINDOWS;
} else {
fullCommand = MOTELIST_LINUX;
@ -123,8 +124,7 @@ public class MoteFinder {
}
err.close();
} catch (IOException e) {
System.err.println("Exception when reading from motelist");
e.printStackTrace();
System.err.println("Exception when reading from motelist error stream: " + e);
}
}
}, "read motelist error stream thread");
@ -143,13 +143,8 @@ public class MoteFinder {
return comList.toArray(new String[comList.size()]);
}
private int[] getMoteList() {
if (moteCount < moteList.length) {
int[] tmp = new int[moteCount];
System.arraycopy(moteList, 0, tmp, 0, tmp.length);
moteList = tmp;
}
return moteList;
private String[] getMoteList() {
return moteList.toArray(new String[moteList.size()]);
}
public void close() {
@ -168,13 +163,17 @@ public class MoteFinder {
} else {
Matcher matcher = motePattern.matcher(line);
if (matcher.find()) {
if (moteCount == moteList.length) {
int[] tmp = new int[moteCount + 10];
System.arraycopy(moteList, 0, tmp, 0, moteCount);
moteList = tmp;
String dev = matcher.group(1);
String no = matcher.group(2);
String comPort = dev + no;
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));
moteList[moteCount++] = Integer.parseInt(matcher.group(2));
comList.add(comPort);
moteList.add(moteID);
} else {
System.err.println("Motelist> " + line);
}
@ -208,12 +207,13 @@ public class MoteFinder {
public static void main(String[] args) throws IOException {
MoteFinder finder = new MoteFinder();
String[] motes = finder.getComPorts();
String[] comPorts = args.length > 0 && "-v".equals(args[0]) ?
finder.getMotes() : finder.getComPorts();
finder.close();
if (motes == null || motes.length == 0) {
if (comPorts == null || comPorts.length == 0) {
System.out.println("No motes connected");
} else {
for(String port: motes) {
for(String port: comPorts) {
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
* 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
* Created : 10 jul 2008
* Updated : $Date: 2008/07/10 14:52:59 $
* $Revision: 1.1 $
* Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.2 $
*/
package se.sics.contiki.collect;
@ -48,6 +48,7 @@ import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
@ -58,10 +59,11 @@ import javax.swing.SwingUtilities;
public class MoteProgrammer {
private MoteProgrammerProcess[] processes;
private int[] motes;
private String[] motes;
private String firmwareFile;
private Window parent;
private JProgressBar progressBar;
protected JTextArea logTextArea;
protected JDialog dialog;
protected JButton closeButton;
@ -82,11 +84,11 @@ public class MoteProgrammer {
return motes != null && motes.length > 0;
}
public int[] getMotes() {
public String[] getMotes() {
return motes;
}
public void setMotes(int[] motes) {
public void setMotes(String[] motes) {
this.motes = motes;
}
@ -118,6 +120,13 @@ public class MoteProgrammer {
if (parent != null) {
// Use GUI
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.setEditable(false);
logTextArea.setLineWrap(true);
@ -190,7 +199,7 @@ public class MoteProgrammer {
protected void handleProcessEnded(MoteProgrammerProcess process) {
// 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;
if (processes != null) {
int running = 0;
@ -205,11 +214,14 @@ public class MoteProgrammer {
if (running == 0) {
// All processes has finished
isDone = true;
log("Programming finished with " + errors + " errors.", null);
final String doneMessage = "Programming finished with " + errors + " errors.";
log(doneMessage, null);
if (closeButton != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
progressBar.setValue(100);
progressBar.setIndeterminate(false);
progressBar.setString(doneMessage);
closeButton.setText("Close");
}});
}
@ -222,7 +234,7 @@ public class MoteProgrammer {
protected boolean handleLogLine(MoteProgrammerProcess moteProgrammerProcess,
String line, boolean stderr, final Throwable e) {
log("Mote@" + moteProgrammerProcess.getMote() + "> " + line, e);
log("Mote@" + moteProgrammerProcess.getMoteID() + "> " + line, e);
return true;
}
@ -255,7 +267,7 @@ public class MoteProgrammer {
}
mp.setFirmwareFile(args[0]);
if (args.length == 2) {
mp.setMotes(new int[] { Integer.parseInt(args[1]) });
mp.setMotes(new String[] { args[1] });
} else {
mp.searchForMotes();
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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
* Created : 10 jul 2008
* Updated : $Date: 2008/07/10 14:52:59 $
* $Revision: 1.1 $
* Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.2 $
*/
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_LINUX = "./tools/msp430-bsl-linux";
private final int mote;
private final String moteID;
private final String firmwareFile;
private final String[][] commandSet;
@ -62,9 +61,8 @@ public class MoteProgrammerProcess {
private boolean isRunning;
private boolean hasError;
public MoteProgrammerProcess(int mote, String firmwareFile) {
this.mote = mote;
this.moteID = "" + (mote - 1);
public MoteProgrammerProcess(String moteID, String firmwareFile) {
this.moteID = moteID;
this.firmwareFile = firmwareFile;
String osName = System.getProperty("os.name").toLowerCase();
String bslCommand;
@ -80,8 +78,8 @@ public class MoteProgrammerProcess {
};
}
public int getMote() {
return mote;
public String getMoteID() {
return moteID;
}
public String getFirmwareFile() {
@ -208,9 +206,9 @@ public class MoteProgrammerProcess {
protected void logLine(String line, boolean stderr, Throwable e) {
if (stderr) {
System.err.println("Programmer@" + mote + "> " + line);
System.err.println("Programmer@" + moteID + "> " + line);
} else {
System.out.println("Programmer@" + mote + "> " + line);
System.out.println("Programmer@" + moteID + "> " + line);
}
if (e != null) {
e.printStackTrace();

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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
* Created : 5 jul 2008
* Updated : $Date: 2008/07/10 14:52:59 $
* $Revision: 1.2 $
* Updated : $Date: 2008/09/03 13:35:21 $
* $Revision: 1.3 $
*/
package se.sics.contiki.collect;
@ -115,8 +115,10 @@ public abstract class SerialConnection {
} catch (IOException e) {
lastError = "Error when reading from serialdump process: " + e;
System.err.println(lastError);
e.printStackTrace();
closeConnection();
if (!isClosed) {
e.printStackTrace();
closeConnection();
}
}
}
}, "read input stream thread");
@ -136,8 +138,10 @@ public abstract class SerialConnection {
}
err.close();
} catch (IOException e) {
System.err.println("Error when reading from serialdump process: " + e);
e.printStackTrace();
if (!isClosed) {
System.err.println("Error when reading from serialdump process: " + e);
e.printStackTrace();
}
}
}
}, "read error stream thread");