| 1 | #include "diabolo.h" | 
|---|
| 2 | #include "bolo.h" | 
|---|
| 3 | #include "acqui.h" | 
|---|
| 4 | #include "fichier.h" | 
|---|
| 5 | #include "auto.h" | 
|---|
| 6 | #include "regul.h" | 
|---|
| 7 | #include "tm.h" | 
|---|
| 8 |  | 
|---|
| 9 |  | 
|---|
| 10 | int auto_tr[nb_max_bolo]; | 
|---|
| 11 | int ib_efface[nb_max_bolo]; | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | //----------------------------------  fenetre : bolo  ----------------------------------- | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 18 | //  le numero du bolometre dans  fen    (fenetres 1 à parametres.nb_bolo ) | 
|---|
| 19 |  | 
|---|
| 20 | void exec_bolo(int fen,int item,double valeur,...) | 
|---|
| 21 | { | 
|---|
| 22 | int a,c,i; | 
|---|
| 23 | int n=gg->reglage.horloge.nb_mesures; | 
|---|
| 24 | if(item>1000) item-=1000;               // pour appeler le case pour tous les cara d'un edit texte | 
|---|
| 25 | //printf("execbolo avec fen=%d , item=%d \n",fen,item); | 
|---|
| 26 | switch(item) | 
|---|
| 27 | { | 
|---|
| 28 | case ouverture  :       ib_efface[fen-1]=0; | 
|---|
| 29 | selectgra(fen); | 
|---|
| 30 | graph->ymin=-18000; | 
|---|
| 31 | graph->ymax=18000; | 
|---|
| 32 | graph->ypas=9000; | 
|---|
| 33 | graph->xmax=gg->reglage.horloge.nb_mesures; | 
|---|
| 34 | graph->xpas=graph->xmax/4; | 
|---|
| 35 | graph->grille=1; | 
|---|
| 36 | graph->graduations=0; | 
|---|
| 37 | graph->sans_image=1; | 
|---|
| 38 | graph->avec_icones=0; | 
|---|
| 39 | graph->aspect=0; | 
|---|
| 40 | graph->xtitre[0]=0; | 
|---|
| 41 | graph->ytitre[0]=0; | 
|---|
| 42 | //                              ecritD(fen,b_voy,fen+1); | 
|---|
| 43 |  | 
|---|
| 44 | ecritgain(fen); | 
|---|
| 45 | break; | 
|---|
| 46 |  | 
|---|
| 47 |  | 
|---|
| 48 | case tache_de_fond  :   // appellé par le programme d'acquisition pour tracer   ----  la cadence est variable | 
|---|
| 49 | n=gg->reglage.horloge.nb_mesures; | 
|---|
| 50 | //                              printf(" nb mesure = %d \n",n); | 
|---|
| 51 | { | 
|---|
| 52 | selectgra(fen); | 
|---|
| 53 | graph->xmax=n;          graph->xpas=n/4; | 
|---|
| 54 | graph->ymin=-18000;     graph->ymax=18000;      graph->ypas=9000; | 
|---|
| 55 | } | 
|---|
| 56 | if(ib_efface[fen-1]--<0) { ib_efface[fen-1]=10; retrace(fen);} | 
|---|
| 57 | c=1234; | 
|---|
| 58 | effacecourbe(fen); | 
|---|
| 59 | //                              style(fen); | 
|---|
| 60 | //tt->bololut[fen-1]=lecture_en_cours; | 
|---|
| 61 |  | 
|---|
| 62 | for(i=0;i<n;i++) | 
|---|
| 63 | { | 
|---|
| 64 | //  16 bit utiles dans     gg->bol_per | 
|---|
| 65 | trace(fen,i, ((double)((gg->bol_per[fen-1][i]&0x7fff)-0x4000))); | 
|---|
| 66 | a=(gg->bol_per[fen-1][i]>>15)&1; | 
|---|
| 67 | if(a!=c)        { | 
|---|
| 68 | c=a;    if(a)   modtrace(fen,1,bleu); | 
|---|
| 69 | else    modtrace(fen,1,rouge); | 
|---|
| 70 | } | 
|---|
| 71 | } | 
|---|
| 72 | trace(fen,n, ((double)((gg->bol_per[fen-1][0]&0x7fff)-0x4000))); | 
|---|
| 73 | if(gg->flag_tc_reduite)         break;  /* pas d'auto en local  si en tc_reduites */ | 
|---|
| 74 | if( (litD(fen,b_auto,0L))!=0)   auto_control(fen,auto_val); | 
|---|
| 75 | if(auto_tr[fen-1])              {auto_transitoire(fen,auto_tr[fen-1]);auto_tr[fen-1]--;} | 
|---|
| 76 |  | 
|---|
| 77 | break; | 
|---|
| 78 | //  avec fenetre de dialogue pour envoyer une valeur directe | 
|---|
| 79 | case b_carre    :       ouvreD(fen_change_bolo,change_bolo_id,"chgbolo",0); | 
|---|
| 80 | if(1==modal(fen_change_bolo)) | 
|---|
| 81 | { | 
|---|
| 82 | valeur=litD(fen_change_bolo,chb_val,0); | 
|---|
| 83 | printf("  val=%d  %n",(int)valeur); | 
|---|
| 84 | ecritD(fen,b_carre,(int)valeur); | 
|---|
| 85 | ecritgain(fen); | 
|---|
| 86 | } | 
|---|
| 87 | ferme(fen_change_bolo); | 
|---|
| 88 | break; | 
|---|
| 89 |  | 
|---|
| 90 | case b_tri      :       ouvreD(fen_change_bolo,change_bolo_id,"chgbolo",0); | 
|---|
| 91 | if(1==modal(fen_change_bolo)) | 
|---|
| 92 | { | 
|---|
| 93 | valeur=litD(fen_change_bolo,chb_val,0); | 
|---|
| 94 | printf("  val=%d  %n",(int)valeur); | 
|---|
| 95 | ecritD(fen,b_tri,(int)valeur); | 
|---|
| 96 | ecritgain(fen); | 
|---|
| 97 | } | 
|---|
| 98 | ferme(fen_change_bolo); | 
|---|
| 99 | break; | 
|---|
| 100 |  | 
|---|
| 101 | case b_trans    :       ouvreD(fen_change_bolo,change_bolo_id,"chgbolo",0); | 
|---|
| 102 | if(1==modal(fen_change_bolo)) | 
|---|
| 103 | { | 
|---|
| 104 | valeur=litD(fen_change_bolo,chb_val,0); | 
|---|
| 105 | printf("  val=%d  %n",(int)valeur); | 
|---|
| 106 | ecritD(fen,b_trans,(int)valeur); | 
|---|
| 107 | ecritgain(fen); | 
|---|
| 108 | } | 
|---|
| 109 | ferme(fen_change_bolo); | 
|---|
| 110 | break; | 
|---|
| 111 |  | 
|---|
| 112 | case b_lin      :       ouvreD(fen_change_bolo,change_bolo_id,"chgbolo",0); | 
|---|
| 113 | if(1==modal(fen_change_bolo)) | 
|---|
| 114 | { | 
|---|
| 115 | valeur=litD(fen_change_bolo,chb_val,0); | 
|---|
| 116 | printf("  val=%d  %n",(int)valeur); | 
|---|
| 117 | ecritD(fen,b_lin,(int)valeur); | 
|---|
| 118 | ecritgain(fen); | 
|---|
| 119 | } | 
|---|
| 120 | ferme(fen_change_bolo); | 
|---|
| 121 | break; | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 |  | 
|---|
| 125 | /* | 
|---|
| 126 | //  reecrit les valeurs dans la fenetre pour appel par un autre programme | 
|---|
| 127 | case b_carre    :       ecritD(fen,b_carre,(int)valeur);                ecritgain(fen);         break; | 
|---|
| 128 | case b_tri      :       ecritD(fen,b_tri,(int)valeur);                  ecritgain(fen);         break; | 
|---|
| 129 | case b_trans    :       ecritD(fen,b_trans,(int)valeur);                ecritgain(fen);         break; | 
|---|
| 130 | case b_lin      :       ecritD(fen,b_lin,(int)valeur);                  ecritgain(fen);         break; | 
|---|
| 131 |  | 
|---|
| 132 | */ | 
|---|
| 133 | case b_gain     :       vg[fen-1]=0;  ecritD(fen,b_gain,(int)valeur);   ecritgain(fen);         break; | 
|---|
| 134 | case b_phase    :       ecritD(fen,b_phase,(int)valeur);                ecritgain(fen);         break; | 
|---|
| 135 | case b_comm     :       ecritD(fen,b_comm,(int)valeur);                 ecritgain(fen);         break; | 
|---|
| 136 | case b_voie     :                                                       ecritgain(fen);         break; | 
|---|
| 137 | case caseferme  :       //SizeWindow(ptf->ptwindow,210,105,1);MoveWindow(ptf->ptwindow,620,-20+fen*95,0);zoom(fen); | 
|---|
| 138 | stop_exec(fen); break; | 
|---|
| 139 |  | 
|---|
| 140 | break; | 
|---|
| 141 | case b_auto_trans:      case    b_auto_trans+1000       :       auto_tr[fen-1]=20;              break; | 
|---|
| 142 | case b_auto_lin :       case    b_auto_lin+1000         :       ecritD(fen,b_lin,2048);         break; | 
|---|
| 143 |  | 
|---|
| 144 | case b_auto     :       ecritgain(fen); | 
|---|
| 145 | //                              if(valeur && (! gg->flag_tc_reduite) ) | 
|---|
| 146 | if(valeur)      auto_control(fen,auto_force); | 
|---|
| 147 | break; | 
|---|
| 148 |  | 
|---|
| 149 | default         :       break; | 
|---|
| 150 | } | 
|---|
| 151 | } | 
|---|
| 152 |  | 
|---|
| 153 |  | 
|---|
| 154 | unsigned char codage_12_bit(int av,int an); | 
|---|
| 155 | unsigned char codage_12_bit(int av,int an) | 
|---|
| 156 | { | 
|---|
| 157 | int a=an-av; | 
|---|
| 158 | if( (a>0) && (a<64) ) a =  0x40  |  a; | 
|---|
| 159 | else    if( (a<0) && (a>-64) ) a = -a; | 
|---|
| 160 | else    a=0x80  |  ((an&0xfff)>>5) ; | 
|---|
| 161 | return(a); | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 |  | 
|---|
| 165 | void ecritgain(int fen)         // ecrit gain, carre, triangle, .....gg->reglage.dac[...] | 
|---|
| 166 | { | 
|---|
| 167 | int carr,tri,lin,tran,i,j,gainbrut,phase,comm,voie; | 
|---|
| 168 | int gain_MLPA[16]={1,2,4,8,10,20,40,80,100,200,400,800,1000,2000,4000,8000}; | 
|---|
| 169 | int gain_BEBO[4]={5,25,100,500};        /*      gainbrut ampli  1 / 5 / 20 / 100        */ | 
|---|
| 170 | int gain_BEDIF[3]={10,40,200};          /*      gainbrut ampli  2 / 8 / 40      */ | 
|---|
| 171 | int table_phase[4]={0,1,3,2}; | 
|---|
| 172 | char bit[80]; | 
|---|
| 173 | int b,ordre; | 
|---|
| 174 | char mot_tc[10]; | 
|---|
| 175 | carr=litD(fen,b_carre,0L); | 
|---|
| 176 | tri=litD(fen,b_tri,0L); | 
|---|
| 177 | lin=litD(fen,b_lin,0L); | 
|---|
| 178 | tran=litD(fen,b_trans,0L); | 
|---|
| 179 | gainbrut=litD(fen,b_gain,0L); | 
|---|
| 180 | phase=litD(fen,b_phase,0L); | 
|---|
| 181 | comm=litD(fen,b_comm,0L); | 
|---|
| 182 | if(litD(fen,b_auto,0L))  voie=litD(fen,b_voie,0L);      else voie=0; | 
|---|
| 183 |  | 
|---|
| 184 | //  verifie les gainsbrut  en fonction de la boite utilisée | 
|---|
| 185 | switch(parametr.bolo[fen-1].bolo_bebo) | 
|---|
| 186 | { | 
|---|
| 187 | case    0:      //  ----------------------   programmation MLPA  ------------------- | 
|---|
| 188 | break; | 
|---|
| 189 | case    2: | 
|---|
| 190 | case    3: | 
|---|
| 191 | case    4:      //  ----------------------   programmation BEBO  ------------------- | 
|---|
| 192 | if(gainbrut>3) {gainbrut=3;ecritD(fen,b_gain,3);} | 
|---|
| 193 | gainbrut+=16;   // pour une BEBO | 
|---|
| 194 | break; | 
|---|
| 195 |  | 
|---|
| 196 | case    10:     //  ----------------------   programmation Bediff  ------------------- | 
|---|
| 197 | if(gainbrut>2) {gainbrut=2;ecritD(fen,b_gain,2);} | 
|---|
| 198 | gainbrut+=20;   //  pour une BEDIFF | 
|---|
| 199 | if(phase>1) {phase=1;ecritD(fen,b_phase,1);} | 
|---|
| 200 |  | 
|---|
| 201 | default :       break; | 
|---|
| 202 | } | 
|---|
| 203 |  | 
|---|
| 204 |  | 
|---|
| 205 |  | 
|---|
| 206 | //  emission des telecommandes reduites au lieu des telecommandes completes | 
|---|
| 207 |  | 
|---|
| 208 | if(gg->flag_tc_reduite) | 
|---|
| 209 | { | 
|---|
| 210 | if(carr!=dac_V(gg->reglage.bolo[fen-1])) | 
|---|
| 211 | emission_tc_reduite(tc2_bolo_dacV,fen-1,codage_12_bit(dac_V(gg->reglage.bolo[fen-1]),carr)); | 
|---|
| 212 |  | 
|---|
| 213 | if(tri!=dac_I(gg->reglage.bolo[fen-1])) | 
|---|
| 214 | emission_tc_reduite(tc2_bolo_dacI,fen-1,codage_12_bit(dac_I(gg->reglage.bolo[fen-1]),tri)); | 
|---|
| 215 |  | 
|---|
| 216 | if(tran!=dac_T(gg->reglage.bolo[fen-1])) | 
|---|
| 217 | emission_tc_reduite(tc2_bolo_dacT,fen-1,codage_12_bit(dac_T(gg->reglage.bolo[fen-1]),tran)); | 
|---|
| 218 |  | 
|---|
| 219 | if(lin!=dac_L(gg->reglage.bolo[fen-1])) | 
|---|
| 220 | emission_tc_reduite(tc2_bolo_dacL,fen-1,codage_12_bit(dac_L(gg->reglage.bolo[fen-1]),lin)); | 
|---|
| 221 |  | 
|---|
| 222 | if( (gainbrut!=gainbrut(gg->reglage.bolo[fen-1])) | 
|---|
| 223 | ou (phase!=phase(gg->reglage.bolo[fen-1])) | 
|---|
| 224 | ou (comm!=comm(gg->reglage.bolo[fen-1])) ) | 
|---|
| 225 | emission_tc_reduite(tc2_bolo_gain,fen-1,bolo_mot1(carr,tri,gainbrut,phase,comm)); | 
|---|
| 226 |  | 
|---|
| 227 | if(voie!=voie(gg->reglage.bolo[fen-1])) | 
|---|
| 228 | emission_tc_reduite(tc2_bolo_voie,fen-1,voie); | 
|---|
| 229 | } | 
|---|
| 230 |  | 
|---|
| 231 | else    { | 
|---|
| 232 | for(j=0;j<72;j++) bit[j]=0;                     //  prepare 72 bits à envoyer en 9 mots de 8 bits | 
|---|
| 233 |  | 
|---|
| 234 | switch(parametr.bolo[fen-1].bolo_bebo) | 
|---|
| 235 | { | 
|---|
| 236 | case    0: | 
|---|
| 237 | {                       //  ----------------------   programmation MLPA  ------------------- | 
|---|
| 238 | //      printf("programmation MLPA:  tri=%d  car=%d \n",tri,carr); | 
|---|
| 239 |  | 
|---|
| 240 | mot_tc[0]=parametr.bolo[fen-1].bolo_num;        //  premier mot de 8 bit (code adresse bolometre) | 
|---|
| 241 | //      printf(" ecrit bolo %d \n",gg->bolo[fen-1].bolo_num); | 
|---|
| 242 | bit[0]=table_phase[phase&3]>>1; bit[1]=table_phase[phase&3]; | 
|---|
| 243 | b=2; | 
|---|
| 244 | for(i=11;i>=0;i--) {bit[b]=1;   bit[b+1]=tran>>i;   bit[b+2]=lin>>i;    bit[b+3]=tri>>i;   bit[b+4]=carr>>i;b+=5;} | 
|---|
| 245 | bit[b]=1;   bit[b+1]=gainbrut>>3;   bit[b+2]=gainbrut>>2;   bit[b+3]=gainbrut>>1;  bit[b+4]=gainbrut; | 
|---|
| 246 | ordre=0; | 
|---|
| 247 | } | 
|---|
| 248 | break; | 
|---|
| 249 |  | 
|---|
| 250 |  | 
|---|
| 251 | case    2: | 
|---|
| 252 | case    3: | 
|---|
| 253 | case    4: | 
|---|
| 254 | {                       //  ----------------------   programmation BEBO  ------------------- | 
|---|
| 255 | mot_tc[0]=8*parametr.bolo[fen-1].bolo_bebo + parametr.bolo[fen-1].bolo_num;     //  premier mot de 8 bit (code adresse bolometre) | 
|---|
| 256 | //      printf("programmation BEBO N° :  tri=%d  car=%d \n",mot_tc[0],tri,carr); | 
|---|
| 257 |  | 
|---|
| 258 | bit[0]=gainbrut>>1;     bit[1]=gainbrut;        bit[2]=table_phase[phase&3]>>1; bit[3]=table_phase[phase&3]; | 
|---|
| 259 | b=4; | 
|---|
| 260 | for(i=11;i>=0;i--)      bit[b++]=(tri>>i)&1; | 
|---|
| 261 | for(i=11;i>=0;i--)      bit[b++]=(carr>>i)&1; | 
|---|
| 262 | for(i=11;i>=0;i--)      bit[b++]=(tran>>i)&1; | 
|---|
| 263 |  | 
|---|
| 264 | ecritD(fen,b_lin,0); | 
|---|
| 265 | ordre=0; | 
|---|
| 266 | } | 
|---|
| 267 | break; | 
|---|
| 268 |  | 
|---|
| 269 | case    10: | 
|---|
| 270 | {                       //  ----------------------   programmation Bediff  ------------------- | 
|---|
| 271 | //  ---  les bits sortent dans l'autre sens : poid faible d'abord  ---- | 
|---|
| 272 | //  --  il faut donc retourner les bits des dacs | 
|---|
| 273 | //              lin=0; | 
|---|
| 274 | //              ecritD(fen,b_lin,lin);  gg->reglage.dac[d_lin][fen-1]=lin; // pas de linearité | 
|---|
| 275 | mot_tc[0]= parametr.bolo[fen-1].bolo_num;       //  premier mot de 8 bit (code adresse bolometre) | 
|---|
| 276 | printf("programmation BEdiff N° %d:  tri=%d  car=%d \n",mot_tc[0],tri,carr); | 
|---|
| 277 |  | 
|---|
| 278 | bit[0]=gainbrut>>1;     bit[1]=gainbrut;        bit[2]=comm; bit[3]=phase; | 
|---|
| 279 | b=4; | 
|---|
| 280 | for(i=11;i>=0;i--)      bit[b++]=(tri>>i)&1; | 
|---|
| 281 | for(i=11;i>=0;i--)      bit[b++]=(carr>>i)&1; | 
|---|
| 282 | for(i=11;i>=0;i--)      bit[b++]=(tran>>i)&1; | 
|---|
| 283 | for(i=11;i>=0;i--)      bit[b++]=(lin>>i)&1; | 
|---|
| 284 | ordre=1; | 
|---|
| 285 | } | 
|---|
| 286 | break; | 
|---|
| 287 |  | 
|---|
| 288 |  | 
|---|
| 289 | default :       break; | 
|---|
| 290 | } | 
|---|
| 291 |  | 
|---|
| 292 |  | 
|---|
| 293 |  | 
|---|
| 294 |  | 
|---|
| 295 | if (ordre)                      //  remet les bit par mot de 8 bit poid faible en premier | 
|---|
| 296 | for(i=0;i<9;i++)        mot_tc[i+1]= | 
|---|
| 297 | ( ((bit[8*i]&1)) | ((bit[8*i+1]&1)<<1) | ((bit[8*i+2]&1)<<2) | ((bit[8*i+3]&1)<<3) | 
|---|
| 298 | | ((bit[8*i+4]&1)<<4) | ((bit[8*i+5]&1)<<5) | ((bit[8*i+6]&1)<<6) | ((bit[8*i+7]&1)<<7 ) ); | 
|---|
| 299 |  | 
|---|
| 300 | else                            //  remet les bit par mot de 8 bit, poid fort en premier | 
|---|
| 301 | for(i=0;i<9;i++)        mot_tc[i+1]= | 
|---|
| 302 | ( ((bit[8*i]&1)<<7) | ((bit[8*i+1]&1)<<6) | ((bit[8*i+2]&1)<<5) | ((bit[8*i+3]&1)<<4) | 
|---|
| 303 | | ((bit[8*i+4]&1)<<3) | ((bit[8*i+5]&1)<<2) | ((bit[8*i+6]&1)<<1) | ((bit[8*i+7]&1) ) ); | 
|---|
| 304 |  | 
|---|
| 305 | emission_telecommande(tc_dir_transputer,mot_tc); | 
|---|
| 306 |  | 
|---|
| 307 | gg->reglage.bolo[fen-1].mot1=bolo_mot1(carr,tri,gainbrut,phase,comm); | 
|---|
| 308 | gg->reglage.bolo[fen-1].mot2=bolo_mot2(tran,lin,voie); | 
|---|
| 309 |  | 
|---|
| 310 | } | 
|---|
| 311 | mesures_bolo(fen,carr,tri,1);           //  mesure temperature, puissance,... pour les bolos | 
|---|
| 312 |  | 
|---|
| 313 | tt->reglage=gg->reglage; | 
|---|
| 314 |  | 
|---|
| 315 | fich_save_partiel(1); | 
|---|
| 316 | } | 
|---|
| 317 |  | 
|---|
| 318 |  | 
|---|
| 319 | /* | 
|---|
| 320 |  | 
|---|
| 321 | void    ecritpulseprisme(int per); | 
|---|
| 322 |  | 
|---|
| 323 | void ecritpulseprisme(int per)                                                  //   ecrit l'etat.bolo :  gg->reglage.diode_dure | 
|---|
| 324 | { | 
|---|
| 325 | //int i; | 
|---|
| 326 | gg->reglage.diode_dure=per; | 
|---|
| 327 | per=per+1; | 
|---|
| 328 | //printf(" ecriture de per=%d  \n",per); | 
|---|
| 329 | // lecture et ecriture carte du nopmbre de mesures | 
|---|
| 330 | if(per<1)       per=1;  if(per>31) per=31; | 
|---|
| 331 | //ecrit_nubus_dec(25);          //  valeur  2 * num_bolo  +1  = 2*12 + 1 = 25 | 
|---|
| 332 | //ecrit_nubus_dec(per & 31 );   //  5 bits ecriture | 
|---|
| 333 | //for(i=0;i<12;i++) ecrit_nubus_dec(0); | 
|---|
| 334 | fich_save_partiel(1); | 
|---|
| 335 | } | 
|---|
| 336 | */ | 
|---|