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

📄 radio_ms.c

📁 软件无线电的平台
💻 C
字号:
/***************************************************************************               radio_ms.c  -  SRadio controller module                            -------------------    begin                :  02/10/30    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02/10/30 - ineiti - begin 03/01/09 - ineiti - clean up 03/02/27 - ineiti - simplified to only two slots 03/03/06 - ineiti - added synchronisation-macro 03/03/19 - ineiti - added SCH and gain-control 03/10/01 - ineiti - added image-transmission 04/03/17 - ineiti - inserted a convolutional-chain  **************************************************************************//*************************************************************************** *                                                                         * *   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 MS that connects to the BS. * * Function: * - listen to Synch * - find synch * - set up a channel for sending */#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 4#define IMG_CHAINS 4swr_sdb_id stfa, mafi, macro_synch, sch, synch_rcv;struct chain_t *ch_img[IMG_CHAINS], *ch_bch;enum st{ user_mode, synching, send_up, stop_stfa, done } state;int count, offset;struct bch_struct bch_data;int callback( int msg, void *data, swr_sdb_id ret_id );/** * This function is called once to clean up the synchronisation-macro, * set up the bch and up-channel, and to set the callback-function * as default. */int synchronised( int msg, void *data, swr_sdb_id ret_id ) {  swr_sdb_id img[IMG_CHAINS], spread, ldpc, mapper;  int size, i;  // Clean the synchronisation  swr_sdb_set_config_int( macro_synch, "synch", 0 );  // Initialise some values  count = 0;  state = send_up;  offset = swr_sdb_get_stats_int( macro_synch, "offset" );  synch_rcv = swr_sdb_get_stats_int( macro_synch, "synch_rcv" );  swr_stfa_notice_func( stfa, 0, callback );  // Listen to the bch  ch_bch = swr_chain_create(             OLD_SPC( synch_rcv ),             NEW_SPC_VAR( "matched_filter", mafi ),             NEW_SPC( "despread" ),             NEW_SPC( "slicer" ),             NEW_SPC_VAR( "sch_rcv", sch ),             CHAIN_END );  swr_sdb_set_config_int( sch, "antenna", 0 );  swr_sdb_set_config_int( sch, "id", 0x1234 );  swr_sdb_set_config_int( mafi, "gain_control", 15000 );  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( "midamble" ),				NEW_SPC( "rrc" ),				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( "midamble" ),				NEW_SPC( "rrc" ),				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( "midamble" ),				NEW_SPC( "rrc" ),				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", ldpc ),				NEW_SPC_VAR( "mapper", mapper ),				NEW_SPC( "midamble" ),				NEW_SPC( "rrc" ),				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] );  PR( "Ready to go" );  return 0;}/** * Once a frame this function is called. Do here whatever seems accurate... */void do_send_up( void ) {}/** * The first time this */int callback( int msg, void *data, swr_sdb_id ret_id ) {  count++;  switch( state ) {  case send_up:    do_send_up();    break;  case stop_stfa:    swr_stfa_stop( stfa );    state++;    break;  case done:    // WARNING: this is never reached...    PR( "Done...\n" );    break;  default:    break;  }  return 0;}void *start_it( void *arg ) {  int i;  PR( "getting sdbs\n" );  stfa = swr_sdb_instantiate_name( "stfa" );  // Initialise the STFA  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 );  PR( "Slots: %i, Length: %i\n", SLOTS, SLOT_LEN );  // Initialise our local vars  for ( i=0; i < IMG_CHAINS; i++ ){    ch_img[i] = NULL;  }  ch_bch = NULL;  // This sets up the synchronisation-macro  PR( "Setting up synchronisation\n" );  macro_synch = swr_sdb_instantiate_name( "macro_synch" );  swr_sdb_set_config_int( macro_synch, "stfa_id", stfa );  swr_sdb_set_config_int( macro_synch, "synch", 1 );  swr_sdb_set_config_pointer( macro_synch, "call_synched", synchronised );  PR( "Starting stfa\n" );  swr_stfa_go( stfa );  i = 0;  while ( state != done ) {    usleep( 1000000 );  }  swr_sdb_set_config_int( macro_synch, "synch", 0 );  swr_stfa_stop( stfa );  PR( "stfa stopped\n" );  return NULL;}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) {  state = synching;  if ( swr_thread_init( &start, start_it, NULL ) ) {    goto rrc_no_thread;  }  return 0;rrc_no_thread:  PR( "Couldn't init thread\n" );  return -1;}void um_module_exit( void ) {  int i;  state = done;  PR( "Waiting for thread to finish\n" );  swr_thread_free( &start, NULL );  PR( "Destroying uplink\n" );  for ( i=0; i<IMG_CHAINS; i++ ){    swr_chain_destroy( ch_img[i] );  }  PR( "Destroying bch\n" );  swr_chain_destroy( ch_bch );  PR( "Destroying macro_synch\n" );  swr_sdb_destroy( macro_synch );  PR( "Destroying stfa\n" );  swr_sdb_destroy( stfa );}module_init( um_module_init );module_exit( um_module_exit );

⌨️ 快捷键说明

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