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

📄 rndstr.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/***************************************************************************              rndstr.c  -  SRadio module to output some random strings                            -------------------    begin                :  2002    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02-10-15 - ineiti- begin  **************************************************************************//*************************************************************************** *                                                                         * *   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 module outputs 4 strings sequentially, each time it is called. The * 4 outputted strings are configurable. */#include "spc.h"#define DBG_LVL 0typedef struct {  // The four strings to be outputted  char str[4][128]; // Rm 12/1, Pr ?/?, Pr 6/6, Pr 1/20}config_t;typedef struct {  // How many bytes have been sent  int bytes;  // How many strings have been sent  int strs;}stats_t;typedef struct {  int rnd;}private_t;/** * The initialisation part that is only called the first time this module * is instantiated. */int spc_init( swr_sdb_t *context ) {  stats_t *stats;  config_t *config;  MOD_INC_USE_COUNT;  swr_sdb_get_stats_struct( context->id, (void**)&stats );  swr_sdb_get_config_struct( context->id, (void**)&config );  stats->bytes = 0;  stats->strs = 0;  strncpy( config->str[0], "Ne vous conformez pas a l'Esprit de ce monde!", 128 );  strncpy( config->str[1], "Do not withhold good from those who deserve it, "           "when it is in your power to act.", 128 );  strncpy( config->str[2], "Go to the ant, you sluggard; "           "consider its ways and be wise!", 128 );  strncpy( config->str[3], "Does not wisdom call out? "           "Does not understanding raise her voice?", 128 );  size_out(0) = 0;  PR_DBG( 1, "Initialised source\n" );  context->private_data = swr_malloc( sizeof( private_t ) );  private->rnd = 0;  swr_sdb_free_config_struct( context->id, (void**)&config );  swr_sdb_free_stats_struct( context->id, (void**)&stats );  return 0;}/** * Every time somebody from the outside changes a configuration value, * this function is called just before the working-function */int spc_reconfig( swr_sdb_t *context ) {  return 0;}/** * The actual working function */int spc_pdata( swr_sdb_t *context ) {  config_t *config;  stats_t *stats;  U8 *out;  // Have some easy definitions  out = buffer_out( 0 );  // Output our string  swr_sdb_get_config_struct( context->id, (void**)&config );  strncpy( out, config->str[ private->rnd % 4 ], min( 128, port_out(0).size ) );  swr_sdb_free_config_struct( context->id, (void**)&config );  private->rnd++;  // Write to the output  context->port_out[0].data = out;  PR_DBG( 2, "Sent %i bytes: %s\n", size_out(0), out );  // Update the stats  swr_sdb_get_stats_struct( context->id, (void**)&stats );  stats->bytes += size_out(0);  stats->strs++;  swr_sdb_free_stats_struct( context->id, (void**)&stats );  return 0;}int spc_custom_msg(swr_sdb_t *context, swr_usr_msg_t* msg_data, swr_msgq ret ) {  spc_pdata( context );  return 0;}int spc_finalize( swr_sdb_t *context ) {  swr_free( private );  MOD_DEC_USE_COUNT;  return 0;}swr_spc_id_t spc_id;/** * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */int spc_module_init(void) {  swr_spc_desc_t *desc;  // Get a description-part from SPM  // Nbr_input_ports, Nbr_output_ports, Nbr_config_values, Nbr_stats_values  desc = swr_spc_get_new_desc( 0, 1, 4, 2 );  if ( !desc ) {    PR_DBG( 0, "Can't initialise the module. This is bad!\n" );    return -1;  }  // Define the different parts of config, stats and io-ports  UM_CONFIG_STRING128( "str0" );  UM_CONFIG_STRING128( "str1" );  UM_CONFIG_STRING128( "str2" );  UM_CONFIG_STRING128( "str3" );  UM_STATS_INT( "bytes" );  UM_STATS_INT( "strs" );  UM_OUTPUT( SIG_U8, 0 );  // Initialise the callback-functions. NULL for not-used functions  desc->fn_init = spc_init;  desc->fn_reconfigure = spc_reconfig;  desc->fn_process_data = spc_pdata;  desc->fn_custom_msg = spc_custom_msg;  desc->fn_finalize = spc_finalize;  // And register the module in the SPM  spc_id = swr_cdb_register_spc( &desc, "rndstr" );  if ( spc_id == SWR_SPM_INVALID_ID ) {    swr_spc_free_desc( desc );    PR_DBG( 0, "Couldn't register the module!\n" );    return 1;  }  PR_DBG( 1, "\"rndstr\" is ready\n" );  return 0;}void spc_module_exit( void ) {  if ( swr_cdb_unregister_spc( spc_id ) < 0 ) {    PR_DBG( 0, "Still in use somewhere\n" );  } else {    PR_DBG( 1, "rndstr is gone\n" );  }}module_init( spc_module_init );module_exit( spc_module_exit );

⌨️ 快捷键说明

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