blob: 87e4cbdd17303cb9b2b22003747c8dc04f7f1a48 [file] [log] [blame]
Pau Espin Pedrold4404d52020-04-20 13:29:31 +02001# osmo_gsm_tester: class defining a RF emulation object implemented using Amarisoft Ctl interface
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 json
21from websocket import create_connection
22
23from ..core import log
24from .rfemu import RFemulation
25
26class RFemulationAmarisoftCtrl(RFemulation):
27##############
28# PROTECTED
29##############
30 def __init__(self, conf):
31 super().__init__(conf, 'amarisoftctl')
32 self.addr = conf.get('addr')
33 self.port = conf.get('ports')
34 if self.addr is None:
35 raise log.Error('No "addr" attribute provided in supply conf!')
36 if self.port is None or len(self.port) != 1:
37 raise log.Error('No "port" attribute provided in supply conf!')
38 self.port = self.port[0]
39 self.set_name('amarisoftctl(%s:%d)' % (self.addr, self.port))
40 self.cell_id = conf.get('cell_id')
41 if self.cell_id is None:
42 raise log.Error('No "cell_id" attribute provided in supply conf!')
43 self.ws = create_connection("ws://%s:%s" % (self.addr, self.port))
44
45 def __del__(self):
46 self.dbg('closing CTRL websocket')
47 self.ws.close()
48
49#############################
50# PUBLIC (test API included)
51#############################
52 def set_attenuation(self, db):
53 msg = { "message": "cell_gain", "cell_id": int(self.cell_id), "gain": -db }
54 msg_str = json.dumps(msg)
55 self.dbg('sending CTRL msg: "%s"' % msg_str)
56 self.ws.send(msg_str)
57 self.dbg('waiting CTRL recv...')
58 result = self.ws.recv()
59 self.dbg('Received CTRL msg: "%s"' % result)
60
61
62# vim: expandtab tabstop=4 shiftwidth=4