[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";
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -223,8 +230,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
||||||
}
|
}
|
||||||
|
@ -291,8 +298,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
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++) {
|
||||||
|
@ -322,8 +328,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
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);
|
||||||
|
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -375,8 +383,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
"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,34 +461,34 @@ 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
|
||||||
|
@ -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 */
|
||||||
|
@ -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);
|
||||||
|
@ -650,7 +657,6 @@ public class ContikiMoteType implements MoteType {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,6 +670,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
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,7 +799,7 @@ 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,
|
||||||
|
@ -806,16 +813,14 @@ public class ContikiMoteType implements MoteType {
|
||||||
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) {
|
||||||
|
@ -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) {
|
||||||
|
@ -984,10 +1000,10 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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();
|
||||||
|
@ -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");
|
||||||
|
@ -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;
|
||||||
|
case "description":
|
||||||
description = element.getText();
|
description = element.getText();
|
||||||
} else if (name.equals("contikiapp") || name.equals("source")) {
|
break;
|
||||||
|
case "contikiapp":
|
||||||
|
case "source":
|
||||||
File file = new File(element.getText());
|
File file = new File(element.getText());
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file = simulation.getCooja().restorePortablePath(file);
|
file = simulation.getCooja().restorePortablePath(file);
|
||||||
}
|
} setContikiSourceFile(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;
|
||||||
|
case "symbols":
|
||||||
hasSystemSymbols = Boolean.parseBoolean(element.getText());
|
hasSystemSymbols = Boolean.parseBoolean(element.getText());
|
||||||
} else if (name.equals("commstack")) {
|
break;
|
||||||
|
case "commstack":
|
||||||
logger.warn("The Cooja communication stack config was removed: " + element.getText());
|
logger.warn("The Cooja communication stack config was removed: " + element.getText());
|
||||||
logger.warn("Instead assuming default network stack.");
|
logger.warn("Instead assuming default network stack.");
|
||||||
netStack = NetworkStack.DEFAULT;
|
netStack = NetworkStack.DEFAULT;
|
||||||
} else if (name.equals("netstack")) {
|
break;
|
||||||
|
case "netstack":
|
||||||
netStack = NetworkStack.parseConfig(element.getText());
|
netStack = NetworkStack.parseConfig(element.getText());
|
||||||
} else if (name.equals("moteinterface")) {
|
break;
|
||||||
|
case "moteinterface":
|
||||||
String intfClass = element.getText().trim();
|
String intfClass = element.getText().trim();
|
||||||
|
|
||||||
/* Backwards compatibility: se.sics -> org.contikios */
|
/* Backwards compatibility: se.sics -> org.contikios */
|
||||||
if (intfClass.startsWith("se.sics")) {
|
if (intfClass.startsWith("se.sics")) {
|
||||||
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
|
intfClass = intfClass.replaceFirst("se\\.sics", "org.contikios");
|
||||||
}
|
} Class<? extends MoteInterface> moteInterfaceClass
|
||||||
|
= simulation.getCooja().tryLoadClass(
|
||||||
Class<? extends MoteInterface> moteInterfaceClass =
|
|
||||||
simulation.getCooja().tryLoadClass(
|
|
||||||
this, MoteInterface.class, intfClass);
|
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);
|
||||||
}
|
}
|
||||||
|
@ -1417,7 +1425,7 @@ 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