1 | /* |
---|
2 | The stellarium telescope library helps building |
---|
3 | telescope server programs, that can communicate with stellarium |
---|
4 | by means of the stellarium TCP telescope protocol. |
---|
5 | It also contains smaple server classes (dummy, Meade LX200). |
---|
6 | |
---|
7 | Author and Copyright of this file and of the stellarium telescope library: |
---|
8 | Johannes Gajdosik, 2006 |
---|
9 | |
---|
10 | This library is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU Lesser General Public |
---|
12 | License as published by the Free Software Foundation; either |
---|
13 | version 2.1 of the License, or (at your option) any later version. |
---|
14 | |
---|
15 | This library is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | Lesser General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU Lesser General Public |
---|
21 | License along with this library; if not, write to the Free Software |
---|
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | */ |
---|
24 | |
---|
25 | #include "ServerBAO.hpp" |
---|
26 | #include "Socket2.hpp" // GetNow |
---|
27 | |
---|
28 | #include <math.h> |
---|
29 | |
---|
30 | ServerDummy::ServerDummy(int port) |
---|
31 | :Server2(port) |
---|
32 | { |
---|
33 | last_pos[0] = current_pos[0] = desired_pos[0] = 1.0; |
---|
34 | last_pos[1] = current_pos[1] = desired_pos[1] = 0.0; |
---|
35 | last_pos[2] = current_pos[2] = desired_pos[2] = 0.0; |
---|
36 | next_pos_time = -0x8000000000000000LL; |
---|
37 | |
---|
38 | |
---|
39 | float a1, a2, a3; |
---|
40 | |
---|
41 | // Le choix de la couleur des caractÚres est adapté pour une fenêtre de terminal |
---|
42 | // ayant un fond blanc. pour un fond noir, mettre couleurs = 2 dans le fichier params |
---|
43 | |
---|
44 | ChoixCouleurs=1; |
---|
45 | |
---|
46 | // Affichage de la version du programme |
---|
47 | |
---|
48 | AfficherLog("\n\n\n\n\n \ |
---|
49 | ******************************************\n \ |
---|
50 | * BAORadio Control *\n \ |
---|
51 | * Laboratoire de l'Accélérateur Linéaire *\n \ |
---|
52 | * *\n \ |
---|
53 | * v0.52 19/04/2012 *\n \ |
---|
54 | * franckrichard033@gmail.com *\n \ |
---|
55 | ******************************************\n\n\n", true); |
---|
56 | |
---|
57 | |
---|
58 | // Initialisation des variables globales et des pointeurs |
---|
59 | // pour la signification des variables, voir baocontrol.h |
---|
60 | |
---|
61 | |
---|
62 | delaitransit = 0; |
---|
63 | delaitracking = 0; |
---|
64 | lognum = 0; |
---|
65 | numAntennes = 0; |
---|
66 | numobjets = 0; |
---|
67 | numEtoiles = 0; |
---|
68 | runnum = 1; |
---|
69 | |
---|
70 | MethodeAlignement = SIMPLE; |
---|
71 | |
---|
72 | Pression = 1013.0; |
---|
73 | Temperature = 10.0; |
---|
74 | |
---|
75 | NoExit = true; |
---|
76 | Transit = false; |
---|
77 | run = false; |
---|
78 | exitrun = false; |
---|
79 | ModificationAlignement = false; |
---|
80 | |
---|
81 | fd = NULL; |
---|
82 | client_socket = NULL; |
---|
83 | |
---|
84 | // chaînes de caractÚres et tableaux |
---|
85 | |
---|
86 | LatitudeChar = ""; |
---|
87 | LongitudeChar = ""; |
---|
88 | Serveur = ""; |
---|
89 | Port = ""; |
---|
90 | |
---|
91 | Antennes = new DefAntenne[ MAXANTENNES ]; |
---|
92 | objets = new DefObjets [ MAXOBJETS ]; |
---|
93 | Etoiles = new DefEtoiles[ MAXETOILES] ; |
---|
94 | |
---|
95 | |
---|
96 | // on initialise aussi les structures |
---|
97 | |
---|
98 | for (int i=0; i<MAXANTENNES; i++) |
---|
99 | { |
---|
100 | Antennes[i].ok = 0; |
---|
101 | Antennes[i].ip = 0; |
---|
102 | |
---|
103 | Antennes[i].AlignementAntenne = new Alignement(); |
---|
104 | } |
---|
105 | |
---|
106 | for (int i=0; i<MAXOBJETS; i++) |
---|
107 | { |
---|
108 | objets[i].JJ = 0.0; |
---|
109 | objets[i].exec = false; |
---|
110 | } |
---|
111 | |
---|
112 | for (int i=0; i<MAXETOILES; i++) |
---|
113 | { |
---|
114 | Etoiles[i].nom = ""; |
---|
115 | Etoiles[i].ad = 0.0; |
---|
116 | Etoiles[i].de = 0.0; |
---|
117 | Etoiles[i].az = 0.0; |
---|
118 | Etoiles[i].ha = 0.0; |
---|
119 | Etoiles[i].mag = 0.0; |
---|
120 | Etoiles[i].selectionnee = false; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | // Chargement du fichier contenant les paramÚtres de l'application BAOcontrol |
---|
125 | // La variable permet de récupérer le nom de l'utilisateur ayant ouvert la session sous linux |
---|
126 | // c'est dans le répertoire /home/USER/ que BAOcontrol cherche le fichier de paramÚtre baocontrol_params |
---|
127 | |
---|
128 | if (!ChargementParametres("/home/" + (string)getenv("USER") + "/baocontrol_params")) |
---|
129 | { |
---|
130 | ErreurLog("Le fichier de configuration 'params' contient des erreurs ou n'existe pas.\n"); |
---|
131 | ErreurLog("Il devrait se trouver dans le répertoire /home/" + (string)getenv("USER") +"\n"); |
---|
132 | ErreurLog("Merci de vérifier...\n\n"); |
---|
133 | exit(1); |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | // Conversion de la latitude et de la longitude en radians |
---|
138 | |
---|
139 | Decomposition(LatitudeChar, 0, &a1, &a2, &a3); |
---|
140 | |
---|
141 | double Latitude = (a1 + a2 / 60.0 + a3 / 3600.0) * Pidiv180; |
---|
142 | |
---|
143 | Decomposition(LongitudeChar, 1, &a1, &a2, &a3); |
---|
144 | |
---|
145 | double Longitude = Pi2 - ( a1 + a2 / 60.0 + a3 / 3600.0 ) * Pidiv180; |
---|
146 | |
---|
147 | |
---|
148 | // Transfert de la latitude, longitude, pression, température à la classe Astro |
---|
149 | |
---|
150 | DefinirLongitudeLatitude(Longitude, Latitude); |
---|
151 | |
---|
152 | DefinirPressionTemp(Pression, Temperature); |
---|
153 | // On lance les calculs (Temps sidéral local etc...) |
---|
154 | |
---|
155 | CalculTSL(); |
---|
156 | |
---|
157 | |
---|
158 | //Chargement du catalogue d'étoiles que l'on utilise pour l'alignement des antennes |
---|
159 | |
---|
160 | /* if ( !ChargementCatalogueEtoiles("/home/" + (string)getenv("USER") + "/bao_catalogue.dat") ) |
---|
161 | { |
---|
162 | ErreurLog("Le catalogue d'étoiles 'bao_catalogue' est introuvable.\n"); |
---|
163 | ErreurLog("Il devrait se trouver dans le répertoire /home/" + (string)getenv("USER") +"\n"); |
---|
164 | ErreurLog("Merci de vérifier...\n\n"); |
---|
165 | exit(1); |
---|
166 | } |
---|
167 | */ |
---|
168 | |
---|
169 | |
---|
170 | // Ouverture du socket avec indi_BAO |
---|
171 | |
---|
172 | client_socket = new ClientSocket("localhost", atoi(Port.c_str()) ); |
---|
173 | |
---|
174 | // On se connecte au pilote indi_BAO |
---|
175 | |
---|
176 | Connect(true); |
---|
177 | // On lance la fenêtre graphique |
---|
178 | |
---|
179 | initialiserFenetre(); |
---|
180 | |
---|
181 | XSelectInput(d,w, ExposureMask ); |
---|
182 | } |
---|
183 | |
---|
184 | void ServerDummy::step(long long int timeout_micros) |
---|
185 | { |
---|
186 | |
---|
187 | if (last_pos[0]!=current_pos[0] || last_pos[1]!=current_pos[1] || last_pos[2]!=current_pos[2]) |
---|
188 | { |
---|
189 | current_pos[0] = desired_pos[0]; |
---|
190 | current_pos[1] = desired_pos[1]; |
---|
191 | current_pos[2] = desired_pos[2]; |
---|
192 | |
---|
193 | const double ra = atan2(current_pos[1],current_pos[0]); |
---|
194 | const double dec = atan2(current_pos[2], |
---|
195 | sqrt(current_pos[0]*current_pos[0]+current_pos[1]*current_pos[1])); |
---|
196 | |
---|
197 | //On actualise le jour julien et le temps sidéral local |
---|
198 | |
---|
199 | Goto(DHMS(VerifAngle(ra)*180.0/M_PI, true), DHMS(dec*180.0/M_PI, false), Transit, true); |
---|
200 | |
---|
201 | last_pos[0] = current_pos[0]; |
---|
202 | last_pos[1] = current_pos[1]; |
---|
203 | last_pos[2] = current_pos[2]; |
---|
204 | } |
---|
205 | |
---|
206 | Update(); |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | // on lit et affiche la réponse des microcontrolleurs |
---|
211 | |
---|
212 | LireReponse(); |
---|
213 | |
---|
214 | Dessiner(); |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | Server2::step(timeout_micros); |
---|
221 | } |
---|
222 | |
---|
223 | void ServerDummy::gotoReceived(unsigned int ra_int, int dec_int) |
---|
224 | { |
---|
225 | const double ra = ra_int*(M_PI/(unsigned int)0x80000000); |
---|
226 | const double dec = dec_int*(M_PI/(unsigned int)0x80000000); |
---|
227 | const double cdec = cos(dec); |
---|
228 | desired_pos[0] = cos(ra)*cdec; |
---|
229 | desired_pos[1] = sin(ra)*cdec; |
---|
230 | desired_pos[2] = sin(dec); |
---|
231 | } |
---|
232 | |
---|
233 | |
---|
234 | /************************************************************************************** |
---|
235 | ** Affiche le message à l'écran (si AfficheEcran==true) et le sauvegarde dans le fichier |
---|
236 | ** BAOControl.log |
---|
237 | ***************************************************************************************/ |
---|
238 | |
---|
239 | void ServerDummy::Affiche(string Message, bool AfficheEcran) |
---|
240 | { |
---|
241 | FILE *pFile = NULL; |
---|
242 | |
---|
243 | if ( (pFile = fopen ("BAOcontrol.log", "a")) != NULL) |
---|
244 | { |
---|
245 | if (AfficheEcran) cout << Message; |
---|
246 | |
---|
247 | fprintf (pFile, Message.c_str()); |
---|
248 | |
---|
249 | fclose (pFile); |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | void ServerDummy::Affiche(stringstream *Message, bool AfficheEcran) |
---|
254 | { |
---|
255 | Affiche(Message->str(), AfficheEcran); |
---|
256 | |
---|
257 | // on efface le buffer |
---|
258 | |
---|
259 | Message->str(""); |
---|
260 | } |
---|
261 | |
---|
262 | |
---|
263 | /************************************************************************************** |
---|
264 | ** Affiche les messages d'erreur en rouge |
---|
265 | ***************************************************************************************/ |
---|
266 | |
---|
267 | void ServerDummy::Erreur(string chaine) |
---|
268 | { |
---|
269 | ChoixCouleurs==1 ? cout << red1 : cout << red2; |
---|
270 | Affiche(chaine, true); |
---|
271 | ChoixCouleurs==1 ? cout << grey1 : cout << grey2; |
---|
272 | } |
---|
273 | |
---|
274 | void ServerDummy::Erreur(stringstream *Message) |
---|
275 | { |
---|
276 | Erreur(Message->str()); |
---|
277 | |
---|
278 | // on efface le buffer |
---|
279 | |
---|
280 | Message->str(""); |
---|
281 | } |
---|
282 | |
---|
283 | |
---|
284 | /************************************************************************************** |
---|
285 | ** Initialise la fenêtre graphique |
---|
286 | ***************************************************************************************/ |
---|
287 | |
---|
288 | void ServerDummy::initialiserFenetre() |
---|
289 | { |
---|
290 | XGCValues gcv; |
---|
291 | |
---|
292 | // contacte le serveur graphique |
---|
293 | |
---|
294 | if ((d = XOpenDisplay(getenv("DISPLAY"))) == NULL) |
---|
295 | { |
---|
296 | Erreur("Impossible de contacter le serveur\n\n"); |
---|
297 | exit(1); |
---|
298 | } |
---|
299 | |
---|
300 | // crée une fenêtre |
---|
301 | |
---|
302 | w = XCreateSimpleWindow(d, RootWindow(d, DefaultScreen(d)), |
---|
303 | 0, 0, larg_fenetre, haut_fenetre, |
---|
304 | 2, BlackPixel(d, DefaultScreen(d)), |
---|
305 | WhitePixel(d, DefaultScreen(d))); |
---|
306 | |
---|
307 | // Création du double buffer |
---|
308 | |
---|
309 | db = XCreatePixmap(d, w, larg_fenetre, haut_fenetre, DefaultDepth(d, DefaultScreen(d))); |
---|
310 | |
---|
311 | // Chargement de la police de caractÚres |
---|
312 | |
---|
313 | if ((fd = XLoadQueryFont(d, "fixed")) == NULL) |
---|
314 | { |
---|
315 | Erreur("Impossible de charger la police fixed\n\n"); |
---|
316 | exit(1); |
---|
317 | } |
---|
318 | |
---|
319 | // Création des couleurs |
---|
320 | |
---|
321 | gcv.font = fd->fid; |
---|
322 | gcv.foreground = BlackPixel(d, DefaultScreen(d)); |
---|
323 | noir = XCreateGC(d, w, GCFont | GCForeground, &gcv); |
---|
324 | |
---|
325 | gcv.foreground = 200*255; |
---|
326 | vert = XCreateGC(d, w, GCFont | GCForeground, &gcv); |
---|
327 | |
---|
328 | gcv.foreground = 255*256*256; |
---|
329 | rouge = XCreateGC(d, w, GCFont | GCForeground, &gcv); |
---|
330 | |
---|
331 | gcv.foreground = 200*256*256+200*256+200; |
---|
332 | gris = XCreateGC(d, w, GCFont | GCForeground, &gcv); |
---|
333 | |
---|
334 | // Affichage de fenêtre |
---|
335 | |
---|
336 | XMapWindow(d, w); |
---|
337 | } |
---|
338 | |
---|
339 | |
---|
340 | /************************************************************************************** |
---|
341 | ** Dessine les éléments dans la fenêtre graphique |
---|
342 | ***************************************************************************************/ |
---|
343 | |
---|
344 | void ServerDummy::Dessiner() |
---|
345 | { |
---|
346 | char *chaine; |
---|
347 | GC color; |
---|
348 | |
---|
349 | chaine = new char [100]; |
---|
350 | |
---|
351 | // On efface la fenêtre |
---|
352 | |
---|
353 | XSetForeground(d, noir, WhitePixel(d, DefaultScreen(d))); |
---|
354 | XFillRectangle(d, db, noir, 0, 0, larg_fenetre, haut_fenetre); |
---|
355 | XSetForeground(d, noir, BlackPixel(d, DefaultScreen(d))); |
---|
356 | |
---|
357 | // On récupÚre la date et l'heure contenue dans la classe astro (et le jour julien) |
---|
358 | |
---|
359 | double h = GetHeure(); |
---|
360 | double mi = GetMin(); |
---|
361 | double s = GetSec(); |
---|
362 | double a = GetAnnee(); |
---|
363 | double m = GetMois(); |
---|
364 | double j = GetJour(); |
---|
365 | double JJ = GetJJ(); |
---|
366 | |
---|
367 | // on évite les affichages de l'heure du genre 12:56:60 ou 24:00:00 |
---|
368 | |
---|
369 | if (s==60) { |
---|
370 | s = 0; |
---|
371 | mi++; |
---|
372 | if (mi == 60) { |
---|
373 | mi = 0; |
---|
374 | h++; |
---|
375 | if (h == 24) { |
---|
376 | h = 0; |
---|
377 | j++; |
---|
378 | } |
---|
379 | } |
---|
380 | } |
---|
381 | |
---|
382 | //affichage de la date et de l'heure |
---|
383 | |
---|
384 | sprintf(chaine, "%02.0f:%02.0f:%02.1f TU %02.0f/%02.0f/%04.0f JJ=%10.5f", |
---|
385 | h, mi, s, j, m, a, JJ); |
---|
386 | |
---|
387 | XDrawString(d, db, noir, 10, 10, chaine, strlen(chaine)); |
---|
388 | |
---|
389 | //En cas d'exécution d'un fichier de mouvements, on affiche la prochaine étape |
---|
390 | |
---|
391 | if (run) |
---|
392 | { |
---|
393 | sprintf(chaine, "Prochaine etape dans %4.1fs", (objets[runnum].JJ - JJ) * 3600.0 * 24.0); |
---|
394 | |
---|
395 | if ((objets[runnum].JJ - JJ) * 3600.0 * 24.0 >= 0.0) |
---|
396 | XDrawString(d, db, noir, 350, 10, chaine, strlen(chaine)); |
---|
397 | } |
---|
398 | |
---|
399 | // affichage des cercles d'état |
---|
400 | // vert = l'antenne fonctionne |
---|
401 | // rouge = problÚme détecté sur l'antenne |
---|
402 | // gris = antenne non connectée |
---|
403 | |
---|
404 | for (int i=0; i <20; i++) |
---|
405 | { |
---|
406 | for (int j=0; j<2; j++) |
---|
407 | { |
---|
408 | switch (Antennes[20*j+i].ok) |
---|
409 | { |
---|
410 | case 1 : |
---|
411 | color=vert; |
---|
412 | break; |
---|
413 | case 2 : |
---|
414 | color=rouge; |
---|
415 | break; |
---|
416 | default: |
---|
417 | color=gris; |
---|
418 | break; |
---|
419 | } |
---|
420 | |
---|
421 | XFillArc(d, db ,color, 10+i*30, 20+j*30, 15, 15, 0, 360*64); |
---|
422 | XDrawArc(d, db ,noir, 10+i*30, 20+j*30, 15, 15, 0, 360*64); |
---|
423 | } |
---|
424 | } |
---|
425 | |
---|
426 | |
---|
427 | // Affichage des messages d'indi_BAO |
---|
428 | // gÚre aussi le défilement |
---|
429 | |
---|
430 | if (lognum>10) |
---|
431 | { |
---|
432 | for (int i=lognum-1; i>lognum-11; i--) |
---|
433 | { |
---|
434 | if ((logs[i].find("Err")!=string::npos) |
---|
435 | || (logs[i].find("ALERTE")!=string::npos)) color=rouge; |
---|
436 | else color=vert; |
---|
437 | XDrawString(d, db, color, 10, 9*12+(i-lognum+10)*12, logs[i].c_str(), strlen(logs[i].c_str())); |
---|
438 | } |
---|
439 | } |
---|
440 | else |
---|
441 | { |
---|
442 | for (int i=0; i<lognum; i++) |
---|
443 | { |
---|
444 | if ((logs[i].find("Err")!=string::npos) |
---|
445 | || (logs[i].find("ALERTE")!=string::npos)) color=rouge; |
---|
446 | else color=vert; |
---|
447 | XDrawString(d, db, color, 10, 9*12+i*12, logs[i].c_str(), strlen(logs[i].c_str())); |
---|
448 | } |
---|
449 | } |
---|
450 | |
---|
451 | // On affiche la copie de l'écran une fois que tout est dessiné |
---|
452 | // on évite ainsi les scientillements de la fenêtre |
---|
453 | |
---|
454 | XCopyArea(d, db, w, noir, 0, 0, larg_fenetre, haut_fenetre, 0, 0); |
---|
455 | |
---|
456 | // On force le rafraichissement de l'écran |
---|
457 | |
---|
458 | XFlush(d); |
---|
459 | |
---|
460 | delete [] chaine; |
---|
461 | } |
---|
462 | |
---|
463 | |
---|
464 | /************************************************************************************** |
---|
465 | ** Gestion des événements affectant la fenêtre graphique |
---|
466 | ***************************************************************************************/ |
---|
467 | |
---|
468 | void ServerDummy::rouler() |
---|
469 | { |
---|
470 | XEvent e; |
---|
471 | |
---|
472 | if (XCheckWindowEvent(d, w, ExposureMask, &e)) |
---|
473 | { |
---|
474 | switch (e.type) |
---|
475 | { |
---|
476 | default: |
---|
477 | //cout << "J'ai reçu un événement " << e.type << endl |
---|
478 | break; |
---|
479 | case Expose : |
---|
480 | Dessiner(); |
---|
481 | break; |
---|
482 | } |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | |
---|
487 | /************************************************************************************** |
---|
488 | ** RécupÚre les messages envoyés par indi_BAO |
---|
489 | ***************************************************************************************/ |
---|
490 | |
---|
491 | void ServerDummy::LireReponse() |
---|
492 | { |
---|
493 | string reponse, memreponse, decomp; |
---|
494 | |
---|
495 | bool test = false; |
---|
496 | |
---|
497 | // on récupÚre les messages provenant d'indi_BAO |
---|
498 | |
---|
499 | *client_socket >> reponse; |
---|
500 | |
---|
501 | do |
---|
502 | { |
---|
503 | // s'il contient le mot message (et vient donc d'indi_BAO) |
---|
504 | |
---|
505 | if (reponse.find("message") != string::npos) |
---|
506 | { |
---|
507 | // On ne garde que la partie intéressante |
---|
508 | // La partie qui suit "message="... |
---|
509 | |
---|
510 | reponse = reponse.substr(reponse.find("message") + 9); |
---|
511 | |
---|
512 | // (on en garde une trace) |
---|
513 | |
---|
514 | memreponse = reponse; |
---|
515 | |
---|
516 | // ...on extrait le message jusqu'au caractÚre " |
---|
517 | |
---|
518 | reponse = reponse.substr(0, reponse.find("\"")); |
---|
519 | |
---|
520 | // On récupÚre l'adresse ip de l'antenne qui nous parle |
---|
521 | // et on met à jour le tableau des états de l'antenne correspondante |
---|
522 | // Dans les messages d'indi_BAO, l'adresse ip précÚde les mots "Antennes connectées" |
---|
523 | |
---|
524 | if (reponse.find(" (Antennes connectees")!=string::npos) |
---|
525 | { |
---|
526 | decomp = reponse.substr(0, reponse.find(" (Antennes connectees")); |
---|
527 | decomp = decomp.substr(decomp.rfind(".")+1); |
---|
528 | |
---|
529 | // si cette antenne est déjà connectée, on change son état si nécessaire |
---|
530 | |
---|
531 | if ( atoi(decomp.c_str()) != 0 ) for (int i=0; i<numAntennes; i++) |
---|
532 | { |
---|
533 | // on a trouvé l'antenne correspondante |
---|
534 | |
---|
535 | if (atoi(decomp.c_str()) == Antennes[i].ip) |
---|
536 | { |
---|
537 | Antennes[i].ok = 1; |
---|
538 | test = true; |
---|
539 | break; |
---|
540 | } |
---|
541 | } |
---|
542 | |
---|
543 | // ou si c'est une nouvelle antenne, on l'ajoute au tableau Antennes |
---|
544 | |
---|
545 | if (!test) |
---|
546 | { |
---|
547 | Antennes[numAntennes].ip = atoi(decomp.c_str()); |
---|
548 | |
---|
549 | Antennes[numAntennes++].ok = 1; |
---|
550 | } |
---|
551 | } |
---|
552 | |
---|
553 | // erreur sur une antenne -> on change son état dans la fenêtre |
---|
554 | // on trouve les erreurs dans les messages d'indi_BAO formulée |
---|
555 | // de la façon suivante: "ALERTE antenne" ou bien "Erreur sur l antenne" |
---|
556 | |
---|
557 | if ((reponse.find("ALERTE antenne ") != string::npos) || |
---|
558 | (reponse.find("Erreur sur l antenne ") != string::npos)) |
---|
559 | { |
---|
560 | decomp = reponse.substr(0, reponse.find(" :")); |
---|
561 | decomp = decomp.substr(decomp.rfind(".") + 1); |
---|
562 | |
---|
563 | for (int i=0; i<numAntennes; i++) |
---|
564 | { |
---|
565 | // On identifie l'antenne dans le tableau Antennes et on change son état |
---|
566 | |
---|
567 | if (atoi(decomp.c_str()) == Antennes[i].ip) |
---|
568 | { |
---|
569 | Antennes[i].ok = 2; // Erreur sur l'antenne i |
---|
570 | } |
---|
571 | } |
---|
572 | } |
---|
573 | |
---|
574 | // On sauvegarde le message dans le fichier logs mais on ne l'affiche pas |
---|
575 | |
---|
576 | stringstream os; |
---|
577 | |
---|
578 | os << lognum << " : " << reponse; |
---|
579 | |
---|
580 | AfficherLog(os.str() + "\n", false); |
---|
581 | |
---|
582 | if ( lognum < MAXLOG - 1 ) logs[ lognum++ ] = os.str(); |
---|
583 | |
---|
584 | reponse = memreponse; |
---|
585 | } |
---|
586 | else reponse = ""; |
---|
587 | |
---|
588 | |
---|
589 | } while ( reponse != "" ); |
---|
590 | |
---|
591 | // on actualise la fenêtre |
---|
592 | |
---|
593 | Dessiner(); |
---|
594 | |
---|
595 | // on envoie un message pour actualiser la fenêtre graphique |
---|
596 | |
---|
597 | rouler(); |
---|
598 | } |
---|
599 | |
---|
600 | |
---|
601 | /************************************************************************************** |
---|
602 | ** Est-ce que la réponse du pilote indi_BAO est conforme à ce que l'on attendait ? |
---|
603 | ***************************************************************************************/ |
---|
604 | |
---|
605 | bool ServerDummy::VerifReponse(string reponseattendue, string *retourreponse) |
---|
606 | { |
---|
607 | string reponse = ""; |
---|
608 | string memreponse = ""; |
---|
609 | int duree = 0; |
---|
610 | bool test = false; |
---|
611 | |
---|
612 | |
---|
613 | // TODO :La réponse du driver ne vient pas tout de suite et on peut recevoir |
---|
614 | // des messages intermédiaires un peu étranges impliquant la fonction CONNECT, pourquoi ? |
---|
615 | // LÃ on lit les messages cinq fois de suite pour essayer de voir passer le bon |
---|
616 | // Essayer de voir si on ne peut pas faire mieux... |
---|
617 | |
---|
618 | if (retourreponse) *retourreponse = ""; |
---|
619 | |
---|
620 | for (int i=0; i<5 ; i++) |
---|
621 | { |
---|
622 | do |
---|
623 | { |
---|
624 | usleep(1000); // attendre 1 ms pour laisser le temps au pilote indi_BAO de répondre |
---|
625 | |
---|
626 | *client_socket >> reponse; |
---|
627 | |
---|
628 | duree++; |
---|
629 | } |
---|
630 | while (reponse.length() == 0 && duree < MAX_DELAI_REPONSE ); // on attend un message pendant 10 ms max |
---|
631 | |
---|
632 | // on ajoute tous les messages reçus dans memmreponse |
---|
633 | // ->intéressant pour le debug |
---|
634 | |
---|
635 | memreponse += reponse; |
---|
636 | |
---|
637 | if (reponse.find(reponseattendue) != string::npos) |
---|
638 | { |
---|
639 | test = true; |
---|
640 | break; |
---|
641 | } |
---|
642 | } |
---|
643 | |
---|
644 | |
---|
645 | if (!test) |
---|
646 | { |
---|
647 | // réponse inconnue -> une erreur ? |
---|
648 | |
---|
649 | long unsigned int pos = memreponse.find("message="); |
---|
650 | |
---|
651 | if ( pos != string::npos ) |
---|
652 | { |
---|
653 | memreponse = memreponse.substr(pos + 9); |
---|
654 | |
---|
655 | memreponse = memreponse.substr(0, memreponse.find("\"")); |
---|
656 | } |
---|
657 | |
---|
658 | if (memreponse != "") ErreurLog("Réponse du pilote indi_BAO :" + memreponse + "\n\n"); |
---|
659 | |
---|
660 | return false; |
---|
661 | } |
---|
662 | |
---|
663 | if (retourreponse) |
---|
664 | { |
---|
665 | long unsigned int pos = memreponse.find(reponseattendue); |
---|
666 | |
---|
667 | if ( pos != string::npos ) |
---|
668 | { |
---|
669 | memreponse = memreponse.substr(pos); |
---|
670 | |
---|
671 | memreponse = memreponse.substr(0, memreponse.find("\"")); |
---|
672 | } |
---|
673 | |
---|
674 | *retourreponse = memreponse; |
---|
675 | } |
---|
676 | |
---|
677 | return true; |
---|
678 | } |
---|
679 | |
---|
680 | |
---|
681 | /************************************************************************************** |
---|
682 | ** Calcul du jour julien et du temps sidéral local |
---|
683 | ***************************************************************************************/ |
---|
684 | |
---|
685 | void ServerDummy::Update() |
---|
686 | { |
---|
687 | struct tm date; |
---|
688 | time_t t; |
---|
689 | struct timeval tv; |
---|
690 | struct timezone tz; |
---|
691 | |
---|
692 | // On récupÚre la date et l'heure depuis l'horloge du systÚme |
---|
693 | |
---|
694 | time(&t); |
---|
695 | date=*gmtime(&t); |
---|
696 | gettimeofday(&tv, &tz); |
---|
697 | |
---|
698 | double Annee = (double)date.tm_year + 1900.0; |
---|
699 | double Mois = (double)date.tm_mon + 1.0; |
---|
700 | double Jour = (double)date.tm_mday; |
---|
701 | double Heu = (double)date.tm_hour; |
---|
702 | double Min = (double)date.tm_min; |
---|
703 | double Sec = (double)date.tm_sec + tv.tv_usec / 1.0E6; |
---|
704 | //double UTCP = 0.0;//(double)date.tm_isdst; |
---|
705 | |
---|
706 | /*Annee=2011; |
---|
707 | Mois=6; |
---|
708 | Jour=17; |
---|
709 | Heu=15; |
---|
710 | Min=53.0; |
---|
711 | Sec=00.0;*/ |
---|
712 | |
---|
713 | // On actualise la date et l'heure dans la classe Astro |
---|
714 | |
---|
715 | DefinirDateHeure(Annee, Mois, Jour, Heu, Min, Sec); |
---|
716 | |
---|
717 | |
---|
718 | // On lance le calcul |
---|
719 | |
---|
720 | CalculTSL(); |
---|
721 | } |
---|
722 | |
---|
723 | |
---|
724 | |
---|
725 | /************************************************************************************** |
---|
726 | ** Envoie la longitude et la latitude du lieu d'observation au pilote indi_BAO |
---|
727 | ** sous la forme de vecteurs xml |
---|
728 | ** (voir les particularités des drivers développés sous Indi) |
---|
729 | ** |
---|
730 | ***************************************************************************************/ |
---|
731 | |
---|
732 | bool ServerDummy::EnvoyerCoordGeographiques() |
---|
733 | { |
---|
734 | // la communication avec le pilote indi_BAO |
---|
735 | // se fait par l'envoi de trames au format xml |
---|
736 | |
---|
737 | try |
---|
738 | { |
---|
739 | *client_socket << "<newNumberVector device=\"BAO\" name=\"GEOGRAPHIC_COORD\">"; |
---|
740 | *client_socket << "<oneNumber name=\"LAT\">"; |
---|
741 | *client_socket << LatitudeChar; |
---|
742 | *client_socket << "</oneNumber>"; |
---|
743 | *client_socket << "<oneNumber name=\"LONG\">"; |
---|
744 | *client_socket << LongitudeChar; |
---|
745 | *client_socket << "</oneNumber>"; |
---|
746 | *client_socket << "</newNumberVector>"; |
---|
747 | |
---|
748 | if (!VerifReponse("name=\"GEOGRAPHIC_COORD\" state=\"Ok\"", NULL)) |
---|
749 | { |
---|
750 | ErreurLog("ERREUR fct EnvoyerCoordGeographiques : pas de réponse du pilote indi_BAO.\n\n"); |
---|
751 | |
---|
752 | return false; |
---|
753 | } |
---|
754 | } |
---|
755 | |
---|
756 | // un problÚme ? |
---|
757 | |
---|
758 | catch ( SocketException& e ) |
---|
759 | { |
---|
760 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
761 | |
---|
762 | return false; |
---|
763 | } |
---|
764 | |
---|
765 | AfficherLog("Les coordonnées géographiques ont bien été envoyées au pilote indi_BAO\n\n", true); |
---|
766 | |
---|
767 | return true; |
---|
768 | } |
---|
769 | |
---|
770 | |
---|
771 | /************************************************************************************** |
---|
772 | ** Transmet la pression et la température au pilote indi_BAO |
---|
773 | ** |
---|
774 | ***************************************************************************************/ |
---|
775 | |
---|
776 | bool ServerDummy::EnvoyerPressionTemperature() |
---|
777 | { |
---|
778 | stringstream os; |
---|
779 | |
---|
780 | try |
---|
781 | { |
---|
782 | *client_socket << "<newNumberVector device=\"BAO\" name=\"PRESSION_DATA\">"; |
---|
783 | *client_socket << "<oneNumber name=\"Pression\">"; |
---|
784 | os << Pression; |
---|
785 | *client_socket << os.str(); |
---|
786 | os.str(""); |
---|
787 | *client_socket << "</oneNumber>"; |
---|
788 | *client_socket << "<oneNumber name=\"Temperature\">"; |
---|
789 | os << Temperature; |
---|
790 | *client_socket << os.str(); |
---|
791 | os.str(""); |
---|
792 | *client_socket << "</oneNumber>"; |
---|
793 | *client_socket << "</newNumberVector>"; |
---|
794 | |
---|
795 | if (!VerifReponse("name=\"PRESSION_DATA\" state=\"Ok\"", NULL)) |
---|
796 | { |
---|
797 | ErreurLog("ERREUR fct EnvoyerPressionTemperature : pas de réponse du pilote indi_BAO.\n\n"); |
---|
798 | |
---|
799 | return false; |
---|
800 | } |
---|
801 | } |
---|
802 | |
---|
803 | // un problÚme ? |
---|
804 | |
---|
805 | catch ( SocketException& e ) |
---|
806 | { |
---|
807 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
808 | |
---|
809 | return false; |
---|
810 | } |
---|
811 | |
---|
812 | AfficherLog("La pression et la température ont bien été envoyées au pilote indi_BAO\n\n", true); |
---|
813 | |
---|
814 | return true; |
---|
815 | } |
---|
816 | |
---|
817 | /************************************************************************************** |
---|
818 | ** Envoie les paramÚtres delaitransit et delaitracking au pilote indi_BAO |
---|
819 | ** Ces paramÚtres définissent la durée (en sec) entre deux actualisations |
---|
820 | ** dans les modes tracking et transit |
---|
821 | ** |
---|
822 | ***************************************************************************************/ |
---|
823 | |
---|
824 | bool ServerDummy::EnvoyerDelaisModesTransitEtTracking() |
---|
825 | { |
---|
826 | stringstream os; |
---|
827 | |
---|
828 | try |
---|
829 | { |
---|
830 | os << delaitransit; |
---|
831 | *client_socket << "<newNumberVector device=\"BAO\" name=\"DELAY1\">"; |
---|
832 | *client_socket << "<oneNumber name=\"DELAY\">"; |
---|
833 | *client_socket << os.str(); |
---|
834 | *client_socket << "</oneNumber>"; |
---|
835 | *client_socket << "</newNumberVector>"; |
---|
836 | os.str(""); |
---|
837 | |
---|
838 | if (!VerifReponse("name=\"DELAY1\" state=\"Ok\"", NULL)) |
---|
839 | { |
---|
840 | ErreurLog("ERREUR fct EnvoyerDelaisModesTransitEtTracking : pas de réponse du pilote indi_BAO.\n\n"); |
---|
841 | |
---|
842 | return false; |
---|
843 | } |
---|
844 | |
---|
845 | os << delaitracking; |
---|
846 | *client_socket << "<newNumberVector device=\"BAO\" name=\"DELAY2\">"; |
---|
847 | *client_socket << "<oneNumber name=\"DELAY\">"; |
---|
848 | *client_socket << os.str(); |
---|
849 | *client_socket << "</oneNumber>"; |
---|
850 | *client_socket << "</newNumberVector>"; |
---|
851 | os.str(""); |
---|
852 | |
---|
853 | if (!VerifReponse("name=\"DELAY2\" state=\"Ok\"", NULL)) |
---|
854 | { |
---|
855 | ErreurLog("ERREUR fct EnvoyerDelaisModesTransitEtTracking : pas de réponse du pilote indi_BAO.\n\n"); |
---|
856 | |
---|
857 | return false; |
---|
858 | } |
---|
859 | } |
---|
860 | |
---|
861 | // un problÚme ? |
---|
862 | |
---|
863 | catch ( SocketException& e ) |
---|
864 | { |
---|
865 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
866 | |
---|
867 | return false; |
---|
868 | } |
---|
869 | |
---|
870 | return true; |
---|
871 | } |
---|
872 | |
---|
873 | |
---|
874 | |
---|
875 | /************************************************************************************** |
---|
876 | ** Envoie la méthode d'alignement au pilote indi_bao |
---|
877 | ** Ce paramÚtre peut être SIMPLE, AFFINE ou TAKI |
---|
878 | ** |
---|
879 | ***************************************************************************************/ |
---|
880 | |
---|
881 | bool ServerDummy::EnvoyerMethodeAlignement() |
---|
882 | { |
---|
883 | stringstream os; |
---|
884 | |
---|
885 | try |
---|
886 | { |
---|
887 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"ALIGNMENT_SET\">"; |
---|
888 | *client_socket << "<oneSwitch name=\"SIMPLE\">"; |
---|
889 | (MethodeAlignement == SIMPLE) ? *client_socket << "On" : *client_socket << "Off"; |
---|
890 | *client_socket << "</oneSwitch>"; |
---|
891 | *client_socket << "<oneSwitch name=\"AFFINE\">"; |
---|
892 | (MethodeAlignement == AFFINE) ? *client_socket << "On" : *client_socket << "Off"; |
---|
893 | *client_socket << "</oneSwitch>"; |
---|
894 | *client_socket << "<oneSwitch name=\"TAKI\">"; |
---|
895 | (MethodeAlignement == TAKI) ? *client_socket << "On" : *client_socket << "Off"; |
---|
896 | *client_socket << "</oneSwitch>"; |
---|
897 | *client_socket << "</newSwitchVector>"; |
---|
898 | |
---|
899 | if (!VerifReponse("name=\"ALIGNMENT_SET\" state=\"Ok\"", NULL)) |
---|
900 | { |
---|
901 | ErreurLog("ERREUR fct EnvoyerMethodeAlignement : pas de réponse du pilote indi_BAO.\n\n"); |
---|
902 | |
---|
903 | return false; |
---|
904 | } |
---|
905 | } |
---|
906 | |
---|
907 | // un problÚme ? |
---|
908 | |
---|
909 | catch ( SocketException& e ) |
---|
910 | { |
---|
911 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
912 | |
---|
913 | return false; |
---|
914 | } |
---|
915 | |
---|
916 | return true; |
---|
917 | } |
---|
918 | |
---|
919 | |
---|
920 | /************************************************************************************** |
---|
921 | ** Envoie une commande aux antennes |
---|
922 | ** exemples : P, Z, A, Gf1000f0100 |
---|
923 | ** |
---|
924 | ***************************************************************************************/ |
---|
925 | |
---|
926 | bool ServerDummy::EnvoyerCommande(string commande) |
---|
927 | { |
---|
928 | stringstream os; |
---|
929 | |
---|
930 | try |
---|
931 | { |
---|
932 | *client_socket << "<newTextVector device=\"BAO\" name=\"COMMAND_SET\">"; |
---|
933 | *client_socket << "<oneText name=\"COMMAND\">"; |
---|
934 | *client_socket << commande; |
---|
935 | *client_socket << "</oneText>"; |
---|
936 | *client_socket << "</newTextVector>"; |
---|
937 | |
---|
938 | if (!VerifReponse("name=\"COMMAND_SET\" state=\"Ok\"", NULL)) |
---|
939 | { |
---|
940 | ErreurLog("ERREUR fct EnvoyerCommande : pas de réponse du pilote indi_BAO.\n\n"); |
---|
941 | |
---|
942 | return false; |
---|
943 | } |
---|
944 | |
---|
945 | } |
---|
946 | |
---|
947 | |
---|
948 | // un problÚme ? |
---|
949 | |
---|
950 | catch ( SocketException& e ) |
---|
951 | { |
---|
952 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
953 | |
---|
954 | return false; |
---|
955 | } |
---|
956 | |
---|
957 | return true; |
---|
958 | } |
---|
959 | |
---|
960 | |
---|
961 | |
---|
962 | /************************************************************************************** |
---|
963 | ** Place les antennes en position de repos |
---|
964 | ** |
---|
965 | ***************************************************************************************/ |
---|
966 | |
---|
967 | bool ServerDummy::Park() |
---|
968 | { |
---|
969 | try |
---|
970 | { |
---|
971 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"\" >"; |
---|
972 | *client_socket << "<oneSwitch name=\"PARK\">"; |
---|
973 | *client_socket << "On"; |
---|
974 | *client_socket << "</oneSwitch>"; |
---|
975 | *client_socket << "</newSwitchVector>"; |
---|
976 | |
---|
977 | if (!VerifReponse("PARK OK", NULL)) |
---|
978 | { |
---|
979 | ErreurLog("La commande PARK a échoué.\n\n");; |
---|
980 | |
---|
981 | return false; |
---|
982 | } |
---|
983 | } |
---|
984 | catch ( SocketException& e) |
---|
985 | { |
---|
986 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
987 | |
---|
988 | return false; |
---|
989 | } |
---|
990 | |
---|
991 | AfficherLog("Le pilote indi_BAO a bien reçu la commande PARK.\n\n", true); |
---|
992 | |
---|
993 | return true; |
---|
994 | } |
---|
995 | |
---|
996 | |
---|
997 | |
---|
998 | /************************************************************************************** |
---|
999 | ** Annule le mouvement en cours |
---|
1000 | ** |
---|
1001 | ***************************************************************************************/ |
---|
1002 | |
---|
1003 | bool ServerDummy::Abort() |
---|
1004 | { |
---|
1005 | try |
---|
1006 | { |
---|
1007 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"ABORT_MOTION\" >"; |
---|
1008 | *client_socket << "<oneSwitch name=\"ABORT\">"; |
---|
1009 | *client_socket << "On"; |
---|
1010 | *client_socket << "</oneSwitch>"; |
---|
1011 | *client_socket << "</newSwitchVector>"; |
---|
1012 | |
---|
1013 | if (!VerifReponse("ABORT OK", NULL)) |
---|
1014 | { |
---|
1015 | ErreurLog("L'annulation a échoué.\n\n"); |
---|
1016 | |
---|
1017 | return false; |
---|
1018 | } |
---|
1019 | } |
---|
1020 | catch ( SocketException& e) |
---|
1021 | { |
---|
1022 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
1023 | |
---|
1024 | return false; |
---|
1025 | } |
---|
1026 | |
---|
1027 | AfficherLog("Le pilote indi_BAO a bien reçu la commande ABORT.\n\n", true); |
---|
1028 | |
---|
1029 | return true; |
---|
1030 | } |
---|
1031 | |
---|
1032 | |
---|
1033 | /************************************************************************************** |
---|
1034 | ** Alignement de l'antenne ip |
---|
1035 | ** |
---|
1036 | ***************************************************************************************/ |
---|
1037 | |
---|
1038 | bool ServerDummy::AlignementIP(string ip) |
---|
1039 | { |
---|
1040 | try |
---|
1041 | { |
---|
1042 | *client_socket << "<newTextVector device=\"BAO\" name=\"ALIGNEMENT_IP\">"; |
---|
1043 | *client_socket << "<oneText name=\"IP\">"; |
---|
1044 | *client_socket << ip; |
---|
1045 | *client_socket << "</oneText>"; |
---|
1046 | *client_socket << "</newTextVector>"; |
---|
1047 | |
---|
1048 | |
---|
1049 | if (!VerifReponse("est maintenant prete pour l alignement", NULL)) |
---|
1050 | { |
---|
1051 | ErreurLog("La sélection de l'antenne située à l'adresse ip a échoué.\n\n"); |
---|
1052 | |
---|
1053 | return false; |
---|
1054 | } |
---|
1055 | } |
---|
1056 | catch ( SocketException& e) |
---|
1057 | { |
---|
1058 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
1059 | |
---|
1060 | return false; |
---|
1061 | } |
---|
1062 | |
---|
1063 | AfficherLog("Le pilote indi_BAO a bien sélectionné l'antenne situé à l'adresse ip pour l'alignement.\n\n", true); |
---|
1064 | |
---|
1065 | return true; |
---|
1066 | } |
---|
1067 | |
---|
1068 | |
---|
1069 | /************************************************************************************** |
---|
1070 | ** Augmenter ou diminuer le delta en ascension droite ou en déclinaison |
---|
1071 | ** |
---|
1072 | ***************************************************************************************/ |
---|
1073 | |
---|
1074 | bool ServerDummy::AlignementDelta(string delta, bool azimut) |
---|
1075 | { |
---|
1076 | string Message = ""; |
---|
1077 | |
---|
1078 | try |
---|
1079 | { |
---|
1080 | if (azimut) |
---|
1081 | { |
---|
1082 | if (delta == "-1") |
---|
1083 | { *client_socket << "<newSwitchVector device=\"BAO\" name=\"AZ\" >"; |
---|
1084 | *client_socket << "<oneSwitch name=\"AZM\">"; |
---|
1085 | *client_socket << "On"; |
---|
1086 | *client_socket << "</oneSwitch>"; |
---|
1087 | *client_socket << "</newSwitchVector>"; |
---|
1088 | } |
---|
1089 | else |
---|
1090 | { |
---|
1091 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"AZ\" >"; |
---|
1092 | *client_socket << "<oneSwitch name=\"AZP\">"; |
---|
1093 | *client_socket << "On"; |
---|
1094 | *client_socket << "</oneSwitch>"; |
---|
1095 | *client_socket << "</newSwitchVector>"; |
---|
1096 | } |
---|
1097 | |
---|
1098 | if (!VerifReponse("Delta", &Message)) |
---|
1099 | { |
---|
1100 | ErreurLog("BAOcontrol:AlignementDelta a échoué.\n\n"); |
---|
1101 | |
---|
1102 | return false; |
---|
1103 | } |
---|
1104 | } |
---|
1105 | else |
---|
1106 | { |
---|
1107 | if (delta == "-1") |
---|
1108 | { |
---|
1109 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"ALT_N\" >"; |
---|
1110 | *client_socket << "<oneSwitch name=\"ALTN\">"; |
---|
1111 | *client_socket << "On"; |
---|
1112 | *client_socket << "</oneSwitch>"; |
---|
1113 | *client_socket << "</newSwitchVector>"; |
---|
1114 | |
---|
1115 | if (!VerifReponse("Delta", &Message)) |
---|
1116 | { |
---|
1117 | ErreurLog("BAOcontrol:AlignementDelta a échoué.\n\n"); |
---|
1118 | |
---|
1119 | return false; |
---|
1120 | } |
---|
1121 | } |
---|
1122 | else |
---|
1123 | { |
---|
1124 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"ALT_P\" >"; |
---|
1125 | *client_socket << "<oneSwitch name=\"ALTP\">"; |
---|
1126 | *client_socket << "On"; |
---|
1127 | *client_socket << "</oneSwitch>"; |
---|
1128 | *client_socket << "</newSwitchVector>"; |
---|
1129 | |
---|
1130 | if (!VerifReponse("Delta", &Message)) |
---|
1131 | { |
---|
1132 | ErreurLog("BAOcontrol:AlignementDelta a échoué.\n\n"); |
---|
1133 | |
---|
1134 | return false; |
---|
1135 | } |
---|
1136 | } |
---|
1137 | } |
---|
1138 | |
---|
1139 | if (Message != "") AfficherLog(Message + "\n\n", true); |
---|
1140 | } |
---|
1141 | catch ( SocketException& e) |
---|
1142 | { |
---|
1143 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
1144 | |
---|
1145 | return false; |
---|
1146 | } |
---|
1147 | |
---|
1148 | // AfficherLog("Le pilote indi_BAO a bien sélectionné l'antenne situé à l'adresse ip pour l'alignement.\n\n", true); |
---|
1149 | |
---|
1150 | return true; |
---|
1151 | } |
---|
1152 | |
---|
1153 | |
---|
1154 | /************************************************************************************** |
---|
1155 | ** Validation de l'alignement sur l'étoile visée actuellement |
---|
1156 | ** |
---|
1157 | ***************************************************************************************/ |
---|
1158 | |
---|
1159 | bool ServerDummy::ValidationAlignement() |
---|
1160 | { |
---|
1161 | try |
---|
1162 | { |
---|
1163 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"ALIGNMENT_OK\" >"; |
---|
1164 | *client_socket << "<oneSwitch name=\"OK\">"; |
---|
1165 | *client_socket << "On"; |
---|
1166 | *client_socket << "</oneSwitch>"; |
---|
1167 | *client_socket << "</newSwitchVector>"; |
---|
1168 | |
---|
1169 | if (!VerifReponse("alignement ont ete valides", NULL)) |
---|
1170 | { |
---|
1171 | ErreurLog("L'alignement sur l'étoile n'a pu être validé.\n\n"); |
---|
1172 | |
---|
1173 | return false; |
---|
1174 | } |
---|
1175 | } |
---|
1176 | catch ( SocketException& e) |
---|
1177 | { |
---|
1178 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
1179 | |
---|
1180 | return false; |
---|
1181 | } |
---|
1182 | |
---|
1183 | AfficherLog("L'alignement sur l'étoile a bien été validé.\n\n", true); |
---|
1184 | |
---|
1185 | return true; |
---|
1186 | } |
---|
1187 | |
---|
1188 | |
---|
1189 | /************************************************************************************** |
---|
1190 | ** Sauvegarde de l'alignement |
---|
1191 | ** |
---|
1192 | ***************************************************************************************/ |
---|
1193 | |
---|
1194 | bool ServerDummy::SauvegardeAlignement() |
---|
1195 | { |
---|
1196 | try |
---|
1197 | { |
---|
1198 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"ALIGNMENT_OK\" >"; |
---|
1199 | *client_socket << "<oneSwitch name=\"SAUV\">"; |
---|
1200 | *client_socket << "On"; |
---|
1201 | *client_socket << "</oneSwitch>"; |
---|
1202 | *client_socket << "</newSwitchVector>"; |
---|
1203 | |
---|
1204 | if (!VerifReponse("Les parametres de l alignement ont ete sauvegardes", NULL)) |
---|
1205 | { |
---|
1206 | ErreurLog("La sauvegarde des paramÚtres de l'alignement a échoué.\n\n"); |
---|
1207 | |
---|
1208 | return false; |
---|
1209 | } |
---|
1210 | } |
---|
1211 | catch ( SocketException& e) |
---|
1212 | { |
---|
1213 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
1214 | |
---|
1215 | return false; |
---|
1216 | } |
---|
1217 | |
---|
1218 | AfficherLog("Les paramÚtres de l'alignemeent ont bien été sauvegardés.\n\n", true); |
---|
1219 | |
---|
1220 | return true; |
---|
1221 | } |
---|
1222 | |
---|
1223 | |
---|
1224 | |
---|
1225 | /************************************************************************************** |
---|
1226 | ** Sauvegarde de l'alignement |
---|
1227 | ** |
---|
1228 | ***************************************************************************************/ |
---|
1229 | |
---|
1230 | bool ServerDummy::ResetAlignement() |
---|
1231 | { |
---|
1232 | try |
---|
1233 | { |
---|
1234 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"ALIGNMENT_RESET\" >"; |
---|
1235 | *client_socket << "<oneSwitch name=\"RESET\">"; |
---|
1236 | *client_socket << "On"; |
---|
1237 | *client_socket << "</oneSwitch>"; |
---|
1238 | *client_socket << "</newSwitchVector>"; |
---|
1239 | |
---|
1240 | if (!VerifReponse("reinitialises", NULL)) |
---|
1241 | { |
---|
1242 | ErreurLog("Impossible de réinitialiser les paramÚtres d'alignement de l'antenne.\n\n"); |
---|
1243 | |
---|
1244 | return false; |
---|
1245 | } |
---|
1246 | } |
---|
1247 | catch ( SocketException& e) |
---|
1248 | { |
---|
1249 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
1250 | |
---|
1251 | return false; |
---|
1252 | } |
---|
1253 | |
---|
1254 | AfficherLog("Les paramÚtres d'alignement de l'antenne ont été réinitialisés.\n\n", true); |
---|
1255 | |
---|
1256 | return true; |
---|
1257 | } |
---|
1258 | |
---|
1259 | |
---|
1260 | /************************************************************************************** |
---|
1261 | ** Sélection vitesse alignement |
---|
1262 | ** |
---|
1263 | ***************************************************************************************/ |
---|
1264 | |
---|
1265 | bool ServerDummy::VitesseAlignement(int vit) |
---|
1266 | { |
---|
1267 | string Message = ""; |
---|
1268 | |
---|
1269 | try |
---|
1270 | { |
---|
1271 | if (vit == 1) |
---|
1272 | { |
---|
1273 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"RAQ\" >"; |
---|
1274 | *client_socket << "<oneSwitch name=\"RAQ1\">"; |
---|
1275 | *client_socket << "On"; |
---|
1276 | *client_socket << "</oneSwitch>"; |
---|
1277 | *client_socket << "</newSwitchVector>"; |
---|
1278 | |
---|
1279 | if (!VerifReponse("La vitesse de la raquette est fixee a 1x", &Message)) |
---|
1280 | { |
---|
1281 | ErreurLog("Impossible de modifier la vitesse de la raquette.\n\n"); |
---|
1282 | |
---|
1283 | return false; |
---|
1284 | } |
---|
1285 | } |
---|
1286 | else |
---|
1287 | { |
---|
1288 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"RAQ\" >"; |
---|
1289 | *client_socket << "<oneSwitch name=\"RAQ10\">"; |
---|
1290 | *client_socket << "On"; |
---|
1291 | *client_socket << "</oneSwitch>"; |
---|
1292 | *client_socket << "</newSwitchVector>"; |
---|
1293 | |
---|
1294 | if (!VerifReponse("La vitesse de la raquette est fixee a 10x", &Message)) |
---|
1295 | { |
---|
1296 | ErreurLog("Impossible de modifier la vitesse de la raquette.\n\n"); |
---|
1297 | |
---|
1298 | return false; |
---|
1299 | } |
---|
1300 | } |
---|
1301 | |
---|
1302 | |
---|
1303 | |
---|
1304 | } |
---|
1305 | catch ( SocketException& e) |
---|
1306 | { |
---|
1307 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
1308 | |
---|
1309 | return false; |
---|
1310 | } |
---|
1311 | |
---|
1312 | if (Message != "") AfficherLog(Message +"\n\n", true); |
---|
1313 | |
---|
1314 | return true; |
---|
1315 | } |
---|
1316 | |
---|
1317 | /************************************************************************************** |
---|
1318 | ** Dirige l'antenne vers les coordonnées ar et dec et suit l'objet en activant le mode |
---|
1319 | ** transit ou tracking. |
---|
1320 | ** |
---|
1321 | ** si J2000 == true, cela signifie que les coordonnées ar et dec sont données dans le |
---|
1322 | ** le systÚme de coordonnées J2000 (écliptique et équinoxe du 1 janvier 2000 à 0 h TU) |
---|
1323 | ** Des calculs supplémentaires (précession, nutation, aberration) sont alors réalisés |
---|
1324 | ** pour ramener les coordonnées horaires à l'écliptique et l'équinoxe de la date de |
---|
1325 | ** l'observation. |
---|
1326 | ** |
---|
1327 | ***************************************************************************************/ |
---|
1328 | |
---|
1329 | bool ServerDummy::Goto(string ar, string dec, bool Transit, bool J2000) |
---|
1330 | { |
---|
1331 | double arf, decf; |
---|
1332 | float ar1, ar2, ar3; |
---|
1333 | float dec1, dec2, dec3; |
---|
1334 | |
---|
1335 | |
---|
1336 | // Conversion de l'AD et de la déclinaison en radians |
---|
1337 | |
---|
1338 | Decomposition(ar, 2, &ar1, &ar2, &ar3); |
---|
1339 | |
---|
1340 | Decomposition(dec, 0, &dec1, &dec2, &dec3); |
---|
1341 | |
---|
1342 | arf = ( ar1 + ar2 / 60.0 + ar3 / 3600.0 ) * 15.0 * Pidiv180; |
---|
1343 | |
---|
1344 | decf = ( fabs(dec1) + dec2 / 60.0 + dec3 / 3600.0 ) * Pidiv180; |
---|
1345 | |
---|
1346 | if (dec[0] == '-') decf = -decf; |
---|
1347 | |
---|
1348 | // Calculs supplémentaires pour ramener les coordonnées horaires |
---|
1349 | // à l'époque de l'observation |
---|
1350 | |
---|
1351 | if ( J2000 ) |
---|
1352 | { |
---|
1353 | Precession(&arf, &decf); |
---|
1354 | NutationEtoile(&arf, &decf); |
---|
1355 | AberrationAnnuelle(&arf, &decf); |
---|
1356 | } |
---|
1357 | |
---|
1358 | // on réécrit l'ar et la dec dans le format d'indi_BAO |
---|
1359 | |
---|
1360 | ar = DHMS(arf * N180divPi, true); |
---|
1361 | |
---|
1362 | dec = DHMS(decf * N180divPi, false); |
---|
1363 | |
---|
1364 | // on en informe l'utilisateur |
---|
1365 | |
---|
1366 | AfficherLog("Coordonnées apparentes de l'objet :\n", true); |
---|
1367 | |
---|
1368 | AfficherLog("AD=" + ar + " Dec=" + dec +"\n", true); |
---|
1369 | |
---|
1370 | |
---|
1371 | // On transmet les coordonnées au pilote BAO |
---|
1372 | |
---|
1373 | try |
---|
1374 | { |
---|
1375 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"ON_COORD_SET\">"; |
---|
1376 | *client_socket << "<oneSwitch name=\"TRANSIT\">"; |
---|
1377 | (Transit) ? *client_socket << "On" : *client_socket << "Off"; |
---|
1378 | *client_socket << "</oneSwitch>"; |
---|
1379 | |
---|
1380 | *client_socket << "<oneSwitch name=\"TRACKING\">"; |
---|
1381 | (Transit) ? *client_socket << "Off" : *client_socket << "On"; |
---|
1382 | *client_socket << "</oneSwitch>"; |
---|
1383 | *client_socket << "</newSwitchVector>"; |
---|
1384 | |
---|
1385 | if (!VerifReponse("name=\"ON_COORD_SET\"", NULL)) |
---|
1386 | { |
---|
1387 | ErreurLog("Le changement de mode TRANSIT/TRACKING a échoué.\n\n"); |
---|
1388 | |
---|
1389 | return false; |
---|
1390 | } |
---|
1391 | |
---|
1392 | *client_socket << "<newNumberVector device=\"BAO\" name=\"EQUATORIAL_EOD_COORD_REQUEST\">"; |
---|
1393 | *client_socket << "<oneNumber name=\"RA\">"; |
---|
1394 | *client_socket << ar; |
---|
1395 | *client_socket << "</oneNumber>"; |
---|
1396 | *client_socket << "<oneNumber name=\"DEC\">"; |
---|
1397 | *client_socket << dec; |
---|
1398 | *client_socket << "</oneNumber>"; |
---|
1399 | *client_socket << "</newNumberVector>"; |
---|
1400 | |
---|
1401 | if (!VerifReponse("name=\"EQUATORIAL_EOD_COORD_REQUEST\"", NULL)) |
---|
1402 | { |
---|
1403 | ErreurLog("Le transfert des coordonnées de l'objet a échoué.\n\n"); |
---|
1404 | |
---|
1405 | return false; |
---|
1406 | } |
---|
1407 | } |
---|
1408 | catch ( SocketException& e) |
---|
1409 | { |
---|
1410 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
1411 | |
---|
1412 | return false; |
---|
1413 | } |
---|
1414 | |
---|
1415 | AfficherLog("Les nouvelles coordonnées AD=" + ar + " Dec=" + dec, true); |
---|
1416 | AfficherLog(" ont été envoyées au pilote indi_BAO.\n\n", true); |
---|
1417 | |
---|
1418 | return true; |
---|
1419 | } |
---|
1420 | |
---|
1421 | /************************************************************************************** |
---|
1422 | ** Se connecte ou se déconnecte au pilote indi_BAO |
---|
1423 | ** |
---|
1424 | ***************************************************************************************/ |
---|
1425 | |
---|
1426 | bool ServerDummy::Connect(bool connect) |
---|
1427 | { |
---|
1428 | try |
---|
1429 | { |
---|
1430 | *client_socket << "<newSwitchVector device=\"BAO\" name=\"CONNECTION\">"; |
---|
1431 | |
---|
1432 | (connect) ? *client_socket << "<oneSwitch name=\"CONNECT\">" : *client_socket << "<oneSwitch name=\"DISCONNECT\">"; |
---|
1433 | |
---|
1434 | *client_socket << "On"; |
---|
1435 | *client_socket << "</oneSwitch>"; |
---|
1436 | *client_socket << "</newSwitchVector>"; |
---|
1437 | |
---|
1438 | if (connect) |
---|
1439 | { |
---|
1440 | if (!VerifReponse("BAORadio is online", NULL)) |
---|
1441 | { |
---|
1442 | ErreurLog("La connexion a échoué.\n\n"); |
---|
1443 | |
---|
1444 | return false; |
---|
1445 | } |
---|
1446 | } |
---|
1447 | else |
---|
1448 | { |
---|
1449 | if (!VerifReponse("BAORadio is offline", NULL)) |
---|
1450 | { |
---|
1451 | ErreurLog("La déconnexion a échoué.\n\n"); |
---|
1452 | |
---|
1453 | return false; |
---|
1454 | } |
---|
1455 | } |
---|
1456 | } |
---|
1457 | |
---|
1458 | catch ( SocketException& e ) |
---|
1459 | { |
---|
1460 | ErreurLog("Exception was caught:" + e.description() + "\n"); |
---|
1461 | |
---|
1462 | return false; |
---|
1463 | } |
---|
1464 | |
---|
1465 | if (connect) |
---|
1466 | { |
---|
1467 | AfficherLog("La connexion a été établie avec le pilote indi_BAO.\n\n", true); |
---|
1468 | |
---|
1469 | // Au moment de la connexion avec le driver indi_BAO |
---|
1470 | // On transmet les paramÚtres du lieu de l'observation, le mode de suivi |
---|
1471 | // ainsi que la méthode d'alignement utilisée |
---|
1472 | |
---|
1473 | usleep(500000); |
---|
1474 | |
---|
1475 | EnvoyerCoordGeographiques(); |
---|
1476 | |
---|
1477 | EnvoyerPressionTemperature(); |
---|
1478 | |
---|
1479 | EnvoyerDelaisModesTransitEtTracking(); |
---|
1480 | |
---|
1481 | EnvoyerMethodeAlignement(); |
---|
1482 | } |
---|
1483 | else |
---|
1484 | { |
---|
1485 | AfficherLog("BAOcontrol s'est bien déconnecté du pilote indi_BAO.\n\n", true); |
---|
1486 | } |
---|
1487 | |
---|
1488 | return true; |
---|
1489 | } |
---|
1490 | |
---|
1491 | |
---|
1492 | |
---|
1493 | /************************************************************************************** |
---|
1494 | ** Décomposition et vérification des dates, heures, AD et déclinaisons |
---|
1495 | ** |
---|
1496 | ** type = 0 -> Déclinaison/latitude |
---|
1497 | ** type = 1 -> longitude |
---|
1498 | ** type = 2 -> AD ou heure |
---|
1499 | ** type = 3 -> date |
---|
1500 | ** |
---|
1501 | ** Exemple de Decomposition("15:23:12", 2, a, b, c) retourne a=15, b=23, c=12 |
---|
1502 | ** si la chaine a un format incorrect, la fct retourne false |
---|
1503 | ***************************************************************************************/ |
---|
1504 | |
---|
1505 | bool ServerDummy::Decomposition(string chaine, char type, float *a1, float *a2, float *a3) |
---|
1506 | { |
---|
1507 | string car, s; |
---|
1508 | float a, b, c; |
---|
1509 | |
---|
1510 | // pour les heures et les coordonnées, on attend ":" comme caractÚre séparateur, sinon |
---|
1511 | // on attend d'avoir des "/" pour une date |
---|
1512 | |
---|
1513 | (type==3) ? car="/" : car=":"; |
---|
1514 | |
---|
1515 | // Y a-t-il 2 caractÚres ':' ou '/' dans la chaine ? |
---|
1516 | // C'est indispensable dans tous les cas |
---|
1517 | |
---|
1518 | int test=0; |
---|
1519 | for (int i=0; i<(int)chaine.length(); i++) if (chaine[i] == car[0]) test++; |
---|
1520 | if (test<2) return false; |
---|
1521 | |
---|
1522 | // Extraction des trois nombres |
---|
1523 | |
---|
1524 | s = chaine.substr(0, chaine.find(car)); |
---|
1525 | |
---|
1526 | a = atoi(s.c_str()); |
---|
1527 | |
---|
1528 | s = chaine.substr(chaine.find(car)+1, chaine.rfind(car) - chaine.find(car) - 1); |
---|
1529 | |
---|
1530 | b = atoi(s.c_str()); |
---|
1531 | |
---|
1532 | s = chaine.substr(chaine.rfind(car)+1); |
---|
1533 | |
---|
1534 | c = Arrondi(atof(s.c_str())*100.0)/100.0; |
---|
1535 | |
---|
1536 | //vérification de la cohérence des infos contenues dans la chaine |
---|
1537 | |
---|
1538 | if (type < 3 ) |
---|
1539 | { |
---|
1540 | // pour une déclinaison |
---|
1541 | if ((type==0) && (a>90.0 || a<-90.0)) return false; |
---|
1542 | // pour une AD |
---|
1543 | if ((type==1) && (a>360.0 || a<0.0 )) return false; |
---|
1544 | // pour une heure |
---|
1545 | if ((type==2) && (a>23.0 || a<0.0 )) return false; |
---|
1546 | // pour les minutes |
---|
1547 | if (b<0.0 || b>59.0 ) return false; |
---|
1548 | //pour les secondes |
---|
1549 | if (c<0.0 || c>=60.0) return false; |
---|
1550 | } |
---|
1551 | else |
---|
1552 | { |
---|
1553 | //pour les jours |
---|
1554 | if (a<0.0 || a>31.0) return false; |
---|
1555 | //pour les mois |
---|
1556 | if (b<0.0 || b>12.0) return false; |
---|
1557 | } |
---|
1558 | |
---|
1559 | if (a1!=NULL) *a1 = a; |
---|
1560 | if (a2!=NULL) *a2 = b; |
---|
1561 | if (a3!=NULL) *a3 = c; |
---|
1562 | |
---|
1563 | return true; |
---|
1564 | } |
---|
1565 | |
---|
1566 | |
---|
1567 | |
---|
1568 | |
---|
1569 | |
---|
1570 | |
---|
1571 | /************************************************************************************** |
---|
1572 | ** Lecteur d'un fichier ligne aprÚs ligne |
---|
1573 | ** retourne -1 Ã la fin |
---|
1574 | ***************************************************************************************/ |
---|
1575 | |
---|
1576 | int ServerDummy::readline (FILE * pfile, char *tab) |
---|
1577 | { |
---|
1578 | int nbchar = 0; |
---|
1579 | char c; |
---|
1580 | |
---|
1581 | while ((c = getc (pfile)) != '\n') |
---|
1582 | { |
---|
1583 | if (c == EOF) |
---|
1584 | { |
---|
1585 | break; |
---|
1586 | } |
---|
1587 | tab[nbchar++] = c; |
---|
1588 | } |
---|
1589 | tab[nbchar] = '\0'; |
---|
1590 | |
---|
1591 | while (nbchar>0 && tab[nbchar-1]==' ') |
---|
1592 | { |
---|
1593 | tab[--nbchar] = '\0'; |
---|
1594 | } |
---|
1595 | |
---|
1596 | while (tab[0]==' ') for (int i=1; i<=nbchar; i++) tab[i-1] = tab[i]; |
---|
1597 | |
---|
1598 | if (c == EOF) nbchar=-1; |
---|
1599 | |
---|
1600 | return (nbchar); |
---|
1601 | } |
---|
1602 | |
---|
1603 | |
---|
1604 | |
---|
1605 | /************************************************************************************** |
---|
1606 | ** chargement des paramÚtres contenus dans le fichier params |
---|
1607 | ***************************************************************************************/ |
---|
1608 | |
---|
1609 | bool ServerDummy::ChargementParametres(string fileName) |
---|
1610 | { |
---|
1611 | string section; |
---|
1612 | string key; |
---|
1613 | char * value; |
---|
1614 | stringstream os; |
---|
1615 | |
---|
1616 | |
---|
1617 | // Si le fichier n'existe pas -> on sort |
---|
1618 | |
---|
1619 | if (!is_readable(fileName)) return false; |
---|
1620 | |
---|
1621 | |
---|
1622 | AfficherLog("Lecture du fichier de configuration 'params' :\n\n", true); |
---|
1623 | |
---|
1624 | |
---|
1625 | ///////////////////////////////////////// |
---|
1626 | // Rubrique Coordonnées géographiques |
---|
1627 | |
---|
1628 | section = "coordonnees geographiques"; |
---|
1629 | |
---|
1630 | key = "latitude"; |
---|
1631 | |
---|
1632 | if ((readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1633 | && (Decomposition(value, 0, NULL, NULL, NULL))) |
---|
1634 | { |
---|
1635 | LatitudeChar = (string)value; |
---|
1636 | SAFEDELETE_TAB(value); |
---|
1637 | AfficherLog("latitude = " + LatitudeChar +"\n", true); |
---|
1638 | } |
---|
1639 | else |
---|
1640 | { |
---|
1641 | ErreurLog("La latitude est incorrecte !\n"); |
---|
1642 | |
---|
1643 | return false; |
---|
1644 | } |
---|
1645 | |
---|
1646 | |
---|
1647 | key = "longitude"; |
---|
1648 | |
---|
1649 | if ((readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1650 | && (Decomposition(value, 1, NULL, NULL, NULL))) |
---|
1651 | { |
---|
1652 | LongitudeChar = (string)value; |
---|
1653 | SAFEDELETE_TAB(value); |
---|
1654 | AfficherLog("longitude = " + LongitudeChar +"\n\n", true); |
---|
1655 | } |
---|
1656 | else |
---|
1657 | { |
---|
1658 | ErreurLog("La longitude est incorrecte !\n"); |
---|
1659 | |
---|
1660 | return false; |
---|
1661 | } |
---|
1662 | |
---|
1663 | |
---|
1664 | ///////////////////////////////////////// |
---|
1665 | // rubrique connexion |
---|
1666 | |
---|
1667 | section = "connexion indi"; |
---|
1668 | |
---|
1669 | key = "serveur"; |
---|
1670 | |
---|
1671 | if (readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1672 | { |
---|
1673 | Serveur = (string)value; |
---|
1674 | SAFEDELETE_TAB(value); |
---|
1675 | AfficherLog("serveur = " + Serveur +"\n", true); |
---|
1676 | } |
---|
1677 | else |
---|
1678 | { |
---|
1679 | ErreurLog("Nom du serveur invalide !\n"); |
---|
1680 | |
---|
1681 | return false; |
---|
1682 | } |
---|
1683 | |
---|
1684 | ///////////////////////////////////////// |
---|
1685 | // Port de connexion du serveur Indi |
---|
1686 | |
---|
1687 | key = "port"; |
---|
1688 | |
---|
1689 | if (readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1690 | { |
---|
1691 | Port = (string)value; |
---|
1692 | SAFEDELETE_TAB(value); |
---|
1693 | AfficherLog("port = " + Port +"\n\n", true); |
---|
1694 | } |
---|
1695 | else |
---|
1696 | { |
---|
1697 | ErreurLog("Numéro de port incorrect !\n"); |
---|
1698 | |
---|
1699 | return false; |
---|
1700 | } |
---|
1701 | |
---|
1702 | |
---|
1703 | ///////////////////////////////////////// |
---|
1704 | // Rubrique paramÚtres de l'atmosphÚre |
---|
1705 | |
---|
1706 | section = "atmosphere"; |
---|
1707 | |
---|
1708 | key = "pression"; |
---|
1709 | |
---|
1710 | if (readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1711 | { |
---|
1712 | Pression = atof(value); |
---|
1713 | SAFEDELETE_TAB(value); |
---|
1714 | os << "pression = " << Pression << endl; |
---|
1715 | AfficherLog(&os, true); |
---|
1716 | } |
---|
1717 | else |
---|
1718 | { |
---|
1719 | os << "La pression atmosphérique est incorrecte !" << endl; |
---|
1720 | ErreurLog(&os); |
---|
1721 | |
---|
1722 | return false; |
---|
1723 | } |
---|
1724 | |
---|
1725 | key = "temperature"; |
---|
1726 | |
---|
1727 | if (readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1728 | { |
---|
1729 | Temperature = atof(value); |
---|
1730 | SAFEDELETE_TAB(value); |
---|
1731 | os << "température = " << Temperature << endl << endl; |
---|
1732 | AfficherLog(&os, true); |
---|
1733 | } |
---|
1734 | else |
---|
1735 | { |
---|
1736 | ErreurLog("La température est incorrecte !\n"); |
---|
1737 | |
---|
1738 | return false; |
---|
1739 | } |
---|
1740 | |
---|
1741 | ///////////////////////////////////////// |
---|
1742 | // Rubrique alignement |
---|
1743 | |
---|
1744 | section = "alignement"; |
---|
1745 | |
---|
1746 | key = "methode_alignement"; |
---|
1747 | |
---|
1748 | if (readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1749 | { |
---|
1750 | AfficherLog("methode d'alignement = " + (string)value + "\n", true); |
---|
1751 | switch (value[0]) |
---|
1752 | { |
---|
1753 | case 's' : |
---|
1754 | case 'S' : |
---|
1755 | MethodeAlignement = SIMPLE; |
---|
1756 | break; |
---|
1757 | |
---|
1758 | case 'a' : |
---|
1759 | case 'A' : |
---|
1760 | MethodeAlignement = AFFINE; |
---|
1761 | break; |
---|
1762 | |
---|
1763 | case 't' : |
---|
1764 | case 'T' : |
---|
1765 | MethodeAlignement = TAKI; |
---|
1766 | break; |
---|
1767 | } |
---|
1768 | |
---|
1769 | SAFEDELETE_TAB(value); |
---|
1770 | } |
---|
1771 | else |
---|
1772 | { |
---|
1773 | ErreurLog("Le paramÚtre methode_alignement est incorrect !\n"); |
---|
1774 | |
---|
1775 | return false; |
---|
1776 | } |
---|
1777 | |
---|
1778 | |
---|
1779 | |
---|
1780 | ///////////////////////////////////////// |
---|
1781 | // Rubrique suivi |
---|
1782 | |
---|
1783 | section = "suivi"; |
---|
1784 | |
---|
1785 | key = "mode"; |
---|
1786 | |
---|
1787 | if (readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1788 | { |
---|
1789 | Transit = (strstr(value, "transit") != NULL); |
---|
1790 | AfficherLog("mode suivi = " + (string)value + "\n", true); |
---|
1791 | SAFEDELETE_TAB(value); |
---|
1792 | } |
---|
1793 | else |
---|
1794 | { |
---|
1795 | ErreurLog("Le paramÚtre mode suivi est incorrect !\n"); |
---|
1796 | |
---|
1797 | return false; |
---|
1798 | } |
---|
1799 | |
---|
1800 | |
---|
1801 | |
---|
1802 | key = "delai_transit"; |
---|
1803 | |
---|
1804 | if (readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1805 | { |
---|
1806 | delaitransit = atoi(value); |
---|
1807 | SAFEDELETE_TAB(value); |
---|
1808 | os << "delai transit = " << delaitransit << " sec" << endl; |
---|
1809 | AfficherLog(&os, true); |
---|
1810 | } |
---|
1811 | else |
---|
1812 | { |
---|
1813 | ErreurLog("Le paramÚtre delai_transit est incorrect !\n"); |
---|
1814 | |
---|
1815 | return false; |
---|
1816 | } |
---|
1817 | |
---|
1818 | |
---|
1819 | key = "delai_tracking"; |
---|
1820 | |
---|
1821 | if (readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1822 | { |
---|
1823 | delaitracking = atoi(value); |
---|
1824 | SAFEDELETE_TAB(value); |
---|
1825 | os << "delai tracking = " << delaitracking << " sec" << endl << endl; |
---|
1826 | AfficherLog(&os, true); |
---|
1827 | } |
---|
1828 | else |
---|
1829 | { |
---|
1830 | ErreurLog("Le paramÚtre delai_tracking est incorrect !\n"); |
---|
1831 | |
---|
1832 | return false; |
---|
1833 | } |
---|
1834 | |
---|
1835 | |
---|
1836 | ///////////////////////////////////////// |
---|
1837 | // Rubrique divers |
---|
1838 | |
---|
1839 | section = "divers"; |
---|
1840 | |
---|
1841 | key = "couleurs"; |
---|
1842 | |
---|
1843 | if (readINI(section.c_str(), key.c_str(), &value, fileName.c_str())) |
---|
1844 | { |
---|
1845 | ChoixCouleurs=atoi(value); |
---|
1846 | SAFEDELETE_TAB(value); |
---|
1847 | } |
---|
1848 | else |
---|
1849 | { |
---|
1850 | /*os << "Le paramÚtre couleurs est incorrect !" << endl; |
---|
1851 | ErreurLog(os.str()); |
---|
1852 | return false;*/ |
---|
1853 | } |
---|
1854 | |
---|
1855 | return true; |
---|
1856 | } |
---|
1857 | |
---|
1858 | |
---|
1859 | |
---|
1860 | /************************************************************************************** |
---|
1861 | ** Le fichier file existe-t-il et n'est-il pas vide ? |
---|
1862 | ** |
---|
1863 | **************************************************************************************/ |
---|
1864 | |
---|
1865 | bool ServerDummy::is_readable( const string & file ) |
---|
1866 | { |
---|
1867 | ifstream fichier( file.c_str() ); |
---|
1868 | if (fichier.fail()) return false; |
---|
1869 | |
---|
1870 | // sauvegarder la position courante |
---|
1871 | |
---|
1872 | // long pos = fichier.tellg(); |
---|
1873 | |
---|
1874 | // se placer en fin de fichier |
---|
1875 | |
---|
1876 | fichier.seekg( 0 , ios_base::end ); |
---|
1877 | |
---|
1878 | // récupérer la nouvelle position = la taille du fichier |
---|
1879 | |
---|
1880 | long size = fichier.tellg(); |
---|
1881 | |
---|
1882 | return (size > 0); |
---|
1883 | } |
---|
1884 | |
---|
1885 | |
---|