This file is indexed.

/usr/include/libindi/indidetector.h is in libindi-dev 1.7.1-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/*******************************************************************************
 Copyright(c) 2010, 2017 Ilia Platone, Jasem Mutlaq. All rights reserved.

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public
 License version 2 as published by the Free Software Foundation.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Library General Public License for more details.

 You should have received a copy of the GNU Library General Public License
 along with this library; see the file COPYING.LIB.  If not, write to
 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 Boston, MA 02110-1301, USA.
*******************************************************************************/

#pragma once

#include "defaultdevice.h"

#include <fitsio.h>

#include <memory>
#include <cstring>

#include <stdint.h>

extern const char *CAPTURE_SETTINGS_TAB;
extern const char *CAPTURE_INFO_TAB;
extern const char *GUIDE_HEAD_TAB;

/**
 * @brief The DetectorDevice class provides functionality of a Detector Device within a Detector.
 */
class DetectorDevice
{
  public:
    DetectorDevice();
    ~DetectorDevice();

    typedef enum {
        DETECTOR_SAMPLERATE,
        DETECTOR_FREQUENCY,
        DETECTOR_BITSPERSAMPLE,
    } DETECTOR_INFO_INDEX;

    typedef enum {
        DETECTOR_BLOB_CONTINUUM,
        DETECTOR_BLOB_SPECTRUM,
    } DETECTOR_BLOB_INDEX;

    /**
     * @brief getBPS Get Detector depth (bits per sample).
     * @return bits per sample.
     */
    inline int getBPS() { return BPS; }

    /**
     * @brief getContinuumBufferSize Get allocated continuum buffer size to hold the Detector captured stream.
     * @return allocated continuum buffer size to hold the Detector capture stream.
     */
    inline int getContinuumBufferSize() { return ContinuumBufferSize; }

    /**
     * @brief getSpectrumBufferSize Get allocated spectrum buffer size to hold the Detector spectrum.
     * @return allocated spectrum buffer size (in doubles) to hold the Detector spectrum.
     */
    inline int getSpectrumBufferSize() { return SpectrumBufferSize; }

    /**
     * @brief getCaptureLeft Get Capture time left in seconds.
     * @return Capture time left in seconds.
     */
    inline double getCaptureLeft() { return FramedCaptureN[0].value; }

    /**
     * @brief getSampleRate Get requested SampleRate for the Detector device in Hz.
     * @return requested SampleRate for the Detector device in Hz.
     */
    inline double getSampleRate() { return samplerate; }

    /**
     * @brief getSamplingFrequency Get requested Capture frequency for the Detector device in Hz.
     * @return requested Capture frequency for the Detector device in Hz.
     */
    inline double getFrequency() { return Frequency; }

    /**
     * @brief getCaptureDuration Get requested Capture duration for the Detector device in seconds.
     * @return requested Capture duration for the Detector device in seconds.
     */
    inline double getCaptureDuration() { return captureDuration; }

    /**
     * @brief getCaptureStartTime
     * @return Capture start time in ISO 8601 format.
     */
    const char *getCaptureStartTime();

    /**
     * @brief getContinuumBuffer Get raw buffer of the continuum stream of the Detector device.
     * @return raw continuum buffer of the Detector device.
     */
    inline uint8_t *getContinuumBuffer() { return ContinuumBuffer; }

    /**
     * @brief getSpectrumBuffer Get raw buffer of the spectrum of the Detector device.
     * @return raw continuum buffer of the Detector device.
     */
    inline double *getSpectrumBuffer() { return SpectrumBuffer; }

    /**
     * @brief setContinuumBuffer Set raw frame buffer pointer.
     * @param buffer pointer to continuum buffer
     * /note Detector Device allocates the frame buffer internally once SetContinuumBufferSize is called
     * with allocMem set to true which is the default behavior. If you allocated the memory
     * yourself (i.e. allocMem is false), then you must call this function to set the pointer
     * to the raw frame buffer.
     */
    void setContinuumBuffer(uint8_t *buffer) { ContinuumBuffer = buffer; }

    /**
     * @brief setSpectrumBuffer Set raw frame buffer pointer.
     * @param buffer pointer to spectrum buffer
     * /note Detector Device allocates the frame buffer internally once SetSpectrumBufferSize is called
     * with allocMem set to true which is the default behavior. If you allocated the memory
     * yourself (i.e. allocMem is false), then you must call this function to set the pointer
     * to the raw frame buffer.
     */
    void setSpectrumBuffer(double *buffer) { SpectrumBuffer = buffer; }

    /**
     * @brief Return Detector Info Property
     */
    INumberVectorProperty *getDetectorSettings() { return &DetectorSettingsNP; }

    /**
     * @brief setMinMaxStep for a number property element
     * @param property Property name
     * @param element Element name
     * @param min Minimum element value
     * @param max Maximum element value
     * @param step Element step value
     * @param sendToClient If true (default), the element limits are updated and is sent to the
     * client. If false, the element limits are updated without getting sent to the client.
     */
    void setMinMaxStep(const char *property, const char *element, double min, double max, double step,
                       bool sendToClient = true);

    /**
     * @brief setContinuumBufferSize Set desired continuum buffer size. The function will allocate memory
     * accordingly. The frame size depends on the desired capture time, sampling frequency, and
     * sample depth of the Detector device (bps). You must set the frame size any time any of
     * the prior parameters gets updated.
     * @param nbuf size of buffer in bytes.
     * @param allocMem if True, it will allocate memory of nbut size bytes.
     */
    void setContinuumBufferSize(int nbuf, bool allocMem = true);

    /**
     * @brief setSpectrumBufferSize Set desired spectrum buffer size. The function will allocate memory
     * accordingly. The frame size depends on the size of the spectrum. You must set the frame size any
     * time the spectrum size changes.
     * @param nbuf size of buffer in doubles.
     * @param allocMem if True, it will allocate memory of nbut size doubles.
     */
    void setSpectrumBufferSize(int nbuf, bool allocMem = true);

    /**
     * @brief setSampleRate Set depth of Detector device.
     * @param bpp bits per pixel
     */
    void setSampleRate(float sr);

    /**
     * @brief setFrequency Set the frequency observed.
     * @param capfreq Capture frequency
     */
    void setFrequency(float freq);

    /**
     * @brief setBPP Set depth of Detector device.
     * @param bpp bits per pixel
     */
    void setBPS(int bps);

    /**
     * @brief setCaptureDuration Set desired Detector frame Capture duration for next Capture. You must
     * call this function immediately before starting the actual Capture as it is used to calculate
     * the timestamp used for the FITS header.
     * @param duration Capture duration in seconds.
     */
    void setCaptureDuration(double duration);

    /**
     * @brief setCaptureLeft Update Capture time left. Inform the client of the new Capture time
     * left value.
     * @param duration Capture duration left in seconds.
     */
    void setCaptureLeft(double duration);

    /**
     * @brief setCaptureFailed Alert the client that the Capture failed.
     */
    void setCaptureFailed();

    /**
     * @return Get number of FITS axis in capture. By default 2
     */
    int getNAxis() const;

    /**
     * @brief setNAxis Set FITS number of axis
     * @param value number of axis
     */
    void setNAxis(int value);

    /**
     * @brief setCaptureExtension Set capture exntension
     * @param ext extension (fits, jpeg, raw..etc)
     */
    void setCaptureExtension(const char *ext);

    /**
     * @return Return capture extension (fits, jpeg, raw..etc)
     */
    char *getCaptureExtension() { return captureExtention; }

    /**
     * @return True if Detector is currently exposing, false otherwise.
     */
    bool isCapturing() { return (FramedCaptureNP.s == IPS_BUSY); }

  private:
    /// # of Axis
    int NAxis;
    /// Bytes per Sample
    int BPS;
    double samplerate;
    double Frequency;
    uint8_t *ContinuumBuffer;
    int ContinuumBufferSize;
    double *SpectrumBuffer;
    int SpectrumBufferSize;
    double captureDuration;
    timeval startCaptureTime;
    char captureExtention[MAXINDIBLOBFMT];

    INumberVectorProperty FramedCaptureNP;
    INumber FramedCaptureN[1];

    INumberVectorProperty DetectorSettingsNP;
    INumber DetectorSettingsN[4];

    ISwitchVectorProperty AbortCaptureSP;
    ISwitch AbortCaptureS[1];

    IBLOB FitsB[2];
    IBLOBVectorProperty FitsBP;

    friend class INDI::Detector;
};

/**
 * \class INDI::Detector
 * \brief Class to provide general functionality of Monodimensional Detector.
 *
 * The Detector capabilities must be set to select which features are exposed to the clients.
 * SetDetectorCapability() is typically set in the constructor or initProperties(), but can also be
 * called after connection is established with the Detector, but must be called /em before returning
 * true in Connect().
 *
 * Developers need to subclass INDI::Detector to implement any driver for Detectors within INDI.
 *
 * \example Detector Simulator
 * \author Jasem Mutlaq, Ilia Platone
 *
 */

namespace INDI
{

class Detector : public DefaultDevice
{
  public:
    Detector();
    virtual ~Detector();

    enum
    {
        DETECTOR_CAN_ABORT      = 1 << 0, /*!< Can the Detector Capture be aborted?  */
        DETECTOR_HAS_SHUTTER    = 1 << 1, /*!< Does the Detector have a mechanical shutter?  */
        DETECTOR_HAS_COOLER     = 1 << 2, /*!< Does the Detector have a cooler and temperature control?  */
        DETECTOR_HAS_CONTINUUM  = 1 << 3,  /*!< Does the Detector support live streaming?  */
        DETECTOR_HAS_SPECTRUM   = 1 << 4,  /*!< Does the Detector support spectrum analysis?  */
    } DetectorCapability;

    virtual bool initProperties();
    virtual bool updateProperties();
    virtual void ISGetProperties(const char *dev);
    virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n);
    virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n);
    virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n);
    virtual bool ISSnoopDevice(XMLEle *root);

  protected:
    /**
     * @brief GetDetectorCapability returns the Detector capabilities.
     */
    uint32_t GetDetectorCapability() const { return capability; }

    /**
     * @brief SetDetectorCapability Set the Detector capabilities. Al fields must be initilized.
     * @param cap pointer to DetectorCapability struct.
     */
    void SetDetectorCapability(uint32_t cap);

    /**
     * @return True if Detector can abort Capture. False otherwise.
     */
    bool CanAbort() { return capability & DETECTOR_CAN_ABORT; }

    /**
     * @return True if Detector has mechanical or electronic shutter. False otherwise.
     */
    bool HasShutter() { return capability & DETECTOR_HAS_SHUTTER; }

    /**
     * @return True if Detector has cooler and temperature can be controlled. False otherwise.
     */
    bool HasCooler() { return capability & DETECTOR_HAS_COOLER; }

    /**
     * @return  True if the Detector supports live streaming. False otherwise.
     */
    bool HasContinuum() { return capability & DETECTOR_HAS_CONTINUUM; }

    /**
     * @return  True if the Detector supports live streaming. False otherwise.
     */
    bool HasSpectrum() { return capability & DETECTOR_HAS_SPECTRUM; }

    /**
     * @brief Set Detector temperature
     * @param temperature Detector temperature in degrees celsius.
     * @return 0 or 1 if setting the temperature call to the hardware is successful. -1 if an
     * error is encountered.
     * Return 0 if setting the temperature to the requested value takes time.
     * Return 1 if setting the temperature to the requested value is complete.
     * \note Upon returning 0, the property becomes BUSY. Once the temperature reaches the requested
     * value, change the state to OK.
     * \note This function is not implemented in Detector, it must be implemented in the child class
     */
    virtual int SetTemperature(double temperature);

    /**
     * \brief Start capture from the Detector device
     * \param duration Duration in seconds
     * \return true if OK and Capture will take some time to complete, false on error.
     * \note This function is not implemented in Detector, it must be implemented in the child class
     */
    virtual bool StartCapture(float duration);

    /**
     * \brief Set common capture params
     * \param sr Detector samplerate (in Hz)
     * \param cfreq Capture frequency of the detector (Hz, observed frequency).
     * \param sfreq Sampling frequency of the detector (Hz, electronic speed of the detector).
     * \param bps Bit resolution of a single sample.
     * \return true if OK and Capture will take some time to complete, false on error.
     * \note This function is not implemented in Detector, it must be implemented in the child class
     */
    virtual bool CaptureParamsUpdated(float sr, float freq, float bps);

    /**
     * \brief Uploads target Device exposed buffer as FITS to the client. Dervied classes should class
     * this function when an Capture is complete.
     * @param targetDevice device that contains upload capture data
     * \note This function is not implemented in Detector, it must be implemented in the child class
     */
    virtual bool CaptureComplete(DetectorDevice *targetDevice);

    /**
     * \brief Abort ongoing Capture
     * \return true is abort is successful, false otherwise.
     * \note This function is not implemented in Detector, it must be implemented in the child class
     */
    virtual bool AbortCapture();

    /**
     * \brief Setup Detector parameters for the Detector. Child classes call this function to update
     * Detector parameters
     * \param samplerate Detector samplerate (in Hz)
     * \param freq Center frequency of the detector (Hz, observed frequency).
     * \param bps Bit resolution of a single sample.
     */
    virtual void SetDetectorParams(float samplerate, float freq, float bps);

    /**
     * \brief Add FITS keywords to a fits file
     * \param fptr pointer to a valid FITS file.
     * \param targetDevice The target device to extract the keywords from.
     * \param blobIndex The blob index of this FITS (0: continuum, 1: spectrum).
     * \note In additional to the standard FITS keywords, this function write the following
     * keywords the FITS file:
     * <ul>
     * <li>EXPTIME: Total Capture Time (s)</li>
     * <li>DATAMIN: Minimum value</li>
     * <li>DATAMAX: Maximum value</li>
     * <li>INSTRUME: Detector Name</li>
     * <li>DATE-OBS: UTC start date of observation</li>
     * </ul>
     *
     * To add additional information, override this function in the child class and ensure to call
     * Detector::addFITSKeywords.
     */
    virtual void addFITSKeywords(fitsfile *fptr, DetectorDevice *targetDevice, int blobIndex);

    /** A function to just remove GCC warnings about deprecated conversion */
    void fits_update_key_s(fitsfile *fptr, int type, std::string name, void *p, std::string explanation, int *status);

    /**
     * @brief activeDevicesUpdated Inform children that ActiveDevices property was updated so they can
     * snoop on the updated devices if desired.
     */
    virtual void activeDevicesUpdated() {}

    /**
     * @brief saveConfigItems Save configuration items in XML file.
     * @param fp pointer to file to write to
     * @return True if successful, false otherwise
     */
    virtual bool saveConfigItems(FILE *fp);

    double RA, Dec;
    double primaryAperture;
    double primaryFocalLength;
    bool InCapture;

    bool AutoLoop;
    bool SendCapture;
    bool ShowMarker;

    float CaptureTime;

    // Sky Quality
    double MPSAS;

    std::vector<std::string> FilterNames;
    int CurrentFilterSlot;

    DetectorDevice PrimaryDetector;

    //  We are going to snoop these from a telescope
    INumberVectorProperty EqNP;
    INumber EqN[2];

    ITextVectorProperty ActiveDeviceTP;
    IText ActiveDeviceT[4] {};

    INumber TemperatureN[1];
    INumberVectorProperty TemperatureNP;

    IText FileNameT[1] {};
    ITextVectorProperty FileNameTP;

    ISwitch DatasetS[1];
    ISwitchVectorProperty DatasetSP;

    ISwitch UploadS[3];
    ISwitchVectorProperty UploadSP;

    IText UploadSettingsT[2] {};
    ITextVectorProperty UploadSettingsTP;
    enum
    {
        UPLOAD_DIR,
        UPLOAD_PREFIX
    };

    ISwitch TelescopeTypeS[2];
    ISwitchVectorProperty TelescopeTypeSP;
    enum
    {
        TELESCOPE_PRIMARY
    };

    // FITS Header
    IText FITSHeaderT[2] {};
    ITextVectorProperty FITSHeaderTP;
    enum
    {
        FITS_OBSERVER,
        FITS_OBJECT
    };

  private:
    uint32_t capability;

    bool uploadFile(DetectorDevice *targetDevice, const void *fitsData, size_t totalBytes, bool sendCapture, bool saveCapture, int blobindex);
    void getMinMax(double *min, double *max, uint8_t *buf, int len, int bpp);
    int getFileIndex(const char *dir, const char *prefix, const char *ext);
};

}