[637] | 1 | #include "diabolo.h"
|
---|
| 2 | #include "bolo.h"
|
---|
| 3 | #include "acqui.h"
|
---|
| 4 | #include "fichier.h"
|
---|
| 5 | #include "tm.h"
|
---|
| 6 | #include "tache.h"
|
---|
| 7 | #include "regul.h"
|
---|
| 8 | #include "auto.h"
|
---|
| 9 | #include "config_transputer.h"
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | void init_struct(int PCI_actif)
|
---|
| 15 | {
|
---|
| 16 | int i,j;
|
---|
| 17 | def_long_block
|
---|
| 18 | def_nom_block
|
---|
| 19 | printf("memoire pour stglob: %d K \nmemoire pour tmtc : %d K \n",
|
---|
| 20 | (sizeof(stglob)>>10),(sizeof(tmtc)>>10));
|
---|
| 21 |
|
---|
| 22 | gg=malloc(sizeof(stglob));
|
---|
| 23 |
|
---|
| 24 | random(-1);
|
---|
| 25 |
|
---|
| 26 | if(parametr.numero_version!=version_num) {erreur("erreur numero de version\n");return;}
|
---|
| 27 | if(parametr.n_max_bolo!=nb_max_bolo) {erreur("erreur nb_max_bolo \n");return;}
|
---|
| 28 | if(parametr.n_per_block!=nb_per_block) {erreur("erreur nb_per_block\n");return;}
|
---|
| 29 | if(parametr.n_max_mes_per!=nb_max_mes_per) {erreur("erreur nb_max_mes_per\n");return;}
|
---|
| 30 | if(parametr.nb_bolo!=nb_bolo_util) {erreur("erreur nb_bolo_util\n");return;}
|
---|
| 31 |
|
---|
| 32 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 33 | {
|
---|
| 34 | // parametr.bolo[j].bolo_code_util=0;
|
---|
| 35 | // strcpy(parametr.bolo[j].bolo_nom,"");
|
---|
| 36 | // parametr.bolo[j].bolo_bebo=0;
|
---|
| 37 | // parametr.bolo[j].bolo_num=0;
|
---|
| 38 | // parametr.bolo[j].bolo_gain=1000;
|
---|
| 39 | // parametr.bolo[j].bolo_capa=0;
|
---|
| 40 | // parametr.bolo[j].bolo_diviseur=0;
|
---|
| 41 | // parametr.presence_bebo=0;
|
---|
| 42 | // parametr.coef[nb_max_bolo][7] non initialisé
|
---|
| 43 |
|
---|
| 44 | gg->reglage.bolo[j].mot1=0;
|
---|
| 45 | gg->reglage.bolo[j].mot2=0;
|
---|
| 46 | // gg->reglage.gainbrut[j]=0;
|
---|
| 47 | // gg->reglage.gain[j]=1;
|
---|
| 48 | }
|
---|
| 49 | gg->temps_cntl=0;
|
---|
| 50 | gg->depou_en_cours=0;
|
---|
| 51 | gg->trace_ouvert=0;
|
---|
| 52 | for(j=0;j<8;j++) gg->trace_tout[j]=0;
|
---|
| 53 | gg->scan_en_cours=0;
|
---|
| 54 | gg->flag_corel=0;
|
---|
| 55 | gg->flag_tc_reduite=0;
|
---|
| 56 | gg->fichier_dia2_ouvert=0;
|
---|
| 57 | gg->fichier_arch_ouvert=0;
|
---|
| 58 | gg->flag_fou=0;
|
---|
| 59 | gg->temps_origine=0;
|
---|
| 60 |
|
---|
| 61 | //---------- initialise les structures de la tache -------------
|
---|
| 62 | tt=malloc(sizeof(tmtc));
|
---|
| 63 |
|
---|
| 64 | tt->PCI_actif=PCI_actif;
|
---|
| 65 | printf("tt->PCI_actif=%d \n",tt->PCI_actif);
|
---|
| 66 |
|
---|
| 67 | tt->reglage=gg->reglage;
|
---|
| 68 |
|
---|
| 69 | tt->vi.temps_cntl=0;
|
---|
| 70 |
|
---|
| 71 | tt->signal_scan_immediat=0;
|
---|
| 72 | // donc toujours zero pour archeops
|
---|
| 73 |
|
---|
| 74 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 75 | {
|
---|
| 76 | tt->ds.ii[j]=0;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | tt->te.pos_ecrit=0;tt->te.pos_lit=0;
|
---|
| 81 | tt->tc.pos_ecrit=0;tt->tc.pos_lit=0;
|
---|
| 82 | tt->tm.pos_ecrit=0;tt->tm.pos_lit=0;
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | j=0;
|
---|
| 87 | for(i=0;i<nb_type_blocks;i++)
|
---|
| 88 | {
|
---|
| 89 | printf(" - size=%5d block : %s\n",long_block[i],nom_block[i]);
|
---|
| 90 | if (long_block[i]> j ) j=long_block[i];
|
---|
| 91 | }
|
---|
| 92 | printf(" taille maxi du block de telemesure = %d // on reserve %d octets par block \n",
|
---|
| 93 | j,sizeof(block_type_modele));
|
---|
| 94 | if(j>sizeof(block_type_modele)) erreur("block_type_modele trops petit");
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | init_tache(); // init dependant des taches
|
---|
| 100 |
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | //_________________________________________________________________________________________________________________
|
---|
| 106 | int test_erreur(void)
|
---|
| 107 | {
|
---|
| 108 | int err,i;
|
---|
| 109 | DateTimeRec date;
|
---|
| 110 | err=tt->te.pos_ecrit-tt->te.pos_lit; if (err<0) err+=long_table_err;
|
---|
| 111 | if(err>0)
|
---|
| 112 | {
|
---|
| 113 | GetTime(&date);
|
---|
| 114 | printf("%dh%d:%d : %d erreurs table: ",date.hour,date.minute,date.second,err);
|
---|
| 115 | for(i=0;(i<err);i++) {
|
---|
| 116 | if(i<5) switch(tt->te.err[tt->te.pos_lit])
|
---|
| 117 | {
|
---|
| 118 | case 900+err_sync_repart : printf(" sync_repart");break;
|
---|
| 119 | // case 900+err_fifo_demi : printf(" fifo_demi");break;
|
---|
| 120 | case 900+err_fifo_pleine : printf(" fifo_pleine");break;
|
---|
| 121 | case 900+err_sync_bebo : printf(" sync-bebo");break;
|
---|
| 122 | case 900+err_sync_ctrl : printf(" sync-ctrl");break;
|
---|
| 123 | case 900+err_lect_pci : printf(" lect_pci");break;
|
---|
| 124 | case 900+err_lect_ctrl : printf(" lect_ctrl");break;
|
---|
| 125 | case 900+err_synchro_block : printf(" synchro_block");break;
|
---|
| 126 | case 900+err_recut_un_block_ok: printf(" err_recut_un_block_ok");break;
|
---|
| 127 | case 900+err_longueur_block : printf(" err_longueur_block");break;
|
---|
| 128 | case 900+err_sauve_block : printf(" err_sauve_block");break;
|
---|
| 129 | case 900+err_pile_pleine : printf(" err_pile_pleine");son(133);break;
|
---|
| 130 |
|
---|
| 131 | case 8 : printf(" +");break;
|
---|
| 132 | case 9 : printf(" -");break;
|
---|
| 133 | default :
|
---|
| 134 | if(tt->te.err[tt->te.pos_lit]>=920)
|
---|
| 135 | printf("bit_%d ",tt->te.err[tt->te.pos_lit]-920);
|
---|
| 136 | else printf(" %d",tt->te.err[tt->te.pos_lit]);
|
---|
| 137 | break;
|
---|
| 138 | }
|
---|
| 139 | tt->te.pos_lit++; if( tt->te.pos_lit>=long_table_err) tt->te.pos_lit=0;
|
---|
| 140 | }
|
---|
| 141 | printf("\n");
|
---|
| 142 | }
|
---|
| 143 | return(err);
|
---|
| 144 | }
|
---|
| 145 | //_________________________________________________________________________________________________________________
|
---|
| 146 |
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | // appel des bolo pour tracé des courbes individuelles
|
---|
| 150 | void affi_bolo(void)
|
---|
| 151 | {
|
---|
| 152 | static int affi1=0,affi2=0;
|
---|
| 153 | int j;
|
---|
| 154 | static long t=0;
|
---|
| 155 | if(!t) t=TickCount();
|
---|
| 156 | if(t>TickCount()) return;
|
---|
| 157 | t=TickCount()+60; //attente au minimum 1 sec entre 2 appels
|
---|
| 158 |
|
---|
| 159 | for(j=0;j<nb_max_bolo;j++) if(parametr.bolo[j].bolo_code_util) exec_bolo(j+1,tache_de_fond,0);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | //*****************************************************************************************
|
---|
| 168 | // ***
|
---|
| 169 | #ifdef _archeops //--------- pour Archeops ------------------------------ ***
|
---|
| 170 | // ***
|
---|
| 171 | //*****************************************************************************************
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | //_________________________________________________________________________________________________________________
|
---|
| 176 | void reset_epld(void)
|
---|
| 177 | {
|
---|
| 178 | printf("reset epld");
|
---|
| 179 | /*
|
---|
| 180 | if(gg->flag_tc_reduite)
|
---|
| 181 | {
|
---|
| 182 | int i;
|
---|
| 183 | for(i=0;i<15;i++) emission_tc_reduite(tc2_reset_epld,i,0);
|
---|
| 184 | }
|
---|
| 185 | else
|
---|
| 186 | */
|
---|
| 187 | {
|
---|
| 188 | char mot_tc[10];
|
---|
| 189 | emission_telecommande(tc_dir_reset_epld,mot_tc);
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | void calfreq(int flag_on) // fabrique l'etat.bolo gg->reglage.horloge et gg->periode_echantillonage
|
---|
| 195 | // le flag_on dit s'il faut commander la sortie des data
|
---|
| 196 | {
|
---|
| 197 | double p,f1,f2,f3;
|
---|
| 198 | int pp,b,tm,flag;
|
---|
| 199 | char mot_tc[10];
|
---|
| 200 |
|
---|
| 201 | p=litD(fenetre_acquisition,e_periode,0L);
|
---|
| 202 | if(p<4) p=4; if(p>16) p=16; // butée sur la periode
|
---|
| 203 | pp=p*5.; p=(double)pp / 5.;
|
---|
| 204 | ecritD(fenetre_acquisition,e_periode,"%6.1f",p); // reconstruit p
|
---|
| 205 |
|
---|
| 206 | b=litD(fenetre_acquisition,e_nb_mes,0L);
|
---|
| 207 | if(b<18) {b=18;ecritD(fenetre_acquisition,e_nb_mes,b);}
|
---|
| 208 | if(b>44) {b=44;ecritD(fenetre_acquisition,e_nb_mes,b);}
|
---|
| 209 | b=b*2;
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | tm=litD(fenetre_acquisition,e_temp_mort,0L); // temps mort = 1 .. nbmes par 1/4 per
|
---|
| 213 | if(tm<2) {tm=2;ecritD(fenetre_acquisition,e_temp_mort,tm);}
|
---|
| 214 | if(tm>13) {tm=13;ecritD(fenetre_acquisition,e_temp_mort,tm);}
|
---|
| 215 |
|
---|
| 216 |
|
---|
| 217 | flag=flag_on;
|
---|
| 218 | if(litD(fenetre_acquisition,e_flag1,0L)) flag +=2;
|
---|
| 219 | if(litD(fenetre_acquisition,e_flag2,0L)) flag +=4;
|
---|
| 220 |
|
---|
| 221 | //printf(" b=%d tm=%d a=%d h=%d \n",b,tm,a,h);
|
---|
| 222 |
|
---|
| 223 | if(gg->flag_tc_reduite)
|
---|
| 224 | {
|
---|
| 225 |
|
---|
| 226 | if((pp!=gg->reglage.horloge.periode) ou clavier(touche_alt) ) emission_tc_reduite(tc2_horloge,tc3_periode,pp);
|
---|
| 227 | if((b!=gg->reglage.horloge.nb_mesures) ou clavier(touche_alt) ) emission_tc_reduite(tc2_horloge,tc3_nb_mesures,b);
|
---|
| 228 | if((tm!=gg->reglage.horloge.temp_mort) ou clavier(touche_alt) ) emission_tc_reduite(tc2_horloge,tc3_temp_mort,tm);
|
---|
| 229 | if((flag!=gg->reglage.horloge.flag) ou clavier(touche_alt) ) emission_tc_reduite(tc2_horloge,tc3_flag,flag);
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | else
|
---|
| 233 | {
|
---|
| 234 | mot_tc[0]=tc_horloge; // commande valeur des horloges
|
---|
| 235 | mot_tc[1]=pp; // periode en multiple de 0.2µsec : de 20 a 80 soit 4 a 16 µsec
|
---|
| 236 | mot_tc[2]=b/2 ; // nb pts/demi periode de 23 a 44
|
---|
| 237 | mot_tc[3]=tm;
|
---|
| 238 | mot_tc[4]=flag; // c'est le flag qui met en route la sortie des mesures
|
---|
| 239 | emission_telecommande(tc_dir_transputer,mot_tc);
|
---|
| 240 |
|
---|
| 241 | gg->reglage.horloge.periode=pp;
|
---|
| 242 | gg->reglage.horloge.nb_mesures=b; // nombre de mesures dans une periode complete
|
---|
| 243 | gg->reglage.horloge.temp_mort=tm;
|
---|
| 244 | gg->reglage.horloge.flag=flag;
|
---|
| 245 |
|
---|
| 246 | }
|
---|
| 247 | // affichage de toutes les fréquences
|
---|
| 248 | f1=1000/p;f2=f1/bitmot;f3=f2*1000./(double)(gg->reglage.horloge.nb_mesures);
|
---|
| 249 | ecritD(fenetre_acquisition,e_freq,"freq: %5.1f kHz -- %5.2f kHz, modulation: %5.1f Hz",f1,f2,f3);
|
---|
| 250 | printf("freq --> : %5.1f kHz -- %5.2f kHz, modulation: %5.1f Hz\n",f1,f2,f3);
|
---|
| 251 | gg->periode_echantillonage=0.5/f3; // 2 fois la frequence de modulation
|
---|
| 252 | printf(" periode d'échantillonage= %g \n",gg->periode_echantillonage);
|
---|
| 253 |
|
---|
| 254 | tt->reglage=gg->reglage;
|
---|
| 255 | fich_save_partiel(1);
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 |
|
---|
| 259 | #endif
|
---|
| 260 | //*****************************************************************************************
|
---|
| 261 | // ***
|
---|
| 262 | #ifdef _diabolo //--------- pour Diabolo ------------------------------ ***
|
---|
| 263 | // ***
|
---|
| 264 | //*****************************************************************************************
|
---|
| 265 |
|
---|
| 266 | void reset_epld(void)
|
---|
| 267 | {
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | void calfreq(int flag_on) // fabrique l'etat.bolo gg->reglage.horloge.nb_mesures et gg->periode_echantillonage
|
---|
| 271 | {
|
---|
| 272 | double p,f1,f2,f3;
|
---|
| 273 | int a,h,pp,b,tm;
|
---|
| 274 | int j;
|
---|
| 275 | char mot_tc[10];
|
---|
| 276 |
|
---|
| 277 | p=litD(fenetre_acquisition,e_periode,0L);
|
---|
| 278 | b=litD(fenetre_acquisition,e_nb_mes,0L);
|
---|
| 279 | tm=litD(fenetre_acquisition,e_temp_mort,0L); // temps mort = 1 .. nbmes par 1/4 per
|
---|
| 280 | if(tm<1) {tm=1;ecritD(fenetre_acquisition,e_temp_mort,tm);}
|
---|
| 281 | if(tm>b) {tm=b;ecritD(fenetre_acquisition,e_temp_mort,b);}
|
---|
| 282 | // lecture externe ou local
|
---|
| 283 | h=litD(fenetre_acquisition,e_horloge_ext_,0L);
|
---|
| 284 |
|
---|
| 285 | //if(p<5) p=5; // butée en periode minimum pour éviter de planter le Mac
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | //---------------------------------------- nombre de mesures
|
---|
| 289 |
|
---|
| 290 | if(b<4) b=4; if(b>44) b=44;
|
---|
| 291 | gg->reglage.horloge.nb_mesures=(b/2)*4;
|
---|
| 292 |
|
---|
| 293 | //---------------------------------------- periode de l'horloge de base
|
---|
| 294 | if (h&1) p=p*frequ_horloge_externe;
|
---|
| 295 | else p=p*frequ_horloge_interne;
|
---|
| 296 |
|
---|
| 297 | a=(p/frequ_divise)-ofset_periode ;
|
---|
| 298 |
|
---|
| 299 | if(a<0) a=0;
|
---|
| 300 | if(a>1020) a=1020; // 10 bits maxi attention a l'ofset
|
---|
| 301 |
|
---|
| 302 | pp=a+ofset_periode;
|
---|
| 303 | p=(double)(pp)*frequ_divise;
|
---|
| 304 | if (h&1) p=p/frequ_horloge_externe;
|
---|
| 305 | else p=p/frequ_horloge_interne;
|
---|
| 306 |
|
---|
| 307 | ecritD(fenetre_acquisition,e_periode,"%6.1f",p); // reconstruit p et pp
|
---|
| 308 |
|
---|
| 309 |
|
---|
| 310 | //printf(" b=%d tm=%d a=%d h=%d \n",b,tm,a,h);
|
---|
| 311 |
|
---|
| 312 | mot_tc[0]=tc_horloge; //79..72
|
---|
| 313 | mot_tc[1]=(tm%7)+ ((b/2)<<3) ; //71..64 3 bit temps mort et 5 bit mb (nombre de coups par 1/4 de periode = b/2)
|
---|
| 314 | mot_tc[2]=(a>>8); //63..56 poid fort (2 bits)
|
---|
| 315 | mot_tc[3]=a; //55..48 poid faible (8 bits)
|
---|
| 316 | mot_tc[4]=h&3; //47..40 horloge externe et bolo-iram
|
---|
| 317 | emission_telecommande(0,mot_tc);
|
---|
| 318 |
|
---|
| 319 |
|
---|
| 320 | // affichage de toutes les fréquences
|
---|
| 321 | f1=1000/p;f2=f1/bitmot;f3=f2*1000./(double)(gg->reglage.horloge.nb_mesures);
|
---|
| 322 | gg->periode_echantillonage=0.5/f3; // 2 fois la frequence de modulation
|
---|
| 323 | // periode * 16 * nbdemesure / 2
|
---|
| 324 | //printf(" durée= %ld \n",gg->periode_echantillonage);
|
---|
| 325 |
|
---|
| 326 | ecritD(fenetre_acquisition,e_freq,"freq: %5.1f kHz -- %5.2f kHz, modulation: %5.1f Hz",f1,f2,f3);
|
---|
| 327 |
|
---|
| 328 |
|
---|
| 329 |
|
---|
| 330 | {//_______________ fabrique les detections synchrones de la modulation électrique
|
---|
| 331 | int i,v,tm;
|
---|
| 332 | tm=litD(fenetre_acquisition,e_temp_mort,0L);
|
---|
| 333 | gg->reglage.temp_mort=tm;
|
---|
| 334 | // detection plus/moins avec tm points supprimé
|
---|
| 335 | // ds[0] == plus / moins
|
---|
| 336 | // ds[1] == plus / plus
|
---|
| 337 | // ds[2] == + - 0 / - + 0
|
---|
| 338 |
|
---|
| 339 | tt->ds.dsnorme=0;
|
---|
| 340 | i=0;
|
---|
| 341 | for(v=0 ;v<gg->reglage.horloge.nb_mesures/2 ;v++)
|
---|
| 342 | {
|
---|
| 343 | if(v<tm) tt->ds.dstable[i]=0;
|
---|
| 344 | else {tt->ds.dstable[i]=1; tt->ds.dsnorme++;}
|
---|
| 345 | i++;
|
---|
| 346 | }
|
---|
| 347 | for(v=0;v<gg->reglage.horloge.nb_mesures/2 ;v++)
|
---|
| 348 | {
|
---|
| 349 | if(v<tm) tt->ds.dstable[i]=0;
|
---|
| 350 | else {tt->ds.dstable[i]=-1; tt->ds.dsnorme++;}
|
---|
| 351 | i++;
|
---|
| 352 | }
|
---|
| 353 | }
|
---|
| 354 | //printf(" normes = %d %d \n",tt->ds.dsnorme[0],tt->ds.dsnorme[1]);
|
---|
| 355 | tt->reglage=gg->reglage;
|
---|
| 356 | fich_save_partiel(1);
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 |
|
---|
| 360 | //*****************************************************************************************
|
---|
| 361 | // ***
|
---|
| 362 | #endif //-------------------------------------------------------------------- ***
|
---|
| 363 | // ***
|
---|
| 364 | //*****************************************************************************************
|
---|
| 365 |
|
---|
| 366 |
|
---|
| 367 |
|
---|
| 368 |
|
---|
| 369 | void deglitch(void)
|
---|
| 370 | {
|
---|
| 371 | int j;
|
---|
| 372 | double x,dx;
|
---|
| 373 | static int debut=1;
|
---|
| 374 | static double X[nb_max_bolo];
|
---|
| 375 | static double DX[nb_max_bolo];
|
---|
| 376 | if(debut)
|
---|
| 377 | {
|
---|
| 378 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 379 | {
|
---|
| 380 | X[j]=0;DX[j]=1000;
|
---|
| 381 | }
|
---|
| 382 | debut=0;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | for(j=0;j<nb_max_bolo;j++)
|
---|
| 386 | {
|
---|
| 387 | x=gg->don.don_bolo[j];
|
---|
| 388 | dx=x-X[j]; if(dx<0) dx=-dx;
|
---|
| 389 | if( dx > DX[j] )
|
---|
| 390 | {
|
---|
| 391 | printf("glitch bolo %d ancien X=%g nouveau x=%g DX=%g \n",j+1,X[j],x,DX[j]);
|
---|
| 392 | gg->don.don_bolo[j]=X[j];
|
---|
| 393 | DX[j] *=1.1;
|
---|
| 394 | }
|
---|
| 395 | else {
|
---|
| 396 | DX[j]=0.9 * DX[j] + 0.5 * dx +1 ;
|
---|
| 397 | X[j]=x;
|
---|
| 398 | } // en moyenne, 5 fois l'interval moyen
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 |
|
---|
| 404 |
|
---|
| 405 |
|
---|
| 406 |
|
---|
| 407 |
|
---|