[cooja] ContikiMoteType: Non-functional indention and code style updates
This commit is contained in:
parent
434c4db1a2
commit
dae92d93bb
|
@ -27,7 +27,6 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.contikios.cooja.contikimote;
|
package org.contikios.cooja.contikimote;
|
||||||
|
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
|
@ -41,6 +40,7 @@ import java.lang.reflect.Method;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -93,7 +93,8 @@ import org.contikios.cooja.util.StringUtils;
|
||||||
@ClassDescription("Cooja mote")
|
@ClassDescription("Cooja mote")
|
||||||
@AbstractionLevelDescription("OS level")
|
@AbstractionLevelDescription("OS level")
|
||||||
public class ContikiMoteType implements MoteType {
|
public class ContikiMoteType implements MoteType {
|
||||||
private static Logger logger = Logger.getLogger(ContikiMoteType.class);
|
|
||||||
|
private static final Logger logger = Logger.getLogger(ContikiMoteType.class);
|
||||||
|
|
||||||
public static final String ID_PREFIX = "mtype";
|
public static final String ID_PREFIX = "mtype";
|
||||||
|
|
||||||
|
@ -121,6 +122,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
* Communication stacks in Contiki.
|
* Communication stacks in Contiki.
|
||||||
*/
|
*/
|
||||||
public enum NetworkStack {
|
public enum NetworkStack {
|
||||||
|
|
||||||
DEFAULT, MANUAL;
|
DEFAULT, MANUAL;
|
||||||
public String manualHeader = "netstack-conf-example.h";
|
public String manualHeader = "netstack-conf-example.h";
|
||||||
|
|
||||||
|
@ -167,7 +169,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String[] sensors = { "button_sensor", "pir_sensor", "vib_sensor" };
|
private final String[] sensors = {"button_sensor", "pir_sensor", "vib_sensor"};
|
||||||
|
|
||||||
private String identifier = null;
|
private String identifier = null;
|
||||||
private String description = null;
|
private String description = null;
|
||||||
|
@ -177,10 +179,15 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
/* For internal use only: using during Contiki compilation. */
|
/* For internal use only: using during Contiki compilation. */
|
||||||
private File contikiApp = null; /* Contiki application: hello-world.c */
|
private File contikiApp = null; /* Contiki application: hello-world.c */
|
||||||
|
|
||||||
public File libSource = null; /* JNI library: obj_cooja/mtype1.c */
|
public File libSource = null; /* JNI library: obj_cooja/mtype1.c */
|
||||||
|
|
||||||
public File libFile = null; /* JNI library: obj_cooja/mtype1.lib */
|
public File libFile = null; /* JNI library: obj_cooja/mtype1.lib */
|
||||||
|
|
||||||
public File archiveFile = null; /* Contiki archive: obj_cooja/mtype1.a */
|
public File archiveFile = null; /* Contiki archive: obj_cooja/mtype1.a */
|
||||||
|
|
||||||
public File mapFile = null; /* Contiki map: obj_cooja/mtype1.map */
|
public File mapFile = null; /* Contiki map: obj_cooja/mtype1.map */
|
||||||
|
|
||||||
public String javaClassName = null; /* Loading Java class name: Lib1 */
|
public String javaClassName = null; /* Loading Java class name: Lib1 */
|
||||||
|
|
||||||
private String[] coreInterfaces = null;
|
private String[] coreInterfaces = null;
|
||||||
|
@ -213,18 +220,18 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean configureAndInit(Container parentContainer, Simulation simulation,
|
public boolean configureAndInit(Container parentContainer, Simulation simulation,
|
||||||
boolean visAvailable) throws MoteTypeCreationException {
|
boolean visAvailable) throws MoteTypeCreationException {
|
||||||
myConfig = simulation.getCooja().getProjectConfig().clone();
|
myConfig = simulation.getCooja().getProjectConfig().clone();
|
||||||
|
|
||||||
if (visAvailable) {
|
if (visAvailable) {
|
||||||
|
|
||||||
if (getDescription() == null) {
|
if (getDescription() == null) {
|
||||||
setDescription("Cooja Mote Type #" + (simulation.getMoteTypes().length+1));
|
setDescription("Cooja Mote Type #" + (simulation.getMoteTypes().length + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compile Contiki from dialog */
|
/* Compile Contiki from dialog */
|
||||||
boolean compileOK =
|
boolean compileOK
|
||||||
ContikiMoteCompileDialog.showDialog(parentContainer, simulation, this);
|
= ContikiMoteCompileDialog.showDialog(parentContainer, simulation, this);
|
||||||
if (!compileOK) {
|
if (!compileOK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -240,17 +247,17 @@ public class ContikiMoteType implements MoteType {
|
||||||
/* Create variables used for compiling Contiki */
|
/* Create variables used for compiling Contiki */
|
||||||
contikiApp = getContikiSourceFile();
|
contikiApp = getContikiSourceFile();
|
||||||
libSource = new File(
|
libSource = new File(
|
||||||
contikiApp.getParentFile(),
|
contikiApp.getParentFile(),
|
||||||
"obj_cooja/" + getIdentifier() + ".c");
|
"obj_cooja/" + getIdentifier() + ".c");
|
||||||
libFile = new File(
|
libFile = new File(
|
||||||
contikiApp.getParentFile(),
|
contikiApp.getParentFile(),
|
||||||
"obj_cooja/" + getIdentifier() + librarySuffix);
|
"obj_cooja/" + getIdentifier() + librarySuffix);
|
||||||
archiveFile = new File(
|
archiveFile = new File(
|
||||||
contikiApp.getParentFile(),
|
contikiApp.getParentFile(),
|
||||||
"obj_cooja/" + getIdentifier() + dependSuffix);
|
"obj_cooja/" + getIdentifier() + dependSuffix);
|
||||||
mapFile = new File(
|
mapFile = new File(
|
||||||
contikiApp.getParentFile(),
|
contikiApp.getParentFile(),
|
||||||
"obj_cooja/" + getIdentifier() + mapSuffix);
|
"obj_cooja/" + getIdentifier() + mapSuffix);
|
||||||
javaClassName = CoreComm.getAvailableClassName();
|
javaClassName = CoreComm.getAvailableClassName();
|
||||||
|
|
||||||
if (javaClassName == null) {
|
if (javaClassName == null) {
|
||||||
|
@ -265,37 +272,36 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
/* Generate Contiki main source */
|
/* Generate Contiki main source */
|
||||||
/*try {
|
/*try {
|
||||||
CompileContiki.generateSourceFile(
|
CompileContiki.generateSourceFile(
|
||||||
libSource,
|
libSource,
|
||||||
javaClassName,
|
javaClassName,
|
||||||
getSensors(),
|
getSensors(),
|
||||||
getCoreInterfaces()
|
getCoreInterfaces()
|
||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw (MoteTypeCreationException) new MoteTypeCreationException(
|
throw (MoteTypeCreationException) new MoteTypeCreationException(
|
||||||
"Error when generating Contiki main source").initCause(e);
|
"Error when generating Contiki main source").initCause(e);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/* Prepare compiler environment */
|
/* Prepare compiler environment */
|
||||||
String[][] env;
|
String[][] env;
|
||||||
try {
|
try {
|
||||||
env = CompileContiki.createCompilationEnvironment(
|
env = CompileContiki.createCompilationEnvironment(
|
||||||
getIdentifier(),
|
getIdentifier(),
|
||||||
contikiApp,
|
contikiApp,
|
||||||
mapFile,
|
mapFile,
|
||||||
libFile,
|
libFile,
|
||||||
archiveFile,
|
archiveFile,
|
||||||
javaClassName);
|
javaClassName);
|
||||||
CompileContiki.redefineCOOJASources(
|
CompileContiki.redefineCOOJASources(
|
||||||
this,
|
this,
|
||||||
env
|
env
|
||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw (MoteTypeCreationException) new MoteTypeCreationException(
|
throw new MoteTypeCreationException("Error when creating environment: " + e.getMessage(), e);
|
||||||
"Error when creating environment: " + e.getMessage()).initCause(e);
|
|
||||||
}
|
}
|
||||||
String[] envOneDimension = new String[env.length];
|
String[] envOneDimension = new String[env.length];
|
||||||
for (int i=0; i < env.length; i++) {
|
for (int i = 0; i < env.length; i++) {
|
||||||
envOneDimension[i] = env[i][0] + "=" + env[i][1];
|
envOneDimension[i] = env[i][0] + "=" + env[i][1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,31 +311,31 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
final MessageList compilationOutput = new MessageList();
|
final MessageList compilationOutput = new MessageList();
|
||||||
String[] arr = getCompileCommands().split("\n");
|
String[] arr = getCompileCommands().split("\n");
|
||||||
for (String cmd: arr) {
|
for (String cmd : arr) {
|
||||||
if (cmd.trim().isEmpty()) {
|
if (cmd.trim().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CompileContiki.compile(
|
CompileContiki.compile(
|
||||||
cmd,
|
cmd,
|
||||||
envOneDimension,
|
envOneDimension,
|
||||||
null /* Do not observe output firmware file */,
|
null /* Do not observe output firmware file */,
|
||||||
getContikiSourceFile().getParentFile(),
|
getContikiSourceFile().getParentFile(),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
compilationOutput,
|
compilationOutput,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
MoteTypeCreationException newException =
|
MoteTypeCreationException newException
|
||||||
new MoteTypeCreationException("Mote type creation failed: " + e.getMessage());
|
= new MoteTypeCreationException("Mote type creation failed: " + e.getMessage());
|
||||||
newException = (MoteTypeCreationException) newException.initCause(e);
|
newException = (MoteTypeCreationException) newException.initCause(e);
|
||||||
newException.setCompilationOutput(compilationOutput);
|
newException.setCompilationOutput(compilationOutput);
|
||||||
|
|
||||||
/* Print last 10 compilation errors to console */
|
/* Print last 10 compilation errors to console */
|
||||||
MessageContainer[] messages = compilationOutput.getMessages();
|
MessageContainer[] messages = compilationOutput.getMessages();
|
||||||
for (int i=messages.length-10; i < messages.length; i++) {
|
for (int i = messages.length - 10; i < messages.length; i++) {
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -342,8 +348,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure compiled firmware exists */
|
/* Make sure compiled firmware exists */
|
||||||
if (getContikiFirmwareFile() == null ||
|
if (getContikiFirmwareFile() == null
|
||||||
!getContikiFirmwareFile().exists()) {
|
|| !getContikiFirmwareFile().exists()) {
|
||||||
throw new MoteTypeCreationException("Contiki firmware file does not exist: " + getContikiFirmwareFile());
|
throw new MoteTypeCreationException("Contiki firmware file does not exist: " + getContikiFirmwareFile());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -355,7 +361,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
public static File getExpectedFirmwareFile(File source) {
|
public static File getExpectedFirmwareFile(File source) {
|
||||||
File parentDir = source.getParentFile();
|
File parentDir = source.getParentFile();
|
||||||
String sourceNoExtension = source.getName().substring(0, source.getName().length()-2);
|
String sourceNoExtension = source.getName().substring(0, source.getName().length() - 2);
|
||||||
|
|
||||||
return new File(parentDir, sourceNoExtension + librarySuffix);
|
return new File(parentDir, sourceNoExtension + librarySuffix);
|
||||||
}
|
}
|
||||||
|
@ -363,8 +369,10 @@ public class ContikiMoteType implements MoteType {
|
||||||
/**
|
/**
|
||||||
* For internal use.
|
* For internal use.
|
||||||
*
|
*
|
||||||
* This method creates a core communicator linking a Contiki library and a Java class.
|
* This method creates a core communicator linking a Contiki library and a
|
||||||
* It furthermore parses library Contiki memory addresses and creates the initial memory.
|
* Java class.
|
||||||
|
* It furthermore parses library Contiki memory addresses and creates the
|
||||||
|
* initial memory.
|
||||||
*
|
*
|
||||||
* @throws MoteTypeCreationException
|
* @throws MoteTypeCreationException
|
||||||
*/
|
*/
|
||||||
|
@ -372,11 +380,11 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
if (myCoreComm != null) {
|
if (myCoreComm != null) {
|
||||||
throw new MoteTypeCreationException(
|
throw new MoteTypeCreationException(
|
||||||
"Core communicator already used: " + myCoreComm.getClass().getName());
|
"Core communicator already used: " + myCoreComm.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getContikiFirmwareFile() == null ||
|
if (getContikiFirmwareFile() == null
|
||||||
!getContikiFirmwareFile().exists()) {
|
|| !getContikiFirmwareFile().exists()) {
|
||||||
throw new MoteTypeCreationException("Library file could not be found: " + getContikiFirmwareFile());
|
throw new MoteTypeCreationException("Library file could not be found: " + getContikiFirmwareFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,8 +434,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Parse command output */
|
/* Parse command output */
|
||||||
if (mapFile == null ||
|
if (mapFile == null
|
||||||
!mapFile.exists()) {
|
|| !mapFile.exists()) {
|
||||||
throw new MoteTypeCreationException("Map file " + mapFile + " could not be found");
|
throw new MoteTypeCreationException("Map file " + mapFile + " could not be found");
|
||||||
}
|
}
|
||||||
String[] mapData = loadMapFile(mapFile);
|
String[] mapData = loadMapFile(mapFile);
|
||||||
|
@ -453,38 +461,38 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataSectionAddr >= 0) {
|
if (dataSectionAddr >= 0) {
|
||||||
logger.info(getContikiFirmwareFile().getName() +
|
logger.info(getContikiFirmwareFile().getName()
|
||||||
": data section at 0x" + Integer.toHexString(dataSectionAddr) +
|
+ ": data section at 0x" + Integer.toHexString(dataSectionAddr)
|
||||||
" (" + dataSectionSize + " == 0x" + Integer.toHexString(dataSectionSize) + " bytes)");
|
+ " (" + dataSectionSize + " == 0x" + Integer.toHexString(dataSectionSize) + " bytes)");
|
||||||
} else {
|
} else {
|
||||||
logger.fatal(getContikiFirmwareFile().getName() + ": no data section found");
|
logger.fatal(getContikiFirmwareFile().getName() + ": no data section found");
|
||||||
}
|
}
|
||||||
if (bssSectionAddr >= 0) {
|
if (bssSectionAddr >= 0) {
|
||||||
logger.info(getContikiFirmwareFile().getName() +
|
logger.info(getContikiFirmwareFile().getName()
|
||||||
": BSS section at 0x" + Integer.toHexString(bssSectionAddr) +
|
+ ": BSS section at 0x" + Integer.toHexString(bssSectionAddr)
|
||||||
" (" + bssSectionSize + " == 0x" + Integer.toHexString(bssSectionSize) + " bytes)");
|
+ " (" + bssSectionSize + " == 0x" + Integer.toHexString(bssSectionSize) + " bytes)");
|
||||||
} else {
|
} else {
|
||||||
logger.fatal(getContikiFirmwareFile().getName() + ": no BSS section found");
|
logger.fatal(getContikiFirmwareFile().getName() + ": no BSS section found");
|
||||||
}
|
}
|
||||||
if (commonSectionAddr >= 0) {
|
if (commonSectionAddr >= 0) {
|
||||||
logger.info(getContikiFirmwareFile().getName() +
|
logger.info(getContikiFirmwareFile().getName()
|
||||||
": common section at 0x" + Integer.toHexString(commonSectionAddr) +
|
+ ": common section at 0x" + Integer.toHexString(commonSectionAddr)
|
||||||
" (" + commonSectionSize + " == 0x" + Integer.toHexString(commonSectionSize) + " bytes)");
|
+ " (" + commonSectionSize + " == 0x" + Integer.toHexString(commonSectionSize) + " bytes)");
|
||||||
} else {
|
} else {
|
||||||
logger.info(getContikiFirmwareFile().getName() + ": no common section found");
|
logger.info(getContikiFirmwareFile().getName() + ": no common section found");
|
||||||
}
|
}
|
||||||
if (readonlySectionAddr >= 0) {
|
if (readonlySectionAddr >= 0) {
|
||||||
logger.info(getContikiFirmwareFile().getName() +
|
logger.info(getContikiFirmwareFile().getName()
|
||||||
": readonly section at 0x" + Integer.toHexString(readonlySectionAddr) +
|
+ ": readonly section at 0x" + Integer.toHexString(readonlySectionAddr)
|
||||||
" (" + readonlySectionSize + " == 0x" + Integer.toHexString(readonlySectionSize) + " bytes)");
|
+ " (" + readonlySectionSize + " == 0x" + Integer.toHexString(readonlySectionSize) + " bytes)");
|
||||||
} else {
|
} else {
|
||||||
logger.warn(getContikiFirmwareFile().getName() + ": no readonly section found");
|
logger.warn(getContikiFirmwareFile().getName() + ": no readonly section found");
|
||||||
}
|
}
|
||||||
if (addresses.size() == 0) {
|
if (addresses.isEmpty()) {
|
||||||
throw new MoteTypeCreationException("Library variables parsing failed");
|
throw new MoteTypeCreationException("Library variables parsing failed");
|
||||||
}
|
}
|
||||||
if (dataSectionAddr <= 0 || dataSectionSize <= 0
|
if (dataSectionAddr <= 0 || dataSectionSize <= 0
|
||||||
|| bssSectionAddr <= 0 || bssSectionSize <= 0) {
|
|| bssSectionAddr <= 0 || bssSectionSize <= 0) {
|
||||||
throw new MoteTypeCreationException("Library section addresses parsing failed");
|
throw new MoteTypeCreationException("Library section addresses parsing failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,8 +501,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
int referenceVar = addresses.get("referenceVar");
|
int referenceVar = addresses.get("referenceVar");
|
||||||
myCoreComm.setReferenceAddress(referenceVar);
|
myCoreComm.setReferenceAddress(referenceVar);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw (MoteTypeCreationException) new MoteTypeCreationException(
|
throw new MoteTypeCreationException("JNI call error: " + e.getMessage(), e);
|
||||||
"JNI call error: " + e.getMessage()).initCause(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We first need the value of Contiki's referenceVar, which tells us the
|
/* We first need the value of Contiki's referenceVar, which tells us the
|
||||||
|
@ -515,8 +522,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
tmp.setMemorySegment(bssSectionAddr, bss);
|
tmp.setMemorySegment(bssSectionAddr, bss);
|
||||||
|
|
||||||
offset = varMem.getIntValueOf("referenceVar");
|
offset = varMem.getIntValueOf("referenceVar");
|
||||||
logger.info(getContikiFirmwareFile().getName() +
|
logger.info(getContikiFirmwareFile().getName()
|
||||||
": offsetting Cooja mote address space: " + offset);
|
+ ": offsetting Cooja mote address space: " + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create initial memory: data+bss+optional common */
|
/* Create initial memory: data+bss+optional common */
|
||||||
|
@ -540,7 +547,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
if (readonlySectionAddr >= 0 && readonlySectionSize > 0) {
|
if (readonlySectionAddr >= 0 && readonlySectionSize > 0) {
|
||||||
byte[] readonlySection = new byte[readonlySectionSize];
|
byte[] readonlySection = new byte[readonlySectionSize];
|
||||||
getCoreMemory(readonlySectionAddr, readonlySectionSize, readonlySection);
|
getCoreMemory(readonlySectionAddr, readonlySectionSize, readonlySection);
|
||||||
initialMemory.setReadonlyMemorySegment(readonlySectionAddr+offset, readonlySection);
|
initialMemory.setReadonlyMemorySegment(readonlySectionAddr + offset, readonlySection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,13 +575,13 @@ public class ContikiMoteType implements MoteType {
|
||||||
* but instead via ContikiMote.setMemory().
|
* but instead via ContikiMote.setMemory().
|
||||||
*
|
*
|
||||||
* @param mem
|
* @param mem
|
||||||
* New memory
|
* New memory
|
||||||
*/
|
*/
|
||||||
public void setCoreMemory(SectionMoteMemory mem) {
|
public void setCoreMemory(SectionMoteMemory mem) {
|
||||||
for (int i = 0; i < mem.getNumberOfSections(); i++) {
|
for (int i = 0; i < mem.getNumberOfSections(); i++) {
|
||||||
setCoreMemory(
|
setCoreMemory(
|
||||||
mem.getSectionNativeAddress(i) /* native address space */,
|
mem.getSectionNativeAddress(i) /* native address space */,
|
||||||
mem.getSizeOfSection(i), mem.getDataOfSection(i));
|
mem.getSizeOfSection(i), mem.getDataOfSection(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,9 +590,9 @@ public class ContikiMoteType implements MoteType {
|
||||||
* mappings are added to the given properties object.
|
* mappings are added to the given properties object.
|
||||||
*
|
*
|
||||||
* @param mapFileData
|
* @param mapFileData
|
||||||
* Contents of entire map file
|
* Contents of entire map file
|
||||||
* @param varAddresses
|
* @param varAddresses
|
||||||
* Properties that should contain the name to addresses mappings.
|
* Properties that should contain the name to addresses mappings.
|
||||||
*/
|
*/
|
||||||
public static boolean parseMapFileData(String[] mapFileData, HashMap<String, Integer> varAddresses) {
|
public static boolean parseMapFileData(String[] mapFileData, HashMap<String, Integer> varAddresses) {
|
||||||
String[] varNames = getMapFileVarNames(mapFileData);
|
String[] varNames = getMapFileVarNames(mapFileData);
|
||||||
|
@ -599,7 +606,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
varAddresses.put(varName, new Integer(varAddress));
|
varAddresses.put(varName, new Integer(varAddress));
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Parsed Contiki variable '" + varName
|
logger.warn("Parsed Contiki variable '" + varName
|
||||||
+ "' but could not find address");
|
+ "' but could not find address");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,8 +623,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
public static boolean parseCommandData(String[] output, HashMap<String, Integer> addresses) {
|
public static boolean parseCommandData(String[] output, HashMap<String, Integer> addresses) {
|
||||||
int nrNew = 0, nrOld = 0, nrMismatch = 0;
|
int nrNew = 0, nrOld = 0, nrMismatch = 0;
|
||||||
|
|
||||||
Pattern pattern =
|
Pattern pattern
|
||||||
Pattern.compile(Cooja.getExternalToolsSetting("COMMAND_VAR_NAME_ADDRESS"));
|
= Pattern.compile(Cooja.getExternalToolsSetting("COMMAND_VAR_NAME_ADDRESS"));
|
||||||
|
|
||||||
for (String line : output) {
|
for (String line : output) {
|
||||||
Matcher matcher = pattern.matcher(line);
|
Matcher matcher = pattern.matcher(line);
|
||||||
|
@ -634,7 +641,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
int oldAddress = addresses.get(symbol);
|
int oldAddress = addresses.get(symbol);
|
||||||
if (oldAddress != address) {
|
if (oldAddress != address) {
|
||||||
/*logger.warn("Warning, command response not matching previous entry of: "
|
/*logger.warn("Warning, command response not matching previous entry of: "
|
||||||
+ varName);*/
|
+ varName);*/
|
||||||
nrMismatch++;
|
nrMismatch++;
|
||||||
}
|
}
|
||||||
nrOld++;
|
nrOld++;
|
||||||
|
@ -643,14 +650,13 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*if (nrMismatch > 0) {
|
/*if (nrMismatch > 0) {
|
||||||
logger.debug("Command response parsing summary: Added " + nrNew
|
logger.debug("Command response parsing summary: Added " + nrNew
|
||||||
+ " variables. Found " + nrOld
|
+ " variables. Found " + nrOld
|
||||||
+ " old variables. Mismatching addresses: " + nrMismatch);
|
+ " old variables. Mismatching addresses: " + nrMismatch);
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Command response parsing summary: Added " + nrNew
|
logger.debug("Command response parsing summary: Added " + nrNew
|
||||||
+ " variables. Found " + nrOld + " old variables");
|
+ " variables. Found " + nrOld + " old variables");
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
return (nrNew + nrOld) > 0;
|
return (nrNew + nrOld) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,11 +665,12 @@ public class ContikiMoteType implements MoteType {
|
||||||
* instead via ContikiMote.getMemory().
|
* instead via ContikiMote.getMemory().
|
||||||
*
|
*
|
||||||
* @param mem
|
* @param mem
|
||||||
* Memory to set
|
* Memory to set
|
||||||
*/
|
*/
|
||||||
public void getCoreMemory(SectionMoteMemory mem) {
|
public void getCoreMemory(SectionMoteMemory mem) {
|
||||||
for (int i = 0; i < mem.getNumberOfSections(); i++) {
|
for (int i = 0; i < mem.getNumberOfSections(); i++) {
|
||||||
int startAddr = mem.getSectionNativeAddress(i); /* native address space */
|
int startAddr = mem.getSectionNativeAddress(i); /* native address space */
|
||||||
|
|
||||||
int size = mem.getSizeOfSection(i);
|
int size = mem.getSizeOfSection(i);
|
||||||
byte[] data = mem.getDataOfSection(i);
|
byte[] data = mem.getDataOfSection(i);
|
||||||
getCoreMemory(startAddr, size, data);
|
getCoreMemory(startAddr, size, data);
|
||||||
|
@ -750,10 +757,10 @@ public class ContikiMoteType implements MoteType {
|
||||||
return varAddrInteger.intValue();
|
return varAddrInteger.intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
String regExp =
|
String regExp
|
||||||
Cooja.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_1") +
|
= Cooja.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_1")
|
||||||
varName +
|
+ varName
|
||||||
Cooja.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_2");
|
+ Cooja.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_2");
|
||||||
String retString = getFirstMatchGroup(mapFileData, regExp, 1);
|
String retString = getFirstMatchGroup(mapFileData, regExp, 1);
|
||||||
|
|
||||||
if (retString != null) {
|
if (retString != null) {
|
||||||
|
@ -792,37 +799,35 @@ public class ContikiMoteType implements MoteType {
|
||||||
* @return Variable names found in the data and bss section
|
* @return Variable names found in the data and bss section
|
||||||
*/
|
*/
|
||||||
public static String[] getMapFileVarNames(String[] mapFileData) {
|
public static String[] getMapFileVarNames(String[] mapFileData) {
|
||||||
ArrayList<String> varNames = new ArrayList<String>();
|
ArrayList<String> varNames = new ArrayList<>();
|
||||||
|
|
||||||
String[] dataVariables = getAllVariableNames(
|
String[] dataVariables = getAllVariableNames(
|
||||||
mapFileData,
|
mapFileData,
|
||||||
parseMapDataSectionAddr(mapFileData),
|
parseMapDataSectionAddr(mapFileData),
|
||||||
parseMapDataSectionAddr(mapFileData) + parseMapDataSectionSize(mapFileData));
|
parseMapDataSectionAddr(mapFileData) + parseMapDataSectionSize(mapFileData));
|
||||||
for (String v: dataVariables) {
|
for (String v : dataVariables) {
|
||||||
varNames.add(v);
|
varNames.add(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] bssVariables = getAllVariableNames(
|
String[] bssVariables = getAllVariableNames(
|
||||||
mapFileData,
|
mapFileData,
|
||||||
parseMapBssSectionAddr(mapFileData),
|
parseMapBssSectionAddr(mapFileData),
|
||||||
parseMapBssSectionAddr(mapFileData) + parseMapBssSectionSize(mapFileData));
|
parseMapBssSectionAddr(mapFileData) + parseMapBssSectionSize(mapFileData));
|
||||||
for (String v: bssVariables) {
|
varNames.addAll(Arrays.asList(bssVariables));
|
||||||
varNames.add(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
return varNames.toArray(new String[0]);
|
return varNames.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] getAllVariableNames(String[] lines,
|
private static String[] getAllVariableNames(String[] lines,
|
||||||
int startAddress, int endAddress) {
|
int startAddress, int endAddress) {
|
||||||
ArrayList<String> varNames = new ArrayList<String>();
|
ArrayList<String> varNames = new ArrayList<>();
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile(Cooja.getExternalToolsSetting("MAPFILE_VAR_NAME"));
|
Pattern pattern = Pattern.compile(Cooja.getExternalToolsSetting("MAPFILE_VAR_NAME"));
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
Matcher matcher = pattern.matcher(line);
|
Matcher matcher = pattern.matcher(line);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
if (Integer.decode(matcher.group(1)).intValue() >= startAddress
|
if (Integer.decode(matcher.group(1)).intValue() >= startAddress
|
||||||
&& Integer.decode(matcher.group(1)).intValue() <= endAddress) {
|
&& Integer.decode(matcher.group(1)).intValue() <= endAddress) {
|
||||||
varNames.add(matcher.group(2));
|
varNames.add(matcher.group(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -832,9 +837,9 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
protected int getVariableSize(Vector<String> lines, String varName) {
|
protected int getVariableSize(Vector<String> lines, String varName) {
|
||||||
Pattern pattern = Pattern.compile(
|
Pattern pattern = Pattern.compile(
|
||||||
Cooja.getExternalToolsSetting("MAPFILE_VAR_SIZE_1") +
|
Cooja.getExternalToolsSetting("MAPFILE_VAR_SIZE_1")
|
||||||
varName +
|
+ varName
|
||||||
Cooja.getExternalToolsSetting("MAPFILE_VAR_SIZE_2"));
|
+ Cooja.getExternalToolsSetting("MAPFILE_VAR_SIZE_2"));
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
Matcher matcher = pattern.matcher(lines.get(i));
|
Matcher matcher = pattern.matcher(lines.get(i));
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
|
@ -845,8 +850,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int parseFirstHexInt(String regexp, String[] data) {
|
private static int parseFirstHexInt(String regexp, String[] data) {
|
||||||
String retString =
|
String retString
|
||||||
getFirstMatchGroup(data, regexp, 1);
|
= getFirstMatchGroup(data, regexp, 1);
|
||||||
|
|
||||||
if (retString != null) {
|
if (retString != null) {
|
||||||
return Integer.parseInt(retString.trim(), 16);
|
return Integer.parseInt(retString.trim(), 16);
|
||||||
|
@ -862,6 +867,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return parseFirstHexInt(regexp, mapFileData);
|
return parseFirstHexInt(regexp, mapFileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseMapDataSectionSize(String[] mapFileData) {
|
public static int parseMapDataSectionSize(String[] mapFileData) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("MAPFILE_DATA_SIZE", "");
|
String regexp = Cooja.getExternalToolsSetting("MAPFILE_DATA_SIZE", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -869,6 +875,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return parseFirstHexInt(regexp, mapFileData);
|
return parseFirstHexInt(regexp, mapFileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseMapBssSectionAddr(String[] mapFileData) {
|
public static int parseMapBssSectionAddr(String[] mapFileData) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("MAPFILE_BSS_START", "");
|
String regexp = Cooja.getExternalToolsSetting("MAPFILE_BSS_START", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -876,6 +883,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return parseFirstHexInt(regexp, mapFileData);
|
return parseFirstHexInt(regexp, mapFileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseMapBssSectionSize(String[] mapFileData) {
|
public static int parseMapBssSectionSize(String[] mapFileData) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("MAPFILE_BSS_SIZE", "");
|
String regexp = Cooja.getExternalToolsSetting("MAPFILE_BSS_SIZE", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -883,6 +891,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return parseFirstHexInt(regexp, mapFileData);
|
return parseFirstHexInt(regexp, mapFileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseMapCommonSectionAddr(String[] mapFileData) {
|
public static int parseMapCommonSectionAddr(String[] mapFileData) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("MAPFILE_COMMON_START", "");
|
String regexp = Cooja.getExternalToolsSetting("MAPFILE_COMMON_START", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -890,6 +899,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return parseFirstHexInt(regexp, mapFileData);
|
return parseFirstHexInt(regexp, mapFileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseMapCommonSectionSize(String[] mapFileData) {
|
public static int parseMapCommonSectionSize(String[] mapFileData) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("MAPFILE_COMMON_SIZE", "");
|
String regexp = Cooja.getExternalToolsSetting("MAPFILE_COMMON_SIZE", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -905,6 +915,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return parseFirstHexInt(regexp, output);
|
return parseFirstHexInt(regexp, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseCommandDataSectionSize(String[] output) {
|
public static int parseCommandDataSectionSize(String[] output) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("COMMAND_DATA_END", "");
|
String regexp = Cooja.getExternalToolsSetting("COMMAND_DATA_END", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -921,6 +932,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return end - start;
|
return end - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseCommandBssSectionAddr(String[] output) {
|
public static int parseCommandBssSectionAddr(String[] output) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("COMMAND_BSS_START", "");
|
String regexp = Cooja.getExternalToolsSetting("COMMAND_BSS_START", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -928,6 +940,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return parseFirstHexInt(regexp, output);
|
return parseFirstHexInt(regexp, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseCommandBssSectionSize(String[] output) {
|
public static int parseCommandBssSectionSize(String[] output) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("COMMAND_BSS_END", "");
|
String regexp = Cooja.getExternalToolsSetting("COMMAND_BSS_END", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -944,6 +957,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return end - start;
|
return end - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseCommandCommonSectionAddr(String[] output) {
|
public static int parseCommandCommonSectionAddr(String[] output) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("COMMAND_COMMON_START", "");
|
String regexp = Cooja.getExternalToolsSetting("COMMAND_COMMON_START", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -951,6 +965,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
return parseFirstHexInt(regexp, output);
|
return parseFirstHexInt(regexp, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int parseCommandCommonSectionSize(String[] output) {
|
public static int parseCommandCommonSectionSize(String[] output) {
|
||||||
String regexp = Cooja.getExternalToolsSetting("COMMAND_COMMON_END", "");
|
String regexp = Cooja.getExternalToolsSetting("COMMAND_COMMON_END", "");
|
||||||
if (regexp.equals("")) {
|
if (regexp.equals("")) {
|
||||||
|
@ -971,6 +986,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
private static int parseCommandReadonlySectionAddr(String[] output) {
|
private static int parseCommandReadonlySectionAddr(String[] output) {
|
||||||
return parseFirstHexInt("^([0-9A-Fa-f]*)[ \t]t[ \t].text$", output);
|
return parseFirstHexInt("^([0-9A-Fa-f]*)[ \t]t[ \t].text$", output);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int parseCommandReadonlySectionSize(String[] output) {
|
private static int parseCommandReadonlySectionSize(String[] output) {
|
||||||
int start = parseCommandReadonlySectionAddr(output);
|
int start = parseCommandReadonlySectionAddr(output);
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
|
@ -978,16 +994,16 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract the last specified address, assuming that the interval covers all the memory */
|
/* Extract the last specified address, assuming that the interval covers all the memory */
|
||||||
String last = output[output.length-1];
|
String last = output[output.length - 1];
|
||||||
int lastAddress = Integer.parseInt(last.split("[ \t]")[0],16);
|
int lastAddress = Integer.parseInt(last.split("[ \t]")[0], 16);
|
||||||
return lastAddress - start;
|
return lastAddress - start;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getRelVarAddr(String mapFileData[], String varName) {
|
private static int getRelVarAddr(String mapFileData[], String varName) {
|
||||||
String regExp =
|
String regExp
|
||||||
Cooja.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_1") +
|
= Cooja.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_1")
|
||||||
varName +
|
+ varName
|
||||||
Cooja.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_2");
|
+ Cooja.getExternalToolsSetting("MAPFILE_VAR_ADDRESS_2");
|
||||||
String retString = getFirstMatchGroup(mapFileData, regExp, 1);
|
String retString = getFirstMatchGroup(mapFileData, regExp, 1);
|
||||||
|
|
||||||
if (retString != null) {
|
if (retString != null) {
|
||||||
|
@ -1012,7 +1028,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
* @return Execution response, or null at failure
|
* @return Execution response, or null at failure
|
||||||
*/
|
*/
|
||||||
public static String[] loadCommandData(File libraryFile) {
|
public static String[] loadCommandData(File libraryFile) {
|
||||||
ArrayList<String> output = new ArrayList<String>();
|
ArrayList<String> output = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String command = Cooja.getExternalToolsSetting("PARSE_COMMAND");
|
String command = Cooja.getExternalToolsSetting("PARSE_COMMAND");
|
||||||
|
@ -1022,17 +1038,17 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
/* Prepare command */
|
/* Prepare command */
|
||||||
command = command.replace("$(LIBFILE)",
|
command = command.replace("$(LIBFILE)",
|
||||||
libraryFile.getName().replace(File.separatorChar, '/'));
|
libraryFile.getName().replace(File.separatorChar, '/'));
|
||||||
|
|
||||||
/* Execute command, read response */
|
/* Execute command, read response */
|
||||||
String line;
|
String line;
|
||||||
Process p = Runtime.getRuntime().exec(
|
Process p = Runtime.getRuntime().exec(
|
||||||
command.split(" "),
|
command.split(" "),
|
||||||
null,
|
null,
|
||||||
libraryFile.getParentFile()
|
libraryFile.getParentFile()
|
||||||
);
|
);
|
||||||
BufferedReader input = new BufferedReader(
|
BufferedReader input = new BufferedReader(
|
||||||
new InputStreamReader(p.getInputStream())
|
new InputStreamReader(p.getInputStream())
|
||||||
);
|
);
|
||||||
p.getErrorStream().close();
|
p.getErrorStream().close();
|
||||||
while ((line = input.readLine()) != null) {
|
while ((line = input.readLine()) != null) {
|
||||||
|
@ -1040,11 +1056,11 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
input.close();
|
input.close();
|
||||||
|
|
||||||
if (output == null || output.size() == 0) {
|
if (output == null || output.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return output.toArray(new String[0]);
|
return output.toArray(new String[0]);
|
||||||
} catch (Exception err) {
|
} catch (IOException err) {
|
||||||
logger.fatal("Command error: " + err.getMessage(), err);
|
logger.fatal("Command error: " + err.getMessage(), err);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1070,7 +1086,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
* simulator project configuration.
|
* simulator project configuration.
|
||||||
*
|
*
|
||||||
* @param moteTypeConfig
|
* @param moteTypeConfig
|
||||||
* Project configuration
|
* Project configuration
|
||||||
*/
|
*/
|
||||||
public void setConfig(ProjectConfig moteTypeConfig) {
|
public void setConfig(ProjectConfig moteTypeConfig) {
|
||||||
myConfig = moteTypeConfig;
|
myConfig = moteTypeConfig;
|
||||||
|
@ -1098,7 +1114,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
* Set core interfaces
|
* Set core interfaces
|
||||||
*
|
*
|
||||||
* @param coreInterfaces
|
* @param coreInterfaces
|
||||||
* New core interfaces
|
* New core interfaces
|
||||||
*/
|
*/
|
||||||
public void setCoreInterfaces(String[] coreInterfaces) {
|
public void setCoreInterfaces(String[] coreInterfaces) {
|
||||||
this.coreInterfaces = coreInterfaces;
|
this.coreInterfaces = coreInterfaces;
|
||||||
|
@ -1116,10 +1132,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMoteInterfaceClasses(Class<? extends MoteInterface>[] moteInterfaces) {
|
public void setMoteInterfaceClasses(Class<? extends MoteInterface>[] moteInterfaces) {
|
||||||
this.moteInterfacesClasses = new ArrayList<Class<? extends MoteInterface>>();
|
this.moteInterfacesClasses = new ArrayList<>();
|
||||||
for (Class<? extends MoteInterface> intf: moteInterfaces) {
|
this.moteInterfacesClasses.addAll(Arrays.asList(moteInterfaces));
|
||||||
this.moteInterfacesClasses.add(intf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1127,7 +1141,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
* when loading a saved simulation.
|
* when loading a saved simulation.
|
||||||
*
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* File containg data to checksum
|
* File containg data to checksum
|
||||||
* @return Checksum
|
* @return Checksum
|
||||||
*/
|
*/
|
||||||
protected byte[] createChecksum(File file) {
|
protected byte[] createChecksum(File file) {
|
||||||
|
@ -1146,9 +1160,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileInputStream.close();
|
fileInputStream.close();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException | IOException e) {
|
||||||
return null;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return messageDigest.digest();
|
return messageDigest.digest();
|
||||||
|
@ -1195,8 +1207,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
// Check if identifier library has been loaded
|
// Check if identifier library has been loaded
|
||||||
/* XXX Currently only checks the build directory! */
|
/* XXX Currently only checks the build directory! */
|
||||||
File libraryFile = new File(
|
File libraryFile = new File(
|
||||||
ContikiMoteType.tempOutputDirectory,
|
ContikiMoteType.tempOutputDirectory,
|
||||||
testID + ContikiMoteType.librarySuffix);
|
testID + ContikiMoteType.librarySuffix);
|
||||||
if (libraryFile.exists() || CoreComm.hasLibraryFileBeenLoaded(libraryFile)) {
|
if (libraryFile.exists() || CoreComm.hasLibraryFileBeenLoaded(libraryFile)) {
|
||||||
okID = false;
|
okID = false;
|
||||||
}
|
}
|
||||||
|
@ -1215,41 +1227,41 @@ public class ContikiMoteType implements MoteType {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
// Identifier
|
// Identifier
|
||||||
sb.append("<html><table><tr><td>Identifier</td><td>")
|
sb.append("<html><table><tr><td>Identifier</td><td>")
|
||||||
.append(getIdentifier()).append("</td></tr>");
|
.append(getIdentifier()).append("</td></tr>");
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
sb.append("<tr><td>Description</td><td>")
|
sb.append("<tr><td>Description</td><td>")
|
||||||
.append(getDescription()).append("</td></tr>");
|
.append(getDescription()).append("</td></tr>");
|
||||||
|
|
||||||
/* Contiki application */
|
/* Contiki application */
|
||||||
sb.append("<tr><td>Contiki application</td><td>")
|
sb.append("<tr><td>Contiki application</td><td>")
|
||||||
.append(getContikiSourceFile().getAbsolutePath()).append("</td></tr>");
|
.append(getContikiSourceFile().getAbsolutePath()).append("</td></tr>");
|
||||||
|
|
||||||
/* Contiki firmware */
|
/* Contiki firmware */
|
||||||
sb.append("<tr><td>Contiki firmware</td><td>")
|
sb.append("<tr><td>Contiki firmware</td><td>")
|
||||||
.append(getContikiFirmwareFile().getAbsolutePath()).append("</td></tr>");
|
.append(getContikiFirmwareFile().getAbsolutePath()).append("</td></tr>");
|
||||||
|
|
||||||
/* JNI class */
|
/* JNI class */
|
||||||
sb.append("<tr><td>JNI library</td><td>")
|
sb.append("<tr><td>JNI library</td><td>")
|
||||||
.append(this.javaClassName).append("</td></tr>");
|
.append(this.javaClassName).append("</td></tr>");
|
||||||
|
|
||||||
/* Contiki sensors */
|
/* Contiki sensors */
|
||||||
sb.append("<tr><td valign=\"top\">Contiki sensors</td><td>");
|
sb.append("<tr><td valign=\"top\">Contiki sensors</td><td>");
|
||||||
for (String sensor: sensors) {
|
for (String sensor : sensors) {
|
||||||
sb.append(sensor).append("<br>");
|
sb.append(sensor).append("<br>");
|
||||||
}
|
}
|
||||||
sb.append("</td></tr>");
|
sb.append("</td></tr>");
|
||||||
|
|
||||||
/* Mote interfaces */
|
/* Mote interfaces */
|
||||||
sb.append("<tr><td valign=\"top\">Mote interface</td><td>");
|
sb.append("<tr><td valign=\"top\">Mote interface</td><td>");
|
||||||
for (Class<? extends MoteInterface> moteInterface: moteInterfacesClasses) {
|
for (Class<? extends MoteInterface> moteInterface : moteInterfacesClasses) {
|
||||||
sb.append(moteInterface.getSimpleName()).append("<br>");
|
sb.append(moteInterface.getSimpleName()).append("<br>");
|
||||||
}
|
}
|
||||||
sb.append("</td></tr>");
|
sb.append("</td></tr>");
|
||||||
|
|
||||||
/* Contiki core mote interfaces */
|
/* Contiki core mote interfaces */
|
||||||
sb.append("<tr><td valign=\"top\">Contiki's mote interface</td><td>");
|
sb.append("<tr><td valign=\"top\">Contiki's mote interface</td><td>");
|
||||||
for (String coreInterface: getCoreInterfaces()) {
|
for (String coreInterface : getCoreInterfaces()) {
|
||||||
sb.append(coreInterface).append("<br>");
|
sb.append(coreInterface).append("<br>");
|
||||||
}
|
}
|
||||||
sb.append("</td></tr>");
|
sb.append("</td></tr>");
|
||||||
|
@ -1261,7 +1273,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Element> getConfigXML(Simulation simulation) {
|
public Collection<Element> getConfigXML(Simulation simulation) {
|
||||||
ArrayList<Element> config = new ArrayList<Element>();
|
ArrayList<Element> config = new ArrayList<>();
|
||||||
Element element;
|
Element element;
|
||||||
|
|
||||||
element = new Element("identifier");
|
element = new Element("identifier");
|
||||||
|
@ -1302,8 +1314,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setConfigXML(Simulation simulation,
|
public boolean setConfigXML(Simulation simulation,
|
||||||
Collection<Element> configXML, boolean visAvailable)
|
Collection<Element> configXML, boolean visAvailable)
|
||||||
throws MoteTypeCreationException {
|
throws MoteTypeCreationException {
|
||||||
boolean warnedOldVersion = false;
|
boolean warnedOldVersion = false;
|
||||||
File oldVersionSource = null;
|
File oldVersionSource = null;
|
||||||
|
|
||||||
|
@ -1311,91 +1323,87 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
for (Element element : configXML) {
|
for (Element element : configXML) {
|
||||||
String name = element.getName();
|
String name = element.getName();
|
||||||
|
switch (name) {
|
||||||
if (name.equals("identifier")) {
|
case "identifier":
|
||||||
identifier = element.getText();
|
identifier = element.getText();
|
||||||
} else if (name.equals("description")) {
|
break;
|
||||||
description = element.getText();
|
case "description":
|
||||||
} else if (name.equals("contikiapp") || name.equals("source")) {
|
description = element.getText();
|
||||||
File file = new File(element.getText());
|
break;
|
||||||
if (!file.exists()) {
|
case "contikiapp":
|
||||||
file = simulation.getCooja().restorePortablePath(file);
|
case "source":
|
||||||
}
|
File file = new File(element.getText());
|
||||||
|
if (!file.exists()) {
|
||||||
setContikiSourceFile(file);
|
file = simulation.getCooja().restorePortablePath(file);
|
||||||
|
} setContikiSourceFile(file);
|
||||||
/* XXX Do not load the generated firmware. Instead, load the unique library file directly */
|
/* XXX Do not load the generated firmware. Instead, load the unique library file directly */
|
||||||
File contikiFirmware = new File(
|
File contikiFirmware = new File(
|
||||||
getContikiSourceFile().getParentFile(),
|
getContikiSourceFile().getParentFile(),
|
||||||
"obj_cooja/" + getIdentifier() + librarySuffix);
|
"obj_cooja/" + getIdentifier() + librarySuffix);
|
||||||
setContikiFirmwareFile(contikiFirmware);
|
setContikiFirmwareFile(contikiFirmware);
|
||||||
|
break;
|
||||||
} else if (name.equals("commands")) {
|
case "commands":
|
||||||
compileCommands = element.getText();
|
compileCommands = element.getText();
|
||||||
} else if (name.equals("symbols")) {
|
break;
|
||||||
hasSystemSymbols = Boolean.parseBoolean(element.getText());
|
case "symbols":
|
||||||
} else if (name.equals("commstack")) {
|
hasSystemSymbols = Boolean.parseBoolean(element.getText());
|
||||||
logger.warn("The Cooja communication stack config was removed: " + element.getText());
|
break;
|
||||||
logger.warn("Instead assuming default network stack.");
|
case "commstack":
|
||||||
netStack = NetworkStack.DEFAULT;
|
logger.warn("The Cooja communication stack config was removed: " + element.getText());
|
||||||
} else if (name.equals("netstack")) {
|
logger.warn("Instead assuming default network stack.");
|
||||||
netStack = NetworkStack.parseConfig(element.getText());
|
netStack = NetworkStack.DEFAULT;
|
||||||
} else if (name.equals("moteinterface")) {
|
break;
|
||||||
String intfClass = element.getText().trim();
|
case "netstack":
|
||||||
|
netStack = NetworkStack.parseConfig(element.getText());
|
||||||
/* Backwards compatibility: se.sics -> org.contikios */
|
break;
|
||||||
if (intfClass.startsWith("se.sics")) {
|
case "moteinterface":
|
||||||
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
|
String intfClass = element.getText().trim();
|
||||||
}
|
/* Backwards compatibility: se.sics -> org.contikios */
|
||||||
|
if (intfClass.startsWith("se.sics")) {
|
||||||
Class<? extends MoteInterface> moteInterfaceClass =
|
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
|
||||||
simulation.getCooja().tryLoadClass(
|
} Class<? extends MoteInterface> moteInterfaceClass
|
||||||
this, MoteInterface.class, intfClass);
|
= simulation.getCooja().tryLoadClass(
|
||||||
|
this, MoteInterface.class, intfClass);
|
||||||
if (moteInterfaceClass == null) {
|
if (moteInterfaceClass == null) {
|
||||||
logger.warn("Can't find mote interface class: " + intfClass);
|
logger.warn("Can't find mote interface class: " + intfClass);
|
||||||
} else {
|
} else {
|
||||||
moteInterfacesClasses.add(moteInterfaceClass);
|
moteInterfacesClasses.add(moteInterfaceClass);
|
||||||
}
|
} break;
|
||||||
} else if (
|
case "contikibasedir":
|
||||||
name.equals("contikibasedir") ||
|
case "contikicoredir":
|
||||||
name.equals("contikicoredir") ||
|
case "projectdir":
|
||||||
name.equals("projectdir") ||
|
case "compilefile":
|
||||||
name.equals("compilefile") ||
|
case "process":
|
||||||
name.equals("process") ||
|
case "sensor":
|
||||||
name.equals("sensor") ||
|
case "coreinterface":
|
||||||
name.equals("coreinterface")) {
|
/* Backwards compatibility: old cooja mote type is being loaded */
|
||||||
/* Backwards compatibility: old cooja mote type is being loaded */
|
if (!warnedOldVersion) {
|
||||||
if (!warnedOldVersion) {
|
warnedOldVersion = true;
|
||||||
warnedOldVersion = true;
|
logger.warn("Old simulation config detected: Cooja mote types may not load correctly");
|
||||||
logger.warn("Old simulation config detected: Cooja mote types may not load correctly");
|
} if (name.equals("compilefile")) {
|
||||||
}
|
|
||||||
|
|
||||||
if (name.equals("compilefile")) {
|
|
||||||
if (element.getText().endsWith(".c")) {
|
if (element.getText().endsWith(".c")) {
|
||||||
File potentialFile = new File(element.getText());
|
File potentialFile = new File(element.getText());
|
||||||
if (potentialFile.exists()) {
|
if (potentialFile.exists()) {
|
||||||
oldVersionSource = potentialFile;
|
oldVersionSource = potentialFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
|
default:
|
||||||
} else {
|
logger.fatal("Unrecognized entry in loaded configuration: " + name);
|
||||||
logger.fatal("Unrecognized entry in loaded configuration: " + name);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create initial core interface dependencies */
|
/* Create initial core interface dependencies */
|
||||||
Class<? extends MoteInterface>[] arr =
|
Class<? extends MoteInterface>[] arr
|
||||||
new Class[moteInterfacesClasses.size()];
|
= new Class[moteInterfacesClasses.size()];
|
||||||
moteInterfacesClasses.toArray(arr);
|
moteInterfacesClasses.toArray(arr);
|
||||||
setCoreInterfaces(ContikiMoteType.getRequiredCoreInterfaces(arr));
|
setCoreInterfaces(ContikiMoteType.getRequiredCoreInterfaces(arr));
|
||||||
|
|
||||||
/* Backwards compatibility: old cooja mote type is being loaded */
|
/* Backwards compatibility: old cooja mote type is being loaded */
|
||||||
if (getContikiSourceFile() == null &&
|
if (getContikiSourceFile() == null
|
||||||
warnedOldVersion &&
|
&& warnedOldVersion
|
||||||
oldVersionSource != null)
|
&& oldVersionSource != null) {
|
||||||
{
|
|
||||||
/* Guess Contiki source */
|
/* Guess Contiki source */
|
||||||
setContikiSourceFile(oldVersionSource);
|
setContikiSourceFile(oldVersionSource);
|
||||||
logger.info("Guessing Contiki source: " + oldVersionSource.getAbsolutePath());
|
logger.info("Guessing Contiki source: " + oldVersionSource.getAbsolutePath());
|
||||||
|
@ -1404,8 +1412,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
logger.info("Guessing Contiki firmware: " + getContikiFirmwareFile().getAbsolutePath());
|
logger.info("Guessing Contiki firmware: " + getContikiFirmwareFile().getAbsolutePath());
|
||||||
|
|
||||||
/* Guess compile commands */
|
/* Guess compile commands */
|
||||||
String compileCommands =
|
String compileCommands
|
||||||
"make " + getExpectedFirmwareFile(oldVersionSource).getName() + " TARGET=cooja";
|
= "make " + getExpectedFirmwareFile(oldVersionSource).getName() + " TARGET=cooja";
|
||||||
logger.info("Guessing compile commands: " + compileCommands);
|
logger.info("Guessing compile commands: " + compileCommands);
|
||||||
setCompileCommands(compileCommands);
|
setCompileCommands(compileCommands);
|
||||||
}
|
}
|
||||||
|
@ -1415,10 +1423,10 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getRequiredCoreInterfaces(
|
public static String[] getRequiredCoreInterfaces(
|
||||||
Class<? extends MoteInterface>[] moteInterfaces) {
|
Class<? extends MoteInterface>[] moteInterfaces) {
|
||||||
/* Extract Contiki dependencies from currently selected mote interfaces */
|
/* Extract Contiki dependencies from currently selected mote interfaces */
|
||||||
ArrayList<String> coreInterfacesList = new ArrayList<String>();
|
ArrayList<String> coreInterfacesList = new ArrayList<>();
|
||||||
for (Class<? extends MoteInterface> intf: moteInterfaces) {
|
for (Class<? extends MoteInterface> intf : moteInterfaces) {
|
||||||
if (!ContikiMoteInterface.class.isAssignableFrom(intf)) {
|
if (!ContikiMoteInterface.class.isAssignableFrom(intf)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1437,10 +1445,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
if (deps == null || deps.length == 0) {
|
if (deps == null || deps.length == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
coreInterfacesList.addAll(Arrays.asList(deps));
|
||||||
for (String dep: deps) {
|
|
||||||
coreInterfacesList.add(dep);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] coreInterfaces = new String[coreInterfacesList.size()];
|
String[] coreInterfaces = new String[coreInterfacesList.size()];
|
||||||
|
|
Loading…
Reference in a new issue