示例#1
0
/**@ingroup gen_mux
 *
 */
int work(void **inp, void **out) {
	int i;
	int out_len;
	int nof_active_inputs;

	nof_active_inputs = 0;
	for (i=0;i<nof_inputs;i++) {
		input_lengths[i] = get_input_samples(i);
		nof_active_inputs++;
	}

	if (exclusive && nof_active_inputs>1) {
		moderror_msg("Exclusive mux but %d inputs have data\n",nof_active_inputs);
		return -1;
	}
	if(check_all && (nof_active_inputs<nof_inputs)) {
		moderror_msg("Only %d/%d inputs have data\n",nof_active_inputs,nof_inputs);
		return -1;
	}
	if (!out[0]) {
		moderror("Output not ready\n");
		return -1;
	}
	out_len = sum_i(input_lengths,nof_inputs);
	if (out_len) {
		mux(inp,out[0],input_lengths,input_padding_pre,nof_inputs,input_sample_sz);
	}
	return out_len;
}
示例#2
0
/** @ingroup gen_convcoderr
 * \param padding (Optional) Default 0. Number of zero bits to add to the output after encoding the data.
 * \param constraint_length
 * \param tail_bit 1 for tail-bitting, 0 for none
 * \param rate
 * \param generator_i polynomy of the i-th generator
 */
int initialize() {
	int i;
	char tmp[64];

	padding_id = param_id("padding");
	if (!padding_id) {
		padding = 0;
		moddebug("Parameter padding not configured. Setting to %d\n",padding);
	}
	if (param_get_int_name("constraint_length",&constraint_length)) {
		moderror("Parameter constraint_length not specified\n");
		return -1;
	}
	if (param_get_int_name("tail_bit",&tail_bit)) {
		moderror("Parameter tail_bit not specified\n");
		return -1;
	}
	if (param_get_int_name("rate",&rate)) {
		moderror("Parameter rate not specified\n");
		return -1;
	}
	if (rate<0 || rate > MAX_RATE) {
		moderror_msg("Invalid rate %d\n",rate);
		return -1;
	}
	for (i=0;i<rate;i++) {
		snprintf(tmp,64,"generator_%d",i);
		if (param_get_int_name(tmp,&g[i])) {
			moderror_msg("Parameter %s not specified\n",tmp);
			return -1;
		}
	}

	return 0;
}
示例#3
0
文件: gen_mux.c 项目: a4a881d4/aloe
int initialize() {
	sample_t d_type;

	if (param_get_int_name("data_type",&data_type)) {
		moderror("Error getting parameter data_type\n");
		return -1;
	}

	if (type_param_2_type(data_type,&d_type)) {
		moderror_msg("Invalid data_type parameter %d\n",data_type);
		return -1;
	}
	input_sample_sz = type_size(d_type);
	output_sample_sz = input_sample_sz;

	if (param_get_int_name("nof_inputs",&nof_inputs)) {
		moderror("Error getting parameter nof_inputs\n");
		return -1;
	}
	nof_input_itf = nof_inputs;
	if (nof_inputs > NOF_INPUT_ITF) {
		moderror_msg("Only %d interfaces are supported. nof_inputs=%d\n",NOF_INPUT_ITF,nof_inputs);
		return -1;
	}
	memset(input_padding_pre,0,sizeof(int)*nof_inputs);
	return 0;
}
示例#4
0
/**
 * @ingroup dac_sink
 *
 *  Writes the received samples to the dac output buffer
 *
 */
int work(void **inp, void **out) {
	int rcv_samples;
	int n;

	rcv_samples = get_input_samples(0);
	if (!rcv_samples) {
		return 0;
	}
	if (check_blen && check_blen != rcv_samples) {
		moderror_msg("Expected %d samples but got %d\n", check_blen, rcv_samples);
		return -1;
	}
	if (process_params()) {
		return -1;
	}
	vec_mult_c_r((complex_t*) inp[0],out_buffer,amplitude,rcv_samples);
	if (enable_dac) {
		n = rtdal_dac_send(dac,out_buffer,rcv_samples,blocking);
	} else {
		n = rcv_samples;
	}
	modinfo_msg("send %d samples amplitude %g\n",n,amplitude);
	if (n != rcv_samples) {
		moderror_msg("Sent %d/%d samples\n",n,rcv_samples);
		return -1;
	}

	return 0;
}
示例#5
0
int process_ctrl_packets(void *ctx) {
	int n, nof_packets;
	int i;

	do {
		moddebug("receiving control\n",0);
		n = oesr_itf_read(ctrl_in, ctrl_in_buffer,
				sizeof(struct ctrl_in_pkt)*MAX_INPUT_PACKETS,oesr_tstamp(ctx));
		if (n == -1) {
			oesr_perror("oesr_itf_read");
			return -1;
		} else if (n>0) {
			if (n % sizeof(struct ctrl_in_pkt)) {
				moderror_msg("Received %d bytes but packet size is %d\n", n,
						sizeof(struct ctrl_in_pkt));
			}
			nof_packets = n / sizeof(struct ctrl_in_pkt);
			for (i=0;i<nof_packets;i++) {
				if (process_ctrl_packet(ctx, &ctrl_in_buffer[i])) {
					moderror_msg("Error processing control packet %d/%d\n",i,nof_packets);
					return -1;
				}
			}
		}
	} while(n>0);
	return 0;
}
示例#6
0
文件: source.c 项目: alring/aloe
int work(void **inp, void **out) {
	int block_length, type;
	int i,j;
	int snd_samples;

	period_cnt++;
	if (period_cnt>=period) {
		period_cnt=0;
	}
	if (period_cnt) {
		return 0;
	}

	block_length = 0;
	if (param_get_int(blen_id,&block_length) != 1) {
		moderror("Getting integer parameter block_length\n");
		return -1;
	}
	type = 0;
	if (param_get_int(gen_id,&type) != 1) {
		moderror("Getting integer parameter type\n");
		return -1;
	}

	for(i=0;i<NOF_GENERATORS;i++) {
		if (generators[i].key == type) {
			break;
		}
	}
	if (i == NOF_GENERATORS) {
		moderror_msg("Generator type %d not implemented\n", type);
		return -1;
	}
	if (type != last_type) {
		moddebug("Select generator: %s\n",generators[i].desc);
		last_type = type;
	}

	if (block_length > OUTPUT_MAX_SAMPLES/generators[i].samp_sz) {
		moderror_msg("block_length %d too large. Maximum is %d for this generator\n",block_length,
				OUTPUT_MAX_SAMPLES/generators[i].samp_sz);
		return -1;
	}

#ifdef _COMPILE_ALOE
	if (block_length != last_block_length) {
		moddebug("Select block_length: block_length=%d at tslot=%d\n",block_length,oesr_tstamp(ctx));
		last_block_length = block_length;
	}
#endif

	snd_samples = generators[i].work(out[0],block_length);

#ifdef _COMPILE_ALOE
	moddebug("Sent %d samples at ts=%d\n",snd_samples,oesr_tstamp(ctx));
#endif
	return snd_samples;
}
示例#7
0
/**
 * @ingroup lte_cfi_coding
 * Main DSP function
 * Encodes the control format indicator (CFI)
 *
 * @return On success, returns a non-negative number indicating the output
 * samples that should be transmitted through all output interface. To specify a different length
 * for certain interface, use the function set_output_samples(int idx, int len)
 * On error returns -1.
 *
 */
int work(void **inp, void **out) {
	int i;
	int rcv_samples, snd_samples;
	input_t *input;
	output_t *output;

	input = inp[0];
	output = out[0];
	rcv_samples = get_input_samples(0);
	snd_samples = NOF_BITS;

	if ((input[0] > 0) && (input[0] < 5)) {
		memcpy(output, &table[input[0]-1], NOF_BITS);
	} else {
		moderror_msg("Wrong cfi %d. Specify 1, 2, 3, or 4 (4 reserved)."
		  "\n", input[0]);
		return -1;
	}

/*	printf("\n\n");
	for (i=0; i<snd_samples; i++) {
		printf("%d",output[i]);
	}
	printf("\n\n %d  %d  %d", table, &table[input[0]-1], &table[input[0]-1][0]);
*/
	return snd_samples;
}
示例#8
0
/**
 * @ingroup Lte Rate Matching of convolutionally encoded information
 * Applied for PDCCH
 * Initialization function
 *
 * \param direction Transmitter mode if 0 and receiver mode otherwise
 * \param E Number of output bits of rate matching in transmitter mode
 * \param S Number of output bits of rate matching in receiver mode
 *
 * \returns This function returns 0 on success or -1 on error
 */
int initialize() {

	if (param_get_int_name("direction", &direction)) {
		moderror_msg("Parameter 'direction' not specified. Assuming "
		  "transmission mode (%d).\n", 0);
		direction = 0;
	}
	if (direction) {
		/* Reception mode */
		S_id = param_id("S");
		if (!S_id) {
			moderror("Parameter S not found\n");
			return -1;
		}

		input_sample_sz=sizeof(float);
		output_sample_sz=sizeof(float);
	} else {
		/* Transmission mode */
		E_id = param_id("E");
		if (!E_id) {
			moderror("Parameter E not found\n");
			return -1;
		}
		input_sample_sz=sizeof(char);
		output_sample_sz=sizeof(char);
	}
	return 0;
}
示例#9
0
/**@ingroup gen_remcyclic
 *
 * \param dft_size Size of the OFDM symbol (in samples). This parameter is mandatory.
 * \param cyclic_prefix_sz Size of the cyclic prefix to add to each received symbol (in samples)
 * This parameter is mandatory.
 * \param first_cyclic_prefix_sz Size of the cyclic prefix to add to the first received symbol
 * (in samples). Optional parameter, default is cyclic_prefix_sz
 */
int initialize() {

	dft_size_id = param_id("dft_size");
	if (!dft_size_id) {
		/*moderror("Parameter dft_size undefined\n");
		return -1;*/
		modinfo("Parameter dft_size not defined. Assuming "
		"dft_size = number of input samples on interface 0 - cyclic_prefix_sz.\n");
	}

	cyclic_prefix_sz_id = param_id("cyclic_prefix_sz");
	if (!cyclic_prefix_sz_id) {
		moderror("Parameter cyclic_prefix_sz undefined\n");
		return -1;
	}

	first_cyclic_prefix_sz_id = param_id("first_cyclic_prefix_sz");

	if (NOF_INPUT_ITF != NOF_OUTPUT_ITF) {
		moderror_msg("Fatal error, the number of input interfaces (%d) must be equal to the "
				"number of output interfaces (%d)\n",NOF_INPUT_ITF,NOF_OUTPUT_ITF);
		return -1;
	}

	return 0;
}
示例#10
0
int scan_remote_itf(void *ctx, int nof_variables) {
	int i,j,k;
	for (i=0;i<MAX_OUTPUTS;i++) {
		outputs[i].module_idx = -1;
	}
	for (i=0;i<nof_variables;i++) {
		k=-1;
		for (j=0;j<MAX_OUTPUTS;j++) {
			if (outputs[j].module_idx == remote_variables[i].module_idx) {
				break;
			} else if (outputs[j].module_idx == -1 && k==-1) {
				k = j;
			}
		}
		if (j==MAX_OUTPUTS) {
			if (k==-1) {
				moderror_msg("Not enough output interfaces. Increase MAX_OUTPUTS (%d) "
									"in oesr/src/ctrl_skeleton.c\n",j);
				return -1;
			} else {
				j=k;
			}
		}
		remote_variables[i].addr = &outputs[j];
		outputs[j].module_idx = remote_variables[i].module_idx;
	}
	k=0;
	for (j=0;j<MAX_OUTPUTS;j++) {
		if (outputs[j].module_idx!=-1) {
			k++;
		}
	}
	return k;
}
示例#11
0
/**@ingroup gen_demux
 *
 */
int work(void **inp, void **out) {
	int i;
	int rcv_len, out_len;

	rcv_len=get_input_samples(0);
	moddebug("%d samples recevied.\n",rcv_len);
	if (!rcv_len)
		return 0;

	modinfo_msg("received %d bytes\n",rcv_len);
	if ((rcv_len - sum_special_output_lengths) % (nof_outputs-nof_special_outputs)) {
/*		moderror_msg("Received length %d is not multiple of the number of output interfaces %d\n",
				rcv_len,nof_outputs);
*/		return 0;
	}

	out_len = (rcv_len - sum_special_output_lengths) / (nof_outputs-nof_special_outputs);
	for (i=0;i<nof_outputs;i++) {
		if (special_output_length[i]) {
			output_lengths[i] = special_output_length[i];
		} else {
			output_lengths[i] = out_len;
		}
		set_output_samples(i,output_lengths[i]);
		if (!out[i]) {
			moderror_msg("output itf %d not ready\n",out[i]);
			return -1;
		}
	}

	demux(inp[0],out,output_lengths,output_padding_pre,
			output_padding_post,nof_outputs,input_sample_sz);

	return 0;
}
示例#12
0
/**
 * @ingroup dac_source
 *
 *  Writes the received samples to the dac output buffer
 *
 */
int work(void **inp, void **out) {
	int n;

	if (!stream_started) {
		rtdal_dac_start_rx_stream(dac);
		stream_started=1;
	}
	if (process_params()) {
		return -1;
	}
	if (!nsamples) {
		return 0;
	}
	if (!out[0]) {
		moderror("Output interface not ready\n");
		return -1;
	}
	if (cnt<wait_packets) {
		cnt++;
		modinfo_msg("not receiving ts=%d\n",oesr_tstamp(ctx));
		return 0;
	}
	n = rtdal_dac_recv(dac,out[0],nsamples,blocking);
	modinfo_msg("ts=%d, recv %d samples\n",oesr_tstamp(ctx),n);
	if (n != nsamples) {
		moderror_msg("Recv %d/%d samples\n",n,nsamples);
		return -1;
	}

	return nsamples;
}
示例#13
0
int init_remote_itf(void *ctx, int nof_itf) {
	int i,j;
	int port,delay;
	char tmp[64];

	for (i=0;i<nof_itf;i++) {
		port = outputs[i].module_idx-oesr_module_id(ctx)+nof_output_data_itf;
		if (port < 0) {
			moderror_msg("Can't sent to a module back in the chain (module_idx=%d)\n",outputs[i].module_idx);
			return -1;
		}

		/* check if a parameter sets a different delay */
		for (j=0;j<nof_remote_variables;j++) {
			if (remote_variables[j].module_idx == outputs[i].module_idx) {
				break;
			}
		}
		if (j < nof_remote_variables) {
			snprintf(tmp,64,"delay_%s",remote_params_db[j].module_name);
			if (!param_get_int_name(tmp,&delay)) {
				moddebug("Setting a delay of %d slots to port %d, module %s\n",delay,port,
					remote_params_db[j].module_name);
				if (oesr_itf_delay_set(ctx,port,ITF_WRITE,delay)) {
					moderror_msg("Setting delay to port %d\n",port);
					return -1;
				}
			}
		}

		/* now create the variable */
		outputs[i].itf = oesr_itf_create(ctx, port,
				ITF_WRITE, sizeof(struct ctrl_in_pkt));
		if (outputs[i].itf == NULL) {
			if (oesr_error_code(ctx) == OESR_ERROR_NOTFOUND) {
				modinfo_msg("Caution output port %d not connected,\n",i);
			} else {
				moderror_msg("Error creating output port %d\n",i);
				oesr_perror("oesr_itf_create\n");
				return -1;
			}
		}
	}

	return 0;
}
示例#14
0
/**
 * @ingroup dac_source
 *
 * \param rate Sets DA converter sampling rateuency
 */
int initialize() {
	var_t pm;
	pm = oesr_var_param_get(ctx, "board");
	if (!pm) {
		moderror("Parameter board undefined\n");
		return -1;
	}

	if (oesr_var_param_get_value(ctx, pm, board, 128) == -1) {
		moderror("Error getting board value\n");
		return -1;
	}
	pm = oesr_var_param_get(ctx, "args");
	if (pm) {
		if (oesr_var_param_get_value(ctx, pm, args, 128) == -1) {
			moderror("Error getting board value\n");
			return -1;
		}
	} else {
		bzero(args,128);
	}

	blocking=0;
	param_get_int_name("blocking",&blocking);

	wait_packets=0;
	param_get_int_name("wait_packets",&wait_packets);

	nsamples_id = param_id("nsamples");
	if (!nsamples_id) {
		moderror("Parameter nsamples not found\n");
		return -1;
	}

	rate_id = param_id("rate");
	if (!rate_id) {
		moderror("Parameter rate not found\n");
		return -1;
	}
	freq_id = param_id("freq");
	if (!freq_id) {
		moderror("Parameter freq not found\n");
		return -1;
	}
	gain_id = param_id("gain");

	dac = rtdal_dac_open(board,args);
	if (!dac) {
		moderror_msg("Initiating DAC %s (args=%s)\n",board,args);
		return -1;
	}
	if (process_params()) {
		moderror("Setting parameters\n");
		return -1;
	}
	return 0;
}
示例#15
0
/**@ingroup Process shift parameters
 * Processes the configuration parameters that define the shift pointer and index 
 * increment (shift_increment).
 * \param df Frequency shift in Hz (positive for upconversion, negative for downconversion)
 * \param fs Sampling rate in Hz
 * \param dft_size Number of DFT/IDFT points
 */
int process_shift_params(int df, int fs, int dft_size)
{
	if (df == df_lte) {
		if ((fs == 1920000) && (dft_size == 128)) {	/* 1.4 MHz LTE mode */
			shift = precomputed_shift_reg;
			shift_increment = 16;
		} else if ((fs == 3840000) && (dft_size == 256)) {/* 3 MHz LTE mode */
			shift = precomputed_shift_reg;
			shift_increment = 8;
		} else if ((fs == 7680000) && (dft_size == 512)) {/* 5 MHz LTE mode */
			shift = precomputed_shift_reg;
			shift_increment = 4;
		} else if ((fs == 15360000) && (dft_size == 1024)) {/* 10 MHz LTE mode */
			shift = precomputed_shift_reg;
			shift_increment = 2;
		} else if ((fs == 23040000) && (dft_size == 1536)) {/* 15 MHz LTE mode */
			shift = precomputed_shift_1536;
			shift_increment = 1;
		} else if ((fs == 30720000) && (dft_size == 2048)) {/* 20 MHz LTE mode */
			shift = precomputed_shift_reg;
			shift_increment = 1;
		} else {
			if (dft_size > MAX_DFT_SIZE) {
				moderror_msg("Too large DFT size %d. Maximum "
				"supported size is %d\n", dft_size, MAX_DFT_SIZE);
				return -1;
			}
			calculate_shift_vector(computed_shift, df, fs, dft_size);
			shift = computed_shift;
			shift_increment = 1;
		} 
	} else {
		if (dft_size > MAX_DFT_SIZE) {
			moderror_msg("Too large DFT size %d. Maximum supported size "
			"is %d\n", dft_size, MAX_DFT_SIZE);
			return -1;
		}
		calculate_shift_vector(computed_shift, df, fs, dft_size);
		shift = computed_shift;
		shift_increment = 1;
	}
	return 0;
}
示例#16
0
int process_ctrl_packet(void *ctx, struct ctrl_in_pkt *packet) {
	if (oesr_var_param_set_value_idx(ctx,packet->pm_idx,packet->value,
			packet->size) == -1) {
		moderror_msg("pm_idx=%d, value=0x%x, size=%d\n",packet->pm_idx,packet->value,packet->size);
		oesr_perror("Error setting control parameter\n");
		return -1;
	}

	return 0;
}
示例#17
0
int initialize() {
	int i;
	sample_t d_type;
	char pname[64];

	if (param_get_int_name("data_type",&data_type)) {
		moderror("Error getting parameter data_type\n");
		return -1;
	}

	if (type_param_2_type(data_type,&d_type)) {
		moderror_msg("Invalid data_type parameter %d\n",data_type);
		return -1;
	}

	input_sample_sz = type_size(d_type);
	output_sample_sz = input_sample_sz;

	if (param_get_int_name("nof_outputs",&nof_outputs)) {
		moderror("Error getting parameter nof_outputs\n");
		return -1;
	}
	if (nof_outputs > NOF_OUTPUT_ITF) {
		moderror_msg("Only %d interfaces are supported. nof_input_itf=%d\n",NOF_OUTPUT_ITF,nof_outputs);
		return -1;
	}
	memset(special_output_length,0,sizeof(int)*nof_outputs);
	nof_special_outputs = 0;
	for (i=0;i<nof_outputs;i++) {
		snprintf(pname,64,"out_len_%d",i);
		if (!param_get_int_name(pname,&special_output_length[i])) {
			nof_special_outputs++;
		}
	}
	sum_special_output_lengths = sum_i(special_output_length,nof_outputs);
	nof_output_itf = nof_outputs;
	memset(output_padding_pre,0,sizeof(int)*nof_outputs);
	memset(output_padding_post,0,sizeof(int)*nof_outputs);

	return 0;
}
示例#18
0
文件: skeleton.c 项目: a4a881d4/aloe
int init_interfaces(void *ctx) {
	int i;
	int has_ctrl=0;

	if (oesr_itf_nofinputs(ctx) > nof_input_itf) {
		/* try to create control interface */
		ctrl_in = oesr_itf_create(ctx, 0, ITF_READ, CTRL_IN_BUFFER);
		if (ctrl_in == NULL) {
			if (oesr_error_code(ctx) == OESR_ERROR_NOTREADY) {
				return 0;
			}
		} else {
			modinfo("Created control port\n");
			has_ctrl=1;
		}
	}

	moddebug("configuring %d inputs and %d outputs %d %d %d\n",nof_input_itf,nof_output_itf,inputs[0],input_max_samples,input_sample_sz);
	for (i=0;i<nof_input_itf;i++) {
		if (inputs[i] == NULL) {
			inputs[i] = oesr_itf_create(ctx, has_ctrl+i, ITF_READ, input_max_samples*input_sample_sz);
			if (inputs[i] == NULL) {
				if (oesr_error_code(ctx) == OESR_ERROR_NOTREADY) {
					return 0;
				} else {
					oesr_perror("creating input interface\n");
					return -1;
				}
			} else {
				moddebug("input_%d=0x%x\n",i,inputs[i]);
			}
		}
	}

	for (i=0;i<nof_output_itf;i++) {
		if (outputs[i] == NULL) {
			outputs[i] = oesr_itf_create(ctx, i, ITF_WRITE, output_max_samples*output_sample_sz);
			if (outputs[i] == NULL) {
				if (oesr_error_code(ctx) == OESR_ERROR_NOTFOUND) {
					modinfo_msg("Caution output port %d not connected,\n",i);
				} else {
					moderror_msg("Error creating output port %d\n",i);
					oesr_perror("oesr_itf_create\n");
					return -1;
				}
			} else {
				moddebug("output_%d=0x%x\n",i,outputs[i]);
			}
		}
	}

	return 1;
}
示例#19
0
文件: skeleton.c 项目: a4a881d4/aloe
int check_configuration(void *ctx) {
	moddebug("nof_input=%d, nof_output=%d\n",nof_input_itf,nof_output_itf);

	if (nof_input_itf > MAX_INPUTS) {
		moderror_msg("Maximum number of input interfaces is %d. The module uses %d. "
				"Increase MAX_INPUTS in oesr_static/skeleton/skeleton.c and recompile ALOE\n",
				MAX_INPUTS,nof_input_itf);
		return -1;
	}
	if (nof_output_itf > MAX_OUTPUTS) {
		moderror_msg("Maximum number of output interfaces is %d. The module uses %d. "
				"Increase MAX_OUTPUTS in oesr_static/skeleton/skeleton.c and recompile ALOE\n",
				MAX_OUTPUTS,nof_output_itf);
		return -1;
	}

	user_vars = NULL;
	nof_vars = 0;

	return 0;
}
示例#20
0
/**
 * @ingroup lte_ratematching
 *
 * Main DSP function
 *
 */
int work(void **inp, void **out) {
	int i, in_pkt_len, out_pkt_len, j;
	int rcv_samples;

	char *input, *output;

	param_get_int(pre_padding_id, &pre_padding);
	param_get_int(post_padding_id, &post_padding);
	param_get_int(nof_packets_id, &nof_packets);

	for (i=0;i<NOF_INPUT_ITF;i++) {
		input = inp[i];
		output = out[i];
		rcv_samples = get_input_samples(i);
		moddebug("%d samples received on input interface %d.\n",rcv_samples,i);
		if (rcv_samples == 0) {
			moddebug("%d samples to process. Returning.\n", rcv_samples);
			continue;
		}

		if ((rcv_samples) % nof_packets) {
			moderror_msg("Received samples (%d) should multiple of "
			"nof_packets (%d)\n", rcv_samples, nof_packets);
			return -1;
		}

		in_pkt_len = rcv_samples / nof_packets;
		if (direction) {
			out_pkt_len = in_pkt_len - pre_padding - post_padding;
		} else {
			out_pkt_len = in_pkt_len + pre_padding + post_padding;
		}

		if (in_pkt_len) {
			if (direction) {
				for (j=0;j<nof_packets;j++) {
					memcpy(outaddr(0),inaddr(pre_padding),input_sample_sz*out_pkt_len);
				}
			} else {
				for (j=0;j<nof_packets;j++) {
					memset(outaddr(0),0,input_sample_sz*pre_padding);
					memcpy(outaddr(pre_padding),inaddr(0),input_sample_sz*in_pkt_len);
					memset(outaddr(pre_padding+in_pkt_len),0,input_sample_sz*post_padding);
				}
			}
			moddebug("%d samples sent to output interface %d.\n",out_pkt_len*nof_packets, i);
			set_output_samples(i,out_pkt_len*nof_packets);
		}

	}
	return 0;
}
示例#21
0
int init_remote_variables(void *ctx) {
	int i;

	for (i=0;i<nof_remote_variables;i++) {
		remote_variables[i].module_idx =
				oesr_get_module_idx(ctx, (char*) remote_params_db[i].module_name);
		if (remote_variables[i].module_idx == -1) {
			moderror_msg("Module %s not found\n",remote_params_db[i].module_name);
			return -1;
		}
		remote_variables[i].variable_idx = oesr_get_variable_idx(ctx,
				(char*) remote_params_db[i].module_name,
				(char*) remote_params_db[i].variable_name);
		if (remote_variables[i].variable_idx == -1) {
			moddebug("Variable %s not found in module %s. "
					"Creating...\n",remote_params_db[i].variable_name,
					remote_params_db[i].module_name);

			/* create a new variable if not defined in .app */
			var_t new_var = oesr_var_param_create_remote(ctx,remote_variables[i].module_idx,
					(char*) remote_params_db[i].variable_name,remote_params_db[i].size);
			if (!new_var) {
				moderror_msg("Error creating remote variable %s in module %s.\n",
						remote_params_db[i].variable_name,
						remote_params_db[i].module_name);
				return -1;
			}
			remote_variables[i].variable_idx = new_var->id-1;
		}
		moddebug("Init remote parameter %s:%s (%d,%d)\n",remote_params_db[i].module_name,
				remote_params_db[i].variable_name,remote_variables[i].module_idx,
				remote_variables[i].variable_idx);
	}
	if (i==MAX_VARIABLES) {
		modinfo_msg("Caution: Only %d variables where parsed. "
				"Increase MAX_VARIABLES in oesr/include/ctrl_skeleton.h",i);
	}
	return i;
}
示例#22
0
文件: file_source.c 项目: alring/aloe
/**
 * @ingroup file_source
 *
 * \param data_type If specified, reads formated data in text mode:
 * 0 for float, 1 for _Complex float and 2 for _Complex short
 * \param block_length Number of samples to read per timeslot, or bytes
 * \param file_name Name of the *.mat file to save the signal
 */
int initialize() {
	char name[64];
	var_t pm;
	int i;

	if (param_get_int_name("data_type", &data_type)) {
		data_type=-1;
	}

	switch(data_type) {
	case 0:
		output_sample_sz = sizeof(float);
		break;
	case 1:
		output_sample_sz = sizeof(_Complex float);
		break;
	case 2:
		output_sample_sz = sizeof(_Complex short);
		break;
	case -1:
		output_sample_sz=sizeof(char);
	}

	if (param_get_int_name("block_length", &block_length)) {
		moderror("Parameter block_length not specified\n");
		return -1;
	}

#ifdef _COMPILE_ALOE
	pm = oesr_var_param_get(ctx, "file_name");
	if (!pm) {
		moderror("Parameter file_name undefined\n");
		return -1;
	}

	if (oesr_var_param_get_value(ctx, pm, name, 64) == -1) {
		moderror("Error getting file_name value\n");
		return -1;
	}
#endif

	modinfo_msg("Opening file %s for reading\n",name);
	fd = rtdal_datafile_open(name,"r");
	if (!fd) {
		moderror_msg("Error opening file %s\n",name);
		return -1;
	}

	return 0;
}
示例#23
0
/**
 * @ingroup file_sink
 *
 * \param data_type If specified, formats data in text mode:
 * 0 for float, 1 for _Complex float and 2 for _Complex short
 * \param file_name Name of the *.mat file to save the signal
 */
int initialize() {
	char name[64];

	if (param_get_int_name("data_type", &data_type)) {
		data_type=-1;
	}

	switch(data_type) {
	case 0:
		input_sample_sz = sizeof(float);
		break;
	case 1:
		input_sample_sz = sizeof(_Complex float);
		break;
	case 2:
		input_sample_sz = sizeof(_Complex short);
		break;
	case -1:
		input_sample_sz=sizeof(char);
	}

#ifdef _COMPILE_ALOE
	var_t pm;
	pm = oesr_var_param_get(ctx, "file_name");
	if (!pm) {
		moderror("Parameter file_name undefined\n");
		return -1;
	}

	if (oesr_var_param_get_value(ctx, pm, name, 64) == -1) {
		moderror("Error getting file_name value\n");
		return -1;
	}
#endif

	modinfo_msg("Opening file %s for writing\n",name);
	fd = rtdal_datafile_open(name,"w");
	if (!fd) {
		moderror_msg("Error opening file %s\n",name);
		return -1;
	}

	last_rcv_samples = 0;

	return 0;
}
示例#24
0
int init_local_variables(void *ctx) {
	int i;

	i=0;
	while(local_params_db[i].name && i<MAX_VARIABLES) {
		local_variables[i] = oesr_var_param_get(ctx,(char*) local_params_db[i].name);
		if (!local_variables[i]) {
			moderror_msg("Parameter %s not found\n",local_params_db[i].name);
			return -1;
		}
		i++;
	}
	if (i==MAX_VARIABLES) {
		modinfo_msg("Caution: Only %d variables where parsed. "
				"Increase MAX_VARIABLES in oesr/include/ctrl_skeleton.h",i);
	}
	return i;
}
示例#25
0
/**
 * @ingroup template
 *  Document here the module's initialization parameters
 *
 * The documentation should explain which are the possible parameters, what they do and if they are
 * mandatory or optional (indicating the default value in such case).
 *
 * \param gain Document paramater gain
 * \param block_length Document parameter block_length
 *
 * \returns This function returns 0 on success or -1 on error
 */
int initialize() {

	/* obtains a handler for fast access to the parameter */
	gain_id = param_id("gain");
	/* In this case, we are obtaining the parameter value directly */
	if (param_get_int_name("block_length", &block_length)) {
		block_length = 0;
	}
	/* use this function to print formatted messages */modinfo_msg("Parameter block_length is %d\n",block_length);

	/* Verify control parameters */
	if (block_length > input_max_samples || block_length < 0) {
		moderror_msg("Invalid block length %d\n", block_length);
		return -1;
	}

	/* here you may do some other initialization stuff */

	return 0;
}
示例#26
0
/**
 * @ingroup lte_resource_mapper
 *
 *	See lte_ctrl_tx for grid params.
 *
 * \param nof_channels Number of channels to extract
 * \param channel_id_n Id of the n-th channel to extract (configured in channel_setup.h)
 * \param (optional) subframe_idx, if not provided, subframe_idx is counted automatically starting at zero
 *
 * \returns This function returns 0 on success or -1 on error
 */
int initialize() {
	int i;
	char tmp[64];
	int max_out_port;

	max_out_port = read_channels();

	grid.fft_size = 128;
	grid.nof_prb = 6;
	grid.nof_osymb_x_subf = 14;
	grid.nof_ports = 1;
	grid.cell_id = 0;
	grid.cfi = -1;
	grid.nof_pdsch = 0;
	grid.nof_pdcch = 0;

	subframe_idx_id = param_id("subframe_idx");
	if (!subframe_idx_id) {
		subframe_idx = 0;
	}

	if (param_get_int_name("nof_channels",&nof_channels)) {
		nof_channels = 1;
	}
	if (nof_channels > MAX_CHANNELS) {
		moderror_msg("Maximum allowed channels is %d (%d)\n",nof_channels,MAX_CHANNELS);
		return -1;
	}
	for (i=0;i<nof_channels;i++) {
		snprintf(tmp,64,"channel_id_%d",i);
		if (param_get_int_name(tmp,&channel_ids[i])) {
			channel_ids[i] = i;
		}
	}

	nof_output_itf = max_out_port+1;
	nof_input_itf = 1;


	return 0;
}
示例#27
0
/**
 * @ingroup gen_hard_demod
 *
 * Main DSP function
 *
 * Calls the appropriate function for demodulating all recevied symbols.
 *
 * \param inp Input interface buffers. The value inp[i] points to the buffer received
 * from the i-th interface. The function get_input_samples(i) returns the number of received
 * samples (the sample size is by default sizeof(input_t))
 *
 * \param out Output interface buffers. The value out[i] points to the buffer where the samples
 * to be sent through the i-th interfaces must be stored.
 *
 * @return On success, returns a non-negative number indicating the output
 * samples that should be transmitted through all output interface. To specify a different length
 * for certain interface, use the function set_output_samples(int idx, int len)
 * On error returns -1.
 *
 *
 */
int work(void **inp, void **out) {

	int rcv_samples, snd_samples;
	int modulation;

	int bits_per_symbol;
	input_t *input;
	output_t *output;
	float *inreal;

	if (!get_input_samples(0)) {
		return 0;
	}

	/* Dynamically obtain modulation type */
	if (param_get_int(modulation_id, &modulation) != 1) {
		moderror("Error getting 'modulation' parameter. Assuming BPSK.\n");
		modulation = BPSK;
	}

	/* Verify parameters */
	if ((modulation != BPSK) && (modulation != QPSK) && (modulation != QAM16) && (modulation != QAM64)) {
		moderror_msg("Invalid modulation %d. Specify 1 for BPSK, 2 for QPSK,"
				"4 for 16QAM, or 6 for 64QAM\n", modulation);
		return -1;
	}

	input = inp[0];
	output = out[0];
	rcv_samples = get_input_samples(0); /* number of input samples */
	bits_per_symbol = get_bits_per_symbol(modulation);
	if (in_real) {
		inreal = inp[0];
		hard_demod_real(inreal, output, rcv_samples, modulation);
	} else {
		hard_demod(input, output, rcv_samples, modulation);
	}
	snd_samples = rcv_samples*bits_per_symbol;

	return snd_samples;
}
示例#28
0
文件: gen_dft.c 项目: agelonch/aloe
int work(void **inp, void **out) {
	int i, j, nof_fft;
	int dft_size;
	input_t *input;
	output_t *output;
	dft_plan_t *plan;

	if (param_get_int(dft_size_id,&dft_size) != 1) {
		moderror("Getting parameter dft_size\n");
		return -1;
	}

	plan = find_plan(dft_size);
	if (!plan) {
		if ((plan = generate_new_plan(dft_size)) == NULL) {
			moderror("Generating plan.\n");
			return -1;
		}
	}

	for (i=0;i<NOF_INPUT_ITF;i++) {
		input = inp[i];
		output = out[i];

		if (get_input_samples(i) % dft_size) {
			moderror_msg("Number of input samples (%d) must be multiple of dft_size (%d), in "
					"interface %d\n",get_input_samples(i),dft_size,i);
			return -1;
		}

		nof_fft = get_input_samples(i)/dft_size;

		for (j=0;j<nof_fft;j++) {
			dft_run_c2c(plan, &input[j*dft_size], &output[j*dft_size]);
		}

		set_output_samples(i,dft_size*nof_fft);
	}
	return 0;
}
示例#29
0
int modulate(input_t *input, output_t *output, int nof_bits) {
	int bits_per_symbol, nof_symbols;
	int i,j;

	j = 0;
	bits_per_symbol = get_bits_per_symbol(modulation);
	nof_symbols = nof_bits/bits_per_symbol;

	switch(modulation) {
	case BPSK:
		for (i=0; i<nof_bits; i+=bits_per_symbol) {
			modulate_BPSK(&input[i], &output[j]);
				j++; // one symbol every bits_per_symbol bits
		}
	break;
	case QPSK:
		for (i=0; i<nof_bits; i+=bits_per_symbol) {
			modulate_QPSK(&input[i], &output[j]);
				j++; // one symbol every bitspersymbol bits
		}
	break;
	case QAM16:
		for (i=0; i<nof_bits; i+=bits_per_symbol) {
			modulate_16QAM(&input[i], &output[j]);
				j++; // one symbol every bitspersymbol bits
		}
	break;
	case QAM64:
		for (i=0; i<nof_bits; i+=bits_per_symbol) {
			modulate_64QAM(&input[i], &output[j]);
				j++; // one symbol every bitspersymbol bits
		}
	break;
	default:
		moderror_msg("Unknown modulation %d\n",modulation);
		return -1;
	}
	return nof_symbols;
}
示例#30
0
/**
 * @ingroup gen_hard_demod
 *
 * Main DSP function
 *
 * Calls the appropriate function for demodulating all recevied symbols.
 *
 * \param inp Input interface buffers. The value inp[i] points to the buffer received
 * from the i-th interface. The function get_input_samples(i) returns the number of received
 * samples (the sample size is by default sizeof(input_t))
 *
 * \param out Output interface buffers. The value out[i] points to the buffer where the samples
 * to be sent through the i-th interfaces must be stored.
 *
 * @return On success, returns a non-negative number indicating the output
 * samples that should be transmitted through all output interface. To specify a different length
 * for certain interface, use the function set_output_samples(int idx, int len)
 * On error returns -1.
 *
 *
 */
int work(void **inp, void **out) {
	int i;
	int rcv_samples, snd_samples;
	int modulation;
	float sigma2;
	int bits_per_symbol;
	input_t *input;
	output_t *output;

	/* Dynamically obtain modulation type */
	if (param_get_int(modulation_id, &modulation) != 1) {
		moderror("Error getting 'modulation' parameter. Assuming QPSK.\n");
		modulation = QPSK;
	}

	/* Verify parameters */
	if (modulation > 3 || modulation < 0) {
		moderror_msg("Invalid modulation %d. Specify 0 for BPSK, 1 for QPSK,"
				"2 for 16QAM, or 3 for 64QAM\n", modulation);
		return -1;
	} else {
		modinfo_msg("Modulation type is %d (0:BPSK; 1:QPSK; 2:16QAM;"
				"3:64QAM)\n",modulation);
	}

	input = inp[0];
	output = out[0];
	rcv_samples = get_input_samples(0); /* number of input samples */
	bits_per_symbol = get_bits_per_symbol(modulation);
	hard_demod(input, output, rcv_samples, modulation);
	snd_samples = rcv_samples*bits_per_symbol;

/*	printf("\n\n");
	for (i=0; i<snd_samples; i++) {
		printf("%d",output[i]);
	}
*/
	return snd_samples;
}