-
Notifications
You must be signed in to change notification settings - Fork 0
/
mySimulation.py
83 lines (65 loc) · 1.87 KB
/
mySimulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python
from TOSSIM import *
import sys ,os
import random
gridDimension = 4 ** 2
t=Tossim([])
#f=sys.stdout #open('./logfile.txt','w')
f= open('./logfile.txt','w');
#SIM_END_TIME= 10000 * t.ticksPerSecond()
SIM_END_TIME= 905 * t.ticksPerSecond()
#Everything in the terminal will be written in the log file
sys.stdout = f;
print "TicksPerSecond : ", t.ticksPerSecond(),"\n"
t.addChannel("Boot",f)
t.addChannel("RoutingMsg",f)
t.addChannel("NotifyParentMsg",f)
t.addChannel("Radio",f)
#t.addChannel("Serial",f)
t.addChannel("SRTreeC",f)
#t.addChannel("PacketQueueC",f)
for i in range(0,gridDimension):
m=t.getNode(i)
m.bootAtTime(10*t.ticksPerSecond() + i)
topo = open("topology.txt", "r")
if topo is None:
print "Topology file not opened!!! \n"
r=t.radio()
lines = topo.readlines()
for line in lines:
s = line.split()
if (len(s) > 0):
#print " ", s[0], " ", s[1], " ", s[2];
r.add(int(s[0]), int(s[1]), float(s[2]))
mTosdir = os.getenv("TINYOS_ROOT_DIR")
noiseF=open(mTosdir+"/tos/lib/tossim/noise/meyer-heavy.txt","r")
lines= noiseF.readlines()
for line in lines:
str1=line.strip()
if str1:
val=int(str1)
for i in range(0,gridDimension):
t.getNode(i).addNoiseTraceReading(val)
noiseF.close()
for i in range(0,gridDimension):
t.getNode(i).createNoiseModel()
ok=False
#if(t.getNode(0).isOn()==True):
# ok=True
h=True
while(h):
try:
h=t.runNextEvent()
#print h
except:
print sys.exc_info()
# e.print_stack_trace()
if (t.time()>= SIM_END_TIME):
h=False
if(h<=0):
ok=False
#print "Node 0 connected with node 1" , r.connected(0,1) , r.connected(1,0)
#print "Node 0 connected with node 2" , r.connected(0,2) , r.connected(2,0)
#print "Node 1 connected with node 7" , r.connected(1,7) , r.connected(7,1)
#print "Node 2 connected with node 3" , r.connected(2,3) , r.connected(3,2)
#print "Node 4 connected with node 8" , r.connected(4,8) , r.connected(8,4)