int main(int argc, char **argv)
{
	/* Se prezinta etapele cronologice ale simularii unei retele de rutere prin
	implementarea unui program care va fi capabil sa ruleze un algoritm de rutare SPF
	(shortest path first) minimalist si sa se adapteze la schimbarile din retea in cadrul
	aceluiasi algoritm si sa ruteze o serie de mesaje date ca input. Se pot adauga sau
	sterge legaturi in retea */
	
	int noRouters;
	ifstream infile(argv[1]);
	infile >> noRouters;
	

	init_api(argc, argv);
	init_sim(argc, argv);

	loop {
		trigger_events();
		process_messages(noRouters);
		update_routing_table(noRouters);
		api_update_state();
		if (api_simulation_ended())
			break;
	}

	clean_sim();
	clean_api();
	
	return 0;
}
Example #2
0
int main(int ac, char** av)
{
	instr_t*	imem;
	int		imem_size;
	int		yyparse();
	int		yylex_destroy();

	progname = av[0];
	output = stdout;

	init_func();
	init_instr();
	init_stmt();
	init_sim();

	params(ac, av);

	if (yyin == NULL) {
		warning("no input file");
		exit(0);	
	}
		
	if (cfg_fp == NULL)
		yyparse();
	
	fclose(yyin);
	yylex_destroy();

	opt();

	if (cfg_fp != NULL)
		exit(0);

	imem = stmt2instr(&imem_size);

	free_func();
	deinit_symtab();
	deinit_sym();

	set_dmem_size(100000);
	set_imem(imem, imem_size);
	set_regs(32);

	run(); 

	print_stats();
		
	free_sim();

	if (output != NULL)
		fclose(output);

	if (yyin != NULL)
		fclose(yyin);

	return 0;
}
Example #3
0
int main(int argc,char *argv[]){
if(argc==4){
sscanf(argv[3],"%d",&stop_ins);
}
init_sim();
int program_start= load_program(argv[1]);
printf("\n");
start_cpu();
return 0;
}
Example #4
0
int main()
{
    if (!init_sim())
        return 1;

    chewing_test_Main();

    {
        printf("_________________________________________________________________________\n" "[ Report ]\n");
        printf("Checks: %d words,  Failures: %d words\n", tested_word_count, failed_word_count);
        printf("Ratio: %.2f%%\n", (float) (tested_word_count - failed_word_count) / tested_word_count * 100);
    }

    fini_sim();
    return 0;
}
Example #5
0
int halide_hexagon_remote_initialize_kernels(const unsigned char *code, int codeLen,
                                             handle_t *module_ptr) {
    int ret = init_sim();
    if (ret != 0) return -1;

    // Copy the pointer arguments to the simulator.
    remote_buffer remote_code(code, codeLen);
    remote_buffer remote_module_ptr(module_ptr, 4);

    // Run the init kernels command.
    ret = send_message(Message::InitKernels, {remote_code.data, codeLen, remote_module_ptr.data});
    if (ret != 0) return ret;

    // Get the module ptr.
    ret = read_memory(module_ptr, remote_module_ptr.data, 4);

    return ret;
}
Example #6
0
int main(int argc, char **argv)
{
	Network network; // pastreaza informatii despre intreaga retea

	init_api(argc, argv);
	init_sim(&network, argv);

	loop {
		trigger_events(&network);
		process_messages(&network);
		update_routing_table(&network);
		api_update_state();
		if (api_simulation_ended())
			break;
	}

	clean_sim(&network);
	clean_api();

	return 0;
}
Example #7
0
void calculate_signal_lengths(struct ir_remote *remote)
{
	if(is_const(remote))
	{
		remote->min_total_signal_length = min_gap(remote);
		remote->max_total_signal_length = max_gap(remote);
	}
	else
	{
		remote->min_gap_length = min_gap(remote);
		remote->max_gap_length = max_gap(remote);
	}

	lirc_t min_signal_length = 0, max_signal_length = 0;
	lirc_t max_pulse = 0, max_space = 0;
	int first_sum = 1;
	struct ir_ncode *c = remote->codes;
	int i;

	while(c->name)
	{
		struct ir_ncode code = *c;
		struct ir_code_node *next = code.next;
		int first = 1;
		int repeat = 0;
		do{
			if(first)
			{
				first = 0;
			}
			else
			{
				code.code = next->code;
				next = next->next;
			}
			for(repeat = 0; repeat < 2; repeat++)
			{
				if(init_sim(remote, &code, repeat))
				{
					lirc_t sum = send_buffer.sum;

					if(sum)
					{
						if(first_sum ||
						   sum < min_signal_length)
						{
							min_signal_length = sum;
						}
						if(first_sum ||
						   sum > max_signal_length)
						{
							max_signal_length = sum;
						}
						first_sum = 0;
					}
					for(i=0; i<send_buffer.wptr; i++)
					{
						if(i&1) /* space */
						{
							if(send_buffer.data[i] > max_space)
							{
								max_space = send_buffer.data[i];
							}
						}
						else /* pulse */
						{
							if(send_buffer.data[i] > max_pulse)
							{
								max_pulse = send_buffer.data[i];
							}
						}
					}
				}
			}
		} while(next);
		c++;
	}
	if(first_sum)
	{
		/* no timing data, so assume gap is the actual total
		   length */
		remote->min_total_signal_length = min_gap(remote);
		remote->max_total_signal_length = max_gap(remote);
		remote->min_gap_length = min_gap(remote);
		remote->max_gap_length = max_gap(remote);
	}
	else if(is_const(remote))
	{
		if(remote->min_total_signal_length > max_signal_length)
		{
			remote->min_gap_length =
				remote->min_total_signal_length
				- max_signal_length;
		}
		else
		{
			logprintf(LOG_WARNING, "min_gap_length is 0 for "
				  "'%s' remote", remote->name);
			remote->min_gap_length = 0;
		}
		if(remote->max_total_signal_length > min_signal_length)
		{
			remote->max_gap_length =
				remote->max_total_signal_length
				- min_signal_length;
		}
		else
		{
			logprintf(LOG_WARNING, "max_gap_length is 0 for "
				  "'%s' remote", remote->name);
			remote->max_gap_length = 0;
		}
	}
	else
	{
		remote->min_total_signal_length = min_signal_length +
			remote->min_gap_length;
		remote->max_total_signal_length = max_signal_length +
			remote->max_gap_length;
	}
	LOGPRINTF(1, "lengths: %lu %lu %lu %lu",
		  remote->min_total_signal_length,
		  remote->max_total_signal_length,
		  remote->min_gap_length,
		  remote->max_gap_length);
}
Example #8
0
int main(int argc, char *argv[])
{
	sim_t s;
	char *devstr = NULL;
	int c;

	int result;
	double duration;
	datetime_t t0;

	if (argc<3)
	{
		usage();
		exit(1);
	}

	s.opt.navfile[0] = 0;
	s.opt.umfile[0] = 0;
	s.opt.g0.week = -1;
	s.opt.g0.sec = 0.0;
	s.opt.iduration = USER_MOTION_SIZE;
	s.opt.verb = TRUE;
	s.opt.nmeaGGA = FALSE;
	s.opt.staticLocationMode = TRUE; // default user motion
	s.opt.llh[0] = 35.274016 / R2D;
	s.opt.llh[1] = 137.013765 / R2D;
	s.opt.llh[2] = 100.0;

	while ((result=getopt(argc,argv,"e:u:g:l:t:d:"))!=-1)
	{
		switch (result)
		{
		case 'e':
			strcpy(s.opt.navfile, optarg);
			break;
		case 'u':
			strcpy(s.opt.umfile, optarg);
			s.opt.nmeaGGA = FALSE;
			s.opt.staticLocationMode = FALSE;
			break;
		case 'g':
			strcpy(s.opt.umfile, optarg);
			s.opt.nmeaGGA = TRUE;
			s.opt.staticLocationMode = FALSE;
			break;
		case 'l':
			// Static geodetic coordinates input mode
			// Added by [email protected]
			s.opt.nmeaGGA = FALSE;
			s.opt.staticLocationMode = TRUE;
			sscanf(optarg,"%lf,%lf,%lf",&s.opt.llh[0],&s.opt.llh[1],&s.opt.llh[2]);
			s.opt.llh[0] /= R2D; // convert to RAD
			s.opt.llh[1] /= R2D; // convert to RAD
			break;
		case 't':
			sscanf(optarg, "%d/%d/%d,%d:%d:%lf", &t0.y, &t0.m, &t0.d, &t0.hh, &t0.mm, &t0.sec);
			if (t0.y<=1980 || t0.m<1 || t0.m>12 || t0.d<1 || t0.d>31 ||
				t0.hh<0 || t0.hh>23 || t0.mm<0 || t0.mm>59 || t0.sec<0.0 || t0.sec>=60.0)
			{
				printf("ERROR: Invalid date and time.\n");
				exit(1);
			}
			t0.sec = floor(t0.sec);
			date2gps(&t0, &s.opt.g0);
			break;
		case 'd':
			duration = atof(optarg);
			if (duration<0.0 || duration>((double)USER_MOTION_SIZE)/10.0)
			{
				printf("ERROR: Invalid duration.\n");
				exit(1);
			}
			s.opt.iduration = (int)(duration*10.0+0.5);
			break;
		case ':':
		case '?':
			usage();
			exit(1);
		default:
			break;
		}
	}

	if (s.opt.navfile[0]==0)
	{
		printf("ERROR: GPS ephemeris file is not specified.\n");
		exit(1);
	}

	if (s.opt.umfile[0]==0 && !s.opt.staticLocationMode)
	{
		printf("ERROR: User motion file / NMEA GGA stream is not specified.\n");
		printf("You may use -l to specify the static location directly.\n");
		exit(1);
	}

	// Initialize simulator
	init_sim(&s);

	// Allocate TX buffer to hold each block of samples to transmit.
	s.tx.buffer = (int16_t *)malloc(SAMPLES_PER_BUFFER * sizeof(int16_t) * 2); // for 16-bit I and Q samples
	
	if (s.tx.buffer == NULL) {
		fprintf(stderr, "Failed to allocate TX buffer.\n");
		goto out;
	}

	// Allocate FIFOs to hold 0.1 seconds of I/Q samples each.
	s.fifo = (int16_t *)malloc(FIFO_LENGTH * sizeof(int16_t) * 2); // for 16-bit I and Q samples

	if (s.fifo == NULL) {
		fprintf(stderr, "Failed to allocate I/Q sample buffer.\n");
		goto out;
	}

	// Initializing device.
	printf("Opening and initializing device...\n");

	s.status = bladerf_open(&s.tx.dev, devstr);
	if (s.status != 0) {
		fprintf(stderr, "Failed to open device: %s\n", bladerf_strerror(s.status));
		goto out;
	}

	s.status = bladerf_set_frequency(s.tx.dev, BLADERF_MODULE_TX, TX_FREQUENCY);
	if (s.status != 0) {
		fprintf(stderr, "Faield to set TX frequency: %s\n", bladerf_strerror(s.status));
		goto out;
	} 
	else {
		printf("TX frequency: %u Hz\n", TX_FREQUENCY);
	}

	s.status = bladerf_set_sample_rate(s.tx.dev, BLADERF_MODULE_TX, TX_SAMPLERATE, NULL);
	if (s.status != 0) {
		fprintf(stderr, "Failed to set TX sample rate: %s\n", bladerf_strerror(s.status));
		goto out;
	}
	else {
		printf("TX sample rate: %u sps\n", TX_SAMPLERATE);
	}

	s.status = bladerf_set_bandwidth(s.tx.dev, BLADERF_MODULE_TX, TX_BANDWIDTH, NULL);
	if (s.status != 0) {
		fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(s.status));
		goto out;
	}
	else {
		printf("TX bandwidth: %u Hz\n", TX_BANDWIDTH);
	}

	s.status = bladerf_set_txvga1(s.tx.dev, TX_VGA1);
	if (s.status != 0) {
		fprintf(stderr, "Failed to set TX VGA1 gain: %s\n", bladerf_strerror(s.status));
		goto out;
	}
	else {
		printf("TX VGA1 gain: %d dB\n", TX_VGA1);
	}

	s.status = bladerf_set_txvga2(s.tx.dev, TX_VGA2);
	if (s.status != 0) {
		fprintf(stderr, "Failed to set TX VGA2 gain: %s\n", bladerf_strerror(s.status));
		goto out;
	}
	else {
		printf("TX VGA2 gain: %d dB\n", TX_VGA2);
	}

	// Start GPS task.
	s.status = start_gps_task(&s);
	if (s.status < 0) {
		fprintf(stderr, "Failed to start GPS task.\n");
		goto out;
	}
	else
		printf("Creating GPS task...\n");

	// Wait until GPS task is initialized
	pthread_mutex_lock(&(s.tx.lock));
	while (!s.gps.ready)
		pthread_cond_wait(&(s.gps.initialization_done), &(s.tx.lock));
	pthread_mutex_unlock(&(s.tx.lock));

	// Fillfull the FIFO.
	if (is_fifo_write_ready(&s))
		pthread_cond_signal(&(s.fifo_write_ready));

	// Configure the TX module for use with the synchronous interface.
	s.status = bladerf_sync_config(s.tx.dev,
			BLADERF_MODULE_TX,
			BLADERF_FORMAT_SC16_Q11,
			NUM_BUFFERS,
			SAMPLES_PER_BUFFER,
			NUM_TRANSFERS,
			TIMEOUT_MS);

	if (s.status != 0) {
		fprintf(stderr, "Failed to configure TX sync interface: %s\n", bladerf_strerror(s.status));
		goto out;
	}

	// We must always enable the modules *after* calling bladerf_sync_config().
	s.status = bladerf_enable_module(s.tx.dev, BLADERF_MODULE_TX, true);
	if (s.status != 0) {
		fprintf(stderr, "Failed to enable TX module: %s\n", bladerf_strerror(s.status));
		goto out;
	}

	// Start TX task
	s.status = start_tx_task(&s);
	if (s.status < 0) {
		fprintf(stderr, "Failed to start TX task.\n");
		goto out;
	}
	else
		printf("Creating TX task...\n");

	// Running...
	printf("Running...\n");
	printf("Press 'q' to exit.\n");
	while (1) {
		c = _getch();
		if (c=='q')
			break;
	}

	//
	// TODO: Cleaning up the threads properly.
	//

	printf("\nDone!\n");

	// Disable TX module, shutting down our underlying TX stream.
	s.status = bladerf_enable_module(s.tx.dev, BLADERF_MODULE_TX, false);
	if (s.status != 0) {
		fprintf(stderr, "Failed to disable TX module: %s\n", bladerf_strerror(s.status));
	}

out:
	// Free up resources
	if (s.tx.buffer != NULL)
		free(s.tx.buffer);

	if (s.fifo != NULL)
		free(s.fifo);

	printf("Closing device...\n");
	bladerf_close(s.tx.dev);

	return(0);
}
Example #9
0
int main(int argc, char *argv[])
{
	sim_t s;
	char *devstr = NULL;
	int c;

	// Initialize structures
	init_sim(&s);

	// Allocate TX buffer to hold each block of samples to transmit.
	s.tx.buffer = (int16_t *)malloc(SAMPLES_PER_BUFFER * sizeof(int16_t) * 2); // for 16-bit I and Q samples
	
	if (s.tx.buffer == NULL) {
		fprintf(stderr, "Failed to allocate TX buffer.\n");
		goto out;
	}

	// Allocate FIFOs to hold 0.1 seconds of I/Q samples each.
	s.fifo = (int16_t *)malloc(FIFO_LENGTH * sizeof(int16_t) * 2); // for 16-bit I and Q samples

	if (s.fifo == NULL) {
		fprintf(stderr, "Failed to allocate I/Q sample buffer.\n");
		goto out;
	}

	// Initializing device.
	printf("Opening and initializing device...\n");

	s.status = bladerf_open(&s.tx.dev, devstr);
	if (s.status != 0) {
		fprintf(stderr, "Failed to open device: %s\n", bladerf_strerror(s.status));
		goto out;
	}

	s.status = bladerf_set_frequency(s.tx.dev, BLADERF_MODULE_TX, TX_FREQUENCY);
	if (s.status != 0) {
		fprintf(stderr, "Faield to set TX frequency: %s\n", bladerf_strerror(s.status));
		goto out;
	} 
	else {
		printf("TX frequency: %u Hz\n", TX_FREQUENCY);
	}

	s.status = bladerf_set_sample_rate(s.tx.dev, BLADERF_MODULE_TX, TX_SAMPLERATE, NULL);
	if (s.status != 0) {
		fprintf(stderr, "Failed to set TX sample rate: %s\n", bladerf_strerror(s.status));
		goto out;
	}
	else {
		printf("TX sample rate: %u sps\n", TX_SAMPLERATE);
	}

	s.status = bladerf_set_bandwidth(s.tx.dev, BLADERF_MODULE_TX, TX_BANDWIDTH, NULL);
	if (s.status != 0) {
		fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(s.status));
		goto out;
	}
	else {
		printf("TX bandwidth: %u Hz\n", TX_BANDWIDTH);
	}

	s.status = bladerf_set_txvga1(s.tx.dev, TX_VGA1);
	if (s.status != 0) {
		fprintf(stderr, "Failed to set TX VGA1 gain: %s\n", bladerf_strerror(s.status));
		goto out;
	}
	else {
		printf("TX VGA1 gain: %d dB\n", TX_VGA1);
	}

	s.status = bladerf_set_txvga2(s.tx.dev, TX_VGA2);
	if (s.status != 0) {
		fprintf(stderr, "Failed to set TX VGA2 gain: %s\n", bladerf_strerror(s.status));
		goto out;
	}
	else {
		printf("TX VGA2 gain: %d dB\n", TX_VGA2);
	}

	// Start GPS task.
	s.status = start_gps_task(&s);
	if (s.status < 0) {
		fprintf(stderr, "Failed to start GPS task.\n");
		goto out;
	}
	else
		printf("Creating GPS task...\n");

	// Wait until GPS task is initialized
	pthread_mutex_lock(&(s.tx.lock));
	while (!s.gps.ready)
		pthread_cond_wait(&(s.gps.initialization_done), &(s.tx.lock));
	pthread_mutex_unlock(&(s.tx.lock));

	// Fillfull the FIFO.
	if (is_fifo_write_ready(&s))
		pthread_cond_signal(&(s.fifo_write_ready));

	// Configure the TX module for use with the synchronous interface.
	s.status = bladerf_sync_config(s.tx.dev,
			BLADERF_MODULE_TX,
			BLADERF_FORMAT_SC16_Q11,
			NUM_BUFFERS,
			SAMPLES_PER_BUFFER,
			NUM_TRANSFERS,
			TIMEOUT_MS);

	if (s.status != 0) {
		fprintf(stderr, "Failed to configure TX sync interface: %s\n", bladerf_strerror(s.status));
		goto out;
	}

	// We must always enable the modules *after* calling bladerf_sync_config().
	s.status = bladerf_enable_module(s.tx.dev, BLADERF_MODULE_TX, true);
	if (s.status != 0) {
		fprintf(stderr, "Failed to enable TX module: %s\n", bladerf_strerror(s.status));
		goto out;
	}

	// Start TX task
	s.status = start_tx_task(&s);
	if (s.status < 0) {
		fprintf(stderr, "Failed to start TX task.\n");
		goto out;
	}
	else
		printf("Creating TX task...\n");

	// Running...
	printf("Running...\n");
	printf("Press 'q' to exit.\n");
	while (1) {
		c = _getch();
		if (c=='q')
			break;
	}

	//
	// TODO: Cleaning up the threads properly.
	//

	printf("\nDone!\n");

	// Disable TX module, shutting down our underlying TX stream.
	s.status = bladerf_enable_module(s.tx.dev, BLADERF_MODULE_TX, false);
	if (s.status != 0) {
		fprintf(stderr, "Failed to disable TX module: %s\n", bladerf_strerror(s.status));
	}

out:
	// Free up resources
	if (s.tx.buffer != NULL)
		free(s.tx.buffer);

	if (s.fifo != NULL)
		free(s.fifo);

	printf("Closing device...\n");
	bladerf_close(s.tx.dev);

	return(0);
}
void SimulatorSingleton::run_sim()
{
  int argc = 0;
  char *argv[1];
  unsigned width, height;
  read_common_mv_setting ("IMG_WIDTH_COMMON", width);
  read_common_mv_setting ("IMG_HEIGHT_COMMON", height);
  
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);
  glutInitWindowSize (width, height);
  glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
  glutInitWindowPosition(10, 0);

  dwn_window = glutCreateWindow ("Down Cam");
  glutPositionWindow(0, 400);
  glutReshapeFunc  (::sim_reshape);
  glutDisplayFunc  (::sim_display);
  glutIdleFunc     (::sim_idle);
  glutKeyboardFunc (::sim_keyboard);
  glutCloseFunc    (::sim_close_window);
  init_sim();

  fwd_window = glutCreateWindow ("Forwards Cam");
  glutReshapeFunc  (::sim_reshape);
  glutDisplayFunc  (::sim_display);
  glutIdleFunc     (::sim_idle);
  glutKeyboardFunc (::sim_keyboard);
  glutCloseFunc    (::sim_close_window);
  init_sim();

  img_fwd = cvCreateImage (cvSize(width,height), IPL_DEPTH_8U, 3);
  img_dwn = cvCreateImage (cvSize(width,height), IPL_DEPTH_8U, 3);

  // set initial position
  std::string start_at;
  read_mv_setting(SIM_SETTINGS_FILE, "START_AT", start_at);

  float start_x = 0.f;
  float start_y = 0.f;
  float start_z = 0.f;
  float start_yaw = 0.f;

  if (start_at == "GATE") {
    start_x = -3.f;
    start_y = 7.5f;
    start_z = 16.f;
  } else if (start_at == "BUOY") {
    start_x = -3.3f;
    start_y = 4.5f;
    start_z = 3.f;
    start_yaw = 18.f;
  } else if (start_at == "GOALPOST") {
    start_x = 1.f;
    start_y = 2.5f;
    start_z = -4.2f;
    start_yaw = 80.f;
  } else if (start_at == "MULTIPATH") {
    start_x = 7.f;
    start_y = 2.5f;
    start_z = -5.f;
    start_yaw = 80.f;
  } else if (start_at == "TORPEDO_TARGET") {
    start_x = 10.1f;
    start_y = 2.35f;
    start_z = -1.9f;
    start_yaw = -170.f;
  } else if (start_at == "MARKER_DROPPER") {
    start_x = 10.8f;
    start_y = 2.5f;
    start_z = -7.1f;
    start_yaw = -4.f;
  }

  model.position.x = start_x;
  model.position.y = start_y;
  model.position.z = start_z;
  model.angle.yaw = start_yaw;

  set_target_depth(POOL_HEIGHT - start_y);
  set_target_yaw(start_yaw);

  // Sim has initialized
  sem_post(&sema);

  glutMainLoop();
}