[Tinyos-help] AMControl.start() will do nothing every other time (tossim)

Ricardo Carrano carrano at midiacom.uff.br
Mon Nov 29 09:36:27 PST 2010


Hi all,

The idea of this simple (I removed everything uninteresting)
application bellow is to turn the radio on and off periodically. I
pasted the module (BoboC.nc) and the wiring (BoboApp.nc), and also the
Tossim script and the corresponding output.

The problem is that the radio is not always started, i.e., sometimes
the AMControl.startDone event is not signaled. Actually it is started
only every other time the AMControl.start() command is called.

I tested, and AMcontrol.start() does return SUCCESS every time is
called, but the AMControl.startDone event is signaled only every other
time, as I said. As for AMControl.stop() everything seems ok.

I fear I am doing something fundamentally wrong, but don't know where
to go from here.  Any help would be highly appreciated.

TinyOS version is 2.1.1

=== Bobo.C ===

module BoboC @safe() {
  uses {
    interface Boot;
    interface Timer<TMilli> as TimerSlot;
    interface SplitControl as AMControl;
  }
}

implementation {

   bool on = FALSE;

   event void Boot.booted() {
     call TimerSlot.startPeriodic(10000);
   }

   event void TimerSlot.fired() {
     if (on) { call AMControl.stop(); on=FALSE; }
     else { call AMControl.start(); on=TRUE; }
   }

   event void AMControl.startDone(error_t err) {
     dbg("BOBO","Radio was turned on.\n");
   }

   event void AMControl.stopDone(error_t err) {
     dbg("BOBO","Radio was turned off.\n");
   }
}


=== BoboApp.C ===

implementation {

  components MainC;
  components BoboC as App;
  components new TimerMilliC() as TimerSlot;
  components ActiveMessageC;

  App.Boot -> MainC.Boot;
  App.AMControl -> ActiveMessageC;
  App.TimerSlot -> TimerSlot;

}



=== Script ===

#! /usr/bin/python
from TOSSIM import *
import sys
import random

N_MOTES = 4
TOPO_FILE = "linkgain.out"
NOISE_FILE = "bobo-noisetrace.txt"

t = Tossim([])
r = t.radio()
f = open(TOPO_FILE, "r")

t.addChannel("BOBO", sys.stdout)
t.addChannel("Boot", sys.stdout)
log = open("energy-log.txt", "w")
lines = f.readlines()

for line in lines:
    s = line.split()
    if (len(s) > 0):
        if s[0] == "gain":
            #print " ", s[0], " ", s[1], " ", s[2], "  ", s[3];
            r.add(int(s[1]), int(s[2]), float(s[3]) + 4)
        elif s[0] == "noise":
            r.setNoise(int(s[1]), float(s[2]), float(s[3]))

noise = open(NOISE_FILE, "r")
lines = noise.readlines()
for line in lines:
  str1 = line.strip()
  if (str1 != ""):
    val = int(str1)
    for i in range(0, N_MOTES):
      t.getNode(i).addNoiseTraceReading(val)

for i in range(0, N_MOTES):
  t.getNode(i).createNoiseModel()

for i in range(0, N_MOTES):
  t.getNode(i).bootAtTime(random.randrange(0,60000000000,1));

for i in range(0, 10000):
  t.runNextEvent()

=== Simulation output (only for node 1) ===

DEBUG (1): Setting start time to 2398036804
DEBUG (1): Turning on mote 1 at time 0:0:0.239803680.
DEBUG (1): Setting start time to 2398036804
DEBUG (1): Mote 1 signaling boot at time 0:0:0.239803680.
DEBUG (1): Radio was turned on.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned on.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned on.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned on.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned on.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned on.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned off.
DEBUG (1): Radio was turned on.
DEBUG (1): Radio was turned off.

Regards,
Ricardo Carrano


More information about the Tinyos-help mailing list