Instrument Neutral Distributed Interface INDI  2.0.2
indispectrograph.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 "indispectrograph.h"
22 
23 #include "indicom.h"
24 #include "stream/streammanager.h"
25 #include "locale_compat.h"
26 
27 #include <fitsio.h>
28 
29 #include <libnova/julian_day.h>
30 #include <libnova/ln_types.h>
31 #include <libnova/precession.h>
32 
33 #include <regex>
34 
35 #include <dirent.h>
36 #include <cerrno>
37 #include <locale.h>
38 #include <cstdlib>
39 #include <zlib.h>
40 #include <sys/stat.h>
41 
42 namespace INDI
43 {
44 
46 {
47 }
48 
50 {
51 }
52 
54 {
55  // PrimarySpectrograph Info
56  IUFillNumber(&SpectrographSettingsN[SPECTROGRAPH_BITSPERSAMPLE], "SPECTROGRAPH_BITSPERSAMPLE", "Bits per sample", "%3.0f",
57  -64, 64, 8, 8);
58  IUFillNumber(&SpectrographSettingsN[SPECTROGRAPH_LOWFREQ], "SPECTROGRAPH_LOW_CUT_FREQUENCY", "Low cut frequency (Hz)",
59  "%16.2f", 0.01, 1.0e+8, 0.01, 1.0e+3);
60  IUFillNumber(&SpectrographSettingsN[SPECTROGRAPH_HIGHFREQ], "SPECTROGRAPH_HIGH_CUT_FREQUENCY", "High cut frequency (Hz)",
61  "%16.2f", 0.01, 1.0e+8, 0.01, 1.0e+3);
62  IUFillNumber(&SpectrographSettingsN[SPECTROGRAPH_GAIN], "SPECTROGRAPH_GAIN", "Gain", "%3.2f", 0.01, 255.0, 0.01, 1.0);
63  IUFillNumber(&SpectrographSettingsN[SPECTROGRAPH_ANTENNA], "SPECTROGRAPH_ANTENNA", "Antenna", "%16.2f", 1, 4, 1, 1);
65  "Spectrograph Settings", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
66 
68 
70 }
71 
72 void Spectrograph::ISGetProperties(const char *dev)
73 {
74  processProperties(dev);
75 }
76 
78 {
79  if (isConnected())
80  {
82 
83  if (HasCooler())
85  }
86  else
87  {
89 
90  if (HasCooler())
92  }
94 }
95 
97 {
98  return processSnoopDevice(root);
99 }
100 
101 bool Spectrograph::ISNewText(const char *dev, const char *name, char *values[], char *names[], int n)
102 {
103  return processText(dev, name, values, names, n);
104 }
105 
106 bool Spectrograph::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
107 {
108  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, SpectrographSettingsNP.name))
109  {
111  }
112  return processNumber(dev, name, values, names, n);
113 }
114 
115 bool Spectrograph::ISNewSwitch(const char *dev, const char *name, ISState *values, char *names[], int n)
116 {
117  return processSwitch(dev, name, values, names, n);
118 }
119 
120 bool Spectrograph::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
121  char *formats[], char *names[], int n)
122 {
123  return processBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
124 }
125 
127 {
128  LowCutFrequency = freq;
129 
131 
133 }
134 
136 {
137  HighCutFrequency = freq;
138 
140 
142 }
143 
144 void Spectrograph::setGain(double gain)
145 {
146  Gain = gain;
147 
149 
151 }
152 
154 {
155  SetCapability(cap);
157 }
158 
159 bool Spectrograph::StartIntegration(double duration)
160 {
161  INDI_UNUSED(duration);
162  DEBUGF(Logger::DBG_WARNING, "Spectrograph::StartIntegration %4.2f - Should never get here", duration);
163  return false;
164 }
165 
166 void Spectrograph::setMinMaxStep(const char *property, const char *element, double min, double max, double step,
167  bool sendToClient)
168 {
169  INDI::SensorInterface::setMinMaxStep(property, element, min, max, step, sendToClient);
170  INumberVectorProperty *nvp = nullptr;
171 
172  if (!strcmp(property, SpectrographSettingsNP.name))
173  nvp = &SpectrographSettingsNP;
174  else
175  return;
176 
177  INumber *np = IUFindNumber(nvp, element);
178  if (np)
179  {
180  np->min = min;
181  np->max = max;
182  np->step = step;
183 
184  if (sendToClient)
185  IUUpdateMinMax(nvp);
186  }
187 }
188 
189 void Spectrograph::addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len)
190 {
191  char fitsString[MAXINDILABEL];
192  int status = 0;
193 
194  // SPECTROGRAPH
195  sprintf(fitsString, "%d", getBPS());
196  fits_update_key_s(fptr, TSTRING, "BPS", fitsString, "Bits per sample", &status);
197 
198  sprintf(fitsString, "%lf", getHighCutFrequency() - getLowCutFrequency());
199  fits_update_key_s(fptr, TSTRING, "BANDWIDT", fitsString, "Bandwidth", &status);
200 
201  sprintf(fitsString, "%lf", getLowCutFrequency() + (getHighCutFrequency() - getLowCutFrequency()) / 2.0);
202  fits_update_key_s(fptr, TSTRING, "FREQ", fitsString, "Center Frequency", &status);
203 
204  sprintf(fitsString, "%lf", getGain());
205  fits_update_key_s(fptr, TSTRING, "GAIN", fitsString, "Gain", &status);
206 
207  SensorInterface::addFITSKeywords(fptr, buf, len);
208 }
209 }
bool isConnected() const
Definition: basedevice.cpp:520
const char * getDeviceName() const
Definition: basedevice.cpp:821
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
virtual void addFITSKeywords(fitsfile *fptr, uint8_t *buf, int len)
Add FITS keywords to a fits file.
bool processBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
INumberVectorProperty TemperatureNP
void fits_update_key_s(fitsfile *fptr, int type, std::string name, void *p, std::string explanation, int *status)
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)
int getBPS() const
getBPS Get Sensor depth (bits per sample).
double getGain()
getGain Get requested integration gain for the sensor.
virtual bool StartIntegration(double duration) override
Start integration from the Sensor device.
void setLowCutFrequency(double freq)
setLowCutFrequency Set low cut frequency of Spectrograph device.
double getHighCutFrequency()
getHighCutFrequency Get requested high cut frequency in Hz.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void SetSpectrographCapability(uint32_t cap)
SetSpectrographCapability Set the Spectrograph capabilities. Al fields must be initialized.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual 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 setGain(double gain)
setGain Set gain of Spectrograph device.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
INumber SpectrographSettingsN[8]
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual void addFITSKeywords(fitsfile *fptr, uint8_t *buf, int len) override
Add FITS keywords to a fits file.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
INumberVectorProperty SpectrographSettingsNP
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void setHighCutFrequency(double freq)
setHighCutFrequency Set high cut frequency of Spectrograph device.
double getLowCutFrequency()
getLowCutFrequency Get requested low cut frequency in Hz.
virtual void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true) override
setMinMaxStep for a number property element
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
#define MAXINDILABEL
Definition: indiapi.h:192
Implementations for common driver routines.
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