Changeset 493 for BAORadio/libindi
- Timestamp:
- Jun 22, 2010, 4:43:27 PM (14 years ago)
- Location:
- BAORadio/libindi/libindi
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
BAORadio/libindi/libindi/BAOTest/BAOtest_main.cpp
r492 r493 149 149 { 150 150 151 client_socket >> asks;151 client_socket.recv(asks); 152 152 153 153 int pos=asks.find("\n"); -
BAORadio/libindi/libindi/BAOTest/ClientSocket.cpp
r490 r493 3 3 #include "ClientSocket.h" 4 4 #include "SocketException.h" 5 6 7 #include <iostream> 8 #include <string> 9 #include <string.h> 10 #include <stdio.h> 11 #include <stdlib.h> 5 12 6 13 … … 16 23 throw SocketException ( "Could not bind to port." ); 17 24 } 18 19 25 } 20 26 … … 24 30 if ( ! Socket::send ( s ) ) 25 31 { 26 throw SocketException ( "Could not write to socket." );32 // throw SocketException ( "Could not write to socket." ); 27 33 } 28 34 … … 36 42 if ( ! Socket::recv ( s ) ) 37 43 { 38 throw SocketException ( "Could not read from socket." );44 // throw SocketException ( "Could not read from socket." ); 39 45 } 40 46 41 47 return *this; 42 48 } 49 50 51 void ClientSocket::recv( std::string& s ) 52 { 53 if ( ! Socket::recv ( s ) ) 54 { 55 sleep(1); 56 57 if (! Socket::shutdown() ) std::cout << "shutdown impossible.\n"; 58 59 if (! Socket::create() ) std::cout << "create impossible.\n"; 60 61 if (! Socket::connect((std::string)"192.168.0.1", 8000)) { std::cout << "connect impossible.\n"; Socket::shutdown(); } else { std::cout << "Reconnexion reussie.\n"; } 62 } 63 } 64 -
BAORadio/libindi/libindi/BAOTest/ClientSocket.h
r490 r493 22 22 const ClientSocket& operator >> ( std::string& ) const; 23 23 24 25 24 void recv( std::string& s ); 26 25 }; 27 26 -
BAORadio/libindi/libindi/BAOTest/Socket.cpp
r492 r493 12 12 13 13 14 15 14 16 Socket::Socket() : 15 17 m_sock ( -1 ) … … 19 21 0, 20 22 sizeof ( m_addr ) ); 23 21 24 } 22 25 … … 48 51 49 52 53 bool Socket::shutdown() 54 { 55 int ret = 0; 56 57 if ( is_valid() ) 58 ret = ::shutdown ( m_sock, 2 ); 59 60 m_sock=-1; 61 62 if ( ret == 0 ) return true; 63 64 return false; 65 } 66 50 67 51 68 bool Socket::bind ( const int port ) … … 107 124 fd_set r; 108 125 struct timeval timeout; 126 127 if ( ! is_valid() ) return false; 109 128 110 129 s=""; … … 167 186 if ( ! is_valid() ) return false; 168 187 188 memset ( &m_addr, 189 0, 190 sizeof ( m_addr ) ); 191 169 192 m_addr.sin_family = AF_INET; 170 193 m_addr.sin_port = htons ( port ); … … 173 196 174 197 if ( errno == EAFNOSUPPORT ) return false; 198 175 199 176 200 status = ::connect ( m_sock, ( sockaddr * ) &m_addr, sizeof ( m_addr ) ); -
BAORadio/libindi/libindi/BAOTest/Socket.h
r492 r493 19 19 const int MAXRECV = 5000; 20 20 21 22 21 23 class Socket 22 24 { … … 24 26 Socket(); 25 27 virtual ~Socket(); 28 26 29 27 30 // Server initialization … … 43 46 bool is_valid() const { return m_sock != -1; } 44 47 48 bool shutdown(); 49 45 50 private: 46 51 … … 49 54 50 55 56 57 51 58 }; 52 59 -
BAORadio/libindi/libindi/drivers/telescope/BAO.cpp
r492 r493 1 #if 02 3 #############################4 ##5 ## BAORadio Indi driver6 ## Franck RICHARD7 ## Mai 20108 ##9 #############################10 #endif11 12 #include <stdio.h>13 #include <stdlib.h>14 #include <string.h>15 #include <stdarg.h>16 #include <math.h>17 #include <unistd.h>18 #include <time.h>19 #include <memory>20 #include <pthread.h>21 #include <iostream>22 #include <time.h>23 #include <unistd.h>24 #include <sys/time.h>25 26 #include <config.h>27 28 #include "indicom.h"29 30 #include "Socket.h"31 32 #include "BAO.h"33 34 using namespace std;35 36 auto_ptr<BAO> telescope(0);37 38 const int POLLMS = 1; // Period of update, 1 ms.39 40 const char *mydev = "BAO"; // Name of our device.41 42 const char *BASIC_GROUP = "Main Control"; // Main Group43 const char *OPTIONS_GROUP = "Options"; // Options Group44 45 /* Handy Macros */46 //#define currentRA EquatorialCoordsRN[0].value47 //#define currentDEC EquatorialCoordsRN[1].value48 #define targetRA EquatorialCoordsWN[0].value49 #define targetDEC EquatorialCoordsWN[1].value50 51 52 static void ISPoll(void *);53 54 static void retry_connection(void *);55 56 /**************************************************************************************57 **58 ***************************************************************************************/59 void *pThreadSocket (void * arg)60 {1 #if 0 2 3 ############################# 4 ## 5 ## BAORadio Indi driver 6 ## Franck RICHARD 7 ## Mai 2010 8 ## 9 ############################# 10 #endif 11 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 #include <stdarg.h> 16 #include <math.h> 17 #include <unistd.h> 18 #include <time.h> 19 #include <memory> 20 #include <pthread.h> 21 #include <iostream> 22 #include <time.h> 23 #include <unistd.h> 24 #include <sys/time.h> 25 26 #include <config.h> 27 28 #include "indicom.h" 29 30 #include "Socket.h" 31 32 #include "BAO.h" 33 34 using namespace std; 35 36 auto_ptr<BAO> telescope(0); 37 38 const int POLLMS = 1; // Period of update, 1 ms. 39 40 const char *mydev = "BAO"; // Name of our device. 41 42 const char *BASIC_GROUP = "Main Control"; // Main Group 43 const char *OPTIONS_GROUP = "Options"; // Options Group 44 45 /* Handy Macros */ 46 //#define currentRA EquatorialCoordsRN[0].value 47 //#define currentDEC EquatorialCoordsRN[1].value 48 #define targetRA EquatorialCoordsWN[0].value 49 #define targetDEC EquatorialCoordsWN[1].value 50 51 52 static void ISPoll(void *); 53 54 static void retry_connection(void *); 55 56 /************************************************************************************** 57 ** 58 ***************************************************************************************/ 59 void *pThreadSocket (void * arg) 60 { 61 61 try 62 62 { 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 63 int pos = SocketsNumber; 64 65 // Trouver éventuellement un emplacement disponible dans l'intervalle [1..SocketsNumber] 66 67 /* 68 for (int i=1; i<SocketsNumber; i++) 69 { 70 if (!Sockets[i].Connected) 71 { 72 pos = i; 73 break; 74 } 75 }*/ 76 77 server.accept ( Sockets[pos].new_sock ); 78 79 Sockets[pos].IP=server.recupip(Sockets[pos].new_sock); 80 81 Sockets[pos].Connected=true; 82 83 if (pos == SocketsNumber ) SocketsNumber++; 84 85 InitThreadOK=true; 86 86 } 87 87 catch ( SocketException& e ) 88 88 { 89 90 91 92 93 94 95 96 97 98 99 100 } 101 89 //A activer pour vérif 90 91 /*std::string oss; 92 oss="pThreadSocket exception : " + e.description() + "\n"; 93 size_t size = oss.size() + 1; 94 char* buffer = new char[size]; 95 strncpy(buffer, oss.c_str(), size); 96 97 IDLog(buffer); 98 99 delete [] buffer;*/ 100 } 101 102 102 return NULL; 103 }104 105 106 /**************************************************************************************107 ** Utilisation d'un thread pour éviter de bloquer l'execution du pilote108 ** avec la commande accept109 ***************************************************************************************/110 111 void BAO::InitThread()112 {103 } 104 105 106 /************************************************************************************** 107 ** Utilisation d'un thread pour éviter de bloquer l'execution du pilote 108 ** avec la commande accept 109 ***************************************************************************************/ 110 111 void BAO::InitThread() 112 { 113 113 if (pthread_create (&th1, NULL, pThreadSocket, NULL) < 0) 114 114 { 115 116 } 117 115 IDLog("pthread_create error for threadSocket\n"); 116 } 117 118 118 pthread_join (th1, NULL); 119 }120 121 /**************************************************************************************122 ** Initialisation du pilote BAO123 ***************************************************************************************/124 void ISInit()125 {119 } 120 121 /************************************************************************************** 122 ** Initialisation du pilote BAO 123 ***************************************************************************************/ 124 void ISInit() 125 { 126 126 static int isInit=0; 127 127 128 128 if (isInit) return; 129 129 130 130 if (telescope.get() == 0) telescope.reset(new BAO()); 131 131 132 132 isInit = 1; 133 133 134 134 IEAddTimer (POLLMS, ISPoll, NULL); 135 }136 137 /**************************************************************************************138 **139 ***************************************************************************************/140 void ISGetProperties (const char *dev)141 {135 } 136 137 /************************************************************************************** 138 ** 139 ***************************************************************************************/ 140 void ISGetProperties (const char *dev) 141 { 142 142 ISInit(); 143 143 telescope->ISGetProperties(dev); 144 }145 146 /**************************************************************************************147 **148 ***************************************************************************************/149 void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)150 {144 } 145 146 /************************************************************************************** 147 ** 148 ***************************************************************************************/ 149 void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n) 150 { 151 151 ISInit(); 152 152 telescope->ISNewSwitch(dev, name, states, names, n); 153 }154 155 /**************************************************************************************156 **157 ***************************************************************************************/158 void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)159 {153 } 154 155 /************************************************************************************** 156 ** 157 ***************************************************************************************/ 158 void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n) 159 { 160 160 ISInit(); 161 161 telescope->ISNewText(dev, name, texts, names, n); 162 }163 164 /**************************************************************************************165 **166 ***************************************************************************************/167 void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)168 {162 } 163 164 /************************************************************************************** 165 ** 166 ***************************************************************************************/ 167 void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n) 168 { 169 169 ISInit(); 170 170 telescope->ISNewNumber(dev, name, values, names, n); 171 }172 173 /**************************************************************************************174 **175 ***************************************************************************************/176 void ISPoll (void *p)177 {171 } 172 173 /************************************************************************************** 174 ** 175 ***************************************************************************************/ 176 void ISPoll (void *p) 177 { 178 178 INDI_UNUSED(p); 179 179 180 180 telescope->ISPoll(); 181 181 IEAddTimer (POLLMS, ISPoll, NULL); 182 }183 184 185 /**************************************************************************************186 **187 ***************************************************************************************/188 void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)189 {182 } 183 184 185 /************************************************************************************** 186 ** 187 ***************************************************************************************/ 188 void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) 189 { 190 190 INDI_UNUSED(dev); 191 191 INDI_UNUSED(name); … … 196 196 INDI_UNUSED(names); 197 197 INDI_UNUSED(n); 198 }199 200 /**************************************************************************************201 **202 ***************************************************************************************/203 void ISSnoopDevice (XMLEle *root)204 {198 } 199 200 /************************************************************************************** 201 ** 202 ***************************************************************************************/ 203 void ISSnoopDevice (XMLEle *root) 204 { 205 205 INDI_UNUSED(root); 206 }207 208 /**************************************************************************************209 ** Initialisation de la classe BAO210 ***************************************************************************************/211 BAO::BAO()212 {206 } 207 208 /************************************************************************************** 209 ** Initialisation de la classe BAO 210 ***************************************************************************************/ 211 BAO::BAO() 212 { 213 213 init_properties(); 214 214 215 215 ConnectSP.s = IPS_IDLE; 216 216 217 217 lastSet = -1; 218 218 fd = -1; … … 222 222 currentSet = 0; 223 223 JJAnc = 0.0; 224 224 225 225 SocketsNumber = 1; 226 226 227 227 InitThreadOK=false; 228 228 LecturePosition=false; … … 230 230 Park=false; 231 231 Goto=false; 232 232 233 233 TrackingMode=1; 234 234 235 235 for (int i=0; i<MAXHOSTNAME; i++) 236 236 { 237 238 239 } 240 237 Sockets[i].Connected=false; 238 Sockets[i].IP=""; 239 } 240 241 241 InitAntennes(); 242 243 242 243 244 244 IDLog("Initilizing from BAO device...\n"); 245 245 IDLog("Driver Version: 2010-05-12\n"); 246 246 247 247 //enableSimulation(true); 248 }249 250 /**************************************************************************************251 **252 ***************************************************************************************/253 BAO::~BAO()254 {255 256 }257 258 /**************************************************************************************259 ** Initialisation des boutons et des zones d'affichage dans la boîte de dialogue INDI260 ***************************************************************************************/261 void BAO::init_properties()262 {248 } 249 250 /************************************************************************************** 251 ** 252 ***************************************************************************************/ 253 BAO::~BAO() 254 { 255 256 } 257 258 /************************************************************************************** 259 ** Initialisation des boutons et des zones d'affichage dans la boîte de dialogue INDI 260 ***************************************************************************************/ 261 void BAO::init_properties() 262 { 263 263 // Connection 264 264 IUFillSwitch(&ConnectS[0], "CONNECT", "Connect", ISS_OFF); 265 265 IUFillSwitch(&ConnectS[1], "DISCONNECT", "Disconnect", ISS_ON); 266 266 IUFillSwitchVector(&ConnectSP, ConnectS, NARRAY(ConnectS), mydev, "CONNECTION", "Connection", BASIC_GROUP, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); 267 267 268 268 // Coord Set 269 269 IUFillSwitch(&OnCoordSetS[0], "TRANSIT", "Transit", ISS_ON); 270 270 IUFillSwitch(&OnCoordSetS[1], "TRACKING", "Tracking", ISS_OFF); 271 271 IUFillSwitchVector(&OnCoordSetSP, OnCoordSetS, NARRAY(OnCoordSetS), mydev, "ON_COORD_SET", "On Set", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); 272 272 273 273 // Abort 274 274 IUFillSwitch(&AbortSlewS[0], "ABORT", "Abort", ISS_OFF); 275 275 IUFillSwitchVector(&AbortSlewSP, AbortSlewS, NARRAY(AbortSlewS), mydev, "ABORT_MOTION", "Abort", BASIC_GROUP, IP_RW, ISR_ATMOST1, 0, IPS_IDLE); 276 276 277 277 // Park 278 278 IUFillSwitch(&ParkS[0], "PARK", "Park", ISS_OFF); 279 279 IUFillSwitchVector(&ParkSP, ParkS, NARRAY(ParkS), mydev, "", "Park", BASIC_GROUP, IP_RW, ISR_ATMOST1, 0, IPS_IDLE); 280 280 281 281 // Object Name 282 282 IUFillText(&ObjectT[0], "OBJECT_NAME", "Name", "--"); 283 283 IUFillTextVector(&ObjectTP, ObjectT, NARRAY(ObjectT), mydev, "OBJECT_INFO", "Object", BASIC_GROUP, IP_RW, 0, IPS_IDLE); 284 285 284 285 286 286 // Equatorial Coords - SET 287 287 IUFillNumber(&EquatorialCoordsWN[0], "RA", "RA H:M:S", "%10.6m", 0., 24., 0., 0.); 288 288 IUFillNumber(&EquatorialCoordsWN[1], "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0.); 289 289 IUFillNumberVector(&EquatorialCoordsWNP, EquatorialCoordsWN, NARRAY(EquatorialCoordsWN), mydev, "EQUATORIAL_EOD_COORD_REQUEST" , "Equatorial JNow", BASIC_GROUP, IP_WO, 0, IPS_IDLE); 290 290 291 291 // Equatorial Coords - READ 292 292 // IUFillNumber(&EquatorialCoordsRN[0], "RA", "RA H:M:S", "%10.6m", 0., 24., 0., 0.); 293 293 // IUFillNumber(&EquatorialCoordsRN[1], "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0.); 294 294 // IUFillNumberVector(&EquatorialCoordsRNP, EquatorialCoordsRN, NARRAY(EquatorialCoordsRN), mydev, "EQUATORIAL_EOD_COORD" , "Equatorial JNow", BASIC_GROUP, IP_RO, 0, IPS_IDLE); 295 295 296 296 // Geographic coord - SET 297 297 IUFillNumber(&GeographicCoordsWN[0], "LAT", "Lat D", "%10.6m", -90., 90., 0., 0.); 298 298 IUFillNumber(&GeographicCoordsWN[1], "LONG", "Long D", "%10.6m", 0., 360., 0., 0.); 299 299 IUFillNumberVector(&GeographicCoordsWNP, GeographicCoordsWN, NARRAY(GeographicCoordsWN), mydev, "GEOGRAPHIC_COORD" , "Geographic coords", OPTIONS_GROUP, IP_WO, 0, IPS_IDLE); 300 301 300 301 302 302 // Transit threshold 303 303 IUFillNumber(&SlewAccuracyN[0], "TransitRA", "RA (arcmin)", "%10.6m", 0., 60., 1., 3.0); 304 304 IUFillNumber(&SlewAccuracyN[1], "TransitDEC", "Dec (arcmin)", "%10.6m", 0., 60., 1., 3.0); 305 305 IUFillNumberVector(&SlewAccuracyNP, SlewAccuracyN, NARRAY(SlewAccuracyN), mydev, "Transit Accuracy", "", OPTIONS_GROUP, IP_RW, 0, IPS_IDLE); 306 306 307 307 // Tracking threshold 308 308 IUFillNumber(&TrackAccuracyN[0], "TrackingRA", "RA (arcmin)", "%10.6m", 0., 60., 1., 3.0); 309 309 IUFillNumber(&TrackAccuracyN[1], "TrackingDEC", "Dec (arcmin)", "%10.6m", 0., 60., 1., 3.0); 310 310 IUFillNumberVector(&TrackAccuracyNP, TrackAccuracyN, NARRAY(TrackAccuracyN), mydev, "Tracking Accuracy", "", OPTIONS_GROUP, IP_RW, 0, IPS_IDLE); 311 312 }313 314 /**************************************************************************************315 ** Initialisation de la boîte de dialogue INDI (suite)316 ***************************************************************************************/317 void BAO::ISGetProperties(const char *dev)318 {319 311 312 } 313 314 /************************************************************************************** 315 ** Initialisation de la boîte de dialogue INDI (suite) 316 ***************************************************************************************/ 317 void BAO::ISGetProperties(const char *dev) 318 { 319 320 320 if (dev && strcmp (mydev, dev)) 321 322 321 return; 322 323 323 // Main Control 324 324 IDDefSwitch(&ConnectSP, NULL); … … 330 330 IDDefSwitch(&AbortSlewSP, NULL); 331 331 IDDefSwitch(&ParkSP, NULL); 332 332 333 333 // Options 334 334 IDDefNumber(&SlewAccuracyNP, NULL); 335 335 IDDefNumber(&TrackAccuracyNP, NULL); 336 337 }338 339 /**************************************************************************************340 ** En cas de changement de texte dans la boîte de dialogue341 ***************************************************************************************/342 void BAO::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)343 {336 337 } 338 339 /************************************************************************************** 340 ** En cas de changement de texte dans la boîte de dialogue 341 ***************************************************************************************/ 342 void BAO::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n) 343 { 344 344 // Ignore if not ours 345 345 if (strcmp (dev, mydev)) 346 347 346 return; 347 348 348 if (is_connected() == false) 349 349 { 350 351 352 353 } 354 350 IDMessage(mydev, "BAORadio. Please connect before issuing any commands."); 351 reset_all_properties(); 352 return; 353 } 354 355 355 // =================================== 356 356 // Object Name … … 358 358 if (!strcmp (name, ObjectTP.name)) 359 359 { 360 361 362 363 364 365 366 } 367 }368 369 /**************************************************************************************370 ** En cas de changement d'une valeur numérique dans la boîte de dialogue Indi371 ***************************************************************************************/372 void BAO::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)373 {374 360 if (IUUpdateText(&ObjectTP, texts, names, n) < 0) 361 return; 362 363 ObjectTP.s = IPS_OK; 364 IDSetText(&ObjectTP, NULL); 365 return; 366 } 367 } 368 369 /************************************************************************************** 370 ** En cas de changement d'une valeur numérique dans la boîte de dialogue Indi 371 ***************************************************************************************/ 372 void BAO::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n) 373 { 374 375 375 // Ignore if not ours 376 376 if (strcmp (dev, mydev)) 377 378 377 return; 378 379 379 if (is_connected() == false) 380 380 { 381 382 383 384 } 385 386 381 IDMessage(mydev, "BAO is offline. Please connect before issuing any commands."); 382 reset_all_properties(); 383 return; 384 } 385 386 387 387 // =================================== 388 388 // Geographic Coords … … 390 390 if (!strcmp (name, GeographicCoordsWNP.name)) 391 391 { 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 } 435 436 392 int i=0, nset=0, error_code=0; 393 394 Latitude=0.0; 395 Longitude=0.0; 396 397 for (nset = i = 0; i < n; i++) 398 { 399 INumber *eqp = IUFindNumber (&GeographicCoordsWNP, names[i]); 400 if (eqp == &GeographicCoordsWN[0]) 401 { 402 Latitude = values[i]; 403 nset += Latitude >= -90.0 && Latitude <= 90.0; 404 405 Latitude*=Pidiv180; 406 } 407 else if (eqp == &GeographicCoordsWN[1]) 408 { 409 Longitude = values[i]; 410 nset += Longitude >= 0.0 && Longitude <= 360.0; 411 412 Longitude*=-Pidiv180; 413 } 414 } 415 416 if (nset == 2) 417 { 418 //Vérification 419 //IDLog("Geographic : RA %5.2f - DEC %5.2f\n", Latitude, Longitude); 420 421 GeographicCoordsWNP.s = IPS_OK; 422 IDSetNumber(&GeographicCoordsWNP, NULL); 423 } 424 else 425 { 426 GeographicCoordsWNP.s = IPS_ALERT; 427 IDSetNumber(&GeographicCoordsWNP, "Latitude or Longitude missing or invalid"); 428 429 Latitude=0.0; 430 Longitude=0.0; 431 } 432 433 return; 434 } 435 436 437 437 // =================================== 438 438 // Equatorial Coords … … 440 440 if (!strcmp (name, EquatorialCoordsWNP.name)) 441 441 { 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 442 int i=0, nset=0, error_code=0; 443 double newRA =0, newDEC =0; 444 445 for (nset = i = 0; i < n; i++) 446 { 447 INumber *eqp = IUFindNumber (&EquatorialCoordsWNP, names[i]); 448 if (eqp == &EquatorialCoordsWN[0]) 449 { 450 newRA = values[i]; 451 nset += newRA >= 0 && newRA <= 24.0; 452 } 453 else if (eqp == &EquatorialCoordsWN[1]) 454 { 455 newDEC = values[i]; 456 nset += newDEC >= -90.0 && newDEC <= 90.0; 457 } 458 } 459 460 targetRA = newRA; 461 targetDEC = newDEC; 462 463 if (nset == 2) 464 { 465 char RAStr[32], DecStr[32]; 466 double targetAZ, targetAlt; 467 468 fs_sexa(RAStr, newRA, 2, 3600); 469 fs_sexa(DecStr, newDEC, 2, 3600); 470 471 IDLog("We received JNow RA %s - DEC %s\n", RAStr, DecStr); 472 473 // on convertit les coordonnées équatoriales de la zone du ciel observée 474 // en unités de codeurs des moteurs 475 476 ADDEC2Motor(newRA, newDEC); 477 478 if (process_coords() == false) 479 { 480 EquatorialCoordsWNP.s = IPS_ALERT; 481 IDSetNumber(&EquatorialCoordsWNP, NULL); 482 } 483 } 484 else 485 { 486 EquatorialCoordsWNP.s = IPS_ALERT; 487 IDSetNumber(&EquatorialCoordsWNP, "RA or Dec missing or invalid"); 488 } 489 490 return; 491 491 } /* end EquatorialCoordsWNP */ 492 }493 494 /**************************************************************************************495 ** L'utilisateur clique sur l'un des boutons de la boîte Indi496 ***************************************************************************************/497 void BAO::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)498 {492 } 493 494 /************************************************************************************** 495 ** L'utilisateur clique sur l'un des boutons de la boîte Indi 496 ***************************************************************************************/ 497 void BAO::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n) 498 { 499 499 // ignore if not ours // 500 500 if (strcmp (mydev, dev)) 501 502 501 return; 502 503 503 // =================================== 504 504 // Connect Switch … … 506 506 if (!strcmp (name, ConnectSP.name)) 507 507 { 508 509 510 511 512 513 } 514 508 if (IUUpdateSwitch(&ConnectSP, states, names, n) < 0) 509 return; 510 511 connect_telescope(); 512 return; 513 } 514 515 515 if (is_connected() == false) 516 516 { 517 518 519 520 } 521 517 IDMessage(mydev, "BAORadio is offline. Please connect before issuing any commands."); 518 reset_all_properties(); 519 return; 520 } 521 522 522 // =================================== 523 523 // Coordinate Set … … 525 525 if (!strcmp(name, OnCoordSetSP.name)) 526 526 { 527 528 529 530 531 532 533 } 534 527 if (IUUpdateSwitch(&OnCoordSetSP, states, names, n) < 0) 528 return; 529 530 currentSet = get_switch_index(&OnCoordSetSP); 531 OnCoordSetSP.s = IPS_OK; 532 IDSetSwitch(&OnCoordSetSP, NULL); 533 } 534 535 535 // =================================== 536 536 // Abort slew … … 538 538 if (!strcmp (name, AbortSlewSP.name)) 539 539 { 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 } 560 561 540 Abort=true; 541 542 IUResetSwitch(&AbortSlewSP); 543 544 /* 545 if (EquatorialCoordsWNP.s == IPS_BUSY) 546 { 547 548 AbortSlewSP.s = IPS_OK; 549 EquatorialCoordsWNP.s = IPS_IDLE; 550 EquatorialCoordsRNP.s = IPS_IDLE; 551 HorizontalCoordsWNP.s = IPS_IDLE; 552 IDSetSwitch(&AbortSlewSP, "Slew aborted."); 553 IDSetNumber(&EquatorialCoordsWNP, NULL); 554 IDSetNumber(&EquatorialCoordsRNP, NULL); 555 IDSetNumber(&HorizontalCoordsWNP, NULL); 556 } 557 */ 558 return; 559 } 560 561 562 562 // =================================== 563 563 // Park … … 565 565 if (!strcmp (name, ParkSP.name)) 566 566 { 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 } 587 }588 589 /**************************************************************************************590 ** fct peut-être inutile591 ***************************************************************************************/592 void BAO::handle_error(INumberVectorProperty *nvp, int err, const char *msg)593 {567 Park=true; 568 569 IUResetSwitch(&ParkSP); 570 571 /* 572 if (EquatorialCoordsWNP.s == IPS_BUSY) 573 { 574 575 AbortSlewSP.s = IPS_OK; 576 EquatorialCoordsWNP.s = IPS_IDLE; 577 EquatorialCoordsRNP.s = IPS_IDLE; 578 HorizontalCoordsWNP.s = IPS_IDLE; 579 IDSetSwitch(&AbortSlewSP, "Slew aborted."); 580 IDSetNumber(&EquatorialCoordsWNP, NULL); 581 IDSetNumber(&EquatorialCoordsRNP, NULL); 582 IDSetNumber(&HorizontalCoordsWNP, NULL); 583 } 584 */ 585 return; 586 } 587 } 588 589 /************************************************************************************** 590 ** fct peut-être inutile 591 ***************************************************************************************/ 592 void BAO::handle_error(INumberVectorProperty *nvp, int err, const char *msg) 593 { 594 594 nvp->s = IPS_ALERT; 595 595 596 596 /* If the error is a time out, then the device doesn't support this property */ 597 597 if (err == -2) 598 598 { 599 600 599 nvp->s = IPS_ALERT; 600 IDSetNumber(nvp, "Device timed out. Current device may be busy or does not support %s. Will retry again.", msg); 601 601 } 602 602 else 603 604 605 603 /* Changing property failed, user should retry. */ 604 IDSetNumber( nvp , "%s failed.", msg); 605 606 606 fault = true; 607 }608 609 /**************************************************************************************610 ** Initialisation des vecteurs INDI611 ***************************************************************************************/612 void BAO::reset_all_properties()613 {607 } 608 609 /************************************************************************************** 610 ** Initialisation des vecteurs INDI 611 ***************************************************************************************/ 612 void BAO::reset_all_properties() 613 { 614 614 ConnectSP.s = IPS_IDLE; 615 615 OnCoordSetSP.s = IPS_IDLE; … … 622 622 SlewAccuracyNP.s = IPS_IDLE; 623 623 TrackAccuracyNP.s = IPS_IDLE; 624 624 625 625 IUResetSwitch(&OnCoordSetSP); 626 626 IUResetSwitch(&AbortSlewSP); 627 627 IUResetSwitch(&ParkSP); 628 628 629 629 OnCoordSetS[0].s = ISS_ON; 630 630 ConnectS[0].s = ISS_OFF; 631 631 ConnectS[1].s = ISS_ON; 632 632 633 633 IDSetSwitch(&ConnectSP, NULL); 634 634 IDSetSwitch(&OnCoordSetSP, NULL); … … 641 641 IDSetNumber(&SlewAccuracyNP, NULL); 642 642 IDSetNumber(&TrackAccuracyNP, NULL); 643 }644 645 /**************************************************************************************646 **647 ***************************************************************************************/648 void BAO::correct_fault()649 {643 } 644 645 /************************************************************************************** 646 ** 647 ***************************************************************************************/ 648 void BAO::correct_fault() 649 { 650 650 fault = false; 651 651 IDMessage(mydev, "Telescope is online."); 652 }653 654 /**************************************************************************************655 **656 ***************************************************************************************/657 bool BAO::is_connected()658 {652 } 653 654 /************************************************************************************** 655 ** 656 ***************************************************************************************/ 657 bool BAO::is_connected() 658 { 659 659 if (simulation) return true; 660 660 661 661 // return (ConnectSP.sp[0].s == ISS_ON); 662 662 return (ConnectSP.s == IPS_OK); 663 }664 665 /**************************************************************************************666 **667 ***************************************************************************************/668 static void retry_connection(void * p)669 {670 671 }672 673 674 /**************************************************************************************675 ** Extraction de la position de l'antenne676 ** dans le retour de la commande POS677 ** POS/Valeur az/Valeur alt678 ***************************************************************************************/679 680 Position BAO::ExtractPosition(std::string str)681 {663 } 664 665 /************************************************************************************** 666 ** 667 ***************************************************************************************/ 668 static void retry_connection(void * p) 669 { 670 671 } 672 673 674 /************************************************************************************** 675 ** Extraction de la position de l'antenne 676 ** dans le retour de la commande POS 677 ** POS/Valeur az/Valeur alt 678 ***************************************************************************************/ 679 680 Position BAO::ExtractPosition(std::string str) 681 { 682 682 Position result; 683 683 684 684 std::string str2; 685 685 686 686 result.x = -1; 687 687 result.y = -1; 688 688 689 689 int pos = str.find("/"); 690 690 691 691 if (pos != string::npos) 692 692 { 693 694 695 696 697 698 699 700 701 702 703 } 704 693 str2 = str.substr(pos+1); 694 695 pos = str2.find("/"); 696 697 if (pos != string::npos) 698 { 699 result.x = atoi(str2.substr(0, pos).c_str()); 700 701 result.y = atoi(str2.substr(pos+1).c_str()); 702 } 703 } 704 705 705 return result; 706 }707 708 709 710 /************************************************************************************711 * cette procédure convertit les coordonnées equatoriales de l'objet visé712 * en unités de codeurs des paraboles (nb de tours des deux axes moteurs depuis la position PARK)713 ************************************************************************************/714 void BAO::ADDEC2Motor(double newRA, double newDEC)715 {706 } 707 708 709 710 /************************************************************************************ 711 * cette procédure convertit les coordonnées equatoriales de l'objet visé 712 * en unités de codeurs des paraboles (nb de tours des deux axes moteurs depuis la position PARK) 713 ************************************************************************************/ 714 void BAO::ADDEC2Motor(double newRA, double newDEC) 715 { 716 716 double targetAz; 717 717 double targetAlt; 718 718 char AzStr[32]; 719 719 char AltStr[32]; 720 720 721 721 // Calcule la hauteur et l'azimut de la zone du ciel pointée (en fonction de la date et du lieu) 722 722 723 723 Azimut(tsl, Latitude, newRA * 15.0 * Pidiv180, newDEC * Pidiv180, &targetAz, &targetAlt); 724 724 725 725 // En degrés 726 726 727 727 targetAlt *= N180divPi; 728 728 targetAz *= N180divPi; 729 729 730 730 // Affichage dans les logs 731 731 732 732 fs_sexa(AzStr, targetAz, 2, 3600); 733 733 fs_sexa(AltStr, targetAlt, 2, 3600); 734 734 735 735 IDLog("Horizontal coords : az %s - Alt %s\n", AzStr, AltStr); 736 736 737 737 // Le calcul est ici trÚs sommaire et arbitraire : 738 738 // Je considÚre qu'il y a 6000 positions possibles sur les deux axes 739 739 // De plus, je considÚre qu'il n'est pas possible de viser un objet à 740 740 // moins de 30° de hauteur au-dessus de l'horizon 741 741 742 742 TargetPosition.x=(int)(targetAz*6000.0/360.0); 743 743 744 744 targetAlt=((90.0-targetAlt)/60.0); 745 745 746 746 if (targetAlt>=1.0) targetAlt=1.0; //on ne peut pas viser un objet situé à moins de 30° 747 748 749 TargetPosition.y=(int)(6000.0*targetAlt);750 }751 752 753 /************************************************************************************754 * Retourne simplement le nombre d'antennes connectées755 * et capables de communiquer756 ************************************************************************************/757 758 int BAO::AntennesConnectees()759 {747 //au-dessus de l'horizon 748 749 TargetPosition.y=(int)(6000.0*targetAlt); 750 } 751 752 753 /************************************************************************************ 754 * Retourne simplement le nombre d'antennes connectées 755 * et capables de communiquer 756 ************************************************************************************/ 757 758 int BAO::AntennesConnectees() 759 { 760 760 int num=0; 761 761 762 762 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) num++; 763 763 764 764 return num; 765 }766 767 768 /************************************************************************************769 * Initialisation des paramÚtres des antennes770 *771 ************************************************************************************/772 void BAO::InitAntennes()773 {765 } 766 767 768 /************************************************************************************ 769 * Initialisation des paramÚtres des antennes 770 * 771 ************************************************************************************/ 772 void BAO::InitAntennes() 773 { 774 774 for (int i=0; i < MAXHOSTNAME ; i++) 775 775 { 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 } 791 }792 793 794 /**************************************************************************************795 ** Procédure principale796 ** Elle est appelée toutes les POLLMS ms (ici 1 ms)797 ***************************************************************************************/798 void BAO::ISPoll()799 {776 Sockets[i].status=0; 777 Sockets[i].sendalertes=0; 778 Sockets[i].AttenteExecution=0; 779 Sockets[i].AnomaliesExecution=0; 780 Sockets[i].etape=0; 781 782 Sockets[i].ack_status=false; 783 Sockets[i].ack_pos=false; 784 Sockets[i].ack_park=false; 785 Sockets[i].ack_abort=false; 786 Sockets[i].ack_goto=false; 787 788 Sockets[i].PosValides=false; 789 Sockets[i].GotoOk=false; 790 } 791 } 792 793 794 /************************************************************************************** 795 ** Procédure principale 796 ** Elle est appelée toutes les POLLMS ms (ici 1 ms) 797 ***************************************************************************************/ 798 void BAO::ISPoll() 799 { 800 800 static bool ISPOLLRunning=false; 801 801 static int memSocketsNumber=-1; 802 static int compt=1000;802 static unsigned int compt=100; 803 803 int pos; 804 804 805 805 struct tm date; 806 806 time_t t; 807 807 struct timeval tv; 808 808 struct timezone tz; 809 809 810 810 if (is_connected() == false) return; 811 811 812 812 if (ISPOLLRunning) return; 813 813 814 814 ISPOLLRunning=true; 815 815 816 816 compt++; 817 818 817 818 819 819 //toutes les 100 millisec 820 821 if (compt>100) 822 { 823 //Récupération de la date et de l'heure 824 825 time(&t); 826 date=*gmtime(&t); 827 gettimeofday(&tv, &tz); 828 829 Annee=(double)(date.tm_year+1900); 830 Mois=(double)(date.tm_mon+1); 831 Jour=(double)date.tm_mday; 832 Heu=(double)date.tm_hour; 833 Min=(double)date.tm_min; 834 Sec=(double)date.tm_sec+tv.tv_usec/1.0E6; 835 UTCP=0.0;//(double)date.tm_isdst; 836 837 838 //Calcul du temps sidéral local 839 840 CalculTSL(); 841 842 843 //Y a-t-il de nouvelles tentatives de connexion sur le serveur ? 844 845 InitThread(); 846 847 compt=0; 848 } 849 850 851 852 820 821 if ( compt%100 == 0) 822 { 823 //Récupération de la date et de l'heure 824 825 time(&t); 826 date=*gmtime(&t); 827 gettimeofday(&tv, &tz); 828 829 Annee=(double)(date.tm_year+1900); 830 Mois=(double)(date.tm_mon+1); 831 Jour=(double)date.tm_mday; 832 Heu=(double)date.tm_hour; 833 Min=(double)date.tm_min; 834 Sec=(double)date.tm_sec+tv.tv_usec/1.0E6; 835 UTCP=0.0;//(double)date.tm_isdst; 836 837 838 //Calcul du temps sidéral local 839 840 CalculTSL(); 841 842 843 //Y a-t-il de nouvelles tentatives de connexion sur le serveur ? 844 845 InitThread(); 846 } 847 848 849 850 853 851 if (InitThreadOK) // Il faut qu'il y ait eu au moins une connexion détectée par le thread pour continuer 854 852 { 855 856 // Nouvelle connexion sur le socket ! 857 858 if (SocketsNumber>memSocketsNumber) 859 { 860 memSocketsNumber=SocketsNumber; 861 862 IDSetSwitch(&ConnectSP, "Connexion de l antenne %s. (Antennes connectées : %i)", 863 Sockets[SocketsNumber-1].IP.c_str(), AntennesConnectees()); 864 } 865 866 867 868 // Début des échanges avec les microcontrÃŽleurs 869 870 // Analyse des réponses des microcontrÃŽleurs 871 872 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 873 { 874 try 875 { 876 std::string reponse, memreponse; 877 // on récupÚre la réponse du microcontrÃŽleur 878 879 Sockets[i].new_sock >> reponse; 880 881 //IDSetSwitch(&OnCoordSetSP, "Réponse ISPOLL : %s\n", reponse.c_str()); // pour vérif 882 883 //Dans le cas où plusieurs trames seraient arrivées entre deux appels de POLLMS 884 //les traiter successivement 885 886 pos=reponse.find("\n"); // d'où l'intérêt de mettre un '\n' à la fin des trames 887 //pour différencier une trame de la précédente 888 while ((pos!=string::npos) && (reponse.length()>1)) 889 { 890 memreponse=reponse.substr(pos+1); 891 892 reponse=reponse.substr(0, pos); 893 894 895 // On traite ici les acknowledges 896 897 if (reponse.find("ACK")!=string::npos) 898 { 899 if (reponse.find("STATUS")!=string::npos) 900 { 901 Sockets[i].ack_status=true; 902 } 903 else if (reponse.find("POS")!=string::npos) 904 { 905 Sockets[i].ack_pos=true; 906 } 907 else if (reponse.find("GOTO")!=string::npos) 908 { 909 Sockets[i].ack_goto=true; 910 } 911 else if (reponse.find("PARK")!=string::npos) 912 { 913 Sockets[i].ack_park=true; 914 } 915 else if (reponse.find("ABORT")!=string::npos) 916 { 917 Sockets[i].ack_abort=true; 918 } 919 } 920 else 921 { 922 //réponse à la requête STATUS 923 if (reponse.find("STATUS")!=string::npos) 924 { 925 if (reponse.find("READY")!=string::npos) 926 { 927 Sockets[i].status='R'; 928 } 929 else if (reponse.find("BUSY")!=string::npos) 930 { 931 Sockets[i].status='B'; 932 } 933 934 }//réponse à la requête POSITION 935 else if (reponse.find("POS")!=string::npos) 936 { 937 if (reponse.find("ERR")!=string::npos) 938 { 939 OnCoordSetSP.s = IPS_ALERT; 940 IDSetSwitch(&OnCoordSetSP, "ALERTE antenne %s : position de l antenne inconnue !\n", 941 Sockets[i].IP.c_str()); 942 Sockets[i].PosValides=false; 943 // Si la position de l'antenne est inconnue, on déconnecte l'antenne 944 Sockets[i].Connected=false; 945 } 946 else 947 { 948 OnCoordSetSP.s = IPS_OK; 949 Sockets[i].Pos = ExtractPosition(reponse); 950 Sockets[i].PosValides = true; 951 IDSetSwitch(&ParkSP, "Antenne %s : POSITION OK (x=%i, y=%i)\n", 952 Sockets[i].IP.c_str(), Sockets[i].Pos.x, Sockets[i].Pos.y); 953 } 954 955 }//réponse à la requête PARK 956 else if (reponse.find("PARK")!=string::npos) 957 { 958 if (reponse.find("ERR")!=string::npos) 959 { 960 ParkSP.s = IPS_ALERT; 961 IDSetSwitch(&ParkSP, "ALERTE antenne %s : erreur PARK !\n", Sockets[i].IP.c_str()); 962 } else if (reponse.find("OK")!=string::npos) 963 { 964 ParkSP.s = IPS_OK; 965 IDSetSwitch(&ParkSP, "Antenne %s : PARK OK\n", Sockets[i].IP.c_str()); 966 } 967 968 }//réponse à la requête ABORT 969 else if (reponse.find("ABORT")!=string::npos) 970 { 971 if (reponse.find("ERR")!=string::npos) 972 { 973 AbortSlewSP.s = IPS_ALERT; 974 IDSetSwitch(&AbortSlewSP, "ALERTE antenne %s : erreur ABORT !\n", Sockets[i].IP.c_str()); 975 } 976 977 if (reponse.find("OK")!=string::npos) 978 { 979 AbortSlewSP.s = IPS_OK; 980 IDSetSwitch(&AbortSlewSP, "Antenne %s : ABORT OK\n", Sockets[i].IP.c_str()); 981 } 982 983 } //réponse à la requête GOTO 984 else if (reponse.find("GOTO")!=string::npos) 985 { 986 if (reponse.find("ERR")!=string::npos) 987 { 988 OnCoordSetSP.s = IPS_ALERT; 989 IDSetSwitch(&OnCoordSetSP, "ALERTE antenne %s : Erreur GOTO !\n", Sockets[i].IP.c_str()); 990 Sockets[i].Connected=false; 991 } 992 else 993 { 994 OnCoordSetSP.s = IPS_OK; 995 996 Sockets[i].GotoOk=true; 997 998 IDSetSwitch(&ParkSP, "Antenne %s : GOTO OK.\n", Sockets[i].IP.c_str()); 999 1000 lastRA = targetRA; 1001 lastDEC = targetDEC; 1002 1003 //IDLog("We received JNow RA %s - DEC %s\n", RAStr, DecStr);*/ 1004 1005 EquatorialCoordsWNP.s = IPS_OK; 1006 IDSetNumber (&EquatorialCoordsWNP, NULL); 1007 1008 // Fin du Goto pour toutes les antennes ? 1009 1010 int num=0; 1011 1012 for (int j=1; j<SocketsNumber; j++) if (Sockets[j].Connected) 1013 { 1014 if (Sockets[j].GotoOk) num++; 1015 } 1016 1017 if (num == AntennesConnectees()) 1018 { 1019 LecturePosition=false; 1020 1021 InitAntennes(); 1022 1023 IDSetSwitch(&OnCoordSetSP, "GOTO OK !"); 1024 } 1025 } 1026 } 1027 } 1028 1029 // On passe éventuellement à la trame suivante 1030 1031 reponse=memreponse; 1032 pos=reponse.find("\n"); 1033 1034 } 1035 } 1036 catch (SocketException& e) //Aïe 1037 { 1038 Sockets[i].Connected=false; 1039 1040 std::string oss; 1041 oss="SocketException IsPoll : " + e.description() + "\n"; 1042 size_t size = oss.size() + 1; 1043 char* buffer = new char[size]; 1044 strncpy(buffer, oss.c_str(), size); 1045 IDLog(buffer); 1046 delete [] buffer; 1047 } 1048 } 1049 1050 1051 1052 if (Abort) 1053 { 1054 IDSetSwitch(&ConnectSP, "Envoi de la commande Abort\n"); 1055 1056 Goto=false; 1057 1058 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 1059 { 1060 if (!ABORT(i)) Sockets[i].sendalertes++; 1061 } 1062 1063 LecturePosition=false; 1064 1065 InitAntennes(); 1066 1067 Abort=false; 1068 } 1069 1070 1071 if (Park) 1072 { 1073 IDSetSwitch(&ConnectSP, "Envoi de la commande Park\n"); 1074 1075 Goto=false; 1076 1077 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 1078 { 1079 if (!PARK(i)) Sockets[i].sendalertes++; 1080 } 1081 1082 LecturePosition=false; 1083 1084 InitAntennes(); 1085 1086 Park=false; 1087 } 1088 1089 1090 // Gestion du suivi 1091 1092 if (Goto) 1093 { 1094 // Durée entre deux actualisations 1095 1096 double delai=15.0/60.0/24.0; // Actualisation toutes les 15 minutes en mode transit 1097 1098 if (TrackingMode==2) delai=5.0/3600.0/24.0; //et 5 secs en mode tracking 1099 1100 1101 // On actualise la position 1102 1103 if (JJ-JJAnc > delai) 1104 { 1105 ADDEC2Motor(targetRA, targetDEC); 1106 1107 InitAntennes(); 1108 1109 LecturePosition=true; 1110 1111 JJAnc=JJ; 1112 } 1113 1114 //Plus d'antenne ! 1115 1116 if (AntennesConnectees() == 0) 1117 { 1118 LecturePosition=false; 1119 1120 Goto=false; 1121 1122 InitAntennes(); 1123 1124 IDSetSwitch(&OnCoordSetSP, "Erreur ! Plus d antennes connectées !"); 1125 } 1126 } 1127 1128 1129 1130 // Exécution de la procédure complÚte de lecture de la position de l'antenne 1131 // puis envoi d'une commande Goto 1132 1133 if (LecturePosition) 1134 { 1135 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 1136 { 1137 switch (Sockets[i].etape) 1138 { 1139 //Envoi des requêtes STATUS 1140 case 0 : 1141 { 1142 Sockets[i].AttenteExecution=0; 1143 Sockets[i].ack_status=false; 1144 Sockets[i].status=0; 1145 1146 if (!STATUS(i)) Sockets[i].sendalertes++; 1147 1148 Sockets[i].etape++; 1149 } 1150 break; 1151 1152 //vérification ack statuts 1153 case 1 : 1154 { 1155 if (Sockets[i].ack_status) 1156 { 1157 Sockets[i].AttenteExecution=0; 1158 Sockets[i].etape++; 1159 i--; 1160 } 1161 else 1162 { 1163 // on réitÚre l'ordre précédent si rien ne se passe 1164 1165 Sockets[i].AttenteExecution++; 1166 1167 if (Sockets[i].AttenteExecution>MAXATTENTE) 1168 { 1169 Sockets[i].etape=0; 1170 Sockets[i].AttenteExecution=0; 1171 Sockets[i].AnomaliesExecution++; 1172 } 1173 1174 if (Sockets[i].AnomaliesExecution>MAXANOMALIES) 1175 { 1176 IDSetSwitch(&OnCoordSetSP, "ERREUR 1000 : Erreur critique sur l antenne %s. Déconnexion de l antenne.", 1177 Sockets[i].IP.c_str()); 1178 Sockets[i].Connected=false; 1179 } 1180 } 1181 } 1182 break; 1183 1184 //status ready ? 1185 case 2 : 1186 { 1187 if (Sockets[i].status == 'R') 1188 { 1189 Sockets[i].AttenteExecution=0; 1190 Sockets[i].etape++; 1191 i--; 1192 } 1193 else 1194 { 1195 // on réitÚre l'ordre précédent si rien ne se passe 1196 1197 Sockets[i].AttenteExecution++; 1198 1199 if (Sockets[i].AttenteExecution>MAXATTENTE) 1200 { 1201 Sockets[i].etape=0; 1202 Sockets[i].AttenteExecution=0; 1203 Sockets[i].AnomaliesExecution++; 1204 } 1205 1206 if (Sockets[i].AnomaliesExecution>MAXANOMALIES) 1207 { 1208 IDSetSwitch(&OnCoordSetSP, "ERREUR 1001 : Erreur critique sur l antenne %s. Déconnexion de l antenne.", 1209 Sockets[i].IP.c_str()); 1210 Sockets[i].Connected=false; 1211 } 1212 } 1213 } 1214 break; 1215 1216 //Envoi de la commande POS 1217 case 3 : 1218 { 1219 Sockets[i].ack_pos=false; 1220 Sockets[i].PosValides=false; 1221 1222 if (!POSITION(i)) Sockets[i].sendalertes++; 1223 1224 Sockets[i].etape++; 1225 } 1226 break; 1227 1228 //ack POS 1229 case 4 : 1230 { 1231 if (Sockets[i].ack_pos) 1232 { 1233 Sockets[i].AttenteExecution=0; 1234 Sockets[i].etape++; 1235 i--; 1236 } 1237 else 1238 { 1239 // on réitÚre l'ordre précédent si rien ne se passe 1240 1241 Sockets[i].AttenteExecution++; 1242 1243 if (Sockets[i].AttenteExecution>MAXATTENTE) 1244 { 1245 Sockets[i].etape=3; 1246 Sockets[i].AttenteExecution=0; 1247 Sockets[i].AnomaliesExecution++; 1248 } 1249 1250 if (Sockets[i].AnomaliesExecution>MAXANOMALIES) 1251 { 1252 IDSetSwitch(&OnCoordSetSP, "ERREUR 1002 : Erreur critique sur l antenne %s. Déconnexion de l antenne.", 1253 Sockets[i].IP.c_str()); 1254 Sockets[i].Connected=false; 1255 } 1256 } 1257 } 1258 break; 1259 1260 //Valeurs pos valides ? 1261 case 5 : 1262 { 1263 if (Sockets[i].PosValides) 1264 { 1265 Sockets[i].AttenteExecution=0; 1266 Sockets[i].etape++; 1267 } 1268 else 1269 { 1270 // on réitÚre l'ordre précédent si rien ne se passe 1271 1272 Sockets[i].AttenteExecution++; 1273 1274 if (Sockets[i].AttenteExecution>MAXATTENTE) 1275 { 1276 Sockets[i].etape=0; 1277 Sockets[i].AttenteExecution=0; 1278 Sockets[i].AnomaliesExecution++; 1279 } 1280 1281 if (Sockets[i].AnomaliesExecution>MAXANOMALIES) 1282 { 1283 IDSetSwitch(&OnCoordSetSP, "ERREUR 1003 : Erreur critique sur l antenne %s. Déconnexion de l antenne.", 1284 Sockets[i].IP.c_str()); 1285 Sockets[i].Connected=false; 1286 } 1287 } 1288 } 1289 break; 1290 1291 } 1292 } 1293 } 1294 1295 1296 1297 1298 1299 1300 // Détection d'anomalies concernant l'envoi de trames sur la socket. déconnexion du micro-cont ? 1301 1302 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 1303 { 1304 if (Sockets[i].sendalertes > 0) 1305 { 1306 IDSetSwitch(&OnCoordSetSP, "Erreur 1004 : Anomalie détectée sur l antenne %s. Déconnexion de l antenne.", 1307 Sockets[i].IP.c_str()); 1308 1309 Sockets[i].Connected=false; 1310 } 1311 } 1312 1313 1314 1315 //On attend que toutes les antennes soient prêtes pour lancer l'ordre Goto -> meilleure synchronisation 1316 1317 int num=0; 1318 1319 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 1320 { 1321 if (Sockets[i].etape == 6) num++; //fin de la procédure LecturePosition. Les antennes sont prêtes 1322 //à recevoir l'ordre GOto 1323 } 1324 1325 if ((num == AntennesConnectees()) && (num>0)) 1326 { 1327 for (int i=1; i<SocketsNumber; i++ ) if (Sockets[i].Connected) 1328 { 1329 Sockets[i].ack_goto=false; 1330 1331 if (!GOTO(i, TargetPosition.x, TargetPosition.y)) Sockets[i].sendalertes++; 1332 1333 Sockets[i].etape++; 1334 } 1335 } 1336 1337 1338 /* 1339 switch (EquatorialCoordsWNP.s) 1340 { 1341 case IPS_IDLE: 1342 1343 break; 1344 1345 case IPS_BUSY: 1346 1347 switch (currentSet) 1348 { 1349 case LX200_TRANSIT: 1350 OnCoordSetSP.sp[LX200_TRANSIT].s = ISS_ON; 1351 IDSetSwitch (&OnCoordSetSP, "Slew is complete."); 1352 break; 1353 1354 case LX200_TRACKING: 1355 OnCoordSetSP.sp[LX200_TRACKING].s = ISS_ON; 1356 IDSetSwitch (&OnCoordSetSP, "Slew is complete. Tracking..."); 1357 break; 1358 } 1359 1360 break; 1361 1362 case IPS_OK: 1363 1364 break; 1365 1366 case IPS_ALERT: 1367 1368 break; 1369 }*/ 1370 } 1371 853 854 // Nouvelle connexion sur le socket ! 855 856 if (SocketsNumber>memSocketsNumber) 857 { 858 memSocketsNumber=SocketsNumber; 859 860 IDSetSwitch(&ConnectSP, "Connexion de l antenne %s. (Antennes connectées : %i)", 861 Sockets[SocketsNumber-1].IP.c_str(), AntennesConnectees()); 862 } 863 864 865 866 // Début des échanges avec les microcontrÃŽleurs 867 868 // Analyse des réponses des microcontrÃŽleurs 869 870 for (int i=1; i<SocketsNumber; i++) /*if (Sockets[i].Connected)*/ 871 { 872 try 873 { 874 std::string reponse, memreponse; 875 // on récupÚre la réponse du microcontrÃŽleur 876 877 Sockets[i].new_sock >> reponse; 878 879 //IDSetSwitch(&OnCoordSetSP, "Réponse ISPOLL : %s\n", reponse.c_str()); // pour vérif 880 881 //Dans le cas où plusieurs trames seraient arrivées entre deux appels de POLLMS 882 //les traiter successivement 883 884 pos=reponse.find("\n"); // d'où l'intérêt de mettre un '\n' à la fin des trames 885 //pour différencier une trame de la précédente 886 while ((pos!=string::npos) && (reponse.length()>1)) 887 { 888 memreponse=reponse.substr(pos+1); 889 890 reponse=reponse.substr(0, pos); 891 892 893 // On traite ici les acknowledges 894 895 if (reponse.find("ACK")!=string::npos) 896 { 897 if (reponse.find("STATUS")!=string::npos) 898 { 899 Sockets[i].ack_status=true; 900 } 901 else if (reponse.find("POS")!=string::npos) 902 { 903 Sockets[i].ack_pos=true; 904 } 905 else if (reponse.find("GOTO")!=string::npos) 906 { 907 Sockets[i].ack_goto=true; 908 } 909 else if (reponse.find("PARK")!=string::npos) 910 { 911 Sockets[i].ack_park=true; 912 } 913 else if (reponse.find("ABORT")!=string::npos) 914 { 915 Sockets[i].ack_abort=true; 916 } 917 } 918 else 919 { 920 //réponse à la requête STATUS 921 if (reponse.find("STATUS")!=string::npos) 922 { 923 if (reponse.find("READY")!=string::npos) 924 { 925 Sockets[i].status='R'; 926 } 927 else if (reponse.find("BUSY")!=string::npos) 928 { 929 Sockets[i].status='B'; 930 } 931 932 }//réponse à la requête POSITION 933 else if (reponse.find("POS")!=string::npos) 934 { 935 if (reponse.find("ERR")!=string::npos) 936 { 937 OnCoordSetSP.s = IPS_ALERT; 938 IDSetSwitch(&OnCoordSetSP, "ALERTE antenne %s : position de l antenne inconnue !\n", 939 Sockets[i].IP.c_str()); 940 Sockets[i].PosValides=false; 941 // Si la position de l'antenne est inconnue, on déconnecte l'antenne 942 Sockets[i].Connected=false; 943 } 944 else 945 { 946 OnCoordSetSP.s = IPS_OK; 947 Sockets[i].Pos = ExtractPosition(reponse); 948 Sockets[i].PosValides = true; 949 IDSetSwitch(&ParkSP, "Antenne %s : POSITION OK (x=%i, y=%i)\n", 950 Sockets[i].IP.c_str(), Sockets[i].Pos.x, Sockets[i].Pos.y); 951 } 952 953 }//réponse à la requête PARK 954 else if (reponse.find("PARK")!=string::npos) 955 { 956 if (reponse.find("ERR")!=string::npos) 957 { 958 ParkSP.s = IPS_ALERT; 959 IDSetSwitch(&ParkSP, "ALERTE antenne %s : erreur PARK !\n", Sockets[i].IP.c_str()); 960 } else if (reponse.find("OK")!=string::npos) 961 { 962 ParkSP.s = IPS_OK; 963 IDSetSwitch(&ParkSP, "Antenne %s : PARK OK\n", Sockets[i].IP.c_str()); 964 } 965 966 }//réponse à la requête ABORT 967 else if (reponse.find("ABORT")!=string::npos) 968 { 969 if (reponse.find("ERR")!=string::npos) 970 { 971 AbortSlewSP.s = IPS_ALERT; 972 IDSetSwitch(&AbortSlewSP, "ALERTE antenne %s : erreur ABORT !\n", Sockets[i].IP.c_str()); 973 } 974 975 if (reponse.find("OK")!=string::npos) 976 { 977 AbortSlewSP.s = IPS_OK; 978 IDSetSwitch(&AbortSlewSP, "Antenne %s : ABORT OK\n", Sockets[i].IP.c_str()); 979 } 980 981 } //réponse à la requête GOTO 982 else if (reponse.find("GOTO")!=string::npos) 983 { 984 if (reponse.find("ERR")!=string::npos) 985 { 986 OnCoordSetSP.s = IPS_ALERT; 987 IDSetSwitch(&OnCoordSetSP, "ALERTE antenne %s : Erreur GOTO !\n", Sockets[i].IP.c_str()); 988 Sockets[i].Connected=false; 989 } 990 else 991 { 992 OnCoordSetSP.s = IPS_OK; 993 994 Sockets[i].GotoOk=true; 995 996 IDSetSwitch(&ParkSP, "Antenne %s : GOTO OK.\n", Sockets[i].IP.c_str()); 997 998 lastRA = targetRA; 999 lastDEC = targetDEC; 1000 1001 //IDLog("We received JNow RA %s - DEC %s\n", RAStr, DecStr);*/ 1002 1003 EquatorialCoordsWNP.s = IPS_OK; 1004 IDSetNumber (&EquatorialCoordsWNP, NULL); 1005 1006 // Fin du Goto pour toutes les antennes ? 1007 1008 int num=0; 1009 1010 for (int j=1; j<SocketsNumber; j++) if (Sockets[j].Connected) 1011 { 1012 if (Sockets[j].GotoOk) num++; 1013 } 1014 1015 if ((num == AntennesConnectees()) && (num>0)) 1016 { 1017 LecturePosition=false; 1018 1019 InitAntennes(); 1020 1021 IDSetSwitch(&OnCoordSetSP, "GOTO OK !"); 1022 } 1023 } 1024 } 1025 } 1026 1027 // On passe éventuellement à la trame suivante 1028 1029 reponse=memreponse; 1030 pos=reponse.find("\n"); 1031 1032 } 1033 } 1034 catch (SocketException& e) //Aïe 1035 { 1036 Sockets[i].new_sock.shutdown(); 1037 Sockets[i].new_sock.create(); 1038 Sockets[i].Connected = Sockets[i].new_sock.connect((std::string)Sockets[i].IP); 1039 1040 if (Sockets[i].Connected) 1041 { 1042 Sockets[i].AttenteExecution=0; 1043 Sockets[i].AnomaliesExecution=0; 1044 } 1045 1046 std::string oss; 1047 oss="SocketException IsPoll : " + e.description() + "\n"; 1048 size_t size = oss.size() + 1; 1049 char* buffer = new char[size]; 1050 strncpy(buffer, oss.c_str(), size); 1051 IDLog(buffer); 1052 delete [] buffer; 1053 } 1054 } 1055 1056 1057 1058 if (Abort) 1059 { 1060 IDSetSwitch(&ConnectSP, "Envoi de la commande Abort\n"); 1061 1062 Goto=false; 1063 1064 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 1065 { 1066 if (!ABORT(i)) Sockets[i].sendalertes++; 1067 } 1068 1069 LecturePosition=false; 1070 1071 InitAntennes(); 1072 1073 Abort=false; 1074 } 1075 1076 1077 if (Park) 1078 { 1079 IDSetSwitch(&ConnectSP, "Envoi de la commande Park\n"); 1080 1081 Goto=false; 1082 1083 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 1084 { 1085 if (!PARK(i)) Sockets[i].sendalertes++; 1086 } 1087 1088 LecturePosition=false; 1089 1090 InitAntennes(); 1091 1092 Park=false; 1093 } 1094 1095 1096 // Gestion du suivi 1097 1098 if (Goto) 1099 { 1100 // Durée entre deux actualisations 1101 1102 double delai=15.0/60.0/24.0; // Actualisation toutes les 15 minutes en mode transit 1103 1104 if (TrackingMode==2) delai=5.0/3600.0/24.0; //et 5 secs en mode tracking 1105 1106 1107 // On actualise la position 1108 1109 if (JJ-JJAnc > delai) 1110 { 1111 ADDEC2Motor(targetRA, targetDEC); 1112 1113 InitAntennes(); 1114 1115 LecturePosition=true; 1116 1117 JJAnc=JJ; 1118 } 1119 1120 //Plus d'antenne ! 1121 1122 if (AntennesConnectees() == 0) 1123 { 1124 // LecturePosition=false; 1125 1126 // Goto=false; 1127 1128 // InitAntennes(); 1129 1130 if ( compt % 1000 == 0) IDSetSwitch(&OnCoordSetSP, "Erreur ! Plus d antennes connectées !"); 1131 } 1132 } 1133 1134 1135 1136 // Exécution de la procédure complÚte de lecture de la position de l'antenne 1137 // puis envoi d'une commande Goto 1138 1139 if (LecturePosition) 1140 { 1141 for (int i=1; i<SocketsNumber; i++) /*if (Sockets[i].Connected)*/ 1142 { 1143 switch (Sockets[i].etape) 1144 { 1145 //Envoi des requêtes STATUS 1146 case 0 : 1147 { 1148 Sockets[i].AttenteExecution=0; 1149 Sockets[i].ack_status=false; 1150 Sockets[i].status=0; 1151 1152 if (!STATUS(i)) Sockets[i].sendalertes++; 1153 1154 Sockets[i].etape++; 1155 } 1156 break; 1157 1158 //vérification ack statuts 1159 case 1 : 1160 { 1161 if (Sockets[i].ack_status) 1162 { 1163 Sockets[i].AttenteExecution=0; 1164 Sockets[i].etape++; 1165 i--; 1166 } 1167 else 1168 { 1169 // on réitÚre l'ordre précédent si rien ne se passe 1170 1171 Sockets[i].AttenteExecution++; 1172 1173 if (Sockets[i].AttenteExecution>MAXATTENTE) 1174 { 1175 Sockets[i].etape=0; 1176 Sockets[i].AttenteExecution=0; 1177 Sockets[i].AnomaliesExecution++; 1178 } 1179 1180 if (Sockets[i].AnomaliesExecution>MAXANOMALIES) 1181 { 1182 Sockets[i].etape=6; 1183 1184 if ( compt % 1000 == 0) 1185 { 1186 IDSetSwitch(&OnCoordSetSP, "ERREUR 1000 : Erreur critique sur l antenne %s. Déconnexion de l antenne.", 1187 Sockets[i].IP.c_str()); 1188 1189 // Sockets[i].Connected=false; 1190 } 1191 } 1192 } 1193 } 1194 break; 1195 1196 //status ready ? 1197 case 2 : 1198 { 1199 if (Sockets[i].status == 'R') 1200 { 1201 Sockets[i].AttenteExecution=0; 1202 Sockets[i].etape++; 1203 i--; 1204 } 1205 else 1206 { 1207 // on réitÚre l'ordre précédent si rien ne se passe 1208 1209 Sockets[i].AttenteExecution++; 1210 1211 if (Sockets[i].AttenteExecution>MAXATTENTE) 1212 { 1213 Sockets[i].etape=0; 1214 Sockets[i].AttenteExecution=0; 1215 Sockets[i].AnomaliesExecution++; 1216 } 1217 1218 if (Sockets[i].AnomaliesExecution>MAXANOMALIES) 1219 { 1220 Sockets[i].etape=6; 1221 1222 if ( compt % 1000 == 0) 1223 { 1224 IDSetSwitch(&OnCoordSetSP, "ERREUR 1001 : Erreur critique sur l antenne %s. Déconnexion de l antenne.", 1225 Sockets[i].IP.c_str()); 1226 // Sockets[i].Connected=false; 1227 } 1228 } 1229 } 1230 } 1231 break; 1232 1233 //Envoi de la commande POS 1234 case 3 : 1235 { 1236 Sockets[i].ack_pos=false; 1237 Sockets[i].PosValides=false; 1238 1239 if (!POSITION(i)) Sockets[i].sendalertes++; 1240 1241 Sockets[i].etape++; 1242 } 1243 break; 1244 1245 //ack POS 1246 case 4 : 1247 { 1248 if (Sockets[i].ack_pos) 1249 { 1250 Sockets[i].AttenteExecution=0; 1251 Sockets[i].etape++; 1252 i--; 1253 } 1254 else 1255 { 1256 // on réitÚre l'ordre précédent si rien ne se passe 1257 1258 Sockets[i].AttenteExecution++; 1259 1260 if (Sockets[i].AttenteExecution>MAXATTENTE) 1261 { 1262 Sockets[i].etape=3; 1263 Sockets[i].AttenteExecution=0; 1264 Sockets[i].AnomaliesExecution++; 1265 } 1266 1267 if (Sockets[i].AnomaliesExecution>MAXANOMALIES) 1268 { 1269 Sockets[i].etape=6; 1270 1271 if ( compt % 1000 == 0) 1272 { 1273 IDSetSwitch(&OnCoordSetSP, "ERREUR 1002 : Erreur critique sur l antenne %s. Déconnexion de l antenne.", 1274 Sockets[i].IP.c_str()); 1275 // Sockets[i].Connected=false; 1276 } 1277 } 1278 } 1279 } 1280 break; 1281 1282 //Valeurs pos valides ? 1283 case 5 : 1284 { 1285 if (Sockets[i].PosValides) 1286 { 1287 Sockets[i].AttenteExecution=0; 1288 Sockets[i].etape++; 1289 } 1290 else 1291 { 1292 // on réitÚre l'ordre précédent si rien ne se passe 1293 1294 Sockets[i].AttenteExecution++; 1295 1296 if (Sockets[i].AttenteExecution>MAXATTENTE) 1297 { 1298 Sockets[i].etape=0; 1299 Sockets[i].AttenteExecution=0; 1300 Sockets[i].AnomaliesExecution++; 1301 } 1302 1303 if (Sockets[i].AnomaliesExecution>MAXANOMALIES) 1304 { 1305 Sockets[i].etape=6; 1306 1307 if ( compt % 1000 == 0) 1308 { 1309 IDSetSwitch(&OnCoordSetSP, "ERREUR 1003 : Erreur critique sur l antenne %s. Déconnexion de l antenne.", 1310 Sockets[i].IP.c_str()); 1311 // Sockets[i].Connected=false; 1312 } 1313 } 1314 } 1315 } 1316 break; 1317 1318 } 1319 } 1320 } 1321 1322 1323 1324 1325 1326 1327 // Détection d'anomalies concernant l'envoi de trames sur la socket. déconnexion du micro-cont ? 1328 1329 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 1330 { 1331 if (Sockets[i].sendalertes > 0) 1332 { 1333 Sockets[i].etape=6; 1334 1335 if ( compt % 1000 == 0) 1336 { 1337 IDSetSwitch(&OnCoordSetSP, "Erreur 1004 : Anomalie détectée sur l antenne %s. Déconnexion de l antenne.", 1338 Sockets[i].IP.c_str()); 1339 1340 // Sockets[i].Connected=false; 1341 } 1342 } 1343 } 1344 1345 1346 1347 //On attend que toutes les antennes soient prêtes pour lancer l'ordre Goto -> meilleure synchronisation 1348 1349 int num=0; 1350 1351 for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) 1352 { 1353 if (Sockets[i].etape == 6) num++; //fin de la procédure LecturePosition. Les antennes sont prêtes 1354 //à recevoir l'ordre GOto 1355 } 1356 1357 if ((num == AntennesConnectees()) && (num>0)) 1358 { 1359 for (int i=1; i<SocketsNumber; i++ ) if (Sockets[i].Connected) 1360 { 1361 Sockets[i].ack_goto=false; 1362 1363 if (!GOTO(i, TargetPosition.x, TargetPosition.y)) Sockets[i].sendalertes++; 1364 1365 Sockets[i].etape++; 1366 } 1367 } 1368 1369 1370 /* 1371 switch (EquatorialCoordsWNP.s) 1372 { 1373 case IPS_IDLE: 1374 1375 break; 1376 1377 case IPS_BUSY: 1378 1379 switch (currentSet) 1380 { 1381 case LX200_TRANSIT: 1382 OnCoordSetSP.sp[LX200_TRANSIT].s = ISS_ON; 1383 IDSetSwitch (&OnCoordSetSP, "Slew is complete."); 1384 break; 1385 1386 case LX200_TRACKING: 1387 OnCoordSetSP.sp[LX200_TRACKING].s = ISS_ON; 1388 IDSetSwitch (&OnCoordSetSP, "Slew is complete. Tracking..."); 1389 break; 1390 } 1391 1392 break; 1393 1394 case IPS_OK: 1395 1396 break; 1397 1398 case IPS_ALERT: 1399 1400 break; 1401 }*/ 1402 } 1403 1372 1404 ISPOLLRunning=false; 1373 }1374 1375 1376 1377 /**************************************************************************************1378 **1379 ***************************************************************************************/1380 bool BAO::process_coords()1381 {1405 } 1406 1407 1408 1409 /************************************************************************************** 1410 ** 1411 ***************************************************************************************/ 1412 bool BAO::process_coords() 1413 { 1382 1414 switch (currentSet) 1383 1415 { 1384 1385 case BAO_TRANSIT:1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 case BAO_TRACKING:1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 } 1422 1416 // Transit 1417 case BAO_TRANSIT: 1418 1419 EquatorialCoordsWNP.s = IPS_BUSY; 1420 1421 IDSetNumber (&EquatorialCoordsWNP, NULL); 1422 1423 InitAntennes(); 1424 1425 JJAnc=JJ; 1426 1427 TrackingMode = 1; 1428 1429 Goto=true; 1430 1431 LecturePosition=true; 1432 1433 break; 1434 1435 // Tracking 1436 case BAO_TRACKING: 1437 1438 EquatorialCoordsWNP.s = IPS_BUSY; 1439 1440 IDSetNumber (&EquatorialCoordsWNP, NULL); 1441 1442 InitAntennes(); 1443 1444 JJAnc=JJ; 1445 1446 TrackingMode = 2; 1447 1448 Goto=true; 1449 1450 LecturePosition=true; 1451 1452 break; 1453 } 1454 1423 1455 return true; 1424 }1425 1426 /**************************************************************************************1427 **1428 ***************************************************************************************/1429 int BAO::get_switch_index(ISwitchVectorProperty *sp)1430 {1456 } 1457 1458 /************************************************************************************** 1459 ** 1460 ***************************************************************************************/ 1461 int BAO::get_switch_index(ISwitchVectorProperty *sp) 1462 { 1431 1463 for (int i=0; i < sp->nsp ; i++) 1432 1433 1434 1435 return -1;1436 }1437 1438 /**************************************************************************************1439 ** Activation de l'interface1440 ***************************************************************************************/1441 void BAO::connect_telescope()1442 {1464 if (sp->sp[i].s == ISS_ON) 1465 return i; 1466 1467 return -1; 1468 } 1469 1470 /************************************************************************************** 1471 ** Activation de l'interface 1472 ***************************************************************************************/ 1473 void BAO::connect_telescope() 1474 { 1443 1475 switch (ConnectSP.sp[0].s) 1444 1476 { 1445 case ISS_ON:1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 case ISS_OFF:1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 server.close(Sockets[i].new_sock);1468 1469 1470 1471 1472 1473 1474 1475 1476 } 1477 }1478 1479 /**************************************************************************************1480 **1481 ***************************************************************************************/1482 void BAO::get_initial_data()1483 {1477 case ISS_ON: 1478 ConnectS[0].s = ISS_ON; 1479 ConnectS[1].s = ISS_OFF; 1480 IDLog("\nHello BAORadio !\n"); 1481 1482 ConnectSP.s = IPS_OK; 1483 IDSetSwitch (&ConnectSP, "BAORadio is online. Retrieving basic data..."); 1484 1485 break; 1486 1487 case ISS_OFF: 1488 ConnectS[0].s = ISS_OFF; 1489 ConnectS[1].s = ISS_ON; 1490 ConnectSP.s = IPS_IDLE; 1491 1492 SocketsNumber=1; 1493 InitThreadOK=false; 1494 1495 for (int i=0; i<MAXHOSTNAME; i++) 1496 { 1497 Sockets[i].Connected=false; 1498 Sockets[i].IP=""; 1499 Sockets[i].new_sock.shutdown(); 1500 } 1501 1502 InitAntennes(); 1503 1504 IDSetSwitch (&ConnectSP, "BAORadio is offline."); 1505 IDLog("Telescope is offline."); 1506 1507 break; 1508 } 1509 } 1510 1511 /************************************************************************************** 1512 ** 1513 ***************************************************************************************/ 1514 void BAO::get_initial_data() 1515 { 1484 1516 // IDSetNumber (&EquatorialCoordsRNP, NULL); 1485 }1486 1487 /**************************************************************************************1488 **1489 ***************************************************************************************/1490 void BAO::slew_error(int slewCode)1491 {1517 } 1518 1519 /************************************************************************************** 1520 ** 1521 ***************************************************************************************/ 1522 void BAO::slew_error(int slewCode) 1523 { 1492 1524 OnCoordSetSP.s = IPS_IDLE; 1493 1525 1494 1526 if (slewCode == 1) 1495 1527 IDSetSwitch (&OnCoordSetSP, "Object below horizon."); 1496 1528 else if (slewCode == 2) 1497 1529 IDSetSwitch (&OnCoordSetSP, "Object below the minimum elevation limit."); 1498 1530 else 1499 1500 }1501 1502 /**************************************************************************************1503 **1504 ***************************************************************************************/1505 void BAO::enable_simulation(bool enable)1506 {1531 IDSetSwitch (&OnCoordSetSP, "Slew failed."); 1532 } 1533 1534 /************************************************************************************** 1535 ** 1536 ***************************************************************************************/ 1537 void BAO::enable_simulation(bool enable) 1538 { 1507 1539 simulation = enable; 1508 1540 1509 1541 if (simulation) 1510 1542 IDLog("Warning: Simulation is activated.\n"); 1511 1543 else 1512 1513 }1514 1515 /**************************************************************************************1516 **1517 ***************************************************************************************/1518 void BAO::connection_lost()1519 {1544 IDLog("Simulation is disabled.\n"); 1545 } 1546 1547 /************************************************************************************** 1548 ** 1549 ***************************************************************************************/ 1550 void BAO::connection_lost() 1551 { 1520 1552 ConnectSP.s = IPS_IDLE; 1521 1553 IDSetSwitch(&ConnectSP, "The connection to the telescope is lost."); 1522 1554 return; 1523 }1524 1525 /**************************************************************************************1526 **1527 ***************************************************************************************/1528 void BAO::connection_resumed()1529 {1555 } 1556 1557 /************************************************************************************** 1558 ** 1559 ***************************************************************************************/ 1560 void BAO::connection_resumed() 1561 { 1530 1562 ConnectS[0].s = ISS_ON; 1531 1563 ConnectS[1].s = ISS_OFF; 1532 1564 ConnectSP.s = IPS_OK; 1533 1565 1534 1566 IDSetSwitch(&ConnectSP, "The connection to the telescope has been resumed."); 1535 }1536 1537 1538 /**************************************************************************************1539 ** Envoi d'une commande sur le socket puis attente de l'acknowledge1540 ***************************************************************************************/1541 1542 bool BAO::COMMANDE(int numsocket, char* Commande, char* Params)1543 {1567 } 1568 1569 1570 /************************************************************************************** 1571 ** Envoi d'une commande sur le socket puis attente de l'acknowledge 1572 ***************************************************************************************/ 1573 1574 bool BAO::COMMANDE(int numsocket, char* Commande, char* Params) 1575 { 1544 1576 char chaine[MAXCARACTERES]; 1545 1577 1546 1578 try 1547 1579 { 1548 1549 1550 1580 sprintf(chaine, "%s%s\n", Commande, Params); 1581 1582 Sockets[numsocket].new_sock << chaine; 1551 1583 } 1552 1584 catch (SocketException& e) 1553 { 1554 // Sockets[numsocket].Connected=false; 1555 //server.close(Sockets[numsocket].new_sock); 1556 //if (AntennesConnectees() == 0) { InitAntennes(); InitThreadOK=false;} 1557 1558 std::string oss; 1559 oss="COMMANDE exception : " + e.description() + "\n"; 1560 size_t size = oss.size() + 1; 1561 char* buffer = new char[size]; 1562 strncpy(buffer, oss.c_str(), size); 1563 1564 IDLog(buffer); 1565 1566 delete [] buffer; 1567 1568 return false; 1569 } 1570 1585 { 1586 Sockets[numsocket].new_sock.shutdown(); 1587 Sockets[numsocket].new_sock.create(); 1588 Sockets[numsocket].Connected = Sockets[numsocket].new_sock.connect((std::string)Sockets[numsocket].IP); 1589 1590 if (Sockets[numsocket].Connected) 1591 { 1592 Sockets[numsocket].AttenteExecution=0; 1593 Sockets[numsocket].AnomaliesExecution=0; 1594 } 1595 1596 // if (AntennesConnectees() == 0) { InitAntennes(); InitThreadOK=false;} 1597 1598 std::string oss; 1599 oss="COMMANDE exception : " + e.description() + "\n"; 1600 size_t size = oss.size() + 1; 1601 char* buffer = new char[size]; 1602 strncpy(buffer, oss.c_str(), size); 1603 1604 IDLog(buffer); 1605 1606 delete [] buffer; 1607 1608 return false; 1609 } 1610 1571 1611 return true; 1572 }1573 1574 /**************************************************************************************1575 ** Commande STATUS1576 ***************************************************************************************/1577 bool BAO::STATUS(int numsocket)1578 {1612 } 1613 1614 /************************************************************************************** 1615 ** Commande STATUS 1616 ***************************************************************************************/ 1617 bool BAO::STATUS(int numsocket) 1618 { 1579 1619 return COMMANDE(numsocket, (char*)"STATUS", (char*)""); 1580 }1581 1582 /**************************************************************************************1583 ** Commande POSITION1584 ***************************************************************************************/1585 1586 bool BAO::POSITION(int numsocket)1587 {1620 } 1621 1622 /************************************************************************************** 1623 ** Commande POSITION 1624 ***************************************************************************************/ 1625 1626 bool BAO::POSITION(int numsocket) 1627 { 1588 1628 return COMMANDE(numsocket, (char*)"POS", (char*)""); 1589 }1590 1591 /**************************************************************************************1592 ** Commande PARK1593 ***************************************************************************************/1594 1595 bool BAO::PARK(int numsocket)1596 {1629 } 1630 1631 /************************************************************************************** 1632 ** Commande PARK 1633 ***************************************************************************************/ 1634 1635 bool BAO::PARK(int numsocket) 1636 { 1597 1637 return COMMANDE(numsocket, (char*)"PARK", (char*)""); 1598 }1599 1600 /**************************************************************************************1601 ** Commande ABORT1602 ***************************************************************************************/1603 1604 bool BAO::ABORT(int numsocket)1605 {1638 } 1639 1640 /************************************************************************************** 1641 ** Commande ABORT 1642 ***************************************************************************************/ 1643 1644 bool BAO::ABORT(int numsocket) 1645 { 1606 1646 return COMMANDE(numsocket, (char*)"ABORT", (char*)""); 1607 }1608 1609 1610 /**************************************************************************************1611 ** Commande GOTO1612 ***************************************************************************************/1613 1614 bool BAO::GOTO(int numsocket, int deltaAz, int deltaAlt)1615 {1647 } 1648 1649 1650 /************************************************************************************** 1651 ** Commande GOTO 1652 ***************************************************************************************/ 1653 1654 bool BAO::GOTO(int numsocket, int deltaAz, int deltaAlt) 1655 { 1616 1656 char Params[MAXCARACTERES]; 1617 1657 1618 1658 int sensAlt=0; 1619 1659 int sensAz=0; 1620 1660 1621 1661 if (deltaAz<0) 1622 1662 { 1623 1624 1625 } 1626 1663 deltaAz=-deltaAz; 1664 sensAz=1; 1665 } 1666 1627 1667 if (deltaAlt<0) 1628 1668 { 1629 1630 1631 } 1632 1669 deltaAlt=-deltaAlt; 1670 sensAlt=1; 1671 } 1672 1633 1673 sprintf(Params, "/%i/# %i Az/%i/# %i Alt", sensAz, deltaAz, sensAlt, deltaAlt); 1634 1674 1635 1675 return COMMANDE(numsocket, (char*)"GOTO", Params); 1636 } 1637 1638 1676 } 1677 1678 1679 -
BAORadio/libindi/libindi/drivers/telescope/ServerSocket.cpp
r490 r493 68 68 } 69 69 70 71 void ServerSocket::close ( ServerSocket& sock ) 70 void ServerSocket::shutdown ( ) 72 71 { 73 if ( ! Socket:: close ( sock) )72 if ( ! Socket::shutdown ( ) ) 74 73 { 75 throw SocketException ( "Could not acceptsocket." );74 throw SocketException ( "Could not shutdown socket." ); 76 75 } 77 76 } 78 77 79 80 void ServerSocket::shutdown ( ServerSocket& sock ) 78 void ServerSocket::create ( ) 81 79 { 82 if ( ! Socket:: shutdown ( sock) )80 if ( ! Socket::create ( ) ) 83 81 { 84 throw SocketException ( "Could not acceptsocket." );82 throw SocketException ( "Could not create socket." ); 85 83 } 86 84 } 87 85 86 bool ServerSocket::connect(std::string IP ) 87 { 88 return Socket::connect (IP, 8000); 89 } 88 90 89 91 std::string ServerSocket::recupip( ServerSocket& sock) -
BAORadio/libindi/libindi/drivers/telescope/ServerSocket.h
r490 r493 19 19 const ServerSocket& operator << ( const std::string& ) const; 20 20 const ServerSocket& operator >> ( std::string& ) const; 21 22 void accept ( ServerSocket& ); 21 23 22 void accept ( ServerSocket& ); 23 void close ( ServerSocket& ); 24 void shutdown ( ServerSocket& ); 24 void shutdown ( ); 25 26 void create(); 27 28 bool connect(std::string IP ); 25 29 26 30 std::string recupip( ServerSocket& ); -
BAORadio/libindi/libindi/drivers/telescope/Socket.cpp
r492 r493 95 95 96 96 97 bool Socket::shutdown() 98 { 99 int ret = 0; 100 101 if ( is_valid() ) 102 ret = ::shutdown ( m_sock, 2 ); 103 104 m_sock=-1; 105 106 if ( ret == 0 ) return true; 107 108 return false; 109 } 110 111 97 112 bool Socket::send ( const std::string s ) const 98 113 { 114 if ( ! is_valid() ) return false; 115 99 116 int status = ::send ( m_sock, s.c_str(), s.size(), MSG_NOSIGNAL); 100 117 … … 105 122 106 123 107 bool Socket::close( Socket& new_socket ) const108 {109 int status = ::close ( m_sock );110 111 if ( status == -1 ) return false;112 113 return true;114 }115 116 bool Socket::shutdown( Socket& new_socket ) const117 {118 int status = ::shutdown ( m_sock, SHUT_RDWR );119 120 if ( status == -1 ) return false;121 122 return true;123 }124 125 124 int Socket::recv ( std::string& s ) const 126 125 { … … 128 127 fd_set r; 129 128 struct timeval timeout; 129 130 if ( ! is_valid() ) return false; 130 131 131 132 s=""; … … 187 188 { 188 189 if ( ! is_valid() ) return false; 190 191 memset ( &m_addr, 192 0, 193 sizeof ( m_addr ) ); 194 189 195 190 196 m_addr.sin_family = AF_INET; -
BAORadio/libindi/libindi/drivers/telescope/Socket.h
r490 r493 44 44 bool is_valid() const { return m_sock != -1; } 45 45 46 bool close( Socket& ) const; 47 48 bool shutdown( Socket& ) const; 46 bool shutdown(); 49 47 50 48 private:
Note: See TracChangeset
for help on using the changeset viewer.