tick method returns true if mote can be ticked again immediately
This commit is contained in:
parent
7579904492
commit
43ef84ad85
4 changed files with 93 additions and 83 deletions
|
@ -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: 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;
|
package se.sics.cooja;
|
||||||
|
@ -177,8 +177,9 @@ public interface Mote {
|
||||||
*
|
*
|
||||||
* @param simTime
|
* @param simTime
|
||||||
* New simulation time
|
* 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
|
* Returns XML elements representing the current config of this mote. This is
|
||||||
|
|
|
@ -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.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;
|
package se.sics.cooja.contikimote;
|
||||||
|
@ -97,7 +97,7 @@ public class ContikiMote implements Mote {
|
||||||
this.mySim = sim;
|
this.mySim = sim;
|
||||||
this.myType = moteType;
|
this.myType = moteType;
|
||||||
this.myMemory = moteType.createInitialMemory();
|
this.myMemory = moteType.createInitialMemory();
|
||||||
this.myInterfaceHandler = new MoteInterfaceHandler((Mote) this, moteType.getMoteInterfaces());
|
this.myInterfaceHandler = new MoteInterfaceHandler(this, moteType.getMoteInterfaces());
|
||||||
|
|
||||||
myState = State.ACTIVE;
|
myState = State.ACTIVE;
|
||||||
}
|
}
|
||||||
|
@ -176,12 +176,13 @@ public class ContikiMote implements Mote {
|
||||||
*
|
*
|
||||||
* @param simTime Current simulation time
|
* @param simTime Current simulation time
|
||||||
*/
|
*/
|
||||||
public void tick(int simTime) {
|
public boolean tick(int simTime) {
|
||||||
State currentState = getState();
|
State currentState = getState();
|
||||||
|
|
||||||
// If mote is dead, do nothing at all
|
// If mote is dead, do nothing at all
|
||||||
if (currentState == State.DEAD)
|
if (currentState == State.DEAD) {
|
||||||
return;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// If mote is sleeping and has a wake up time, should it wake up now?
|
// If mote is sleeping and has a wake up time, should it wake up now?
|
||||||
if (currentState == State.LPM && wakeUpTime > 0 && wakeUpTime <= simTime) {
|
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")) {
|
if (name.equals("motetype_identifier")) {
|
||||||
myType = (ContikiMoteType) simulation.getMoteType(element.getText());
|
myType = (ContikiMoteType) simulation.getMoteType(element.getText());
|
||||||
myMemory = myType.createInitialMemory();
|
myMemory = myType.createInitialMemory();
|
||||||
myInterfaceHandler = new MoteInterfaceHandler((Mote) this, myType.getMoteInterfaces());
|
myInterfaceHandler = new MoteInterfaceHandler(this, myType.getMoteInterfaces());
|
||||||
|
|
||||||
} else if (name.equals("interface_config")) {
|
} else if (name.equals("interface_config")) {
|
||||||
Class<? extends MoteInterface> moteInterfaceClass =
|
Class<? extends MoteInterface> moteInterfaceClass =
|
||||||
|
@ -307,10 +310,11 @@ public class ContikiMote implements Mote {
|
||||||
}
|
}
|
||||||
|
|
||||||
MoteInterface moteInterface = myInterfaceHandler.getInterfaceOfType(moteInterfaceClass);
|
MoteInterface moteInterface = myInterfaceHandler.getInterfaceOfType(moteInterfaceClass);
|
||||||
if (moteInterface != null)
|
if (moteInterface != null) {
|
||||||
moteInterface.setConfigXML(element.getChildren(), visAvailable);
|
moteInterface.setConfigXML(element.getChildren(), visAvailable);
|
||||||
else
|
} else {
|
||||||
logger.warn("Can't restore configuration for non-existing interface: " + moteInterfaceClass.getName());
|
logger.warn("Can't restore configuration for non-existing interface: " + moteInterfaceClass.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,8 +324,9 @@ public class ContikiMote implements Mote {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (getInterfaces().getMoteID() != null) {
|
if (getInterfaces().getMoteID() != null) {
|
||||||
return "Contiki Mote, ID=" + getInterfaces().getMoteID().getMoteID();
|
return "Contiki Mote, ID=" + getInterfaces().getMoteID().getMoteID();
|
||||||
} else
|
} else {
|
||||||
return "Contiki Mote, ID=null";
|
return "Contiki Mote, ID=null";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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: 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;
|
package se.sics.cooja.motes;
|
||||||
|
@ -141,11 +141,12 @@ public class DisturberMote implements Mote {
|
||||||
this.mySim = simulation;
|
this.mySim = simulation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick(int simTime) {
|
public boolean tick(int simTime) {
|
||||||
myInterfaceHandler.doPassiveActionsBeforeTick();
|
myInterfaceHandler.doPassiveActionsBeforeTick();
|
||||||
myInterfaceHandler.doActiveActionsBeforeTick();
|
myInterfaceHandler.doActiveActionsBeforeTick();
|
||||||
myInterfaceHandler.doActiveActionsAfterTick();
|
myInterfaceHandler.doActiveActionsAfterTick();
|
||||||
myInterfaceHandler.doPassiveActionsAfterTick();
|
myInterfaceHandler.doPassiveActionsAfterTick();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Element> getConfigXML() {
|
public Collection<Element> getConfigXML() {
|
||||||
|
@ -228,8 +229,9 @@ public class DisturberMote implements Mote {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (getInterfaces().getMoteID() != null) {
|
if (getInterfaces().getMoteID() != null) {
|
||||||
return "Disturber Mote, ID=" + getInterfaces().getMoteID().getMoteID();
|
return "Disturber Mote, ID=" + getInterfaces().getMoteID().getMoteID();
|
||||||
} else
|
} else {
|
||||||
return "Disturber Mote, ID=null";
|
return "Disturber Mote, ID=null";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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: 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;
|
package se.sics.cooja.motes;
|
||||||
|
@ -146,7 +146,7 @@ public class DummyMote implements Mote {
|
||||||
this.mySim = simulation;
|
this.mySim = simulation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick(int simTime) {
|
public boolean tick(int simTime) {
|
||||||
|
|
||||||
// Perform some dummy task
|
// Perform some dummy task
|
||||||
if (myRandom.nextDouble() > 0.9) {
|
if (myRandom.nextDouble() > 0.9) {
|
||||||
|
@ -157,6 +157,7 @@ public class DummyMote implements Mote {
|
||||||
+ myRandom.nextDouble() - 0.5, myPosition.getZCoordinate()
|
+ myRandom.nextDouble() - 0.5, myPosition.getZCoordinate()
|
||||||
+ myRandom.nextDouble() - 0.5);
|
+ myRandom.nextDouble() - 0.5);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Element> getConfigXML() {
|
public Collection<Element> getConfigXML() {
|
||||||
|
@ -215,8 +216,9 @@ public class DummyMote implements Mote {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (getInterfaces().getMoteID() != null) {
|
if (getInterfaces().getMoteID() != null) {
|
||||||
return "Dummy Mote, ID=" + getInterfaces().getMoteID().getMoteID();
|
return "Dummy Mote, ID=" + getInterfaces().getMoteID().getMoteID();
|
||||||
} else
|
} else {
|
||||||
return "Dummy Mote, ID=null";
|
return "Dummy Mote, ID=null";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue