Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: class defining a RF emulation object |
| 2 | # |
| 3 | # Copyright (C) 2020 by sysmocom - s.f.m.c. GmbH |
| 4 | # |
| 5 | # Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as |
| 9 | # published by the Free Software Foundation, either version 3 of the |
| 10 | # License, or (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | from abc import ABCMeta, abstractmethod |
| 21 | from ..core import log |
| 22 | from ..core.event_loop import MainLoop |
| 23 | |
| 24 | class RFemulation(log.Origin, metaclass=ABCMeta): |
| 25 | |
| 26 | ############## |
| 27 | # PROTECTED |
| 28 | ############## |
| 29 | def __init__(self, conf, name): |
| 30 | """Base constructor. Must be called by subclass.""" |
| 31 | super().__init__(log.C_RUN, name) |
| 32 | self.conf = conf |
| 33 | |
| 34 | ############################# |
| 35 | # PUBLIC (test API included) |
| 36 | ############################# |
| 37 | @abstractmethod |
| 38 | def set_attenuation(self, db): |
| 39 | """Set attenuation in dB on the configured channel""" |
| 40 | pass |
| 41 | |
Andre Puschmann | 8b1547b | 2020-06-12 15:10:24 +0200 | [diff] [blame] | 42 | @abstractmethod |
| 43 | def get_max_attenuation(self): |
| 44 | """Get maximum channel attenuation""" |
| 45 | pass |
| 46 | |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 47 | def get_instance_by_type(rfemu_type, rfemu_opt): |
| 48 | """Allocate a RFemulation child class based on type. Opts are passed to the newly created object.""" |
| 49 | if rfemu_type == 'amarisoftctl': |
| 50 | from .rfemu_amarisoftctrl import RFemulationAmarisoftCtrl |
| 51 | obj = RFemulationAmarisoftCtrl |
| 52 | elif rfemu_type == 'minicircuits': |
| 53 | from .rfemu_minicircuits import RFemulationMinicircuitsHTTP |
| 54 | obj = RFemulationMinicircuitsHTTP |
Pau Espin Pedrol | 1f46d24 | 2020-10-05 12:40:24 +0200 | [diff] [blame] | 55 | elif rfemu_type == 'srsenb_stdin': |
| 56 | from .rfemu_srsenb_stdin import RFemulationSrsStdin |
| 57 | obj = RFemulationSrsStdin |
Pau Espin Pedrol | 4109123 | 2020-10-05 19:23:38 +0200 | [diff] [blame] | 58 | elif rfemu_type == 'gnuradio_zmq': |
| 59 | from .rfemu_gnuradio_zmq import RFemulationGnuradioZmq |
| 60 | obj = RFemulationGnuradioZmq |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 61 | else: |
| 62 | raise log.Error('RFemulation type not supported:', rfemu_type) |
| 63 | |
| 64 | return obj(rfemu_opt) |
| 65 | |
| 66 | |
| 67 | |
| 68 | # vim: expandtab tabstop=4 shiftwidth=4 |