示例#1
0
def clean_task_list():
    """ Check the task list to see if any tasks have stopped running. If so, release the associated SDR """

    for _key in autorx.task_list.keys():
        # Attempt to get the state of the task
        try:
            _running = autorx.task_list[_key]['task'].running()
            _task_sdr = autorx.task_list[_key]['device_idx']
        except Exception as e:
            logging.error("Task Manager - Error getting task %s state - %s" %
                          (str(_key), str(e)))
            continue

        if _running == False:
            # This task has stopped. Release its associated SDR.
            autorx.sdr_list[_task_sdr]['in_use'] = False
            autorx.sdr_list[_task_sdr]['task'] = None
            # Pop the task from the task list.
            autorx.task_list.pop(_key)
            # Indicate to the web client that the task list has been updated.
            flask_emit_event('task_event')

    # Check if there is a scanner thread still running. If not, and if there is a SDR free, start one up again.
    if ('SCAN' not in autorx.task_list) and (allocate_sdr(check_only=True)
                                             is not None):
        # We have a SDR free, and we are not running a scan thread. Start one.
        start_scanner()
示例#2
0
def start_decoder(freq: float, sonde_type: str) -> None:
    """ Attempt to start a decoder thread for a given sonde.

    Args:
        freq (float): Radiosonde frequency in Hz.
        sonde_type (str): The radiosonde type ('RS41', 'RS92', 'DFM', 'M10, 'iMet')

    """
    global config, RS_PATH, exporter_functions, rs92_ephemeris, temporary_block_list

    # Allocate a SDR.
    _device_idx = allocate_sdr(
        task_description="Decoder ({0}, {0.3f} MHz)".format(
            sonde_type, freq / 1e6))

    if _device_idx is None:
        logging.error("Could not allocate SDR for decoder!")
        return
    else:
        # Add an entry to the task list
        autorx.task_list[freq] = {"device_idx": _device_idx, "task": None}

        # Set the SDR to in-use
        autorx.sdr_list[_device_idx]["in_use"] = True

        if sonde_type.startswith("-"):
            _exp_sonde_type = sonde_type[1:]
        else:
            _exp_sonde_type = sonde_type

        # Initialise a decoder.
        autorx.task_list[freq]["task"] = SondeDecoder(
            sonde_type=sonde_type,
            sonde_freq=freq,
            rs_path=RS_PATH,
            sdr_fm=config["sdr_fm"],
            device_idx=_device_idx,
            gain=autorx.sdr_list[_device_idx]["gain"],
            ppm=autorx.sdr_list[_device_idx]["ppm"],
            bias=autorx.sdr_list[_device_idx]["bias"],
            save_decode_audio=config["save_decode_audio"],
            save_decode_iq=config["save_decode_iq"],
            exporter=exporter_functions,
            timeout=config["rx_timeout"],
            telem_filter=telemetry_filter,
            rs92_ephemeris=rs92_ephemeris,
            imet_location=config["station_code"],
            rs41_drift_tweak=config["rs41_drift_tweak"],
            experimental_decoder=config["experimental_decoders"]
            [_exp_sonde_type],
        )
        autorx.sdr_list[_device_idx]["task"] = autorx.task_list[freq]["task"]

    # Indicate to the web client that the task list has been updated.
    flask_emit_event("task_event")
示例#3
0
def start_scanner():
    """Start a scanner thread on the first available SDR"""
    global config, RS_PATH, temporary_block_list

    if "SCAN" in autorx.task_list:
        # Already a scanner running! Return.
        logging.debug(
            "Task Manager - Attempted to start a scanner, but one already running."
        )
        return

    # Attempt to allocate a SDR.
    _device_idx = allocate_sdr(task_description="Scanner")
    if _device_idx is None:
        logging.debug("Task Manager - No SDRs free to run Scanner.")
        return
    else:
        # Create entry in task list.
        autorx.task_list["SCAN"] = {"device_idx": _device_idx, "task": None}

        # Init Scanner using settings from the global config.
        # TODO: Nicer way of passing in the huge list of args.
        autorx.task_list["SCAN"]["task"] = SondeScanner(
            callback=autorx.scan_results.put,
            auto_start=True,
            min_freq=config["min_freq"],
            max_freq=config["max_freq"],
            search_step=config["search_step"],
            only_scan=config["only_scan"],
            always_scan=config["always_scan"],
            never_scan=config["never_scan"],
            snr_threshold=config["snr_threshold"],
            min_distance=config["min_distance"],
            quantization=config["quantization"],
            scan_dwell_time=config["scan_dwell_time"],
            scan_delay=config["scan_delay"],
            detect_dwell_time=config["detect_dwell_time"],
            max_peaks=config["max_peaks"],
            rs_path=RS_PATH,
            sdr_power=config["sdr_power"],
            sdr_fm=config["sdr_fm"],
            device_idx=_device_idx,
            gain=autorx.sdr_list[_device_idx]["gain"],
            ppm=autorx.sdr_list[_device_idx]["ppm"],
            bias=autorx.sdr_list[_device_idx]["bias"],
            save_detection_audio=config["save_detection_audio"],
            temporary_block_list=temporary_block_list,
            temporary_block_time=config["temporary_block_time"],
        )

        # Add a reference into the sdr_list entry
        autorx.sdr_list[_device_idx]["task"] = autorx.task_list["SCAN"]["task"]

    # Indicate to the web client that the task list has been updated.
    flask_emit_event("task_event")
示例#4
0
def start_decoder(freq, sonde_type):
    """ Attempt to start a decoder thread for a given sonde.

    Args:
        freq (float): Radiosonde frequency in Hz.
        sonde_type (str): The radiosonde type ('RS41', 'RS92', 'DFM', 'M10, 'iMet')

    """
    global config, RS_PATH, exporter_functions, rs92_ephemeris, temporary_block_list

    # Allocate a SDR.
    _device_idx = allocate_sdr(task_description="Decoder (%s, %.3f MHz)" %
                               (sonde_type, freq / 1e6))

    if _device_idx is None:
        logging.error("Could not allocate SDR for decoder!")
        return
    else:
        # Add an entry to the task list
        autorx.task_list[freq] = {'device_idx': _device_idx, 'task': None}

        # Set the SDR to in-use
        autorx.sdr_list[_device_idx]['in_use'] = True

        if sonde_type.startswith('-'):
            _exp_sonde_type = sonde_type[1:]
        else:
            _exp_sonde_type = sonde_type

        # Initialise a decoder.
        autorx.task_list[freq]['task'] = SondeDecoder(
            sonde_type=sonde_type,
            sonde_freq=freq,
            rs_path=RS_PATH,
            sdr_fm=config['sdr_fm'],
            device_idx=_device_idx,
            gain=autorx.sdr_list[_device_idx]['gain'],
            ppm=autorx.sdr_list[_device_idx]['ppm'],
            bias=autorx.sdr_list[_device_idx]['bias'],
            save_decode_audio=config['save_decode_audio'],
            save_decode_iq=config['save_decode_iq'],
            exporter=exporter_functions,
            timeout=config['rx_timeout'],
            telem_filter=telemetry_filter,
            rs92_ephemeris=rs92_ephemeris,
            imet_location=config['station_code'],
            rs41_drift_tweak=config['rs41_drift_tweak'],
            experimental_decoder=config['experimental_decoders']
            [_exp_sonde_type],
            decoder_stats=config['decoder_stats'])
        autorx.sdr_list[_device_idx]['task'] = autorx.task_list[freq]['task']

    # Indicate to the web client that the task list has been updated.
    flask_emit_event('task_event')
示例#5
0
def start_scanner():
    """ Start a scanner thread on the first available SDR """
    global config, RS_PATH, temporary_block_list

    if 'SCAN' in autorx.task_list:
        # Already a scanner running! Return.
        logging.debug(
            "Task Manager - Attempted to start a scanner, but one already running."
        )
        return

    # Attempt to allocate a SDR.
    _device_idx = allocate_sdr(task_description="Scanner")
    if _device_idx is None:
        logging.debug("Task Manager - No SDRs free to run Scanner.")
        return
    else:
        # Create entry in task list.
        autorx.task_list['SCAN'] = {'device_idx': _device_idx, 'task': None}

        # Init Scanner using settings from the global config.
        # TODO: Nicer way of passing in the huge list of args.
        autorx.task_list['SCAN']['task'] = SondeScanner(
            callback=autorx.scan_results.put,
            auto_start=True,
            min_freq=config['min_freq'],
            max_freq=config['max_freq'],
            search_step=config['search_step'],
            whitelist=config['whitelist'],
            greylist=config['greylist'],
            blacklist=config['blacklist'],
            snr_threshold=config['snr_threshold'],
            min_distance=config['min_distance'],
            quantization=config['quantization'],
            scan_dwell_time=config['scan_dwell_time'],
            detect_dwell_time=config['detect_dwell_time'],
            max_peaks=config['max_peaks'],
            rs_path=RS_PATH,
            sdr_power=config['sdr_power'],
            sdr_fm=config['sdr_fm'],
            device_idx=_device_idx,
            gain=autorx.sdr_list[_device_idx]['gain'],
            ppm=autorx.sdr_list[_device_idx]['ppm'],
            bias=autorx.sdr_list[_device_idx]['bias'],
            save_detection_audio=config['save_detection_audio'],
            temporary_block_list=temporary_block_list,
            temporary_block_time=config['temporary_block_time'])

        # Add a reference into the sdr_list entry
        autorx.sdr_list[_device_idx]['task'] = autorx.task_list['SCAN']['task']

    # Indicate to the web client that the task list has been updated.
    flask_emit_event('task_event')
示例#6
0
def clean_task_list():
    """ Check the task list to see if any tasks have stopped running. If so, release the associated SDR """

    for _key in autorx.task_list.keys():
        # Attempt to get the state of the task
        try:
            _running = autorx.task_list[_key]['task'].running()
            _task_sdr = autorx.task_list[_key]['device_idx']
            _exit_state = autorx.task_list[_key]['task'].exit_state
        except Exception as e:
            logging.error("Task Manager - Error getting task %s state - %s" %
                          (str(_key), str(e)))
            continue

        if _running == False:
            # This task has stopped.
            # Check the exit state of the task for any abnormalities:
            if _exit_state == "Encrypted":
                # This task was a decoder, and it has encountered an encrypted sonde.
                logging.info(
                    "Task Manager - Adding temporary block for frequency %.3f MHz"
                    % (_key / 1e6))
                # Add the sonde's frequency to the global temporary block-list
                temporary_block_list[_key] = time.time()
                # If there is a scanner currently running, add it to the scanners internal block list.
                if 'SCAN' in autorx.task_list:
                    autorx.task_list['SCAN']['task'].add_temporary_block(_key)

            # Release its associated SDR.
            autorx.sdr_list[_task_sdr]['in_use'] = False
            autorx.sdr_list[_task_sdr]['task'] = None

            # Pop the task from the task list.
            autorx.task_list.pop(_key)
            # Indicate to the web client that the task list has been updated.
            flask_emit_event('task_event')

    # Clean out the temporary block list of old entries.
    for _freq in temporary_block_list.keys():
        if temporary_block_list[_freq] < (time.time() -
                                          config['temporary_block_time'] * 60):
            temporary_block_list.pop(_freq)
            logging.info(
                "Task Manager - Removed %.3f MHz from temporary block list." %
                (_freq / 1e6))

    # Check if there is a scanner thread still running.
    # If not, and if there is a SDR free, start one up again.
    # Also check for a global scan inhibit flag.
    if ('SCAN' not in autorx.task_list) and (not autorx.scan_inhibit) and (
            allocate_sdr(check_only=True) is not None):
        # We have a SDR free, and we are not running a scan thread. Start one.
        start_scanner()
示例#7
0
def clean_task_list():
    """ Check the task list to see if any tasks have stopped running. If so, release the associated SDR """

    for _key in autorx.task_list.copy().keys():
        # Attempt to get the state of the task
        try:
            _running = autorx.task_list[_key]["task"].running()
            _task_sdr = autorx.task_list[_key]["device_idx"]
            _exit_state = autorx.task_list[_key]["task"].exit_state
        except Exception as err:
            logging.error(
                "Task Manager - Error getting task {} state - {}".format(
                    _key, err))
            continue

        if not _running:
            # This task has stopped.
            # Check the exit state of the task for any abnormalities:
            if (_exit_state == "Encrypted") or (_exit_state == "TempBlock"):
                # This task was a decoder, and it has encountered an encrypted sonde, or one too far away.
                logging.info(
                    "Task Manager - Adding temporary block for frequency {0.3f} MHz"
                    .format(_key / 1e6))
                # Add the sonde's frequency to the global temporary block-list
                temporary_block_list[_key] = time.time()
                # If there is a scanner currently running, add it to the scanners internal block list.
                if "SCAN" in autorx.task_list:
                    autorx.task_list["SCAN"]["task"].add_temporary_block(_key)

            if _exit_state == "FAILED SDR":
                # The SDR was not able to be recovered after many attempts.
                # Remove it from the SDR list and flag an error.
                autorx.sdr_list.pop(_task_sdr)
                _error_msg = (
                    "Task Manager - Removed SDR {} from SDR list due to repeated failures."
                    .format(_task_sdr))
                logging.error(_error_msg)

                # Send email if configured.
                email_error(_error_msg)

            else:
                # Release its associated SDR.
                autorx.sdr_list[_task_sdr]["in_use"] = False
                autorx.sdr_list[_task_sdr]["task"] = None

            # Pop the task from the task list.
            autorx.task_list.pop(_key)
            # Indicate to the web client that the task list has been updated.
            flask_emit_event("task_event")

    # Clean out the temporary block list of old entries.
    for _freq in temporary_block_list.copy().keys():
        if temporary_block_list[_freq] < (time.time() -
                                          config["temporary_block_time"] * 60):
            temporary_block_list.pop(_freq)
            logging.info(
                "Task Manager - Removed {0.3f} MHz from temporary block list.".
                format(_freq / 1e6))

    # Check if there is a scanner thread still running.
    # If not, and if there is a SDR free, start one up again.
    # Also check for a global scan inhibit flag.
    if (("SCAN" not in autorx.task_list) and (not autorx.scan_inhibit)
            and (allocate_sdr(check_only=True) is not None)):
        # We have a SDR free, and we are not running a scan thread. Start one.
        start_scanner()
示例#8
0
def clean_task_list():
    """Check the task list to see if any tasks have stopped running. If so, release the associated SDR"""
    global decode_attemp_dict
    global fail_detect_dict

    for _key in autorx.task_list.copy().keys():
        # Attempt to get the state of the task
        try:
            _running = autorx.task_list[_key]["task"].running()
            _task_sdr = autorx.task_list[_key]["device_idx"]
            _exit_state = autorx.task_list[_key]["task"].exit_state
        except Exception as e:
            logging.error("Task Manager - Error getting task %s state - %s" %
                          (str(_key), str(e)))
            continue

        if _running == False:
            # This task has stopped.
            # Check the exit state of the task for any abnormalities:
            if (_exit_state == "Encrypted") or (_exit_state == "TempBlock"):
                # This task was a decoder, and it has encountered an encrypted sonde, or one too far away.
                logging.info(
                    "Task Manager - Adding temporary block for frequency %.3f MHz"
                    % (_key / 1e6))
                # Add the sonde's frequency to the global temporary block-list
                temporary_block_list[_key] = time.time()
                # If there is a scanner currently running, add it to the scanners internal block list.
                if "SCAN" in autorx.task_list:
                    autorx.task_list["SCAN"]["task"].add_temporary_block(_key)

            #Zigi
            elif _exit_state == "Lockout":
                # This task was a decoder, and it has encountered an locked-out sonde.
                logging.info(
                    "Task Manager - Adding temporary lockout for frequency %.3f MHz"
                    % (_key / 1e6))
                # Add the sonde's frequency to the global temporary block-list
                temporary_block_list[_key] = time.time()
                # If there is a scanner currently running, add it to the scanners internal block list.
                if 'SCAN' in autorx.task_list:
                    autorx.task_list['SCAN']['task'].add_temporary_block(_key)
            elif _exit_state == "Brown":
                # This task was a decoder, and it has encountered an locked-out sonde.
                logging.info(
                    "Task Manager - Adding temporary lockout for frequency %.3f MHz"
                    % (_key / 1e6))
                # Add the sonde's frequency to the global temporary block-list
                temporary_block_list[_key] = time.time(
                ) - config['temporary_block_time'] * 60 + 60 * 60
                # If there is a scanner currently running, add it to the scanners internal block list.
                if 'SCAN' in autorx.task_list:
                    autorx.task_list['SCAN']['task'].add_temporary_block(_key)
            #Zigi
            #elif _exit_state == "LIMIT":
            # This task was a decoder, and it has encountered an locked-out sonde.
            if (config['decode_limit_period'] > 0):
                #logging.info("Task Manager - Storing frequency %.3f MHz" % (_key/1e6))
                for attemptFreq in decode_attemp_dict.copy().keys():
                    if np.abs(attemptFreq - _key) < (10000 / 2.0):
                        decode_attemp_dict.pop(attemptFreq)
                        #print("Reordering:" +str(attemptFreq))
                decode_attemp_dict[_key] = time.time()
                #print("Added:" +str(_key))
                #print(decode_attemp_dict)

                #_index = np.argwhere(np.abs(np.array(detect_attemp_list)-_key)<(10000/2.0))
                #detect_attemp_np = np.delete(detect_attemp_list, _index)
                #detect_attemp_list = detect_attemp_np.tolist()
                #detect_attemp_list.append(_key)

                #if len(detect_attemp_list) > config['max_peaks']: #self.max_peaks:
                #    detect_attemp_list = detect_attemp_list[-config['max_peaks']:]

                #print("New detect_attemp_list:"+ str(np.array(detect_attemp_list)/1e6))

            if _exit_state == "FAILED SDR":
                # The SDR was not able to be recovered after many attempts.
                # Remove it from the SDR list and flag an error.
                autorx.sdr_list.pop(_task_sdr)
                _error_msg = (
                    "Task Manager - Removed SDR %s from SDR list due to repeated failures."
                    % (str(_task_sdr)))
                logging.error(_error_msg)

                # Send email if configured.
                email_error(_error_msg)

            else:
                # Release its associated SDR.
                autorx.sdr_list[_task_sdr]["in_use"] = False
                autorx.sdr_list[_task_sdr]["task"] = None

            # Pop the task from the task list.
            autorx.task_list.pop(_key)
            # Indicate to the web client that the task list has been updated.
            flask_emit_event("task_event")

    #Zigi
    if (config['decode_limit_period'] > 0):
        #logging.info("Task Manager - Storing frequency %.3f MHz" % (_key/1e6))
        for attemptFreq in decode_attemp_dict.copy().keys():
            if ((time.time() - decode_attemp_dict[attemptFreq]) >=
                ((2 * len(decode_attemp_dict.copy().keys()) + 1) *
                 config['decode_limit_period'] * 60)):
                decode_attemp_dict.pop(attemptFreq)
                #print("Removing:" +str(attemptFreq))

    # Clean out the temporary block list of old entries.
    for _freq in temporary_block_list.copy().keys():
        if temporary_block_list[_freq] < (time.time() -
                                          config["temporary_block_time"] * 60):
            temporary_block_list.pop(_freq)
            logging.info(
                "Task Manager - Removed %.3f MHz from temporary block list." %
                (_freq / 1e6))

    # Check if there is a scanner thread still running.
    # If not, and if there is a SDR free, start one up again.
    # Also check for a global scan inhibit flag.
    if (("SCAN" not in autorx.task_list) and (not autorx.scan_inhibit)
            and (allocate_sdr(check_only=True) is not None)):
        # We have a SDR free, and we are not running a scan thread. Start one.
        start_scanner()
示例#9
0
def start_decoder(freq, sonde_type):
    """Attempt to start a decoder thread for a given sonde.

    Args:
        freq (float): Radiosonde frequency in Hz.
        sonde_type (str): The radiosonde type ('RS41', 'RS92', 'DFM', 'M10, 'iMet')

    """
    global config, RS_PATH, exporter_functions, rs92_ephemeris, temporary_block_list
    global decode_attemp_dict

    # Allocate a SDR.
    _device_idx = allocate_sdr(task_description="Decoder (%s, %.3f MHz)" %
                               (sonde_type, freq / 1e6))

    if _device_idx is None:
        logging.error("Could not allocate SDR for decoder!")
        return
    else:
        # Add an entry to the task list
        autorx.task_list[freq] = {"device_idx": _device_idx, "task": None}

        # Set the SDR to in-use
        autorx.sdr_list[_device_idx]["in_use"] = True

        if sonde_type.startswith("-"):
            _exp_sonde_type = sonde_type[1:]
        else:
            _exp_sonde_type = sonde_type

        # Initialise a decoder.
        autorx.task_list[freq]["task"] = SondeDecoder(
            sonde_type=sonde_type,
            sonde_freq=freq,
            rs_path=RS_PATH,
            sdr_fm=config["sdr_fm"],
            device_idx=_device_idx,
            gain=autorx.sdr_list[_device_idx]["gain"],
            ppm=autorx.sdr_list[_device_idx]["ppm"],
            bias=autorx.sdr_list[_device_idx]["bias"],
            save_decode_audio=config["save_decode_audio"],
            save_decode_iq=config["save_decode_iq"],
            exporter=exporter_functions,
            timeout=config["rx_timeout"],
            telem_filter=telemetry_filter,
            rs92_ephemeris=rs92_ephemeris,
            rs41_drift_tweak=config["rs41_drift_tweak"],
            experimental_decoder=config["experimental_decoders"]
            [_exp_sonde_type],
            geo_filter_enable=config['geo_filter_enable'],
            decode_limit_period=config['decode_limit_period'],
            decode_limit_min_alt=config['decode_limit_min_alt'],
            brownlist=config['brownlist'],
            black_types=config['black_types'],
            imet_upload_filter_polygon=zip(
                config['imet_upload_filter_polygon_lat'],
                config['imet_upload_filter_polygon_lon']),
            save_raw_hex=config["save_raw_hex"])
        autorx.sdr_list[_device_idx]["task"] = autorx.task_list[freq]["task"]

    # Indicate to the web client that the task list has been updated.
    flask_emit_event("task_event")
示例#10
0
def start_decoder(freq, sonde_type):
    """ Attempt to start a decoder thread for a given sonde.

    Args:
        freq (float): Radiosonde frequency in Hz.
        sonde_type (str): The radiosonde type ('RS41', 'RS92', 'DFM', 'M10, 'iMet')

    """
    global config, RS_PATH, exporter_functions, rs92_ephemeris, temporary_block_list

    # Check the frequency is not in our temporary block list
    # (This may happen from time-to-time depending on the timing of the scan thread)
    if freq in temporary_block_list.keys():
        if temporary_block_list[freq] > (time.time() -
                                         config['temporary_block_time'] * 60):
            logging.error(
                "Task Manager - Attempted to start a decoder on a temporarily blocked frequency (%.3f MHz)"
                % (freq / 1e6))
            return
        else:
            # This frequency should not be blocked any more, remove it from the block list.
            logging.info(
                "Task Manager - Removed %.3f MHz from temporary block list." %
                (freq / 1e6))
            temporary_block_list.pop(freq)

    # Allocate a SDR.
    _device_idx = allocate_sdr(task_description="Decoder (%s, %.3f MHz)" %
                               (sonde_type, freq / 1e6))

    if _device_idx is None:
        logging.error("Could not allocate SDR for decoder!")
        return
    else:
        # Add an entry to the task list
        autorx.task_list[freq] = {'device_idx': _device_idx, 'task': None}

        # Set the SDR to in-use
        autorx.sdr_list[_device_idx]['in_use'] = True

        # Initialise a decoder.
        autorx.task_list[freq]['task'] = SondeDecoder(
            sonde_type=sonde_type,
            sonde_freq=freq,
            rs_path=RS_PATH,
            sdr_fm=config['sdr_fm'],
            device_idx=_device_idx,
            gain=autorx.sdr_list[_device_idx]['gain'],
            ppm=autorx.sdr_list[_device_idx]['ppm'],
            bias=autorx.sdr_list[_device_idx]['bias'],
            save_decode_audio=config['save_decode_audio'],
            save_decode_iq=config['save_decode_iq'],
            exporter=exporter_functions,
            timeout=config['rx_timeout'],
            telem_filter=telemetry_filter,
            rs92_ephemeris=rs92_ephemeris,
            imet_location=config['station_code'])
        autorx.sdr_list[_device_idx]['task'] = autorx.task_list[freq]['task']

    # Indicate to the web client that the task list has been updated.
    flask_emit_event('task_event')