Instrument Neutral Distributed Interface INDI  1.9.5
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", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
63 
65 
67 }
68 
69 void Receiver::ISGetProperties(const char *dev)
70 {
71  processProperties(dev);
72 }
73 
75 {
76  if (isConnected())
77  {
79 
80  if (HasCooler())
82  }
83  else
84  {
86 
87  if (HasCooler())
89  }
91 }
92 
94 {
95  return processSnoopDevice(root);
96 }
97 
98 bool Receiver::ISNewText(const char *dev, const char *name, char *values[], char *names[], int n)
99 {
100  return processText(dev, name, values, names, n);
101 }
102 
103 bool Receiver::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
104 {
105  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, ReceiverSettingsNP.name)) {
106  IDSetNumber(&ReceiverSettingsNP, nullptr);
107  }
108  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, ReceiverSettingsNP.name)) {
109  IDSetNumber(&ReceiverSettingsNP, nullptr);
110  }
111  return processNumber(dev, name, values, names, n);
112 }
113 
114 bool Receiver::ISNewSwitch(const char *dev, const char *name, ISState *values, char *names[], int n)
115 {
116  return processSwitch(dev, name, values, names, n);
117 }
118 
119 bool Receiver::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
120  char *formats[], char *names[], int n)
121 {
122  return processBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
123 }
124 
125 void Receiver::setBandwidth(double bandwidth)
126 {
127  Bandwidth = bandwidth;
128 
130 
132 }
133 
134 void Receiver::setSampleRate(double sr)
135 {
136  SampleRate = sr;
137 
139 
140  IDSetNumber(&ReceiverSettingsNP, nullptr);
141 }
142 
143 void Receiver::setGain(double gain)
144 {
145  Gain = gain;
146 
148 
149  IDSetNumber(&ReceiverSettingsNP, nullptr);
150 }
151 
152 void Receiver::setFrequency(double freq)
153 {
154  Frequency = freq;
155 
157 
158  IDSetNumber(&ReceiverSettingsNP, nullptr);
159 }
160 
161 void Receiver::SetReceiverCapability(uint32_t cap)
162 {
163  SetCapability(cap);
165 }
166 
167 bool Receiver::StartIntegration(double duration)
168 {
169  INDI_UNUSED(duration);
170  DEBUGF(Logger::DBG_WARNING, "Receiver::StartIntegration %4.2f - Should never get here", duration);
171  return false;
172 }
173 
174 void Receiver::setMinMaxStep(const char *property, const char *element, double min, double max, double step,
175  bool sendToClient)
176 {
177  INumberVectorProperty *vp = nullptr;
178 
179  if (!strcmp(property, ReceiverSettingsNP.name)) {
180  vp = &FramedIntegrationNP;
181 
182  INumber *np = IUFindNumber(vp, element);
183  if (np)
184  {
185  np->min = min;
186  np->max = max;
187  np->step = step;
188 
189  if (sendToClient)
190  IUUpdateMinMax(vp);
191  }
192  }
193  INDI::SensorInterface::setMinMaxStep(property, element, min, max, step, sendToClient);
194 }
195 
196 void Receiver::addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len)
197 {
198  char fitsString[MAXINDILABEL];
199  int status = 0;
200 
201  // RECEIVER
202  sprintf(fitsString, "%d", getBPS());
203  fits_update_key_s(fptr, TSTRING, "BPS", fitsString, "Bits per sample", &status);
204 
205  sprintf(fitsString, "%lf", getBandwidth());
206  fits_update_key_s(fptr, TSTRING, "BANDWIDT", fitsString, "Bandwidth", &status);
207 
208  sprintf(fitsString, "%lf", getFrequency());
209  fits_update_key_s(fptr, TSTRING, "FREQ", fitsString, "Center Frequency", &status);
210 
211  sprintf(fitsString, "%lf", getSampleRate());
212  fits_update_key_s(fptr, TSTRING, "SRATE", fitsString, "Sampling Rate", &status);
213 
214  sprintf(fitsString, "%lf", getGain());
215  fits_update_key_s(fptr, TSTRING, "GAIN", fitsString, "Gain", &status);
216 
217  SensorInterface::addFITSKeywords(fptr, buf, len);
218 }
219 }
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::SensorInterface::TemperatureNP
INumberVectorProperty TemperatureNP
Definition: indisensorinterface.h:503
INDI::Receiver::RECEIVER_ANTENNA
@ RECEIVER_ANTENNA
Definition: indireceiver.h:187
INDI::Receiver::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: indireceiver.cpp:136
INDI::Receiver::getGain
double getGain()
getGain Get requested integration gain for the sensor.
Definition: indireceiver.h:122
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::Receiver::RECEIVER_BANDWIDTH
@ RECEIVER_BANDWIDTH
Definition: indireceiver.h:184
INDI::BaseDevice::SPECTROGRAPH_INTERFACE
@ SPECTROGRAPH_INTERFACE
Definition: basedevice.h:85
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::Receiver::setBandwidth
void setBandwidth(double bandwidth)
setBandwidth Set bandwidth of Receiver device.
Definition: indireceiver.cpp:142
INDI::Receiver::getSampleRate
double getSampleRate()
getSampleRate Get requested sample rate for the sensor in Hz.
Definition: indireceiver.h:140
INumber
One number descriptor.
INDI::Receiver::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: indireceiver.cpp:120
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
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::Receiver::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: indireceiver.cpp:191
INDI::Receiver::setSampleRate
void setSampleRate(double sr)
setSampleRate Set depth of Receiver device.
Definition: indireceiver.cpp:151
INDI::SensorInterface::processText
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Definition: indisensorinterface.cpp:194
INDI::Receiver::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: indireceiver.cpp:91
INDI::SensorInterface::processSwitch
bool processSwitch(const char *dev, const char *name, ISState states[], char *names[], int n)
Definition: indisensorinterface.cpp:318
INDI::Receiver::getBandwidth
double getBandwidth()
getBandwidth Get requested integration bandwidth for the sensor in Hz.
Definition: indireceiver.h:113
max
double max(void)
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
INDI::Receiver::Receiver
Receiver()
Definition: indireceiver.cpp:62
streammanager.h
INDI::DefaultDevice::getDriverInterface
virtual uint16_t getDriverInterface() override
Definition: defaultdevice.cpp:896
INDI::Receiver::RECEIVER_BITSPERSAMPLE
@ RECEIVER_BITSPERSAMPLE
Definition: indireceiver.h:185
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
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::Receiver::ReceiverSettingsN
INumber ReceiverSettingsN[7]
Definition: indireceiver.h:190
INDI::SensorInterface::getBPS
int getBPS() const
getBPS Get Sensor depth (bits per sample).
Definition: indisensorinterface.h:168
xml_ele_
Definition: lilxml.c:105
INDI::Receiver::~Receiver
virtual ~Receiver()
Definition: indireceiver.cpp:66
_INumberVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:322
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::Receiver::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: indireceiver.cpp:70
INDI::Receiver::SetReceiverCapability
void SetReceiverCapability(uint32_t cap)
SetReceiverCapability Set the Receiver capabilities. Al fields must be initilized.
Definition: indireceiver.cpp:178
INDI::SensorInterface::FramedIntegrationNP
INumberVectorProperty FramedIntegrationNP
Definition: indisensorinterface.h:420
INDI::Receiver::ReceiverSettingsNP
INumberVectorProperty ReceiverSettingsNP
Definition: indireceiver.h:189
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::Receiver::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: indireceiver.cpp:86
INDI::Receiver::addFITSKeywords
virtual void addFITSKeywords(fitsfile *fptr, uint8_t *buf, int len) override
Add FITS keywords to a fits file.
Definition: indireceiver.cpp:213
INDI::Receiver::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: indireceiver.cpp:115
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::Receiver::setFrequency
void setFrequency(double freq)
setFrequency Set the frequency observed.
Definition: indireceiver.cpp:169
INDI::Receiver::RECEIVER_FREQUENCY
@ RECEIVER_FREQUENCY
Definition: indireceiver.h:183
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::Receiver::RECEIVER_GAIN
@ RECEIVER_GAIN
Definition: indireceiver.h:182
INDI::Receiver::RECEIVER_SAMPLERATE
@ RECEIVER_SAMPLERATE
Definition: indireceiver.h:186
INDI::Receiver::getFrequency
double getFrequency()
getFrequency Get requested integration frequency for the sensor in Hz.
Definition: indireceiver.h:131
DEBUGF
#define DEBUGF(priority, msg,...)
Definition: indilogger.h:57
INDI::Receiver::setGain
void setGain(double gain)
setGain Set gain of Receiver device.
Definition: indireceiver.cpp:160
IP_RW
@ IP_RW
Definition: indiapi.h:185
MAXINDILABEL
#define MAXINDILABEL
Definition: indiapi.h:191
INDI::SensorInterface::processSnoopDevice
bool processSnoopDevice(XMLEle *root)
Definition: indisensorinterface.cpp:169
ISState
ISState
Switch state.
Definition: indiapi.h:148
indireceiver.h
INDI::SensorInterface::SetCapability
void SetCapability(uint32_t cap)
SetCapability Set the Sensor capabilities. Al fields must be initilized.
Definition: indisensorinterface.cpp:519
INDI::Receiver::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: indireceiver.cpp:131
INDI::Receiver::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: indireceiver.cpp:110
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
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::Receiver::StartIntegration
virtual bool StartIntegration(double duration) override
Start integration from the Sensor device.
Definition: indireceiver.cpp:184