Пример #1
0
/**@ingroup gen_crc
 * Adds a CRC to every received packet from each interface
 */
int work(void **inp, void **out) {
	int i;
	unsigned int n;
	input_t *input;

	if (poly_id) param_get_int(poly_id,&poly);
	if (long_crc_id) param_get_int(long_crc_id, &long_crc);

	for (i=0;i<NOF_INPUT_ITF;i++) {
		if (get_input_samples(i)) {
			moddebug("rcv_len=%d\n",get_input_samples(i));
			memcpy(out[i],inp[i],sizeof(input_t)*get_input_samples(i));
			input = out[i];
			n = icrc(0, input, get_input_samples(i), long_crc, poly, mode == MODE_ADD);

			if (mode==MODE_CHECK) {
				if (n) {
					total_errors++;
				}
				total_pkts++;
				set_output_samples(i,get_input_samples(i)-long_crc);

				if (!print_nof_pkts) {
					tscnt++;
					if (tscnt==interval_ts) {
						tscnt=0;
						#ifdef PRINT_BLER
						printf("Total blocks: %d\tTotal errors: %d\tBLER=%g\n",
								total_pkts,total_errors,(float)total_errors/total_pkts);
						#endif
					}
				} else {
					print_nof_pkts_cnt++;
					if (print_nof_pkts_cnt == print_nof_pkts) {
						print_nof_pkts_cnt=0;
						printf("Total blocks: %d\tTotal errors: %d\tBLER=%g\n",
								total_pkts,total_errors,(float)total_errors/total_pkts);
						total_pkts=0;
						total_errors=0;
					}
				}

			} else {
				set_output_samples(i,get_input_samples(i)+long_crc);
			}
		}
	}
	return 0;
}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
0
int recv_dci(char *input, char *output, int len) {
	struct dci_format1 dci; /* Only format1 is currently supported */
	int rbg_mask = 0;
	int i;

	if (len == 0) {
		return 0;
	} else {
		memset(&dci,0,sizeof(struct dci_format1));
		dci.harq_pnum_len = 3;
		dci.carrier_indicator_len=2;
		if (param_get_int_name("nof_rbg",&dci.nof_rbg)) {
			modinfo("could not get parameter nof_rbg\n");
		}
		if (dci_format1_unpack(input,len,&dci)<0) {
			moderror("Reading DCI Format 1 packet\n");
			return -1;
		}
		for (i=0;i<MAX_RBG_SET;i++) {
			rbg_mask |= (dci.rbg_mask[i] & 0x1) << (i);
		}
	}

#ifdef _COMPILE_ALOE
	len = 0;
	int n;
	n = param_remote_set_ptr(&output[len], mcs_rx, &dci.mcs, sizeof(int));
	if (n == -1) {
		moderror("Setting parameter mcs\n");
		return -1;
	}
	len += n;
	n = param_remote_set_ptr(&output[len], nof_rbg_rx, &dci.nof_rbg, sizeof(int));
	if (n == -1) {
		moderror("Setting parameter nof_rbg\n");
		return -1;
	}
	len += n;
	n = param_remote_set_ptr(&output[len], rbg_mask_rx, &rbg_mask, sizeof(int));
	if (n == -1) {
		moderror("Setting parameter rbg_mask\n");
		return -1;
	}
	len += n;
	set_output_samples(0,len);
	modinfo_msg("received mcs=%d, nof_rbg=%d, rbgmask=0x%x\n",dci.mcs,dci.nof_rbg,rbg_mask);
#endif

	return len;
}
Пример #5
0
int param_remote_set(void **out_ptr, int module_idx, int param_idx, void *value, int value_sz) {
	struct ctrl_in_pkt *pkt;

	if (module_idx<0 || module_idx > nof_output_itf) {
		return -1;
	}
	pkt = out_ptr[module_idx];
	if (value_sz > CTRL_PKT_VALUE_SZ) {
		return -1;
	}
	pkt->pm_idx = param_idx;
	pkt->size = value_sz;
	memcpy(pkt->value,value,value_sz);
	set_output_samples(module_idx,1);
	return 0;
}
Пример #6
0
int work(void **inp, void **out) {
	int i,n;
#if NOF_INPUTS>1
	for (i=0;i<NOF_INPUT_ITF;i++) {
		binsource.input[i] = inp[i];
		binsource.in_len[i] = get_input_samples(i)
	}
#elif NOF_INPUTS == 1
	binsource.input = inp[0];
	binsource.in_len = get_input_samples(0);
#endif

#if NOF_OUTPUTS>1
	for (i=0;i<NOF_OUTPUT_ITF;i++) {
		binsource.output[i] = out[i];
		binsource.out_len = &out_len[i];
	}
#elif NOF_OUTPUTS == 1
	binsourceoutput = out[0];
	binsource.out_len = &out_len[0];
#endif

	/* Get input parameters */
	if (param_get_int(nbits_id, &binsource.ctrl_in.nbits) != 1) {
		moderror("Error getting parameter nbits\n");
		return -1;
	}

	/* call work */
	n = binsource_work(&binsource);

	/* Set output nof_samples */
	for (i=0;i<NOF_OUTPUT_ITF;i++) {
		set_output_samples(i,out_len[i]);
		binsource.out_len = &out_len[i];
	}

	/* Set output parameters */

	return n;
}
Пример #7
0
int work(void **inp, void **out) {
	int i, out_len;
	input_t *input;
	output_t *output;

	param_get_int(modulation_id,&modulation);

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

		if (get_input_samples(i)) {
			out_len = modulate(input,output,get_input_samples(i));
			if (out_len == -1) {
				return -1;
			}
			set_output_samples(i,out_len);
		}
	}
	return 0;
}
Пример #8
0
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;
}
Пример #9
0
int work(void **inp, void **out) {
	int i, out_len, j;
	input_t *input;
	output_t *output;
	int rcv_samples;

	for (i=0;i<NOF_INPUT_ITF;i++) {
		input = inp[i];
		output = out[i];
		moddebug("rcv_len=%d\n",get_input_samples(i));
		rcv_samples = get_input_samples(i);
		if (rcv_samples) {
			conv_encode(input,rcv_samples,constraint_length,rate,g,tail_bit,
								output,&out_len);

			for (j=0;j<padding;j++) {
				output[out_len+j] = 0;
			}

			set_output_samples(i,out_len+padding);
		}
	}
	return 0;
}
Пример #10
0
int work(void **inp, void **out) {
	int i, j, k;
	int rcv_samples, nof_ffts;
	int df, fs;
	int e;
	int dft_size;
	input_t *input;
	output_t *output;
	dft_plan_t *plan;
	
 
	if (param_get_int(dft_size_id,&dft_size) != 1) {
		dft_size = get_input_samples(0);
		moddebug("Parameter dft_size not defined. Assuming %d"
		" (number of input samples on interface 0).\n", dft_size);
		/*moderror("Getting parameter dft_size\n");
		return -1;*/
	}

	if (dft_size == 0) {
		modinfo("dft_size = 0. Returning.\n");
		return 0;
	} else {
		moddebug("dft_size = %d.\n", dft_size);
	}
	
/*	if (param_get_int(param_id("dft_size"),&dft_size) != 1) {
		
		moddebug("Parameter dft_size not defined. Assuming %d"
			" (number of input samples on interface 0).\n", dft_size);
	}
*/
	plan = find_plan(dft_size);
	if (!plan) {
		if ((plan = generate_new_plan(dft_size)) == NULL) {
			moderror("Generating plan.\n");
			return -1;
		}
	}
	
	if (param_get_int(df_id, &df) != 1) {
		df = 0;
	}
	if (df != 0) {
		if (param_get_int(fs_id, &fs) != 1) {
			moderror("Parameter fs not defined.\n");
			return -1;
		}
		if (fs <= 0) {
			moderror("Sampling rate fs must be larger than 0.\n");
			return -1;
		}
		if ((df != previous_df) || (fs != previous_fs) || (dft_size != previous_dft_size)) {
			e = process_shift_params(df, fs, dft_size);
			if (e < 0) {
				return -1;
			}
			previous_df = df;
			previous_fs = fs;
			previous_dft_size = dft_size;
		}
	}

	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 interface %d.\n",rcv_samples, i);
		if (rcv_samples == 0) {
			moddebug("%d samples to process. Returning.\n", rcv_samples);
			continue;
		}
		moddebug("Processing %d samples...\n",rcv_samples);

		if (rcv_samples % dft_size) {
			moderror_msg("Number of input samples (%d) not integer multiple"
			" of dft_size (%d) on interface %d\n",rcv_samples,dft_size,i);
			return -1;
		}
		if (get_input_samples(0)>0) {
			modinfo_msg("received %d samples\n",get_input_samples(0));
		}

		nof_ffts = rcv_samples/dft_size;

		for (j=0;j<nof_ffts;j++) {
			if ((df != 0) && (direction == FORWARD)) { /* Rx: shift before FFT */
				for (k=0;k<dft_size;k++) {
					input[j*dft_size+k] *= shift[k*shift_increment];
				}
			}

			dft_run_c2c(plan, &input[j*dft_size], &output[j*dft_size]);

			if ((df !=0) && (direction == BACKWARD)) { /* Tx: shift after IFFT */
				for (k=0;k<dft_size;k++) {
					output[j*dft_size+k] *= shift[k*shift_increment];
				}
			}
		}

		set_output_samples(i,dft_size*nof_ffts);
		moddebug("%d samples sent to output interface %d.\n",dft_size*nof_ffts,i);
	}

	return 0;
}
Пример #11
0
/**@ingroup gen_remcyclic
 *
 * For each interface, the number of received samples must be multiple of the OFDM symbol size,
 * otherwise the module produces and error and stops the waveform.
 *
 * It removes a cyclic prefix to each OFDM symbol received from each interface.
 */
int work(void **inp, void **out) {
	int i, j;
	int dft_size, cyclic_prefix_sz, first_cyclic_prefix_sz;
	int k, nof_ofdm_symbols_per_slot, rcv_samples;
	int cpy;
	int cnt;
	input_t *input;
	output_t *output;

	if (param_get_int(cyclic_prefix_sz_id, &cyclic_prefix_sz) != 1) {
		moderror("getting parameter cyclic_prefix_sz\n");
		return -1;
	}
	if (first_cyclic_prefix_sz_id) {
		if (param_get_int(first_cyclic_prefix_sz_id, &first_cyclic_prefix_sz) != 1) {
			moderror("getting parameter first_cyclic_prefix_sz\n");
			return -1;
		}
	} else {
		first_cyclic_prefix_sz = cyclic_prefix_sz;
	}

	if (param_get_int(dft_size_id, &dft_size) != 1) {
		/*moderror("getting parameter dft_size\n");
		return -1;*/
		dft_size = get_input_samples(0)-cyclic_prefix_sz;
		moddebug("Parameter dft_size not defined. Assuming %d"
		" (number of input samples on interface 0 - cyclic_prefix_sz)."
		"\n", dft_size);
	}

	if (dft_size <= 0) {
		modinfo("dft_size <= 0. Returning.\n");
		return 0;
	} else {
		moddebug("dft_size = %d.\n", dft_size);
	}

	if (first_cyclic_prefix_sz > dft_size || cyclic_prefix_sz > dft_size) {
		moderror_msg("Error with parameters dft_size=%d, cyclic_prefix_sz=%d, "
				"first_cyclic_prefix_sz=%d\n",dft_size,cyclic_prefix_sz,first_cyclic_prefix_sz);
		return -1;
	}

	if (first_cyclic_prefix_sz == cyclic_prefix_sz) {
		nof_ofdm_symbols_per_slot = 6;
	} else {
		nof_ofdm_symbols_per_slot = 7;
	}

	for (i=0;i<NOF_INPUT_ITF;i++) {
		cnt=0;
		input = inp[i];
		output = out[i];
		rcv_samples = get_input_samples(i);
		moddebug("rcv_len=%d samples \n",rcv_samples);

		if (rcv_samples > 0) {
			j = 0;
			k = 0;
			while (cnt < rcv_samples) {
				if (j == k*nof_ofdm_symbols_per_slot) {
					cpy = first_cyclic_prefix_sz;
					k++;
				} else {
					cpy = cyclic_prefix_sz;
				}
				memcpy(output,&input[cpy],sizeof(input_t)*dft_size);
				input += dft_size+cpy;
				output += dft_size;
				cnt += dft_size+cpy;
				j++;
			}
			if (rcv_samples != cnt) {
				moderror_msg("Number of input samples (%d) should be "
				"equal to %d on interface %d\n",rcv_samples,cnt,i);
				return -1;
			}
			set_output_samples(i, j*dft_size);
		}
	}
	return 0;
}
Пример #12
0
/**@ingroup gen_cyclic
 *
 * For each interface, the number of received samples must be multiple of the OFDM symbol size,
 * otherwise the module produces and error and stops the waveform.
 *
 * It adds a cyclic prefix to each OFDM symbol received from each interface.
 */
int work(void **inp, void **out) {
	int i, j;
	int nof_ofdm_symb;
	int dft_size, cyclic_prefix_sz, first_cyclic_prefix_sz;
	int k, nof_ofdm_symbols_per_slot,rcv_samples;
	int cnt;
	int cpy;
	div_t symbols;
	input_t *input;
	output_t *output;

	if (param_get_int(dft_size_id, &dft_size) != 1) {
		/*moderror("getting parameter dft_size\n");
		return -1;*/
		dft_size = get_input_samples(0);
		moddebug("Parameter dft_size not defined. Assuming %d"
		" (number of input samples on interface 0).\n", dft_size);
	}

	if (dft_size == 0) {
		modinfo("dft_size = 0. Returning.\n");
		return 0;
	} else {
		moddebug("dft_size = %d.\n", dft_size);
	}

	if (param_get_int(cyclic_prefix_sz_id, &cyclic_prefix_sz) != 1) {
		moderror("getting parameter cyclic_prefix_sz\n");
		return -1;
	}
	if (first_cyclic_prefix_sz_id) {
		if (param_get_int(first_cyclic_prefix_sz_id, &first_cyclic_prefix_sz) != 1) {
			moderror("getting parameter first_cyclic_prefix_sz\n");
			return -1;
		}
	} else {
		first_cyclic_prefix_sz = cyclic_prefix_sz;
	}
	if (first_cyclic_prefix_sz > dft_size || cyclic_prefix_sz > dft_size) {
		moderror_msg("Error with parameters dft_size=%d, cyclic_prefix_sz=%d, "
				"first_cyclic_prefix_sz=%d\n",dft_size,cyclic_prefix_sz,first_cyclic_prefix_sz);
		return -1;
	}

	if (first_cyclic_prefix_sz == cyclic_prefix_sz) {
		nof_ofdm_symbols_per_slot = 6;
	} else {
		nof_ofdm_symbols_per_slot = 7;
	}

	for (i=0;i<NOF_INPUT_ITF;i++) {
		input = inp[i];
		output = out[i];
		rcv_samples = get_input_samples(i);
		moddebug("rcv_len=%d samples \n",rcv_samples);

		symbols = div(rcv_samples,dft_size);

		if (symbols.rem) {
			moderror_msg("Number of input samples (%d) must be "
			"integer multiple of dft_size (%d) on interface "
			"%d\n",rcv_samples,dft_size,i);
			return -1;
		}

		nof_ofdm_symb = symbols.quot;

		if (nof_ofdm_symb) {
			k = 0;
			cnt = 0;
			for (j=0;j<nof_ofdm_symb;j++) {
				if (j == k*nof_ofdm_symbols_per_slot) {
					cpy = first_cyclic_prefix_sz;
					k++;
				} else {
					cpy = cyclic_prefix_sz;
				}
				memcpy(output, &input[dft_size-cpy], sizeof(input_t)*cpy);
				memcpy(&output[cpy], input, sizeof(input_t)*dft_size);
				input += dft_size;
				output += dft_size+cpy;
				cnt += dft_size+cpy;
			}

			set_output_samples(i, cnt);
		}
	}
	return 0;
}