Пример #1
0
 def __init__(self, callback_function=None):
     """ """
     self._callback_function = callback_function
     self._logger = logging.getLogger('CloudedBatsWURB')
     self._settings = wurb_core.WurbSettings()
     #
     self._sound_manager = None
 def __init__(self):
     """ """
     self._logger = logging.getLogger('CloudedBatsWURB')
     self._settings = wurb_core.WurbSettings()
     #
     self._debug = self._settings.boolean('sound_debug')
     self.sampling_freq = self._settings.float(
         'rec_sampling_freq_khz') * 1000
Пример #3
0
 def __init__(self, callback_function=None):
     """ """
     self._callback_function = callback_function
     self._logger = logging.getLogger('CloudedBatsWURB')
     self._settings = wurb_core.WurbSettings()
     #
     super(SoundProcess, self).__init__()
     #
     self._debug = self._settings.boolean('rec_proc_debug')
     self._rec_buffers_s = self._settings.float('rec_buffers_s')
Пример #4
0
 def __init__(self):
     """ """
     self._logger = logging.getLogger('CloudedBatsWURB')
     self._settings = wurb_core.WurbSettings()
     # Use clear to initiate class members.
     self._clear()
     # Default port for GPSD.
     self._gpsd_port = self._settings.integer('gps_reader_port')
     # Default timezone.
     self._timezone = pytz.timezone(self._settings.text('timezone'))
     # Use GPS time for Raspberry Pi.
     self._set_rpi_time_from_gps = self._settings.boolean(
         'set_time_from_gps')
     #
     self._debug = False
Пример #5
0
 def __init__(self, callback_function=None):
     """ """
     self._callback_function = callback_function
     self._logger = logging.getLogger('CloudedBatsWURB')
     self._settings = wurb_core.WurbSettings()
     #
     super(SoundSource, self).__init__()
     #
     self._debug = self._settings.boolean('rec_source_debug')
     self._rec_source_adj_time_on_drift = self._settings.boolean(
         'rec_source_adj_time_on_drift')
     #
     self._pyaudio = pyaudio.PyAudio()
     self._stream = None
     #
     self.read_settings()
Пример #6
0
 def __init__(self, callback_function=None):
     """ """
     self._callback_function = callback_function
     self._logger = logging.getLogger('CloudedBatsWURB')
     self._settings = wurb_core.WurbSettings()
     #
     self._local_time = datetime.datetime.now()
     self._latitude = None
     self._longitude = None
     self._use_gps = False
     self._wait_for_gps_at_startup = False
     #
     self._scheduler_event_list = []
     self._read_settings()
     #
     self._rec_on = False
     self._thread_active = False
     self.start()
Пример #7
0
 def __init__(self, callback_function=None):
     """ """
     self._callback_function = callback_function
     self._logger = logging.getLogger('CloudedBatsWURB')
     self._settings = wurb_core.WurbSettings()
     #
     super(SoundTarget, self).__init__()
     # From settings.
     self._dir_path = self._settings.text('rec_directory_path')
     self._filename_prefix = self._settings.text('rec_filename_prefix')
     rec_max_length_s = self._settings.integer('rec_max_length_s')
     self._rec_max_length = rec_max_length_s * 2
     # Default for latitude/longitude in the decimal degree format.
     self._latitude = float(self._settings.float('default_latitude'))
     self._longitude = float(self._settings.float('default_longitude'))
     # Different microphone types.
     if self._settings.text('rec_microphone_type') == 'M500':
         # For M500 only.
         if self._settings.text('rec_format') == 'TE':
             self._filename_rec_type = 'TE500'
             self._out_sampling_rate_hz = 50000
         else:
             self._filename_rec_type = 'FS500'
             self._out_sampling_rate_hz = 500000
     else:
         # For standard USB, inclusive M500-384.
         if self._settings.text('rec_format') == 'TE':
             self._filename_rec_type = 'TE' + self._settings.text(
                 'rec_sampling_freq_khz')
             self._out_sampling_rate_hz = self._settings.integer(
                 'rec_sampling_freq_khz') * 100
         else:
             self._filename_rec_type = 'FS' + self._settings.text(
                 'rec_sampling_freq_khz')
             self._out_sampling_rate_hz = self._settings.integer(
                 'rec_sampling_freq_khz') * 1000
     #
     self._total_start_time = None
     self._internal_buffer_list = []
     self._write_thread_active = False
     self._active = False
Пример #8
0
                ' sec.')


# === TEST ===
if __name__ == "__main__":
    """ """
    import sys
    import pathlib
    path = ".."
    sys.path.append(path)

    # Logging to standard output.
    logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

    #
    settings = wurb_core.WurbSettings()
    (desc, default, dev) = wurb_core.wurb_recorder.default_settings()
    settings.set_default_values(desc, default, dev)
    (desc, default, dev) = wurb_core.wurb_gps_reader.default_settings()
    settings.set_default_values(desc, default, dev)
    #
    internal_setting_path = pathlib.Path('../wurb_settings/user_settings.txt')
    settings.load_settings(internal_setting_path)
    #
    recorder = wurb_core.WurbRecorder()
    recorder.setup_sound_manager()
    #
    print('TEST - started.')
    recorder.start_recording()
    time.sleep(5.5)
    recorder.stop_recording()
 def __init__(self):
     """ """
     self._logger = logging.getLogger('CloudedBatsWURB')
     self._settings = wurb_core.WurbSettings()
    def start(self):
        """ """
        # State machine.
        self._logger.info('')
        self._logger.info('=== State machine startup. ===')
        self._state_machine = wurb_core.WurbStateMachine()
        self._state_machine.load_states(self.define_state_machine())
        self._state_machine.set_perform_action_function(self.perform_action)
        self._state_machine.set_current_state('wurb_init')
        self._state_machine.start()

        # Settings. Singleton util.
        self._logger.info('')
        self._logger.info('=== Setting startup. ===')
        self._settings = wurb_core.WurbSettings()
        desc = [
            '# ',
            '# Default settings for CloudedBats WURB.',
            '# Check the file "cloudedbats_wurb/README.txt" for more info.',
            '# ',
        ]
        self._settings.set_default_values(desc, [], [])
        # Load default settings for wurb_recorder.
        (desc, default, dev) = wurb_core.wurb_recorder.default_settings()
        self._settings.set_default_values(desc, default, dev)
        # Load default settings for wurb_scheduler.
        desc, default, dev = wurb_core.wurb_scheduler.default_settings()
        self._settings.set_default_values(desc, default, dev)
        # Load default settings for wurb_gps_reader.
        desc, default, dev = wurb_core.wurb_gps_reader.default_settings()
        self._settings.set_default_values(desc, default, dev)
        # Load default settings for wurb_sound_detector.
        desc, default, dev = wurb_core.wurb_sound_detector.default_settings()
        self._settings.set_default_values(desc, default, dev)
        # Internal and external paths to setting files.
        current_dir = pathlib.Path(__file__).parents[1]
        internal_path = pathlib.Path(current_dir, 'wurb_settings')
        external_path = pathlib.Path('/media/usb0/cloudedbats_wurb/settings')
        internal_setting_path = pathlib.Path(internal_path,
                                             'user_settings.txt')
        # Create directories.
        if not internal_path.exists():
            internal_path.mkdir(parents=True)
        if self._usb_memory_used:
            if not external_path.exists():
                external_path.mkdir(parents=True)
        # Copy settings from USB.
        if self._usb_memory_used:
            external_setting_path = pathlib.Path(external_path,
                                                 'user_settings.txt')
            if external_setting_path.exists():
                self._logger.info(
                    'Settings: Copying user_settings.txt from USB')
                shutil.copy(str(external_setting_path),
                            str(internal_setting_path))
        # Load setting from file.
        self._logger.info('WURB Main: Loading user settings file.')
        self._settings.load_settings(internal_setting_path)
        # Save default setting and last used settings.
        self._settings.save_default_settings(
            pathlib.Path(internal_path, 'user_settings_DEFAULT.txt'))
        self._settings.save_last_used_settings(
            pathlib.Path(internal_path, 'user_settings_LAST_USED.txt'))
        if self._usb_memory_used:
            self._logger.info(
                'Settings: Copying settings files and readme.txt to USB')
            shutil.copy(str(pathlib.Path(current_dir, 'wurb_core/README.txt')),
                        str(pathlib.Path(external_path.parent, 'README.txt')))
            self._settings.save_default_settings(
                pathlib.Path(external_path, 'user_settings_DEFAULT.txt'))
            self._settings.save_last_used_settings(
                pathlib.Path(external_path, 'user_settings_LAST_USED.txt'))

        # Sunset-sunrise. Singleton util.
        self._logger.info('')
        self._logger.info('=== Setting and config startup. ===')
        wurb_core.WurbSunsetSunrise().set_timezone(
            self._settings.text('timezone'))

        # GPS. Singleton util.
        self._logger.info('')
        self._logger.info('=== GPS startup. ===')
        wurb_core.WurbGpsReader().start()

        # Initiate sound recorder.
        self._logger.info('')
        self._logger.info('=== Sound recorder startup. ===')
        self._recorder = wurb_core.WurbRecorder(
            callback_function=self.perform_event)
        self._recorder.setup_sound_manager()

        # Control-GPIO. Connected by callback.
        self._logger.info('')
        self._logger.info('=== GPIO control startup. ===')
        self._gpio_ctrl = wurb_raspberry_pi.ControlByGpio(
            callback_function=self.perform_event)
        # Control-mouse. Connected by callback.
        self._logger.info('')
        self._logger.info('=== Computer mouse startup. ===')
        self._mouse_ctrl = wurb_raspberry_pi.ControlByMouse(
            callback_function=self.perform_event)

        # Control-scheduler. Connected by callback.
        self._logger.info('')
        self._logger.info('=== Scheduler startup. ===')
        self._scheduler = wurb_core.WurbScheduler(
            callback_function=self.perform_event)

        self._logger.info('')
        self._logger.info('=== Startup done. ===')
        self._logger.info('')