| [637] | 1 | #include "diabolo.h" | 
|---|
|  | 2 | #include "bolo.h" | 
|---|
|  | 3 | #include "synchro.h" | 
|---|
|  | 4 | #include "fichier.h" | 
|---|
|  | 5 | #include "trace.h" | 
|---|
|  | 6 | #include "alarme.h" | 
|---|
|  | 7 | #include "controle.h" | 
|---|
|  | 8 | #include "tm.h" | 
|---|
|  | 9 |  | 
|---|
|  | 10 | //----------------------------------  fenetre : synchro  ----------------------------------- | 
|---|
|  | 11 | void appel_detection_synchrone(void); | 
|---|
|  | 12 |  | 
|---|
|  | 13 |  | 
|---|
|  | 14 | double  synchro_periode=0;                      //  valeur courante mesurée de la periode en nb de pts de mesure | 
|---|
|  | 15 | int select_synchro=0; | 
|---|
|  | 16 | int sy_flag[nb_sync]; | 
|---|
|  | 17 | double  sy_per;                 // nombre de points de mesure dans une periode | 
|---|
|  | 18 | int force_scan,force_subscan; | 
|---|
|  | 19 |  | 
|---|
|  | 20 | // ------------------  programme synchro : traite les synchro et appelle trace_DS avec argument ds_debut ou ds_suite | 
|---|
|  | 21 |  | 
|---|
|  | 22 | void exec_synchro(int fen,int item,double valeur,...) | 
|---|
|  | 23 | { | 
|---|
|  | 24 | int j; | 
|---|
|  | 25 |  | 
|---|
|  | 26 | switch(item) | 
|---|
|  | 27 | { | 
|---|
|  | 28 | case ouverture  : | 
|---|
|  | 29 | case sy_select  : | 
|---|
|  | 30 | case sy_fixe    : | 
|---|
|  | 31 | case sy_fixe+1000 : | 
|---|
|  | 32 | case sy_force_scan : | 
|---|
|  | 33 | case sy_force_subscan : | 
|---|
|  | 34 |  | 
|---|
|  | 35 | force_scan=litD(fenetre_synchro,sy_force_scan,0L); | 
|---|
|  | 36 | force_subscan=litD(fenetre_synchro,sy_force_subscan,0L); | 
|---|
|  | 37 |  | 
|---|
|  | 38 | select_synchro=litD(fenetre_synchro,sy_select,0L); | 
|---|
|  | 39 | if(select_synchro)      gg->trace_ouvert=gg->trace_ouvert | 32 ; | 
|---|
|  | 40 | else                    gg->trace_ouvert=gg->trace_ouvert & (255-32);           // enleve le 32 | 
|---|
|  | 41 | synchro_periode=litD(fenetre_synchro,sy_fixe,0L); | 
|---|
|  | 42 | if(fenetre(fenetre_trace_DS))  exec_trace_DS(fenetre_trace_DS,ds_choix_DS,0); | 
|---|
|  | 43 | break; | 
|---|
|  | 44 |  | 
|---|
|  | 45 |  | 
|---|
|  | 46 | case caseferme  :       cache(fen);stop_exec(fen);      break; | 
|---|
|  | 47 |  | 
|---|
|  | 48 |  | 
|---|
|  | 49 | case 100        :       //  appellé à chaque point de mesure avec err dans valeur | 
|---|
|  | 50 | if(force_scan)  gg->don.sync[sync_scan]=1; | 
|---|
|  | 51 | if(force_subscan)       gg->don.sync[sync_subscan]=1; | 
|---|
|  | 52 |  | 
|---|
|  | 53 | if(select_synchro)  appel_detection_synchrone(); | 
|---|
|  | 54 |  | 
|---|
|  | 55 | for(j=0;j<nb_sync;j++)           // eclaire tous les voyants | 
|---|
|  | 56 | { | 
|---|
|  | 57 | if(gg->don.sync[j]) | 
|---|
|  | 58 | { | 
|---|
|  | 59 | if(!sy_flag[j]) { | 
|---|
|  | 60 | sy_flag[j]=1; | 
|---|
|  | 61 | ecritD(fenetre_synchro,sy_voyant+j,j+1); | 
|---|
|  | 62 | ecritD(fenetre_controle,con_voyant+j,j+1); | 
|---|
|  | 63 | } | 
|---|
|  | 64 | } | 
|---|
|  | 65 | else | 
|---|
|  | 66 | { | 
|---|
|  | 67 | if(sy_flag[j])  { | 
|---|
|  | 68 | sy_flag[j]=0; | 
|---|
|  | 69 | ecritD(fenetre_synchro,sy_voyant+j,0); | 
|---|
|  | 70 | ecritD(fenetre_controle,con_voyant+j,0); | 
|---|
|  | 71 | } | 
|---|
|  | 72 | } | 
|---|
|  | 73 | } | 
|---|
|  | 74 | if( tt->signal_scan_immediat ou gg->don.sync[sync_scan] )               //  debut scan seulement si pas d'erreur synchro | 
|---|
|  | 75 | { | 
|---|
|  | 76 | if(!gg->scan_en_cours) | 
|---|
|  | 77 | { | 
|---|
|  | 78 | debut_scan_fich(); | 
|---|
|  | 79 | gg->compte_subscan=0; | 
|---|
|  | 80 | ecritD(fenetre_controle,con_subscan,"debut scan"); | 
|---|
|  | 81 | } | 
|---|
|  | 82 |  | 
|---|
|  | 83 | gg->scan_en_cours=10;   // ou n'importe quoi >0 | 
|---|
|  | 84 | if( (gg->don.sync[sync_subscan]) && (gg->compte_subscan<1) ) | 
|---|
|  | 85 | { | 
|---|
|  | 86 | gg->compte_subscan=-gg->compte_subscan+1; | 
|---|
|  | 87 | ecritD(fenetre_controle,con_subscan,"subscan %d",gg->compte_subscan); | 
|---|
|  | 88 | } | 
|---|
|  | 89 | if( (!gg->don.sync[sync_subscan]) && (gg->compte_subscan>0) ) | 
|---|
|  | 90 | { | 
|---|
|  | 91 | gg->compte_subscan=-gg->compte_subscan; | 
|---|
|  | 92 | ecritD(fenetre_controle,con_subscan,"fin (%d)",-gg->compte_subscan); | 
|---|
|  | 93 | } | 
|---|
|  | 94 | } | 
|---|
|  | 95 | else | 
|---|
|  | 96 | { | 
|---|
|  | 97 | if( gg->compte_subscan>0) | 
|---|
|  | 98 | { | 
|---|
|  | 99 | gg->compte_subscan=-gg->compte_subscan; | 
|---|
|  | 100 | } | 
|---|
|  | 101 | if(gg->scan_en_cours) | 
|---|
|  | 102 | { | 
|---|
|  | 103 | ecritD(fenetre_controle,con_subscan,"       "); | 
|---|
|  | 104 | // affiche rien mais compte_subscan se rappelle la derniere valeur en negatif | 
|---|
|  | 105 | if(litD(fenetre_alarme,a_fin_scan,0)>0) | 
|---|
|  | 106 | {son(5);son(6);son(7);son(8);son(133);son(135);son(133);} | 
|---|
|  | 107 | } | 
|---|
|  | 108 | gg->scan_en_cours=0; | 
|---|
|  | 109 | } | 
|---|
|  | 110 | break; | 
|---|
|  | 111 |  | 
|---|
|  | 112 | default : break; | 
|---|
|  | 113 | } | 
|---|
|  | 114 |  | 
|---|
|  | 115 | } | 
|---|
|  | 116 |  | 
|---|
|  | 117 |  | 
|---|
|  | 118 | void appel_detection_synchrone(void) | 
|---|
|  | 119 | { | 
|---|
|  | 120 | int i; | 
|---|
|  | 121 | double x; | 
|---|
| [639] | 122 | static long ancien_temps; | 
|---|
| [637] | 123 | if(select_synchro==7)   // selection  valeur fixe | 
|---|
|  | 124 | { | 
|---|
| [639] | 125 | if((gg->temps_cntl%(int)synchro_periode)==0) | 
|---|
|  | 126 | //      if(sy_per>=synchro_periode) | 
|---|
| [637] | 127 | { | 
|---|
|  | 128 | if(gg->trace_ouvert&2)  exec_trace_1_per(fenetre_trace_1_per,ds_debut,0); | 
|---|
|  | 129 | if(gg->trace_ouvert&4)  exec_trace_DS(fenetre_trace_DS,ds_debut,0); | 
|---|
|  | 130 | sy_per=1; | 
|---|
|  | 131 | } | 
|---|
|  | 132 | else | 
|---|
|  | 133 | { | 
|---|
| [639] | 134 | if(gg->temps_cntl!=ancien_temps+1) | 
|---|
|  | 135 | { | 
|---|
|  | 136 | sy_per+=gg->temps_cntl-ancien_temps; | 
|---|
|  | 137 | printf("erreur synchro corrigée\n"); | 
|---|
|  | 138 | } | 
|---|
|  | 139 | else    sy_per=sy_per+1; | 
|---|
|  | 140 |  | 
|---|
| [637] | 141 | if(gg->trace_ouvert&2)  exec_trace_1_per(fenetre_trace_1_per,ds_suite,0); | 
|---|
|  | 142 | if(gg->trace_ouvert&4)  exec_trace_DS(fenetre_trace_DS,ds_suite,0); | 
|---|
|  | 143 | } | 
|---|
| [639] | 144 | ancien_temps=gg->temps_cntl; | 
|---|
| [637] | 145 | } | 
|---|
|  | 146 | else | 
|---|
|  | 147 | { | 
|---|
|  | 148 | i=gg->don.sync[select_synchro-1]; | 
|---|
|  | 149 | if(i && !sy_flag[select_synchro-1]) | 
|---|
|  | 150 | { | 
|---|
|  | 151 | x=1-2.*(double)i/(double)gg->reglage.horloge.nb_mesures; | 
|---|
|  | 152 | ecritD(fenetre_synchro,sy_phase,(int)(x*100)); | 
|---|
|  | 153 | ecritD(fenetre_controle,con_phase,(int)(x*100)); | 
|---|
|  | 154 | sy_per=sy_per+x; | 
|---|
|  | 155 | //                                              printf("i=%d  x=%g  p=%6.2f  frequ=%g Hz\n",i,x,sy_per,1e6/(sy_per*gg->periode_echantillonage)); | 
|---|
|  | 156 | ecritD(fenetre_synchro,sy_periode," p=%6.2f\r frequ=%g Hz",sy_per,1e6/(sy_per*gg->periode_echantillonage)); | 
|---|
|  | 157 | ecritD(fenetre_controle,con_periode," p=%6.2f",sy_per); | 
|---|
|  | 158 | synchro_periode=sy_per; | 
|---|
|  | 159 | sy_per=1-x; | 
|---|
|  | 160 | if(gg->trace_ouvert&2)  exec_trace_1_per(fenetre_trace_1_per,ds_debut,0); | 
|---|
|  | 161 | if(gg->trace_ouvert&4)  exec_trace_DS(fenetre_trace_DS,ds_debut,0); | 
|---|
|  | 162 | } | 
|---|
|  | 163 | else | 
|---|
|  | 164 | { | 
|---|
|  | 165 | sy_per=sy_per+1; | 
|---|
|  | 166 | if(gg->trace_ouvert&2)  exec_trace_1_per(fenetre_trace_1_per,ds_suite,0); | 
|---|
|  | 167 | if(gg->trace_ouvert&4)  exec_trace_DS(fenetre_trace_DS,ds_suite,0); | 
|---|
|  | 168 | } | 
|---|
|  | 169 |  | 
|---|
|  | 170 | } | 
|---|
|  | 171 | } | 
|---|
|  | 172 | //                                      printf("\n"); | 
|---|
|  | 173 |  | 
|---|