Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: class defining a RF emulation object implemented using a Minicircuits RC4DAT-6G-60 device |
| 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 | import urllib.request |
| 21 | import xml.etree.ElementTree as ET |
| 22 | |
| 23 | from ..core import log |
| 24 | from .rfemu import RFemulation |
| 25 | |
| 26 | # https://www.minicircuits.com/softwaredownload/Prog_Manual-6-Programmable_Attenuator.pdf |
| 27 | class RFemulationMinicircuitsHTTP(RFemulation): |
| 28 | |
| 29 | # HTTP request timeout, in seconds |
| 30 | HTTP_TIMEOUT = 5 |
| 31 | |
| 32 | ############## |
| 33 | # PROTECTED |
| 34 | ############## |
| 35 | def __init__(self, conf): |
| 36 | super().__init__(conf, 'minicircuits') |
| 37 | self.addr = conf.get('addr') |
| 38 | self.ports = conf.get('ports') |
| 39 | if self.addr is None: |
| 40 | raise log.Error('No "addr" attribute provided in supply conf!') |
| 41 | if self.ports is None or len(self.ports) == 0: |
| 42 | raise log.Error('No "port" attribute provided in supply conf!') |
| 43 | self.set_name('minicircuits(%s:%r)' % (self.addr, self.ports)) |
| 44 | |
Andre Puschmann | 69dd689 | 2020-07-02 11:30:13 +0200 | [diff] [blame] | 45 | def __del__(self): |
| 46 | self.dbg('Resetting channel attenuation to zero') |
| 47 | self.set_attenuation(0) |
| 48 | |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 49 | def _url_prefix(self): |
| 50 | #http://10.12.1.216/:SetAttPerChan:1:0_2:0_3:0_4:0 |
| 51 | return 'http://' + self.addr |
| 52 | |
| 53 | def _utl_set_attenauation(self, db): |
| 54 | ports_str = "" |
| 55 | for port in self.ports: |
| 56 | ports_str = ports_str + str(port) + ":" |
| 57 | |
| 58 | return self._url_prefix() + '/:CHAN:' + ports_str + 'SETATT:' + str(db) |
| 59 | |
| 60 | ############################# |
| 61 | # PUBLIC (test API included) |
| 62 | ############################# |
| 63 | def set_attenuation(self, db): |
| 64 | url = self._utl_set_attenauation(db) |
| 65 | self.dbg('sending HTTP req: "%s"' % url) |
| 66 | data = urllib.request.urlopen(url, timeout = self.HTTP_TIMEOUT).read() |
| 67 | data_str = str(data, 'utf-8') |
| 68 | self.dbg('Received response: "%s"' % data_str) |
| 69 | if data_str != '1': |
| 70 | raise log.Error('Mini-circuits attenuation device returned failure! %s' & data_str) |
Andre Puschmann | 8b1547b | 2020-06-12 15:10:24 +0200 | [diff] [blame] | 71 | |
| 72 | def get_max_attenuation(self): |
| 73 | return 95 # Maximum value of the Mini-Circuits RC4DAT-6G-95 |
| 74 | |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 75 | # vim: expandtab tabstop=4 shiftwidth=4 |