Instrument Neutral Distributed Interface INDI  2.0.2
indisensorinterface.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2010, 2017 Ilia Platone, Jasem Mutlaq. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 *******************************************************************************/
18 
19 #pragma once
20 
21 #include "defaultdevice.h"
22 #include "dsp.h"
23 #include "dsp/manager.h"
24 #include "stream/streammanager.h"
25 #include <fitsio.h>
26 
27 #ifdef HAVE_WEBSOCKET
28 #include "indiwsserver.h"
29 #endif
30 
31 #include <fitsio.h>
32 
33 #include <memory>
34 #include <cstring>
35 #include <chrono>
36 #include <stdint.h>
37 #include <mutex>
38 #include <thread>
39 #include <stream/streammanager.h>
40 
41 //JM 2019-01-17: Disabled until further notice
42 //#define WITH_EXPOSURE_LOOPING
43 
59 namespace DSP
60 {
61 class Manager;
62 }
63 namespace INDI
64 {
65 class StreamManager;
66 
71 {
72 
73  public:
74  enum
75  {
76  SENSOR_CAN_ABORT = 1 << 0,
78  SENSOR_HAS_SHUTTER = 1 << 2,
79  SENSOR_HAS_COOLER = 1 << 3,
80  SENSOR_HAS_DSP = 1 << 4,
83 
86 
87 
92  enum
93  {
94  CONNECTION_NONE = 1 << 0,
95  CONNECTION_SERIAL = 1 << 1,
96  CONNECTION_TCP = 1 << 2
98 
99  bool initProperties();
100  bool updateProperties();
101  bool processNumber(const char *dev, const char *name, double values[], char *names[], int n);
102  void processProperties(const char *dev);
103  bool processText(const char *dev, const char *name, char *texts[], char *names[], int n);
104  bool processSwitch(const char *dev, const char *name, ISState states[], char *names[], int n);
105  bool processBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
106  char *formats[], char *names[], int n);
107  bool processSnoopDevice(XMLEle *root);
108 
113  inline int getBufferSize() const
114  {
115  return BufferSize;
116  }
117 
122  inline double getIntegrationLeft() const
123  {
124  return FramedIntegrationN[0].value;
125  }
126 
131  inline double getIntegrationTime() const
132  {
133  return integrationTime;
134  }
135 
140  const char *getIntegrationStartTime();
141 
146  inline uint8_t *getBuffer()
147  {
148  return Buffer;
149  }
150 
159  inline void setBuffer(uint8_t *buffer)
160  {
161  Buffer = buffer;
162  }
163 
168  inline int getBPS() const
169  {
170  return BPS;
171  }
172 
183  virtual void setMinMaxStep(const char *property, const char *element, double min, double max, double step,
184  bool sendToClient = true);
185 
194  void setBufferSize(int nbuf, bool allocMem = true);
195 
200  void setBPS(int bps);
201 
208  void setIntegrationTime(double duration);
209 
215  void setIntegrationLeft(double duration);
216 
220  void setIntegrationFailed();
221 
225  int getNAxis() const;
226 
231  void setNAxis(int value);
232 
237  void setIntegrationFileExtension(const char *ext);
238 
243  {
244  return integrationExtention;
245  }
246 
250  inline bool isCapturing() const
251  {
252  return (FramedIntegrationNP.s == IPS_BUSY);
253  }
254 
266  virtual int SetTemperature(double temperature);
267 
271  friend class StreamManager;
272  friend class StreamManagerPrivate;
277  virtual bool StartStreaming();
278 
283  virtual bool StopStreaming();
284 
291  virtual bool StartIntegration(double duration);
292 
299  virtual bool IntegrationComplete();
300 
302  virtual bool Handshake();
303 
309  void setSensorConnection(const uint8_t &value);
310 
314  inline uint8_t getSensorConnection()
315  {
316  return sensorConnection;
317  }
318 
337  virtual void addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len);
338 
340  void fits_update_key_s(fitsfile *fptr, int type, std::string name, void *p, std::string explanation, int *status);
341 
342  protected:
343 
347  bool HasShutter() const
348  {
350  }
351 
355  bool HasCooler() const
356  {
357  return capability & SENSOR_HAS_COOLER;
358  }
359 
363  bool CanAbort() const
364  {
365  return capability & SENSOR_CAN_ABORT;
366  }
367 
371  bool HasDSP()
372  {
374  {
375  if(DSP.get() == nullptr)
376  {
377  DSP.reset(new DSP::Manager(this));
378  }
379  return true;
380  }
381  return false;
382  }
383 
388  {
390  {
391  if(Streamer.get() == nullptr)
392  {
393  Streamer.reset(new StreamManager(this));
394  Streamer->initProperties();
395  }
396  return true;
397  }
398  return false;
399  }
400 
404  uint32_t GetCapability() const
405  {
406  return capability;
407  }
408 
413  void SetCapability(uint32_t cap);
414 
420  virtual bool AbortIntegration();
421 
422  uint32_t capability;
423 
426 
429 
432 
435 
438  enum
439  {
441  };
442 
445 
446 
449 
452  enum
453  {
456  };
457 
460 
461  // FITS Header
464  enum
465  {
468  };
469 
475  virtual bool saveConfigItems(FILE *fp);
476 
478 
481  double RA, Dec;
482 
486 
490 
491  bool AutoLoop;
494 
496 
497  // Sky Quality
498  double MPSAS;
499 
504  virtual void activeDevicesUpdated() {}
505 
508 
509  // Threading
510  std::mutex detectorBufferLock;
511 
512  std::unique_ptr<StreamManager> Streamer;
513  std::unique_ptr<DSP::Manager> DSP;
514 
515 
516 
519 
521  int PortFD = -1;
522 
523  private:
524  bool callHandshake();
525  uint8_t sensorConnection = CONNECTION_NONE;
526 
527  int BPS;
529  int NAxis;
531  uint8_t *Buffer;
532  int BufferSize;
533  double integrationTime;
534  double startIntegrationTime;
535  char integrationExtention[MAXINDIBLOBFMT];
536 
537  bool uploadFile(const void *fitsData, size_t totalBytes, bool sendIntegration, bool saveIntegration);
538  void getMinMax(double *min, double *max, uint8_t *buf, int len, int bpp);
539  int getFileIndex(const char *dir, const char *prefix, const char *ext);
540 
541  bool IntegrationCompletePrivate();
542  void* sendFITS(uint8_t* buf, int len);
543 };
544 }
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successfull connectio...
Definition: connectiontcp.h:38
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
The SensorDevice class provides functionality of a Sensor Device within a Sensor.
void setIntegrationFailed()
setIntegrationFailed Alert the client that the Integration failed.
ITextVectorProperty FileNameTP
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.
ITextVectorProperty FITSHeaderTP
enum INDI::SensorInterface::@251 SensorCapability
virtual bool StartStreaming()
StartStreaming Start live video streaming.
virtual bool StopStreaming()
StopStreaming Stop live video streaming.
ITextVectorProperty UploadSettingsTP
INumberVectorProperty LocationNP
double getIntegrationLeft() const
getIntegrationLeft Get Integration time left in seconds.
bool processSwitch(const char *dev, const char *name, ISState states[], char *names[], int n)
void setBPS(int bps)
setBPP Set depth of Sensor device.
ISwitchVectorProperty DatasetSP
INumberVectorProperty EqNP
void setBufferSize(int nbuf, bool allocMem=true)
setBufferSize Set desired buffer size. The function will allocate memory accordingly....
void setNAxis(int value)
setNAxis Set FITS number of axis
void setSensorConnection(const uint8_t &value)
setSensorConnection Set Sensor connection mode. Child class should call this in the constructor befor...
void setIntegrationLeft(double duration)
setIntegrationLeft Update Integration time left. Inform the client of the new Integration time left v...
ITextVectorProperty ActiveDeviceTP
IBLOBVectorProperty FitsBP
virtual bool AbortIntegration()
Abort ongoing Integration.
uint8_t * getBuffer()
getBuffer Get raw buffer of the stream of the Sensor device.
std::unique_ptr< StreamManager > Streamer
void setIntegrationTime(double duration)
setIntegrationTime Set desired Sensor frame Integration duration for next Integration....
int PortFD
For Serial & TCP connections.
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.
int getBufferSize() const
getContinuumBufferSize Get allocated continuum buffer size to hold the Sensor integrationd stream.
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)
const char * getIntegrationStartTime()
getIntegrationStartTime
friend class StreamManager
Misc.
INumberVectorProperty FramedIntegrationNP
uint32_t GetCapability() const
GetCapability returns the Sensor capabilities.
ISwitchVectorProperty AbortIntegrationSP
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save configuration items in XML file.
enum INDI::SensorInterface::@252 SensorConnection
virtual bool IntegrationComplete()
Uploads target Device exposed buffer as FITS to the client. Dervied classes should class this functio...
ISwitchVectorProperty TelescopeTypeSP
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.
ISwitchVectorProperty UploadSP
virtual bool Handshake()
perform handshake with device to check communication
Connection::TCP * tcpConnection
bool processSnoopDevice(XMLEle *root)
int getBPS() const
getBPS Get Sensor depth (bits per sample).
void setIntegrationFileExtension(const char *ext)
setIntegrationExtension Set integration exntension
void setBuffer(uint8_t *buffer)
setBuffer Set raw frame buffer pointer.
Connection::Serial * serialConnection
virtual void activeDevicesUpdated()
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
double getIntegrationTime() const
getIntegrationTime Get requested Integration duration for the Sensor device in seconds.
INumberVectorProperty ScopeParametersNP
std::unique_ptr< DSP::Manager > DSP
virtual int SetTemperature(double temperature)
Set Sensor temperature.
virtual bool StartIntegration(double duration)
Start integration from the Sensor device.
Class to provide video streaming and recording functionality.
double max(void)
double min(void)
ISState
Switch state.
Definition: indiapi.h:150
#define MAXINDIBLOBFMT
Definition: indiapi.h:196
@ IPS_BUSY
Definition: indiapi.h:163
std::vector< uint8_t > buffer
The DSP Namespace adds signal processing to INDI drivers. Primarily written for sensors and detectors...
Definition: convolution.cpp:40
Namespace to encapsulate INDI client, drivers, and mediator classes.
__le16 type
Definition: pwc-ioctl.h:0
One Blob (Binary Large Object) descriptor.
One number descriptor.
One switch descriptor.
One text descriptor.
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:471
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246
void uploadFile(const char *filename)
Definition: stv.c:1710