blob: 90d6740e0600c456bfa638a8e49744fd6992c6c3 [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()
Vadim Yanitskiydd0b06a2017-07-19 15:22:41 +070068 self.tb.wait()
Vadim Yanitskiyf3eccbf2017-07-19 15:17:37 +070069
70 return 0
71
72 elif self.verify_cmd(request, "SETRXGAIN", 1):
73 print("[i] Recv SETRXGAIN cmd")
74
75 # TODO: check gain value
76 gain = int(request[1])
77 self.tb.set_gain(gain)
78
79 return 0
80
81 # Tuning Control
82 elif self.verify_cmd(request, "RXTUNE", 1):
83 print("[i] Recv RXTUNE cmd")
84
85 # TODO: check freq range
86 freq = int(request[1]) * 1000
87 self.tb.set_fc(freq)
88
89 return 0
90
91 elif self.verify_cmd(request, "TXTUNE", 1):
92 print("[i] Recv TXTUNE cmd")
93
94 # TODO: is not implemented yet
95 return 0
96
97 # Misc
98 elif self.verify_cmd(request, "ECHO", 0):
99 print("[i] Recv ECHO cmd")
100 return 0
101
102 # Wrong / unknown command
103 else:
104 print("[!] Wrong request on CTRL interface")
105 return -1