Skip to content

Commit

Permalink
Merge branch 'ptrkrysik/trx' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrkrysik committed Apr 16, 2018
2 parents 8b9b88d + fe4db93 commit 8a8d41a
Show file tree
Hide file tree
Showing 89 changed files with 4,574 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build
*.pyc
*.pyo
.unittests
build/
build*/
debian/tmp/
debian/files
.directory
1 change: 1 addition & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ GR_PYTHON_INSTALL(
${CMAKE_CURRENT_BINARY_DIR}/grgsm_livemon_headless
grgsm_scanner
grgsm_decode
grgsm_trx
DESTINATION bin
)

Expand Down
165 changes: 165 additions & 0 deletions apps/grgsm_trx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

# GR-GSM based transceiver
#
# (C) 2016-2017 by Vadim Yanitskiy <[email protected]>
#
# All Rights Reserved
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import signal
import getopt
import sys

from grgsm.trx import ctrl_if_bb
from grgsm.trx import radio_if
from grgsm.trx import fake_pm

COPYRIGHT = \
"Copyright (C) 2016-2017 by Vadim Yanitskiy <[email protected]>\n" \
"License GPLv2+: GNU GPL version 2 or later " \
"<http://gnu.org/licenses/gpl.html>\n" \
"This is free software: you are free to change and redistribute it.\n" \
"There is NO WARRANTY, to the extent permitted by law.\n"

class Application:
# Application variables
remote_addr = "127.0.0.1"
base_port = 5700

# PHY specific
phy_sample_rate = 4*1625000/6
phy_tx_antenna = "TX/RX"
phy_rx_antenna = "RX2"
phy_rx_gain = 30
phy_tx_gain = 40
phy_args = ""
phy_ppm = 0

def __init__(self):
self.print_copyright()
self.parse_argv()

# Set up signal handlers
signal.signal(signal.SIGINT, self.sig_handler)

def run(self):
# Init Radio interface
self.radio = radio_if(self.phy_args, self.phy_sample_rate,
self.phy_rx_gain, self.phy_tx_gain, self.phy_ppm,
self.phy_rx_antenna, self.phy_tx_antenna,
self.remote_addr, self.base_port)

# Power measurement emulation
# Noise: -120 .. -105
# BTS: -75 .. -50
self.pm = fake_pm(-120, -105, -75, -50)

# Init TRX CTRL interface
self.server = ctrl_if_bb(self.remote_addr,
self.base_port + 101, self.base_port + 1,
self.radio, self.pm)

print("[i] Init complete")

# Enter main loop
while True:
self.server.loop()

def shutdown(self):
print("[i] Shutting down...")
self.server.shutdown()
self.radio.shutdown()

def print_copyright(self):
print(COPYRIGHT)

def print_help(self):
s = " Usage: " + sys.argv[0] + " [options]\n\n" \
" Some help...\n" \
" -h --help this text\n\n"

# TRX specific
s += " TRX interface specific\n" \
" -i --remote-addr Set remote address (default 127.0.0.1)\n" \
" -p --base-port Set base port number (default 5700)\n\n"

# PHY specific
s += " Radio interface specific\n" \
" -a --device-args Set device arguments\n" \
" -s --sample-rate Set sample rate (default 2000000)\n" \
" -g --rx-gain Set RX gain (default 30)\n" \
" -G --tx-gain Set TX gain (default 10)\n" \
" --rx-antenna Set RX antenna (default RX2)\n" \
" --tx-antenna Set TX antenna (default TX/RX)\n" \
" --ppm Set frequency correction (default 0)\n"

print(s)

def parse_argv(self):
try:
opts, args = getopt.getopt(sys.argv[1:],
"i:p:a:s:g:G:h",
["help", "remote-addr=", "base-port=", "device-args=",
"sample-rate=", "rx-gain=", "tx-gain=", "ppm=",
"rx-antenna=", "tx-antenna="])
except getopt.GetoptError as err:
# Print(help and exit)
self.print_help()
print("[!] " + str(err))
sys.exit(2)

for o, v in opts:
if o in ("-h", "--help"):
self.print_help()
sys.exit(2)

# TRX specific
elif o in ("-i", "--remote-addr"):
self.remote_addr = v
elif o in ("-p", "--base-port"):
if int(v) >= 0 and int(v) <= 65535:
self.base_port = int(v)
else:
print("[!] The port number should be in range [0-65536]")
sys.exit(2)

# PHY specific
elif o in ("-a", "--device-args"):
self.phy_args = v
elif o in ("-s", "--sample-rate"):
self.phy_sample_rate = int(v)
elif o in ("-g", "--rx-gain"):
self.phy_rx_gain = int(v)
elif o in ("-G", "--tx-gain"):
self.phy_tx_gain = int(v)
elif o in ("--rx-antenna"):
self.phy_rx_antenna = v
elif o in ("--tx-antenna"):
self.phy_tx_antenna = v
elif o in ("--ppm"):
self.phy_ppm = int(v)

def sig_handler(self, signum, frame):
print("Signal %d received" % signum)
if signum is signal.SIGINT:
self.shutdown()
sys.exit(0)

if __name__ == '__main__':
app = Application()
app.run()
1 change: 1 addition & 0 deletions grc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_subdirectory(demapping)
add_subdirectory(receiver)
add_subdirectory(flow_control)
add_subdirectory(misc_utils)
add_subdirectory(transmitter)
install(FILES
gsm_block_tree.xml DESTINATION share/gnuradio/grc/blocks
)
1 change: 1 addition & 0 deletions grc/flow_control/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ install(FILES
gsm_burst_timeslot_splitter.xml
gsm_burst_fnr_filter.xml
gsm_burst_timeslot_filter.xml
gsm_burst_type_filter.xml
gsm_dummy_burst_filter.xml
gsm_burst_sdcch_subslot_splitter.xml
gsm_burst_sdcch_subslot_filter.xml
Expand Down
32 changes: 32 additions & 0 deletions grc/flow_control/gsm_burst_type_filter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<block>
<name>Burst Type Filter</name>
<key>gsm_burst_type_filter</key>
<import>import grgsm</import>
<make>grgsm.burst_type_filter($selected_burst_types)</make>

<param>
<name>Selected burst types</name>
<key>selected_burst_types</key>
<value>[0,1,2,3,4,5,6,7]</value>
<type>int_vector</type>
</param>

<sink>
<name>bursts_in</name>
<type>message</type>
<optional>1</optional>
</sink>

<source>
<name>bursts_out</name>
<type>message</type>
<optional>1</optional>
</source>

<doc>
This block filters bursts based on their type.

For more information on burst types, see GSM 05.02.
</doc>
</block>
11 changes: 11 additions & 0 deletions grc/gsm_block_tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
<block>gsm_clock_offset_control</block>
<block>gsm_input</block>
</cat>
<cat>
<name>Transmitter</name>
<block>gsm_txtime_bursts_tagger</block>
<block>gsm_txtime_setter</block>
<block>gsm_gmsk_mod</block>
<block>gsm_preprocess_tx_burst</block>
<block>gsm_gen_test_ab</block>
</cat>
<cat>
<name>Logical channels demapping</name>
<block>gsm_universal_ctrl_chans_demapper</block>
Expand All @@ -45,6 +53,7 @@
<block>gsm_burst_timeslot_filter</block>
<block>gsm_burst_sdcch_subslot_filter</block>
<block>gsm_burst_fnr_filter</block>
<block>gsm_burst_type_filter</block>
<block>gsm_dummy_burst_filter</block>
<block>gsm_uplink_downlink_splitter</block>
</cat>
Expand All @@ -66,6 +75,8 @@
<block>gsm_clock_offset_corrector_tagged</block>
<block>gsm_msg_to_tag.xml</block>
<block>gsm_tmsi_dumper</block>
<block>gsm_trx_burst_if</block>
<block>gsm_burst_to_fn_time</block>
</cat>
</cat>
</cat>
5 changes: 4 additions & 1 deletion grc/misc_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ install(FILES
gsm_burst_file_source.xml
gsm_message_file_sink.xml
gsm_message_file_source.xml
gsm_trx_burst_if.xml
gsm_msg_to_tag.xml
gsm_controlled_fractional_resampler_cc.xml DESTINATION share/gnuradio/grc/blocks
gsm_controlled_fractional_resampler_cc.xml
gsm_burst_to_fn_time.xml
DESTINATION share/gnuradio/grc/blocks
)
19 changes: 19 additions & 0 deletions grc/misc_utils/gsm_burst_to_fn_time.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<block>
<name>Burst to fn_time</name>
<key>gsm_burst_to_fn_time</key>
<import>import grgsm</import>
<make>grgsm.burst_to_fn_time()</make>

<sink>
<name>bursts_in</name>
<type>message</type>
<optional>1</optional>
</sink>

<source>
<name>fn_time_out</name>
<type>message</type>
<optional>1</optional>
</source>
</block>
58 changes: 58 additions & 0 deletions grc/misc_utils/gsm_trx_burst_if.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0"?>
<block>
<name>TRX Burst Interface</name>
<key>gsm_trx_burst_if</key>
<import>import grgsm</import>
<make>grgsm.trx_burst_if($remote_addr, $base_port)</make>

<param>
<name>base_port</name>
<key>base_port</key>
<value>5700</value>
<type>string</type>
</param>

<param>
<name>remote_addr</name>
<key>remote_addr</key>
<value>127.0.0.1</value>
<type>string</type>
</param>

<sink>
<name>bursts</name>
<type>message</type>
<optional>1</optional>
</sink>

<source>
<name>bursts</name>
<type>message</type>
<optional>1</optional>
</source>

<doc>
OsmoTRX like UDP burst interface for external applications.

There are two UDP connections, where each message carries
one radio burst with header. Give a base port B (5700 by default).
One connection at port P=B+100+2 is used for sending received bursts
to an external application. Another one at port P=B+2 is used to
obtain to be transmitted bursts.

Received burst format:
1 byte timeslot index
4 bytes GSM frame number, big endian
1 byte RSSI in -dBm
2 bytes correlator timing offset in 1/256 symbol steps,
2's-comp, big endian
148 bytes soft symbol estimates, 0 -&gt; definite "0",
255 -&gt; definite "1"

To be transmitted burst format:
1 byte timeslot index
4 bytes GSM frame number, big endian
1 byte transmit level wrt ARFCN max, -dB (attenuation)
148 bytes output symbol values, 0 &amp; 1
</doc>
</block>
27 changes: 27 additions & 0 deletions grc/transmitter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2011,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.

install(FILES
gsm_gmsk_mod.xml
gsm_txtime_bursts_tagger.xml
gsm_txtime_setter.xml
gsm_preprocess_tx_burst.xml
gsm_gen_test_ab.xml
DESTINATION share/gnuradio/grc/blocks
)
Loading

0 comments on commit 8a8d41a

Please sign in to comment.