⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 radio_bs.c

📁 软件无线电的平台
💻 C
字号:
/***************************************************************************               radio_bs.c  -  SRadio image bs                            -------------------    begin                :  02/10/30    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02/10/30 - ineiti - begin 02/11/04 - ineiti - no msgqs... 03/02/27 - ineiti - simplified to only two slots: BCH and RACH 03/03/19 - ineiti - added SCH and gain-control 03/10/01 - ineiti - added image-functionality, so that you can see something 04/03/17 - ineiti - inserted a convolutional chain 04/04/20 - ineiti - messed up an index. Copy'n paste...  **************************************************************************//*************************************************************************** *                                                                         * *   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.                                   * *                                                                         * ***************************************************************************//** * Make a simple BS * * Function: * - emit sync * - listen to RACh * - transmit images over different channels */#include "system.h"#include "sdb.h"#include "stfa.h"#include "antenna.h"#include "std.h"#include "debugging.h"#include "../image_radio.h"#include "chain.h"#include "spc.h"#define ANTENNA 0#define DBG_LVL 1#define TARGET_MOBILE_HERE 1000*1000#define IMG_CHAINS 4swr_sdb_id stfa, sch, mafi;struct chain_t *ch_bch, *ch_img[IMG_CHAINS];struct bch_struct bch_data;double gain;int looping, delay;/** * Once a frame this function is called. Do here whatever seems accurate... */int do_send_down( int msg, void *data, swr_sdb_id ret_id ) {#ifdef USER_SPACE  // Have some fun - move the BS. This is done 'automatically' in real-mode  //  swr_sdb_set_config_int( stfa, "offset_chips_rcv", delay++ );#endif  return 0;}void *start_it( void *arg ) {  swr_sdb_id mod, spread, ldpc, img[IMG_CHAINS], mapper, rrc_send;  int size, i;  looping = 1;  gain = 0.;  usleep( 100000 );  PR( "Init STFA\n" );  stfa = swr_sdb_instantiate_name( "stfa_ics" );  PR( "Initialized STFA\n" );  swr_sdb_set_config_int( stfa, "slots_per_frame", SLOTS );  swr_sdb_set_config_int( stfa, "blocks_per_slot", SLOT_LEN );  swr_sdb_set_config_int( stfa, "slot_send_offset", SLOT_OFFSET );  swr_sdb_set_config_int( stfa, "tx", 1 );  swr_sdb_set_config_int( stfa, "attn_tx", 0 );  PR( "Setting up BCh on slot 0\n" );  ch_bch = swr_chain_create(             NEW_SPC_VAR( "sch_send", sch ),             NEW_SPC_VAR( "mapper", mod ),             NEW_SPC( "spread" ),             NEW_SPC( "chest_send" ),             NEW_SPC( "synch_send" ),             NEW_SPC_VAR( "rrc_complex_send", rrc_send ),             OLD_SPC_IN( stfa, 0 ),             CHAIN_END );  swr_stfa_notice_sdb( stfa, 0, sch );  swr_sdb_set_config_int( sch, "id0", 0x1234 );  swr_sdb_set_config_int( sch, "uplinks0", 2 );  swr_sdb_set_config_double( sch, "target_snr0", 4 );  swr_sdb_set_config_int( rrc_send, "rrc_index", 1 );  PR( "Setting uplink in slot 1\n" );  PR( "Slot 1: uncoded transmission\n" );  ch_img[0] = swr_chain_create( NEW_SPC_VAR( "image_send", img[0] ),				NEW_SPC( "mapper" ),				NEW_SPC( "chest_send" ),				NEW_SPC( "rrc_complex_send" ),				OLD_SPC_IN( stfa, 1 ),				CHAIN_END );   swr_stfa_notice_sdb( stfa, 1, img[0] );  size = swr_sdb_get_stats_int( img[0], "size" );  PR( "Slot 3: spreaded transmission (repetition-code)\n" );  ch_img[1] = swr_chain_create( NEW_SPC_VAR( "image_send", img[1] ),				NEW_SPC( "mapper" ),				NEW_SPC_VAR( "spread", spread ),				NEW_SPC( "chest_send" ),				NEW_SPC( "rrc_complex_send" ),				OLD_SPC_IN( stfa, 3 ),				CHAIN_END );  swr_stfa_notice_sdb( stfa, 3, img[1] );  swr_sdb_set_config_int( spread, "factor", SPREADING );  size = min( swr_sdb_get_stats_int( img[1], "size" ), size );  PR( "Slot 5: convolutional encoding\n" );  ch_img[2] = swr_chain_create( NEW_SPC_VAR( "image_send", img[2] ),				NEW_SPC( "convolution_send" ),				NEW_SPC_VAR( "mapper", mapper ),				NEW_SPC( "chest_send" ),				NEW_SPC( "rrc_complex_send" ),				OLD_SPC_IN( stfa, 5 ),				CHAIN_END );  // We set up mapper as the stfa-notice-sdb, because else  // we're much too slow.  swr_stfa_notice_sdb( stfa, 5, img[2] );  size = min( swr_sdb_get_stats_int( img[2], "size" ), size );  PR( "Slot 7: ldpc coding\n" );  ch_img[3] = swr_chain_create( NEW_SPC_VAR( "image_send", img[3] ),				NEW_SPC_VAR( "ldpc_encode_siso_ics", ldpc ),				NEW_SPC_VAR( "mapper", mapper ),				NEW_SPC( "chest_send" ),				NEW_SPC( "rrc_complex_send" ),				OLD_SPC_IN( stfa, 7 ),				CHAIN_END );  // We set up mapper as the stfa-notice-sdb, because else  // we're much too slow.  swr_stfa_notice_sdb( stfa, 7, mapper );  swr_sdb_set_config_int( ldpc, "ldpc_code_id", LDPC_CODE );  size = min( swr_sdb_get_stats_int( img[3], "size" ), size );  for ( i=0; i<IMG_CHAINS; i++ ){    swr_sdb_set_config_int( img[i], "size", size );  }  // We call the img[3] only once, to initialise all data.  call_module( img[3] );   swr_stfa_notice_func( stfa, 2, do_send_down );  swr_stfa_go( stfa );    PR_DBG( 2, "Looping while nothing happens\n" );    while ( looping ) {    usleep( 10000 );  }  PR_DBG( 2, "About to stop stfa\n" );  swr_stfa_stop( stfa );  PR_DBG( 2, "STFA stopped\n" );  return 0;}struct thread start;/** * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */int um_module_init(void) {  int i;  MOD_INC_USE_COUNT;  looping = 1;  delay = 0;  ch_bch = NULL;  for ( i=0; i < IMG_CHAINS; i++ ){    ch_img[i] = NULL;  }  if ( swr_thread_init( &start, start_it, NULL ) ) {    goto rrc_no_thread;  }  MOD_DEC_USE_COUNT;  return 0;rrc_no_thread:  PR_DBG( 0, "Couldn't init thread\n" );  MOD_DEC_USE_COUNT;  return -1;}void um_module_exit( void ) {  int i;  looping = 0;  PR_DBG( 2, "Waiting for main to finish\n" );  swr_thread_free( &start, NULL );  PR_DBG( 3, "deleting everything\n" );  swr_chain_destroy( ch_bch );  for ( i=0; i <= IMG_CHAINS; i++ ){    PR_DBG( 3, "Deleting ch_img[%i]\n", i );    swr_chain_destroy( ch_img[i] );  }  // Ugh, ldpc_decoder is still decoding sometimes, and  // he wants to deliver data, so we have to wait before  // destroying stfa...  usleep( 100000 );  PR_DBG( 3, "Deleting stfa\n" );  swr_sdb_destroy( stfa );  PR_DBG( 1, "Finished\n" );}module_init( um_module_init );module_exit( um_module_exit );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -