added configurable environment + other minor changes
This commit is contained in:
parent
c0bdeed635
commit
e1baf890e4
1 changed files with 47 additions and 9 deletions
|
@ -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: AbstractCompileDialog.java,v 1.1 2009/03/09 13:58:12 fros4943 Exp $
|
* $Id: AbstractCompileDialog.java,v 1.2 2009/03/10 21:13:07 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.dialogs;
|
package se.sics.cooja.dialogs;
|
||||||
|
@ -76,11 +76,12 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
|
|
||||||
protected Simulation simulation;
|
protected Simulation simulation;
|
||||||
protected GUI gui;
|
protected GUI gui;
|
||||||
|
protected MoteType moteType;
|
||||||
|
|
||||||
protected JTabbedPane tabbedPane;
|
protected JTabbedPane tabbedPane;
|
||||||
protected Box moteIntfBox;
|
protected Box moteIntfBox;
|
||||||
|
|
||||||
private JTextField contikiField;
|
protected JTextField contikiField;
|
||||||
private JTextField descriptionField;
|
private JTextField descriptionField;
|
||||||
private JTextArea commandsArea;
|
private JTextArea commandsArea;
|
||||||
private JButton nextButton;
|
private JButton nextButton;
|
||||||
|
@ -100,6 +101,7 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
|
|
||||||
this.simulation = simulation;
|
this.simulation = simulation;
|
||||||
this.gui = simulation.getGUI();
|
this.gui = simulation.getGUI();
|
||||||
|
this.moteType = moteType;
|
||||||
|
|
||||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||||
JLabel label;
|
JLabel label;
|
||||||
|
@ -211,7 +213,11 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
nextButton.addActionListener(new ActionListener() {
|
nextButton.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (nextButton.getText().equals("Compile")) {
|
if (nextButton.getText().equals("Compile")) {
|
||||||
compileContiki();
|
try {
|
||||||
|
compileContiki();
|
||||||
|
} catch (Exception e1) {
|
||||||
|
logger.fatal("Error while compiling Contiki: " + e1.getMessage());
|
||||||
|
}
|
||||||
} else if (nextButton.getText().equals("Create")) {
|
} else if (nextButton.getText().equals("Create")) {
|
||||||
/* Write mote type settings (generic) */
|
/* Write mote type settings (generic) */
|
||||||
moteType.setDescription(descriptionField.getText());
|
moteType.setDescription(descriptionField.getText());
|
||||||
|
@ -279,8 +285,6 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
});
|
});
|
||||||
|
|
||||||
setDialogState(DialogState.NO_SELECTION);
|
setDialogState(DialogState.NO_SELECTION);
|
||||||
descriptionField.requestFocus();
|
|
||||||
descriptionField.select(0, descriptionField.getText().length());
|
|
||||||
|
|
||||||
/* Restore old configuration if mote type is already configured */
|
/* Restore old configuration if mote type is already configured */
|
||||||
if (moteType != null) {
|
if (moteType != null) {
|
||||||
|
@ -312,6 +316,9 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
descriptionField.requestFocus();
|
||||||
|
descriptionField.select(0, descriptionField.getText().length());
|
||||||
|
|
||||||
/* Add listener only after restoring old config */
|
/* Add listener only after restoring old config */
|
||||||
contikiField.getDocument().addDocumentListener(contikiFieldListener);
|
contikiField.getDocument().addDocumentListener(contikiFieldListener);
|
||||||
|
|
||||||
|
@ -355,15 +362,28 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
|
|
||||||
public abstract boolean canLoadFirmware(File file);
|
public abstract boolean canLoadFirmware(File file);
|
||||||
|
|
||||||
private void compileContiki() {
|
protected String[] compilationEnvironment = null; /* Default environment: inherit from current process */
|
||||||
|
public void compileContiki()
|
||||||
|
throws Exception {
|
||||||
final MessageList taskOutput = new MessageList();
|
final MessageList taskOutput = new MessageList();
|
||||||
|
|
||||||
|
if (contikiFirmware.exists()) {
|
||||||
|
contikiFirmware.delete();
|
||||||
|
}
|
||||||
|
|
||||||
/* Handle multiple compilation commands one by one */
|
/* Handle multiple compilation commands one by one */
|
||||||
final ArrayList<String> commands = new ArrayList<String>();
|
final ArrayList<String> commands = new ArrayList<String>();
|
||||||
String[] arr = getCompileCommands().split("\n");
|
String[] arr = getCompileCommands().split("\n");
|
||||||
for (String cmd: arr) {
|
for (String cmd: arr) {
|
||||||
|
if (cmd.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
commands.add(cmd);
|
commands.add(cmd);
|
||||||
}
|
}
|
||||||
|
if (commands.isEmpty()) {
|
||||||
|
throw new Exception("No compile commands specified");
|
||||||
|
}
|
||||||
|
|
||||||
setDialogState(DialogState.IS_COMPILING);
|
setDialogState(DialogState.IS_COMPILING);
|
||||||
createNewCompilationTab(taskOutput);
|
createNewCompilationTab(taskOutput);
|
||||||
|
@ -382,6 +402,13 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
final Action compilationSuccessAction = new AbstractAction() {
|
final Action compilationSuccessAction = new AbstractAction() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
abortMenuItem.setEnabled(false);
|
abortMenuItem.setEnabled(false);
|
||||||
|
|
||||||
|
/* Make sure firmware exists */
|
||||||
|
if (!contikiFirmware.exists()) {
|
||||||
|
logger.fatal("Contiki firmware does not exist: " + contikiFirmware.getAbsolutePath());
|
||||||
|
setDialogState(DialogState.AWAITING_COMPILATION);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setDialogState(DialogState.COMPILED_FIRMWARE);
|
setDialogState(DialogState.COMPILED_FIRMWARE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -411,7 +438,8 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
try {
|
try {
|
||||||
currentCompilationProcess = CompileContiki.compile(
|
currentCompilationProcess = CompileContiki.compile(
|
||||||
command,
|
command,
|
||||||
null,
|
compilationEnvironment,
|
||||||
|
null /* Do not observe output firmware file */,
|
||||||
new File(contikiField.getText()).getParentFile(),
|
new File(contikiField.getText()).getParentFile(),
|
||||||
nextSuccessAction,
|
nextSuccessAction,
|
||||||
compilationFailureAction,
|
compilationFailureAction,
|
||||||
|
@ -454,6 +482,8 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
* @param dialogState New dialog state
|
* @param dialogState New dialog state
|
||||||
*/
|
*/
|
||||||
public void setDialogState(DialogState dialogState) {
|
public void setDialogState(DialogState dialogState) {
|
||||||
|
File sourceFile = new File(contikiField.getText());
|
||||||
|
|
||||||
switch (dialogState) {
|
switch (dialogState) {
|
||||||
case NO_SELECTION:
|
case NO_SELECTION:
|
||||||
nextButton.setText("Compile");
|
nextButton.setText("Compile");
|
||||||
|
@ -463,7 +493,6 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SELECTED_SOURCE:
|
case SELECTED_SOURCE:
|
||||||
File sourceFile = new File(contikiField.getText());
|
|
||||||
if (!sourceFile.exists()) {
|
if (!sourceFile.exists()) {
|
||||||
setDialogState(DialogState.NO_SELECTION);
|
setDialogState(DialogState.NO_SELECTION);
|
||||||
return;
|
return;
|
||||||
|
@ -483,6 +512,15 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AWAITING_COMPILATION:
|
case AWAITING_COMPILATION:
|
||||||
|
if (!sourceFile.exists()) {
|
||||||
|
setDialogState(DialogState.NO_SELECTION);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!sourceFile.getName().endsWith(".c")) {
|
||||||
|
setDialogState(DialogState.NO_SELECTION);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
nextButton.setText("Compile");
|
nextButton.setText("Compile");
|
||||||
nextButton.setEnabled(true);
|
nextButton.setEnabled(true);
|
||||||
commandsArea.setEnabled(true);
|
commandsArea.setEnabled(true);
|
||||||
|
@ -536,7 +574,7 @@ public abstract class AbstractCompileDialog extends JDialog {
|
||||||
setDialogState(DialogState.AWAITING_COMPILATION);
|
setDialogState(DialogState.AWAITING_COMPILATION);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
parent.addTab("Compile commands", null, commandsArea, "Manually alter Contiki compilation commands");
|
parent.addTab("Compile commands", null, new JScrollPane(commandsArea), "Manually alter Contiki compilation commands");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMoteInterfacesTab(JTabbedPane parent) {
|
private void addMoteInterfacesTab(JTabbedPane parent) {
|
||||||
|
|
Loading…
Reference in a new issue