From b0d37c34e34e0e9b3ba1ee8daccc2f84dd4a449b Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 1 Apr 2008 08:12:16 +0000 Subject: [PATCH] experimental: ticking msp motes separately allows for different tick durations per different nodes --- .../cooja/java/se/sics/cooja/Simulation.java | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index 909252864..1967d73f9 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.java @@ -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: Simulation.java,v 1.21 2008/03/17 08:35:10 fros4943 Exp $ + * $Id: Simulation.java,v 1.22 2008/04/01 08:12:16 fros4943 Exp $ */ package se.sics.cooja; @@ -130,9 +130,17 @@ public class Simulation extends Observable implements Runnable { this.setChanged(); this.notifyObservers(this); + /* Experimental: Tick MSP motes separately */ + ArrayList mspMotes = new ArrayList(); + for (Mote mote: motes) { + if (mote.getType().getClass().toString().contains(".mspmote.")) { + mspMotes.add(mote); + } + } + // Distribute motes in tick lists according to random seed // TODO Timeconsuming approach (but only performed once) - int motesToDistribute = motes.size(); + int motesToDistribute = motes.size() - mspMotes.size(); Mote[][] allLists = new Mote[nrTickLists][]; for (int i=0; i < nrTickLists; i++) { allLists[i] = new Mote[(int) Math.ceil((double)motesToDistribute/(double)(nrTickLists - i))]; @@ -141,7 +149,12 @@ public class Simulation extends Observable implements Runnable { // Distribute motes according to seed tickListRandom.setSeed(randomSeed); - Vector motesClone = (Vector) motes.clone(); + Vector motesClone = new Vector(); + for (Mote mote: motes) { + if (!mote.getType().getClass().toString().contains(".mspmote.")) { + motesClone.add(mote); + } + } for (int i=0; i < allLists.length; i++) { for (int j=0; j < allLists[i].length; j++) { int moteNr = tickListRandom.nextInt(motesClone.size()); @@ -152,6 +165,24 @@ public class Simulation extends Observable implements Runnable { while (isRunning) { try { + /* Tick MSP motes */ + try { + boolean wantMoreTicks = true; + while (wantMoreTicks) { + /* Tick all MSP motes until none need more ticks */ + wantMoreTicks = false; + for (Mote moteToTick : mspMotes) { + if (moteToTick.tick(currentSimulationTime)) { + wantMoreTicks = true; + } + } + } + } catch (RuntimeException e) { + isRunning = false; + thread = null; + break; + } + // Tick current mote subset for (Mote moteToTick : allLists[currentTickListIndex]) { moteToTick.tick(currentSimulationTime);