Changeset 492


Ignore:
Timestamp:
May 21, 2010, 3:11:33 PM (14 years ago)
Author:
frichard
Message:

-Meilleure gestion des trames sur le réseau Ethernet
-Meilleure synchronisation des antennes lors d'un GOto

Location:
BAORadio/libindi/libindi
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • BAORadio/libindi/libindi/.kdev4/libindi.kdev4

    r490 r492  
    11[Buildset]
    2 BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00)
     2BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x0e\x00l\x00i\x00b\x00i\x00n\x00d\x00i)
    33
    44[CMake]
  • BAORadio/libindi/libindi/BAOTest/BAOtest_main.cpp

    r490 r492  
    104104***************************************************************************************/
    105105
     106#define ERREURS 50
     107
    106108int main ( int argc, int argv[] )
    107109{
     
    109111    char cIP;
    110112    char IP[20];
     113    bool Aleat;
     114
     115    // Parametres sups
     116    bool ErreursAleatoires=false;
     117    bool Affichage=false;
    111118
    112119    // Position PARK
     
    115122
    116123    //init nbs aléatoires
    117     srand(time(NULL));
    118 
    119     //Probabilité qu'il y ait une erreur
    120     int ERREUR=50;
     124    if (ErreursAleatoires) srand(time(NULL));
     125
     126   
    121127
    122128    std::cout <<  "******************\n";
     
    128134    std::cin >> cIP;
    129135
    130     if (cIP=='1') strcpy(IP, "192.168.0.1"); else strcpy(IP, "127.0.0.1");
     136    if (cIP=='1') strcpy(IP, "192.168.0.1");
     137    else strcpy(IP, "127.0.0.1");
    131138
    132139
     
    136143
    137144        std::string reply;
    138         std::string asks;
    139         char chaine[500];
    140 
    141         int numserveur=NumeroServeur();
    142 
     145        std::string asks,memasks;
     146        char chaine[5000];
    143147
    144148        while (true)
    145149        {
    146             try
    147             {
     150           
    148151                client_socket >> asks;
    149152
    150                 if (asks.length()>1)
     153                int pos=asks.find("\n");
     154                memasks=asks;
     155               
     156                while ((pos!=string::npos) && (asks.length()>1))
    151157                {
    152                 std::cout <<  "Pilote BAO : " << asks ;
    153 
    154                 strcpy(chaine, "");
    155 
    156                 if (asks.find("STATUS")!=string::npos)
    157                 {
    158                     strcpy(chaine, "ACK/STATUS\n");
    159                     client_socket << chaine;
    160 
    161                     std::cout <<  "MicrocontrÃŽleur : " << chaine;
    162 
    163                     if (rand()%ERREUR!=1)
    164                     {
    165                         strcpy(chaine, "STATUS/READY\n");
    166                     }
    167                     else
    168                     {
    169                         strcpy(chaine, "STATUS/BUSY\n");
    170                     }
    171                 }
    172 
    173                 if (asks.find("POS")!=string::npos)
    174                 {
    175 
    176                     strcpy(chaine,"ACK/POS\n");
    177                     client_socket << chaine;
    178 
    179                     std::cout <<  "MicrocontrÃŽleur : " << chaine;
    180 
    181                     if (rand()%ERREUR!=1)
    182                     {
    183                         sprintf(chaine, "POS/%i/%i/\n", Pos.x, Pos.y);
    184                     }
    185                     else
    186                     {
    187                         strcpy(chaine, "ERR/HALT/POS/\n");   //erreur moteur !
    188                     }
    189                 }
    190 
    191                 if (asks.find("GOTO")!=string::npos)
    192                 {
    193                     Pos=ExtractPosition(asks);
    194 
    195                     strcpy(chaine,"ACK/GOTO/\n");
    196                     client_socket << chaine;
    197 
    198                     std::cout <<  "MicrocontrÃŽleur : " << chaine;
    199 
    200                     std::cout <<  "Positionnement de l antenne...\n";
    201 
    202                     sleep(rand()%10);
    203 
    204                     if (rand()%ERREUR!=1)
    205                     {
    206                         strcpy(chaine, "OK/GOTO/\n");
    207                     }
    208                     else
    209                     {
    210                         strcpy(chaine, "ERR/HALT/GOTO/\n");   //erreur moteur !
    211                     }
    212                 }
    213 
    214                 if (asks.find("PARK")!=string::npos)
    215                 {
    216 
    217                     strcpy(chaine, "ACK/PARK\n");
    218                     client_socket << chaine;
    219 
    220                     std::cout <<  "MicrocontrÃŽleur : " << chaine;
    221 
    222                     if (rand()%ERREUR!=1)
    223                     {
    224                         strcpy(chaine, "OK/PARK/\n");
    225                     }
    226                     else
    227                     {
    228                         strcpy(chaine, "ERR/HALT/PARK/\n");   //erreur
    229                     }
    230                 }
    231 
    232                 if (asks.find("ABORT")!=string::npos)
    233                 {
    234 
    235                     strcpy(chaine,"ACK/ABORT\n");
    236                     client_socket << chaine;
    237 
    238                     std::cout <<  "MicrocontrÃŽleur : " << chaine;
    239 
    240                     if (rand()%ERREUR!=1)
    241                     {
    242                         strcpy(chaine, "OK/ABORT/\n");
    243                     }
    244                     else
    245                     {
    246                         strcpy(chaine, "ERR/HALT/ABORT/\n");   //erreur
    247                     }                   
    248                 }
    249 
    250                 if (strlen(chaine)>0)
    251                 {
    252                 //   usleep(200);
    253 
    254                    client_socket << chaine;
    255 
    256 
    257                    std::cout <<  "MicrocontrÃŽleur : " << chaine;
    258 
    259                    std::cout <<  "---------\n";
    260                 }
    261 
    262                
    263                 }
    264             }
    265             catch ( SocketException& e) {
    266                 std::cout  << e.description() << "\n";
    267                 break;
    268             }
    269 
    270            
     158                    memasks=asks.substr(pos+1);
     159                    asks=asks.substr(0,pos);
     160
     161                    strcpy(chaine, "");
     162
     163                   
     164                        if (ErreursAleatoires) Aleat=rand()%ERREURS != 1; else Aleat=1;
     165
     166                        if (Affichage) std::cout <<  "Pilote BAO : " << asks << "\n" ;
     167         
     168
     169                        if (asks.find("STATUS")!=string::npos)
     170                        {
     171                            strcpy(chaine, "ACK/STATUS\n");
     172                            client_socket << chaine;
     173
     174                            if (Affichage) std::cout <<  "MicrocontrÃŽleur : " << chaine;
     175
     176                            if (Aleat)
     177                            {
     178                                strcpy(chaine, "STATUS/READY\n");
     179                            }
     180                            else
     181                            {
     182                                strcpy(chaine, "STATUS/BUSY\n");
     183                            }
     184                        }
     185
     186                        if (asks.find("POS")!=string::npos)
     187                        {
     188
     189                            strcpy(chaine,"ACK/POS\n");
     190                            client_socket << chaine;
     191
     192                            if (Affichage) std::cout <<  "MicrocontrÃŽleur : " << chaine;
     193
     194                            if (Aleat)
     195                            {
     196                                sprintf(chaine, "POS/%i/%i/\n", Pos.x, Pos.y);
     197                            }
     198                            else
     199                            {
     200                                strcpy(chaine, "ERR/HALT/POS/\n");   //erreur moteur !
     201                            }
     202                        }
     203
     204                        if (asks.find("GOTO")!=string::npos)
     205                        {
     206                            Pos=ExtractPosition(asks);
     207
     208                            strcpy(chaine,"ACK/GOTO/\n");
     209                            client_socket << chaine;
     210
     211                            if (Affichage)
     212                            {
     213                               std::cout <<  "MicrocontrÃŽleur : " << chaine;
     214
     215                               std::cout <<  "Positionnement de l antenne...\n";
     216                            }
     217
     218                            // sleep(rand()%10);
     219
     220                            if (Aleat)
     221                            {
     222                                strcpy(chaine, "OK/GOTO/\n");
     223                            }
     224                            else
     225                            {
     226                                strcpy(chaine, "ERR/HALT/GOTO/\n");   //erreur moteur !
     227                            }
     228                        }
     229
     230                        if (asks.find("PARK")!=string::npos)
     231                        {
     232
     233                            strcpy(chaine, "ACK/PARK\n");
     234                            client_socket << chaine;
     235
     236                            if (Affichage) std::cout <<  "MicrocontrÃŽleur : " << chaine;
     237
     238                            if (Aleat)
     239                            {
     240                                strcpy(chaine, "OK/PARK/\n");
     241                            }
     242                            else
     243                            {
     244                                strcpy(chaine, "ERR/HALT/PARK/\n");   //erreur
     245                            }
     246                        }
     247
     248                        if (asks.find("ABORT")!=string::npos)
     249                        {
     250
     251                            strcpy(chaine,"ACK/ABORT\n");
     252                            client_socket << chaine;
     253
     254                            if (Affichage) std::cout <<  "MicrocontrÃŽleur : " << chaine;
     255
     256                            if (Aleat)
     257                            {
     258                                strcpy(chaine, "OK/ABORT/\n");
     259                            }
     260                            else
     261                            {
     262                                strcpy(chaine, "ERR/HALT/ABORT/\n");   //erreur
     263                            }
     264                        }
     265
     266                        if (strlen(chaine)>1)
     267                        {
     268                            //   usleep(200);
     269
     270                            client_socket << chaine;
     271
     272
     273                            if (Affichage)
     274                            {
     275                                std::cout <<  "MicrocontrÃŽleur : " << chaine;
     276
     277                                std::cout <<  "---------\n";
     278                            }
     279                        }
     280                   
     281
     282                    asks=memasks;
     283                    pos=asks.find("\n");
     284                }           
     285           
    271286        }
    272287    }
  • BAORadio/libindi/libindi/BAOTest/Socket.cpp

    r490 r492  
    88#include <fcntl.h>
    99#include <iostream>
     10#include <netinet/tcp.h>
    1011
    1112
     
    3839   //  TIME_WAIT - argh
    3940    int on = 1;
     41
    4042    if ( setsockopt ( m_sock, SOL_SOCKET, SO_REUSEADDR, ( const char* ) &on, sizeof ( on ) ) == -1 ) return false;
     43
     44    if (setsockopt(m_sock, SOL_TCP, TCP_NODELAY, (const char*) &on, sizeof(on)) <0) return false;
    4145
    4246    return true;
     
    118122    else if (sel == 0) // timeout
    119123    {
    120         s="\n";
    121124        return 1;
    122125    }
     
    140143                 if (errno == EAGAIN )
    141144                 {
    142                    s="\n";
    143                    return 1;
     145                   return 0;
    144146                 }
    145147                 
  • BAORadio/libindi/libindi/BAOTest/Socket.h

    r490 r492  
    1717const int MAXHOSTNAME = 200;
    1818const int MAXCONNECTIONS = 5;
    19 const int MAXRECV = 500;
     19const int MAXRECV = 5000;
    2020
    2121class Socket
  • BAORadio/libindi/libindi/drivers/telescope/BAO.cpp

    r490 r492  
    2222#include <time.h>
    2323#include <unistd.h>
     24#include <sys/time.h>
    2425
    2526#include <config.h>
     
    6465        // Trouver éventuellement un emplacement disponible dans l'intervalle [1..SocketsNumber]
    6566
    66        /*
     67        /*
    6768        for (int i=1; i<SocketsNumber; i++)
    6869        {
     
    8081        Sockets[pos].Connected=true;
    8182
    82         if (pos == SocketsNumber) SocketsNumber++;
     83        if (pos == SocketsNumber ) SocketsNumber++;
    8384
    8485        InitThreadOK=true;
     
    112113    if (pthread_create (&th1, NULL, pThreadSocket, NULL) < 0)
    113114    {
    114         IDLog("pthread_create error for thread 1\n");
     115        IDLog("pthread_create error for threadSocket\n");
    115116    }
    116117
     
    242243
    243244    IDLog("Initilizing from BAO device...\n");
    244     IDLog("Driver Version: 2010-05-06\n");
     245    IDLog("Driver Version: 2010-05-12\n");
    245246
    246247    //enableSimulation(true);
     
    282283    IUFillTextVector(&ObjectTP, ObjectT, NARRAY(ObjectT), mydev, "OBJECT_INFO", "Object", BASIC_GROUP, IP_RW, 0, IPS_IDLE);
    283284
     285
    284286    // Equatorial Coords - SET
    285287    IUFillNumber(&EquatorialCoordsWN[0], "RA", "RA  H:M:S", "%10.6m",  0., 24., 0., 0.);
    286288    IUFillNumber(&EquatorialCoordsWN[1], "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0.);
    287     IUFillNumberVector(&EquatorialCoordsWNP, EquatorialCoordsWN, NARRAY(EquatorialCoordsWN), mydev, "EQUATORIAL_EOD_COORD_REQUEST" , "Equatorial JNow", BASIC_GROUP, IP_RW, 0, IPS_IDLE);
     289    IUFillNumberVector(&EquatorialCoordsWNP, EquatorialCoordsWN, NARRAY(EquatorialCoordsWN), mydev, "EQUATORIAL_EOD_COORD_REQUEST" , "Equatorial JNow", BASIC_GROUP, IP_WO, 0, IPS_IDLE);
    288290
    289291    // Equatorial Coords - READ
     
    295297    IUFillNumber(&GeographicCoordsWN[0], "LAT", "Lat  D", "%10.6m",  -90., 90., 0., 0.);
    296298    IUFillNumber(&GeographicCoordsWN[1], "LONG", "Long D", "%10.6m", 0., 360., 0., 0.);
    297     IUFillNumberVector(&GeographicCoordsWNP, GeographicCoordsWN, NARRAY(GeographicCoordsWN), mydev, "GEOGRAPHIC_COORD" , "Geographic coords", OPTIONS_GROUP, IP_RW, 0, IPS_IDLE);
     299    IUFillNumberVector(&GeographicCoordsWNP, GeographicCoordsWN, NARRAY(GeographicCoordsWN), mydev, "GEOGRAPHIC_COORD" , "Geographic coords", OPTIONS_GROUP, IP_WO, 0, IPS_IDLE);
    298300
    299301
     
    416418            //Vérification
    417419            //IDLog("Geographic : RA %5.2f - DEC %5.2f\n", Latitude, Longitude);
     420
     421            GeographicCoordsWNP.s = IPS_OK;
     422            IDSetNumber(&GeographicCoordsWNP, NULL);
    418423        }
    419424        else
    420425        {
     426            GeographicCoordsWNP.s = IPS_ALERT;
    421427            IDSetNumber(&GeographicCoordsWNP, "Latitude or Longitude missing or invalid");
    422428
     
    466472
    467473            // on convertit les coordonnées équatoriales de la zone du ciel observée
    468             // en unités des codeurs des moteurs
     474            // en unités de codeurs des moteurs
    469475
    470476            ADDEC2Motor(newRA, newDEC);
     
    669675** Extraction de la position de l'antenne
    670676** dans le retour de la commande POS
    671 ** de type id/POS/Valeur az/Valeur alt
     677** POS/Valeur az/Valeur alt
    672678***************************************************************************************/
    673679
     
    678684    std::string str2;
    679685
    680     result.x=-1;
    681     result.y=-1;
     686    result.x = -1;
     687    result.y = -1;
    682688
    683689    int pos = str.find("/");
    684690
    685     if (pos!=string::npos)
     691    if (pos != string::npos)
    686692    {
    687693        str2 = str.substr(pos+1);
     
    689695        pos = str2.find("/");
    690696
    691         if (pos!=string::npos)
    692         {
    693             result.x=atoi(str2.substr(0, pos).c_str());
    694 
    695             result.y=atoi(str2.substr(pos+1).c_str());
     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());
    696702        }
    697703    }
     
    704710/************************************************************************************
    705711* cette procédure convertit les coordonnées equatoriales de l'objet visé
    706 * en unités des codeurs des paraboles (nb de tours des deux axes moteurs depuis la position PARK)
     712* en unités de codeurs des paraboles (nb de tours des deux axes moteurs depuis la position PARK)
    707713************************************************************************************/
    708714void BAO::ADDEC2Motor(double newRA, double newDEC)
     
    713719    char AltStr[32];
    714720
    715     // Calcule l'azimut et la hauteur de la zone du ciel pointée en fonction de la date et du lieu
    716 
    717     Azimut(tsl, Latitude, newRA*15.0*Pidiv180, newDEC*Pidiv180, &targetAz, &targetAlt);
     721    // Calcule la hauteur et l'azimut de la zone du ciel pointée (en fonction de la date et du lieu)
     722
     723    Azimut(tsl, Latitude, newRA * 15.0 * Pidiv180, newDEC * Pidiv180, &targetAz, &targetAlt);
    718724
    719725    // En degrés
    720726
    721     targetAlt*=N180divPi;
    722     targetAz*=N180divPi;
     727    targetAlt *= N180divPi;
     728    targetAz *= N180divPi;
    723729
    724730    // Affichage dans les logs
     
    738744    targetAlt=((90.0-targetAlt)/60.0);
    739745
    740     if (targetAlt>=1.0) targetAlt=1.0; //on ne peut pas viser un objet situé à moins de 30° de l'horizon
     746    if (targetAlt>=1.0) targetAlt=1.0; //on ne peut pas viser un objet situé à moins de 30°
     747                                       //au-dessus de l'horizon
    741748
    742749    TargetPosition.y=(int)(6000.0*targetAlt);
     
    746753/************************************************************************************
    747754* Retourne simplement le nombre d'antennes connectées
    748 *
     755* et capables de communiquer
    749756************************************************************************************/
    750757
     
    765772void BAO::InitAntennes()
    766773{
    767     for (int i=0; i< MAXHOSTNAME ; i++)
     774    for (int i=0; i < MAXHOSTNAME ; i++)
    768775    {
    769776        Sockets[i].status=0;
     
    772779        Sockets[i].AnomaliesExecution=0;
    773780        Sockets[i].etape=0;
    774         Sockets[i].PosValides=false;
    775 
     781     
    776782        Sockets[i].ack_status=false;
    777783        Sockets[i].ack_pos=false;
     
    779785        Sockets[i].ack_abort=false;
    780786        Sockets[i].ack_goto=false;
    781 
     787       
     788        Sockets[i].PosValides=false;
    782789        Sockets[i].GotoOk=false;
    783790    }
     
    793800    static bool ISPOLLRunning=false;
    794801    static int memSocketsNumber=-1;
     802    static int compt=1000;
     803    int pos;
    795804
    796805    struct tm date;
    797806    time_t t;
     807    struct timeval tv;
     808    struct timezone tz;
    798809
    799810    if (is_connected() == false) return;
     
    803814    ISPOLLRunning=true;
    804815
    805 
    806     //Récupération de la date et de l'heure
    807 
    808     time(&t);
    809     date=*gmtime(&t) ;
    810 
    811     Annee=(double)(date.tm_year+1900);
    812     Mois=(double)(date.tm_mon+1);
    813     Jour=(double)date.tm_mday;
    814     Heu=(double)date.tm_hour;
    815     Min=(double)date.tm_min;
    816     Sec=(double)date.tm_sec;
    817     UTCP=0.0;//(double)date.tm_isdst;
    818 
    819 
    820     //Calcul du temps sidéral local
    821 
    822     CalculTSL();
    823 
    824 
    825     //Y a-t-il de nouvelles tentatives de connexion sur le serveur ?
    826 
    827     InitThread();
    828 
    829 
    830     if (InitThreadOK)  // Il faut au moins une connexion détectée par le thread pour continuer
     816    compt++;
     817
     818
     819    //toutes les 100 millisec
     820
     821    if (compt>100)
     822    {
     823        //Récupération de la date et de l'heure
     824
     825        time(&t);
     826        date=*gmtime(&t);
     827        gettimeofday(&tv, &tz);
     828
     829        Annee=(double)(date.tm_year+1900);
     830        Mois=(double)(date.tm_mon+1);
     831        Jour=(double)date.tm_mday;
     832        Heu=(double)date.tm_hour;
     833        Min=(double)date.tm_min;
     834        Sec=(double)date.tm_sec+tv.tv_usec/1.0E6;
     835        UTCP=0.0;//(double)date.tm_isdst;
     836       
     837       
     838        //Calcul du temps sidéral local
     839
     840        CalculTSL();
     841       
     842       
     843        //Y a-t-il de nouvelles tentatives de connexion sur le serveur ?
     844
     845        InitThread();
     846
     847        compt=0;
     848    }
     849
     850
     851
     852
     853    if (InitThreadOK)  // Il faut qu'il y ait eu au moins une connexion détectée par le thread pour continuer
    831854    {
    832855
     
    837860            memSocketsNumber=SocketsNumber;
    838861
    839             IDSetSwitch(&ConnectSP, "Connexion de l antenne %s. (Antennes connectées : %i)", Sockets[SocketsNumber-1].IP.c_str(), AntennesConnectees());
     862            IDSetSwitch(&ConnectSP, "Connexion de l antenne %s. (Antennes connectées : %i)",
     863                        Sockets[SocketsNumber-1].IP.c_str(), AntennesConnectees());
    840864        }
    841865
     
    851875                {
    852876                    std::string reponse, memreponse;
    853 
    854 
    855877                    // on récupÚre la réponse du microcontrÃŽleur
    856878
    857879                    Sockets[i].new_sock >> reponse;
    858880
    859                     if (reponse.length()>1)
     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))
    860889                    {
    861                         //Dans le cas où plusieurs trames seraient arrivées entre deux appels de POLLMS
    862                         //les traiter successivement
    863 
    864                         int pos=reponse.find("\n");   // d'où l'intérêt de mettre un '\n' à la fin des trames
    865 
    866                         memreponse=reponse;
    867 
    868                         while (pos!=string::npos)
     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)
    869898                        {
    870                             memreponse=reponse.substr(pos+1);
    871 
    872                             reponse=reponse.substr (0, pos);
    873 
    874                             //IDSetSwitch(&OnCoordSetSP, "Réponse ISPOLL : %s\n", reponse.c_str());        // pour vérif
    875 
    876 
    877                             // On traite ici les acknowledges
    878 
    879                             if (reponse.find("ACK")!=string::npos)
    880                             {
    881                                 if (reponse.find("STATUS")!=string::npos)
     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)
    882926                                {
    883                                     Sockets[i].ack_status=true;
     927                                    Sockets[i].status='R';
    884928                                }
    885 
    886                                 if (reponse.find("POS")!=string::npos)
     929                                else if (reponse.find("BUSY")!=string::npos)
    887930                                {
    888                                     Sockets[i].ack_pos=true;
     931                                    Sockets[i].status='B';
    889932                                }
    890933
    891                                 if (reponse.find("PARK")!=string::npos)
     934                            }//réponse à la requête POSITION
     935                            else if (reponse.find("POS")!=string::npos)
     936                            {
     937                                if (reponse.find("ERR")!=string::npos)
    892938                                {
    893                                     Sockets[i].ack_park=true;
     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;
    894945                                }
    895 
    896                                 if (reponse.find("ABORT")!=string::npos)
     946                                else
    897947                                {
    898                                     Sockets[i].ack_abort=true;
     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);
    899953                                }
    900954
    901                                 if (reponse.find("GOTO")!=string::npos)
     955                            }//réponse à la requête PARK
     956                            else if (reponse.find("PARK")!=string::npos)
     957                            {
     958                                if (reponse.find("ERR")!=string::npos)
    902959                                {
    903                                     Sockets[i].ack_goto=true;
     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());
    904966                                }
    905                             }
    906                             else
    907                             {
    908                                 //réponse à la requête STATUS
    909                                 if (reponse.find("STATUS")!=string::npos)
     967
     968                            }//réponse à la requête ABORT
     969                            else if (reponse.find("ABORT")!=string::npos)
     970                            {
     971                                if (reponse.find("ERR")!=string::npos)
    910972                                {
    911                                     if (reponse.find("READY")!=string::npos) Sockets[i].status='R';
    912 
    913                                     if (reponse.find("BUSY")!=string::npos) Sockets[i].status='B';
     973                                    AbortSlewSP.s = IPS_ALERT;
     974                                    IDSetSwitch(&AbortSlewSP, "ALERTE antenne %s : erreur ABORT !\n",  Sockets[i].IP.c_str());
    914975                                }
    915976
    916                                 //réponse à la requête POSITION
    917                                 if (reponse.find("POS")!=string::npos)
     977                                if (reponse.find("OK")!=string::npos)
    918978                                {
    919                                     if (reponse.find("ERR")!=string::npos)
     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())
    9201018                                    {
    921                                         OnCoordSetSP.s = IPS_ALERT;
    922                                         IDSetSwitch(&OnCoordSetSP, "ALERTE !\n");
    923                                         IDSetSwitch(&OnCoordSetSP, "Antenne %s : position de l antenne inconnue !\n",  Sockets[i].IP.c_str());
    924                                         Sockets[i].PosValides=false;
    925                                         Sockets[i].Connected=false;   // Si la position de l'antenne est inconnue, c'est peut être risqué de faire un GOto
    926                                     }
    927                                     else
    928                                     {
    929                                         OnCoordSetSP.s = IPS_OK;
    930                                         Sockets[i].Pos=ExtractPosition(reponse);
    931                                         Sockets[i].PosValides=true;
    932                                         IDSetSwitch(&ParkSP, "Antenne %s : POSITION OK  (x=%i, y=%i)\n",  Sockets[i].IP.c_str(), Sockets[i].Pos.x, Sockets[i].Pos.y);
    933                                     }
    934                                 }
    935 
    936 
    937                                 //réponse à la requête PARK
    938                                 if (reponse.find("PARK")!=string::npos)
    939                                 {
    940                                     if (reponse.find("ERR")!=string::npos)
    941                                     {
    942                                         ParkSP.s = IPS_ALERT;
    943                                         IDSetSwitch(&ParkSP, "ALERTE !\n");
    944                                         IDSetSwitch(&ParkSP, "Antenne %s : erreur PARK !\n", Sockets[i].IP.c_str());
    945                                     }
    946 
    947                                     if (reponse.find("OK")!=string::npos)
    948                                     {
    949                                         ParkSP.s = IPS_OK;
    950                                         IDSetSwitch(&ParkSP, "Antenne %s : PARK OK\n",  Sockets[i].IP.c_str());
    951                                     }
    952                                 }
    953 
    954                                 //réponse à la requête ABORT
    955                                 if (reponse.find("ABORT")!=string::npos)
    956                                 {
    957                                     if (reponse.find("ERR")!=string::npos)
    958                                     {
    959                                         AbortSlewSP.s = IPS_ALERT;
    960                                         IDSetSwitch(&AbortSlewSP, "ALERTE !\n");
    961                                         IDSetSwitch(&AbortSlewSP, "Antenne %s : erreur ABORT !\n",  Sockets[i].IP.c_str());
    962                                     }
    963 
    964                                     if (reponse.find("OK")!=string::npos)
    965                                     {
    966                                         AbortSlewSP.s = IPS_OK;
    967                                         IDSetSwitch(&AbortSlewSP, "Antenne %s : ABORT OK\n",  Sockets[i].IP.c_str());
    968                                     }
    969                                 }
    970 
    971                                 //réponse à la requête GOTO
    972                                 if (reponse.find("GOTO")!=string::npos)
    973                                 {
    974                                     if (reponse.find("ERR")!=string::npos)
    975                                     {
    976                                         OnCoordSetSP.s = IPS_ALERT;
    977                                         IDSetSwitch(&OnCoordSetSP, "ALERTE !\n");
    978                                         IDSetSwitch(&OnCoordSetSP, "Antenne %s : Erreur GOTO !\n",  Sockets[i].IP.c_str());
    979                                         Sockets[i].Connected=false;
    980                                     }
    981                                     else
    982                                     {
    983                                         OnCoordSetSP.s = IPS_OK;
    984 
    985                                         Sockets[i].GotoOk=true;
    986 
    987                                         IDSetSwitch(&ParkSP, "Antenne %s : GOTO OK.\n",  Sockets[i].IP.c_str());
    988 
    989                                         char RAStr[32], DecStr[32];
    990 
    991                                         //currentRA=targetRA;
    992                                         //currentDEC=targetDEC;
    993                                         lastRA  = targetRA;
    994                                         lastDEC = targetDEC;
    995 
    996                                         /*fs_sexa(RAStr, targetRA, 2, 3600);
    997                                         fs_sexa(DecStr, targetDEC, 2, 3600);
    998 
    999                                         IDLog("We received JNow RA %s - DEC %s\n", RAStr, DecStr);*/
    1000 
    1001                                         //IDSetNumber (&EquatorialCoordsRNP, NULL);
    1002                                         EquatorialCoordsWNP.s = IPS_OK;
    1003                                         IDSetNumber (&EquatorialCoordsWNP, NULL);
    1004 
    1005                                         // Fin du Goto pour toutes les antennes ?
    1006 
    1007                                         int num=0;
    1008 
    1009                                         for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected)
    1010                                             {
    1011                                                 if (Sockets[i].GotoOk) num++;
    1012                                             }
    1013 
    1014                                         if (num == AntennesConnectees())
    1015                                         {
    1016                                             LecturePosition=false;
    1017 
    1018                                             InitAntennes();
    1019 
    1020                                             IDSetSwitch(&OnCoordSetSP, "GOTO OK !");
    1021                                         }
     1019                                        LecturePosition=false;
     1020
     1021                                        InitAntennes();
     1022
     1023                                        IDSetSwitch(&OnCoordSetSP, "GOTO OK !");
    10221024                                    }
    10231025                                }
    10241026                            }
    1025 
    1026                             // On passe enventuellement à la trame suivante
    1027 
    1028                             reponse=memreponse;
    1029                             pos=reponse.find("\n");
    10301027                        }
     1028
     1029                        // On passe éventuellement à la trame suivante
     1030
     1031                        reponse=memreponse;
     1032                        pos=reponse.find("\n");
     1033
    10311034                    }
    10321035                }
     
    10341037                {
    10351038                    Sockets[i].Connected=false;
    1036                    
     1039
    10371040                    std::string oss;
    10381041                    oss="SocketException IsPoll : " + e.description() + "\n";
     
    10441047                }
    10451048            }
    1046    
    1047 
    1048 
    1049     if (Abort)
    1050     {
    1051         IDSetSwitch(&ConnectSP, "Envoi de la commande Abort\n");
    1052 
    1053         Goto=false;
     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 ?
    10541301
    10551302        for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected)
    10561303            {
    1057                 if (!ABORT(i)) Sockets[i].sendalertes++;
     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                }
    10581311            }
    10591312
    1060         LecturePosition=false;
    1061 
    1062         InitAntennes();
    1063 
    1064         Abort=false;
    1065     }
    1066 
    1067 
    1068     if (Park)
    1069     {
    1070         IDSetSwitch(&ConnectSP, "Envoi de la commande Park\n");
    1071 
    1072         Goto=false;
     1313
     1314
     1315        //On attend que toutes les antennes soient prêtes pour lancer l'ordre Goto -> meilleure synchronisation
     1316
     1317        int num=0;
    10731318
    10741319        for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected)
    10751320            {
    1076                 if (!PARK(i)) Sockets[i].sendalertes++;
     1321                if (Sockets[i].etape == 6) num++; //fin de la procédure LecturePosition. Les antennes sont prêtes
     1322                //à recevoir l'ordre GOto
    10771323            }
    10781324
    1079         LecturePosition=false;
    1080 
    1081         InitAntennes();
    1082 
    1083         Park=false;
    1084     }
    1085 
    1086     // Gestion du suivi
    1087 
    1088     if (Goto)
    1089     {
    1090         // Durée entre deux actualisations
    1091 
    1092         double delai=15.0/60.0/24.0;   // Actualisation toutes les 15 minutes en mode transit
    1093 
    1094         if (TrackingMode==2) delai=1.0/60.0/24.0;   //et 1 minute en mode tracking
    1095 
    1096 
    1097         // On actualise la position
    1098 
    1099         if (JJ-JJAnc > delai)
    1100         {
    1101             ADDEC2Motor(targetRA, targetDEC);
    1102 
    1103             InitAntennes();
    1104 
    1105             LecturePosition=true;
    1106 
    1107             JJAnc=JJ;
    1108         }
    1109 
    1110         //Plus d'antenne !
    1111 
    1112         if (AntennesConnectees() == 0)
    1113         {
    1114             LecturePosition=false;
    1115 
    1116             Goto=false;
    1117 
    1118             InitAntennes();
    1119 
    1120             IDSetSwitch(&OnCoordSetSP, "Erreur 1004 : Plus d antennes connectées !");
    1121         }
    1122     }
    1123 
    1124 
    1125 
    1126     // Exécution de la procédure complÚte de lecture de la position de l'antenne
    1127     // puis envoi d'une commande Goto
    1128 
    1129     if (LecturePosition)
    1130     {
    1131         for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected)
    1132             {
    1133                 switch (Sockets[i].etape)
     1325        if ((num == AntennesConnectees()) && (num>0))
     1326        {
     1327            for (int i=1; i<SocketsNumber; i++ ) if (Sockets[i].Connected)
    11341328                {
    1135                     //Envoi des requêtes STATUS
    1136                 case 0 :
    1137                 {
    1138                     Sockets[i].AttenteExecution=0;
    1139                     Sockets[i].ack_status=false;
    1140                     Sockets[i].status=0;
    1141 
    1142                     if (!STATUS(i)) Sockets[i].sendalertes++;
     1329                    Sockets[i].ack_goto=false;
     1330
     1331                    if (!GOTO(i, TargetPosition.x, TargetPosition.y)) Sockets[i].sendalertes++;
    11431332
    11441333                    Sockets[i].etape++;
    11451334                }
    1146                 break;
    1147 
    1148                 //vérification ack statuts
    1149                 case 1 :
    1150                 {
    1151                     if (Sockets[i].ack_status)
    1152                     {
    1153                         Sockets[i].AttenteExecution=0;
    1154                         Sockets[i].etape++;
    1155                     }
    1156                     else
    1157                     {
    1158                         // on réitÚre l'ordre précédent si rien ne se passe
    1159 
    1160                         Sockets[i].AttenteExecution++;
    1161 
    1162                         if (Sockets[i].AttenteExecution>MAXATTENTE)
    1163                         {
    1164                             Sockets[i].etape=0;
    1165                             Sockets[i].AttenteExecution=0;
    1166                         }
    1167                     }
    1168                 }
    1169                 break;
    1170 
    1171                 //status ready ?
    1172                 case 2 :
    1173                 {
    1174                     if (Sockets[i].status == 'R')
    1175                     {
    1176                         Sockets[i].AttenteExecution=0;
    1177                         Sockets[i].etape++;
    1178                     }
    1179                     else
    1180                     {
    1181                         // on réitÚre l'ordre précédent si rien ne se passe
    1182 
    1183                         Sockets[i].AttenteExecution++;
    1184 
    1185                         if (Sockets[i].AttenteExecution>MAXATTENTE)
    1186                         {
    1187                             Sockets[i].etape=0;
    1188                             Sockets[i].AttenteExecution=0;
    1189                             Sockets[i].AnomaliesExecution++;
    1190                         }
    1191 
    1192                         if (Sockets[i].AnomaliesExecution>MAXANOMALIES)
    1193                         {
    1194                             IDSetSwitch(&OnCoordSetSP, "ERREUR 1001 : Erreur critique sur l antenne %s. Déconnexion de l antenne.",  Sockets[i].IP.c_str());
    1195                             Sockets[i].Connected=false;                           
    1196                         }
    1197                     }
    1198                 }
    1199                 break;
    1200 
    1201                 //Envoi de la commande POS
    1202                 case 3 :
    1203                 {
    1204                     Sockets[i].ack_pos=false;
    1205                     Sockets[i].PosValides=false;
    1206 
    1207                     if (!POSITION(i)) Sockets[i].sendalertes++;
    1208 
    1209                     Sockets[i].etape++;
    1210                 }
    1211                 break;
    1212 
    1213                 //ack POS
    1214                 case 4 :
    1215                 {
    1216                     if (Sockets[i].ack_pos)
    1217                     {
    1218                         Sockets[i].AttenteExecution=0;
    1219                         Sockets[i].etape++;
    1220                     }
    1221                     else
    1222                     {
    1223                         // on réitÚre l'ordre précédent si rien ne se passe
    1224 
    1225                         Sockets[i].AttenteExecution++;
    1226 
    1227                         if (Sockets[i].AttenteExecution>MAXATTENTE)
    1228                         {
    1229                             Sockets[i].etape=3;
    1230                             Sockets[i].AnomaliesExecution=0;
    1231                         }
    1232                     }
    1233                 }
    1234                 break;
    1235 
    1236                 //Valeurs pos valides ?
    1237                 case 5 :
    1238                 {
    1239                     if (Sockets[i].PosValides)
    1240                     {
    1241                         Sockets[i].ack_goto=false;
    1242 
    1243                         if (!GOTO(i, TargetPosition.x, TargetPosition.y)) Sockets[i].sendalertes++;
    1244 
    1245                         Sockets[i].AttenteExecution=0;
    1246                         Sockets[i].etape++;
    1247                     }
    1248                     else
    1249                     {
    1250                         // on réitÚre l'ordre précédent si rien ne se passe
    1251 
    1252                         Sockets[i].AttenteExecution++;
    1253 
    1254                         if (Sockets[i].AttenteExecution>MAXATTENTE)
    1255                         {
    1256                             Sockets[i].etape=0;
    1257                             Sockets[i].AttenteExecution=0;
    1258                             Sockets[i].AnomaliesExecution++;
    1259                         }
    1260 
    1261                         if (Sockets[i].AnomaliesExecution>MAXANOMALIES)
    1262                         {
    1263                             IDSetSwitch(&OnCoordSetSP, "ERREUR 1002 : Erreur critique sur l antenne %s. Déconnexion de l antenne.",  Sockets[i].IP.c_str());
    1264                             Sockets[i].Connected=false;
    1265                         }
    1266                     }
    1267                 }
    1268                 break;
    1269 
    1270                 //ack goto
    1271                 case 6 :
    1272                 {
    1273                     if (Sockets[i].ack_goto)
    1274                     {
    1275                         Sockets[i].etape++;
    1276                     }
    1277                     else
    1278                     {
    1279                         // on réitÚre l'ordre précédent si rien ne se passe
    1280 
    1281                         Sockets[i].AttenteExecution++;
    1282 
    1283                         if (Sockets[i].AttenteExecution>MAXATTENTE)
    1284                         {
    1285                             Sockets[i].etape=5;
    1286                             Sockets[i].AttenteExecution=0;
    1287                         }
    1288                     }
    1289                 }
    1290                 break;
    1291 
    1292                 }
     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;
    12931358            }
    1294     }
    1295 
    1296 
    1297     // Détection d'anomalies concernant l'envoi de trames sur la socket. déconnexion du micro-cont ?
    1298 
    1299     for (int i=1; i<SocketsNumber; i++) if (Sockets[i].Connected)
    1300         {
    1301             if (Sockets[i].sendalertes > 0)
    1302             {
    1303                 IDSetSwitch(&OnCoordSetSP, "Erreur 1003 : Anomalie détectée sur l antenne %s. Déconnexion de l antenne.",  Sockets[i].IP.c_str());
    1304 
    1305                 Sockets[i].Connected=false;
    1306             }
    1307         }
    1308 
    1309    
    1310    
    1311     switch (EquatorialCoordsWNP.s)
    1312     {
    1313     case IPS_IDLE:
     1359
     1360            break;
     1361
     1362        case IPS_OK:
     1363
     1364            break;
     1365
     1366        case IPS_ALERT:
     1367
     1368            break;
     1369        }*/
     1370    }
     1371
     1372    ISPOLLRunning=false;
     1373}
     1374
     1375
     1376
     1377/**************************************************************************************
     1378**
     1379***************************************************************************************/
     1380bool BAO::process_coords()
     1381{
     1382    switch (currentSet)
     1383    {
     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;
    13141400
    13151401        break;
    13161402
    1317     case IPS_BUSY:
    1318 
    1319         /*switch (currentSet)
    1320         {
    1321         case LX200_TRANSIT:
    1322         OnCoordSetSP.sp[LX200_TRANSIT].s = ISS_ON;
    1323         IDSetSwitch (&OnCoordSetSP, "Slew is complete.");
    1324         break;
    1325 
    1326         case LX200_TRACKING:
    1327         OnCoordSetSP.sp[LX200_TRACKING].s = ISS_ON;
    1328         IDSetSwitch (&OnCoordSetSP, "Slew is complete. Tracking...");
    1329         break;
    1330         }*/
    1331 
    1332         break;
    1333 
    1334     case IPS_OK:
    1335 
    1336         break;
    1337 
    1338     case IPS_ALERT:
    1339 
    1340         break;
    1341     }
    1342     }
    1343 
    1344     ISPOLLRunning=false;
    1345 }
    1346 
    1347 
    1348 
    1349 /**************************************************************************************
    1350 **
    1351 ***************************************************************************************/
    1352 bool BAO::process_coords()
    1353 {
    1354     switch (currentSet)
    1355     {
    1356         // Transit
    1357     case LX200_TRANSIT:
    1358 
    1359         InitAntennes();
    1360 
    1361         JJAnc=JJ;
    1362 
    1363         TrackingMode = 1;
    1364 
    1365         Goto=true;
    1366 
    1367         LecturePosition=true;
    1368 
    1369         break;
    1370 
    13711403        // Tracking
    1372     case LX200_TRACKING:
     1404    case BAO_TRACKING:
     1405
     1406        EquatorialCoordsWNP.s = IPS_BUSY;
     1407
     1408        IDSetNumber (&EquatorialCoordsWNP, NULL);
    13731409
    13741410        InitAntennes();
  • BAORadio/libindi/libindi/drivers/telescope/BAO.h

    r490 r492  
    3030#define MAXCARACTERES 1024
    3131
    32 #define MAXATTENTE 20                //Si une commande ne recoit pas d'acknowledge. Alors refaire 20 tentatives en renvoyant la commande
    33 #define MAXANOMALIES 2                //Si pas de réponse au bout de 40 tentatives -> erreur critique -> socket perdue ?
     32#define MAXATTENTE 40                //Si une commande ne recoit pas d'acknowledge. Alors refaire 40 tentatives en renvoyant la commande
     33#define MAXANOMALIES 2               //Si pas de réponse au bout de 80 tentatives -> erreur critique -> socket perdu ?
    3434
    3535struct Position
     
    4646   
    4747    bool Connected;              //le micro-contrÃŽleur est-il connecté ?
    48     bool PosValides;             //le micro-contrÃŽleur a-t-il donné sa position ?
     48    bool PosValides;             //le micro-contrÃŽleur a-t-il donné une position valide ?
    4949    char status;                 //status='B' pour busy  'R' pour READY
    50     int sendalertes;             //une requête send sur le réseau a généré une erreur
    51     int AttenteExecution;        //Une antenne rencontre des difficultés pour executer un cycle de commandes
    52     int AnomaliesExecution;      //Erreur critique. L'antenne ne réagit plus
     50    int sendalertes;             //une requête "send" a généré une erreur sur le réseau
     51    int AttenteExecution;        //L'antenne parvient-elle à executer un cycle de commandes ?
     52    int AnomaliesExecution;      //Erreur critique. L'antenne ne répond plus !
    5353                   
    5454    Position Pos;                //derniÚre position retournée par le microcontrÃŽleur   
    5555    int etape;
    5656   
    57     bool ack_status;
     57    bool ack_status;             //Etat des acknowledges ?
    5858    bool ack_pos;
    5959    bool ack_park;
    6060    bool ack_abort;
    6161    bool ack_goto;
    62     bool GotoOk; 
     62    bool GotoOk;                 //Est-ce que le dernier goto est OK ?
    6363};
    6464
     
    101101private:
    102102
    103     enum LX200_STATUS { LX200_TRANSIT, LX200_TRACKING, LX200_PARK };
     103    enum BAO_STATUS { BAO_TRANSIT, BAO_TRACKING, BAO_PARK };
    104104
    105105    /* Switches */
     
    127127
    128128    /* Number Vectors */
    129     INumberVectorProperty EquatorialCoordsRNP;
     129    //INumberVectorProperty EquatorialCoordsRNP;
    130130    INumberVectorProperty EquatorialCoordsWNP;
    131131    INumberVectorProperty GeographicCoordsWNP;
  • BAORadio/libindi/libindi/drivers/telescope/Socket.cpp

    r490 r492  
    88#include <fcntl.h>
    99#include <iostream>
     10#include <netinet/tcp.h>
    1011
    1112
     
    3637
    3738
    38    //  TIME_WAIT - argh
    3939    int on = 1;
     40
    4041    if ( setsockopt ( m_sock, SOL_SOCKET, SO_REUSEADDR, ( const char* ) &on, sizeof ( on ) ) == -1 ) return false;
     42
     43    // Réduire les délais lors des transmissions TCP/IP
     44    // Voir article à l'adresse
     45    // http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Realtime_Tuning_Guide/sect-Realtime_Tuning_Guide-Application_Tuning_and_Deployment-TCP_NODELAY_and_Small_Buffer_Writes.html
     46   
     47    if ( setsockopt(m_sock, SOL_TCP, TCP_NODELAY, (const char*) &on, sizeof(on)) < 0 ) return false;
    4148
    4249    return true;
     
    116123}
    117124
    118 
    119125int Socket::recv ( std::string& s ) const
    120126{
     
    131137    FD_SET(m_sock, &r); // ajoute la socket dans la liste des fd
    132138    sel = select(m_sock + 1, &r, NULL, NULL, &timeout);
    133    
    134139    if (sel < 0) // select a rencontré un problÚme
    135140    {
    136         return -1;
     141        return -1;
    137142    }
    138143    else if (sel == 0) // timeout
    139144    {
    140         s="\n";
    141145        return 1;
    142146    }
     
    160164                 if (errno == EAGAIN )
    161165                 {
    162                    s="\n";
    163                    return 1;
     166                   return 0;
    164167                 }
    165168                 
     
    199202}
    200203
    201 
    202204void Socket::set_non_blocking ( const bool b )
    203205{
Note: See TracChangeset for help on using the changeset viewer.