TSP: The Transport Sample Protocol



Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

bb_test.c

00001 
00002 #include <stdio.h>
00003 #include <malloc.h>
00004 #include <unistd.h>
00005 #include <math.h>
00006 #include <libgen.h>
00007 #include <string.h>
00008 #include <bb_core.h>
00009 #include <bb_simple.h>
00010 #include "tsp_abs_types.h"
00011 
00012 typedef struct mytype {
00013   int     a;
00014   double  d;
00015   uint8_t byte;
00016 } mytype_t;
00017 
00018 int 
00019 main (int argc, char ** argv) {
00020 
00021   /* Définitions des variables */
00022  
00023   int retcode=0;
00024   int data_size;
00025   int n_data;
00026   uint32_t* display_level;
00027   int32_t* Toto;
00028   double* Titi;
00029   double* Tata;
00030   double* HugeArray;
00031   int i;
00032   int synchro;
00033   S_BB_T* mybb;
00034   mytype_t* myvar;
00035   char*     astring;
00036 
00037   /*
00038    * Analyse options de lancement
00039    */
00040   if (EOF != getopt(argc,argv,"s")) {
00041     synchro = 1;
00042     printf("Run with synchro ACTIVE\n");
00043   } else {
00044     synchro = 0;
00045     printf("Run with synchro INACTIVE\n");
00046   }
00047   /* Creation BB */
00048   /***************/
00049   n_data = 10000;
00050   data_size = n_data*8 + 5000*30*4 + 200000*8;
00051   if (E_NOK==bb_create(&mybb,basename(argv[0]),n_data,data_size)) {
00052     bb_attach(&mybb,basename(argv[0]));
00053 /*     bb_destroy(&mybb); */
00054 /*     bb_create(&mybb,argv[0],n_data,data_size); */
00055   }
00056 
00057   /* Publish data in the BB */
00058   /**************************/
00059 
00060   display_level = (uint32_t*) bb_simple_publish(mybb,"display_level",basename(argv[0]),-1, E_BB_UINT32, sizeof(uint32_t),1);
00061   *display_level = 0;
00062   
00063   myvar = (mytype_t*) bb_simple_publish(mybb,"mytype_t_var",basename(argv[0]),-1, E_BB_USER, sizeof(mytype_t),1);
00064   myvar->a = 1;
00065   myvar->d = 3.14159;
00066   myvar->byte = 0xFF;
00067 
00068   astring = (char*) bb_simple_publish(mybb,"astring",basename(argv[0]),-1, E_BB_CHAR, sizeof(char),20);
00069   strncpy(astring,"A little string",20);
00070 
00071   Toto = (int32_t*) bb_simple_publish(mybb,"Toto",basename(argv[0]),1, E_BB_INT32, sizeof(int32_t),3);  
00072   for (i=0;i<3;++i) {
00073     Toto[i] = i;
00074   }
00075   for (i=0;i<3;++i) {
00076     printf("@Toto = 0x%x, Toto[%d] = %d\n",(unsigned int)&Toto[i],i,Toto[i]);  
00077   }
00078   
00079   Titi= (double*) bb_simple_publish(mybb,"Titi",basename(argv[0]),1, E_BB_DOUBLE, sizeof(double),1);
00080   *Titi = 3.14159;
00081   
00082   printf("@Titi = 0x%x, Titi = %f\n",(unsigned int)Titi,*Titi);
00083   
00084   Tata = (double*) bb_simple_publish(mybb,"Tata",basename(argv[0]),1, E_BB_DOUBLE, sizeof(double),9);
00085   for (i=0;i<9;++i) {
00086     Tata[i] = cos(*Titi/(i+1));
00087   }
00088 
00089 #undef HUGE_ARRAY
00090 #ifdef HUGE_ARRAY
00091 #define BIG_SIZE 200000
00092 #else
00093 #define BIG_SIZE 10
00094 #endif
00095   HugeArray = (double*) bb_simple_publish(mybb,"HugeArray",basename(argv[0]),1, E_BB_DOUBLE, sizeof(double),BIG_SIZE);
00096   for (i=0;i<BIG_SIZE;++i) {
00097     HugeArray[i] = cos(*Titi/(i+1));
00098   }
00099   
00100   for (i=0;i<3;++i) {
00101     printf("Toto[%d] = %d\n",i,Toto[i]);  
00102   }
00103   printf("Titi = %f\n",*Titi);
00104   for (i=0;i<9;++i) {
00105     printf("Tata[%d] = %f\n",i,Tata[i]);  
00106   }
00107   
00108   i = 0;
00109   sleep(5);
00110   while (i<2000000) {
00111     Tata[0] = sin((2.0*i)/180.0);
00112     Tata[1] = cos((2.0*i)/180.0);
00113     Toto[0] = i % 1000;
00114     if (0==(i % 100)) {
00115       Toto[1] = -Toto[1];
00116     }     
00117     if ((i % 2) == 0) {
00118       bb_lock(mybb);
00119       *Titi += 1;
00120       if (*display_level & 0x1) {
00121         printf("Titi = %f\n",*Titi);
00122       }
00123       if (*display_level & 0x2) {
00124         printf("BB locked <i=%d>\n",i);
00125       }
00126     } else {
00127       *Titi += 1;
00128       if (*display_level & 0x1) {
00129         printf("Titi = %f\n",*Titi);
00130       }
00131       bb_unlock(mybb);      
00132       if (*display_level & 0x2) {
00133         printf("BB unlocked\n");
00134       }
00135       if (synchro) {
00136         if (*display_level & 0x4) {
00137           printf("Synchro GO...");
00138           fflush(stdout);
00139         }
00140         bb_simple_synchro_go(mybb,BB_SIMPLE_MSGID_SYNCHRO_COPY);
00141         if (*display_level & 0x4) {
00142           printf("OK.\n");
00143         }
00144 /*      printf("Synchro Wait..."); */
00145 /*      fflush(stdout); */
00146 /*      bbntb_synchro_wait(BBNTB_MSGID_SYNCHRO_COPY_ACK); */
00147 /*      printf("OK.\n"); */
00148 /*      fflush(stdout); */
00149       }
00150     }
00151     usleep(10000);
00152     ++i;
00153   }
00154   
00155   /* Destruction BB */
00156   /******************/
00157   retcode = bb_destroy(&mybb);
00158 
00159   return (retcode);
00160 }
Framework Home Page.

Beware !! TSP wave is coming...