Instrument Neutral Distributed Interface INDI 2.2.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"
25#include <fitsio.h>
26
27#include <fitsio.h>
28
29#include <memory>
30#include <cstring>
31#include <chrono>
32#include <stdint.h>
33#include <mutex>
34#include <thread>
38
39//JM 2019-01-17: Disabled until further notice
40//#define WITH_EXPOSURE_LOOPING
41
57namespace DSP
58{
59class Manager;
60}
61namespace INDI
62{
63class StreamManager;
64
69{
70
71 public:
72 enum
73 {
81
84
85
90 enum
91 {
92 CONNECTION_NONE = 1 << 0,
94 CONNECTION_TCP = 1 << 2
96
97 bool initProperties();
98 bool updateProperties();
99 bool processNumber(const char *dev, const char *name, double values[], char *names[], int n);
100 void processProperties(const char *dev);
101 bool processText(const char *dev, const char *name, char *texts[], char *names[], int n);
102 bool processSwitch(const char *dev, const char *name, ISState states[], char *names[], int n);
103 bool processBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
104 char *formats[], char *names[], int n);
105 bool processSnoopDevice(XMLEle *root);
106
111 inline int getBufferSize() const
112 {
113 return BufferSize;
114 }
115
120 inline double getIntegrationLeft() const
121 {
122 return FramedIntegrationN[0].value;
123 }
124
129 inline double getIntegrationTime() const
130 {
131 return integrationTime;
132 }
133
138 const char *getIntegrationStartTime();
139
144 inline uint8_t *getBuffer()
145 {
146 return Continuum;
147 }
148
157 inline void setBuffer(uint8_t *buffer)
158 {
159 Continuum = buffer;
160 }
161
166 inline uint8_t *getReal()
167 {
168 return Real;
169 }
170
179 inline void setReal(uint8_t *buffer)
180 {
181 int x = 0;
182 for(x = 0; x < getBufferSize(); x++) {
183 getMagnitude()[x] = pow(pow(getReal()[x], 2)+pow(buffer[x], 2), 0.5);
184 if(getMagnitude()[x] > 0) {
185 getPhase()[x] = acos(buffer[x]/getMagnitude()[x]);
186 if(asin(getReal()[x]/getMagnitude()[x]) < 0)
187 getPhase()[x] += M_PI;
188 } else {
189 getPhase()[x] = 0;
190 }
191 }
192
193 Real = buffer;
194 }
195
200 inline uint8_t *getImaginary()
201 {
202 return Imaginary;
203 }
204
213 inline void setImaginary(uint8_t *buffer)
214 {
215 int x = 0;
216 for(x = 0; x < getBufferSize(); x++) {
217 getMagnitude()[x] = pow(pow(getReal()[x], 2)+pow(buffer[x], 2), 0.5);
218 if(getMagnitude()[x] > 0) {
219 getPhase()[x] = acos(buffer[x]/getMagnitude()[x]);
220 if(asin(getReal()[x]/getMagnitude()[x]) < 0)
221 getPhase()[x] += M_PI;
222 } else {
223 getPhase()[x] = 0;
224 }
225 }
226
227 Imaginary = buffer;
228 }
229
234 inline uint8_t *getMagnitude()
235 {
236 return Magnitude;
237 }
238
247 inline void setMagnitude(uint8_t *buffer)
248 {
249 int x = 0;
250 for(x = 0; x < getBufferSize(); x++) {
251 getReal()[x] = sin(getPhase()[x]*buffer[x]);
252 getImaginary()[x] = cos(getPhase()[x]*buffer[x]);
253 }
254
255 Magnitude = buffer;
256 }
257
262 inline uint8_t *getPhase()
263 {
264 return Phase;
265 }
266
275 inline void setPhase(uint8_t *buffer)
276 {
277 int x = 0;
278 for(x = 0; x < getBufferSize(); x++) {
279 getReal()[x] = sin(getPhase()[x]*buffer[x]);
280 getImaginary()[x] = cos(getPhase()[x]*buffer[x]);
281 }
282
283 Phase = buffer;
284 }
285
290 inline int getBPS() const
291 {
292 return BPS;
293 }
294
305 virtual void setMinMaxStep(const char *property, const char *element, double min, double max, double step,
306 bool sendToClient = true);
307
316 void setBufferSize(int nbuf, bool allocMem = true);
317
322 void setBPS(int bps);
323
330 void setIntegrationTime(double duration);
331
337 void setIntegrationLeft(double duration);
338
343
347 int getNAxis() const;
348
353 void setNAxis(int value);
354
359 void setIntegrationFileExtension(const char *ext);
360
365 {
366 return integrationExtention;
367 }
368
372 inline bool isCapturing() const
373 {
374 return (FramedIntegrationNP.s == IPS_BUSY);
375 }
376
388 virtual int SetTemperature(double temperature);
389
393 friend class StreamManager;
399 virtual bool StartStreaming();
400
405 virtual bool StopStreaming();
406
413 virtual bool StartIntegration(double duration);
414
421 virtual bool IntegrationComplete();
422
424 virtual bool Handshake();
425
431 void setSensorConnection(const uint8_t &value);
432
436 inline uint8_t getSensorConnection()
437 {
438 return sensorConnection;
439 }
440
459 virtual void addFITSKeywords(fitsfile *fptr, uint8_t* buf, int len);
460
462 void fits_update_key_s(fitsfile *fptr, int type, std::string name, void *p, std::string explanation, int *status);
463
466 {
467 return PortFD;
468 }
469
475
481
482 protected:
483
487 bool HasShutter() const
488 {
490 }
491
495 bool HasCooler() const
496 {
498 }
499
503 bool CanAbort() const
504 {
506 }
507
511 bool HasDSP()
512 {
514 {
515 if(DSP.get() == nullptr)
516 {
517 DSP.reset(new DSP::Manager(this));
518 }
519 return true;
520 }
521 return false;
522 }
523
528 {
530 {
531 if(Streamer.get() == nullptr)
532 {
533 Streamer.reset(new StreamManager(this));
534 Streamer->initProperties();
535 }
536 return true;
537 }
538 return false;
539 }
540
544 uint32_t GetCapability() const
545 {
546 return capability;
547 }
548
553 void SetCapability(uint32_t cap);
554
560 virtual bool AbortIntegration();
561
562 uint32_t capability;
563
566
569
574
577 enum
578 {
580 };
581
584
585
588
591 enum
592 {
595 };
596
599
600 // FITS Header
603 enum
604 {
607 };
608
614 virtual bool saveConfigItems(FILE *fp);
615
617
620 double RA, Dec;
621
625
629
633
635
636 // Sky Quality
637 double MPSAS;
638
643 virtual void activeDevicesUpdated() {}
644
647
648 // Threading
650
651 std::unique_ptr<StreamManager> Streamer;
652 std::unique_ptr<DSP::Manager> DSP;
655
657 int PortFD = -1;
658
659 private:
660 bool callHandshake();
661 uint8_t sensorConnection = CONNECTION_NONE;
662
663 int BPS;
665 int NAxis;
667 uint8_t *Continuum;
668 uint8_t *Real;
669 uint8_t *Imaginary;
670 uint8_t *Magnitude;
671 uint8_t *Phase;
672 int BufferSize;
673 double integrationTime;
674 double startIntegrationTime;
675 char integrationExtention[MAXINDIBLOBFMT];
676
677 bool uploadFile(const void *fitsData, size_t totalBytes, IBLOB blob, bool sendIntegration, bool saveIntegration);
678 void getMinMax(double *min, double *max, uint8_t *buf, int len, int bpp);
679 int getFileIndex(const char *dir, const char *prefix, const char *ext);
680
681 bool IntegrationCompletePrivate();
682 void* sendFITS(uint8_t* buf, int len, IBLOB blob);
683};
684}
double temperature
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 successful connection...
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
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)
uint8_t * getReal()
getBuffer Get real buffer of the stream of the Sensor device.
void setBPS(int bps)
setBPP Set depth of Sensor device.
Connection::TCP * getTcpConnection()
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...
enum INDI::SensorInterface::@467 SensorCapability
void setIntegrationLeft(double duration)
setIntegrationLeft Update Integration time left. Inform the client of the new Integration time left v...
void setImaginary(uint8_t *buffer)
setBuffer Set imaginary frame buffer pointer.
ITextVectorProperty ActiveDeviceTP
IBLOBVectorProperty FitsBP
virtual bool AbortIntegration()
Abort ongoing Integration.
uint8_t * getImaginary()
getBuffer Get imaginary 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)
enum INDI::SensorInterface::@468 SensorConnection
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
void setMagnitude(uint8_t *buffer)
setBuffer Set magnitude frame buffer pointer.
uint8_t * getMagnitude()
getBuffer Get magnitude buffer of the stream of the Sensor device.
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save configuration items in XML file.
virtual bool IntegrationComplete()
Uploads target Device exposed buffer as FITS to the client. Derived classes should class this functio...
ISwitchVectorProperty TelescopeTypeSP
void processProperties(const char *dev)
void setPhase(uint8_t *buffer)
setBuffer Set phase frame buffer pointer.
uint8_t * getBuffer()
getBuffer Get continuum buffer of the stream of the Sensor device.
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.
ISwitchVectorProperty UploadSP
virtual bool Handshake()
perform handshake with device to check communication
Connection::TCP * tcpConnection
bool processSnoopDevice(XMLEle *root)
void setReal(uint8_t *buffer)
setBuffer Set real frame buffer pointer.
Connection::Serial * getSerialConnection()
int getBPS() const
getBPS Get Sensor depth (bits per sample).
void setIntegrationFileExtension(const char *ext)
setIntegrationExtension Set integration extension
void setBuffer(uint8_t *buffer)
setBuffer Set continuum 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
uint8_t * getPhase()
getBuffer Get phase buffer of the stream of the Sensor device.
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.
#define M_PI
Definition dsp.h:52
double max(void)
#define min(a, b)
ISState
Switch state.
Definition indiapi.h:148
#define MAXINDIBLOBFMT
Definition indiapi.h:194
@ IPS_BUSY
Definition indiapi.h:161
The DSP Namespace adds signal processing to INDI drivers. Primarily written for sensors and detectors...
Namespace to encapsulate INDI client, drivers, and mediator classes.
uint16_t 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:469
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244
void uploadFile(const char *filename)
Definition stv.c:1710