blob: c501dcfbff8a407684ac375f076d4b0f7635f481 [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
Andre Puschmann69dd6892020-07-02 11:30:13 +020045 def __del__(self):
46 self.dbg('Resetting channel attenuation to zero')
47 self.set_attenuation(0)
48
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020049 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 Puschmann8b1547b2020-06-12 15:10:24 +020071
72 def get_max_attenuation(self):
73 return 95 # Maximum value of the Mini-Circuits RC4DAT-6G-95
74
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020075# vim: expandtab tabstop=4 shiftwidth=4