Instrument Neutral Distributed Interface INDI  2.0.2
indicorrelator.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2010, 2017 Ilia Platone, Jasem Mutlaq. All rights reserved.
3 
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 *******************************************************************************/
19 
20 #include "defaultdevice.h"
21 #include "indicorrelator.h"
22 
23 #include "indicom.h"
24 #include "locale_compat.h"
25 
26 #include <fitsio.h>
27 
28 #include <libnova/julian_day.h>
29 #include <libnova/ln_types.h>
30 #include <libnova/precession.h>
31 
32 #include <regex>
33 
34 #include <dirent.h>
35 #include <cerrno>
36 #include <locale.h>
37 #include <cstdlib>
38 #include <zlib.h>
39 #include <sys/stat.h>
40 
41 namespace INDI
42 {
43 
45 {
47 }
48 
50 {
51 }
52 
54 {
55  // PrimaryCorrelator Info
56  IUFillNumber(&CorrelatorSettingsN[CORRELATOR_BASELINE_X], "CORRELATOR_BASELINE_X", "Baseline X size (m)", "%16.12f",
57  1.0e-12, 1.0e+6, 1.0e-12, 10.0);
58  IUFillNumber(&CorrelatorSettingsN[CORRELATOR_BASELINE_X], "CORRELATOR_BASELINE_Y", "Baseline Y size (m)", "%16.12f",
59  1.0e-12, 1.0e+6, 1.0e-12, 10.0);
60  IUFillNumber(&CorrelatorSettingsN[CORRELATOR_BASELINE_X], "CORRELATOR_BASELINE_Z", "Baseline Z size (m)", "%16.12f",
61  1.0e-12, 1.0e+6, 1.0e-12, 10.0);
62  IUFillNumber(&CorrelatorSettingsN[CORRELATOR_WAVELENGTH], "CORRELATOR_WAVELENGTH", "Wavelength (m)", "%7.12f", 3.0e-12,
63  3.0e+6, 3.0e-12, 350.0e-9);
64  IUFillNumber(&CorrelatorSettingsN[CORRELATOR_BANDWIDTH], "CORRELATOR_BANDWIDTH", "Bandwidth (Hz)", "%12.0f", 1.0, 100.0e+9,
65  1.0, 1.42e+9);
66  IUFillNumberVector(&CorrelatorSettingsNP, CorrelatorSettingsN, 5, getDeviceName(), "CORRELATOR_SETTINGS",
67  "Correlator Settings", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
68 
70 
72 }
73 
74 void Correlator::ISGetProperties(const char *dev)
75 {
76  return processProperties(dev);
77 }
78 
80 {
81  if (isConnected())
82  {
84 
85  if (HasCooler())
87  }
88  else
89  {
91 
92  if (HasCooler())
94  }
96 }
97 
99 {
100  return processSnoopDevice(root);
101 }
102 
103 bool Correlator::ISNewText(const char *dev, const char *name, char *values[], char *names[], int n)
104 {
105  return processText(dev, name, values, names, n);
106 }
107 
108 bool Correlator::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
109 {
110  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, CorrelatorSettingsNP.name))
111  {
113  }
114  return processNumber(dev, name, values, names, n);
115 }
116 
117 bool Correlator::ISNewSwitch(const char *dev, const char *name, ISState *values, char *names[], int n)
118 {
119  return processSwitch(dev, name, values, names, n);
120 }
121 
122 bool Correlator::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
123  char *formats[], char *names[], int n)
124 {
125  return processBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
126 }
127 
129 {
130  baseline = bl;
131 
132  CorrelatorSettingsN[Correlator::CORRELATOR_BASELINE_X].value = baseline.x;
133  CorrelatorSettingsN[Correlator::CORRELATOR_BASELINE_Y].value = baseline.y;
134  CorrelatorSettingsN[Correlator::CORRELATOR_BASELINE_Z].value = baseline.z;
135 
137 }
138 
140 {
141  wavelength = wl;
142 
143  CorrelatorSettingsN[Correlator::CORRELATOR_WAVELENGTH].value = wl;
144 
146 }
147 
149 {
150  bandwidth = bw;
151 
152  CorrelatorSettingsN[Correlator::CORRELATOR_BANDWIDTH].value = bw;
153 
155 }
156 
158 {
159  SetCapability(cap);
161 }
162 
164 {
165  UVCoordinate ret;
166  double lst = get_local_sidereal_time(Longitude);
167  double ha = get_local_hour_angle(lst, RA);
168  baseline_2d_projection(Dec, ha * 15, baseline.values, wavelength, ret.values);
169  return ret;
170 }
171 
173 {
174  UVCoordinate ret;
175  double ha = get_local_hour_angle(lst, RA);
176  baseline_2d_projection(Dec, ha * 15, baseline.values, wavelength, ret.values);
177  return ret;
178 }
179 
181 {
182  UVCoordinate ret;
183  baseline_2d_projection(alt, az, baseline.values, wavelength, ret.values);
184  return ret;
185 }
186 
188 {
189  double lst = get_local_sidereal_time(Longitude);
190  double ha = get_local_hour_angle(lst, RA);
191  return baseline_delay(Dec, ha * 15, baseline.values);
192 }
193 
194 double Correlator::getDelay(double lst)
195 {
196  double ha = get_local_hour_angle(lst, RA);
197  return baseline_delay(Dec, ha * 15, baseline.values);
198 }
199 
200 double Correlator::getDelay(double alt, double az)
201 {
202  return baseline_delay(alt, az, baseline.values);
203 }
204 
205 bool Correlator::StartIntegration(double duration)
206 {
207  INDI_UNUSED(duration);
208  DEBUGF(Logger::DBG_WARNING, "Correlator::StartIntegration %4.2f - Not supported", duration);
209  return false;
210 }
211 
212 void Correlator::setMinMaxStep(const char *property, const char *element, double min, double max, double step,
213  bool sendToClient)
214 {
215  INDI::SensorInterface::setMinMaxStep(property, element, min, max, step, sendToClient);
216  INumberVectorProperty *nvp = nullptr;
217 
218  if (!strcmp(property, CorrelatorSettingsNP.name))
219  nvp = &CorrelatorSettingsNP;
220  else
221  return;
222 
223  INumber *np = IUFindNumber(nvp, element);
224  if (np)
225  {
226  np->min = min;
227  np->max = max;
228  np->step = step;
229 
230  if (sendToClient)
231  IUUpdateMinMax(nvp);
232  }
233 }
234 }
235 
bool isConnected() const
Definition: basedevice.cpp:520
const char * getDeviceName() const
Definition: basedevice.cpp:821
bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override
Process the client newBLOB command.
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
double setBandwidth()
setBandwidth Get the bandwidth of the correlator.
INumberVectorProperty CorrelatorSettingsNP
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
void SetCorrelatorCapability(uint32_t cap)
SetCorrelatorCapability Set the Correlator capabilities. Al fields must be initialized.
virtual bool StartIntegration(double duration) override
Start integration from the Sensor device.
double getDelay()
getDelay Get current baseline delay with reference to the current sidereal time.
virtual void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient) override
setMinMaxStep for a number property element
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void setBaseline(Baseline bl)
setBaseline Set the baseline size in meters.
void setWavelength(double wl)
setWavelength Set the observed wavelength.
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
UVCoordinate getUVCoordinates()
getUVCoordinates Get current UV projected coordinates with reference to the current sidereal time.
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
uint16_t getDriverInterface() const
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
void SetCapability(uint32_t cap)
SetCapability Set the Sensor capabilities. Al fields must be initialized.
bool processSwitch(const char *dev, const char *name, ISState states[], char *names[], int n)
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
virtual void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true)
setMinMaxStep for a number property element
bool processBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
INumberVectorProperty TemperatureNP
void processProperties(const char *dev)
bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
bool processSnoopDevice(XMLEle *root)
void setIntegrationFileExtension(const char *ext)
setIntegrationExtension Set integration exntension
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
double max(void)
double min(void)
ISState
Switch state.
Definition: indiapi.h:150
@ IP_RW
Definition: indiapi.h:186
@ IPS_IDLE
Definition: indiapi.h:161
void baseline_2d_projection(double alt, double az, double baseline[3], double wavelength, double uvresult[2])
baseline_2d_projection Returns the coordinates of the projection of a single baseline targeting the o...
Definition: indicom.c:1408
double baseline_delay(double alt, double az, double baseline[3])
baseline_delay Returns the delay in meters of a single baseline targeting the object by coordinates
Definition: indicom.c:1418
double get_local_hour_angle(double sideral_time, double ra)
get_local_hour_angle Returns local hour angle of an object
Definition: indicom.c:1293
Implementations for common driver routines.
double get_local_sidereal_time(double longitude)
get_local_sidereal_time Returns local sideral time given longitude and system clock.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition: indidevapi.c:272
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
Definition: indidevapi.c:66
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition: indidevapi.c:180
#define INDI_UNUSED(x)
Definition: indidevapi.h:131
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
Definition: indidriver.c:1211
void IUUpdateMinMax(const INumberVectorProperty *nvp)
Function to update the min and max elements of a number in the client.
Definition: indidriver.c:1296
#define DEBUGF(priority, msg,...)
Definition: indilogger.h:57
Namespace to encapsulate INDI client, drivers, and mediator classes.
One number descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
char name[MAXINDINAME]
Definition: indiapi.h:323
the baseline (position of the telescopes) of this correlator.