blob: ec8ed688072b57b8a018b10d79cefc26d0e4c60d [file] [log] [blame]
Pau Espin Pedrold4404d52020-04-20 13:29:31 +02001# 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
20from abc import ABCMeta, abstractmethod
21from ..core import log
22from ..core.event_loop import MainLoop
23
24class 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 Puschmann8b1547b2020-06-12 15:10:24 +020042 @abstractmethod
43 def get_max_attenuation(self):
44 """Get maximum channel attenuation"""
45 pass
46
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020047def 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 Pedrol1f46d242020-10-05 12:40:24 +020055 elif rfemu_type == 'srsenb_stdin':
56 from .rfemu_srsenb_stdin import RFemulationSrsStdin
57 obj = RFemulationSrsStdin
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020058 else:
59 raise log.Error('RFemulation type not supported:', rfemu_type)
60
61 return obj(rfemu_opt)
62
63
64
65# vim: expandtab tabstop=4 shiftwidth=4