Package mosp :: Package external_persons :: Module external_person
[hide private]
[frames] | no frames]

Source Code for Module mosp.external_persons.external_person

  1  #!/bin/env python 
  2   
  3  """ Wrapper for a real person using an Android smartphone.""" 
  4   
  5  import sys 
  6  sys.path.append("../..") 
  7  import time 
  8   
  9  from SimPy.Simulation import infinity 
 10   
 11  from mosp.core import Person 
 12  from mosp.geo import utm 
 13   
 14  __author__ = "P. Tute" 
 15  __maintainer__ = "B. Henne" 
 16  __contact__ = "henne@dcsec.uni-hannover.de" 
 17  __copyright__ = "(c) 2010-2011, DCSec, Leibniz Universitaet Hannover, Germany" 
 18  __license__ = "GPLv3" 
 19   
 20   
21 -class ExternalPerson(Person):
22 - def __init__(self, id, sim, random, speed=1.4, **kwargs):
23 super(ExternalPerson, self).__init__(id, sim, random, speed=1.4, **kwargs) 24 #Person.__init__(self, id, sim, random, speed=1.4, **kwargs) 25 self.new_next_node = None 26 self.new_last_node = None 27 self.last_received_coords = [] 28 print 'Created external person with ID ', id, '.'
29
30 - def current_coords_free_move(self):
31 """Return the last received location. 32 33 @todo: interpolation between received coordinates 34 35 """ 36 return self.last_received_coords if self.last_received_coords else None
37
39 return infinity
40
41 - def next_target(self):
42 """Set last and next node based on received data.""" 43 self.last_node = self.new_last_node 44 self.next_node = self.new_next_node
45
46 - def reactivate(self, at = 'undefined', delay = 'undefined', prior = False):
47 """Reactivates passivated person and optionally restarts stopped actions.""" 48 Person.reactivate(self)
49
50 - def pause_movement(self, duration, location_offset_xy=0, deactivateActions=False):
51 """Stops movement of person. Currently only works with passivating at next_node. 52 Currently cannot be used to stop on a way like after infect! 53 @param duration: pause duration 54 @param location_offset_xy: optional random offset to be added to current location when stopping. 55 @param deactivateActions: deactive actions while pausing? 56 57 """ 58 Person.pause_movement(self, duration, location_offset_xy=0, deactivateActions=False)
59
60 - def act_at_node(self, node):
61 """Actions of the person when arriving at a node. To be overwritten with an implementation. 62 63 This method is executes when the Person arrives at a node. 64 @param node: is the next_node the Person arrives at""" 65 pass
66
67 - def think(self):
68 """Think about what to do next. 69 70 This method can include all logic of the person (what to do, where to go etc.). 71 Decisions could be made by using flags for example. 72 This is where a new self.dest_node and self.start_node should be set if necessary. 73 self.next_node should not be set here. This should be done in self.next_target. 74 @return: time until next wakeup (int, ticks), returning a negative number or 0 will cause self.go() to find a time 75 @note: This method provides only the most basic functionality. Overwrite (and if necessary call) it to implement own behaviour. 76 77 """ 78 #print '\tcorrect think' 79 return 1000
80
81 - def handle_interrupts(self):
82 """Find out, what caused an interrupt and act accordingly. 83 84 This method is called whenever a person is interrupted. 85 This is the place to implement own reactions to interrupts. Calling methods that were send via a send() call is done BEFORE this method is called. Handling pause, stop, removal and change of movement speed is done automatically AFTER this method is called. Removing the corresponding flag (setting it to False) in this method allows for handling these things on your own. 86 @note: This method does nothing per default. Implement it to react to interrupts. If you do not want or need to react to interrupts, ignore this method. 87 """ 88 Person.handle_interrupts(self)
89
90 - def receive(self, message, sender):
91 """Receive a message and handle it. 92 93 Removal from the message queue and earliest arrival time are handled automatically. 94 95 @param message: a message from the persons message queue. 96 @param sender: the sender of the message. 97 @return: True if the message should be removed from the queue, False else. It will then be delivered again in the next cycle. 98 99 """ 100 return Person.receive(self, message, sender)
101