tick method returns true if mote can be ticked again immediately

This commit is contained in:
fros4943 2008-03-31 15:22:41 +00:00
parent 7579904492
commit 43ef84ad85
4 changed files with 93 additions and 83 deletions

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: Mote.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $
* $Id: Mote.java,v 1.5 2008/03/31 15:22:42 fros4943 Exp $
*/
package se.sics.cooja;
@ -177,8 +177,9 @@ public interface Mote {
*
* @param simTime
* New simulation time
* @return True is mote accepts another immediate tick
*/
public void tick(int simTime);
public boolean tick(int simTime);
/**
* Returns XML elements representing the current config of this mote. This is

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.6 2007/07/13 09:08:24 fros4943 Exp $
* $Id: ContikiMote.java,v 1.7 2008/03/31 15:22:43 fros4943 Exp $
*/
package se.sics.cooja.contikimote;
@ -97,7 +97,7 @@ public class ContikiMote implements Mote {
this.mySim = sim;
this.myType = moteType;
this.myMemory = moteType.createInitialMemory();
this.myInterfaceHandler = new MoteInterfaceHandler((Mote) this, moteType.getMoteInterfaces());
this.myInterfaceHandler = new MoteInterfaceHandler(this, moteType.getMoteInterfaces());
myState = State.ACTIVE;
}
@ -176,12 +176,13 @@ public class ContikiMote implements Mote {
*
* @param simTime Current simulation time
*/
public void tick(int simTime) {
public boolean tick(int simTime) {
State currentState = getState();
// If mote is dead, do nothing at all
if (currentState == State.DEAD)
return;
if (currentState == State.DEAD) {
return false;
}
// If mote is sleeping and has a wake up time, should it wake up now?
if (currentState == State.LPM && wakeUpTime > 0 && wakeUpTime <= simTime) {
@ -240,6 +241,8 @@ public class ContikiMote implements Mote {
}
}
return false;
}
/**
@ -295,7 +298,7 @@ public class ContikiMote implements Mote {
if (name.equals("motetype_identifier")) {
myType = (ContikiMoteType) simulation.getMoteType(element.getText());
myMemory = myType.createInitialMemory();
myInterfaceHandler = new MoteInterfaceHandler((Mote) this, myType.getMoteInterfaces());
myInterfaceHandler = new MoteInterfaceHandler(this, myType.getMoteInterfaces());
} else if (name.equals("interface_config")) {
Class<? extends MoteInterface> moteInterfaceClass =
@ -307,12 +310,13 @@ public class ContikiMote implements Mote {
}
MoteInterface moteInterface = myInterfaceHandler.getInterfaceOfType(moteInterfaceClass);
if (moteInterface != null)
if (moteInterface != null) {
moteInterface.setConfigXML(element.getChildren(), visAvailable);
else
} else {
logger.warn("Can't restore configuration for non-existing interface: " + moteInterfaceClass.getName());
}
}
}
return true;
}
@ -320,8 +324,9 @@ public class ContikiMote implements Mote {
public String toString() {
if (getInterfaces().getMoteID() != null) {
return "Contiki Mote, ID=" + getInterfaces().getMoteID().getMoteID();
} else
} else {
return "Contiki Mote, ID=null";
}
}
}

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: DisturberMote.java,v 1.2 2007/01/09 10:01:14 fros4943 Exp $
* $Id: DisturberMote.java,v 1.3 2008/03/31 15:22:42 fros4943 Exp $
*/
package se.sics.cooja.motes;
@ -141,11 +141,12 @@ public class DisturberMote implements Mote {
this.mySim = simulation;
}
public void tick(int simTime) {
public boolean tick(int simTime) {
myInterfaceHandler.doPassiveActionsBeforeTick();
myInterfaceHandler.doActiveActionsBeforeTick();
myInterfaceHandler.doActiveActionsAfterTick();
myInterfaceHandler.doPassiveActionsAfterTick();
return false;
}
public Collection<Element> getConfigXML() {
@ -228,8 +229,9 @@ public class DisturberMote implements Mote {
public String toString() {
if (getInterfaces().getMoteID() != null) {
return "Disturber Mote, ID=" + getInterfaces().getMoteID().getMoteID();
} else
} else {
return "Disturber Mote, ID=null";
}
}
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: DummyMote.java,v 1.3 2007/01/09 10:01:14 fros4943 Exp $
* $Id: DummyMote.java,v 1.4 2008/03/31 15:22:41 fros4943 Exp $
*/
package se.sics.cooja.motes;
@ -146,7 +146,7 @@ public class DummyMote implements Mote {
this.mySim = simulation;
}
public void tick(int simTime) {
public boolean tick(int simTime) {
// Perform some dummy task
if (myRandom.nextDouble() > 0.9) {
@ -157,6 +157,7 @@ public class DummyMote implements Mote {
+ myRandom.nextDouble() - 0.5, myPosition.getZCoordinate()
+ myRandom.nextDouble() - 0.5);
}
return false;
}
public Collection<Element> getConfigXML() {
@ -215,8 +216,9 @@ public class DummyMote implements Mote {
public String toString() {
if (getInterfaces().getMoteID() != null) {
return "Dummy Mote, ID=" + getInterfaces().getMoteID().getMoteID();
} else
} else {
return "Dummy Mote, ID=null";
}
}
}