removing unsafe MoteID interface dependencies

This commit is contained in:
fros4943 2009-09-17 13:19:08 +00:00
parent 87aa2c2aad
commit e974b896dc
14 changed files with 48 additions and 93 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MicaZMote.java,v 1.7 2009/09/17 10:45:14 fros4943 Exp $ * $Id: MicaZMote.java,v 1.8 2009/09/17 13:19:08 fros4943 Exp $
*/ */
package se.sics.cooja.avrmote; package se.sics.cooja.avrmote;
@ -280,12 +280,7 @@ public class MicaZMote implements Mote {
} }
public String toString() { public String toString() {
MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null; return "MicaZ " + getID();
if (moteID != null) {
return "MicaZ Mote, ID=" + moteID.getMoteID();
} else {
return "MicaZ Mote, ID=null";
}
} }
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ESBMote.java,v 1.9 2009/09/17 10:50:11 fros4943 Exp $ * $Id: ESBMote.java,v 1.10 2009/09/17 13:19:08 fros4943 Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
@ -67,12 +67,7 @@ public class ESBMote extends MspMote {
} }
public String toString() { public String toString() {
MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null; return "ESB " + getID();
if (moteID != null) {
return "ESB Mote, ID=" + moteID.getMoteID();
} else {
return "ESB Mote, ID=null";
}
} }
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: SkyMote.java,v 1.15 2009/09/17 10:50:11 fros4943 Exp $ * $Id: SkyMote.java,v 1.16 2009/09/17 13:19:08 fros4943 Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
@ -36,7 +36,6 @@ import java.io.File;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.MoteID;
import se.sics.mspsim.platform.sky.SkyNode; import se.sics.mspsim.platform.sky.SkyNode;
/** /**
@ -71,12 +70,7 @@ public class SkyMote extends MspMote {
} }
public String toString() { public String toString() {
MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null; return "Sky " + getID();
if (moteID != null) {
return "Sky Mote, ID=" + moteID.getMoteID();
} else {
return "Sky Mote, ID=null";
}
} }
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MspCLI.java,v 1.2 2009/03/21 14:40:22 fros4943 Exp $ * $Id: MspCLI.java,v 1.3 2009/09/17 13:19:08 fros4943 Exp $
*/ */
package se.sics.cooja.mspmote.plugins; package se.sics.cooja.mspmote.plugins;
@ -68,7 +68,7 @@ public class MspCLI extends VisPlugin {
private LineListener myListener; private LineListener myListener;
public MspCLI(Mote mote, Simulation simulationToVisualize, GUI gui) { public MspCLI(Mote mote, Simulation simulationToVisualize, GUI gui) {
super("Msp CLI (" + mote.getInterfaces().getMoteID().getMoteID() + ')', gui); super("Msp CLI (" + mote.getID() + ')', gui);
this.mspMote = (MspMote) mote; this.mspMote = (MspMote) mote;
final Container panel = getContentPane(); final Container panel = getContentPane();

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ContikiMote.java,v 1.13 2009/09/17 11:05:56 fros4943 Exp $ * $Id: ContikiMote.java,v 1.14 2009/09/17 13:20:03 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -225,7 +225,7 @@ public class ContikiMote implements Mote {
} }
public String toString() { public String toString() {
return "Contiki Mote ID=" + getID(); return "Contiki " + getID();
} }
private TimeEvent tickMoteEvent = new MoteTimeEvent(this, 0) { private TimeEvent tickMoteEvent = new MoteTimeEvent(this, 0) {

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: AddMoteDialog.java,v 1.9 2009/04/20 16:09:29 fros4943 Exp $ * $Id: AddMoteDialog.java,v 1.10 2009/09/17 13:20:03 fros4943 Exp $
*/ */
package se.sics.cooja.dialogs; package se.sics.cooja.dialogs;
@ -504,20 +504,21 @@ public class AddMoteDialog extends JDialog {
} }
} }
// Set unique mote id's for all new motes /* Set unique mote id's for all new motes
* TODO ID should be provided differently; not rely on the unsafe MoteID interface */
int nextMoteID = 1; int nextMoteID = 1;
for (int i = 0; i < simulation.getMotesCount(); i++) { for (Mote m: simulation.getMotes()) {
MoteID moteID = simulation.getMote(i).getInterfaces() int existing = m.getID();
.getMoteID(); if (existing >= nextMoteID) {
if (moteID != null && moteID.getMoteID() >= nextMoteID) { nextMoteID = existing + 1;
nextMoteID = moteID.getMoteID() + 1;
} }
} }
for (Mote m: newMotes) {
for (int i = 0; i < newMotes.size(); i++) { MoteID moteID = m.getInterfaces().getMoteID();
MoteID moteID = newMotes.get(i).getInterfaces().getMoteID();
if (moteID != null) { if (moteID != null) {
moteID.setMoteID(nextMoteID++); moteID.setMoteID(nextMoteID++);
} else {
logger.warn("Can't set mote ID (no mote ID interface): " + m);
} }
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: IdIPDistributor.java,v 1.1 2006/08/21 12:13:06 fros4943 Exp $ * $Id: IdIPDistributor.java,v 1.2 2009/09/17 13:20:03 fros4943 Exp $
*/ */
package se.sics.cooja.ipdistributors; package se.sics.cooja.ipdistributors;
@ -54,15 +54,12 @@ public class IdIPDistributor extends IPDistributor {
generatedIPAddresses = new Vector<String>(); generatedIPAddresses = new Vector<String>();
for (int i=0; i < newMotes.size(); i++) { for (int i=0; i < newMotes.size(); i++) {
if (newMotes.get(i).getInterfaces().getMoteID() != null) { int moteId = newMotes.get(i).getID();
int moteId = newMotes.get(i).getInterfaces().getMoteID().getMoteID(); generatedIPAddresses.add("10." +
generatedIPAddresses.add("10." + (moteId / 256 % (256*256))
(moteId / 256 % (256*256)) + "." +
+ "." + (moteId % 256)
(moteId % 256) + ".1");
+ ".1");
} else
generatedIPAddresses.add("0.0.0.0");
} }
} }

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: EventListener.java,v 1.9 2009/06/10 15:57:08 fros4943 Exp $ * $Id: EventListener.java,v 1.10 2009/09/17 13:20:48 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -105,10 +105,7 @@ public class EventListener extends VisPlugin {
public void update(Observable obs, Object obj) { public void update(Observable obs, Object obj) {
final MoteInterface moteInterface = (MoteInterface) obs; final MoteInterface moteInterface = (MoteInterface) obs;
int moteID = -1; int moteID = myMote.getID();
if (myMote.getInterfaces().getMoteID() != null) {
moteID = myMote.getInterfaces().getMoteID().getMoteID();
}
myParent.actOnChange("'" + GUI.getDescriptionOf(moteInterface.getClass()) myParent.actOnChange("'" + GUI.getDescriptionOf(moteInterface.getClass())
+ "'" + " of mote '" + (moteID > 0 ? Integer.toString(moteID) : "?") + "'" + " of mote '" + (moteID > 0 ? Integer.toString(moteID) : "?")

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: LogListener.java,v 1.19 2009/07/06 14:04:21 nifi Exp $ * $Id: LogListener.java,v 1.20 2009/09/17 13:20:48 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -356,17 +356,9 @@ public class LogListener extends VisPlugin {
public LogData(LogOutputEvent ev) { public LogData(LogOutputEvent ev) {
this.ev = ev; this.ev = ev;
this.strID = "ID:" + getMoteID(ev.getMote()); this.strID = "ID:" + ev.getMote().getID();
this.strTime = "" + ev.getTime()/Simulation.MILLISECOND; this.strTime = "" + ev.getTime()/Simulation.MILLISECOND;
} }
private static String getMoteID(Mote mote) {
MoteID moteID = mote.getInterfaces().getMoteID();
if (moteID != null) {
return Integer.toString(moteID.getMoteID());
}
return mote.toString();
}
} }
private Action saveAction = new AbstractAction("Save to file") { private Action saveAction = new AbstractAction("Save to file") {

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: LogScriptEngine.java,v 1.17 2009/06/15 17:39:02 fros4943 Exp $ * $Id: LogScriptEngine.java,v 1.18 2009/09/17 13:20:48 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -118,7 +118,7 @@ public class LogScriptEngine {
Mote mote = (Mote) obj; Mote mote = (Mote) obj;
handleNewMoteOutput( handleNewMoteOutput(
mote, mote,
mote.getInterfaces().getMoteID().getMoteID(), mote.getID(),
mote.getSimulation().getSimulationTime(), mote.getSimulation().getSimulationTime(),
mote.getInterfaces().getLog().getLastLogMessage() mote.getInterfaces().getLog().getLastLogMessage()
); );
@ -167,7 +167,7 @@ public class LogScriptEngine {
public void execute(long time) { public void execute(long time) {
handleNewMoteOutput( handleNewMoteOutput(
mote, mote,
mote.getInterfaces().getMoteID().getMoteID(), mote.getID(),
mote.getSimulation().getSimulationTime(), mote.getSimulation().getSimulationTime(),
msg msg
); );
@ -405,7 +405,7 @@ public class LogScriptEngine {
/* Update script variables */ /* Update script variables */
engine.put("mote", currentMote); engine.put("mote", currentMote);
engine.put("id", currentMote.getInterfaces().getMoteID().getMoteID()); engine.put("id", currentMote.getID());
engine.put("time", currentMote.getSimulation().getSimulationTime()); engine.put("time", currentMote.getSimulation().getSimulationTime());
engine.put("msg", msg); engine.put("msg", msg);

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: RadioLogger.java,v 1.22 2009/06/15 10:53:24 fros4943 Exp $ * $Id: RadioLogger.java,v 1.23 2009/09/17 13:20:48 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -130,17 +130,17 @@ public class RadioLogger extends VisPlugin {
if (col == COLUMN_TIME) { if (col == COLUMN_TIME) {
return Long.toString(conn.startTime / Simulation.MILLISECOND); return Long.toString(conn.startTime / Simulation.MILLISECOND);
} else if (col == COLUMN_FROM) { } else if (col == COLUMN_FROM) {
return getMoteID(conn.connection.getSource().getMote()); return "" + conn.connection.getSource().getMote().getID();
} else if (col == COLUMN_TO) { } else if (col == COLUMN_TO) {
Radio[] dests = conn.connection.getDestinations(); Radio[] dests = conn.connection.getDestinations();
if (dests.length == 0) { if (dests.length == 0) {
return "-"; return "-";
} }
if (dests.length == 1) { if (dests.length == 1) {
return getMoteID(dests[0].getMote()); return dests[0].getMote().getID();
} }
if (dests.length == 2) { if (dests.length == 2) {
return getMoteID(dests[0].getMote()) + ',' + getMoteID(dests[1].getMote()); return dests[0].getMote().getID() + ',' + dests[1].getMote().getID();
} }
return "[" + dests.length + " d]"; return "[" + dests.length + " d]";
} else if (col == COLUMN_DATA) { } else if (col == COLUMN_DATA) {
@ -295,14 +295,6 @@ public class RadioLogger extends VisPlugin {
} }
} }
private String getMoteID(Mote mote) {
MoteID moteID = mote.getInterfaces().getMoteID();
if (moteID != null) {
return Integer.toString(moteID.getMoteID());
}
return mote.toString();
}
private void prepareDataString(RadioConnectionLog conn) { private void prepareDataString(RadioConnectionLog conn) {
byte[] data; byte[] data;
if (conn.packet == null) { if (conn.packet == null) {
@ -385,11 +377,11 @@ public class RadioLogger extends VisPlugin {
return "-"; return "-";
} }
if (dests.length == 1) { if (dests.length == 1) {
return getMoteID(dests[0].getMote()); return "" + dests[0].getMote().getID();
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Radio dest: dests) { for (Radio dest: dests) {
sb.append(getMoteID(dest.getMote()) + ','); sb.append(dest.getMote().getID() + ',');
} }
sb.setLength(sb.length()-1); sb.setLength(sb.length()-1);
return sb.toString(); return sb.toString();

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ScriptMote.java,v 1.1 2008/09/22 16:20:03 joxe Exp $ * $Id: ScriptMote.java,v 1.2 2009/09/17 13:20:48 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -46,7 +46,7 @@ public class ScriptMote {
public void setMoteMsg(Mote mote, String msg) { public void setMoteMsg(Mote mote, String msg) {
this.mote = mote; this.mote = mote;
if (mote != null) { if (mote != null) {
id = mote.getInterfaces().getMoteID().getMoteID(); id = mote.getID();
} else { } else {
id = -1; id = -1;
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: TimeLine.java,v 1.12 2009/08/27 16:38:09 fros4943 Exp $ * $Id: TimeLine.java,v 1.13 2009/09/17 13:20:48 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -1232,10 +1232,7 @@ public class TimeLine extends VisPlugin {
g.setFont(new Font("SansSerif", Font.PLAIN, paintedMoteHeight)); g.setFont(new Font("SansSerif", Font.PLAIN, paintedMoteHeight));
int y = FIRST_MOTE_PIXEL_OFFSET-EVENT_PIXEL_HEIGHT/2+paintedMoteHeight; int y = FIRST_MOTE_PIXEL_OFFSET-EVENT_PIXEL_HEIGHT/2+paintedMoteHeight;
for (MoteEvents moteLog: allMoteEvents) { for (MoteEvents moteLog: allMoteEvents) {
String str = "??"; String str = "" + moteLog.mote.getID();
if (moteLog.mote.getInterfaces().getMoteID() != null) {
str = "" + moteLog.mote.getInterfaces().getMoteID().getMoteID();
}
int w = g.getFontMetrics().stringWidth(str) + 1; int w = g.getFontMetrics().stringWidth(str) + 1;
/*g.drawRect(0, y, getWidth()-1, paintedMoteHeight);*/ /*g.drawRect(0, y, getWidth()-1, paintedMoteHeight);*/

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: IDVisualizerSkin.java,v 1.2 2009/08/27 13:59:47 fros4943 Exp $ * $Id: IDVisualizerSkin.java,v 1.3 2009/09/17 13:20:59 fros4943 Exp $
*/ */
package se.sics.cooja.plugins.skins; package se.sics.cooja.plugins.skins;
@ -80,15 +80,10 @@ public class IDVisualizerSkin implements VisualizerSkin {
/* Paint ID inside each mote */ /* Paint ID inside each mote */
Mote[] allMotes = simulation.getMotes(); Mote[] allMotes = simulation.getMotes();
for (Mote mote: allMotes) { for (Mote mote: allMotes) {
MoteID id = mote.getInterfaces().getMoteID();
if (id == null) {
continue;
}
Position pos = mote.getInterfaces().getPosition(); Position pos = mote.getInterfaces().getPosition();
Point pixel = visualizer.transformPositionToPixel(pos); Point pixel = visualizer.transformPositionToPixel(pos);
String msg = "" + id.getMoteID(); String msg = "" + mote.getID();
int msgWidth = fm.stringWidth(msg); int msgWidth = fm.stringWidth(msg);
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 5); g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 5);
} }