Exemplo n.º 1
0
 def __enter__(self):
     self._datariver = DataRiver.get_instance()
     self._dispatcher = Dispatcher()
     self._new_thing_discovered_listener = NewThingDiscoveredListener(self._datariver)
     self._thing = self.create_thing()
     
     return self
    def run(self, running_time):
        # Use custom dispatcher for processing events
        dispatcher = Dispatcher()

        # Add listener for new GPS sensor Things using our custom dispatcher
        gps_data_received_listener = GpsSensorDataListener(self)
        self._thing.add_listener(gps_data_received_listener, dispatcher)

        # Process events with our dispatcher
        start = time.time()
        elapsed_seconds = 0
        while True:
            try:
                # block the call for 1000ms
                dispatcher.process_events(1000)
            except TimeoutError as e:
                # Ignore.
                pass

            elapsed_seconds = time.time() - start

            if elapsed_seconds >= running_time:
                break

        # Remove listener
        self._thing.remove_listener(gps_data_received_listener, dispatcher)
Exemplo n.º 3
0
    def run(self) -> None:
        """
        The main loop of the Thing, when it exits the lifecycle of the Thing is done.
        A listener is attached to the VideoFrame input and as the frames are received they a passed through
        the TensorFlow Object Detection API to transform the frame into a set of Regions of Interest (or
        Detection Boxes) that have a classification of what is in them.
        The result is packaged into a DetectionBox and written to the Data River.
        It exists when the `terminate` flage is set on the Thing by calling __exit__
        """
        dispatcher = Dispatcher()
        self.thing.add_listener(self.__listener, 'VideoFrameData', dispatcher)

        while not self.terminate:
            try:
                dispatcher.process_events(1000)
            except:
                continue
    def run(self):
        self.pipeline = GstPipeline(self.command)
        # override on_pipeline_init to se specific properties before launching pipeline
        self.pipeline._on_pipeline_init = self.__on_pipeline_init

        try:
            self.pipeline.startup()
            self.app_src = self.pipeline.get_by_cls(GstApp.AppSrc)[0]
            self.app_sink = self.pipeline.get_by_cls(GstApp.AppSink)[0]
        except Exception as e:
            log.error('Problem starting pipeline')
            self.terminate()

        dispatcher = Dispatcher()
        self.thing.add_listener(self.__listener, 'VideoFrameData', dispatcher)

        while not self.terminate:
            try:
                dispatcher.process_events(1000)
            except:
                continue
Exemplo n.º 5
0
class ThingBrowser(object):
    
    # Initializing
    def __init__(self, thing_properties_uri):
        self._thing_properties_uri = thing_properties_uri
        self._datariver = None
        self._thing = None
        self._dispatcher = None
        self._new_thing_discovered_listener = None
    
    # Enter the runtime context related to the object
    def __enter__(self):
        self._datariver = DataRiver.get_instance()
        self._dispatcher = Dispatcher()
        self._new_thing_discovered_listener = NewThingDiscoveredListener(self._datariver)
        self._thing = self.create_thing()
        
        return self
    
    # Exit the runtime context related to the object
    def __exit__(self, exc_type, exc_value, exc_traceback):
        if self._datariver is not None:
            try:
                # Remove the discovered Thing listener that was added during class initialization
                self._datariver.remove_listener(self._new_thing_discovered_listener, self._dispatcher)
            except ThingAPIException as e:
                print('Unexpected error while removing discovered Thing listener: '.format(e))
            
            self._datariver.close()
        print(COLOR_GREEN + 'ThingBrowser stopped' + NO_COLOR)
    
    
    def create_thing(self):
        # Add listener for discovery of Things
        self._datariver.add_listener(self._new_thing_discovered_listener, self._dispatcher)
        
        # Create and Populate the ThingClass registry with JSON resource files.
        tcr = JSonThingClassRegistry()
        tcr.register_thing_classes_from_uri('file://definitions/ThingClass/com.adlinktech.example/ThingBrowserThingClass.json')
        self._datariver.add_thing_class_registry(tcr)
  
        # Create a Thing based on properties specified in a JSON resource file.
        tp = JSonThingProperties()
        tp.read_properties_from_uri(self._thing_properties_uri)
        
        return self._datariver.create_thing(tp)
    
    
    def run(self, running_time):
        # Process events with our dispatcher
        start = time.time()
        elapsed_seconds = 0
        
        while True:
            try:
                self._dispatcher.process_events(1000)
            except TimeoutError:
                # Ignore
                pass
            
            elapsed_seconds = time.time() - start
            
            if elapsed_seconds >= running_time:
                break
        
        return 0