By default TOSSIM simulates low-level TinyOS components that potentially generate a lot of events. The only way to know the exact number of times you need to call t.runNextEvent()
is to know what exactly is going on in those layers. But this is a) probably impossible and b) unnecessary.
I have been using following approach:
- Estimate how long (in seconds/minutes/hours) I want my simulation to run. This can depend on the project requirements or nature of code you are simulating.
- Find out how many ticks are there per simulated second using
t.ticksPerSecond()
. Note that I said simulated second (Usefull paper on TOSSIM, see top of page 3). - Call
t.runNextEvent()
inside a loop that iteratest.ticksPerSecond() * simulation_length
times. Although there is no direct link between the amount of time your code would run on real motes and the time it will take to simulate it using TOSSIM, I have found that using real time intervals is quite good for sizing the number of iterations required for a particular simulation.
Example:
simLength = 60*5 #run code for simulated 5 minutes
while True:
t.runNextEvent()
if t.time() > simLength * t.ticksPerSecond():
break