source: Sophya/trunk/Poubelle/archediab.old/archediab.sources/c/telecommande.c@ 649

Last change on this file since 649 was 649, checked in by ansari, 26 years ago

archediab 28 vol

File size: 10.7 KB
RevLine 
[637]1#include "diabolo.h"
2#include "carte_acqui.h"
3#include "carte_pci.h"
4#include "fenetres_diabolo.h"
5#include "acqui.h"
6#include "tm.h"
[649]7#include "simulmission.h"
8#include "controle.h"
[637]9
10
11 // telecommande une chaine de 10 mots pour Diabolo
12 // une chaine de 8 mots pour Archeops et Planck
13 // pour les telecommandes reduites, seuls 4 mots sont utiles
14
15#define verif_bolo {bolo=tc[2];if(bolo>nb_max_bolo) {printf("erreur: telecommande pour bolo=%d >nb_max_bolo \n",bolo);return;}}
16
17void relit_telecommandes_reduites(unsigned char* tc);
18
19
20void relit_telecommandes_reduites(unsigned char* tc)
21{
[643]22int bolo,a;
[637]23if(tc[0]!=tc_reduite) return;
24printf("relit une telecommande reduite : ");
25switch(tc[1])
26 {
27 case tc2_bolo_dacV:
28 verif_bolo;a=dac_V(gg->reglage.bolo[bolo]);
29 a=new_val_dac(a,tc[3]);
30 gg->reglage.bolo[bolo].mot1=(gg->reglage.bolo[bolo].mot1&0xfff000ff) | (a<<8);
31 printf(" nouvelle valeur dacV=%d \n",a);
32 break;
33
34 case tc2_bolo_dacI:
35 verif_bolo;a=dac_I(gg->reglage.bolo[bolo]);
36 a=new_val_dac(a,tc[3]);
37 gg->reglage.bolo[bolo].mot1=(gg->reglage.bolo[bolo].mot1&0x000fffff) | (a<<20);
38 printf(" nouvelle valeur dacI=%d \n",a);
39 break;
40
41 case tc2_bolo_gain:
42 verif_bolo;
43 gg->reglage.bolo[bolo].mot1=(gg->reglage.bolo[bolo].mot1&0xffffff00) | tc[3];
44
45 printf(" nouvelle valeur gain=%x \n",tc[3]);
46 break;
47
48 case tc2_bolo_dacT:
49 verif_bolo;a=dac_T(gg->reglage.bolo[bolo]);
50 a=new_val_dac(a,tc[3]);
51 gg->reglage.bolo[bolo].mot2=(gg->reglage.bolo[bolo].mot2&0xfff000ff) | (a<<8);
52 printf(" nouvelle valeur dacT=%d \n",a);
53 break;
54
55 case tc2_bolo_dacL:
56 verif_bolo;a=dac_L(gg->reglage.bolo[bolo]);
57 a=new_val_dac(a,tc[3]);
58 gg->reglage.bolo[bolo].mot2=(gg->reglage.bolo[bolo].mot2&0x000fffff) | (a<<20);
59 printf(" nouvelle valeur dacL=%d \n",a);
60 break;
61
62 case tc2_bolo_voie:
63 verif_bolo;
64 gg->reglage.bolo[bolo].mot2=(gg->reglage.bolo[bolo].mot2&0xffffff00) | tc[3];
65
66 printf(" nouvelle valeur voie=%d \n",tc[3]);
67 break;
68 case tc2_horloge:
69 switch(tc[2])
70 {
71 case tc3_periode :
72 gg->reglage.horloge.periode=tc[3];
73 printf(" nouvelle valeur periode=%d \n",tc[3]);
74 break;
75 case tc3_nb_mesures : gg->reglage.horloge.nb_mesures=tc[3];
76 printf(" nouvelle valeur nb_mesures=%d \n",tc[3]);
77 break;
78 case tc3_temp_mort : gg->reglage.horloge.temp_mort=tc[3];
79 printf(" nouvelle valeur temp_mort=%d \n",tc[3]);
80 break;
81 case tc3_flag : gg->reglage.horloge.flag=tc[3];
82 printf(" nouvelle valeur flag=%d \n",tc[3]);
83 break;
84 default :
[643]85// i=tc[2]-tc3_vitesse;
86// if( (i>=0) && (i<nb_type_blocks) )
87// gg->reglage.vitesse[i]=tc[3];
88// printf(" nouvelle valeur block%d vitesse %d \n",i,tc[3]);
[637]89 break;
90 }
91 case tc2_regul:
92 {
93 char * pt;
94 printf(" tc reduite: ecrit regul val=%d pour position %d \n",tc[3],tc[2]);
95 pt=(char*)(&(gg->reglage.regul[0]));
96 pt=pt+tc[2];
97 if(tc[2]<nombre_de_regul*sizeof(regul_bolo)) *pt=tc[3];
98 else printf("erreur telecommande reduite tc2_regul \n");
99 }
100 break;
101
102
103
104 case tc2_auto_bolo:
105 {
106 char * pt;
107 printf(" tc reduite: ecrit autobolo val=%d pour position %d \n",tc[3],tc[2]);
108 pt=(char*)(&(gg->reglage.autom[0]));
109 pt=pt+tc[2];
110 if(tc[2]<nombre_de_voies*sizeof(auto_bolo)) *pt=tc[3];
111 else printf("erreur telecommande reduite tc2_auto_bolo \n");
112 }
113 break;
114
115
116 case tc2_auto_dilu:
117 {
118 char * pt;
119 printf(" tc reduite: ecrit auto_dilu val=%d pour position %d \n",tc[3],tc[2]);
120 pt=(char*)(&(gg->reglage.dilu));
121 pt=pt+tc[2];
122 if(tc[2]<sizeof(auto_dilu)) *pt=tc[3];
123 else printf("erreur telecommande reduite tc2_auto_bolo \n");
124 }
125 break;
126
127
128 default : printf("telecommande reduite type inconnu \n\n");
129 son(130);
130 break;
131 }
132rafraichis_fenetres();
133}
134
135
136void emission_tc_reduite(unsigned char mot1,unsigned char mot2,unsigned char mot3)
137{
138unsigned char mot_tc[10];
[649]139 {
140 mot_tc[0] = tc_reduite;
141 mot_tc[1] = mot1;
142 mot_tc[2] = mot2;
143 mot_tc[3] = mot3;
144 emission_telecommande(tc_dir_transputer,mot_tc);
145 }
[637]146}
147
148
149void emission_telecommande(int direction,void* tc)
150{
151char *mot=tc;
152int j;
153
[649]154if(!acquisition_avec_telecommande) return;
155
156
[637]157//*****************************************************************************************
158// ***
159#ifdef _archeops //--------- pour Archeops ------------------------------ ***
160// ***
161//*****************************************************************************************
162// direction contient un octet de direction: bebo ou transputer
163// la commande elle même est dans mot[0..7]
164
165#define delai(xx) {long uu;for(uu=0;uu<(10000L*(long)xx);uu++){};}
[649]166#define tc_char(x) {delai(40);if(acquisition_PCI) ecrit_carte((x)&0xff);}
[637]167#define tc_int(x) {tc_char(x);tc_char(x>>8);tc_char(x>>16);tc_char(x>>24);}
168//printf("telecommande: ");
169
170
171
172//*****************************************************************************************
173#ifdef _sans_transputer //--------- pour Archeops avec ctb ------------- ***
174//*****************************************************************************************
175if((mot[0]&0xff) == (tc_horloge&0xff) )
176
177 {
178 printf("horloge tc_transputer sans transputer:\n");
179 mot[1]=83-mot[1]; // periode
180 mot[2]=((mot[2]+5)-29 + 2* (((mot[2]+5)-1)/6) );
181 mot[2]=mot[2]+(mot[4]<<5); /* + les trois flags */
182
183 mot[4]=0;
184 for(j=0;j<8;j++)
185 {
186 printf(" %x ",mot[j]&0xff);
187 tc_char(mot[j]);
188 }
189 printf(" \n");
190 }
191
192else {
193 printf("tc_bebo directe:");
194 for(j=0;j<8;j++)
195 {
196 printf(" %x ",mot[j]&0xff);
197 tc_char(mot[j]);
198 }
199 printf(" \n");
200 }
201//*****************************************************************************************
202#else //--------- pour Archeops avec transputer ----------------------- ***
203//*****************************************************************************************
204switch(direction)
205 {
206 case tc_dir_transputer : //printf("tc_transputer:\n");
207 if( ((mot[0]&0xff)!=tc_reduite) && gg->flag_tc_reduite)
208 {
[649]209 printf("attention: une telecommande normale non envoyée !!\n\n");
[637]210 son(130);
211 select(printf_ref);
[649]212 break;
[637]213 }
214// pour test en mode simulation sans le retour des blocks reglage du transputer
[649]215 if(tt->PCI_actif==2)
216 {
217 relit_telecommandes_reduites(tc);
218 break;
219 }
220 else if(tt->PCI_actif==3)
221 {
222 simul_telecommandes_reduites(tc);
223 }
224 else {char ss[200];
225 static long t;
226
227#define tcl(iii) ((long)mot[iii])
228
229 long mothexa[5]; /* les 5 cara hexa envoyée */
230 /* on range les bit: bit 1 en poid fort de tout */
231 mothexa[0]=tcl(1); /* 4 bit choix de commande */
232 mothexa[1]=tcl(2)>>2; /* les 4 bits poid fort du code direction */
233 mothexa[2]=((tcl(2)<<2)&0xc) + ((tcl(3)>>6)&0x3);
234 mothexa[3]=(tcl(3)>>2)&0xf;
235 mothexa[4]=(tcl(3)&0x3) + 0x0C;
236 printf("commande 18bit: %d %d %d -> %lx%lx%lx%lx%lx ",tcl(1),tcl(2),tcl(3)
237 ,mothexa[0],mothexa[1],mothexa[2],mothexa[3],mothexa[4]);
238 ecritD(fenetre_controle,con_subscan,"tc: %x %x %x %x %x ",mothexa[0],mothexa[1],mothexa[2],mothexa[3],mothexa[4]);
239
[637]240 tc_char(0x11); // synchro
241 tc_int(debut_telecommande);
[649]242 for(j=0;j<4;j++) tc_char(mot[j]);
243 tc_char(0x00); // synchro
244 sprintf(ss,"S%X%X%X%X%X07WS%X%X%X%X%X07WS%X%X%X%X%X07W\r\n"
245 ,mothexa[0],mothexa[1],mothexa[2],mothexa[3],mothexa[4]
246 ,mothexa[0],mothexa[1],mothexa[2],mothexa[3],mothexa[4]
247 ,mothexa[0],mothexa[1],mothexa[2],mothexa[3],mothexa[4]);
248/* sprintf(ss,"S%x%x%x%x%x07WS%x%x%x%x%x07WS%x%x%x%x%x07W\r\l"
249 ,mothexa[0],mothexa[1],mothexa[2],mothexa[3],mothexa[4]
250 ,mothexa[0],mothexa[1],mothexa[2],mothexa[3],mothexa[4]
251 ,mothexa[0],mothexa[1],mothexa[2],mothexa[3],mothexa[4]);*/
252 if(ss[7]!='7') erreur("adresse not equal to 7");
253 if(ss[16]!='7') erreur("adresse not equal to 7");
254 if(ss[25]!='7') erreur("adresse not equal to 7");
255 while( (TickCount()>t) et (TickCount()<(t+60*15)) ) // 15sec
256 {
257 static int q;
258 q++;
259 son(130);
260 if(q%10==0) printf("attente pour envoi de telecommande\n");
261 controlemanip(0);
262 }
263 son(133);
264
265 printf(" envoi de la telecommande : %s \n",ss);
266 ecritRS(0,ss,0);
267 t=TickCount(); // 10 secondes (tick = 1/60 sec)
268 }
269/* else {
270 tc_char(0x11); // synchro
271 tc_int(debut_telecommande);
[637]272 for(j=0;j<8;j++) tc_char(mot[j]);
273 tc_int(fin_telecommande);
274 tc_char(0x00);tc_char(0x00); // synchro
275 }
[649]276*/
[637]277 break;
278
279 case tc_dir_reset_epld : //printf("tc_reset_epld:\n");
280
[649]281 for(j=0;j<8;j++) tc_char(j);
282 tc_char(1);tc_char(1);
283 tc_char(0x00);tc_char(0x00); // synchro
284
285 break;
286
287 case tc_dir_reset_trp : //printf("tc_reset_epld:\n");
288
[645]289 for(j=0;j<15;j++) tc_char(j); // reset epld+transputer
[637]290 tc_char(1);tc_char(1);
291 tc_char(0x00);tc_char(0x00); // synchro
292
293 break;
294
295 default : break;
296 }
297
298
299//*****************************************************************************************
300#endif //-------------------------------------------------------------------- ***
301//*****************************************************************************************
302
303// delai pour separer les télécommandes (archeops, transputer ou non)
[649]304if(acquisition_PCI) delai(1000);
[637]305
306#endif //-------------------------------------------------------------------- ***
307
308
309//*****************************************************************************************
310// ***
311#ifdef _diabolo //--------- pour Diabolo ------------------------------ ***
312// ***
313//*****************************************************************************************
314
315int q;
316
317// emission dans la table tc
318// la commande elle même est dans mot[0..9]
319// le parametre direction n'est pas utilisé
320
321if(!litD(fenetre_acquisition,e_tache_inter,0L) ) // ecriture forcée directe sur carte pci
322 {
323 for(j=0;j<5;j++) printf(".");
324 printf(" ecriture forcée des données \n");
325 for(j=0;j<10;j++) ecrit_carte(mot[j]);
326 son(1);
327 }
328
329
330else {
331 tt->tc.btc[tt->tc.pos_ecrit]=*((block_tc*)tc);
332 tt->tc.pos_ecrit++; if(tt->tc.pos_ecrit>=longueur_table_tc) tt->tc.pos_ecrit=0;
333 q=tt->tc.pos_ecrit-tt->tc.pos_lit; if (q<0) q+=longueur_table_tc;
334
335// printf(" liste de telecommande : %d chaines :",q);
336// printf(" %d %d %d %d %d %d %d %d %d %d\n",mot[0],mot[1],mot[2],mot[3],mot[4],mot[5],mot[6],mot[7],mot[8],mot[9]);
337// if(mot[0]==tc_regul) printf("telecommande regul: %d %d %d %d %d %d\n",mot[1],mot[2],mot[3],mot[4],mot[5],mot[6]);
338 }
339
340
341
342//*****************************************************************************************
343// ***
344#endif //-------------------------------------------------------------------- ***
345// ***
346//*****************************************************************************************
347
348}
349
350
Note: See TracBrowser for help on using the repository browser.