Ejemplo n.º 1
0
/*----------------------------------------------------------------------------------------------*/
void Parse_Arguments(int32 argc, char* argv[])
{

	int32 lcv;

	/* Set default options */
	gopt.verbose 		= 0;
	gopt.realtime 		= 1;
	gopt.post_process 	= 0;
	gopt.ocean 			= 0;
	gopt.log_channel 	= 0;
	gopt.log_nav		= 0;
	gopt.log_decimate	= 1;
	gopt.google_earth	= 0;
	gopt.ncurses 		= 1;
	gopt.gui			= 0;
	gopt.serial			= 0;
	gopt.doppler_min 	= -MAX_DOPPLER;
	gopt.doppler_max 	= MAX_DOPPLER;
	gopt.corr_sleep 	= 500;
	gopt.startup		= COLD_START;
	gopt.usrp_internal	= 0;
	strcpy(gopt.filename_direct, "data.bda");
	strcpy(gopt.filename_reflected, "rdata.bda");

	for(lcv = 1; lcv < argc; lcv++)
	{
		if(strcmp(argv[lcv],"-p") == 0)
		{
			gopt.post_process = 1;
			gopt.realtime = 0;
			gopt.ocean = 0;
			gopt.corr_sleep = 100;

			if(argc < lcv+2)
				usage(argc, argv);

			strcpy(gopt.filename_direct, argv[lcv+1]);
			lcv += 1;
		}
		else if(strcmp(argv[lcv],"-o") == 0)
		{
			gopt.post_process = 0;
			gopt.realtime = 0;
			gopt.ocean = 1;

			if(argc < lcv+3)
				usage(argc, argv);

			strcpy(gopt.filename_direct, argv[lcv+1]);
			strcpy(gopt.filename_reflected, argv[lcv+2]);
			lcv += 2;
		}
		else if(strcmp(argv[lcv],"-v") == 0)
		{
			gopt.verbose = 1;
		}
		else if(strcmp(argv[lcv],"-d") == 0)
		{
			if(isdigit(argv[lcv+1][0]))
			{
				lcv++;
				gopt.log_decimate = atoi(argv[lcv]);
			}
			else
			{
				usage(argc, argv);
			}
		}
		else if(strcmp(argv[lcv],"-c") == 0)
		{
			gopt.log_channel = 1;
		}
		else if(strcmp(argv[lcv],"-l") == 0)
		{
			gopt.log_nav = 1;
		}
		else if(strcmp(argv[lcv],"-g") == 0)
		{
			gopt.google_earth = 1;
		}
		else if(strcmp(argv[lcv],"-n") == 0)
		{
			gopt.ncurses = 0;
		}
		else if(strcmp(argv[lcv],"-w") == 0)
		{
			gopt.startup = WARM_START;
		}
		else if(strcmp(argv[lcv],"-gui") == 0)
		{
			gopt.gui = 1;
			gopt.serial = 0;
			gopt.ncurses = 0;
		}
		else if(strcmp(argv[lcv],"-ser") == 0)
		{
			gopt.serial = 1;
			gopt.gui = 0;
			gopt.ncurses = 0;
			gopt.log_decimate = 10;
		}
		else if(strcmp(argv[lcv],"-u") == 0)
		{
			gopt.usrp_internal = 1;
		}
		else
			usage(argc, argv);
	}

	echo_options();

}
Ejemplo n.º 2
0
/*----------------------------------------------------------------------------------------------*/
void Parse_Arguments(int32 argc, char* argv[])
{

	char *parse;
	int32 lcv;


	/* Set default options */
	gopt.verbose 		= 0;
	gopt.log_channel 	= 0;
	gopt.tlm_type		= TELEM_NAMED_PIPE;
	gopt.mode 			= 0;		//!< Single board L1 mode by default
	gopt.decimate		= 16;		//!< Default to work with both 65.536 and 64 MHz clocks
	gopt.gr 			= 40; 		//!< 40 dB of RF gain
	gopt.gi 			= 10; 		//!< 10 dB of IF gain
	gopt.f_lo_a 		= L1 - IF_FREQUENCY;	//!< Board A L1 by default
	gopt.f_ddc_a 		= 0;		//!< no DDC correction
	gopt.f_lo_b			= L2 - IF_FREQUENCY;	//!< Board B L2 by default
	gopt.f_ddc_b 		= 0;		//!< no DDC correction
	gopt.bandwidth 		= 6.0e6; 	//!< DBS-RX is set to 10 MHz wide
	gopt.f_sample 		= 64.0e6;	//!< Nominal sample rate
	gopt.realtime		= 1;
	gopt.source			= SOURCE_USRP_V1;
	gopt.recorder = 0;

	for(lcv = 1; lcv < argc; lcv++)
	{
		switch(argv[lcv][1])
		{

			case 'c':
				gopt.log_channel = 1;
				break;
			case 'v':
				gopt.verbose = 1;
				break;
			case 'g':
				if(argv[lcv][2] == 'r')
				{
					if(++lcv >= argc)
						usage (argv[0]);

					if(isdigit(argv[lcv][0]))
						gopt.gr = strtod(argv[lcv], &parse);
					else
						usage (argv[0]);
					break;
				}
				else if(argv[lcv][2] == 'i')
				{
					if(++lcv >= argc)
						usage (argv[0]);

					if(isdigit(argv[lcv][0]))
						gopt.gi = strtod(argv[lcv], &parse);
					else
						usage (argv[0]);
					break;
				}
				else if(strcmp(argv[lcv], "-gn3s") == 0)
				{
					gopt.source	= SOURCE_SIGE_GN3S;
				}
				else
					usage(argv[0]);
				break;
//			case 'd':
//				gopt.mode = 1;
//				break;
			case 'l':
				gopt.mode = 1;
				gopt.f_lo_b = L2- IF_FREQUENCY; /* L2C center frequency */
				
				break;
			case 'w':
				if(++lcv >= argc)
					usage (argv[0]);

				if(isdigit(argv[lcv][0]))
					gopt.bandwidth = strtod(argv[lcv], &parse);
				else
					usage (argv[0]);
				break;
			case 'x':
				gopt.f_sample = 65.536e6;
				break;
			case 's':
				gopt.tlm_type = TELEM_SERIAL;
				break;

			case 'f':
				gopt.source	= SOURCE_FILE;
				if(argc < lcv+3)
				usage (argv[0]);
				gopt.mode =1; 
				strcpy(gopt.file_name_1, argv[lcv+1]);
				strcpy(gopt.file_name_2, argv[lcv+2]);
				lcv += 2;
				break;
			case 'p':
				gopt.source	= SOURCE_FILE;
				if(argc < lcv+2)
				usage (argv[0]);

				strcpy(gopt.file_name_1, argv[lcv+1]);

				lcv += 1;	
				break;
			case 'r':
				gopt.recorder=1;
				break;


			default:
				usage(argv[0]);
		}
	}

	echo_options();

}
Ejemplo n.º 3
0
const int salad_predict_stub(const config_t* const c, const data_processor_t* const dp, file_t* const fIn, FILE* const fOut)
{
	salad_header("Predict scores of", &fIn->meta, c);
	SALAD_T(good);
	SALAD_T(bad);

	if (salad_from_file_v("training", c->bloom, &good) != EXIT_SUCCESS)
	{
		return EXIT_FAILURE;
	}


	if (c->bbloom)
	{
		if (salad_from_file_v("bad content", c->bbloom, &bad) != EXIT_SUCCESS)
		{
			salad_destroy(&good);
			return EXIT_FAILURE;
		}

		if (salad_spec_diff(&good, &bad))
		{
			salad_destroy(&good);
			salad_destroy(&bad);
			status("The normal and the bad content filter were not generated with the same parameters.");
			return EXIT_FAILURE;
		}
		// XXX: Just checking the validity of the model ;)
		// GET_BLOOMFILTER(bad.model);
		assert(bad.model.type == SALAD_MODEL_BLOOMFILTER);
	}

	// TODO: right now there only are bloom filters!
	BLOOM* const good_model = GET_BLOOMFILTER(good.model);
	BLOOM* const bad_model = TO_BLOOMFILTER(bad.model);


	if (c->echo_params)
	{
		config_t cfg;
		cfg.ngramLength = good.ngramLength;
		cfg.filter_size = log2(good_model->bitsize);

		switch (bloomfct_cmp(good_model, HASHSET_SIMPLE, HASHSET_MURMUR))
		{
		case 0:
			cfg.hash_set = HASHES_SIMPLE;
			break;
		case 1:
			cfg.hash_set = HASHES_MURMUR;
			break;
		default:
			cfg.hash_set = HASHES_UNDEFINED;
			break;
		}

		STRDUP(good.delimiter.str, cfg.delimiter);
		echo_options(&cfg);
		free(cfg.delimiter);
	}

	FN_ANACHECK anacheck = (bad_model == NULL ?
			(good.useWGrams ? anacheckw_ex_wrapper  : anacheck_ex_wrapper) :
			(good.useWGrams ? anacheckw_ex2_wrapper : anacheck_ex2_wrapper));

	predict_t context = {
			.fct = anacheck,
			.param = {good_model, bad_model, good.ngramLength, good.delimiter.d},
			.config = c,
			// TODO: we do not know the batch size of the recv function
			.scores = (float*) calloc(c->batch_size, sizeof(float)),
			.fOut = fOut,
			.totalTime = 0.0
	};

	dp->recv(fIn, salad_predict_callback, c->batch_size, &context);
	free(context.scores);

#ifdef USE_NETWORK
	if (c->input_type != NETWORK)
#endif
	{
		info("Net calculation time: %.4f seconds", context.totalTime);

		const double size = ((double)fIn->meta.total_size) /(1024*1024 /8);
		const double throughput = size/ context.totalTime;

		if (!isinf(throughput))
		{
			info("Net throughput: %.3f Mb/s", throughput);
		}
	}

	if (bad_model != NULL)
	{
		salad_destroy(&bad);
	}
	salad_destroy(&good);
	return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
const saladstate_t parse_traininglike_options_ex(int argc, char* argv[], config_t* const config,
		const char *shortopts, const struct option *longopts)
{
	assert(argv != NULL);
	assert(config != NULL);

	int option, bs = FALSE, fo = FALSE;
	while ((option = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
	{
		switch (option)
		{
		case 'i':
			config->input = optarg;
			break;

		case 'f':
			config->input_type = as_iomode(optarg);
			break;

		case OPTION_INPUTFILTER:
			config->input_filter = optarg;
			break;

		case OPTION_BATCHSIZE:
		{
			int batch_size = atoi(optarg); // TODO: strtol
			if (batch_size <= 0)
			{
				warn("Illegal batch size specified.\n");
				// This is not true in case of network data as input. Therefore,
				// we simply suppress this output at this point.
				// warn("Defaulting to: %u\n", (unsigned int) config->batch_size);
			}
			else
			{
				bs = TRUE;
				config->batch_size = batch_size;
			}
			break;
		}
#ifdef USE_NETWORK
		case 'p':
			config->pcap_filter = optarg;
			break;
#endif
		case 'b':
			config->bloom = optarg;
			break;

		case 'u':
			config->update_model = TRUE;
			break;

		case 'o':
			config->output = optarg;
			break;

		case 'n':
		{
			fo = TRUE;
			int ngramLength = atoi(optarg); // TODO: strtol
			if (ngramLength <= 0)
			{
				warn("Illegal n-gram length specified.");
				warn("Defaulting to: %u\n", (unsigned int) config->ngramLength);
			}
			else config->ngramLength = ngramLength;
			break;
		}
		case 'd':
			fo = TRUE;
			config->delimiter = optarg;
			break;

		case 's':
		{
			fo = TRUE;
			int filter_size = atoi(optarg); // TODO: strtol
			if (filter_size <= 0)
			{
				warn("Illegal filter size specified.");
				warn("Defaulting to: %u\n", (unsigned int) config->filter_size);
			}
			else config->filter_size = filter_size;
			break;
		}
		case OPTION_HASHSET:
		{
			fo = TRUE;
			hashset_t hashset = to_hashset(optarg);
			if (hashset == HASHES_UNDEFINED)
			{
				warn("Illegal hash set specified.");
				warn("Defaulting to: %s\n", hashset_to_string(config->hash_set));
			}
			else config->hash_set = hashset;
			break;
		}
		case 'e':
			config->echo_params = TRUE;
			break;

		case '?':
		case 'h':
			return SALAD_HELP_TRAIN;

		default:
			// In order to catch program argument that correspond to
			// features that were excluded at compile time.
			fprintf(stderr, "invalid option -- '%c'\n", option);
			return SALAD_HELP_TRAIN;
		}
	}

	config->transfer_spec = !fo;

	if (check_input(config, TRUE, bs) == EXIT_FAILURE) return SALAD_EXIT;
	if (check_output(config) == EXIT_FAILURE) return SALAD_EXIT;

	if (config->echo_params)
	{
		if (config->update_model && config->transfer_spec) {
			// cf. salad_train_stub
		} else {
			echo_options(config);
		}
	}
	return SALAD_RUN;
}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: chwress/salad
const saladstate_t parse_traininglike_options_ex(int argc, char* argv[], config_t* const config,
		const char *shortopts, const struct option *longopts)
{
	assert(argv != NULL);
	assert(config != NULL);

	char* end; // For parsing numbers with strto*
	int conly = FALSE, sonly = FALSE;

	int option, bs = FALSE, fo = FALSE;
	while ((option = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
	{
		switch (option)
		{
		case 'i':
			config->input = optarg;
			break;

		case 'f':
			config->input_type = as_inputmode(optarg);
			break;

		case OPTION_INPUTFILTER:
			config->input_filter = optarg;
			break;

		case OPTION_BATCHSIZE:
		{
			const long long int batch_size = strtoll(optarg, &end, 10);
			if (batch_size <= 0)
			{
				warn("Illegal batch size specified.\n");
				// This is not true in case of network data as input. Therefore,
				// we simply suppress this output at this point.
				// warn("Defaulting to: %u\n", (unsigned int) config->batch_size);
			}
			else
			{
				bs = TRUE;
				config->batch_size = (size_t) MIN(SIZE_MAX, (unsigned long) MAX(0, batch_size));
			}
			break;
		}

#ifdef USE_NETWORK
		case 'p':
			config->pcap_filter = optarg;
			break;

		case OPTION_NETCLIENT:
			conly = TRUE;
			break;

		case OPTION_NETSERVER:
			sonly = TRUE;
			break;
#endif
		case 'b':
			config->bloom = optarg;
			break;

		case 'u':
			config->update_model = TRUE;
			break;

		case 'o':
			config->output = optarg;
			break;

		case 'F':
			config->output_type = as_outputmode(optarg);
			break;

		case 'n':
		{
			fo = TRUE;
			const long long int ngram_length = strtoll(optarg, &end, 10);
			if (ngram_length <= 0)
			{
				warn("Illegal n-gram length specified.");
				warn("Defaulting to: %"ZU"\n", (SIZE_T) config->ngram_length);
			}
			else config->ngram_length = (size_t) MIN(SIZE_MAX, (unsigned long) ngram_length);
			break;
		}
		case 'd':
			fo = TRUE;
			config->delimiter = optarg;
			break;

		case OPTION_BINARY:
			config->binary_ngrams = TRUE;
			break;

		case 's':
		{
			fo = TRUE;
			const long long int filter_size = strtoll(optarg, &end, 10);
			if (filter_size <= 0)
			{
				warn("Illegal filter size specified.");
				warn("Defaulting to: %u\n", (unsigned int) config->filter_size);
			}
			else config->filter_size = (unsigned int) MIN(UINT_MAX, (unsigned long) MAX(0, filter_size));
			break;
		}
		case OPTION_HASHSET:
		{
			fo = TRUE;
			hashset_t hashset = to_hashset(optarg);
			if (hashset == HASHES_UNDEFINED)
			{
				warn("Illegal hash set specified.");
				warn("Defaulting to: %s\n", hashset_to_string(config->hash_set));
			}
			else config->hash_set = hashset;
			break;
		}
		case 'e':
			config->echo_params = TRUE;
			break;

		case 'q':
			log_level = WARNING;
			break;

		case '?':
		case 'h':
			log_level = STATUS;
			return SALAD_HELP_TRAIN;

		default:
			// In order to catch program argument that correspond to
			// features that were excluded at compile time.
			fprintf(stderr, "invalid option -- '%c'\n", option);
			return SALAD_HELP_TRAIN;
		}
	}

	config->transfer_spec = !fo;

	if (config->binary_ngrams && config->ngram_length > MASK_BITSIZE)
	{
		error("When using binary n-grams currently only a maximal");
		error("length of %u bits is supported.", MASK_BITSIZE);
		return SALAD_EXIT;
	}

	if (check_netparams(config, conly, sonly) == EXIT_FAILURE) return SALAD_HELP_TRAIN;
	if (check_input(config, TRUE, bs) == EXIT_FAILURE) return SALAD_EXIT;
	if (check_output(config) == EXIT_FAILURE) return SALAD_EXIT;

	if (config->echo_params)
	{
		if (config->update_model && config->transfer_spec) {
			// cf. salad_train_stub
		} else {
			echo_options(config);
		}
	}
	return SALAD_RUN;
}