blob: 6214040bd94b7de3309dc70709634231b969329f [file] [log] [blame]
Pau Espin Pedrold4404d52020-04-20 13:29:31 +02001# 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
20import urllib.request
21import xml.etree.ElementTree as ET
22
23from ..core import log
24from .rfemu import RFemulation
25
26# https://www.minicircuits.com/softwaredownload/Prog_Manual-6-Programmable_Attenuator.pdf
27class 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
45 def _url_prefix(self):
46 #http://10.12.1.216/:SetAttPerChan:1:0_2:0_3:0_4:0
47 return 'http://' + self.addr
48
49 def _utl_set_attenauation(self, db):
50 ports_str = ""
51 for port in self.ports:
52 ports_str = ports_str + str(port) + ":"
53
54 return self._url_prefix() + '/:CHAN:' + ports_str + 'SETATT:' + str(db)
55
56#############################
57# PUBLIC (test API included)
58#############################
59 def set_attenuation(self, db):
60 url = self._utl_set_attenauation(db)
61 self.dbg('sending HTTP req: "%s"' % url)
62 data = urllib.request.urlopen(url, timeout = self.HTTP_TIMEOUT).read()
63 data_str = str(data, 'utf-8')
64 self.dbg('Received response: "%s"' % data_str)
65 if data_str != '1':
66 raise log.Error('Mini-circuits attenuation device returned failure! %s' & data_str)
Andre Puschmann8b1547b2020-06-12 15:10:24 +020067
68 def get_max_attenuation(self):
69 return 95 # Maximum value of the Mini-Circuits RC4DAT-6G-95
70
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020071# vim: expandtab tabstop=4 shiftwidth=4