gnuradio_handler.py 3.91 KB
Newer Older
1
from __future__ import absolute_import, division, print_function
2

3
import logging
4
import subprocess
5
import os
6
import json
7 8 9

from satnogsclient import settings as client_settings

10
LOGGER = logging.getLogger('default')
11

John Giannelos's avatar
John Giannelos committed
12

13
def get_gnuradio_info():
Vasilis Tsiligiannis's avatar
Vasilis Tsiligiannis committed
14 15 16
    process = subprocess.Popen(['python', '-m', 'satnogs.satnogs_info'],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
17
    gr_satnogs_info, _ = process.communicate()  # pylint: disable=W0612
18 19 20
    client_metadata = {
        'radio': {
            'name': 'gr-satnogs',
21
            'version': None,
cgbsat's avatar
cgbsat committed
22
            'rx_device': client_settings.SATNOGS_RX_DEVICE,
23 24 25 26 27 28 29
            'ppm_error': client_settings.SATNOGS_PPM_ERROR,
            'if_gain': client_settings.SATNOGS_IF_GAIN,
            'rf_gain': client_settings.SATNOGS_RF_GAIN,
            'bb_gain': client_settings.SATNOGS_BB_GAIN,
            'antenna': client_settings.SATNOGS_ANTENNA,
        }
    }
30 31 32 33 34 35 36
    if process.returncode == 0:
        # Convert to valid JSON
        gr_satnogs_info = ''.join(gr_satnogs_info.partition('{')[1:])
        gr_satnogs_info = ''.join(gr_satnogs_info.partition('}')[:2])
        try:
            gr_satnogs_info = json.loads(gr_satnogs_info)
        except ValueError:
37
            client_metadata['radio']['version'] = 'invalid'
38 39
        else:
            if 'version' in gr_satnogs_info:
40 41
                client_metadata['radio']['version'] = gr_satnogs_info[
                    'version']
42
            else:
43
                client_metadata['radio']['version'] = 'unknown'
44 45 46
    return client_metadata


47 48
def exec_gnuradio(observation_file, waterfall_file, freq, baud, script_name,
                  decoded_data):
49 50
    if not script_name:
        script_name = client_settings.GNURADIO_SCRIPT_FILENAME
51
    device = client_settings.SATNOGS_RX_DEVICE
52 53 54 55
    args = [
        script_name, '--rx-sdr-device=' + device, '--rx-freq=' + str(freq),
        '--file-path=' + observation_file
    ]
56
    if waterfall_file != "":
57
        args += ['--waterfall-file-path=' + waterfall_file]
58

59
    # If this is a CW observation pass the WPM parameter
60
    if script_name == client_settings.GNURADIO_CW_SCRIPT_FILENAME and baud > 0:
61
        args += ['--wpm=' + str(int(baud))]
62
    # If this is a BPSK observation pass the baudrate parameter
63
    if script_name == client_settings.GNURADIO_BPSK_SCRIPT_FILENAME and baud > 0:
64
        args += ['--baudrate=' + str(int(baud))]
65
    if client_settings.SATNOGS_DOPPLER_CORR_PER_SEC:
66 67 68 69
        args += [
            '--doppler-correction-per-sec=' +
            client_settings.SATNOGS_DOPPLER_CORR_PER_SEC
        ]
70
    if client_settings.SATNOGS_LO_OFFSET:
71
        args += ['--lo-offset=' + client_settings.SATNOGS_LO_OFFSET]
72
    if client_settings.SATNOGS_RIG_PORT:
73
        args += ['--rigctl-port=' + str(client_settings.SATNOGS_RIG_PORT)]
74
    if client_settings.SATNOGS_PPM_ERROR:
75
        args += ['--ppm=' + client_settings.SATNOGS_PPM_ERROR]
76
    if client_settings.SATNOGS_IF_GAIN:
77
        args += ['--if-gain=' + client_settings.SATNOGS_IF_GAIN]
78
    if client_settings.SATNOGS_RF_GAIN:
79
        args += ['--rf-gain=' + client_settings.SATNOGS_RF_GAIN]
80
    if client_settings.SATNOGS_BB_GAIN:
81
        args += ['--bb-gain=' + client_settings.SATNOGS_BB_GAIN]
82
    if client_settings.SATNOGS_ANTENNA:
83
        args += ['--antenna=' + client_settings.SATNOGS_ANTENNA]
84
    if client_settings.SATNOGS_DEV_ARGS:
85
        args += ['--dev-args=' + client_settings.SATNOGS_DEV_ARGS]
86
    if client_settings.ENABLE_IQ_DUMP:
87 88 89 90
        args += [
            '--enable-iq-dump=' + str(
                int(client_settings.ENABLE_IQ_DUMP is True))
        ]
91
    if client_settings.IQ_DUMP_FILENAME:
92
        args += ['--iq-file-path=' + client_settings.IQ_DUMP_FILENAME]
93
    if not client_settings.DISABLE_DECODED_DATA:
94
        args += ['--decoded-data-file-path=' + decoded_data]
95

96
    LOGGER.info('Starting GNUradio python script')
97
    proc = subprocess.Popen(args, preexec_fn=os.setsid)
98
    return proc