Пример #1
0
 def start(self):
     if not self.running:
         if not self.parent.is_open():
             self.parent.open()
         self.csafe = CSafe(self.parent) #port
         if feu_poll_thread:
             #global feu_poll_thread
             feu_poll_thread.add_feu(self)   #register with the status loop
     CompositeNode.start(self)
     self.running = 1
Пример #2
0
class FEU(CompositeNode, AutoDiscoveredNode, EventProducerMixin):
    def __init__(self):
        self.running = 0
        self._children_have_been_discovered = 0
        CompositeNode.__init__(self)
        AutoDiscoveredNode.__init__(self)
        EventProducerMixin.__init__(self)
        self.csafe = None
        self._mutex = threading.Lock() #preven multiple io operations
        self.ttl = 10
        self.feu_state = None
        self.cov = ChangeOfValueEvent(self, None, self.feu_state)
        self.description = None
    def default_name(self):
        return 'FEU' #only one per port so no need to individualize it like for a aerocomm client
    def configure(self, dict):
        CompositeNode.configure(self, dict)
        set_attribute(self, 'ttl', self.ttl, dict, float)
    def configuration(self):
        config = CompositeNode.configuration(self)
        get_attribute(self, 'ttl', config, str)
        return config
    def start(self):
        if not self.running:
            if not self.parent.is_open():
                self.parent.open()
            self.csafe = CSafe(self.parent) #port
            if feu_poll_thread:
                #global feu_poll_thread
                feu_poll_thread.add_feu(self)   #register with the status loop
        CompositeNode.start(self)
        self.running = 1
    def _discover_children(self):
        if self.debug: print 'FEU io group discover children'
        if self.running and not self._children_have_been_discovered: #empty
            self._children_have_been_discovered = 1
            answer = {}
            keys = self._get_attribute_node_names()
            for k in keys:
                child = _PropAttr()  #note this could be just the class, not the instance
                if self.debug: print 'IO point: %s discovered child: %s' % (self.name, k)
                answer[k] = child                                      
            return answer
        return self._nascent_children
    def update_state(self, new_state):
        if new_state is None: return
        if self.feu_state != new_state:
            try:
                new_state = status_text[new_state] #make sure its an enumerated value
            except:
                pass
            if self.debug: print 'update feu state, old state: %s new state: %s' % (str(self.feu_state), str(new_state))
            self.cov.old_value = self.feu_state
            self.feu_state = new_state
            self.cov.value = new_state
            self.event_generate(self.cov)
    def get(self, skipCache=0):
        return self.feu_state
    def _get_attribute_node_names(self):
        return self.csafe.properties.keys() + ['description']
    def _get_attr_value(self, name, skipCache=0):
        #if self.parent.transceiver_state in ('transceiver_responding','exception_in_xmit'):
        state, value = self.csafe.get(name)
        self.update_state(state)
        return value        
    def _allow_set(self, name):
        if name == 'description':
            return 1
        return 0
    def get_status(self): #must be called either with the lock locked
        return self._get_attr_value('Status')