Instrument Neutral Distributed Interface INDI  1.9.5
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  {
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  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;
276  virtual bool StartStreaming();
277 
282  virtual bool StopStreaming();
283 
290  virtual bool StartIntegration(double duration);
291 
298  virtual bool IntegrationComplete();
299 
301  virtual bool Handshake();
302 
308  void setSensorConnection(const uint8_t &value);
309 
313  inline uint8_t getSensorConnection() { return sensorConnection; }
314 
333  virtual void addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len);
334 
336  void fits_update_key_s(fitsfile *fptr, int type, std::string name, void *p, std::string explanation, int *status);
337 
338 protected:
339 
343  bool HasShutter() const
344  {
346  }
347 
351  bool HasCooler() const
352  {
353  return capability & SENSOR_HAS_COOLER;
354  }
355 
359  bool CanAbort() const
360  {
361  return capability & SENSOR_CAN_ABORT;
362  }
363 
367  bool HasDSP()
368  {
370  {
371  if(DSP.get() == nullptr)
372  {
373  DSP.reset(new DSP::Manager(this));
374  }
375  return true;
376  }
377  return false;
378  }
379 
384  {
386  {
387  if(Streamer.get() == nullptr)
388  {
389  Streamer.reset(new StreamManager(this));
390  Streamer->initProperties();
391  }
392  return true;
393  }
394  return false;
395  }
396 
400  uint32_t GetCapability() const
401  {
402  return capability;
403  }
404 
409  void SetCapability(uint32_t cap);
410 
416  virtual bool AbortIntegration();
417 
418  uint32_t capability;
419 
422 
425 
428 
431 
434  enum
435  {
437  };
438 
441 
442 
445 
448  enum
449  {
452  };
453 
456 
457  // FITS Header
460  enum
461  {
464  };
465 
471  virtual bool saveConfigItems(FILE *fp);
472 
474 
477  double RA, Dec;
478 
482 
486 
487  bool AutoLoop;
490 
492 
493  // Sky Quality
494  double MPSAS;
495 
500  virtual void activeDevicesUpdated() {}
501 
504 
505  // Threading
506  std::mutex detectorBufferLock;
507 
508  std::unique_ptr<StreamManager> Streamer;
509  std::unique_ptr<DSP::Manager> DSP;
510 
511 
512 
515 
517  int PortFD = -1;
518 
519  private:
520  bool callHandshake();
521  uint8_t sensorConnection = CONNECTION_NONE;
522 
523  int BPS;
525  int NAxis;
527  uint8_t *Buffer;
528  int BufferSize;
529  double integrationTime;
530  double startIntegrationTime;
531  char integrationExtention[MAXINDIBLOBFMT];
532 
533  bool uploadFile(const void *fitsData, size_t totalBytes, bool sendIntegration, bool saveIntegration);
534  void getMinMax(double *min, double *max, uint8_t *buf, int len, int bpp);
535  int getFileIndex(const char *dir, const char *prefix, const char *ext);
536 
537  bool IntegrationCompletePrivate();
538  void* sendFITS(uint8_t* buf, int len);
539 };
540 }
INDI::SensorInterface::HasDSP
bool HasDSP()
Definition: indisensorinterface.h:367
INDI::SensorInterface::saveConfigItems
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save configuration items in XML file.
Definition: indisensorinterface.cpp:1047
INDI::SensorInterface::getBuffer
uint8_t * getBuffer()
getBuffer Get raw buffer of the stream of the Sensor device.
Definition: indisensorinterface.h:146
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::SensorInterface::TemperatureN
INumber TemperatureN[1]
Definition: indisensorinterface.h:502
INDI::SensorInterface::SensorInterface
SensorInterface()
Definition: indisensorinterface.cpp:66
INDI::SensorInterface::SENSOR_HAS_COOLER
@ SENSOR_HAS_COOLER
Definition: indisensorinterface.h:79
INDI::SensorInterface::TemperatureNP
INumberVectorProperty TemperatureNP
Definition: indisensorinterface.h:503
INDI::SensorInterface::IntegrationComplete
virtual bool IntegrationComplete()
Uploads target Device exposed buffer as FITS to the client. Dervied classes should class this functio...
Definition: indisensorinterface.cpp:885
INDI::SensorInterface::getIntegrationTime
double getIntegrationTime() const
getIntegrationTime Get requested Integration duration for the Sensor device in seconds.
Definition: indisensorinterface.h:131
INDI::SensorInterface::FileNameT
IText FileNameT[1]
Definition: indisensorinterface.h:432
INDI::SensorInterface::SendIntegration
bool SendIntegration
Definition: indisensorinterface.h:488
dsp.h
INDI::SensorInterface::CanAbort
bool CanAbort() const
Definition: indisensorinterface.h:359
INDI::SensorInterface::CONNECTION_TCP
@ CONNECTION_TCP
Definition: indisensorinterface.h:96
INDI::SensorInterface::SENSOR_HAS_SHUTTER
@ SENSOR_HAS_SHUTTER
Definition: indisensorinterface.h:78
INDI::SensorInterface::AutoLoop
bool AutoLoop
Definition: indisensorinterface.h:487
_INumberVectorProperty::s
IPState s
Definition: indiapi.h:332
min
double min(void)
INDI::SensorInterface::detectorBufferLock
std::mutex detectorBufferLock
Definition: indisensorinterface.h:506
ISwitch
One switch descriptor.
INDI::SensorInterface::StartStreaming
virtual bool StartStreaming()
StartStreaming Start live video streaming.
Definition: indisensorinterface.cpp:1028
INDI::SensorInterface::DatasetS
ISwitch DatasetS[1]
Definition: indisensorinterface.h:439
INDI::SensorInterface::GetCapability
uint32_t GetCapability() const
GetCapability returns the Sensor capabilities.
Definition: indisensorinterface.h:400
INDI::SensorInterface::PortFD
int PortFD
For Serial & TCP connections.
Definition: indisensorinterface.h:517
INumber
One number descriptor.
Connection::Serial
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Definition: connectionserial.h:56
INDI::SensorInterface::serialConnection
Connection::Serial * serialConnection
Definition: indisensorinterface.h:513
INDI::SensorInterface::setSensorConnection
void setSensorConnection(const uint8_t &value)
setSensorConnection Set Sensor connection mode. Child class should call this in the constructor befor...
Definition: indisensorinterface.cpp:1274
INDI::SensorInterface::IntegrationTime
double IntegrationTime
Definition: indisensorinterface.h:491
Connection::TCP
The TCP class manages connection with devices over the network via TCP/IP. Upon successfull connectio...
Definition: connectiontcp.h:55
_IBLOBVectorProperty
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:469
INDI::SensorInterface::ScopeParametersNP
INumberVectorProperty ScopeParametersNP
Definition: indisensorinterface.h:483
INDI::StreamManager
Definition: streammanager.h:96
uploadFile
void uploadFile(const char *filename)
Definition: stv.c:1710
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
MAXINDIBLOBFMT
#define MAXINDIBLOBFMT
Definition: indiapi.h:195
INDI::SensorInterface::FitsBP
IBLOBVectorProperty FitsBP
Definition: indisensorinterface.h:427
INDI::SensorInterface
The SensorDevice class provides functionality of a Sensor Device within a Sensor.
Definition: indisensorinterface.h:70
INDI::SensorInterface::SensorConnection
enum INDI::SensorInterface::@196 SensorConnection
INDI::SensorInterface::setBuffer
void setBuffer(uint8_t *buffer)
setBuffer Set raw frame buffer pointer.
Definition: indisensorinterface.h:159
INDI::SensorInterface::AbortIntegration
virtual bool AbortIntegration()
Abort ongoing Integration.
Definition: indisensorinterface.cpp:630
INDI::SensorInterface::HasShutter
bool HasShutter() const
Definition: indisensorinterface.h:343
INDI::SensorInterface::SENSOR_HAS_DSP
@ SENSOR_HAS_DSP
Definition: indisensorinterface.h:80
INDI::SensorInterface::tcpConnection
Connection::TCP * tcpConnection
Definition: indisensorinterface.h:514
INDI::SensorInterface::FileNameTP
ITextVectorProperty FileNameTP
Definition: indisensorinterface.h:433
INDI::SensorInterface::processText
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Definition: indisensorinterface.cpp:194
INDI::SensorInterface::SENSOR_MAX_CAPABILITY
@ SENSOR_MAX_CAPABILITY
Definition: indisensorinterface.h:81
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
StreamManager
Class to provide video streaming and recording functionality.
INDI::SensorInterface::RA
double RA
Definition: indisensorinterface.h:477
INDI::SensorInterface::primaryAperture
double primaryAperture
Definition: indisensorinterface.h:485
INDI::SensorInterface::setIntegrationFailed
void setIntegrationFailed()
setIntegrationFailed Alert the client that the Integration failed.
Definition: indisensorinterface.cpp:608
INDI::SensorInterface::DSP
std::unique_ptr< DSP::Manager > DSP
Definition: indisensorinterface.h:509
INDI::SensorInterface::SetTemperature
virtual int SetTemperature(double temperature)
Set Sensor temperature.
Definition: indisensorinterface.cpp:1040
max
double max(void)
INDI::SensorInterface::getSensorConnection
uint8_t getSensorConnection()
Definition: indisensorinterface.h:313
INDI::SensorInterface::getIntegrationFileExtension
char * getIntegrationFileExtension()
Definition: indisensorinterface.h:242
INDI::SensorInterface::UploadSP
ISwitchVectorProperty UploadSP
Definition: indisensorinterface.h:444
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
INDI::SensorInterface::Streamer
std::unique_ptr< StreamManager > Streamer
Definition: indisensorinterface.h:508
INDI::SensorInterface::UPLOAD_DIR
@ UPLOAD_DIR
Definition: indisensorinterface.h:450
INDI::SensorInterface::DatasetSP
ISwitchVectorProperty DatasetSP
Definition: indisensorinterface.h:440
INDI::SensorInterface::FITSHeaderT
IText FITSHeaderT[2]
Definition: indisensorinterface.h:458
INDI::SensorInterface::setIntegrationTime
void setIntegrationTime(double duration)
setIntegrationTime Set desired Sensor frame Integration duration for next Integration....
Definition: indisensorinterface.cpp:586
INDI::SensorInterface::setNAxis
void setNAxis(int value)
setNAxis Set FITS number of axis
Definition: indisensorinterface.cpp:619
type
__le16 type
Definition: pwc-ioctl.h:2
INDI::SensorInterface::capability
uint32_t capability
Definition: indisensorinterface.h:418
INDI::SensorInterface::getIntegrationLeft
double getIntegrationLeft() const
getIntegrationLeft Get Integration time left in seconds.
Definition: indisensorinterface.h:122
INDI::SensorInterface::FITS_OBJECT
@ FITS_OBJECT
Definition: indisensorinterface.h:463
INDI::SensorInterface::UPLOAD_PREFIX
@ UPLOAD_PREFIX
Definition: indisensorinterface.h:451
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
INDI::SensorInterface::getNAxis
int getNAxis() const
Definition: indisensorinterface.cpp:614
INDI::SensorInterface::CONNECTION_SERIAL
@ CONNECTION_SERIAL
Definition: indisensorinterface.h:95
IText
One text descriptor.
streammanager.h
INDI::SensorInterface::~SensorInterface
~SensorInterface()
Definition: indisensorinterface.cpp:96
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
INDI::SensorInterface::initProperties
bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
Definition: indisensorinterface.cpp:398
IPS_BUSY
@ IPS_BUSY
Definition: indiapi.h:162
INDI::SensorInterface::StartIntegration
virtual bool StartIntegration(double duration)
Start integration from the Sensor device.
Definition: indisensorinterface.cpp:572
INDI::SensorInterface::FITS_OBSERVER
@ FITS_OBSERVER
Definition: indisensorinterface.h:462
INDI::SensorInterface::ScopeParametersN
INumber ScopeParametersN[4]
Definition: indisensorinterface.h:484
INDI::SensorInterface::StopStreaming
virtual bool StopStreaming()
StopStreaming Stop live video streaming.
Definition: indisensorinterface.cpp:1034
INDI::SensorInterface::Latitude
double Latitude
Definition: indisensorinterface.h:481
INDI::SensorInterface::activeDevicesUpdated
virtual void activeDevicesUpdated()
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
Definition: indisensorinterface.h:500
INDI::SensorInterface::getBPS
int getBPS() const
getBPS Get Sensor depth (bits per sample).
Definition: indisensorinterface.h:168
INDI::SensorInterface::FramedIntegrationN
INumber FramedIntegrationN[1]
Definition: indisensorinterface.h:421
xml_ele_
Definition: lilxml.c:105
INDI::SensorInterface::CONNECTION_NONE
@ CONNECTION_NONE
Definition: indisensorinterface.h:94
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
INDI::SensorInterface::AbortIntegrationS
ISwitch AbortIntegrationS[1]
Definition: indisensorinterface.h:424
defaultdevice.h
INDI::SensorInterface::FramedIntegrationNP
INumberVectorProperty FramedIntegrationNP
Definition: indisensorinterface.h:420
INDI::SensorInterface::processNumber
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Definition: indisensorinterface.cpp:250
INDI::SensorInterface::InIntegration
bool InIntegration
Definition: indisensorinterface.h:473
indiwsserver.h
INDI::SensorInterface::Dec
double Dec
Definition: indisensorinterface.h:477
INDI::SensorInterface::TelescopeTypeS
ISwitch TelescopeTypeS[2]
Definition: indisensorinterface.h:454
INDI::SensorInterface::FITSHeaderTP
ITextVectorProperty FITSHeaderTP
Definition: indisensorinterface.h:459
DSP
The DSP Namespace adds signal processing to INDI drivers. Primarily written for sensors and detectors...
Definition: convolution.cpp:39
INDI::SensorInterface::primaryFocalLength
double primaryFocalLength
Definition: indisensorinterface.h:485
INDI::SensorInterface::SENSOR_CAN_ABORT
@ SENSOR_CAN_ABORT
Definition: indisensorinterface.h:76
INDI::SensorInterface::TELESCOPE_PRIMARY
@ TELESCOPE_PRIMARY
Definition: indisensorinterface.h:436
INDI::SensorInterface::ActiveDeviceT
IText ActiveDeviceT[4]
Definition: indisensorinterface.h:430
INDI::SensorInterface::Handshake
virtual bool Handshake()
perform handshake with device to check communication
Definition: indisensorinterface.cpp:1256
INDI::SensorInterface::getBufferSize
int getBufferSize() const
getContinuumBufferSize Get allocated continuum buffer size to hold the Sensor integrationd stream.
Definition: indisensorinterface.h:113
INDI::SensorInterface::HasCooler
bool HasCooler() const
Definition: indisensorinterface.h:351
INDI::SensorInterface::getIntegrationStartTime
const char * getIntegrationStartTime()
getIntegrationStartTime
Definition: indisensorinterface.cpp:595
name
const char * name
Definition: indiserver.c:116
manager.h
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::SensorInterface::TelescopeTypeSP
ISwitchVectorProperty TelescopeTypeSP
Definition: indisensorinterface.h:455
INDI::SensorInterface::isCapturing
bool isCapturing() const
Definition: indisensorinterface.h:250
INDI::SensorInterface::Longitude
double Longitude
Definition: indisensorinterface.h:481
INDI::SensorInterface::processProperties
void processProperties(const char *dev)
Definition: indisensorinterface.cpp:155
INDI::SensorInterface::HasStreaming
bool HasStreaming()
Definition: indisensorinterface.h:383
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::SensorInterface::EqNP
INumberVectorProperty EqNP
Definition: indisensorinterface.h:475
INDI::SensorInterface::StreamManager
friend class StreamManager
Misc.
Definition: indisensorinterface.h:271
INDI::SensorInterface::ActiveDeviceTP
ITextVectorProperty ActiveDeviceTP
Definition: indisensorinterface.h:429
INDI::SensorInterface::ShowMarker
bool ShowMarker
Definition: indisensorinterface.h:489
INDI::SensorInterface::setIntegrationLeft
void setIntegrationLeft(double duration)
setIntegrationLeft Update Integration time left. Inform the client of the new Integration time left v...
Definition: indisensorinterface.cpp:579
INDI::SensorInterface::processSnoopDevice
bool processSnoopDevice(XMLEle *root)
Definition: indisensorinterface.cpp:169
INDI::SensorInterface::UploadSettingsTP
ITextVectorProperty UploadSettingsTP
Definition: indisensorinterface.h:447
INDI::SensorInterface::UploadS
ISwitch UploadS[3]
Definition: indisensorinterface.h:443
INDI::SensorInterface::MPSAS
double MPSAS
Definition: indisensorinterface.h:494
INDI::SensorInterface::FitsB
IBLOB FitsB
Definition: indisensorinterface.h:426
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::SensorInterface::SensorCapability
enum INDI::SensorInterface::@195 SensorCapability
INDI::SensorInterface::SetCapability
void SetCapability(uint32_t cap)
SetCapability Set the Sensor capabilities. Al fields must be initilized.
Definition: indisensorinterface.cpp:519
INDI::SensorInterface::EqN
INumber EqN[2]
Definition: indisensorinterface.h:476
INDI::SensorInterface::UploadSettingsT
IText UploadSettingsT[2]
Definition: indisensorinterface.h:446
INDI::DefaultDevice
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:118
DSP::Manager
Definition: manager.h:38
INDI::SensorInterface::setBPS
void setBPS(int bps)
setBPP Set depth of Sensor device.
Definition: indisensorinterface.cpp:1242
IBLOB
One Blob (Binary Large Object) descriptor.
INDI::SensorInterface::SENSOR_HAS_STREAMING
@ SENSOR_HAS_STREAMING
Definition: indisensorinterface.h:77
INDI::SensorInterface::LocationN
INumber LocationN[3]
Definition: indisensorinterface.h:480
Aux::buffer
std::vector< uint8_t > buffer
Definition: celestronauxpacket.h:38
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
INDI::SensorInterface::setBufferSize
void setBufferSize(int nbuf, bool allocMem=true)
setBufferSize Set desired buffer size. The function will allocate memory accordingly....
Definition: indisensorinterface.cpp:551
INDI::SensorInterface::LocationNP
INumberVectorProperty LocationNP
Definition: indisensorinterface.h:479
INDI::SensorInterface::Elevation
double Elevation
Definition: indisensorinterface.h:481
INDI::SensorInterface::AbortIntegrationSP
ISwitchVectorProperty AbortIntegrationSP
Definition: indisensorinterface.h:423