Instrument Neutral Distributed Interface INDI 2.2.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"
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
42namespace INDI
43{
44
48
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
70void Receiver::ISGetProperties(const char *dev)
71{
73}
74
93
95{
96 return processSnoopDevice(root);
97}
98
99bool 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
104bool 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 {
109 }
110 return processNumber(dev, name, values, names, n);
111}
112
113bool Receiver::ISNewSwitch(const char *dev, const char *name, ISState *values, char *names[], int n)
114{
115 return processSwitch(dev, name, values, names, n);
116}
117
118bool Receiver::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
119 char *formats[], char *names[], int n)
120{
121 return processBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
122}
123
124void Receiver::setBandwidth(double bandwidth)
125{
126 Bandwidth = bandwidth;
127
129
131}
132
134{
135 SampleRate = sr;
136
138
140}
141
142void Receiver::setGain(double gain)
143{
144 Gain = gain;
145
147
149}
150
151void Receiver::setFrequency(double freq)
152{
153 Frequency = freq;
154
156
158
159}
160
161void Receiver::setBPS(int BPS)
162{
163 BitsPerSample = BPS;
164
166
169}
170
176
177bool Receiver::StartIntegration(double duration)
178{
179 INDI_UNUSED(duration);
180 DEBUGF(Logger::DBG_WARNING, "Receiver::StartIntegration %4.2f - Should never get here", duration);
181 return false;
182}
183
184void Receiver::setMinMaxStep(const char *property, const char *element, double min, double max, double step,
185 bool sendToClient)
186{
187 INDI::SensorInterface::setMinMaxStep(property, element, min, max, step, sendToClient);
188 INumberVectorProperty *nvp = nullptr;
189
190 if (!strcmp(property, ReceiverSettingsNP.name))
191 nvp = &ReceiverSettingsNP;
192 else
193 return;
194
195 INumber *np = IUFindNumber(nvp, element);
196 if (np)
197 {
198 np->min = min;
199 np->max = max;
200 np->step = step;
201
202 if (sendToClient)
203 IUUpdateMinMax(nvp);
204 }
205}
206
207void Receiver::addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len)
208{
209 char fitsString[MAXINDILABEL];
210 int status = 0;
211
212 // RECEIVER
213 sprintf(fitsString, "%d", getBPS());
214 fits_update_key_s(fptr, TSTRING, "BPS", fitsString, "Bits per sample", &status);
215
216 sprintf(fitsString, "%lf", getBandwidth());
217 fits_update_key_s(fptr, TSTRING, "BANDWIDT", fitsString, "Bandwidth", &status);
218
219 sprintf(fitsString, "%lf", getFrequency());
220 fits_update_key_s(fptr, TSTRING, "FREQ", fitsString, "Center Frequency", &status);
221
222 sprintf(fitsString, "%lf", getSampleRate());
223 fits_update_key_s(fptr, TSTRING, "SRATE", fitsString, "Sampling Rate", &status);
224
225 sprintf(fitsString, "%lf", getGain());
226 fits_update_key_s(fptr, TSTRING, "GAIN", fitsString, "Gain", &status);
227
228 SensorInterface::addFITSKeywords(fptr, buf, len);
229}
230}
bool isConnected() const
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
uint32_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]
void setBPS(int BPS)
setBPS Set the bits per sample.
virtual bool initProperties() override
Initialize 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
double getSampleRate()
getSampleRate Get requested sample rate for the sensor in Hz.
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.
double getBandwidth()
getBandwidth Get requested integration bandwidth for the sensor in Hz.
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.
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)
void setBPS(int bps)
setBPP Set depth of Sensor device.
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()
Initialize 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)
#define min(a, b)
ISState
Switch state.
Definition indiapi.h:148
@ IP_RW
Definition indiapi.h:184
@ IPS_IDLE
Definition indiapi.h:159
#define MAXINDILABEL
Definition indiapi.h:190
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:490
INumber * IUFindNumber(const INumberVectorProperty *nvp, const char *name)
Find an INumber member in a number text property.
Definition indidevapi.c:275
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:398
#define INDI_UNUSED(x)
Definition indidevapi.h:132
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IUUpdateMinMax(const INumberVectorProperty *nvp)
Function to update the min and max elements of a number in the client.
#define DEBUGF(priority, msg,...)
Definition indilogger.h:57
#define getDeviceName
Namespace to encapsulate INDI client, drivers, and mediator classes.
One number descriptor.
Number vector property descriptor.
Definition indiapi.h:317
char name[MAXINDINAME]
Definition indiapi.h:321