Instrument Neutral Distributed Interface INDI  2.0.2
indidetector.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 "indidetector.h"
22 
23 #include "indicom.h"
24 #include "locale_compat.h"
25 
26 #include <fitsio.h>
27 
28 #include <libnova/julian_day.h>
29 #include <libnova/ln_types.h>
30 #include <libnova/precession.h>
31 
32 #include <regex>
33 
34 #include <dirent.h>
35 #include <cerrno>
36 #include <locale.h>
37 #include <cstdlib>
38 #include <zlib.h>
39 #include <sys/stat.h>
40 
41 namespace INDI
42 {
43 
45 {
46  setBPS(sizeof(pulse_t) * sizeof(uint8_t));
48 }
49 
51 {
52 }
53 
55 {
56  // PrimaryDetector Info
57  IUFillNumber(&DetectorSettingsN[DETECTOR_RESOLUTION], "DETECTOR_RESOLUTION", "Resolution (ns)", "%16.3f", 0.01, 1.0e+8,
58  0.01, 1.0e+6);
59  IUFillNumber(&DetectorSettingsN[DETECTOR_TRIGGER], "DETECTOR_TRIGGER", "Trigger pulse (%)", "%3.2f", 0.01, 1.0e+15, 0.01,
60  1.42e+9);
61  IUFillNumberVector(&DetectorSettingsNP, DetectorSettingsN, 2, getDeviceName(), "DETECTOR_SETTINGS", "Detector Settings",
63 
65 
67 }
68 
69 void Detector::ISGetProperties(const char *dev)
70 {
71  return 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 Detector::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 Detector::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
104 {
105  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, DetectorSettingsNP.name))
106  {
107  IDSetNumber(&DetectorSettingsNP, nullptr);
108  }
109  return processNumber(dev, name, values, names, n);
110 }
111 
112 bool Detector::ISNewSwitch(const char *dev, const char *name, ISState *values, char *names[], int n)
113 {
114  return processSwitch(dev, name, values, names, n);
115 }
116 
117 bool Detector::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
118  char *formats[], char *names[], int n)
119 {
120  return processBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
121 }
122 
123 void Detector::setTriggerLevel(double level)
124 {
125  TriggerLevel = level;
126 
127  DetectorSettingsN[Detector::DETECTOR_TRIGGER].value = level;
128 
129  IDSetNumber(&DetectorSettingsNP, nullptr);
130 }
131 
132 void Detector::setResolution(double res)
133 {
134  Resolution = res;
135 
136  DetectorSettingsN[Detector::DETECTOR_RESOLUTION].value = res;
137 
138  IDSetNumber(&DetectorSettingsNP, nullptr);
139 }
140 
142 {
143  SetCapability(cap);
145 }
146 
147 bool Detector::StartIntegration(double duration)
148 {
149  INDI_UNUSED(duration);
150  DEBUGF(Logger::DBG_WARNING, "Detector::StartIntegration %4.2f - Should never get here", duration);
151  return false;
152 }
153 
154 void Detector::setMinMaxStep(const char *property, const char *element, double min, double max, double step,
155  bool sendToClient)
156 {
157  INDI::SensorInterface::setMinMaxStep(property, element, min, max, step, sendToClient);
158  INumberVectorProperty *nvp = nullptr;
159 
160  if (!strcmp(property, DetectorSettingsNP.name))
161  nvp = &DetectorSettingsNP;
162  else
163  return;
164 
165  INumber *np = IUFindNumber(nvp, element);
166  if (np)
167  {
168  np->min = min;
169  np->max = max;
170  np->step = step;
171 
172  if (sendToClient)
173  IUUpdateMinMax(nvp);
174  }
175 }
176 
177 void Detector::addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len)
178 {
179  char fitsString[MAXINDILABEL];
180  int status = 0;
181 
182  // SPECTROGRAPH
183  sprintf(fitsString, "%lf", getResolution());
184  fits_update_key_s(fptr, TSTRING, "RESOLUTI", fitsString, "Timing resolution", &status);
185 
186  sprintf(fitsString, "%lf", getTriggerLevel());
187  fits_update_key_s(fptr, TSTRING, "TRIGGER", fitsString, "Trigger level", &status);
188 
189  SensorInterface::addFITSKeywords(fptr, buf, len);
190 }
191 }
192 
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 ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
double getResolution()
getResolution Get resolution of the detector in ns.
Definition: indidetector.h:104
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
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 addFITSKeywords(fitsfile *fptr, uint8_t *buf, int len) override
Add FITS keywords to a fits file.
INumberVectorProperty DetectorSettingsNP
Definition: indidetector.h:164
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool StartIntegration(double duration) override
Start integration from the Sensor device.
bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
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
void SetDetectorCapability(uint32_t cap)
SetDetectorCapability Set the Detector capabilities. Al fields must be initialized.
void setTriggerLevel(double level)
setTriggerLevel Set Trigger voltage level used for pulse detection.
double getTriggerLevel()
getTriggerLevel Get Trigger voltage level used for pulse detection.
Definition: indidetector.h:119
void setResolution(double res)
setResolution Set resolution of the detector in ns.
virtual ~Detector()
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()
Initilize properties initial state and value. The child class must implement this function.
bool processSnoopDevice(XMLEle *root)
void setIntegrationFileExtension(const char *ext)
setIntegrationExtension Set integration exntension
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