This repository was archived by the owner on Apr 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsn_main.py
126 lines (99 loc) · 3.98 KB
/
wsn_main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""Event driven simulation for a wireless sensor network.
Properties:
- The area is 10km^2
- The network consists of 1000 motes-sensors, cloud A
- The motes are uniformly spread
- One node (Cloud B) enters the area and croses it at a given speed
- Once the node enters the area, it starts receiving data from the motes
- The network reorganizes as the node croses the area
- Time is measured in seconds
For more details see the readme file.
"""
import global_vars
import classes
import functions
import events
__author__ = "Giannis Petrousov"
__copyright__ = "Copyright 2014"
__credits__ = ["Giannis Petrousov"]
__license__ = "The MIT License"
__maintainer__ = "Giannis Petrousov"
__email__ = "petrousov@gmail"
__status__ = "beta"
def wsn_main():
"""Main function that loops over the event list and calls the events themselves"""
functions.initialize_motes()
functions.initialize_nodes()
functions.initialize_channels()
functions.initialize_event_list()
###########################ECHO-MEETING STEP###################################
echoed_nodes = 0
while echoed_nodes < 1000:
#Initially take some time for the motes to meet eachother and populate lookup tables
#Reschedule delay and cca until echoed
current_time = global_vars.EVENT_LIST[1][0]
if global_vars.EVENT_LIST[0][0] == 0:
#0 = Take random time
events.assign_random_wait_time()
#pass
if global_vars.EVENT_LIST[0][0] == 1:
#1 = Perform CCA-Clear Channel Assesment
events.cca()
if global_vars.EVENT_LIST[0][0] == 2:
#2 = Send echo
events.echo()
echoed_nodes += 1
#passed event must be deleted
for x in global_vars.EVENT_LIST:
del x[0]
#sort the the event list
global_vars.EVENT_LIST = functions.sortrows(global_vars.EVENT_LIST, 1)
#global_vars.EVENT_LIST[0] = list(global_vars.EVENT_LIST[0])
#global_vars.EVENT_LIST[1] = list(global_vars.EVENT_LIST[1])
#global_vars.EVENT_LIST[2] = list(global_vars.EVENT_LIST[2])
#pass
#When the loop above finishes, all motes know their neigbors == lookup tables updated
###############################################################################
#node enters here
global_vars.EVENT_LIST[0].append(5)
global_vars.EVENT_LIST[1].append(current_time)
global_vars.EVENT_LIST[2].append('node0')
global_vars.EVENT_LIST = functions.sortrows(global_vars.EVENT_LIST, 1)
####################### DEBUG TILL HERE ; ALL GOOD ##############
###########################################
while True:
current_time = global_vars.EVENT_LIST[1][0] #for debugging purposes
print current_time
if global_vars.EVENT_LIST[0][0] == 0:
#delay by random time
events.assign_random_wait_time()
if global_vars.EVENT_LIST[0][0] == 1:
events.cca()
if global_vars.EVENT_LIST[0][0] == 2:
events.echo()
if global_vars.EVENT_LIST[0][0] == 3:
events.send_payload()
if global_vars.EVENT_LIST[0][0] == 4:
events.update_lookup_tables()
if global_vars.EVENT_LIST[0][0] == 5:
events.random_node_entry()
if global_vars.EVENT_LIST[0][0] == 6:
events.presence_entry()
if global_vars.EVENT_LIST[0][0] == 7:
events.node_step()
if global_vars.EVENT_LIST[0][0] == 8:
events.propagate_new_gateway()
if global_vars.EVENT_LIST[0][0] == 9:
events.forward_payload()
if global_vars.EVENT_LIST[0][0] == 10:
#terminate
break
#passed event must be deleted
for x in global_vars.EVENT_LIST:
del x[0]
#sort the the event list
global_vars.EVENT_LIST = functions.sortrows(global_vars.EVENT_LIST, 1)
#pass
###############################################
functions.write_simulation_results_to_file()
return