Beispiel #1
0
static int net_receive_chan_list(unsigned char *buffer, size_t len)
{
	struct net_chan_list *nc;
	int num_chans = 0;

	if (len < sizeof(struct net_chan_list))
		return 0;

	nc = (struct net_chan_list *)buffer;

	for (int i = 0; i < nc->num_bands; i++) {
		channel_band_add(nc->band[i].num_chans, nc->band[i].max_width,
				 nc->band[i].streams_rx, nc->band[i].streams_tx);
		num_chans += nc->band[i].num_chans;
	}

	if (len < sizeof(struct net_chan_list) + sizeof(unsigned int) * (num_chans - 1))
		return 0;

	for (int i = 0; i < num_chans; i++) {
		channel_list_add(le32toh(nc->freq[i]));
		DEBUG("NET recv freq %d %d\n", i, le32toh(nc->freq[i]));
	}
	init_spectrum();
	return sizeof(struct net_chan_list) + sizeof(unsigned int) * (num_chans - 1);
}
Beispiel #2
0
static int
net_receive_chan_list(unsigned char *buffer, size_t len)
{
	struct net_chan_list *nc;
	int i;

	if (len < sizeof(struct net_chan_list))
		return 0;

	nc = (struct net_chan_list *)buffer;

	if (len < sizeof(struct net_chan_list) + sizeof(struct net_chan_freq)*(nc->num_channels - 1))
		return 0;

	if (nc->num_channels > MAX_CHANNELS) {
		printlog("ERR: server sent too many channels, truncated");
		conf.num_channels = MAX_CHANNELS;
	} else {
		conf.num_channels = nc->num_channels;
	}

	for (i = 0; i < conf.num_channels; i++) {
		channel_set(i, nc->channel[i].chan, le32toh(nc->channel[i].freq));
		DEBUG("NET recv chan %d %d %d\n", i, nc->channel[i].chan, le32toh(nc->channel[i].freq));
	}
	init_spectrum();
	return sizeof(struct net_chan_list) + sizeof(struct net_chan_freq)*(nc->num_channels - 1);
}
Beispiel #3
0
int fes2004_extraction (char *netcdf_filename,int nb_position,double *lat,double *lon,double **amplitude, double **phase,int nb_CPU)
{

  /*####################################################*/
  /* variable*/
  /*####################################################*/
  //classical variables
  int rstatus;
  
  //prediction typedef variables
  spectrum_struct *spectrum=NULL;
  mega_struct *P=NULL;
  
 /*####################################################*/
  /* allocation*/
  /*####################################################*/

  alloc_tide_spectrum(&spectrum);
  P=calloc(nb_CPU,sizeof(mega_struct));
  alloc_extraction_threads(P,nb_CPU);
 
  /*####################################################*/
  /*init prediction spectrum*/
  /*####################################################*/

  rstatus=init_spectrum(spectrum,99);
  if (rstatus != 0 ) print_error_2();  

  /*####################################################*/
  /* load data files*/
  /*####################################################*/

  load_netcdf_fes2004_data(netcdf_filename,P,nb_CPU);
   

  /*####################################################*/
  /*init thread struct*/
  /*####################################################*/

  init_thread_struct(nb_CPU, P, 99, lat, lon, NULL, NULL, spectrum,amplitude,phase);

  /*####################################################*/
  /*Multithreaded extraction*/
  /*####################################################*/
  
   multi_t_extraction( nb_position, nb_CPU, P);

  /*####################################################*/
  /*free memory and exit*/
  /*####################################################*/
   free_threads(P,nb_CPU);
   free(P);

   return 0;
}/*end*/		  
Beispiel #4
0
int main(int argc, char **argv)
{
	pthread_t rtl_thread; 
	pthread_t fm_thread;
	char cert_path[1024];
	char key_path[1024];
	int n = 0;
	int use_ssl = 0;
	struct libwebsocket_context *context;
	int opts = 0;
	char interface_name[128] = "";
	const char *iface = NULL;
	int syslog_options = LOG_PID | LOG_PERROR;
	unsigned int oldus = 0;
	struct lws_context_creation_info info;

	int debug_level = 7;

	memset(&info, 0, sizeof info);
	info.port = PORT;

	rtl_init(DEV_INDEX);
	transfer.buf = NULL;
 	transfer.block_id = 0;

	spectrum = init_spectrum(FFT_POINTS);
        spectrum_temp_buffer = malloc(FFT_POINTS*2*4);
	send_buffer = malloc(LWS_SEND_BUFFER_PRE_PADDING + SEND_BUFFER_SIZE + LWS_SEND_BUFFER_POST_PADDING);
	while (n >= 0) {
		n = getopt_long(argc, argv, "i:hsp:d:Dr:", options, NULL);
		if (n < 0)
			continue;
		switch (n) {
		case 'd':
			debug_level = atoi(optarg);
			break;
		case 's':
			use_ssl = 1;
			break;
		case 'p':
			info.port = atoi(optarg);
			break;
		case 'i':
			strncpy(interface_name, optarg, sizeof interface_name);
			interface_name[(sizeof interface_name) - 1] = '\0';
			iface = interface_name;
			break;
		case 'r':
			resource_path = optarg;
			printf("Setting resource path to \"%s\"\n", resource_path);
			break;
		case 'h':
			fprintf(stderr, "Usage: rtl-ws-server "
					"[--port=<p>] [--ssl] "
					"[-d <log bitfield>] "
					"[--resource_path <path>]\n");
			exit(1);
		}
	}

	signal(SIGINT, sighandler);

	/* we will only try to log things according to our debug_level */
	setlogmask(LOG_UPTO (LOG_DEBUG));
	openlog("lwsts", syslog_options, LOG_DAEMON);

	/* tell the library what debug level to emit and to send it to syslog */
	lws_set_log_level(debug_level, lwsl_emit_syslog);

	info.iface = iface;
	info.protocols = protocols;
	info.extensions = libwebsocket_get_internal_extensions();

	if (!use_ssl) {
		info.ssl_cert_filepath = NULL;
		info.ssl_private_key_filepath = NULL;
	} else {
		if (strlen(resource_path) > sizeof(cert_path) - 32) {
			lwsl_err("resource path too long\n");
			return -1;
		}
		sprintf(cert_path, "%s/libwebsockets-test-server.pem",
								resource_path);
		if (strlen(resource_path) > sizeof(key_path) - 32) {
			lwsl_err("resource path too long\n");
			return -1;
		}
		sprintf(key_path, "%s/libwebsockets-test-server.key.pem",
								resource_path);

		info.ssl_cert_filepath = cert_path;
		info.ssl_private_key_filepath = key_path;
	}
	info.gid = -1;
	info.uid = -1;
	info.options = opts;

	context = libwebsocket_create_context(&info);
	if (context == NULL) {
		lwsl_err("libwebsocket init failed\n");
		return -1;
	}

	n = 0;
	pthread_mutex_init(&data_mutex, NULL);
	pthread_create(&rtl_thread, NULL, rtl_worker, NULL);
	pthread_create(&fm_thread, NULL, fm_worker, NULL);

	while (n >= 0 && !force_exit) {
		n = libwebsocket_service(context, 50);
	}
	force_exit = 1;
	usleep(100);

	libwebsocket_context_destroy(context);

	lwsl_notice("rtl-ws-server exited\n");

	closelog();

	rtl_close();

	pthread_mutex_destroy(&data_mutex);
	pthread_exit(NULL);

	if (transfer.buf != NULL) {
		free(transfer.buf);
		transfer.buf = NULL;
		transfer.block_id = 0;
	}

	free(send_buffer);
	free_spectrum(spectrum);
    free(spectrum_temp_buffer);
	return 0;
}