Instrument Neutral Distributed Interface INDI  1.9.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, 0.01, 1.0e+6);
58  IUFillNumber(&DetectorSettingsN[DETECTOR_TRIGGER], "DETECTOR_TRIGGER", "Trigger pulse (%)", "%3.2f", 0.01, 1.0e+15, 0.01, 1.42e+9);
59  IUFillNumberVector(&DetectorSettingsNP, DetectorSettingsN, 2, getDeviceName(), "DETECTOR_SETTINGS", "Detector Settings", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
60 
62 
64 }
65 
66 void Detector::ISGetProperties(const char *dev)
67 {
68  return processProperties(dev);
69 }
70 
72 {
73  if (isConnected())
74  {
76 
77  if (HasCooler())
79  }
80  else
81  {
83 
84  if (HasCooler())
86  }
88 }
89 
91 {
92  return processSnoopDevice(root);
93 }
94 
95 bool Detector::ISNewText(const char *dev, const char *name, char *values[], char *names[], int n)
96 {
97  return processText(dev, name, values, names, n);
98 }
99 
100 bool Detector::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
101 {
102  if (dev && !strcmp(dev, getDeviceName()) && !strcmp(name, DetectorSettingsNP.name)) {
103  IDSetNumber(&DetectorSettingsNP, nullptr);
104  }
105  return processNumber(dev, name, values, names, n);
106 }
107 
108 bool Detector::ISNewSwitch(const char *dev, const char *name, ISState *values, char *names[], int n)
109 {
110  return processSwitch(dev, name, values, names, n);
111 }
112 
113 bool Detector::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
114  char *formats[], char *names[], int n)
115 {
116  return processBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
117 }
118 
119 void Detector::setTriggerLevel(double level)
120 {
121  TriggerLevel = level;
122 
123  DetectorSettingsN[Detector::DETECTOR_TRIGGER].value = level;
124 
126 }
127 
128 void Detector::setResolution(double res)
129 {
130  Resolution = res;
131 
132  DetectorSettingsN[Detector::DETECTOR_RESOLUTION].value = res;
133 
134  IDSetNumber(&DetectorSettingsNP, nullptr);
135 }
136 
137 void Detector::SetDetectorCapability(uint32_t cap)
138 {
139  SetCapability(cap);
141 }
142 
143 bool Detector::StartIntegration(double duration)
144 {
145  INDI_UNUSED(duration);
146  DEBUGF(Logger::DBG_WARNING, "Detector::StartIntegration %4.2f - Should never get here", duration);
147  return false;
148 }
149 
150 void Detector::setMinMaxStep(const char *property, const char *element, double min, double max, double step,
151  bool sendToClient)
152 {
153  INumberVectorProperty *vp = nullptr;
154 
155  if (!strcmp(property, DetectorSettingsNP.name)) {
156  vp = &FramedIntegrationNP;
157 
158  INumber *np = IUFindNumber(vp, element);
159  if (np)
160  {
161  np->min = min;
162  np->max = max;
163  np->step = step;
164 
165  if (sendToClient)
166  IUUpdateMinMax(vp);
167  }
168  }
169  INDI::SensorInterface::setMinMaxStep(property, element, min, max, step, sendToClient);
170 }
171 
172 void Detector::addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len)
173 {
174  char fitsString[MAXINDILABEL];
175  int status = 0;
176 
177  // SPECTROGRAPH
178  sprintf(fitsString, "%lf", getResolution());
179  fits_update_key_s(fptr, TSTRING, "RESOLUTI", fitsString, "Timing resolution", &status);
180 
181  sprintf(fitsString, "%lf", getTriggerLevel());
182  fits_update_key_s(fptr, TSTRING, "TRIGGER", fitsString, "Trigger level", &status);
183 
184  SensorInterface::addFITSKeywords(fptr, buf, len);
185 }
186 }
187 
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::Detector::ISNewText
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
Definition: indidetector.cpp:112
INDI::SensorInterface::TemperatureNP
INumberVectorProperty TemperatureNP
Definition: indisensorinterface.h:503
INDI::Detector::getResolution
double getResolution()
getResolution Get resolution of the detector in ns.
Definition: indidetector.h:102
IUUpdateMinMax
void IUUpdateMinMax(const INumberVectorProperty *nvp)
Function to update the min and max elements of a number in the client.
Definition: indidriver.c:1849
INDI::Detector::DETECTOR_TRIGGER
@ DETECTOR_TRIGGER
Definition: indidetector.h:159
INDI::Detector::ISGetProperties
void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition: indidetector.cpp:83
min
double min(void)
indicom.h
Implementations for common driver routines.
locale_compat.h
INDI::Logger::DBG_WARNING
@ DBG_WARNING
Definition: indilogger.h:193
INumber
One number descriptor.
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::Detector::getTriggerLevel
double getTriggerLevel()
getTriggerLevel Get Trigger voltage level used for pulse detection.
Definition: indidetector.h:117
INDI::Detector::setTriggerLevel
void setTriggerLevel(double level)
setTriggerLevel Set Trigger voltage level used for pulse detection.
Definition: indidetector.cpp:136
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::Detector::ISNewNumber
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition: indidetector.cpp:117
INDI::SensorInterface::processText
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Definition: indisensorinterface.cpp:194
INDI::SensorInterface::setIntegrationFileExtension
void setIntegrationFileExtension(const char *ext)
setIntegrationExtension Set integration exntension
Definition: indisensorinterface.cpp:624
INDI::SensorInterface::processSwitch
bool processSwitch(const char *dev, const char *name, ISState states[], char *names[], int n)
Definition: indisensorinterface.cpp:318
max
double max(void)
INDI::Detector::setResolution
void setResolution(double res)
setResolution Set resolution of the detector in ns.
Definition: indidetector.cpp:145
INDI::Detector::ISSnoopDevice
bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: indidetector.cpp:107
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
INDI::Detector::DetectorSettingsNP
INumberVectorProperty DetectorSettingsNP
Definition: indidetector.h:161
INDI::DefaultDevice::getDriverInterface
virtual uint16_t getDriverInterface() override
Definition: defaultdevice.cpp:896
INDI::Detector::ISNewSwitch
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition: indidetector.cpp:125
INDI::BaseDevice::DETECTOR_INTERFACE
@ DETECTOR_INTERFACE
Definition: basedevice.h:83
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::Detector::Detector
Detector()
Definition: indidetector.cpp:61
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
xml_ele_
Definition: lilxml.c:105
INDI::Detector::updateProperties
bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: indidetector.cpp:88
_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::SensorInterface::FramedIntegrationNP
INumberVectorProperty FramedIntegrationNP
Definition: indisensorinterface.h:420
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:1351
INDI::SensorInterface::processNumber
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Definition: indisensorinterface.cpp:250
indidetector.h
INDI::Detector::StartIntegration
virtual bool StartIntegration(double duration)
Start integration from the Sensor device.
Definition: indidetector.cpp:160
INDI::Detector::addFITSKeywords
void addFITSKeywords(fitsfile *fptr, uint8_t *buf, int len)
Add FITS keywords to a fits file.
Definition: indidetector.cpp:189
INDI::SensorInterface::HasCooler
bool HasCooler() const
Definition: indisensorinterface.h:351
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::Detector::SetDetectorCapability
void SetDetectorCapability(uint32_t cap)
SetDetectorCapability Set the Detector capabilities. Al fields must be initilized.
Definition: indidetector.cpp:154
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::Detector::initProperties
bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
Definition: indidetector.cpp:71
DEBUGF
#define DEBUGF(priority, msg,...)
Definition: indilogger.h:57
IP_RW
@ IP_RW
Definition: indiapi.h:185
MAXINDILABEL
#define MAXINDILABEL
Definition: indiapi.h:191
INDI::Detector::DETECTOR_RESOLUTION
@ DETECTOR_RESOLUTION
Definition: indidetector.h:158
INDI::SensorInterface::processSnoopDevice
bool processSnoopDevice(XMLEle *root)
Definition: indisensorinterface.cpp:169
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::SensorInterface::SetCapability
void SetCapability(uint32_t cap)
SetCapability Set the Sensor capabilities. Al fields must be initilized.
Definition: indisensorinterface.cpp:519
INDI::SensorInterface::setBPS
void setBPS(int bps)
setBPP Set depth of Sensor device.
Definition: indisensorinterface.cpp:1242
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
INDI::Detector::~Detector
virtual ~Detector()
Definition: indidetector.cpp:67
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::Detector::ISNewBLOB
bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Process the client newBLOB command.
Definition: indidetector.cpp:130
INDI::Detector::setMinMaxStep
void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient)
setMinMaxStep for a number property element
Definition: indidetector.cpp:167