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
* 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;
@ -280,12 +280,7 @@ public class MicaZMote implements Mote {
}
public String toString() {
MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null;
if (moteID != null) {
return "MicaZ Mote, ID=" + moteID.getMoteID();
} else {
return "MicaZ Mote, ID=null";
}
return "MicaZ " + getID();
}
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -67,12 +67,7 @@ public class ESBMote extends MspMote {
}
public String toString() {
MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null;
if (moteID != null) {
return "ESB Mote, ID=" + moteID.getMoteID();
} else {
return "ESB Mote, ID=null";
}
return "ESB " + getID();
}
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -36,7 +36,6 @@ import java.io.File;
import org.apache.log4j.Logger;
import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.MoteID;
import se.sics.mspsim.platform.sky.SkyNode;
/**
@ -71,12 +70,7 @@ public class SkyMote extends MspMote {
}
public String toString() {
MoteID moteID = getInterfaces() != null ? getInterfaces().getMoteID() : null;
if (moteID != null) {
return "Sky Mote, ID=" + moteID.getMoteID();
} else {
return "Sky Mote, ID=null";
}
return "Sky " + getID();
}
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -68,7 +68,7 @@ public class MspCLI extends VisPlugin {
private LineListener myListener;
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;
final Container panel = getContentPane();

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -225,7 +225,7 @@ public class ContikiMote implements Mote {
}
public String toString() {
return "Contiki Mote ID=" + getID();
return "Contiki " + getID();
}
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
* 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;
@ -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;
for (int i = 0; i < simulation.getMotesCount(); i++) {
MoteID moteID = simulation.getMote(i).getInterfaces()
.getMoteID();
if (moteID != null && moteID.getMoteID() >= nextMoteID) {
nextMoteID = moteID.getMoteID() + 1;
for (Mote m: simulation.getMotes()) {
int existing = m.getID();
if (existing >= nextMoteID) {
nextMoteID = existing + 1;
}
}
for (int i = 0; i < newMotes.size(); i++) {
MoteID moteID = newMotes.get(i).getInterfaces().getMoteID();
for (Mote m: newMotes) {
MoteID moteID = m.getInterfaces().getMoteID();
if (moteID != null) {
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
* 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;
@ -54,15 +54,12 @@ public class IdIPDistributor extends IPDistributor {
generatedIPAddresses = new Vector<String>();
for (int i=0; i < newMotes.size(); i++) {
if (newMotes.get(i).getInterfaces().getMoteID() != null) {
int moteId = newMotes.get(i).getInterfaces().getMoteID().getMoteID();
generatedIPAddresses.add("10." +
(moteId / 256 % (256*256))
+ "." +
(moteId % 256)
+ ".1");
} else
generatedIPAddresses.add("0.0.0.0");
int moteId = newMotes.get(i).getID();
generatedIPAddresses.add("10." +
(moteId / 256 % (256*256))
+ "." +
(moteId % 256)
+ ".1");
}
}

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* 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;
@ -105,10 +105,7 @@ public class EventListener extends VisPlugin {
public void update(Observable obs, Object obj) {
final MoteInterface moteInterface = (MoteInterface) obs;
int moteID = -1;
if (myMote.getInterfaces().getMoteID() != null) {
moteID = myMote.getInterfaces().getMoteID().getMoteID();
}
int moteID = myMote.getID();
myParent.actOnChange("'" + GUI.getDescriptionOf(moteInterface.getClass())
+ "'" + " 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
* 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;
@ -356,17 +356,9 @@ public class LogListener extends VisPlugin {
public LogData(LogOutputEvent ev) {
this.ev = ev;
this.strID = "ID:" + getMoteID(ev.getMote());
this.strID = "ID:" + ev.getMote().getID();
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") {

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -118,7 +118,7 @@ public class LogScriptEngine {
Mote mote = (Mote) obj;
handleNewMoteOutput(
mote,
mote.getInterfaces().getMoteID().getMoteID(),
mote.getID(),
mote.getSimulation().getSimulationTime(),
mote.getInterfaces().getLog().getLastLogMessage()
);
@ -167,7 +167,7 @@ public class LogScriptEngine {
public void execute(long time) {
handleNewMoteOutput(
mote,
mote.getInterfaces().getMoteID().getMoteID(),
mote.getID(),
mote.getSimulation().getSimulationTime(),
msg
);
@ -405,7 +405,7 @@ public class LogScriptEngine {
/* Update script variables */
engine.put("mote", currentMote);
engine.put("id", currentMote.getInterfaces().getMoteID().getMoteID());
engine.put("id", currentMote.getID());
engine.put("time", currentMote.getSimulation().getSimulationTime());
engine.put("msg", msg);

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -130,17 +130,17 @@ public class RadioLogger extends VisPlugin {
if (col == COLUMN_TIME) {
return Long.toString(conn.startTime / Simulation.MILLISECOND);
} else if (col == COLUMN_FROM) {
return getMoteID(conn.connection.getSource().getMote());
return "" + conn.connection.getSource().getMote().getID();
} else if (col == COLUMN_TO) {
Radio[] dests = conn.connection.getDestinations();
if (dests.length == 0) {
return "-";
}
if (dests.length == 1) {
return getMoteID(dests[0].getMote());
return dests[0].getMote().getID();
}
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]";
} 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) {
byte[] data;
if (conn.packet == null) {
@ -385,11 +377,11 @@ public class RadioLogger extends VisPlugin {
return "-";
}
if (dests.length == 1) {
return getMoteID(dests[0].getMote());
return "" + dests[0].getMote().getID();
}
StringBuilder sb = new StringBuilder();
for (Radio dest: dests) {
sb.append(getMoteID(dest.getMote()) + ',');
sb.append(dest.getMote().getID() + ',');
}
sb.setLength(sb.length()-1);
return sb.toString();

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -46,7 +46,7 @@ public class ScriptMote {
public void setMoteMsg(Mote mote, String msg) {
this.mote = mote;
if (mote != null) {
id = mote.getInterfaces().getMoteID().getMoteID();
id = mote.getID();
} else {
id = -1;
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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;
@ -1232,10 +1232,7 @@ public class TimeLine extends VisPlugin {
g.setFont(new Font("SansSerif", Font.PLAIN, paintedMoteHeight));
int y = FIRST_MOTE_PIXEL_OFFSET-EVENT_PIXEL_HEIGHT/2+paintedMoteHeight;
for (MoteEvents moteLog: allMoteEvents) {
String str = "??";
if (moteLog.mote.getInterfaces().getMoteID() != null) {
str = "" + moteLog.mote.getInterfaces().getMoteID().getMoteID();
}
String str = "" + moteLog.mote.getID();
int w = g.getFontMetrics().stringWidth(str) + 1;
/*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
* 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;
@ -80,15 +80,10 @@ public class IDVisualizerSkin implements VisualizerSkin {
/* Paint ID inside each mote */
Mote[] allMotes = simulation.getMotes();
for (Mote mote: allMotes) {
MoteID id = mote.getInterfaces().getMoteID();
if (id == null) {
continue;
}
Position pos = mote.getInterfaces().getPosition();
Point pixel = visualizer.transformPositionToPixel(pos);
String msg = "" + id.getMoteID();
String msg = "" + mote.getID();
int msgWidth = fm.stringWidth(msg);
g.drawString(msg, pixel.x - msgWidth/2, pixel.y + 5);
}