2016-03-01 17:40:38 +00:00
/* A-Netz main
*
* ( C ) 2016 by Andreas Eversberg < jolly @ eversberg . eu >
* 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 3 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 , see < http : //www.gnu.org/licenses/>.
*/
# include <stdio.h>
# include <stdint.h>
# include <stdlib.h>
# include <string.h>
2018-05-19 08:56:43 +00:00
# include <errno.h>
2017-01-08 10:22:24 +00:00
# include <math.h>
2017-11-18 07:06:06 +00:00
# include "../libsample/sample.h"
2017-11-18 07:33:07 +00:00
# include "../libmobile/main_mobile.h"
2024-01-05 13:20:36 +00:00
# include "../liblogging/logging.h"
# include <osmocom/core/timer.h>
2017-11-18 07:33:07 +00:00
# include "../libmobile/call.h"
2018-05-19 08:56:43 +00:00
# include "../liboptions/options.h"
2018-11-10 14:16:20 +00:00
# include "../libfm/fm.h"
2017-11-16 17:37:25 +00:00
# include "freiton.h"
# include "besetztton.h"
2016-03-01 17:40:38 +00:00
# include "anetz.h"
# include "dsp.h"
2016-03-02 18:47:40 +00:00
# include "stations.h"
2016-03-01 17:40:38 +00:00
/* settings */
2017-10-30 07:00:47 +00:00
static char operator [ 32 ] = " 010 " ;
static double page_gain = 1 ;
static int page_sequence = 0 ;
static double squelch_db = - INFINITY ;
2016-03-01 17:40:38 +00:00
void print_help ( const char * arg0 )
{
2017-08-30 15:42:49 +00:00
main_mobile_print_help ( arg0 , " [-V 12] " ) ;
2016-03-01 17:40:38 +00:00
/* - - */
2017-10-30 07:00:47 +00:00
printf ( " -O --operator <number> \n " ) ;
printf ( " Give number to dial when mobile station initiated a call. A-Netz does \n " ) ;
printf ( " not support automatic dialing, so operator assistance is required. \n " ) ;
printf ( " By default, the operator '%s' is dialed. \n " , operator ) ;
2016-11-27 05:47:06 +00:00
printf ( " -G --geo <lat>,<lon> \n " ) ;
2016-03-02 18:47:40 +00:00
printf ( " Give your coordinates of your location, to find closest base station. \n " ) ;
printf ( " (e.g. '--geo 51.186959,7.080194') Or use '--geo list' to get a list of \n " ) ;
printf ( " all base station locations. \n " ) ;
2017-01-08 10:22:24 +00:00
printf ( " -V --page-gain <dB> \n " ) ;
printf ( " Raise the gain of paging tones to compensate loss due to pre-emphasis \n " ) ;
printf ( " of the transmitter. (If you can't disable it.) \n " ) ;
2016-03-01 17:40:38 +00:00
printf ( " -P --page-sequence 0 | <ms> \n " ) ;
2016-11-29 06:50:32 +00:00
printf ( " Cycle paging tones, rather than sending simultaniously. Try 100. \n " ) ;
2016-03-01 17:40:38 +00:00
printf ( " (default = '%d') \n " , page_sequence ) ;
2017-10-09 18:49:14 +00:00
printf ( " -S --squelch <dB> | auto \n " ) ;
printf ( " Use given RF level to detect loss of signal. When the signal gets lost \n " ) ;
printf ( " and stays below this level, the connection is released. \n " ) ;
printf ( " Use 'auto' to do automatic noise floor calibration to detect loss. \n " ) ;
printf ( " Only works with SDR! (disabled by default) \n " ) ;
2021-10-07 17:35:56 +00:00
main_mobile_print_station_id ( ) ;
2017-08-30 15:42:49 +00:00
main_mobile_print_hotkeys ( ) ;
2016-03-01 17:40:38 +00:00
}
2018-05-19 08:56:43 +00:00
static void add_options ( void )
{
main_mobile_add_options ( ) ;
option_add ( ' O ' , " operator " , 1 ) ;
option_add ( ' G ' , " geo " , 1 ) ;
option_add ( ' V ' , " page-gain " , 1 ) ;
option_add ( ' P ' , " page-sequence " , 1 ) ;
option_add ( ' S ' , " squelch " , 1 ) ;
}
static int handle_options ( int short_option , int argi , char * * argv )
2016-03-01 17:40:38 +00:00
{
2016-03-02 18:47:40 +00:00
char * p ;
2017-01-08 10:22:24 +00:00
double gain_db ;
2016-03-01 17:40:38 +00:00
2018-05-19 08:56:43 +00:00
switch ( short_option ) {
case ' O ' :
strncpy ( operator , argv [ argi ] , sizeof ( operator ) - 1 ) ;
operator [ sizeof ( operator ) - 1 ] = ' \0 ' ;
break ;
case ' G ' :
if ( ! strcasecmp ( argv [ argi ] , " list " ) ) {
station_list ( ) ;
return 0 ;
}
if ( ( p = strchr ( argv [ argi ] , ' , ' ) ) ) {
get_station_by_coordinates ( atof ( argv [ argi ] ) , atof ( p + 1 ) ) ;
return 0 ;
2016-03-01 17:40:38 +00:00
}
2018-05-19 08:56:43 +00:00
fprintf ( stderr , " Invalid geo parameter \n " ) ;
return - EINVAL ;
case ' V ' :
gain_db = atof ( argv [ argi ] ) ;
page_gain = pow ( 10 , gain_db / 20.0 ) ;
break ;
case ' P ' :
page_sequence = atoi ( argv [ argi ] ) ;
break ;
case ' S ' :
if ( ! strcasecmp ( argv [ argi ] , " auto " ) )
squelch_db = 0.0 ;
else
squelch_db = atof ( argv [ argi ] ) ;
break ;
default :
return main_mobile_handle_options ( short_option , argi , argv ) ;
2016-03-01 17:40:38 +00:00
}
2018-05-19 08:56:43 +00:00
return 1 ;
2016-03-01 17:40:38 +00:00
}
2021-10-07 17:35:56 +00:00
static const struct number_lengths number_lengths [ ] = {
{ 5 , " number without channel prefix " } ,
{ 7 , " number with channel prefix " } ,
{ 0 , NULL }
} ;
2016-03-01 17:40:38 +00:00
int main ( int argc , char * argv [ ] )
{
2018-05-19 08:56:43 +00:00
int rc , argi ;
2016-03-01 17:40:38 +00:00
const char * station_id = " " ;
2016-04-25 18:20:54 +00:00
int i ;
2016-03-01 17:40:38 +00:00
2017-01-02 09:16:49 +00:00
/* a-netz does not use emphasis, so disable it */
uses_emphasis = 0 ;
2016-03-11 05:59:05 +00:00
/* init common tones */
init_freiton ( ) ;
init_besetzton ( ) ;
2021-10-07 17:35:56 +00:00
main_mobile_init ( " 0123456789 " , number_lengths , NULL , anetz_number_valid ) ;
2017-08-30 15:42:49 +00:00
2018-05-19 08:56:43 +00:00
/* handle options / config file */
add_options ( ) ;
2021-03-11 06:38:00 +00:00
rc = options_config_file ( argc , argv , " ~/.osmocom/analog/anetz.conf " , handle_options ) ;
2018-05-19 08:56:43 +00:00
if ( rc < 0 )
return 0 ;
argi = options_command_line ( argc , argv , handle_options ) ;
if ( argi < = 0 )
return argi ;
2016-03-01 17:40:38 +00:00
2018-05-19 08:56:43 +00:00
if ( argi < argc ) {
station_id = argv [ argi ] ;
2021-10-07 17:35:56 +00:00
rc = main_mobile_number_ask ( station_id , " station ID " ) ;
if ( rc )
return rc ;
2016-03-01 17:40:38 +00:00
}
2016-04-25 18:20:54 +00:00
if ( ! num_kanal ) {
2016-03-01 17:40:38 +00:00
printf ( " No channel ( \" Kanal \" ) is specified, I suggest channel 30. \n \n " ) ;
2018-05-19 08:56:43 +00:00
print_help ( argv [ 0 ] ) ;
2016-03-01 17:40:38 +00:00
return 0 ;
}
2017-05-14 10:27:56 +00:00
if ( use_sdr ) {
2021-09-18 09:43:01 +00:00
/* set device */
2017-05-14 10:27:56 +00:00
for ( i = 0 ; i < num_kanal ; i + + )
2021-09-18 09:43:01 +00:00
dsp_device [ i ] = " sdr " ;
num_device = num_kanal ;
2017-05-14 10:27:56 +00:00
}
2021-09-18 09:43:01 +00:00
if ( num_kanal = = 1 & & num_device = = 0 )
num_device = 1 ; /* use default */
if ( num_kanal ! = num_device ) {
2016-11-28 08:16:48 +00:00
fprintf ( stderr , " You need to specify as many sound devices as you have channels. \n " ) ;
2016-04-25 18:20:54 +00:00
exit ( 0 ) ;
}
2016-03-01 17:40:38 +00:00
2018-11-10 14:16:20 +00:00
/* inits */
fm_init ( fast_math ) ;
2016-03-01 17:40:38 +00:00
dsp_init ( ) ;
anetz_init ( ) ;
/* create transceiver instance */
2016-04-25 18:20:54 +00:00
for ( i = 0 ; i < num_kanal ; i + + ) {
2021-09-18 09:43:01 +00:00
rc = anetz_create ( kanal [ i ] , dsp_device [ i ] , use_sdr , dsp_samplerate , rx_gain , tx_gain , page_gain , page_sequence , do_pre_emphasis , do_de_emphasis , write_rx_wave , write_tx_wave , read_rx_wave , read_tx_wave , loopback , squelch_db , operator ) ;
2016-04-25 18:20:54 +00:00
if ( rc < 0 ) {
fprintf ( stderr , " Failed to create \" Sender \" instance. Quitting! \n " ) ;
goto fail ;
}
2019-07-20 16:11:17 +00:00
printf ( " Base station on channel %s ready, please tune transmitter to %.3f MHz and receiver to %.3f MHz. (%.3f MHz offset) \n " , kanal [ i ] , anetz_kanal2freq ( atoi ( kanal [ i ] ) , 0 ) / 1e6 , anetz_kanal2freq ( atoi ( kanal [ i ] ) , 1 ) / 1e6 , anetz_kanal2freq ( atoi ( kanal [ i ] ) , 2 ) / 1e6 ) ;
2016-03-01 17:40:38 +00:00
}
2021-10-07 17:35:56 +00:00
main_mobile_loop ( " anetz " , & quit , NULL , station_id ) ;
2016-03-01 17:40:38 +00:00
fail :
/* destroy transceiver instance */
while ( sender_head )
anetz_destroy ( sender_head ) ;
2018-11-10 14:16:20 +00:00
/* exits */
2024-01-05 13:20:36 +00:00
main_mobile_exit ( ) ;
2018-11-10 14:16:20 +00:00
fm_exit ( ) ;
2021-01-25 14:16:29 +00:00
options_free ( ) ;
2016-03-01 17:40:38 +00:00
return 0 ;
}