~mutlaqja/indi-maxdomeii/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
    MaxDome II 
    Copyright (C) 2009 Ferran Casarramona (ferran.casarramona@gmail.com)

    Migrated to INDI::Dome by Jasem Mutlaq (2014)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/

#ifndef MAXDOMEII_H
#define MAXDOMEII_H

#include <indidevapi.h>
#include <indicom.h>
#include <indidome.h>

#define MD_AZIMUTH_IDLE 0
#define MD_AZIMUTH_MOVING 1
#define MD_AZIMUTH_HOMING 2

class MaxDomeII : public INDI::Dome
{
 public:
 MaxDomeII();
 ~MaxDomeII();

 const char *getDefaultName();
 bool initProperties();
 bool updateProperties();
 virtual bool saveConfigItems(FILE *fp);

 bool Connect();
 bool Disconnect();

 void TimerHit();

 virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
 virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);

 virtual IPState MoveAbs(double az);
 //virtual IPState Home();
 virtual bool Abort();

protected:

 // Parking
 IPState ConfigurePark(int nCSBP, double ParkAzimuth);
 virtual void SetCurrentPark();
 virtual void SetDefaultPark();
 virtual IPState ControlShutter(ShutterOperation operation);

 /*******************************************************/
 /* Misc routines
 ********************************************************/
 int AzimuthDistance(int nPos1, int nPos2);
 double TicksToAzimuth(int nTicks);
 int AzimuthToTicks(double nAzimuth);
 int handle_driver_error(int *error, int *nRetry); // Handles errors returned by driver

 ISwitch ShutterModeS[2];
 ISwitchVectorProperty ShutterModeSP;

 INumber ShutterOperationAzimuthN[1];
 INumberVectorProperty ShutterOperationAzimuthNP;
 
 ISwitch ShutterConflictS[2];
 ISwitchVectorProperty ShutterConflictSP;
 
 ISwitch HomeS[1];
 ISwitchVectorProperty HomeSP;

 INumber TicksPerTurnN[1];
 INumberVectorProperty TicksPerTurnNP;

 INumber WatchDogN[1];
 INumberVectorProperty WatchDogNP;

 INumber HomeAzimuthN[1];
 INumberVectorProperty HomeAzimuthNP;
 
 INumber HomePosRN[1];
 INumberVectorProperty HomePosRNP;

private:

 int nTicksPerTurn;             // Number of ticks per turn of azimuth dome
 unsigned nCurrentTicks;        // Position as reported by the MaxDome II
 int nCloseShutterBeforePark;   // 0 no close shutter
 double nParkPosition;		// Park position
 double nHomeAzimuth;		// Azimuth of home position
 int nHomeTicks;		// Ticks from 0 azimuth to home
 int fd;                        // Telescope tty file descriptor
 int nTimeSinceShutterStart;	// Timer since shutter movement has started, in order to check timeouts
 int nTimeSinceAzimuthStart;	// Timer since azimuth movement has started, in order to check timeouts
 int nTargetAzimuth;
 int nTimeSinceLastCommunication;  // Used by Watch Dog

 double prev_az, prev_alt;

 bool SetupParms();


};

#endif