Instrument Neutral Distributed Interface INDI  1.9.5
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", 1.0e-12, 1.0e+6, 1.0e-12, 10.0);
57  IUFillNumber(&CorrelatorSettingsN[CORRELATOR_BASELINE_X], "CORRELATOR_BASELINE_Y", "Baseline Y size (m)", "%16.12f", 1.0e-12, 1.0e+6, 1.0e-12, 10.0);
58  IUFillNumber(&CorrelatorSettingsN[CORRELATOR_BASELINE_X], "CORRELATOR_BASELINE_Z", "Baseline Z size (m)", "%16.12f", 1.0e-12, 1.0e+6, 1.0e-12, 10.0);
59  IUFillNumber(&CorrelatorSettingsN[CORRELATOR_WAVELENGTH], "CORRELATOR_WAVELENGTH", "Wavelength (m)", "%7.12f", 3.0e-12, 3.0e+6, 3.0e-12, 350.0e-9);
60  IUFillNumber(&CorrelatorSettingsN[CORRELATOR_BANDWIDTH], "CORRELATOR_BANDWIDTH", "Bandwidth (Hz)", "%12.0f", 1.0, 100.0e+9, 1.0, 1.42e+9);
61  IUFillNumberVector(&CorrelatorSettingsNP, CorrelatorSettingsN, 5, getDeviceName(), "CORRELATOR_SETTINGS", "Correlator Settings", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
62 
64 
66 }
67 
68 void Correlator::ISGetProperties(const char *dev)
69 {
70  return processProperties(dev);
71 }
72 
74 {
75  if (isConnected())
76  {
78 
79  if (HasCooler())
81  }
82  else
83  {
85 
86  if (HasCooler())
88  }
90 }
91 
93 {
94  return processSnoopDevice(root);
95 }
96 
97 bool Correlator::ISNewText(const char *dev, const char *name, char *values[], char *names[], int n)
98 {
99  return processText(dev, name, values, names, n);
100 }
101 
102 bool Correlator::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
103 {
104  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, CorrelatorSettingsNP.name)) {
106  }
107  return processNumber(dev, name, values, names, n);
108 }
109 
110 bool Correlator::ISNewSwitch(const char *dev, const char *name, ISState *values, char *names[], int n)
111 {
112  return processSwitch(dev, name, values, names, n);
113 }
114 
115 bool Correlator::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
116  char *formats[], char *names[], int n)
117 {
118  return processBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
119 }
120 
121 void Correlator::setBaseline(Baseline bl)
122 {
123  baseline = bl;
124 
125  CorrelatorSettingsN[Correlator::CORRELATOR_BASELINE_X].value = baseline.x;
126  CorrelatorSettingsN[Correlator::CORRELATOR_BASELINE_Y].value = baseline.y;
127  CorrelatorSettingsN[Correlator::CORRELATOR_BASELINE_Z].value = baseline.z;
128 
130 }
131 
133 {
134  wavelength = wl;
135 
136  CorrelatorSettingsN[Correlator::CORRELATOR_WAVELENGTH].value = wl;
137 
139 }
140 
141 void Correlator::setBandwidth(double bw)
142 {
143  bandwidth = bw;
144 
145  CorrelatorSettingsN[Correlator::CORRELATOR_BANDWIDTH].value = bw;
146 
148 }
149 
150 void Correlator::SetCorrelatorCapability(uint32_t cap)
151 {
152  SetCapability(cap);
154 }
155 
157 {
159  double lst = get_local_sidereal_time(Longitude);
160  double ha = get_local_hour_angle(lst, RA);
161  baseline_2d_projection(Dec, ha*15, baseline.values, wavelength, ret.values);
162  return ret;
163 }
164 
166 {
168  double ha = get_local_hour_angle(lst, RA);
169  baseline_2d_projection(Dec, ha*15, baseline.values, wavelength, ret.values);
170  return ret;
171 }
172 
174 {
175  UVCoordinate ret;
176  baseline_2d_projection(alt, az, baseline.values, wavelength, ret.values);
177  return ret;
178 }
179 
180 double Correlator::getDelay()
181 {
183  double ha = get_local_hour_angle(lst, RA);
184  return baseline_delay(Dec, ha*15, baseline.values);
185 }
186 
187 double Correlator::getDelay(double lst)
188 {
189  double ha = get_local_hour_angle(lst, RA);
190  return baseline_delay(Dec, ha*15, baseline.values);
191 }
192 
193 double Correlator::getDelay(double alt, double az)
194 {
195  return baseline_delay(alt, az, baseline.values);
196 }
197 
198 bool Correlator::StartIntegration(double duration)
199 {
200  INDI_UNUSED(duration);
201  DEBUGF(Logger::DBG_WARNING, "Correlator::StartIntegration %4.2f - Not supported", duration);
202  return false;
203 }
204 
205 void Correlator::setMinMaxStep(const char *property, const char *element, double min, double max, double step,
206  bool sendToClient)
207 {
208  INumberVectorProperty *vp = nullptr;
209 
210  if (!strcmp(property, CorrelatorSettingsNP.name)) {
211  vp = &FramedIntegrationNP;
212 
213  INumber *np = IUFindNumber(vp, element);
214  if (np)
215  {
216  np->min = min;
217  np->max = max;
218  np->step = step;
219 
220  if (sendToClient)
221  IUUpdateMinMax(vp);
222  }
223  }
224  INDI::SensorInterface::setMinMaxStep(property, element, min, max, step, sendToClient);
225 }
226 }
227 
INDI::SensorInterface::updateProperties
bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: indisensorinterface.cpp:104
INDI::Correlator::ISNewNumber
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: indicorrelator.cpp:119
INDI::SensorInterface::TemperatureNP
INumberVectorProperty TemperatureNP
Definition: indisensorinterface.h:503
INDI::Correlator::getDelay
double getDelay()
getDelay Get current baseline delay with reference to the current sidereal time.
Definition: indicorrelator.cpp:197
IUUpdateMinMax
void IUUpdateMinMax(const INumberVectorProperty *nvp)
Function to update the min and max elements of a number in the client.
Definition: indidriver.c:1850
INDI::Correlator::Baseline::z
double z
Definition: indicorrelator.h:73
INDI::Correlator::initProperties
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: indicorrelator.cpp:70
INDI::Correlator::CORRELATOR_BASELINE_Y
@ CORRELATOR_BASELINE_Y
Definition: indicorrelator.h:255
INDI::Correlator::ISSnoopDevice
bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: indicorrelator.cpp:109
min
double min(void)
get_local_hour_angle
double get_local_hour_angle(double sideral_time, double ra)
get_local_hour_angle Returns local hour angle of an object
Definition: indicom.c:1543
INDI::Correlator::ISNewSwitch
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: indicorrelator.cpp:127
indicom.h
Implementations for common driver routines.
locale_compat.h
INDI::Logger::DBG_WARNING
@ DBG_WARNING
Definition: indilogger.h:193
INumber
One number descriptor.
IUFillNumber
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: indidriver.c:348
INDI::DefaultDevice::defineProperty
void defineProperty(INumberVectorProperty *property)
Definition: defaultdevice.cpp:997
INDI::Correlator::~Correlator
virtual ~Correlator()
Definition: indicorrelator.cpp:66
MAIN_CONTROL_TAB
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
Definition: defaultdevice.cpp:34
INDI::Correlator::Correlator
Correlator()
Definition: indicorrelator.cpp:61
INDI_UNUSED
#define INDI_UNUSED(x)
Definition: indidevapi.h:799
INDI::SensorInterface::processBLOB
bool processBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Definition: indisensorinterface.cpp:389
INDI::BaseDevice::getDeviceName
const char * getDeviceName() const
Definition: basedevice.cpp:799
INDI::Correlator::ISNewBLOB
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.
Definition: indicorrelator.cpp:132
INDI::SensorInterface::processText
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Definition: indisensorinterface.cpp:194
INDI::Correlator::Baseline::y
double y
Definition: indicorrelator.h:72
INDI::SensorInterface::setIntegrationFileExtension
void setIntegrationFileExtension(const char *ext)
setIntegrationExtension Set integration exntension
Definition: indisensorinterface.cpp:624
INDI::SensorInterface::processSwitch
bool processSwitch(const char *dev, const char *name, ISState states[], char *names[], int n)
Definition: indisensorinterface.cpp:318
INDI::SensorInterface::RA
double RA
Definition: indisensorinterface.h:477
INDI::Correlator::UVCoordinate
Definition: indicorrelator.h:82
max
double max(void)
INDI::Correlator::StartIntegration
virtual bool StartIntegration(double duration) override
Start integration from the Sensor device.
Definition: indicorrelator.cpp:215
INDI::Correlator::CORRELATOR_BASELINE_X
@ CORRELATOR_BASELINE_X
Definition: indicorrelator.h:254
INDI::Correlator::updateProperties
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: indicorrelator.cpp:90
INDI::Correlator::setBaseline
void setBaseline(Baseline bl)
setBaseline Set the baseline size in meters.
Definition: indicorrelator.cpp:138
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
INDI::Correlator::UVCoordinate::values
double values[2]
Definition: indicorrelator.h:87
INDI::Correlator::ISGetProperties
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition: indicorrelator.cpp:85
indicorrelator.h
INDI::DefaultDevice::getDriverInterface
virtual uint16_t getDriverInterface() override
Definition: defaultdevice.cpp:896
INDI::Correlator::Baseline::x
double x
Definition: indicorrelator.h:71
INDI::SensorInterface::setMinMaxStep
void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true)
setMinMaxStep for a number property element
Definition: indisensorinterface.cpp:529
INDI::Correlator::ISNewText
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: indicorrelator.cpp:114
IUFillNumberVector
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: indidriver.c:455
INDI::SensorInterface::initProperties
bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
Definition: indisensorinterface.cpp:398
IPS_IDLE
@ IPS_IDLE
Definition: indiapi.h:160
xml_ele_
Definition: lilxml.c:105
_INumberVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:322
INDI::Correlator::CORRELATOR_WAVELENGTH
@ CORRELATOR_WAVELENGTH
Definition: indicorrelator.h:257
defaultdevice.h
INDI::SensorInterface::FramedIntegrationNP
INumberVectorProperty FramedIntegrationNP
Definition: indisensorinterface.h:420
INDI::BaseDevice::isConnected
bool isConnected() const
Definition: basedevice.cpp:518
IUFindNumber
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
Definition: indicom.c:1372
INDI::SensorInterface::processNumber
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Definition: indisensorinterface.cpp:250
get_local_sidereal_time
double get_local_sidereal_time(double longitude)
get_local_sidereal_time Returns local sideral time given longitude and system clock.
INDI::SensorInterface::Dec
double Dec
Definition: indisensorinterface.h:477
INDI::Correlator::CORRELATOR_BASELINE_Z
@ CORRELATOR_BASELINE_Z
Definition: indicorrelator.h:256
baseline_2d_projection
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:1658
INDI::SensorInterface::HasCooler
bool HasCooler() const
Definition: indisensorinterface.h:351
name
const char * name
Definition: indiserver.c:116
baseline_delay
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:1668
INDI::SensorInterface::Longitude
double Longitude
Definition: indisensorinterface.h:481
INDI::SensorInterface::processProperties
void processProperties(const char *dev)
Definition: indisensorinterface.cpp:155
INDI::Correlator::getUVCoordinates
UVCoordinate getUVCoordinates()
getUVCoordinates Get current UV projected coordinates with reference to the current sidereal time.
Definition: indicorrelator.cpp:173
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::Correlator::CorrelatorSettingsNP
INumberVectorProperty CorrelatorSettingsNP
Definition: indicorrelator.h:260
DEBUGF
#define DEBUGF(priority, msg,...)
Definition: indilogger.h:57
IP_RW
@ IP_RW
Definition: indiapi.h:185
INDI::Correlator::CORRELATOR_BANDWIDTH
@ CORRELATOR_BANDWIDTH
Definition: indicorrelator.h:258
INDI::Correlator::Baseline::values
double values[3]
Definition: indicorrelator.h:75
INDI::SensorInterface::processSnoopDevice
bool processSnoopDevice(XMLEle *root)
Definition: indisensorinterface.cpp:169
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::Correlator::setMinMaxStep
void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient)
setMinMaxStep for a number property element
Definition: indicorrelator.cpp:222
INDI::Correlator::SetCorrelatorCapability
void SetCorrelatorCapability(uint32_t cap)
SetCorrelatorCapability Set the Correlator capabilities. Al fields must be initilized.
Definition: indicorrelator.cpp:167
INDI::SensorInterface::SetCapability
void SetCapability(uint32_t cap)
SetCapability Set the Sensor capabilities. Al fields must be initilized.
Definition: indisensorinterface.cpp:519
INDI::DefaultDevice::deleteProperty
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
Definition: defaultdevice.cpp:965
INDI::Correlator::setWavelength
void setWavelength(double wl)
setWavelength Set the observed wavelength.
Definition: indicorrelator.cpp:149
IDSetNumber
void void void IDSetNumber(const INumberVectorProperty *n, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing number vector property.
INDI::DefaultDevice::setDriverInterface
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
Definition: defaultdevice.cpp:902
INDI::BaseDevice::SENSOR_INTERFACE
@ SENSOR_INTERFACE
Definition: basedevice.h:89
INDI::Correlator::setBandwidth
double setBandwidth()
setBandwidth Get the bandwidth of the correlator.
Definition: indicorrelator.h:213