Example #1
0
static int bb_test(void *data)
{
	int *v1, *v2;
	S_BB_T *test_bb1;
	S_BB_T *test_bb2;
	struct S_BB_MSG msg;


	bb_create(&test_bb1, "bb_test1", 2, 200);
	v1 = (int*)bb_simple_publish(test_bb1,"variable","bb_test1", -1, E_BB_INT32, sizeof(int), 1);

	bb_create(&test_bb2, "bb_test2", 2, 200);
	v2 = (int*)bb_simple_publish(test_bb2,"variable","bb_test2", -1, E_BB_INT32, sizeof(int), 1);
	*v1 = 0;
	*v2 = 0;

	msg.mtype = 10;
	bb_msg_subscribe(test_bb2, "Coucou bb2 10",  &msg, msg_callback);

	msg.mtype = 20;
	bb_msg_subscribe(test_bb1, "Coucou bb1 20",  &msg, msg_callback);


	while(!kthread_should_stop()) {
		test_running = 1;
		msleep(1000);
		*v1=*v1+1;
		*v2=*v2+1;

		bb_simple_synchro_go(test_bb1, 10);
		bb_simple_synchro_go(test_bb2, 20);
	}
	test_running = 0;
	bb_destroy(&test_bb1);
	bb_destroy(&test_bb2);
	return 0;
}
Example #2
0
int main(int argc, char *argv[]) {
BBoardPtr board=NULL;
char grid[MAX_ROWS][MAX_COLS];
int cmd;
int nrows, ncols, r, c, score;
int done;



    if(argc == 1) 
	board = bb_create(30, 30);
    else if(argc==2){
	if(!read_grid(grid, argv[1], &nrows, &ncols)) {
	    fprintf(stderr, "failed to read file %s\n", argv[1]);
	    fprintf(stderr, "Goodbye\n");
	    return 0;
	}
	printf("Successfully read input file %s\n", argv[1]);
	scrub_grid(grid, nrows, ncols);
	board = bb_create_from_mtx(grid, nrows, ncols);
     }
    else {
        fprintf(stderr, "usage error:  zero or 1 cmd-line arg\n");
        fprintf(stderr, "Goodbye\n");
	return 0;
    }
    // if we get here
    if(board != NULL) {

	if(!bb_is_compact(board)) {
		fprintf(stderr, "ERR:  board not compact\n");
		bb_display(board);
		fprintf(stderr, "Goodbye\n");
		bb_destroy(board);
		return 1;
	}
	done = 0;
	while(!done) {
	    bb_display(board);
	    score = bb_score(board);
	    printf("SCORE: %i\n", score);
	    cmd = read_cmd(&r, &c);
	    
	    switch(cmd) {
		case POP:  bb_pop(board, r, c); 
			   make_compact(board);
			   break;
		case QUIT: // bb_destroy(board);
			   done = 1;
			   break;
		case UNDO: if(!bb_undo(board)) {
				printf("  undo failed\n");
			   }
			   break;
		case UNKNOWN:
			   printf("  what?  try again\n");
			   break;
	
	    }
	}
	printf("FINAL SCORE:  %i\n", bb_score(board));
	bb_destroy(board);
	printf("  Goodbye\n");
    }  // end if board != NULL
}
Example #3
0
int main(int argc, char **argv)
{

	/* Définitions des variables */

	int retcode = 0;
	int data_size;
	int n_data;
	uint32_t *display_level;
	int32_t *Toto;
	int8_t *aint8;
	uint8_t *auint8;
	double *Titi;
	double *Tata;
	double *HugeArray;
	int i;
	int synchro = 0;
	MyType_t *myvar;
	char *astring;
	int opt;

	/*
	 * FIXME we should add
	 *   -a for acknowledged BB mode
	 */
#define USAGE_STRING "Usage: %s [-s] [-x]\n\
\t\t-s: use synchro\n\
\t\t-x: destroy bb on exit\n"
	while ((opt = getopt(argc, argv, "sxh")) != -1) {
		switch (opt) {
		case 's':
			synchro = 1;
			break;
		case 'x':
			signal(SIGINT, sigint_handler);
			break;
		case 'h':
		default:
			fprintf(stderr, USAGE_STRING, argv[0]);
			exit(EXIT_FAILURE);
		}
	}

	/* Creation BB */
	n_data = 1000;
	data_size = n_data * 8 + 500 * 30 * 4 + 200000 * 8;
	if (BB_NOK == bb_create(&mybb, basename(argv[0]), n_data, data_size)) {
		bb_attach(&mybb, basename(argv[0]));
	}

	/* Publish data in the BB */
	display_level = (uint32_t *) bb_simple_publish(mybb, "display_level",
						       basename(argv[0]), -1,
						       E_BB_UINT32, sizeof(uint32_t),
						       1);
	*display_level = 0;

	aint8 = (int8_t *) bb_simple_publish(mybb, "int8", basename(argv[0]),
					     -1, E_BB_INT8, sizeof(int8_t), 2);
	auint8 = (uint8_t *) bb_simple_publish(mybb, "uint8", basename(argv[0]),
					       -1, E_BB_UINT8, sizeof(uint8_t),
					       2);

	myvar = (MyType_t *) bb_simple_publish(mybb, "MyType_t_var",
					       basename(argv[0]), -1,
					       E_BB_USER, sizeof(MyType_t), 1);

	/* Now we may alias publish the structure in order to be able 
	 * to distribute the component of the structure using TSP
	 * Note that most of the time we may ignore the return value
	 * since the variable is usable trough the structure itself
	 */
	bb_simple_alias_publish(mybb, "a", "MyType_t_var",
				basename(argv[0]), -1, E_BB_INT32,
				sizeof(int32_t), 1, offsetof(MyType_t, a));
	bb_simple_alias_publish(mybb, "d", "MyType_t_var",
				basename(argv[0]), -1, E_BB_DOUBLE,
				sizeof(double), 1, offsetof(MyType_t, d));
	bb_simple_alias_publish(mybb, "byte", "MyType_t_var",
				basename(argv[0]), -1, E_BB_UINT8,
				sizeof(uint8_t), 1, offsetof(MyType_t,
							     byte));

	/* You may specify USER type in USER type */
	bb_simple_alias_publish(mybb, "insider", "MyType_t_var",
				basename(argv[0]), -1, E_BB_USER,
				sizeof(MyInsiderType_t), 1,
				offsetof(MyType_t, insider));

	/* Now the (in)famous structure in structure i.e. alias of alias example */
	bb_simple_alias_publish(mybb, "ai", "MyType_t_var.insider",
				basename(argv[0]), -1, E_BB_INT32,
				sizeof(int32_t), 2,
				offsetof(MyInsiderType_t, ai));

	bb_simple_alias_publish(mybb, "f", "MyType_t_var.insider",
				basename(argv[0]), -1, E_BB_DOUBLE,
				sizeof(double), 1,
				offsetof(MyInsiderType_t, f));

	/* You may even specify ARRAY of USER type in USER type */
	bb_simple_alias_publish(mybb, "insider_array", "MyType_t_var",
				basename(argv[0]), -1, E_BB_USER,
				sizeof(MyInsiderType_t), 2,
				offsetof(MyType_t, insider_array));

	/* Then you should re-specify alias of alias where target alias is an array */
	bb_simple_alias_publish(mybb, "ai", "MyType_t_var.insider_array",
				basename(argv[0]), -1, E_BB_INT32,
				sizeof(int32_t), 2,
				offsetof(MyInsiderType_t, ai));

	bb_simple_alias_publish(mybb, "f", "MyType_t_var.insider_array",
				basename(argv[0]), -1, E_BB_DOUBLE,
				sizeof(double), 1,
				offsetof(MyInsiderType_t, f));
	myvar->a = 1;
	myvar->d = 3.14159;
	myvar->byte = 0xFF;

	astring =
	    (char *) bb_simple_publish(mybb, "astring", basename(argv[0]),
				       -1, E_BB_CHAR, sizeof(char), 20);
	strncpy(astring, "A little string", 20);

	Toto =
	    (int32_t *) bb_simple_publish(mybb, "Toto", basename(argv[0]),
					  1, E_BB_INT32, sizeof(int32_t),
					  3);
	for (i = 0; i < 3; ++i) {
		Toto[i] = i;
	}
	for (i = 0; i < 3; ++i) {
		printf("@Toto = %p, Toto[%d] = %d\n",
		       &Toto[i], i, Toto[i]);
	}

	Titi =
	    (double *) bb_simple_publish(mybb, "Titi", basename(argv[0]),
					 1, E_BB_DOUBLE, sizeof(double),
					 1);
	*Titi = 3.14159;

	printf("@Titi = %p, Titi = %f\n", Titi, *Titi);

	Tata =
	    (double *) bb_simple_publish(mybb, "Tata", basename(argv[0]),
					 1, E_BB_DOUBLE, sizeof(double),
					 9);
	for (i = 0; i < 9; ++i) {
		Tata[i] = cos(*Titi / (i + 1));
	}

#undef HUGE_ARRAY
#ifdef HUGE_ARRAY
#define BIG_SIZE 200000
#else
#define BIG_SIZE 250
#endif
	HugeArray =
	    (double *) bb_simple_publish(mybb, "HugeArray",
					 basename(argv[0]), 1, E_BB_DOUBLE,
					 sizeof(double), BIG_SIZE);
	if (NULL == HugeArray) {
		printf("Cannot allocate HUGE array of size %d aborting...\n",
		       BIG_SIZE);
		return -1;
	}
	for (i = 0; i < BIG_SIZE; ++i) {
		HugeArray[i] = cos(*Titi / (i + 1));
	}

	BB_PUBLISH(mybb, DYN_0_d_qsat, "", -1, E_BB_DOUBLE, double, 4);
	BB_PUBLISH(mybb, ORBT_0_d_possat_m, "", -1, E_BB_DOUBLE, double, 3);
	BB_PUBLISH(mybb, ECLA_0_d_ecl_sol, "", -1, E_BB_DOUBLE, double, 1);
	BB_PUBLISH(mybb, ECLA_0_d_ecl_lune, "", -1, E_BB_DOUBLE, double, 1);
	BB_PUBLISH(mybb, POSA_0_d_DirSol, "", -1, E_BB_DOUBLE, double, 3);
	BB_PUBLISH(mybb, POSA_0_d_DirLun, "", -1, E_BB_DOUBLE, double, 3);
	BB_PUBLISH(mybb, Sequenceur_0_d_t_s, "", -1, E_BB_DOUBLE, double, 1);

	for (i = 0; i < 3; ++i) {
		printf("Toto[%d] = %d\n", i, Toto[i]);
	}
	printf("Titi = %f\n", *Titi);
	for (i = 0; i < 9; ++i) {
		printf("Tata[%d] = %f\n", i, Tata[i]);
	}

	i = 0;
	sleep(5);
	while (i < 2000000) {
		double dq1, dq2, teta, d = 7e6 /*km */ ;
		*Sequenceur_0_d_t_s = *Sequenceur_0_d_t_s + 0.01;	/* 10 Hz Simu */
		teta = *Sequenceur_0_d_t_s * 2 * 3.14 / 100;	/* 100s for a complete turn around */
		ORBT_0_d_possat_m[0] = d * cos(teta);	/* simple circular orbit */
		ORBT_0_d_possat_m[1] = d * sin(teta);	/* do better later */
		ORBT_0_d_possat_m[2] = d * 0.0;	/* force Z axis is null */
		dq1 = cos(teta) / 4;
		dq2 = sin(teta) / 4;
		DYN_0_d_qsat[0] = 0.7 + dq1;
		DYN_0_d_qsat[1] = 0.3 - dq1;
		DYN_0_d_qsat[2] = 0.3 + dq2;
		DYN_0_d_qsat[3] = -0.2 - dq2;
		POSA_0_d_DirLun[1] = 0.4;	/* e6 */
		POSA_0_d_DirSol[0] = 0.15;	/* e3 */
		*ECLA_0_d_ecl_lune = 1;
		*ECLA_0_d_ecl_sol = 1;


		Tata[0] = sin((2.0 * i) / 180.0);
		Tata[1] = cos((2.0 * i) / 180.0);
		Toto[0] = i % 1000;
		if (0 == (i % 100)) {
			Toto[1] = -Toto[1];
		}
		if ((i % 2) == 0) {
			bb_lock(mybb);
			*Titi += 1;
			if (*display_level & 0x1) {
				printf("Titi = %f\n", *Titi);
			}
			if (*display_level & 0x2) {
				printf("BB locked <i=%d>\n", i);
			}
		} else {
			*Titi += 1;
			if (*display_level & 0x1) {
				printf("Titi = %f\n", *Titi);
			}
			bb_unlock(mybb);
			if (*display_level & 0x2) {
				printf("BB unlocked\n");
			}
			if (synchro) {
				if (*display_level & 0x4) {
					printf("Synchro GO...");
					fflush(stdout);
				}
				bb_simple_synchro_go(mybb, BB_SIMPLE_MSGID_SYNCHRO_COPY);
				if (*display_level & 0x4) {
					printf("OK.\n");
				}
#if 0
 	printf("Synchro Wait...");
 	fflush(stdout);
 	bbntb_synchro_wait(BBNTB_MSGID_SYNCHRO_COPY_ACK);
 	printf("OK.\n");
 	fflush(stdout);
#endif
			}
		}
		usleep(10000);
		if (++i % 100 == 0) {
			printf(".");
			fflush(stdout);
		}
	}

	/* Destroy BB */
	retcode = bb_destroy(&mybb);

	return (retcode);
}
Example #4
0
int main(int argc, char *argv[])
{
  int my_time=0;
  unsigned long  last_us, now_us, t0_us, jitter, jitter_max=0;
  long delay;
  double retard, simtime, rtctime;

  S_BB_T	*mybb;
  mybbdata_t    *data;

  printf ("#============================================================#\n");
  printf ("# Launching <LinuxRTServer> for %d Symbols at %dHz #\n", GLU_MAX_SYMBOLS, TSP_STUB_FREQ);
  printf ("# RTmode=%d	Mask=0x%lX \n", rt_mode, affinity_mask);
  printf ("#============================================================#\n");

  /* Open the logical device */
  printf ("=====================================\n");
  rtc_init();
  tsp_histo_init();
  tsp_histo_set_delta (10); /* Jitter of 10us*/
  if (rt_mode) {
      rt_memory_lock(0);
    }
  
  /* Can use kill -2 for stopping prog */
  signal(SIGINT, signalled);
  
  /* Creation BB 1000 data of 1KO => 1Mo*/
  /***************/
  if (E_NOK==bb_create(&mybb,basename(argv[0]),1000,1000)) {
    bb_attach(&mybb,basename(argv[0]));
    /*     bb_destroy(&mybb); */
    /*     bb_create(&mybb,argv[0],n_data,data_size); */
  }
  data = bb_data_allocate();
  bb_data_publish(mybb,data);
  bb_data_propagate(mybb,data);

  printf (" GLU_thread :Last Time in NO RT mode !!!!\n");

  /* Must synchronise to first IT then RAZ  handler */
  rtc_wait_next_it();
  last_us = now_us = rtc_read_time();
  rtc_wait_next_it();
  t0_us = rtc_read_time();

  /* infinite loop for symbols generation */
  stopit = 0;
  while(!stopit)
    {
      delay = 0;

      /* Wait to a new Period of time */
      switch (it_mode) 
	{
	case 0: /* Polling like a beast on time */
	  while (delay < TSP_PERIOD_US)
	    {
	      now_us = rtc_read_time();
	      delay =  (now_us - last_us); /* in us  on 64 bits */
	    }
	  break;
	case 1: /* Blocking / Non blocking IT before read */
	  rtc_wait_next_it();
	  now_us = rtc_read_time();
	  delay =  (now_us - last_us); /* in us  on 64 bits */
	  if (delay<0 || delay >= 1.5* TSP_PERIOD_US) printf ("Warning : delay=%ld, now=%lu, last=%lu\n", delay, now_us, last_us);
	  break;
	default: break;
	}
	  

      /* We got a new period, must calculate the data */
      my_time++;    
      last_us = now_us;
      jitter =  delay-TSP_PERIOD_US; 
      simtime = (double)(my_time) / (double)(TSP_STUB_FREQ);
      rtctime =  ((now_us-t0_us)/1e6);
      retard = rtctime - simtime;
      if (jitter>jitter_max) jitter_max = jitter;
      tsp_histo_enter_with_date(jitter, rtctime);

      *data->bench.simtime	= simtime; /* s */
      *data->bench.rtime	= rtctime; /* s */
      *data->bench.delay	= (double)delay/1e3; /* ms */
      *data->bench.jitter	= jitter; /* s */
      *data->bench.jitter_max	= jitter_max; /* s */
      *data->bench.retard	= retard; /* ms */
 
    }

  /* Exit the program  */
  printf ("Exiting from GLU_Thread loop because stopit=%d\n", stopit);

	    
  tsp_histo_dump(stdout , "LOOP on RTC");
  /* Destruction BB */
  /******************/
  bb_destroy(&mybb);
 
  printf ("simtime\t= %gs\n", simtime);
  printf ("rtctime\t= %gs\n", rtctime);
  printf ("retard\t= %gs\n", retard);
  printf ("delay\t= %gms\n", (double)delay/1e3);
  printf ("max jit\t= %gms\n", jitter_max/1e3);

  return 0;
}