example mote implementation uses main random generator
This commit is contained in:
parent
00c88ca2d3
commit
fbb09061c8
|
@ -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.6 2008/12/04 14:03:42 joxe Exp $
|
* $Id: DummyMote.java,v 1.7 2009/02/18 10:41:50 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.motes;
|
package se.sics.cooja.motes;
|
||||||
|
@ -68,7 +68,7 @@ public class DummyMote implements Mote {
|
||||||
private MoteInterfaceHandler myInterfaceHandler = null;
|
private MoteInterfaceHandler myInterfaceHandler = null;
|
||||||
private Simulation mySim = null;
|
private Simulation mySim = null;
|
||||||
|
|
||||||
private Random myRandom = new Random();
|
private Random random = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new uninitialized dummy mote.
|
* Creates a new uninitialized dummy mote.
|
||||||
|
@ -88,6 +88,7 @@ public class DummyMote implements Mote {
|
||||||
public DummyMote(MoteType moteType, Simulation sim) {
|
public DummyMote(MoteType moteType, Simulation sim) {
|
||||||
mySim = sim;
|
mySim = sim;
|
||||||
myType = moteType;
|
myType = moteType;
|
||||||
|
random = mySim.getRandomGenerator();
|
||||||
|
|
||||||
// Create memory
|
// Create memory
|
||||||
myMemory = new SectionMoteMemory(new Properties());
|
myMemory = new SectionMoteMemory(new Properties());
|
||||||
|
@ -95,8 +96,11 @@ public class DummyMote implements Mote {
|
||||||
// Create interface handler
|
// Create interface handler
|
||||||
myInterfaceHandler = new MoteInterfaceHandler();
|
myInterfaceHandler = new MoteInterfaceHandler();
|
||||||
Position myPosition = new Position(this);
|
Position myPosition = new Position(this);
|
||||||
myPosition.setCoordinates(myRandom.nextDouble() * 100, myRandom
|
myPosition.setCoordinates(
|
||||||
.nextDouble() * 100, myRandom.nextDouble() * 100);
|
random.nextDouble() * 100,
|
||||||
|
random.nextDouble() * 100,
|
||||||
|
random.nextDouble() * 100
|
||||||
|
);
|
||||||
myInterfaceHandler.addInterface(myPosition);
|
myInterfaceHandler.addInterface(myPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,13 +153,13 @@ public class DummyMote implements Mote {
|
||||||
public boolean tick(long simTime) {
|
public boolean tick(long simTime) {
|
||||||
|
|
||||||
// Perform some dummy task
|
// Perform some dummy task
|
||||||
if (myRandom.nextDouble() > 0.9) {
|
if (random.nextDouble() > 0.9) {
|
||||||
// Move mote randomly
|
// Move mote randomly
|
||||||
Position myPosition = myInterfaceHandler.getPosition();
|
Position myPosition = myInterfaceHandler.getPosition();
|
||||||
myPosition.setCoordinates(myPosition.getXCoordinate()
|
myPosition.setCoordinates(myPosition.getXCoordinate()
|
||||||
+ myRandom.nextDouble() - 0.5, myPosition.getYCoordinate()
|
+ random.nextDouble() - 0.5, myPosition.getYCoordinate()
|
||||||
+ myRandom.nextDouble() - 0.5, myPosition.getZCoordinate()
|
+ random.nextDouble() - 0.5, myPosition.getZCoordinate()
|
||||||
+ myRandom.nextDouble() - 0.5);
|
+ random.nextDouble() - 0.5);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -187,6 +191,7 @@ public class DummyMote implements Mote {
|
||||||
Collection<Element> configXML, boolean visAvailable) {
|
Collection<Element> configXML, boolean visAvailable) {
|
||||||
mySim = simulation;
|
mySim = simulation;
|
||||||
myMemory = new SectionMoteMemory(new Properties());
|
myMemory = new SectionMoteMemory(new Properties());
|
||||||
|
random = mySim.getRandomGenerator();
|
||||||
myInterfaceHandler = new MoteInterfaceHandler();
|
myInterfaceHandler = new MoteInterfaceHandler();
|
||||||
myInterfaceHandler.addInterface(new Position(this));
|
myInterfaceHandler.addInterface(new Position(this));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue