using external tools regular expressions

This commit is contained in:
fros4943 2007-09-10 13:26:54 +00:00
parent 08d42b2251
commit 919a35801d

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: ContikiMoteType.java,v 1.17 2007/07/11 15:22:22 fros4943 Exp $
* $Id: ContikiMoteType.java,v 1.18 2007/09/10 13:26:54 fros4943 Exp $
*/
package se.sics.cooja.contikimote;
@ -92,69 +92,73 @@ public class ContikiMoteType implements MoteType {
* Communication stacks in Contiki.
*/
public enum CommunicationStack {
UIP,
UIP_UAODV,
RIME;
UIP, UIP_UAODV, RIME;
public String toString() {
if (this == UIP)
if (this == UIP) {
return "uIP";
if (this == UIP_UAODV)
}
if (this == UIP_UAODV) {
return "uIP over uAODV";
if (this == RIME)
}
if (this == RIME) {
return "Rime";
}
return "[unknown]";
}
public String getSourceFilenamesString() {
if (this == UIP)
if (this == UIP) {
return " cooja-radio.c radio-uip.c init-net-uip.c";
if (this == UIP_UAODV)
}
if (this == UIP_UAODV) {
return " cooja-radio.c radio-uip-uaodv.c init-net-uip-uaodv.c crc16.c";
if (this == RIME)
}
if (this == RIME) {
return " cooja-radio.c init-net-rime.c";
}
return " ";
}
public static CommunicationStack parse(String name) {
if (name.equals("uIP") || name.equals("UIP"))
if (name.equals("uIP") || name.equals("UIP")) {
return UIP;
if (name.equals("uIP over uAODV") || name.equals("UIP_UAODV"))
}
if (name.equals("uIP over uAODV") || name.equals("UIP_UAODV")) {
return UIP_UAODV;
if (name.equals("Rime") || name.equals("RIME"))
}
if (name.equals("Rime") || name.equals("RIME")) {
return RIME;
}
logger.warn("Can't parse communication stack name: " + name);
return UIP;
}
}
// Regular expressions for parsing the map file
final static private String bssSectionAddrRegExp = "^.bss[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$";
final static private String bssSectionSizeRegExp = "^.bss[ \t]*0x[0-9A-Fa-f]*[ \t]*0x([0-9A-Fa-f]*)[ \t]*$";
final static private String dataSectionAddrRegExp = "^.data[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$";
final static private String dataSectionSizeRegExp = "^.data[ \t]*0x[0-9A-Fa-f]*[ \t]*0x([0-9A-Fa-f]*)[ \t]*$";
final static private String varAddressRegExpPrefix = "^[ \t]*0x([0-9A-Fa-f]*)[ \t]*";
final static private String varAddressRegExpSuffix = "[ \t]*$";
final static private String varNameRegExp = "^[ \t]*(0x[0-9A-Fa-f]*)[ \t]*([^ ]*)[ \t]*$";
final static private String varSizeRegExpPrefix = "^";
final static private String varSizeRegExpSuffix = "[ \t]*(0x[0-9A-Fa-f]*)[ \t]*[^ ]*[ \t]*$";
// Regular expressions for parsing nm response
final static private String nmRegExp = "^([0-9A-Fa-f][0-9A-Fa-f]*)[ \t][^Tt][ \t]([^ ._][^ ]*)";
// Mote type specific data
private String identifier = null;
private String description = null;
private String contikiBaseDir = null;
private String contikiCoreDir = null;
private Vector<File> projectDirs = null;
private Vector<File> compilationFiles = null;
private Vector<String> processes = null;
private Vector<String> sensors = null;
private Vector<String> coreInterfaces = null;
private Vector<Class<? extends MoteInterface>> moteInterfaces = null;
private boolean hasSystemSymbols = false;
private CommunicationStack commStack = CommunicationStack.UIP;
// Simulation holding this mote type
@ -165,7 +169,9 @@ public class ContikiMoteType implements MoteType {
// Core communication variables
private String libraryClassName = null;
private int offsetRelToAbs = 0;
private CoreComm myCoreComm = null;
// Variable name to address mappings
@ -198,65 +204,75 @@ public class ContikiMoteType implements MoteType {
return new ContikiMote(this, simulation);
}
public boolean configureAndInit(JFrame parentFrame, Simulation simulation, boolean visAvailable)
throws MoteTypeCreationException {
public boolean configureAndInit(JFrame parentFrame, Simulation simulation,
boolean visAvailable) throws MoteTypeCreationException {
if (visAvailable) {
return ContikiMoteTypeDialog.showDialog(parentFrame, simulation, this);
} else {
// Create temp output directory if not already exists
if (!ContikiMoteType.tempOutputDirectory.exists())
ContikiMoteType.tempOutputDirectory.mkdir();
if (!ContikiMoteType.tempOutputDirectory.exists()) {
throw new MoteTypeCreationException("Could not create output directory: " + ContikiMoteType.tempOutputDirectory);
ContikiMoteType.tempOutputDirectory.mkdir();
}
if (!ContikiMoteType.tempOutputDirectory.exists()) {
throw new MoteTypeCreationException(
"Could not create output directory: "
+ ContikiMoteType.tempOutputDirectory);
}
// Delete output files
File libFile = new File(ContikiMoteType.tempOutputDirectory,
identifier + ContikiMoteType.librarySuffix);
File mapFile = new File(ContikiMoteType.tempOutputDirectory,
identifier + ContikiMoteType.mapSuffix);
File depFile = new File(ContikiMoteType.tempOutputDirectory,
identifier + ContikiMoteType.dependSuffix);
if (libFile.exists())
libFile.delete();
if (depFile.exists())
depFile.delete();
if (mapFile.exists())
mapFile.delete();
File libFile = new File(ContikiMoteType.tempOutputDirectory, identifier
+ ContikiMoteType.librarySuffix);
File mapFile = new File(ContikiMoteType.tempOutputDirectory, identifier
+ ContikiMoteType.mapSuffix);
File depFile = new File(ContikiMoteType.tempOutputDirectory, identifier
+ ContikiMoteType.dependSuffix);
if (libFile.exists()) {
throw new MoteTypeCreationException("Could not delete output file: " + libFile);
libFile.delete();
}
if (depFile.exists()) {
throw new MoteTypeCreationException("Could not delete output file: " + depFile);
depFile.delete();
}
if (mapFile.exists()) {
throw new MoteTypeCreationException("Could not delete output file: " + mapFile);
mapFile.delete();
}
if (libFile.exists()) {
throw new MoteTypeCreationException("Could not delete output file: "
+ libFile);
}
if (depFile.exists()) {
throw new MoteTypeCreationException("Could not delete output file: "
+ depFile);
}
if (mapFile.exists()) {
throw new MoteTypeCreationException("Could not delete output file: "
+ mapFile);
}
// Generate Contiki main source file
try {
ContikiMoteTypeDialog.generateSourceFile(identifier, sensors, coreInterfaces, processes);
ContikiMoteTypeDialog.generateSourceFile(identifier, sensors,
coreInterfaces, processes);
} catch (Exception e) {
throw (MoteTypeCreationException) new MoteTypeCreationException(
"Error during main source file generation: " + e.getMessage()).initCause(e);
"Error during main source file generation: " + e.getMessage())
.initCause(e);
}
// Compile library
MessageList taskOutput = new MessageList();
boolean compilationSucceded = ContikiMoteTypeDialog.compileLibrary(
identifier,
new File(contikiBaseDir),
compilationFiles,
hasSystemSymbols,
commStack,
taskOutput.getInputStream(MessageList.NORMAL),
taskOutput.getInputStream(MessageList.ERROR));
if (!libFile.exists() || !depFile.exists() || !mapFile.exists())
identifier, new File(contikiBaseDir), compilationFiles,
hasSystemSymbols, commStack, taskOutput
.getInputStream(MessageList.NORMAL), taskOutput
.getInputStream(MessageList.ERROR));
if (!libFile.exists() || !depFile.exists() || !mapFile.exists()) {
compilationSucceded = false;
}
if (!compilationSucceded) {
MoteTypeCreationException ex = new MoteTypeCreationException("Compilation error");
MoteTypeCreationException ex = new MoteTypeCreationException(
"Compilation error");
ex.setCompilationOutput(taskOutput);
throw ex;
}
@ -286,22 +302,25 @@ public class ContikiMoteType implements MoteType {
this.identifier = identifier;
if (myCoreComm != null) {
throw new MoteTypeCreationException("Core communicator already used: " + myCoreComm.getClass().getName());
throw new MoteTypeCreationException("Core communicator already used: "
+ myCoreComm.getClass().getName());
}
File libFile = new File(ContikiMoteType.tempOutputDirectory,
identifier + librarySuffix);
File mapFile = new File(ContikiMoteType.tempOutputDirectory,
identifier + mapSuffix);
File libFile = new File(ContikiMoteType.tempOutputDirectory, identifier
+ librarySuffix);
File mapFile = new File(ContikiMoteType.tempOutputDirectory, identifier
+ mapSuffix);
// Check that library file exists
if (!libFile.exists()) {
throw new MoteTypeCreationException("Library file could not be found: " + libFile);
throw new MoteTypeCreationException("Library file could not be found: "
+ libFile);
}
// Check that map file exists
if (!mapFile.exists()) {
throw new MoteTypeCreationException("Map file could not be found: " + mapFile);
throw new MoteTypeCreationException("Map file could not be found: "
+ mapFile);
}
// Allocate core communicator class
@ -319,13 +338,15 @@ public class ContikiMoteType implements MoteType {
if (mapFileData == null || !parseMapFileData(mapFileData, varAddresses)) {
logger.fatal("Map file parsing failed");
}
logger.info("Testing experimental nm response parsing for finding variable addresses");
logger
.info("Testing experimental nm response parsing for finding variable addresses");
if (nmData == null || !parseNmData(nmData, varAddresses)) {
logger.fatal("Nm response parsing failed");
}
if (varAddresses.size() == 0) {
throw new MoteTypeCreationException("Variable name to addresses mappings could not be created");
throw new MoteTypeCreationException(
"Variable name to addresses mappings could not be created");
}
try {
@ -345,16 +366,17 @@ public class ContikiMoteType implements MoteType {
if (relDataSectionAddr <= 0 || dataSectionSize <= 0
|| relBssSectionAddr <= 0 || bssSectionSize <= 0) {
throw new MoteTypeCreationException("Could not parse section addresses correctly");
throw new MoteTypeCreationException(
"Could not parse section addresses correctly");
}
// Create initial memory
byte[] initialDataSection = new byte[dataSectionSize];
getCoreMemory(relDataSectionAddr
+ offsetRelToAbs, dataSectionSize, initialDataSection);
getCoreMemory(relDataSectionAddr + offsetRelToAbs, dataSectionSize,
initialDataSection);
byte[] initialBssSection = new byte[bssSectionSize];
getCoreMemory(
relBssSectionAddr + offsetRelToAbs, bssSectionSize, initialBssSection);
getCoreMemory(relBssSectionAddr + offsetRelToAbs, bssSectionSize,
initialBssSection);
initialMemory = new SectionMoteMemory(varAddresses);
initialMemory.setMemorySegment(relDataSectionAddr, initialDataSection);
initialMemory.setMemorySegment(relBssSectionAddr, initialBssSection);
@ -402,19 +424,22 @@ public class ContikiMoteType implements MoteType {
* @param varAddresses
* Properties that should contain the name to addresses mappings.
*/
private boolean parseMapFileData(Vector<String> mapFileData, Properties varAddresses) {
public static boolean parseMapFileData(Vector<String> mapFileData,
Properties varAddresses) {
Vector<String> varNames = getMapFileVarNames(mapFileData);
if (varNames == null || varNames.size() == 0)
if (varNames == null || varNames.size() == 0) {
return false;
}
for (String varName : varNames) {
int varAddress = getMapFileVarAddress(mapFileData, varName);
int varAddress = getMapFileVarAddress(mapFileData, varName, varAddresses);
if (varAddress > 0) {
varAddresses.put(varName, new Integer(varAddress));
} else
} else {
logger.warn("Parsed Contiki variable '" + varName
+ "' but could not find address");
}
}
return true;
}
@ -428,10 +453,12 @@ public class ContikiMoteType implements MoteType {
* @param varAddresses
* Properties that should contain the name to addresses mappings.
*/
public static boolean parseNmData(Vector<String> nmData, Properties varAddresses) {
public static boolean parseNmData(Vector<String> nmData,
Properties varAddresses) {
int nrNew = 0, nrOld = 0, nrMismatch = 0;
Pattern pattern = Pattern.compile(nmRegExp);
Pattern pattern = Pattern.compile(GUI
.getExternalToolsSetting("NM_VAR_NAME_ADDRESS"));
for (String nmLine : nmData) {
Matcher matcher = pattern.matcher(nmLine);
@ -446,7 +473,8 @@ public class ContikiMoteType implements MoteType {
} else {
int oldAddress = (Integer) varAddresses.get(varName);
if (oldAddress != varAddress) {
logger.warn("Warning, nm response not matching previous entry of: " + varName);
logger.warn("Warning, nm response not matching previous entry of: "
+ varName);
nrMismatch++;
}
@ -455,10 +483,14 @@ public class ContikiMoteType implements MoteType {
}
}
if (nrMismatch > 0)
logger.debug("Nm response parsing summary: Added " + nrNew + " variables. Found " + nrOld + " old variables. MISMATCHING ADDRESSES: " + nrMismatch);
else
logger.debug("Nm response parsing summary: Added " + nrNew + " variables. Found " + nrOld + " old variables");
if (nrMismatch > 0) {
logger.debug("Nm response parsing summary: Added " + nrNew
+ " variables. Found " + nrOld
+ " old variables. MISMATCHING ADDRESSES: " + nrMismatch);
} else {
logger.debug("Nm response parsing summary: Added " + nrNew
+ " variables. Found " + nrOld + " old variables");
}
return (nrNew + nrOld) > 0;
}
@ -476,8 +508,7 @@ public class ContikiMoteType implements MoteType {
int size = mem.getSizeOfSection(i);
byte[] data = mem.getDataOfSection(i);
getCoreMemory(startAddr + offsetRelToAbs,
size, data);
getCoreMemory(startAddr + offsetRelToAbs, size, data);
}
}
@ -490,7 +521,8 @@ public class ContikiMoteType implements MoteType {
}
/**
* @param using Core library has system symbols information
* @param using
* Core library has system symbols information
*/
public void setHasSystemSymbols(boolean using) {
hasSystemSymbols = using;
@ -504,7 +536,8 @@ public class ContikiMoteType implements MoteType {
}
/**
* @param commStack Communication stack
* @param commStack
* Communication stack
*/
public void setCommunicationStack(CommunicationStack commStack) {
this.commStack = commStack;
@ -531,7 +564,7 @@ public class ContikiMoteType implements MoteType {
* Name of variable
* @return Relative memory address of variable or -1 if not found
*/
protected int getMapFileVarAddress(Vector<String> mapFileData, String varName) {
public static int getMapFileVarAddress(Vector<String> mapFileData, String varName, Properties varAddresses) {
int varAddr;
String varAddrString;
if ((varAddrString = varAddresses.getProperty(varName)) != null) {
@ -539,16 +572,18 @@ public class ContikiMoteType implements MoteType {
return varAddr;
}
String regExp = varAddressRegExpPrefix + varName + varAddressRegExpSuffix;
String regExp = GUI.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_1")
+ varName + GUI.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_2");
String retString = getFirstMatchGroup(mapFileData, regExp, 1);
if (retString != null) {
varAddresses.setProperty(varName, Integer.toString(Integer.parseInt(
retString.trim(), 16)));
return Integer.parseInt(retString.trim(), 16);
} else
} else {
return -1;
}
}
private int getReferenceAbsAddr() {
return myCoreComm.getReferenceAbsAddr();
@ -581,7 +616,7 @@ public class ContikiMoteType implements MoteType {
*
* @return Variable names found in the data and bss section
*/
private Vector<String> getMapFileVarNames(Vector<String> mapFileData) {
public static Vector<String> getMapFileVarNames(Vector<String> mapFileData) {
Vector<String> varNames = getAllVariableNames(mapFileData,
loadRelDataSectionAddr(mapFileData),
@ -594,11 +629,12 @@ public class ContikiMoteType implements MoteType {
return varNames;
}
private Vector<String> getAllVariableNames(Vector<String> lines,
public static Vector<String> getAllVariableNames(Vector<String> lines,
int startAddress, int endAddress) {
Vector<String> varNames = new Vector<String>();
Pattern pattern = Pattern.compile(varNameRegExp);
Pattern pattern = Pattern.compile(GUI
.getExternalToolsSetting("MAPFILE_VAR_NAME"));
for (int i = 0; i < lines.size(); i++) {
Matcher matcher = pattern.matcher(lines.elementAt(i));
if (matcher.find()) {
@ -612,8 +648,9 @@ public class ContikiMoteType implements MoteType {
}
protected int getVariableSize(Vector<String> lines, String varName) {
Pattern pattern = Pattern.compile(varSizeRegExpPrefix + varName
+ varSizeRegExpSuffix);
Pattern pattern = Pattern.compile(GUI
.getExternalToolsSetting("MAPFILE_VAR_SIZE_1")
+ varName + GUI.getExternalToolsSetting("MAPFILE_VAR_SIZE_2"));
for (int i = 0; i < lines.size(); i++) {
Matcher matcher = pattern.matcher(lines.elementAt(i));
if (matcher.find()) {
@ -623,53 +660,131 @@ public class ContikiMoteType implements MoteType {
return -1;
}
private static int loadRelDataSectionAddr(Vector<String> mapFileData) {
String retString = getFirstMatchGroup(mapFileData, dataSectionAddrRegExp, 1);
public static int loadRelDataSectionAddr(Vector<String> mapFileData) {
String retString = getFirstMatchGroup(mapFileData, GUI
.getExternalToolsSetting("MAPFILE_DATA_START"), 1);
if (retString != null)
if (retString != null) {
return Integer.parseInt(retString.trim(), 16);
else
return 0;
} else {
return -1;
}
}
private static int loadDataSectionSize(Vector<String> mapFileData) {
String retString = getFirstMatchGroup(mapFileData, dataSectionSizeRegExp, 1);
public static int loadDataSectionSize(Vector<String> mapFileData) {
String retString = getFirstMatchGroup(mapFileData, GUI
.getExternalToolsSetting("MAPFILE_DATA_SIZE"), 1);
if (retString != null)
if (retString != null) {
return Integer.parseInt(retString.trim(), 16);
else
return 0;
} else {
return -1;
}
}
private static int loadRelBssSectionAddr(Vector<String> mapFileData) {
String retString = getFirstMatchGroup(mapFileData, bssSectionAddrRegExp, 1);
public static int loadRelBssSectionAddr(Vector<String> mapFileData) {
String retString = getFirstMatchGroup(mapFileData, GUI
.getExternalToolsSetting("MAPFILE_BSS_START"), 1);
if (retString != null)
if (retString != null) {
return Integer.parseInt(retString.trim(), 16);
else
return 0;
} else {
return -1;
}
}
private static int loadBssSectionSize(Vector<String> mapFileData) {
String retString = getFirstMatchGroup(mapFileData, bssSectionSizeRegExp, 1);
public static int loadBssSectionSize(Vector<String> mapFileData) {
String retString = getFirstMatchGroup(mapFileData, GUI
.getExternalToolsSetting("MAPFILE_BSS_SIZE"), 1);
if (retString != null)
if (retString != null) {
return Integer.parseInt(retString.trim(), 16);
else
return 0;
} else {
return -1;
}
}
public static int loadNmRelDataSectionAddr(Vector<String> nmData) {
String retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_DATA_START"), 1);
if (retString != null) {
return Integer.parseInt(retString.trim(), 16);
} else {
return -1;
}
}
public static int loadNmDataSectionSize(Vector<String> nmData) {
String retString;
int start, end;
retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_DATA_START"), 1);
if (retString != null) {
start = Integer.parseInt(retString.trim(), 16);
} else {
return -1;
}
retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_DATA_END"), 1);
if (retString != null) {
end = Integer.parseInt(retString.trim(), 16);
} else {
return -1;
}
return end - start;
}
public static int loadNmRelBssSectionAddr(Vector<String> nmData) {
String retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_BSS_START"), 1);
if (retString != null) {
return Integer.parseInt(retString.trim(), 16);
} else {
return -1;
}
}
public static int loadNmBssSectionSize(Vector<String> nmData) {
String retString;
int start, end;
retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_BSS_START"), 1);
if (retString != null) {
start = Integer.parseInt(retString.trim(), 16);
} else {
return -1;
}
retString = getFirstMatchGroup(nmData, GUI
.getExternalToolsSetting("NM_BSS_END"), 1);
if (retString != null) {
end = Integer.parseInt(retString.trim(), 16);
} else {
return -1;
}
return end - start;
}
private static int getRelVarAddr(Vector<String> mapFileData, String varName) {
String regExp = varAddressRegExpPrefix + varName + varAddressRegExpSuffix;
String regExp = GUI.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_1")
+ varName + GUI.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_2");
String retString = getFirstMatchGroup(mapFileData, regExp, 1);
if (retString != null)
if (retString != null) {
return Integer.parseInt(retString.trim(), 16);
else
return 0;
} else {
return -1;
}
}
private static Vector<String> loadMapFile(File mapFile) {
public static Vector<String> loadMapFile(File mapFile) {
Vector<String> mapFileData = new Vector<String>();
try {
@ -693,7 +808,8 @@ public class ContikiMoteType implements MoteType {
/**
* Runs external tool nm on given file and returns the result.
*
* @param libraryFile File
* @param libraryFile
* File
* @return Execution response
*/
public static Vector<String> loadNmData(File libraryFile) {
@ -703,8 +819,9 @@ public class ContikiMoteType implements MoteType {
String nmPath = GUI.getExternalToolsSetting("PATH_NM");
String nmArgs = GUI.getExternalToolsSetting("NM_ARGS");
if (nmPath == null || nmPath.equals(""))
if (nmPath == null || nmPath.equals("")) {
return null;
}
String[] nmExecArray;
if (!nmArgs.trim().equals("")) {
@ -715,7 +832,8 @@ public class ContikiMoteType implements MoteType {
nmExecArray[0] = nmPath.trim();
nmExecArray[nmExecArray.length - 1] = libraryFile.getAbsolutePath();
System.arraycopy(splittedNmArgs, 0, nmExecArray, 1, splittedNmArgs.length);
System.arraycopy(splittedNmArgs, 0, nmExecArray, 1,
splittedNmArgs.length);
} else {
nmExecArray = new String[2];
nmExecArray[0] = nmPath.trim();
@ -724,22 +842,21 @@ public class ContikiMoteType implements MoteType {
String line;
Process p = Runtime.getRuntime().exec(nmExecArray);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
BufferedReader input = new BufferedReader(new InputStreamReader(p
.getInputStream()));
p.getErrorStream().close(); // Ignore error stream
while ((line = input.readLine()) != null) {
nmData.add(line);
}
input.close();
}
catch (Exception err) {
} catch (Exception err) {
err.printStackTrace();
return null;
}
if (nmData == null || nmData.size() == 0)
if (nmData == null || nmData.size() == 0) {
return null;
}
return nmData;
}
@ -747,7 +864,8 @@ public class ContikiMoteType implements MoteType {
/**
* Runs external tool objdump on given file and returns the result.
*
* @param libraryFile File
* @param libraryFile
* File
* @return Execution response
*/
public static Vector<String> loadObjdumpData(File libraryFile) {
@ -757,8 +875,9 @@ public class ContikiMoteType implements MoteType {
String objdumpPath = GUI.getExternalToolsSetting("PATH_OBJDUMP");
String objdumpArgs = GUI.getExternalToolsSetting("OBJDUMP_ARGS");
if (objdumpPath == null || objdumpPath.equals(""))
if (objdumpPath == null || objdumpPath.equals("")) {
return null;
}
String[] objdumpExecArray;
if (!objdumpArgs.trim().equals("")) {
@ -768,8 +887,10 @@ public class ContikiMoteType implements MoteType {
objdumpExecArray[0] = objdumpPath.trim();
objdumpExecArray[objdumpExecArray.length-1] = libraryFile.getAbsolutePath();
System.arraycopy(splittedObjdumpArgs, 0, objdumpExecArray, 1, splittedObjdumpArgs.length);
objdumpExecArray[objdumpExecArray.length - 1] = libraryFile
.getAbsolutePath();
System.arraycopy(splittedObjdumpArgs, 0, objdumpExecArray, 1,
splittedObjdumpArgs.length);
} else {
objdumpExecArray = new String[2];
objdumpExecArray[0] = objdumpPath.trim();
@ -778,22 +899,21 @@ public class ContikiMoteType implements MoteType {
String line;
Process p = Runtime.getRuntime().exec(objdumpExecArray);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
BufferedReader input = new BufferedReader(new InputStreamReader(p
.getInputStream()));
p.getErrorStream().close(); // Ignore error stream
while ((line = input.readLine()) != null) {
objdumpData.add(line);
}
input.close();
}
catch (Exception err) {
} catch (Exception err) {
err.printStackTrace();
return null;
}
if (objdumpData == null || objdumpData.size() == 0)
if (objdumpData == null || objdumpData.size() == 0) {
return null;
}
return objdumpData;
}
@ -1012,9 +1132,10 @@ public class ContikiMoteType implements MoteType {
while (bytesRead > 0) {
bytesRead = fileInputStream.read(readBytes);
if (bytesRead > 0)
if (bytesRead > 0) {
messageDigest.update(readBytes, 0, bytesRead);
}
}
fileInputStream.close();
} catch (NoSuchAlgorithmException e) {
return null;
@ -1205,7 +1326,8 @@ public class ContikiMoteType implements MoteType {
}
public boolean setConfigXML(Simulation simulation,
Collection<Element> configXML, boolean visAvailable) throws MoteTypeCreationException {
Collection<Element> configXML, boolean visAvailable)
throws MoteTypeCreationException {
projectDirs = new Vector<File>();
compilationFiles = new Vector<File>();
processes = new Vector<String>();
@ -1240,13 +1362,14 @@ public class ContikiMoteType implements MoteType {
} else if (name.equals("coreinterface")) {
coreInterfaces.add(element.getText());
} else if (name.equals("moteinterface")) {
Class<? extends MoteInterface> moteInterfaceClass =
simulation.getGUI().tryLoadClass(this, MoteInterface.class, element.getText().trim());
Class<? extends MoteInterface> moteInterfaceClass = simulation.getGUI()
.tryLoadClass(this, MoteInterface.class, element.getText().trim());
if (moteInterfaceClass == null) {
logger.warn("Can't find mote interface class: " + element.getText());
} else
} else {
moteInterfaces.add(moteInterfaceClass);
}
} else {
logger.fatal("Unrecognized entry in loaded configuration: " + name);
}