| 1 | /* | 
|---|
| 2 | LX200 Basic Driver | 
|---|
| 3 | Copyright (C) 2005 Jasem Mutlaq (mutlaqja@ikarustech.com) | 
|---|
| 4 |  | 
|---|
| 5 | This library is free software; you can redistribute it and/or | 
|---|
| 6 | modify it under the terms of the GNU Lesser General Public | 
|---|
| 7 | License as published by the Free Software Foundation; either | 
|---|
| 8 | version 2.1 of the License, or (at your option) any later version. | 
|---|
| 9 |  | 
|---|
| 10 | This library is distributed in the hope that it will be useful, | 
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 13 | Lesser General Public License for more details. | 
|---|
| 14 |  | 
|---|
| 15 | You should have received a copy of the GNU Lesser General Public | 
|---|
| 16 | License along with this library; if not, write to the Free Software | 
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
|---|
| 18 |  | 
|---|
| 19 | */ | 
|---|
| 20 |  | 
|---|
| 21 | #ifndef BAO_H | 
|---|
| 22 | #define BAO_H | 
|---|
| 23 |  | 
|---|
| 24 | #include "indidevapi.h" | 
|---|
| 25 | #include "indicom.h" | 
|---|
| 26 | #include "ServerSocket.h" | 
|---|
| 27 | #include "SocketException.h" | 
|---|
| 28 | #include "astro.h" | 
|---|
| 29 |  | 
|---|
| 30 | #define MAXCARACTERES 1024 | 
|---|
| 31 |  | 
|---|
| 32 | #define MAXATTENTE 80                //Si une commande ne recoit pas d'acknowledge. Alors refaire 80 tentatives en renvoyant la commande | 
|---|
| 33 | #define MAXANOMALIES 2               //Si pas de réponse au bout de 80 tentatives -> erreur critique -> socket perdu ? | 
|---|
| 34 | #define MAXANOMALIESGOTO 1500 | 
|---|
| 35 |  | 
|---|
| 36 | struct Position | 
|---|
| 37 | { | 
|---|
| 38 | int x; | 
|---|
| 39 | int y; | 
|---|
| 40 | }; | 
|---|
| 41 |  | 
|---|
| 42 | struct DefSocket | 
|---|
| 43 | { | 
|---|
| 44 | ServerSocket new_sock; | 
|---|
| 45 |  | 
|---|
| 46 | std::string IP;              //IP de l'antenne | 
|---|
| 47 |  | 
|---|
| 48 | bool Connected;              //le micro-contrÎleur est-il connecté ? | 
|---|
| 49 | bool PosValides;             //le micro-contrÎleur a-t-il donné une position valide ? | 
|---|
| 50 | char status;                 //status='B' pour busy  'R' pour READY | 
|---|
| 51 | int sendalertes;             //une requête "send" a généré une erreur sur le réseau | 
|---|
| 52 | int AttenteExecution;        //L'antenne parvient-elle à executer un cycle de commandes ? | 
|---|
| 53 | int AnomaliesExecution;      //Erreur critique. L'antenne ne répond plus ! | 
|---|
| 54 |  | 
|---|
| 55 | Position Pos;                //derniÚre position retournée par le microcontrÎleur | 
|---|
| 56 | int etape; | 
|---|
| 57 |  | 
|---|
| 58 | bool ack_status;             //Etat des acknowledges ? | 
|---|
| 59 | bool ack_pos; | 
|---|
| 60 | bool ack_park; | 
|---|
| 61 | bool ack_abort; | 
|---|
| 62 | bool ack_goto; | 
|---|
| 63 | bool GotoOk;                 //Est-ce que le dernier goto est OK ? | 
|---|
| 64 | }; | 
|---|
| 65 |  | 
|---|
| 66 | ServerSocket server( 8000 ); | 
|---|
| 67 | int SocketsNumber; | 
|---|
| 68 | bool InitThreadOK; | 
|---|
| 69 | DefSocket Sockets[MAXHOSTNAME + 1]; | 
|---|
| 70 | pthread_t th1; | 
|---|
| 71 |  | 
|---|
| 72 | class BAO : public Astro | 
|---|
| 73 | { | 
|---|
| 74 | public: | 
|---|
| 75 | BAO(); | 
|---|
| 76 | ~BAO(); | 
|---|
| 77 |  | 
|---|
| 78 | void ISGetProperties (const char *dev); | 
|---|
| 79 | void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n); | 
|---|
| 80 | void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n); | 
|---|
| 81 | void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n); | 
|---|
| 82 | void ISPoll (); | 
|---|
| 83 | void InitThread(); | 
|---|
| 84 |  | 
|---|
| 85 | bool COMMANDE(int numsocket, char* Commande, char* Params); | 
|---|
| 86 | Position ExtractPosition(std::string str); | 
|---|
| 87 |  | 
|---|
| 88 | void connection_lost(); | 
|---|
| 89 | void connection_resumed(); | 
|---|
| 90 |  | 
|---|
| 91 | bool STATUS(int numsocket); | 
|---|
| 92 | bool POSITION(int numsocket); | 
|---|
| 93 | bool ABORT(int numsocket); | 
|---|
| 94 | bool PARK(int numsocket); | 
|---|
| 95 | bool GOTO(int numsocket, int deltaAz, int deltaAlt); | 
|---|
| 96 | void ADDEC2Motor(double newRA, double newDEC); | 
|---|
| 97 | int  AntennesConnectees(); | 
|---|
| 98 | void InitAntennes(); | 
|---|
| 99 |  | 
|---|
| 100 |  | 
|---|
| 101 |  | 
|---|
| 102 | private: | 
|---|
| 103 |  | 
|---|
| 104 | enum BAO_STATUS { BAO_TRANSIT, BAO_TRACKING, BAO_PARK }; | 
|---|
| 105 |  | 
|---|
| 106 | /* Switches */ | 
|---|
| 107 | ISwitch ConnectS[2]; | 
|---|
| 108 | ISwitch OnCoordSetS[2]; | 
|---|
| 109 | ISwitch AbortSlewS[1]; | 
|---|
| 110 | ISwitch ParkS[1]; | 
|---|
| 111 |  | 
|---|
| 112 | /* Texts */ | 
|---|
| 113 | IText PortT[1]; | 
|---|
| 114 | IText ObjectT[1]; | 
|---|
| 115 |  | 
|---|
| 116 | /* Numbers */ | 
|---|
| 117 | //INumber EquatorialCoordsRN[2]; | 
|---|
| 118 | INumber EquatorialCoordsWN[2]; | 
|---|
| 119 | INumber GeographicCoordsWN[2]; | 
|---|
| 120 | INumber ActualisationN1[1]; | 
|---|
| 121 | INumber ActualisationN2[1]; | 
|---|
| 122 |  | 
|---|
| 123 | //INumber SlewAccuracyN[2]; | 
|---|
| 124 | //INumber TrackAccuracyN[2]; | 
|---|
| 125 |  | 
|---|
| 126 | /* Switch Vectors */ | 
|---|
| 127 | ISwitchVectorProperty ConnectSP; | 
|---|
| 128 | ISwitchVectorProperty OnCoordSetSP; | 
|---|
| 129 | ISwitchVectorProperty AbortSlewSP; | 
|---|
| 130 | ISwitchVectorProperty ParkSP; | 
|---|
| 131 |  | 
|---|
| 132 | /* Number Vectors */ | 
|---|
| 133 | //INumberVectorProperty EquatorialCoordsRNP; | 
|---|
| 134 | INumberVectorProperty EquatorialCoordsWNP; | 
|---|
| 135 | INumberVectorProperty GeographicCoordsWNP; | 
|---|
| 136 | //INumberVectorProperty SlewAccuracyNP; | 
|---|
| 137 | //INumberVectorProperty TrackAccuracyNP; | 
|---|
| 138 | INumberVectorProperty ActualisationNP1; | 
|---|
| 139 | INumberVectorProperty ActualisationNP2; | 
|---|
| 140 |  | 
|---|
| 141 |  | 
|---|
| 142 | /* Text Vectors */ | 
|---|
| 143 | ITextVectorProperty PortTP; | 
|---|
| 144 | ITextVectorProperty ObjectTP; | 
|---|
| 145 |  | 
|---|
| 146 | /*******************************************************/ | 
|---|
| 147 | /* Connection Routines | 
|---|
| 148 | ********************************************************/ | 
|---|
| 149 | void init_properties(); | 
|---|
| 150 | void get_initial_data(); | 
|---|
| 151 | void connect_telescope(); | 
|---|
| 152 | bool is_connected(void); | 
|---|
| 153 |  | 
|---|
| 154 | /*******************************************************/ | 
|---|
| 155 | /* Misc routines | 
|---|
| 156 | ********************************************************/ | 
|---|
| 157 | bool process_coords(); | 
|---|
| 158 | int get_switch_index(ISwitchVectorProperty *sp); | 
|---|
| 159 |  | 
|---|
| 160 | /*******************************************************/ | 
|---|
| 161 | /* Simulation Routines | 
|---|
| 162 | ********************************************************/ | 
|---|
| 163 | void enable_simulation(bool enable); | 
|---|
| 164 |  | 
|---|
| 165 | /*******************************************************/ | 
|---|
| 166 | /* Error handling routines | 
|---|
| 167 | ********************************************************/ | 
|---|
| 168 | void slew_error(int slewCode); | 
|---|
| 169 | void reset_all_properties(); | 
|---|
| 170 | void handle_error(INumberVectorProperty *nvp, int err, const char *msg); | 
|---|
| 171 | void correct_fault(); | 
|---|
| 172 |  | 
|---|
| 173 | protected: | 
|---|
| 174 |  | 
|---|
| 175 | double JD;                          /* Julian Date */ | 
|---|
| 176 | double lastRA; | 
|---|
| 177 | double lastDEC; | 
|---|
| 178 | double JJAnc;                       // Sauvegarde du jour julien de la derniÚre actualisation de la position (fct Goto) | 
|---|
| 179 | double ActualisationTM1; | 
|---|
| 180 | double ActualisationTM2; | 
|---|
| 181 | bool   simulation; | 
|---|
| 182 | bool   fault; | 
|---|
| 183 | bool   LecturePosition;             // étape dans le processus d'actualisation de la position | 
|---|
| 184 | bool   Abort; | 
|---|
| 185 | bool   Park; | 
|---|
| 186 | bool   Goto; | 
|---|
| 187 | bool   BAOConnected; | 
|---|
| 188 | bool   LastGotoOK; | 
|---|
| 189 |  | 
|---|
| 190 | int    fd;                          /* Telescope tty file descriptor */ | 
|---|
| 191 | int    currentSet; | 
|---|
| 192 | int    lastSet; | 
|---|
| 193 | int    TrackingMode;                //1 : Transit           2: Tracking | 
|---|
| 194 |  | 
|---|
| 195 | Position TargetPosition;            //Position à atteindre en coordonnées équatoriales | 
|---|
| 196 | }; | 
|---|
| 197 |  | 
|---|
| 198 | #endif | 
|---|