def send_payload(): """Schedules CCA after 60 seconds to send packet.""" current_time = global_vars.EVENT_LIST[1][0] #origin mote origin_mote_row = int( global_vars.EVENT_LIST[2][0].split(';')[1] ) origin_mote_col = int( global_vars.EVENT_LIST[2][0].split(';')[2] ) #parent mote if global_vars.MOTES_ARRAY[origin_mote_row][origin_mote_col].gateway == False: #mote is NOT the gateway of cloud A parent_mote_row = int( global_vars.MOTES_ARRAY[origin_mote_row][origin_mote_col].parent.split(';')[1] ) parent_mote_col = int( global_vars.MOTES_ARRAY[origin_mote_row][origin_mote_col].parent.split(';')[2] ) global_vars.MOTES_ARRAY[parent_mote_row][parent_mote_col].packets_received += 1 #schedule packet forwarding global_vars.EVENT_LIST[0].append(9) global_vars.EVENT_LIST[1].append(current_time + functions.calculate_transmission_delay(4)) global_vars.EVENT_LIST[2].append(global_vars.MOTES_ARRAY[parent_mote_row][parent_mote_col].moteID) elif global_vars.MOTES_ARRAY[origin_mote_row][origin_mote_col].gateway == True: #mote is the gateway of cloud A global_vars.NODES_ARRAY[0].packets_received += 1 #send packet to node directly global_vars.MOTES_ARRAY[origin_mote_row][origin_mote_col].packets_sent += 1 global_vars.EVENT_LIST[0].append(0) global_vars.EVENT_LIST[1].append(current_time + 60) global_vars.EVENT_LIST[2].append(global_vars.EVENT_LIST[2][0]) return
def cca(): """The mote checks if the channel is clear to send data. This operation lasts 0.000128 seconds. If the channel is clear after 0.000128 seconds, mote will schedule to send it's packets and update the channel release time. Otherwise random delay will be performed and the CCA again.""" current_time = global_vars.EVENT_LIST[1][0] if (current_time + global_vars.CCA_TIME) > global_vars.CHANNEL_ARRAY[0].release_time: #channel is released by that time #mote takes the channel global_vars.EVENT_LIST[1].append(current_time + global_vars.CCA_TIME) global_vars.EVENT_LIST[2].append(global_vars.EVENT_LIST[2][0]) mote_row = int( global_vars.EVENT_LIST[2][0].split(';')[1] ) mote_col = int( global_vars.EVENT_LIST[2][0].split(';')[2] ) if global_vars.MOTES_ARRAY[ mote_row ][ mote_col ].payload == True: #mote has payload ready #Updates the channel release time according to the time it takes to transmit 4 Bytes global_vars.CHANNEL_ARRAY[0].release_time = current_time + global_vars.CCA_TIME + functions.calculate_transmission_delay(4) #schedule the send package event global_vars.EVENT_LIST[0].append(3) elif global_vars.MOTES_ARRAY[ mote_row ][ mote_col ].echo == True: #mote has echo ready #Updates the channel release time according to the time it takes to transmit 1 Byte global_vars.CHANNEL_ARRAY[0].release_time = current_time + global_vars.CCA_TIME + functions.calculate_transmission_delay(1) global_vars.EVENT_LIST[0].append(2) #schedule echo event else: #channel will not be free #schedule cca again after random time global_vars.EVENT_LIST[0].append(0) global_vars.EVENT_LIST[1].append(current_time + global_vars.CCA_TIME) #reschedule after you perform CCA global_vars.EVENT_LIST[2].append(global_vars.EVENT_LIST[2][0]) return
def forward_payload(): current_time = global_vars.EVENT_LIST[1][0] try: if (current_time + global_vars.CCA_TIME) > global_vars.CHANNEL_ARRAY[0].release_time: #channel is released by that time #mote takes the channel #Updates the channel release time according to the time it takes to transmit 4 Bytes global_vars.CHANNEL_ARRAY[0].release_time = current_time + global_vars.CCA_TIME + functions.calculate_transmission_delay(4) #add packet sent by child origin_mote_row = int( global_vars.EVENT_LIST[2][0].split(';')[1] ) origin_mote_col = int( global_vars.EVENT_LIST[2][0].split(';')[2] ) global_vars.MOTES_ARRAY[ origin_mote_row ][ origin_mote_col ].packets_sent += 1 #add packet received to parent parent_mote_row = int( global_vars.MOTES_ARRAY[origin_mote_row][origin_mote_col].parent.split(';')[1] ) parent_mote_col = int( global_vars.MOTES_ARRAY[origin_mote_row][origin_mote_col].parent.split(';')[2] ) global_vars.MOTES_ARRAY[ parent_mote_row ][ parent_mote_col ].packets_received += 1 else: #channel will not be free #schedule cca again after random time global_vars.EVENT_LIST[0].append(9) global_vars.EVENT_LIST[1].append(current_time + global_vars.CCA_TIME) #reschedule after you perform CCA global_vars.EVENT_LIST[2].append(global_vars.EVENT_LIST[2][0]) except: #in case the parent is the node #maybe I have not seen this happening #temporary fix pass return