Changeset 493 for BAORadio


Ignore:
Timestamp:
Jun 22, 2010, 4:43:27 PM (14 years ago)
Author:
frichard
Message:

Le programme gère mieux les connexion/déconnexion des microcontrôleurs.

Location:
BAORadio/libindi/libindi
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • BAORadio/libindi/libindi/BAOTest/BAOtest_main.cpp

    r492 r493  
    149149        {
    150150           
    151                 client_socket >> asks;
     151                client_socket.recv(asks);
    152152
    153153                int pos=asks.find("\n");
  • BAORadio/libindi/libindi/BAOTest/ClientSocket.cpp

    r490 r493  
    33#include "ClientSocket.h"
    44#include "SocketException.h"
     5
     6
     7#include <iostream>
     8#include <string>
     9#include <string.h>
     10#include <stdio.h>
     11#include <stdlib.h>
    512
    613
     
    1623      throw SocketException ( "Could not bind to port." );
    1724    }
    18 
    1925}
    2026
     
    2430  if ( ! Socket::send ( s ) )
    2531    {
    26       throw SocketException ( "Could not write to socket." );
     32     // throw SocketException ( "Could not write to socket." );
    2733    }
    2834
     
    3642  if ( ! Socket::recv ( s ) )
    3743    {
    38       throw SocketException ( "Could not read from socket." );
     44    //   throw SocketException ( "Could not read from socket." );
    3945    }
    4046
    4147  return *this;
    4248}
     49
     50
     51void 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  
    2222  const ClientSocket& operator >> ( std::string& ) const;
    2323
    24 
    25 
     24void recv( std::string& s );
    2625};
    2726
  • BAORadio/libindi/libindi/BAOTest/Socket.cpp

    r492 r493  
    1212
    1313
     14
     15
    1416Socket::Socket() :
    1517        m_sock ( -1 )
     
    1921             0,
    2022             sizeof ( m_addr ) );
     23
    2124}
    2225
     
    4851
    4952
     53bool 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
    5067
    5168bool Socket::bind ( const int port )
     
    107124    fd_set r;
    108125    struct timeval timeout;
     126
     127    if ( ! is_valid() ) return false;
    109128   
    110129    s="";
     
    167186    if ( ! is_valid() ) return false;
    168187
     188    memset ( &m_addr,
     189             0,
     190             sizeof ( m_addr ) );
     191
    169192    m_addr.sin_family = AF_INET;
    170193    m_addr.sin_port = htons ( port );
     
    173196
    174197    if ( errno == EAFNOSUPPORT ) return false;
     198
    175199
    176200    status = ::connect ( m_sock, ( sockaddr * ) &m_addr, sizeof ( m_addr ) );
  • BAORadio/libindi/libindi/BAOTest/Socket.h

    r492 r493  
    1919const int MAXRECV = 5000;
    2020
     21
     22
    2123class Socket
    2224{
     
    2426  Socket();
    2527  virtual ~Socket();
     28
    2629
    2730  // Server initialization
     
    4346  bool is_valid() const { return m_sock != -1; }
    4447
     48  bool shutdown();
     49
    4550 private:
    4651
     
    4954
    5055
     56
     57
    5158};
    5259
  • BAORadio/libindi/libindi/drivers/telescope/BAO.cpp

    r492 r493  
    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 {
     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  {
    6161    try
    6262    {
    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;
     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;
    8686    }
    8787    catch ( SocketException& e )
    8888    {
    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 
     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   
    102102    return NULL;
    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 {
     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  {
    113113    if (pthread_create (&th1, NULL, pThreadSocket, NULL) < 0)
    114114    {
    115         IDLog("pthread_create error for threadSocket\n");
    116     }
    117 
     115      IDLog("pthread_create error for threadSocket\n");
     116    }
     117   
    118118    pthread_join (th1, NULL);
    119 }
    120 
    121 /**************************************************************************************
    122 ** Initialisation du pilote BAO
    123 ***************************************************************************************/
    124 void ISInit()
    125 {
     119  }
     120 
     121  /**************************************************************************************
     122  ** Initialisation du pilote BAO
     123  ***************************************************************************************/
     124  void ISInit()
     125  {
    126126    static int isInit=0;
    127 
     127   
    128128    if (isInit) return;
    129 
     129   
    130130    if (telescope.get() == 0) telescope.reset(new BAO());
    131 
     131   
    132132    isInit = 1;
    133 
     133   
    134134    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  {
    142142    ISInit();
    143143    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  {
    151151    ISInit();
    152152    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  {
    160160    ISInit();
    161161    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  {
    169169    ISInit();
    170170    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  {
    178178    INDI_UNUSED(p);
    179 
     179   
    180180    telescope->ISPoll();
    181181    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  {
    190190    INDI_UNUSED(dev);
    191191    INDI_UNUSED(name);
     
    196196    INDI_UNUSED(names);
    197197    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  {
    205205    INDI_UNUSED(root);
    206 }
    207 
    208 /**************************************************************************************
    209 ** Initialisation de la classe BAO
    210 ***************************************************************************************/
    211 BAO::BAO()
    212 {
     206  }
     207 
     208  /**************************************************************************************
     209  ** Initialisation de la classe BAO
     210  ***************************************************************************************/
     211  BAO::BAO()
     212  {
    213213    init_properties();
    214 
     214   
    215215    ConnectSP.s = IPS_IDLE;
    216 
     216   
    217217    lastSet        = -1;
    218218    fd             = -1;
     
    222222    currentSet     = 0;
    223223    JJAnc          = 0.0;
    224 
     224   
    225225    SocketsNumber  = 1;
    226 
     226   
    227227    InitThreadOK=false;
    228228    LecturePosition=false;
     
    230230    Park=false;
    231231    Goto=false;
    232 
     232   
    233233    TrackingMode=1;
    234 
     234   
    235235    for (int i=0; i<MAXHOSTNAME; i++)
    236236    {
    237         Sockets[i].Connected=false;
    238         Sockets[i].IP="";
    239     }
    240 
     237      Sockets[i].Connected=false;
     238      Sockets[i].IP="";
     239    }
     240   
    241241    InitAntennes();
    242 
    243 
     242   
     243   
    244244    IDLog("Initilizing from BAO device...\n");
    245245    IDLog("Driver Version: 2010-05-12\n");
    246 
     246   
    247247    //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 INDI
    260 ***************************************************************************************/
    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  {
    263263    // Connection
    264264    IUFillSwitch(&ConnectS[0], "CONNECT", "Connect", ISS_OFF);
    265265    IUFillSwitch(&ConnectS[1], "DISCONNECT", "Disconnect", ISS_ON);
    266266    IUFillSwitchVector(&ConnectSP, ConnectS, NARRAY(ConnectS), mydev, "CONNECTION", "Connection", BASIC_GROUP, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
    267 
     267   
    268268    // Coord Set
    269269    IUFillSwitch(&OnCoordSetS[0], "TRANSIT", "Transit", ISS_ON);
    270270    IUFillSwitch(&OnCoordSetS[1], "TRACKING", "Tracking", ISS_OFF);
    271271    IUFillSwitchVector(&OnCoordSetSP, OnCoordSetS, NARRAY(OnCoordSetS), mydev, "ON_COORD_SET", "On Set", BASIC_GROUP, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
    272 
     272   
    273273    // Abort
    274274    IUFillSwitch(&AbortSlewS[0], "ABORT", "Abort", ISS_OFF);
    275275    IUFillSwitchVector(&AbortSlewSP, AbortSlewS, NARRAY(AbortSlewS), mydev, "ABORT_MOTION", "Abort", BASIC_GROUP, IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
    276 
     276   
    277277    // Park
    278278    IUFillSwitch(&ParkS[0], "PARK", "Park", ISS_OFF);
    279279    IUFillSwitchVector(&ParkSP, ParkS, NARRAY(ParkS), mydev, "", "Park", BASIC_GROUP, IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
    280 
     280   
    281281    // Object Name
    282282    IUFillText(&ObjectT[0], "OBJECT_NAME", "Name", "--");
    283283    IUFillTextVector(&ObjectTP, ObjectT, NARRAY(ObjectT), mydev, "OBJECT_INFO", "Object", BASIC_GROUP, IP_RW, 0, IPS_IDLE);
    284 
    285 
     284   
     285   
    286286    // Equatorial Coords - SET
    287287    IUFillNumber(&EquatorialCoordsWN[0], "RA", "RA  H:M:S", "%10.6m",  0., 24., 0., 0.);
    288288    IUFillNumber(&EquatorialCoordsWN[1], "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0.);
    289289    IUFillNumberVector(&EquatorialCoordsWNP, EquatorialCoordsWN, NARRAY(EquatorialCoordsWN), mydev, "EQUATORIAL_EOD_COORD_REQUEST" , "Equatorial JNow", BASIC_GROUP, IP_WO, 0, IPS_IDLE);
    290 
     290   
    291291    // Equatorial Coords - READ
    292292    //    IUFillNumber(&EquatorialCoordsRN[0], "RA", "RA  H:M:S", "%10.6m",  0., 24., 0., 0.);
    293293    //    IUFillNumber(&EquatorialCoordsRN[1], "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0.);
    294294    //    IUFillNumberVector(&EquatorialCoordsRNP, EquatorialCoordsRN, NARRAY(EquatorialCoordsRN), mydev, "EQUATORIAL_EOD_COORD" , "Equatorial JNow", BASIC_GROUP, IP_RO, 0, IPS_IDLE);
    295 
     295   
    296296    // Geographic coord - SET
    297297    IUFillNumber(&GeographicCoordsWN[0], "LAT", "Lat  D", "%10.6m",  -90., 90., 0., 0.);
    298298    IUFillNumber(&GeographicCoordsWN[1], "LONG", "Long D", "%10.6m", 0., 360., 0., 0.);
    299299    IUFillNumberVector(&GeographicCoordsWNP, GeographicCoordsWN, NARRAY(GeographicCoordsWN), mydev, "GEOGRAPHIC_COORD" , "Geographic coords", OPTIONS_GROUP, IP_WO, 0, IPS_IDLE);
    300 
    301 
     300   
     301   
    302302    // Transit threshold
    303303    IUFillNumber(&SlewAccuracyN[0], "TransitRA",  "RA (arcmin)", "%10.6m",  0., 60., 1., 3.0);
    304304    IUFillNumber(&SlewAccuracyN[1], "TransitDEC", "Dec (arcmin)", "%10.6m", 0., 60., 1., 3.0);
    305305    IUFillNumberVector(&SlewAccuracyNP, SlewAccuracyN, NARRAY(SlewAccuracyN), mydev, "Transit Accuracy", "", OPTIONS_GROUP, IP_RW, 0, IPS_IDLE);
    306 
     306   
    307307    // Tracking threshold
    308308    IUFillNumber(&TrackAccuracyN[0], "TrackingRA", "RA (arcmin)", "%10.6m",  0., 60., 1., 3.0);
    309309    IUFillNumber(&TrackAccuracyN[1], "TrackingDEC", "Dec (arcmin)", "%10.6m", 0., 60., 1., 3.0);
    310310    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   
    320320    if (dev && strcmp (mydev, dev))
    321         return;
    322 
     321      return;
     322   
    323323    // Main Control
    324324    IDDefSwitch(&ConnectSP, NULL);
     
    330330    IDDefSwitch(&AbortSlewSP, NULL);
    331331    IDDefSwitch(&ParkSP, NULL);
    332 
     332   
    333333    // Options
    334334    IDDefNumber(&SlewAccuracyNP, NULL);
    335335    IDDefNumber(&TrackAccuracyNP, NULL);
    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 {
     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  {
    344344    // Ignore if not ours
    345345    if (strcmp (dev, mydev))
    346         return;
    347 
     346      return;
     347   
    348348    if (is_connected() == false)
    349349    {
    350         IDMessage(mydev, "BAORadio. Please connect before issuing any commands.");
    351         reset_all_properties();
    352         return;
    353     }
    354 
     350      IDMessage(mydev, "BAORadio. Please connect before issuing any commands.");
     351      reset_all_properties();
     352      return;
     353    }
     354   
    355355    // ===================================
    356356    // Object Name
     
    358358    if (!strcmp (name, ObjectTP.name))
    359359    {
    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 
     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   
    375375    // Ignore if not ours
    376376    if (strcmp (dev, mydev))
    377         return;
    378 
     377      return;
     378   
    379379    if (is_connected() == false)
    380380    {
    381         IDMessage(mydev, "BAO is offline. Please connect before issuing any commands.");
    382         reset_all_properties();
    383         return;
    384     }
    385 
    386 
     381      IDMessage(mydev, "BAO is offline. Please connect before issuing any commands.");
     382      reset_all_properties();
     383      return;
     384    }
     385   
     386   
    387387    // ===================================
    388388    // Geographic  Coords
     
    390390    if (!strcmp (name, GeographicCoordsWNP.name))
    391391    {
    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 
     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   
    437437    // ===================================
    438438    // Equatorial Coords
     
    440440    if (!strcmp (name, EquatorialCoordsWNP.name))
    441441    {
    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;
     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;
    491491    } /* end EquatorialCoordsWNP */
    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 {
     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  {
    499499    // ignore if not ours //
    500500    if (strcmp (mydev, dev))
    501         return;
    502 
     501      return;
     502   
    503503    // ===================================
    504504    // Connect Switch
     
    506506    if (!strcmp (name, ConnectSP.name))
    507507    {
    508         if (IUUpdateSwitch(&ConnectSP, states, names, n) < 0)
    509             return;
    510 
    511         connect_telescope();
    512         return;
    513     }
    514 
     508      if (IUUpdateSwitch(&ConnectSP, states, names, n) < 0)
     509        return;
     510     
     511      connect_telescope();
     512      return;
     513    }
     514   
    515515    if (is_connected() == false)
    516516    {
    517         IDMessage(mydev, "BAORadio is offline. Please connect before issuing any commands.");
    518         reset_all_properties();
    519         return;
    520     }
    521 
     517      IDMessage(mydev, "BAORadio is offline. Please connect before issuing any commands.");
     518      reset_all_properties();
     519      return;
     520    }
     521   
    522522    // ===================================
    523523    // Coordinate Set
     
    525525    if (!strcmp(name, OnCoordSetSP.name))
    526526    {
    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 
     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   
    535535    // ===================================
    536536    // Abort slew
     
    538538    if (!strcmp (name, AbortSlewSP.name))
    539539    {
    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 
     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   
    562562    // ===================================
    563563    // Park
     
    565565    if (!strcmp (name, ParkSP.name))
    566566    {
    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 {
     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  {
    594594    nvp->s = IPS_ALERT;
    595 
     595   
    596596    /* If the error is a time out, then the device doesn't support this property */
    597597    if (err == -2)
    598598    {
    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);
     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);
    601601    }
    602602    else
    603         /* Changing property failed, user should retry. */
    604         IDSetNumber( nvp , "%s failed.", msg);
    605 
     603      /* Changing property failed, user should retry. */
     604      IDSetNumber( nvp , "%s failed.", msg);
     605   
    606606    fault = true;
    607 }
    608 
    609 /**************************************************************************************
    610 ** Initialisation des vecteurs INDI
    611 ***************************************************************************************/
    612 void BAO::reset_all_properties()
    613 {
     607  }
     608 
     609  /**************************************************************************************
     610  ** Initialisation des vecteurs INDI
     611  ***************************************************************************************/
     612  void BAO::reset_all_properties()
     613  {
    614614    ConnectSP.s                 = IPS_IDLE;
    615615    OnCoordSetSP.s              = IPS_IDLE;
     
    622622    SlewAccuracyNP.s            = IPS_IDLE;
    623623    TrackAccuracyNP.s           = IPS_IDLE;
    624 
     624   
    625625    IUResetSwitch(&OnCoordSetSP);
    626626    IUResetSwitch(&AbortSlewSP);
    627627    IUResetSwitch(&ParkSP);
    628 
     628   
    629629    OnCoordSetS[0].s = ISS_ON;
    630630    ConnectS[0].s = ISS_OFF;
    631631    ConnectS[1].s = ISS_ON;
    632 
     632   
    633633    IDSetSwitch(&ConnectSP, NULL);
    634634    IDSetSwitch(&OnCoordSetSP, NULL);
     
    641641    IDSetNumber(&SlewAccuracyNP, NULL);
    642642    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  {
    650650    fault = false;
    651651    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  {
    659659    if (simulation) return true;
    660 
     660   
    661661    // return (ConnectSP.sp[0].s == ISS_ON);
    662662    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'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 {
     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  {
    682682    Position result;
    683 
     683   
    684684    std::string str2;
    685 
     685   
    686686    result.x = -1;
    687687    result.y = -1;
    688 
     688   
    689689    int pos = str.find("/");
    690 
     690   
    691691    if (pos != string::npos)
    692692    {
    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 
     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   
    705705    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  {
    716716    double targetAz;
    717717    double targetAlt;
    718718    char AzStr[32];
    719719    char AltStr[32];
    720 
     720   
    721721    // Calcule la hauteur et l'azimut de la zone du ciel pointée (en fonction de la date et du lieu)
    722 
     722   
    723723    Azimut(tsl, Latitude, newRA * 15.0 * Pidiv180, newDEC * Pidiv180, &targetAz, &targetAlt);
    724 
     724   
    725725    // En degrés
    726 
     726   
    727727    targetAlt *= N180divPi;
    728728    targetAz *= N180divPi;
    729 
     729   
    730730    // Affichage dans les logs
    731 
     731   
    732732    fs_sexa(AzStr, targetAz, 2, 3600);
    733733    fs_sexa(AltStr, targetAlt, 2, 3600);
    734 
     734   
    735735    IDLog("Horizontal coords : az %s - Alt %s\n", AzStr, AltStr);
    736 
     736   
    737737    // Le calcul est ici trÚs sommaire et arbitraire :
    738738    // Je considÚre qu'il y a 6000 positions possibles sur les deux axes
    739739    // De plus, je considÚre qu'il n'est pas possible de viser un objet à
    740740    // moins de 30° de hauteur au-dessus de l'horizon
    741 
     741   
    742742    TargetPosition.x=(int)(targetAz*6000.0/360.0);
    743 
     743   
    744744    targetAlt=((90.0-targetAlt)/60.0);
    745 
     745   
    746746    if (targetAlt>=1.0) targetAlt=1.0; //on ne peut pas viser un objet situé à moins de 30°
    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 {
     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  {
    760760    int num=0;
    761 
     761   
    762762    for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected) num++;
    763 
     763   
    764764    return num;
    765 }
    766 
    767 
    768 /************************************************************************************
    769 * Initialisation des paramÚtres des antennes
    770 *
    771 ************************************************************************************/
    772 void BAO::InitAntennes()
    773 {
     765  }
     766 
     767 
     768  /************************************************************************************
     769  * Initialisation des paramÚtres des antennes
     770  *
     771  ************************************************************************************/
     772  void BAO::InitAntennes()
     773  {
    774774    for (int i=0; i < MAXHOSTNAME ; i++)
    775775    {
    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 {
     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  {
    800800    static bool ISPOLLRunning=false;
    801801    static int memSocketsNumber=-1;
    802     static int compt=1000;
     802    static unsigned int compt=100;
    803803    int pos;
    804 
     804   
    805805    struct tm date;
    806806    time_t t;
    807807    struct timeval tv;
    808808    struct timezone tz;
    809 
     809   
    810810    if (is_connected() == false) return;
    811 
     811   
    812812    if (ISPOLLRunning) return;
    813 
     813   
    814814    ISPOLLRunning=true;
    815 
     815   
    816816    compt++;
    817 
    818 
     817   
     818   
    819819    //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   
    853851    if (InitThreadOK)  // Il faut qu'il y ait eu au moins une connexion détectée par le thread pour continuer
    854852    {
    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   
    13721404    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  {
    13821414    switch (currentSet)
    13831415    {
    1384         // Transit
    1385     case BAO_TRANSIT:
    1386 
    1387         EquatorialCoordsWNP.s = IPS_BUSY;
    1388 
    1389         IDSetNumber (&EquatorialCoordsWNP, NULL);
    1390 
    1391         InitAntennes();
    1392 
    1393         JJAnc=JJ;
    1394 
    1395         TrackingMode = 1;
    1396 
    1397         Goto=true;
    1398 
    1399         LecturePosition=true;
    1400 
    1401         break;
    1402 
    1403         // Tracking
    1404     case BAO_TRACKING:
    1405 
    1406         EquatorialCoordsWNP.s = IPS_BUSY;
    1407 
    1408         IDSetNumber (&EquatorialCoordsWNP, NULL);
    1409 
    1410         InitAntennes();
    1411 
    1412         JJAnc=JJ;
    1413 
    1414         TrackingMode = 2;
    1415 
    1416         Goto=true;
    1417 
    1418         LecturePosition=true;
    1419 
    1420         break;
    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   
    14231455    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  {
    14311463    for (int i=0; i < sp->nsp ; i++)
    1432         if (sp->sp[i].s == ISS_ON)
    1433             return i;
    1434 
    1435     return -1;
    1436 }
    1437 
    1438 /**************************************************************************************
    1439 ** Activation de l'interface
    1440 ***************************************************************************************/
    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  {
    14431475    switch (ConnectSP.sp[0].s)
    14441476    {
    1445     case ISS_ON:
    1446         ConnectS[0].s = ISS_ON;
    1447         ConnectS[1].s = ISS_OFF;
    1448         IDLog("\nHello BAORadio !\n");
    1449 
    1450         ConnectSP.s = IPS_OK;
    1451         IDSetSwitch (&ConnectSP, "BAORadio is online. Retrieving basic data...");
    1452 
    1453         break;
    1454 
    1455     case ISS_OFF:
    1456         ConnectS[0].s = ISS_OFF;
    1457         ConnectS[1].s = ISS_ON;
    1458         ConnectSP.s = IPS_IDLE;
    1459 
    1460         SocketsNumber=1;
    1461         InitThreadOK=false;
    1462 
    1463         for (int i=0; i<MAXHOSTNAME; i++)
    1464         {
    1465             Sockets[i].Connected=false;
    1466             Sockets[i].IP="";
    1467             server.close(Sockets[i].new_sock);
    1468         }
    1469 
    1470         InitAntennes();
    1471 
    1472         IDSetSwitch (&ConnectSP, "BAORadio is offline.");
    1473         IDLog("Telescope is offline.");
    1474 
    1475         break;
    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  {
    14841516    //  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  {
    14921524    OnCoordSetSP.s = IPS_IDLE;
    1493 
     1525   
    14941526    if (slewCode == 1)
    1495         IDSetSwitch (&OnCoordSetSP, "Object below horizon.");
     1527      IDSetSwitch (&OnCoordSetSP, "Object below horizon.");
    14961528    else if (slewCode == 2)
    1497         IDSetSwitch (&OnCoordSetSP, "Object below the minimum elevation limit.");
     1529      IDSetSwitch (&OnCoordSetSP, "Object below the minimum elevation limit.");
    14981530    else
    1499         IDSetSwitch (&OnCoordSetSP, "Slew failed.");
    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  {
    15071539    simulation = enable;
    1508 
     1540   
    15091541    if (simulation)
    1510         IDLog("Warning: Simulation is activated.\n");
     1542      IDLog("Warning: Simulation is activated.\n");
    15111543    else
    1512         IDLog("Simulation is disabled.\n");
    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  {
    15201552    ConnectSP.s = IPS_IDLE;
    15211553    IDSetSwitch(&ConnectSP, "The connection to the telescope is lost.");
    15221554    return;
    1523 }
    1524 
    1525 /**************************************************************************************
    1526 **
    1527 ***************************************************************************************/
    1528 void BAO::connection_resumed()
    1529 {
     1555  }
     1556 
     1557  /**************************************************************************************
     1558  **
     1559  ***************************************************************************************/
     1560  void BAO::connection_resumed()
     1561  {
    15301562    ConnectS[0].s = ISS_ON;
    15311563    ConnectS[1].s = ISS_OFF;
    15321564    ConnectSP.s = IPS_OK;
    1533 
     1565   
    15341566    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'acknowledge
    1540 ***************************************************************************************/
    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  {
    15441576    char chaine[MAXCARACTERES];
    1545 
     1577   
    15461578    try
    15471579    {
    1548         sprintf(chaine, "%s%s\n", Commande, Params);
    1549 
    1550         Sockets[numsocket].new_sock << chaine;
     1580      sprintf(chaine, "%s%s\n", Commande, Params);
     1581     
     1582      Sockets[numsocket].new_sock << chaine;
    15511583    }
    15521584    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   
    15711611    return true;
    1572 }
    1573 
    1574 /**************************************************************************************
    1575 ** Commande STATUS
    1576 ***************************************************************************************/
    1577 bool BAO::STATUS(int numsocket)
    1578 {
     1612  }
     1613 
     1614  /**************************************************************************************
     1615  ** Commande STATUS
     1616  ***************************************************************************************/
     1617  bool BAO::STATUS(int numsocket)
     1618  {
    15791619    return COMMANDE(numsocket, (char*)"STATUS", (char*)"");
    1580 }
    1581 
    1582 /**************************************************************************************
    1583 ** Commande POSITION
    1584 ***************************************************************************************/
    1585 
    1586 bool BAO::POSITION(int numsocket)
    1587 {
     1620  }
     1621 
     1622  /**************************************************************************************
     1623  ** Commande POSITION
     1624  ***************************************************************************************/
     1625 
     1626  bool BAO::POSITION(int numsocket)
     1627  {
    15881628    return COMMANDE(numsocket, (char*)"POS", (char*)"");
    1589 }
    1590 
    1591 /**************************************************************************************
    1592 ** Commande PARK
    1593 ***************************************************************************************/
    1594 
    1595 bool BAO::PARK(int numsocket)
    1596 {
     1629  }
     1630 
     1631  /**************************************************************************************
     1632  ** Commande PARK
     1633  ***************************************************************************************/
     1634 
     1635  bool BAO::PARK(int numsocket)
     1636  {
    15971637    return COMMANDE(numsocket, (char*)"PARK", (char*)"");
    1598 }
    1599 
    1600 /**************************************************************************************
    1601 ** Commande ABORT
    1602 ***************************************************************************************/
    1603 
    1604 bool BAO::ABORT(int numsocket)
    1605 {
     1638  }
     1639 
     1640  /**************************************************************************************
     1641  ** Commande ABORT
     1642  ***************************************************************************************/
     1643 
     1644  bool BAO::ABORT(int numsocket)
     1645  {
    16061646    return COMMANDE(numsocket, (char*)"ABORT", (char*)"");
    1607 }
    1608 
    1609 
    1610 /**************************************************************************************
    1611 ** Commande GOTO
    1612 ***************************************************************************************/
    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  {
    16161656    char Params[MAXCARACTERES];
    1617 
     1657   
    16181658    int sensAlt=0;
    16191659    int sensAz=0;
    1620 
     1660   
    16211661    if (deltaAz<0)
    16221662    {
    1623         deltaAz=-deltaAz;
    1624         sensAz=1;
    1625     }
    1626 
     1663      deltaAz=-deltaAz;
     1664      sensAz=1;
     1665    }
     1666   
    16271667    if (deltaAlt<0)
    16281668    {
    1629         deltaAlt=-deltaAlt;
    1630         sensAlt=1;
    1631     }
    1632 
     1669      deltaAlt=-deltaAlt;
     1670      sensAlt=1;
     1671    }
     1672   
    16331673    sprintf(Params, "/%i/# %i Az/%i/# %i Alt", sensAz, deltaAz, sensAlt, deltaAlt);
    1634 
     1674   
    16351675    return COMMANDE(numsocket, (char*)"GOTO", Params);
    1636 }
    1637 
    1638 
     1676  }
     1677 
     1678 
     1679 
  • BAORadio/libindi/libindi/drivers/telescope/ServerSocket.cpp

    r490 r493  
    6868}
    6969
    70 
    71 void ServerSocket::close ( ServerSocket& sock )
     70void ServerSocket::shutdown ( )
    7271{
    73     if ( ! Socket::close ( sock ) )
     72    if ( ! Socket::shutdown ( ) )
    7473    {
    75         throw SocketException ( "Could not accept socket." );
     74        throw SocketException ( "Could not shutdown socket." );
    7675    }
    7776}
    7877
    79 
    80 void ServerSocket::shutdown ( ServerSocket& sock )
     78void ServerSocket::create ( )
    8179{
    82     if ( ! Socket::shutdown ( sock ) )
     80    if ( ! Socket::create ( ) )
    8381    {
    84         throw SocketException ( "Could not accept socket." );
     82        throw SocketException ( "Could not create socket." );
    8583    }
    8684}
    8785
     86bool ServerSocket::connect(std::string IP )
     87{
     88   return Socket::connect (IP, 8000); 
     89}
    8890
    8991std::string ServerSocket::recupip( ServerSocket& sock)
  • BAORadio/libindi/libindi/drivers/telescope/ServerSocket.h

    r490 r493  
    1919  const ServerSocket& operator << ( const std::string& ) const;
    2020  const ServerSocket& operator >> ( std::string& ) const;
     21 
     22  void accept ( ServerSocket& );
    2123
    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 );
    2529 
    2630  std::string recupip( ServerSocket& );
  • BAORadio/libindi/libindi/drivers/telescope/Socket.cpp

    r492 r493  
    9595
    9696
     97bool 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
    97112bool Socket::send ( const std::string s ) const
    98113{
     114    if ( ! is_valid() ) return false;
     115   
    99116    int status = ::send ( m_sock, s.c_str(), s.size(), MSG_NOSIGNAL);
    100117   
     
    105122
    106123
    107 bool Socket::close(  Socket& new_socket ) const
    108 {
    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 ) const
    117 {
    118   int status = ::shutdown ( m_sock, SHUT_RDWR );
    119    
    120     if ( status == -1 ) return false;
    121        
    122     return true;     
    123 }
    124 
    125124int Socket::recv ( std::string& s ) const
    126125{
     
    128127    fd_set r;
    129128    struct timeval timeout;
     129   
     130    if ( ! is_valid() ) return false;
    130131   
    131132    s="";
     
    187188{
    188189    if ( ! is_valid() ) return false;
     190   
     191    memset ( &m_addr,
     192             0,
     193             sizeof ( m_addr ) );
     194
    189195
    190196    m_addr.sin_family = AF_INET;
  • BAORadio/libindi/libindi/drivers/telescope/Socket.h

    r490 r493  
    4444  bool is_valid() const { return m_sock != -1; }
    4545
    46   bool close( Socket& ) const;
    47  
    48   bool shutdown( Socket& ) const;
     46  bool shutdown();
    4947 
    5048 private:
Note: See TracChangeset for help on using the changeset viewer.