blob: 8f7b57a3824d8ccd6be4641539203efc2a83027a [file] [log] [blame]
Vadim Yanitskiyf3eccbf2017-07-19 15:17:37 +07001#!/usr/bin/env python2
2# -*- coding: utf-8 -*-
3
4# GR-GSM based transceiver
5# CTRL interface for OsmocomBB
6#
7# (C) 2016-2017 by Vadim Yanitskiy <axilirator@gmail.com>
8#
9# All Rights Reserved
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License along
22# with this program; if not, write to the Free Software Foundation, Inc.,
23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25from ctrl_if import CTRLInterface
26
27class CTRLInterfaceBB(CTRLInterface):
28 def __init__(self, remote_addr, remote_port, bind_port, tb):
29 print("[i] Init CTRL interface")
30 CTRLInterface.__init__(self, remote_addr, remote_port, bind_port)
31
32 # Set link to the follow graph (top block)
33 self.tb = tb
34
35 def shutdown(self):
36 print("[i] Shutdown CTRL interface")
37 CTRLInterface.shutdown(self)
38
39 def parse_cmd(self, request):
40 # Power control
41 if self.verify_cmd(request, "POWERON", 0):
42 print("[i] Recv POWERON CMD")
43
44 # Ensure transceiver isn't working
45 if self.tb.trx_started:
46 print("[!] Transceiver already started")
47 return -1
48
49 # Ensure transceiver is ready to start
50 if not self.tb.check_available():
51 print("[!] Transceiver isn't ready to start")
52 return -1
53
54 print("[i] Starting transceiver...")
55 self.tb.trx_started = True
56 self.tb.start()
57
58 return 0
59
60 elif self.verify_cmd(request, "POWEROFF", 0):
61 print("[i] Recv POWEROFF cmd")
62
63 # TODO: flush all buffers between blocks
64 if self.tb.trx_started:
65 print("[i] Stopping transceiver...")
66 self.tb.trx_started = False
67 self.tb.stop()
68
69 return 0
70
71 elif self.verify_cmd(request, "SETRXGAIN", 1):
72 print("[i] Recv SETRXGAIN cmd")
73
74 # TODO: check gain value
75 gain = int(request[1])
76 self.tb.set_gain(gain)
77
78 return 0
79
80 # Tuning Control
81 elif self.verify_cmd(request, "RXTUNE", 1):
82 print("[i] Recv RXTUNE cmd")
83
84 # TODO: check freq range
85 freq = int(request[1]) * 1000
86 self.tb.set_fc(freq)
87
88 return 0
89
90 elif self.verify_cmd(request, "TXTUNE", 1):
91 print("[i] Recv TXTUNE cmd")
92
93 # TODO: is not implemented yet
94 return 0
95
96 # Misc
97 elif self.verify_cmd(request, "ECHO", 0):
98 print("[i] Recv ECHO cmd")
99 return 0
100
101 # Wrong / unknown command
102 else:
103 print("[!] Wrong request on CTRL interface")
104 return -1