Instrument Neutral Distributed Interface INDI 2.2.5
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
41namespace INDI
42{
43
45{
46 setBPS(sizeof(pulse_t) * sizeof(uint8_t));
48}
49
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
69void Detector::ISGetProperties(const char *dev)
70{
71 return processProperties(dev);
72}
73
92
94{
95 return processSnoopDevice(root);
96}
97
98bool 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
103bool 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 {
108 }
109 return processNumber(dev, name, values, names, n);
110}
111
112bool 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
117bool 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
124{
125 TriggerLevel = level;
126
127 DetectorSettingsN[Detector::DETECTOR_TRIGGER].value = level;
128
130}
131
133{
134 Resolution = res;
135
136 DetectorSettingsN[Detector::DETECTOR_RESOLUTION].value = res;
137
139}
140
146
147bool 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
154void 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
177void 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
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 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.
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool initProperties() override
Initialize 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
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.
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()
Initialize properties initial state and value. The child class must implement this function.
bool processSnoopDevice(XMLEle *root)
void setIntegrationFileExtension(const char *ext)
setIntegrationExtension Set integration extension
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