<commit_before># -*- coding: utf-8 -*-
import logging
import os

from datetime import datetime
from subprocess import Popen

import settings


logger = logging.getLogger('satnogsclient')


class SignalReceiver():

    _decoding_values = [
        'POCSAG512',
        'POCSAG1200',
        'POCSAG2400',
        'EAS',
        'UFSK1200',
        'CLIPFSK',
        'FMSFSK',
        'AFSK1200',
        'AFSK2400',
        'AFSK2400_2',
        'AFSK2400_3',
        'HAPN4800',
        'FSK9600',
        'DTMF',
        'ZVEI1',
        'ZVEI2',
        'ZVEI3',
        'DZVEI',
        'PZVEI',
        'EEA',
        'EIA',
        'CCIR',
        'MORSE_CW',
        'DUMPCSV',
        'SCOPE'
    ]

    def __init__(self, observation_id, frequency, decoding=None, **kwargs):
        """Initialises receiver"""

        # Check input values
        # We need the observation_id so that it accompanies the serialised output
        if not observation_id:
            raise LookupError('arg not found: observation_id')

        # Frequency is needed to pass to rtl_fm
        if not frequency:
            raise LookupError('arg not found: frequency')

        # Decoding can be None or any value in _decoding_values
        if decoding not in self._decoding_values and decoding is not None:
            raise LookupError('arg not found: decoding')

        # Initialise attributes and default values
        self.observation_id = observation_id
        self.frequency = frequency
        self.decoding = kwargs.get('decoding', None)
        self.ppm_error = settings.PPM_ERROR  # sliding error of receiver
        self.pcm_demodulator = kwargs.get('demodulator', 'AFSK1200')
        self.modulation = kwargs.get('modulation', 'fm')  # mode of received signal
        self.sample_rate = kwargs.get('sample_rate', 22050)  # sample rate for rtl_fm output

        # If aprs is True, multimon-ng sets pcm_demodulator to 'AFSK1200' automagically
        self.aprs = kwargs.get('aprs', True)

    def get_decoding_cmd(self):
        """Provides decoding command."""
        if self.decoding:
            params = {
                '-t': 'raw',  # always raw
                '-a': self.pcm_demodulator,
            }

            args = []
            for key in params:
                args.append(key)
                args.append(params[key])

            if self.aprs:
                args.append('-A')

            args.append('-')
            cmd = [settings.ENCODING_COMMAND] + args
        else:
            # oggenc --raw-endianess=0 -R 24k -B 16 -C 1 -r -q 4
            params = {
                '-R': '24000',
                '-B': '16',
                '-C': '1',
                '-q': '4'
            }
            args = ['--raw-endianness=0', '-r']
            for key in params:
                args.append(key)
                args.append(params[key])

            args.append('-')
            cmd = [settings.ENCODING_COMMAND] + args
        return cmd

    def get_demodulation_cmd(self):
        """Provides demodulation command."""
        if settings.HARDWARE_RADIO:
            params = {
                '-f': 'cd',
                '-t': 'raw'
            }<commit_msg>Match demodulator and decoder raw audio options when a hardware radio is used<commit_after># -*- coding: utf-8 -*-
import logging
import os

from datetime import datetime
from subprocess import Popen

import settings


logger = logging.getLogger('satnogsclient')


class SignalReceiver():

    _decoding_values = [
        'POCSAG512',
        'POCSAG1200',
        'POCSAG2400',
        'EAS',
        'UFSK1200',
        'CLIPFSK',
        'FMSFSK',
        'AFSK1200',
        'AFSK2400',
        'AFSK2400_2',
        'AFSK2400_3',
        'HAPN4800',
        'FSK9600',
        'DTMF',
        'ZVEI1',
        'ZVEI2',
        'ZVEI3',
        'DZVEI',
        'PZVEI',
        'EEA',
        'EIA',
        'CCIR',
        'MORSE_CW',
        'DUMPCSV',
        'SCOPE'
    ]

    def __init__(self, observation_id, frequency, decoding=None, **kwargs):
        """Initialises receiver"""

        # Check input values
        # We need the observation_id so that it accompanies the serialised output
        if not observation_id:
            raise LookupError('arg not found: observation_id')

        # Frequency is needed to pass to rtl_fm
        if not frequency:
            raise LookupError('arg not found: frequency')

        # Decoding can be None or any value in _decoding_values
        if decoding not in self._decoding_values and decoding is not None:
            raise LookupError('arg not found: decoding')

        # Initialise attributes and default values
        self.observation_id = observation_id
        self.frequency = frequency
        self.decoding = kwargs.get('decoding', None)
        self.ppm_error = settings.PPM_ERROR  # sliding error of receiver
        self.pcm_demodulator = kwargs.get('demodulator', 'AFSK1200')
        self.modulation = kwargs.get('modulation', 'fm')  # mode of received signal
        self.sample_rate = kwargs.get('sample_rate', 22050)  # sample rate for rtl_fm output

        # If aprs is True, multimon-ng sets pcm_demodulator to 'AFSK1200' automagically
        self.aprs = kwargs.get('aprs', True)

    def get_decoding_cmd(self):
        """Provides decoding command."""
        if self.decoding:
            params = {
                '-t': 'raw',  # always raw
                '-a': self.pcm_demodulator,
            }

            args = []
            for key in params:
                args.append(key)
                args.append(params[key])

            if self.aprs:
                args.append('-A')

            args.append('-')
            cmd = [settings.ENCODING_COMMAND] + args
        else:
            # oggenc --raw-endianess=0 -R 24k -B 16 -C 1 -r -q 4
            params = {
                '-R': '24000',
                '-B': '16',
                '-C': '1',
                '-q': '4'
            }
            args = ['--raw-endianness=0', '-r']
            for key in params:
                args.append(key)
                args.append(params[key])

            args.append('-')
            cmd = [settings.ENCODING_COMMAND] + args
        return cmd

    def get_demodulation_cmd(self):
        """Provides demodulation command."""
        if settings.HARDWARE_RADIO:
            params = {
                '-f': 'S16_LE',
                '-c': '1',
                '-r': '24000',
                '-t': 'raw'
            }
{'fraction_non_alphanumeric': 0.11237334970832054, 'fraction_numerical': 0.024255449800429842, 'mean_word_length': 1.6323232323232324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2101102', 'n_tokens_mistral': 2086, 'n_tokens_neox': 1935, 'n_words': 498}