blob: 4e706e33e9a459168a195a49be36c2de263f8c60 [file] [log] [blame]
Vadim Yanitskiy180a0372019-01-19 10:22:59 +07001#!/usr/bin/env python2
2# -*- coding: utf-8 -*-
3
4# GR-GSM based transceiver
5# Transceiver implementation
6#
7# (C) 2018-2019 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
Vasil Velichkov46c90be2019-09-02 04:06:41 +030025from .ctrl_if_bb import CTRLInterfaceBB
Vadim Yanitskiy180a0372019-01-19 10:22:59 +070026
27class Transceiver:
28 """ Base transceiver implementation.
29
30 Represents a single transceiver, that can be used as for the BTS side,
31 as for the MS side. Each individual instance of Transceiver unifies
32 three basic interfaces built on three independent UDP connections:
33
34 - CLCK (base port + 100/0) - clock indications from TRX to L1,
35 - CTRL (base port + 101/1) - control interface for L1,
36 - DATA (base port + 102/2) - bidirectional data interface for bursts.
37
38 A transceiver can be either in active (i.e. working), or in idle mode.
39
40 NOTE: both CLCK and DATA interfaces are handled by the flow-graph,
41 (see RadioInterface), so we only initialize CTRL interface.
42
43 """
44
45 def __init__(self, bind_addr, remote_addr, base_port, radio_if):
46 # Connection info
47 self.remote_addr = remote_addr
48 self.bind_addr = bind_addr
49 self.base_port = base_port
50
51 # Execution state (running or idle)
52 self.running = False
53
54 # Radio interface (handles both CLCK and DATA interfaces)
55 self.radio_if = radio_if
56
57 # Init CTRL interface
58 self.ctrl_if = CTRLInterfaceBB(self,
59 remote_addr, base_port + 101,
60 bind_addr, base_port + 1)
61
62 def start(self):
63 # Check execution state
64 if self.running:
65 print("[!] Transceiver is already started")
66 return False
67
68 # Make sure that Radio interface is ready, i.e.
69 # all parameters (e.g. RX / RX freq) are set.
70 if not self.radio_if.ready:
71 print("[!] RadioInterface is not ready")
72 return False
73
74 print("[i] Starting transceiver...")
75 self.radio_if.start()
76 self.running = True
77
78 return True
79
80 def stop(self):
81 # POWEROFF is also used to reset transceiver,
82 # so we should not complain that it isn't running.
83 if not self.running:
84 print("[i] Resetting transceiver")
85 self.radio_if.reset()
86 return
87
88 print("[i] Stopping transceiver...")
89
90 # TODO: flush all buffers between blocks
91 self.radio_if.stop()
92 self.radio_if.wait()
93
94 self.running = False
95
96 def measure(self, freq):
97 # TODO: transceiver should be in idle mode
98 return self.radio_if.measure(freq)