Beispiel #1
0
/**
 * @ingroup udp_sink
 *
 *  Writes the received samples to the dac output buffer
 *
 */
int work(void **inp, void **out) {
	int rcv_samples;
	int n;
	char tmp[16];
	int nof_pkts,pkt_len,i;
	input_t *input = inp[0];

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

	nof_pkts=1;
	param_get_int(blen_id,&nof_pkts);

	if (rcv_samples % nof_pkts) {
		modinfo_msg("Warning received packet len %d not multiple of %d packets\n",
				rcv_samples,nof_pkts);
	}
	pkt_len = rcv_samples/nof_pkts;

	modinfo_msg("Sending %d packets of %d bytes\n",nof_pkts,pkt_len);

	for (i=0;i<nof_pkts;i++) {
		n = sendto(fd,&input[i*pkt_len],pkt_len,0,(struct sockaddr *) &servaddr, sizeof (servaddr));
		if (n == -1) {
			perror("sendto");
			return -1;
		}
	}

	return 0;
}
Beispiel #2
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;
}
Beispiel #3
0
/**
 *  Generates input signal. VERY IMPORTANT to fill length vector with the number of
 * samples that have been generated.
 * @param inp Input interface buffers. Data from other interfaces is stacked in the buffer.
 * Use in(ptr,idx) to access the address.
 *
 * @param lengths Save on n-th position the number of samples generated for the n-th interface
 */
int generate_input_signal(void *in, int *lengths)
{
  int i;
  input_t *input = in;
  int block_length;
  pmid_t blen_id;

  blen_id = param_id("block_length");
  if (!blen_id) {
    moderror("Parameter block_length not found\n");
    return -1;
  }
  if (!param_get_int(blen_id,&block_length)) {
    moderror("Getting integer parameter block_length\n");
    return -1;
  }

  modinfo_msg("Parameter block_length is %d\n",block_length);


  /** HERE INDICATE THE LENGTH OF THE SIGNAL */
  lengths[0] = block_length;

  for (i=0;i<block_length;i++) {
#ifdef GENESRSLTE_TCOD_RATE_COMPLEX
    __real__ input[i] = (float) ((i+offset)%(block_length));
    __imag__ input[i] = (float) ((block_length-i-1+offset)%(block_length));
#else
    input[i] = (i+offset)%(block_length);
#endif
  }
  offset++;
  return 0;
}
Beispiel #4
0
/**
 * @ingroup file_source
 *
 *  Writes the received samples to the dac output buffer
 *
 */
int work(void **inp, void **out) {
	int n;
	output_t *output = out[0];

	switch(data_type) {
	case 0:
		n = rtdal_datafile_read_real(fd,(float*) output,block_length);
		break;
	case 1:
		n = rtdal_datafile_read_complex(fd,
				(_Complex float*) output,block_length);
		break;
	case 2:
		n = rtdal_datafile_read_complex_short(fd,
				(_Complex short*) output,block_length);
		break;
	case -1:
		n = rtdal_datafile_read_bin(fd,output,block_length);
	}

#ifdef _COMPILE_ALOE
	if (n != last_snd_samples) {
		last_snd_samples = n;
		modinfo_msg("Sending %d samples at tslot %d\n",
				n,oesr_tstamp(ctx));
	}
#endif

	return n;
}
Beispiel #5
0
/**
 * @ingroup lte_dci_pack
 * \param direction 0 for dci packing, 1 for dci unpacking
 * \returns This function returns 0 on success or -1 on error
 */
int initialize() {

	if (param_get_int_name("direction",&direction)) {
		moderror("Getting parameter direction\n");
		return -1;
	}

	if (!direction) {
		nof_input_itf = 0;
		nof_output_itf = 1;
	} else {
		nof_input_itf = 1;
		nof_output_itf = 1;
	}
#ifdef _COMPILE_ALOE
	mcs_rx = oesr_get_variable_idx(ctx, "ctrl","mcs_rx");
	nof_rbg_rx = oesr_get_variable_idx(ctx, "ctrl","nof_rbg_rx");
	rbg_mask_rx = oesr_get_variable_idx(ctx, "ctrl","rbg_mask_rx");
	if (mcs_rx < 0 || nof_rbg_rx < 0 || rbg_mask_rx < 0) {
		moderror("Error getting remote parameters\n");
	}
	modinfo_msg("remote params: mcs_rx=%d, nof_rbg_rx=%d, rbg_mask_rx=%d\n",mcs_rx,nof_rbg_rx,rbg_mask_rx);
#endif
	return 0;
}
Beispiel #6
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;
}
Beispiel #7
0
/**
 * @ingroup udp_sink
 *
 * \param address IP address to connect
 * \param port	Port to connect
 */
int initialize() {
	char address[64];
	var_t pm;
	int i;
	int port;

	blen_id = param_id("nof_pkts");

	if (param_get_int_name("port",&port)) {
		moderror("Port undefined\n");
		return -1;
	}

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

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

	fd = create_client_upd(address,port,&servaddr);
	if (fd == -1) {
		moderror("Creating socket\n");
		return -1;
	}
	modinfo_msg("sock=%d\n",fd);

	return 0;
}
Beispiel #8
0
/**
 * Generates input signal. VERY IMPORTANT to fill length vector with the number of
 * samples that have been generated.
 * @param inp Input interface buffers. Data from other interfaces is stacked in the buffer.
 * Use in(ptr,idx) to access the address.
 *
 * @param lengths Save on n-th position the number of samples generated for the n-th interface
 */
int generate_input_signal(void *in, int *lengths)
{
	int i;
	input_t *input = in;
	int block_length;
	pmid_t blen_id;

	blen_id = param_id("block_length");
	if (!blen_id) {
		moderror("Parameter block_length not found\n");
		return -1;
	}
	if (!param_get_int(blen_id,&block_length)) {
		moderror("Getting integer parameter block_length\n");
		return -1;
	}

	modinfo_msg("Parameter block_length is %d\n",block_length);


	/** HERE INDICATE THE LENGTH OF THE SIGNAL */
	lengths[0] = block_length;

	for (i=0;i<block_length;i++) {
		input[i] = 0.7 + 0.7*_Complex_I;
	}
	return 0;
}
Beispiel #9
0
/**
 * @ingroup file_sink
 *
 *  Writes the received samples to the dac output buffer
 *
 */
int work(void **inp, void **out) {
	int rcv_samples;
	input_t *buffer = inp[0];

	rcv_samples = get_input_samples(0);

#ifdef _COMPILE_ALOE
	if (rcv_samples != last_rcv_samples) {
		last_rcv_samples = rcv_samples;
		modinfo_msg("Receiving %d samples at tslot %d\n",
				rcv_samples,oesr_tstamp(ctx));
	}
#endif

	if (!rcv_samples) {
		return 0;
	}
	switch(data_type) {
	case 0:
		rtdal_datafile_write_real(fd,(float*) buffer,rcv_samples);
		break;
	case 1:
		rtdal_datafile_write_complex(fd,
				(_Complex float*) buffer,rcv_samples);
		break;
	case 2:
		rtdal_datafile_write_complex_short(fd,
				(_Complex short*) buffer,rcv_samples);
		break;
	case -1:
		rtdal_datafile_write_bin(fd,buffer,rcv_samples);
	}

	return 0;
}
Beispiel #10
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;
}
Beispiel #11
0
int findMAXFinal(int numsamples, _Complex float *corr, p2MAX_t *pMAXe, float threshold){

	int i;

	//Find Max total
	pMAXe->MAX=0.;
	for(i=0; i<numsamples; i++){
		if(pMAXe->MAX < __real__ corr[i]){
			pMAXe->MAX = __real__ corr[i];
			pMAXe->pMAX = i;
		}
		pMAXe->average += __real__ corr[i];
		pMAXe->var += fabsf(__real__ corr[i]);
	}
	pMAXe->average /= numsamples;
	pMAXe->var /= numsamples;
	pMAXe->max2average=pMAXe->MAX/pMAXe->average;
	pMAXe->max2var=pMAXe->MAX/pMAXe->var;
//	printf("pMAX = %d, MAX = %3.3f, average = %3.3f, MAX/average=%3.3f, var = %3.3f MAX/var=%3.3f\n",
//			pMAXe->pMAX, pMAXe->MAX, pMAXe->average, pMAXe->max2average, pMAXe->var, pMAXe->max2var);
	if(pMAXe->max2var > threshold){
		modinfo_msg("pMAX = %d, MAX = %3.3f, average = %3.3f, MAX/average = %3.3f, var = %3.3f MAX/var = %3.3f \n",
			pMAXe->pMAX, pMAXe->MAX, pMAXe->average, pMAXe->max2average, pMAXe->var, pMAXe->max2var);
		return 1;
	}
	else return 0;
}
Beispiel #12
0
dft_plan_t* generate_new_plan(int dft_size) {
	int i;
	static int oldest_extra_plan = 0;

	modinfo_msg("Warning, no plan was precomputed for size %d. Generating.\n",dft_size);
	for (i=0;i<(MAX_EXTRA_PLANS-1);i++) {
		if (!extra_plans[i].size) {
			if (dft_plan_c2c(dft_size, (!direction)?FORWARD:BACKWARD, &extra_plans[i])) {
				return NULL;
			}
			extra_plans[i].options = options;
			return &extra_plans[i];
		}
	}

	if (oldest_extra_plan == (MAX_EXTRA_PLANS-1)) {
		oldest_extra_plan = 0;
	} else {
		oldest_extra_plan++;
	}
	if (dft_plan_c2c(dft_size, (!direction)?FORWARD:BACKWARD, &extra_plans[oldest_extra_plan])) {
		return NULL;
	}
	extra_plans[oldest_extra_plan].options = options;
	return &extra_plans[oldest_extra_plan];
	/*modinfo_msg("Maximum number of extra plans (%d) surpassed.\n",MAX_EXTRA_PLANS);
	return NULL;*/
}
Beispiel #13
0
int process_params() {
	float _rate,_gain,_freq;
	if (param_get_float(rate_id,&_rate) != 1) {
		modinfo("Getting parameter rate\n");
		return -1;
	}
	if (_rate != rate) {
		rate = _rate;
		_rate = rtdal_dac_set_tx_srate(dac,rate);
		modinfo_msg("Set TX sampling rate %g MHz\n", _rate/1000000);
	}

	if (param_get_float(freq_id,&_freq) != 1) {
		modinfo("Getting parameter freq\n");
		return -1;
	}
	if (_freq != freq) {
		freq = _freq;
		_freq = rtdal_dac_set_tx_freq(dac,freq);
		modinfo_msg("Set TX freq %g MHz\n",_freq/1000000);
	}

	if (gain_id) {
		if (param_get_float(gain_id,&_gain) != 1) {
			modinfo("Getting parameter gain\n");
			return -1;
		}
	} else {
		_gain = 0.0;
	}
	if (_gain != gain) {
		gain = _gain;
		_gain = rtdal_dac_set_tx_gain(dac,gain);
		modinfo_msg("Set TX gain %g dB (%g)\n",_gain,gain);
	}
	if (amp_id) {
		if (param_get_float(amp_id,&amplitude) != 1) {
			modinfo("Getting parameter amplitude\n");
			return -1;
		}
	} else {
		amplitude = 1.0;
	}
	return 0;
}
Beispiel #14
0
int initialize() {
	int tslen;

	if (param_get_int_name("direction",&mode)) {
		mode = MODE_ADD;
	}

	if (param_get_int_name("print_nof_pkts",&print_nof_pkts)) {
		print_nof_pkts = 0;
	} else {
		print_nof_pkts_cnt = 0;
	}

	long_crc_id = param_id("long_crc");
	if (param_get_int(long_crc_id,&long_crc) != 1) {
		modinfo_msg("Parameter long_crc not configured. Set to %d\n",
				DEFAULT_LONG_CRC);
		long_crc = DEFAULT_LONG_CRC;
		long_crc_id = NULL;
	}

	poly_id = param_id("poly");
	if (param_get_int(poly_id,&poly) != 1) {
		poly = DEFAULT_POLY;
		poly_id = NULL;
	}


#ifdef _COMPILE_ALOE
	tslen = oesr_tslot_length(ctx);
	if (tslen > EXEC_MIN_INTERVAL_MS*1000) {
		interval_ts = 1;
	} else {
		interval_ts = (EXEC_MIN_INTERVAL_MS*1000)/tslen;
		modinfo_msg("Timeslot is %d usec, refresh interval set to %d tslots\n",tslen,interval_ts);
	}
#endif
	total_errors=0;
	total_pkts=0;
	tscnt=0;
	return 0;
}
Beispiel #15
0
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;
}
Beispiel #16
0
/**
 * @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;
}
Beispiel #17
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;
}
Beispiel #18
0
dft_plan_t* generate_new_plan(int dft_size) {
	int i;

	modinfo_msg("Warning, no plan was precomputed for size %d. Generating.\n",dft_size);
	for (i=0;i<MAX_EXTRA_PLANS;i++) {
		if (!extra_plans[i].size) {
			if (dft_plan_c2c(dft_size, (!direction)?FORWARD:BACKWARD, &extra_plans[i])) {
				return NULL;
			}
			extra_plans[i].options = options;
			return &extra_plans[i];
		}
	}
	return NULL;
}
Beispiel #19
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;
}
Beispiel #20
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;
}
Beispiel #21
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;
}
Beispiel #22
0
int create_client_upd(char *address, int port, struct sockaddr_in *server) {
	int sockfd,n;

	modinfo_msg("Opening socket to %s:%d\n",address,port);

	sockfd=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
	if (sockfd == -1) {
		perror("socket");
		return -1;
	}
	bzero(server,sizeof(struct sockaddr_in));
	server->sin_family = AF_INET;
	server->sin_addr.s_addr=inet_addr(address);
	server->sin_port=htons(port);

	return sockfd;

}
Beispiel #23
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;
}
Beispiel #24
0
dft_plan_t* generate_new_plan(int dft_size) {
	int i;

	modinfo_msg("Warning, no plan was precomputed for size %d. Generating.\n",dft_size);
	for (i=0;i<MAX_EXTRA_PLANS;i++) {
		if (!extra_plans[i].size) {
			if (is_complex) {
				if (dft_plan_c2r(dft_size, FORWARD, &extra_plans[i])) {
					return NULL;
				}
			} else {
				if (dft_plan_r2r(dft_size, FORWARD, &extra_plans[i])) {
					return NULL;
				}
			}
			extra_plans[i].options = DFT_PSD | DFT_OUT_DB | DFT_NORMALIZE;
			return &extra_plans[i];
		}
	}
	return NULL;
	}
Beispiel #25
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;
}
Beispiel #26
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;
}
Beispiel #27
0
/**
 * @TODO:
 * - re-compute c from N_id_2
 */
int work(void **inp, void **out) {
	int rcv_samples=get_input_samples(0);
	int m0,m1;
	int subframe_idx,N_id_1;
	input_t *input=inp[0];

	if (!rcv_samples) {
		return 0;
	}

	dft_run_c2c(&plan, &input[sss_pos_in_frame], input_fft);

	if (!get_m0m1(&input_fft[sss_pos_in_symbol],&m0,&m1,correlation_threshold)) {
		return 0;
	}

	subframe_idx=decide_subframe(m0,m1);

	N_id_1=decide_N_id_1(m0,m1);

	modinfo_msg("m0=%d, m1=%d subframe=%d\n", m0,m1,subframe_idx,N_id_1);

#ifdef _COMPILE_ALOE

	if (sf_pm_idx >= 0 && !(subframe_idx && first)) {
		first=0;
		if (param_remote_set(out, 0, sf_pm_idx, &subframe_idx,
				sizeof(int))) {
			moderror("Setting parameter\n");
			return -1;
		}
	}
#endif

	return 0;
}
Beispiel #28
0
/**
 * Generates input signal. VERY IMPORTANT to fill length vector with the number of
 * samples that have been generated.
 * @param inp Input interface buffers. Data from other interfaces is stacked in the buffer.
 * Use in(ptr,idx) to access the address.
 *
 * @param lengths Save on n-th position the number of samples generated for the n-th interface
 */
int generate_input_signal(void *in, int *lengths)
{
	int i;
	input_t *input = in;
	int block_length;
	pmid_t blen_id;
	int size;

	blen_id = param_id("block_length");
	if (!blen_id) {
		moderror("Parameter block_length not found\n");
		return -1;
	}
	if (!param_get_int(blen_id,&block_length)) {
		moderror("Getting integer parameter block_length\n");
		return -1;
	}

	modinfo_msg("Parameter block_length is %d\n",block_length);


	/** HERE INDICATE THE LENGTH OF THE SIGNAL */
	lengths[0] = block_length;

	for (i=0;i<block_length;i++) {
		input[i] = 0x1;
	}
	/* UL: test*/
	input[10] = 'x';
	input[11] = 'x';
	input[12] = 'x';
	input[13] = 'x';
	input[14] = 'y';

	return 0;
}
Beispiel #29
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;
}
Beispiel #30
0
/**
 *  Generates input signal. VERY IMPORTANT to fi
--------------------------------------
Avg. processing time 0.011118 msec/frame
*** Plotting signal ***
*** Plotting signal ***

Press ENTER to continue...
 *  ll length vector with the number of
 * samples that have been generated.
 * @param inp Input interface buffers. Data from other interfaces is stacked in the buffer.
 * Use in(ptr,idx) to access the address.
 *
 * @param lengths Save on n-th position the number of samples generated for the n-th interface
 */
int generate_input_signal(void *in, int *lengths)
{
	int k;
	complex_t realchannel [2048];
	input_t *input = in;
	int block_length;
	int err, i, j;
	int nofdm;
	int	Ndlrb;		// Number of PRBs in a downlink ofdm symbol
	int Ncp;		// Cyclic prefix type (1 for normal CP, 0 for extended CP)

	/* Obtain the configuration parameters */
	i = 0;
	while (prms[i].var != NULL){
		if (param_get_int_name((char*) prms[i].name, prms[i].var)) {
			*prms[i].var = prms[i].value;
			modinfo_msg("Test: Parameter %s not defined, setting default %d\n", prms[i].name, *prms[i].var);
		} else {
			modinfo_msg("Test: Parameter %s is %d\n", prms[i].name, *prms[i].var);
		}
		i++;
	}
	modinfo_msg("Test: Parameters have been loaded!\n", NULL);

	/* Generate secondary parameters */
	// Downlink Resource Blocks (RBs)
	if (fftsize == 128){
		Ndlrb = 6;
	} else if (fftsize == 256){
		Ndlrb = 12;
	} else if (fftsize == 512){
		Ndlrb = 25;
	} else if (fftsize == 1024){
		Ndlrb = 50;
	} else if (fftsize == 1536){
		Ndlrb = 75;
	} else if (fftsize == 2048){
		Ndlrb = 100;
	} else {
		moderror("The fft size exceeds the maximum (2048)\n");
	}

	// Number of OFDM symbols per processing TS
	nofdm = Ndlsym*20/fseg;

	block_length=nofdm*fftsize;
	param_get_int_name("block_length",&block_length);

	// Get the Frame configuration for cyclic prefix
	switch (Ndlsym){
		case 7:
			Ncp = 1;
			break;
		case 6:
			Ncp = 0;
			break;
		default:
			moderror_msg("Bad parameter Ndlsym, only valid 6 and 7 (default)\n", NULL);
			break;
	}

	/* Generate RS and map them */
	err = setRefSignals (	Ndlrb,		// Number of PRBs in a downlink ofdm symbol
					Nid,		// Cell identifier number
					Ncp,		// Cyclic prefix
					Ndlsym,		// Number of ODFDM symbols in a downlink slot
					p, 			// Antenna Port (0, 1, 2, 3)
					rs,			// ReferenceNSUBC signals pointer
					rspos,		// Reference signals positions
					fseg		// Frame segmentation that is received each processing TS
				);
	if (err<0) {	// Check if any error occur
		moderror_msg("Bad parameters input in RS initialization (error %d)\n", err);
	} /*else {
		nrs = err/fseg;
	}*/
#define GUARD	((fftsize-12*Ndlrb)/2)

	/* Generate testing channel */
	for (i=0; i<fftsize; i++){
			/*arg = 2*PI*((float)(i%fftsize)/(float)fftsize);
			cosf(arg)+I*sinf(arg);*/
			realchannel[i] = -1.0+1.0*I;
	}
	modinfo_msg("Test: testing channel has been generated.\n", NULL);

	/* Generate test frame */
	k = j = 0;
	for (i = 0; i < block_length; i++){
		/* If reference symbol is allocated */
		if (i == rspos[k]){
			input[i] = rs[k]*realchannel [i%fftsize];
			k++; j++;
		/* If traffic symbol is allocated */
		} else if (i%fftsize>GUARD && i%fftsize<(fftsize-GUARD)){
			input[i] = realchannel [i%fftsize];
		}
		/* If nothing */
		else
			input[i] = 0;
	}

	/** HERE INDICATE THE LENGTH OF THE SIGNAL */
	lengths[0] = block_length;

	modinfo_msg("Test: testing frame size %d has been generated.\n", lengths[0]);

	return 0;
}