File: AlignmentSubsystemForDrivers.cpp

package info (click to toggle)
indi 2.1.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 15,888 kB
  • sloc: cpp: 217,447; ansic: 31,363; xml: 1,195; sh: 311; makefile: 13
file content (247 lines) | stat: -rw-r--r-- 7,156 bytes parent folder | download | duplicates (4)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*!
 * \file AlignmentSubsystemForDrivers.cpp
 *
 * \author Roger James
 * \date 13th November 2013
 *
 */

#include "AlignmentSubsystemForDrivers.h"

namespace INDI
{
namespace AlignmentSubsystem
{
AlignmentSubsystemForDrivers::AlignmentSubsystemForDrivers()
{
    // Set up the in memory database pointer for math plugins
    SetCurrentInMemoryDatabase(this);
    // Tell the built in math plugin about it
    Initialise(this);
    // Fix up the database load callback
    SetLoadDatabaseCallback(&MyDatabaseLoadCallback, this);
}

// Public methods

void AlignmentSubsystemForDrivers::InitAlignmentProperties(Telescope *pTelescope)
{
    MapPropertiesToInMemoryDatabase::InitProperties(pTelescope);
    MathPluginManagement::InitProperties(pTelescope);
}

void AlignmentSubsystemForDrivers::ProcessAlignmentBLOBProperties(Telescope *pTelescope, const char *name, int sizes[],
        int blobsizes[], char *blobs[], char *formats[],
        char *names[], int n)
{
    MapPropertiesToInMemoryDatabase::ProcessBlobProperties(pTelescope, name, sizes, blobsizes, blobs, formats, names,
            n);
}

void AlignmentSubsystemForDrivers::ProcessAlignmentNumberProperties(Telescope *pTelescope, const char *name,
        double values[], char *names[], int n)
{
    MapPropertiesToInMemoryDatabase::ProcessNumberProperties(pTelescope, name, values, names, n);
}

void AlignmentSubsystemForDrivers::ProcessAlignmentSwitchProperties(Telescope *pTelescope, const char *name,
        ISState *states, char *names[], int n)
{
    MapPropertiesToInMemoryDatabase::ProcessSwitchProperties(pTelescope, name, states, names, n);
    MathPluginManagement::ProcessSwitchProperties(pTelescope, name, states, names, n);
}

void AlignmentSubsystemForDrivers::ProcessAlignmentTextProperties(Telescope *pTelescope, const char *name,
        char *texts[], char *names[], int n)
{
    MathPluginManagement::ProcessTextProperties(pTelescope, name, texts, names, n);
}

void AlignmentSubsystemForDrivers::SaveAlignmentConfigProperties(FILE *fp)
{
    MathPluginManagement::SaveConfigProperties(fp);
}

// Helper methods

bool AlignmentSubsystemForDrivers::AddAlignmentEntryEquatorial(double actualRA, double actualDec, double mountRA,
        double mountDec)
{
    IGeographicCoordinates location;
    if (!GetDatabaseReferencePosition(location))
    {
        return false;
    }

    INDI::IEquatorialCoordinates RaDec {mountRA, mountDec};
    AlignmentDatabaseEntry NewEntry;
    TelescopeDirectionVector TDV = TelescopeDirectionVectorFromEquatorialCoordinates(RaDec);

    NewEntry.ObservationJulianDate = ln_get_julian_from_sys();
    NewEntry.RightAscension = actualRA;
    NewEntry.Declination = actualDec;
    NewEntry.TelescopeDirection = TDV;
    NewEntry.PrivateDataSize = 0;

    if (!CheckForDuplicateSyncPoint(NewEntry))
    {
        GetAlignmentDatabase().push_back(NewEntry);
        UpdateSize();

        // tell the math plugin about the new alignment point
        Initialise(this);

        return true;
    }

    return false;
}

bool AlignmentSubsystemForDrivers::SkyToTelescopeEquatorial(double actualRA, double actualDec, double &mountRA,
        double &mountDec)
{
    INDI::IEquatorialCoordinates eq{0, 0};
    TelescopeDirectionVector TDV;
    IGeographicCoordinates location;

    // by default, just return what we were given
    mountRA = actualRA;
    mountDec = actualDec;

    if (!GetDatabaseReferencePosition(location))
    {
        return false;
    }

    if (GetAlignmentDatabase().size() > 1)
    {
        if (TransformCelestialToTelescope(actualRA, actualDec, 0.0, TDV))
        {
            EquatorialCoordinatesFromTelescopeDirectionVector(TDV, eq);
            //  and now we have to convert from lha back to RA
            mountRA = eq.rightascension;
            mountDec = eq.declination;
            return true;
        }
    }

    return false;
}

bool AlignmentSubsystemForDrivers::TelescopeEquatorialToSky(double mountRA, double mountDec, double &actualRA,
        double &actualDec)
{
    INDI::IEquatorialCoordinates eq{0, 0};
    IGeographicCoordinates location;

    // by default, just return what we were given
    actualRA = mountRA;
    actualDec = mountDec;

    if (!GetDatabaseReferencePosition(location))
    {
        return false;
    }

    if (GetAlignmentDatabase().size() > 1)
    {
        TelescopeDirectionVector TDV;
        eq.rightascension = mountRA;
        eq.declination = mountDec;

        TDV = TelescopeDirectionVectorFromEquatorialCoordinates(eq);
        return TransformTelescopeToCelestial(TDV, actualRA, actualDec);
    }

    return false;
}

bool AlignmentSubsystemForDrivers::AddAlignmentEntryAltAz(double actualRA, double actualDec, double mountAlt,
        double mountAz)
{
    IGeographicCoordinates location;
    if (!GetDatabaseReferencePosition(location))
    {
        return false;
    }

    INDI::IHorizontalCoordinates AltAz {range360(mountAz), range360(mountAlt)};
    AlignmentDatabaseEntry NewEntry;
    TelescopeDirectionVector TDV = TelescopeDirectionVectorFromAltitudeAzimuth(AltAz);

    NewEntry.ObservationJulianDate = ln_get_julian_from_sys();
    NewEntry.RightAscension = actualRA;
    NewEntry.Declination = actualDec;
    NewEntry.TelescopeDirection = TDV;
    NewEntry.PrivateDataSize = 0;

    if (!CheckForDuplicateSyncPoint(NewEntry))
    {
        GetAlignmentDatabase().push_back(NewEntry);
        UpdateSize();

        // tell the math plugin about the new alignment point
        Initialise(this);

        return true;
    }

    return false;
}

bool AlignmentSubsystemForDrivers::SkyToTelescopeAltAz(double actualRA, double actualDec, double &mountAlt, double &mountAz)
{
    INDI::IHorizontalCoordinates altAz{0, 0};
    TelescopeDirectionVector TDV;
    IGeographicCoordinates location;

    if (!GetDatabaseReferencePosition(location))
    {
        return false;
    }

    if (GetAlignmentDatabase().size() > 1)
    {
        if (TransformCelestialToTelescope(actualRA, actualDec, 0.0, TDV))
        {
            AltitudeAzimuthFromTelescopeDirectionVector(TDV, altAz);
            mountAz = range360(altAz.azimuth);
            mountAlt = range360(altAz.altitude);
            return true;
        }
    }

    return false;
}

bool AlignmentSubsystemForDrivers::TelescopeAltAzToSky(double mountAlt, double mountAz, double &actualRa, double &actualDec)
{
    INDI::IHorizontalCoordinates altaz{0, 0};
    IGeographicCoordinates location;

    if (!GetDatabaseReferencePosition(location))
    {
        return false;
    }

    if (GetAlignmentDatabase().size() > 1)
    {
        TelescopeDirectionVector TDV;
        altaz.azimuth  = range360(mountAz);
        altaz.altitude = range360(mountAlt);
        TDV = TelescopeDirectionVectorFromAltitudeAzimuth(altaz);
        return TransformTelescopeToCelestial(TDV, actualRa, actualDec);
    }

    return false;
}

// Private methods

void AlignmentSubsystemForDrivers::MyDatabaseLoadCallback(void *ThisPointer)
{
    ((AlignmentSubsystemForDrivers *)ThisPointer)->Initialise((AlignmentSubsystemForDrivers *)ThisPointer);
}

} // namespace AlignmentSubsystem
} // namespace INDI