Instrument Neutral Distributed Interface INDI  1.9.5
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", -64, 64, 8, 8);
57  IUFillNumber(&SpectrographSettingsN[SPECTROGRAPH_LOWFREQ], "SPECTROGRAPH_LOW_CUT_FREQUENCY", "Low cut frequency (Hz)", "%16.2f", 0.01, 1.0e+8, 0.01, 1.0e+3);
58  IUFillNumber(&SpectrographSettingsN[SPECTROGRAPH_HIGHFREQ], "SPECTROGRAPH_HIGH_CUT_FREQUENCY", "High cut frequency (Hz)", "%16.2f", 0.01, 1.0e+8, 0.01, 1.0e+3);
59  IUFillNumber(&SpectrographSettingsN[SPECTROGRAPH_GAIN], "SPECTROGRAPH_GAIN", "Gain", "%3.2f", 0.01, 255.0, 0.01, 1.0);
60  IUFillNumber(&SpectrographSettingsN[SPECTROGRAPH_ANTENNA], "SPECTROGRAPH_ANTENNA", "Antenna", "%16.2f", 1, 4, 1, 1);
61  IUFillNumberVector(&SpectrographSettingsNP, SpectrographSettingsN, 6, getDeviceName(), "SPECTROGRAPH_SETTINGS", "Spectrograph Settings", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
62 
64 
66 }
67 
68 void Spectrograph::ISGetProperties(const char *dev)
69 {
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 Spectrograph::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 Spectrograph::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
103 {
104  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, SpectrographSettingsNP.name)) {
106  }
107  return processNumber(dev, name, values, names, n);
108 }
109 
110 bool Spectrograph::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 Spectrograph::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 Spectrograph::setLowCutFrequency(double freq)
122 {
123  LowCutFrequency = freq;
124 
126 
128 }
129 
130 void Spectrograph::setHighCutFrequency(double freq)
131 {
132  HighCutFrequency = freq;
133 
135 
137 }
138 
139 void Spectrograph::setGain(double gain)
140 {
141  Gain = gain;
142 
144 
146 }
147 
149 {
150  SetCapability(cap);
152 }
153 
154 bool Spectrograph::StartIntegration(double duration)
155 {
156  INDI_UNUSED(duration);
157  DEBUGF(Logger::DBG_WARNING, "Spectrograph::StartIntegration %4.2f - Should never get here", duration);
158  return false;
159 }
160 
161 void Spectrograph::setMinMaxStep(const char *property, const char *element, double min, double max, double step,
162  bool sendToClient)
163 {
164  INumberVectorProperty *vp = nullptr;
165 
166  if (!strcmp(property, SpectrographSettingsNP.name)) {
167  vp = &FramedIntegrationNP;
168 
169  INumber *np = IUFindNumber(vp, element);
170  if (np)
171  {
172  np->min = min;
173  np->max = max;
174  np->step = step;
175 
176  if (sendToClient)
177  IUUpdateMinMax(vp);
178  }
179  }
180  INDI::SensorInterface::setMinMaxStep(property, element, min, max, step, sendToClient);
181 }
182 
183 void Spectrograph::addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len)
184 {
185  char fitsString[MAXINDILABEL];
186  int status = 0;
187 
188  // SPECTROGRAPH
189  sprintf(fitsString, "%d", getBPS());
190  fits_update_key_s(fptr, TSTRING, "BPS", fitsString, "Bits per sample", &status);
191 
192  sprintf(fitsString, "%lf", getHighCutFrequency()-getLowCutFrequency());
193  fits_update_key_s(fptr, TSTRING, "BANDWIDT", fitsString, "Bandwidth", &status);
194 
195  sprintf(fitsString, "%lf", getLowCutFrequency()+(getHighCutFrequency()-getLowCutFrequency())/2.0);
196  fits_update_key_s(fptr, TSTRING, "FREQ", fitsString, "Center Frequency", &status);
197 
198  sprintf(fitsString, "%lf", getGain());
199  fits_update_key_s(fptr, TSTRING, "GAIN", fitsString, "Gain", &status);
200 
201  SensorInterface::addFITSKeywords(fptr, buf, len);
202 }
203 }
INDI::Spectrograph::SetSpectrographCapability
void SetSpectrographCapability(uint32_t cap)
SetSpectrographCapability Set the Spectrograph capabilities. Al fields must be initilized.
Definition: indispectrograph.cpp:165
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::Spectrograph::setGain
void setGain(double gain)
setGain Set gain of Spectrograph device.
Definition: indispectrograph.cpp:156
INDI::SensorInterface::TemperatureNP
INumberVectorProperty TemperatureNP
Definition: indisensorinterface.h:503
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::Spectrograph::setHighCutFrequency
void setHighCutFrequency(double freq)
setHighCutFrequency Set high cut frequency of Spectrograph device.
Definition: indispectrograph.cpp:147
INDI::BaseDevice::SPECTROGRAPH_INTERFACE
@ SPECTROGRAPH_INTERFACE
Definition: basedevice.h:85
INDI::Spectrograph::SPECTROGRAPH_GAIN
@ SPECTROGRAPH_GAIN
Definition: indispectrograph.h:167
min
double min(void)
indicom.h
Implementations for common driver routines.
locale_compat.h
INDI::Logger::DBG_WARNING
@ DBG_WARNING
Definition: indilogger.h:193
INDI::Spectrograph::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: indispectrograph.cpp:119
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
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
indispectrograph.h
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::SensorInterface::processText
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Definition: indisensorinterface.cpp:194
INDI::Spectrograph::ISNewBLOB
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.
Definition: indispectrograph.cpp:132
INDI::Spectrograph::getGain
double getGain()
getGain Get requested integration gain for the sensor.
Definition: indispectrograph.h:125
INDI::Spectrograph::Spectrograph
Spectrograph()
Definition: indispectrograph.cpp:62
INDI::SensorInterface::processSwitch
bool processSwitch(const char *dev, const char *name, ISState states[], char *names[], int n)
Definition: indisensorinterface.cpp:318
INDI::Spectrograph::getLowCutFrequency
double getLowCutFrequency()
getLowCutFrequency Get requested low cut frequency in Hz.
Definition: indispectrograph.h:107
INDI::Spectrograph::SpectrographSettingsNP
INumberVectorProperty SpectrographSettingsNP
Definition: indispectrograph.h:173
max
double max(void)
INDI::Spectrograph::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: indispectrograph.cpp:127
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
streammanager.h
INDI::DefaultDevice::getDriverInterface
virtual uint16_t getDriverInterface() override
Definition: defaultdevice.cpp:896
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::Spectrograph::ISSnoopDevice
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: indispectrograph.cpp:109
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
INDI::Spectrograph::SPECTROGRAPH_LOWFREQ
@ SPECTROGRAPH_LOWFREQ
Definition: indispectrograph.h:168
INDI::SensorInterface::getBPS
int getBPS() const
getBPS Get Sensor depth (bits per sample).
Definition: indisensorinterface.h:168
INDI::Spectrograph::SPECTROGRAPH_ANTENNA
@ SPECTROGRAPH_ANTENNA
Definition: indispectrograph.h:171
xml_ele_
Definition: lilxml.c:105
INDI::Spectrograph::ISGetProperties
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...
Definition: indispectrograph.cpp:85
_INumberVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:322
INDI::Spectrograph::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: indispectrograph.cpp:178
INDI::SensorInterface::fits_update_key_s
void fits_update_key_s(fitsfile *fptr, int type, std::string name, void *p, std::string explanation, int *status)
Definition: indisensorinterface.cpp:760
defaultdevice.h
INDI::SensorInterface::FramedIntegrationNP
INumberVectorProperty FramedIntegrationNP
Definition: indisensorinterface.h:420
INDI::Spectrograph::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: indispectrograph.cpp:114
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
INDI::Spectrograph::setLowCutFrequency
void setLowCutFrequency(double freq)
setLowCutFrequency Set low cut frequency of Spectrograph device.
Definition: indispectrograph.cpp:138
INDI::Spectrograph::StartIntegration
virtual bool StartIntegration(double duration) override
Start integration from the Sensor device.
Definition: indispectrograph.cpp:171
INDI::SensorInterface::HasCooler
bool HasCooler() const
Definition: indisensorinterface.h:351
name
const char * name
Definition: indiserver.c:116
INDI::SensorInterface::addFITSKeywords
virtual void addFITSKeywords(fitsfile *fptr, uint8_t *buf, int len)
Add FITS keywords to a fits file.
Definition: indisensorinterface.cpp:636
INDI::SensorInterface::processProperties
void processProperties(const char *dev)
Definition: indisensorinterface.cpp:155
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::Spectrograph::SPECTROGRAPH_BITSPERSAMPLE
@ SPECTROGRAPH_BITSPERSAMPLE
Definition: indispectrograph.h:170
DEBUGF
#define DEBUGF(priority, msg,...)
Definition: indilogger.h:57
IP_RW
@ IP_RW
Definition: indiapi.h:185
MAXINDILABEL
#define MAXINDILABEL
Definition: indiapi.h:191
INDI::Spectrograph::SPECTROGRAPH_HIGHFREQ
@ SPECTROGRAPH_HIGHFREQ
Definition: indispectrograph.h:169
INDI::SensorInterface::processSnoopDevice
bool processSnoopDevice(XMLEle *root)
Definition: indisensorinterface.cpp:169
INDI::Spectrograph::~Spectrograph
virtual ~Spectrograph()
Definition: indispectrograph.cpp:66
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::SensorInterface::SetCapability
void SetCapability(uint32_t cap)
SetCapability Set the Sensor capabilities. Al fields must be initilized.
Definition: indisensorinterface.cpp:519
INDI::Spectrograph::addFITSKeywords
virtual void addFITSKeywords(fitsfile *fptr, uint8_t *buf, int len) override
Add FITS keywords to a fits file.
Definition: indispectrograph.cpp:200
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::Spectrograph::getHighCutFrequency
double getHighCutFrequency()
getHighCutFrequency Get requested high cut frequency in Hz.
Definition: indispectrograph.h:116
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::Spectrograph::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: indispectrograph.cpp:90
INDI::Spectrograph::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: indispectrograph.cpp:70
INDI::Spectrograph::SpectrographSettingsN
INumber SpectrographSettingsN[8]
Definition: indispectrograph.h:174