Instrument Neutral Distributed Interface INDI  2.0.2
indireceiver.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 "indireceiver.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  // Receiver Info
56  IUFillNumber(&ReceiverSettingsN[RECEIVER_GAIN], "RECEIVER_GAIN", "Gain", "%16.2f", 1, 4, 1, 1);
57  IUFillNumber(&ReceiverSettingsN[RECEIVER_FREQUENCY], "RECEIVER_FREQUENCY", "Frequency", "%16.2f", 1, 4, 1, 1);
58  IUFillNumber(&ReceiverSettingsN[RECEIVER_BANDWIDTH], "RECEIVER_BANDWIDTH", "Bandwidth", "%16.2f", 1, 4, 1, 1);
59  IUFillNumber(&ReceiverSettingsN[RECEIVER_BITSPERSAMPLE], "RECEIVER_BITSPERSAMPLE", "Bits per sample", "%16.2f", 1, 4, 1, 1);
60  IUFillNumber(&ReceiverSettingsN[RECEIVER_SAMPLERATE], "RECEIVER_SAMPLERATE", "Sampling rate", "%16.2f", 1, 4, 1, 1);
61  IUFillNumber(&ReceiverSettingsN[RECEIVER_ANTENNA], "RECEIVER_ANTENNA", "Antenna", "%16.2f", 1, 4, 1, 1);
62  IUFillNumberVector(&ReceiverSettingsNP, ReceiverSettingsN, 6, getDeviceName(), "RECEIVER_SETTINGS", "Receiver Settings",
64 
66 
68 }
69 
70 void Receiver::ISGetProperties(const char *dev)
71 {
72  processProperties(dev);
73 }
74 
76 {
77  if (isConnected())
78  {
80 
81  if (HasCooler())
83  }
84  else
85  {
87 
88  if (HasCooler())
90  }
92 }
93 
95 {
96  return processSnoopDevice(root);
97 }
98 
99 bool Receiver::ISNewText(const char *dev, const char *name, char *values[], char *names[], int n)
100 {
101  return processText(dev, name, values, names, n);
102 }
103 
104 bool Receiver::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
105 {
106  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, ReceiverSettingsNP.name))
107  {
108  IDSetNumber(&ReceiverSettingsNP, nullptr);
109  }
110  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, ReceiverSettingsNP.name))
111  {
112  IDSetNumber(&ReceiverSettingsNP, nullptr);
113  }
114  return processNumber(dev, name, values, names, n);
115 }
116 
117 bool Receiver::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 Receiver::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 
128 void Receiver::setBandwidth(double bandwidth)
129 {
130  Bandwidth = bandwidth;
131 
133 
134  IDSetNumber(&ReceiverSettingsNP, nullptr);
135 }
136 
137 void Receiver::setSampleRate(double sr)
138 {
139  SampleRate = sr;
140 
142 
143  IDSetNumber(&ReceiverSettingsNP, nullptr);
144 }
145 
146 void Receiver::setGain(double gain)
147 {
148  Gain = gain;
149 
151 
152  IDSetNumber(&ReceiverSettingsNP, nullptr);
153 }
154 
155 void Receiver::setFrequency(double freq)
156 {
157  Frequency = freq;
158 
160 
161  IDSetNumber(&ReceiverSettingsNP, nullptr);
162 }
163 
165 {
166  SetCapability(cap);
168 }
169 
170 bool Receiver::StartIntegration(double duration)
171 {
172  INDI_UNUSED(duration);
173  DEBUGF(Logger::DBG_WARNING, "Receiver::StartIntegration %4.2f - Should never get here", duration);
174  return false;
175 }
176 
177 void Receiver::setMinMaxStep(const char *property, const char *element, double min, double max, double step,
178  bool sendToClient)
179 {
180  INDI::SensorInterface::setMinMaxStep(property, element, min, max, step, sendToClient);
181  INumberVectorProperty *nvp = nullptr;
182 
183  if (!strcmp(property, ReceiverSettingsNP.name))
184  nvp = &ReceiverSettingsNP;
185  else
186  return;
187 
188  INumber *np = IUFindNumber(nvp, element);
189  if (np)
190  {
191  np->min = min;
192  np->max = max;
193  np->step = step;
194 
195  if (sendToClient)
196  IUUpdateMinMax(nvp);
197  }
198 }
199 
200 void Receiver::addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len)
201 {
202  char fitsString[MAXINDILABEL];
203  int status = 0;
204 
205  // RECEIVER
206  sprintf(fitsString, "%d", getBPS());
207  fits_update_key_s(fptr, TSTRING, "BPS", fitsString, "Bits per sample", &status);
208 
209  sprintf(fitsString, "%lf", getBandwidth());
210  fits_update_key_s(fptr, TSTRING, "BANDWIDT", fitsString, "Bandwidth", &status);
211 
212  sprintf(fitsString, "%lf", getFrequency());
213  fits_update_key_s(fptr, TSTRING, "FREQ", fitsString, "Center Frequency", &status);
214 
215  sprintf(fitsString, "%lf", getSampleRate());
216  fits_update_key_s(fptr, TSTRING, "SRATE", fitsString, "Sampling Rate", &status);
217 
218  sprintf(fitsString, "%lf", getGain());
219  fits_update_key_s(fptr, TSTRING, "GAIN", fitsString, "Gain", &status);
220 
221  SensorInterface::addFITSKeywords(fptr, buf, len);
222 }
223 }
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
void setGain(double gain)
setGain Set gain of Receiver device.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void setBandwidth(double bandwidth)
setBandwidth Set bandwidth of Receiver device.
INumber ReceiverSettingsN[7]
Definition: indireceiver.h:191
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
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
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.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
void setFrequency(double freq)
setFrequency Set the frequency observed.
INumberVectorProperty ReceiverSettingsNP
Definition: indireceiver.h:190
double getSampleRate()
getSampleRate Get requested sample rate for the sensor in Hz.
Definition: indireceiver.h:141
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual void addFITSKeywords(fitsfile *fptr, uint8_t *buf, int len) override
Add FITS keywords to a fits file.
double getFrequency()
getFrequency Get requested integration frequency for the sensor in Hz.
Definition: indireceiver.h:132
double getBandwidth()
getBandwidth Get requested integration bandwidth for the sensor in Hz.
Definition: indireceiver.h:114
void SetReceiverCapability(uint32_t cap)
SetReceiverCapability Set the Receiver capabilities. Al fields must be initialized.
virtual ~Receiver()
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
void setSampleRate(double sr)
setSampleRate Set depth of Receiver device.
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 bool StartIntegration(double duration) override
Start integration from the Sensor device.
double getGain()
getGain Get requested integration gain for the sensor.
Definition: indireceiver.h:123
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).
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