Instrument Neutral Distributed Interface INDI 2.2.5
indiccd.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2010-2018 Jasem Mutlaq. All rights reserved.
3
4 Copyright(c) 2010, 2011 Gerry Rozema. All rights reserved.
5
6 Rapid Guide support added by CloudMakers, s. r. o.
7 Copyright(c) 2013 CloudMakers, s. r. o. All rights reserved.
8
9 Star detection algorithm is based on PHD Guiding by Craig Stark
10 Copyright (c) 2006-2010 Craig Stark. All rights reserved.
11
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Library General Public
14 License version 2 as published by the Free Software Foundation.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Library General Public License for more details.
20
21 You should have received a copy of the GNU Library General Public License
22 along with this library; see the file COPYING.LIB. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA.
25*******************************************************************************/
26
27#pragma once
28
29#include "indiccdchip.h"
30#include "defaultdevice.h"
31#include "indiguiderinterface.h"
32#include "indipropertynumber.h"
33#include "indipropertyswitch.h"
34#include "inditimer.h"
35#include "indielapsedtimer.h"
36#include "fitskeyword.h"
37#include "dsp/manager.h"
39
40
41#include <fitsio.h>
42
43#include <map>
44#include <cstring>
45#include <chrono>
46#include <stdint.h>
47#include <mutex>
48#include <thread>
49
50extern const char * IMAGE_SETTINGS_TAB;
51extern const char * IMAGE_INFO_TAB;
52extern const char * GUIDE_HEAD_TAB;
53//extern const char * RAPIDGUIDE_TAB;
54
55namespace DSP
56{
57class Manager;
58}
59namespace INDI
60{
61
62class StreamManager;
63class XISFWrapper;
64
108{
109 public:
110 CCD();
111 virtual ~CCD();
112
113 enum
114 {
115 CCD_CAN_BIN = 1 << 0,
117 CCD_CAN_ABORT = 1 << 2,
121 CCD_HAS_COOLER = 1 << 6,
122 CCD_HAS_BAYER = 1 << 7,
124 CCD_HAS_DSP = 1 << 10
126
128
129 typedef struct CaptureFormat
130 {
131 std::string name;
132 std::string label;
133 uint8_t bitsPerPixel {8};
134 bool isDefault {false};
135 bool isLittleEndian {true};
136 } CaptureFormat;
137
138 virtual bool initProperties() override;
139 virtual bool updateProperties() override;
140 virtual void ISGetProperties(const char * dev) override;
141 virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override;
142 virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override;
143 virtual bool ISNewText(const char * dev, const char * name, char * texts[], char * names[], int n) override;
144 virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[],
145 char *names[], int n) override;
146 virtual bool ISSnoopDevice(XMLEle * root) override;
147
148 static void wsThreadHelper(void * context);
149
153 static constexpr const char *GUIDE_CONTROL_TAB = "Guider Control";
154 static constexpr const char * WCS_TAB = "WCS";
155
156
157 protected:
161 uint32_t GetCCDCapability() const
162 {
163 return capability;
164 }
165
170 void SetCCDCapability(uint32_t cap);
171
175 bool CanAbort()
176 {
177 return capability & CCD_CAN_ABORT;
178 }
179
183 bool CanBin()
184 {
185 return capability & CCD_CAN_BIN;
186 }
187
192 {
193 return capability & CCD_CAN_SUBFRAME;
194 }
195
200 {
201 return capability & CCD_HAS_GUIDE_HEAD;
202 }
203
208 {
209 return capability & CCD_HAS_SHUTTER;
210 }
211
216 {
217 return capability & CCD_HAS_ST4_PORT;
218 }
219
224 {
225 return capability & CCD_HAS_COOLER;
226 }
227
231 bool HasBayer()
232 {
233 return capability & CCD_HAS_BAYER;
234 }
235
240 {
241 if (capability & CCD_HAS_STREAMING)
242 {
243 if(Streamer.get() == nullptr)
244 {
245 Streamer.reset(new StreamManager(this));
246 Streamer->initProperties();
247 }
248 return true;
249 }
250 return false;
251 }
252
253
257 bool HasDSP()
258 {
259 if (capability & CCD_HAS_DSP)
260 {
261 if(DSP.get() == nullptr)
262 {
263 DSP.reset(new DSP::Manager(this));
264 }
265 return true;
266 }
267 return false;
268 }
269
281 virtual int SetTemperature(double temperature);
282
289 virtual bool StartExposure(float duration);
290
297 virtual bool ExposureComplete(CCDChip * targetChip);
298
304 virtual bool AbortExposure();
305
312 virtual bool StartGuideExposure(float duration);
313
319 virtual bool AbortGuideExposure();
320
332 virtual bool UpdateCCDFrame(int x, int y, int w, int h);
333
345 virtual bool UpdateGuiderFrame(int x, int y, int w, int h);
346
355 virtual bool UpdateCCDBin(int hor, int ver);
356
365 virtual bool UpdateGuiderBin(int hor, int ver);
366
375 virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType);
376
385 {
386 INDI_UNUSED(mode);
387 return true;
388 }
389
398 virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType);
399
409 virtual void SetCCDParams(int x, int y, int bpp, float xf, float yf);
410
420 virtual void SetGuiderParams(int x, int y, int bpp, float xf, float yf);
421
428 virtual IPState GuideNorth(uint32_t ms) override;
429
436 virtual IPState GuideSouth(uint32_t ms) override;
437
444 virtual IPState GuideEast(uint32_t ms) override;
445
452 virtual IPState GuideWest(uint32_t ms) override;
453
458 virtual bool StartStreaming();
459
464 virtual bool StopStreaming();
465
471 virtual bool SetCaptureFormat(uint8_t index);
472
494 virtual void addFITSKeywords(CCDChip * targetChip, std::vector<FITSRecord> &fitsKeywords);
495
497 void fits_update_key_s(fitsfile * fptr, int type, std::string name, void * p, std::string explanation, int * status);
498
503 virtual void activeDevicesUpdated() {}
504
510 virtual bool saveConfigItems(FILE * fp) override;
511
516 virtual void GuideComplete(INDI_EQ_AXIS axis) override;
517
523 virtual void UploadComplete(CCDChip *) {}
524
530 virtual void checkTemperatureTarget();
531
539 virtual bool processFastExposure(CCDChip * targetChip);
540
548 virtual void addCaptureFormat(const CaptureFormat &format);
549
550 // Epoch Position
551 double RA, Dec;
552
553 // pier side, read from mount if available, set to -1 if not available
554 int pierSide; // West = 0, East =1. No enum available
555
556 // J2000 Position
557 double J2000RA;
558 double J2000DE;
560
561 // exposure information
564
568 //bool RapidGuideEnabled;
569 //bool GuiderRapidGuideEnabled;
570
577
580
581 // Sky Quality
582 double MPSAS;
583
584 // Rotator Angle
586
587 // Native absolute rotator position
589
590 // JJ ed 2019-12-10 current focuser position
593
594 // Airmass
595 double Airmass;
596 double Latitude;
597 double Longitude;
598 double Azimuth;
599 double Altitude;
600
601 // Temperature Control
605 // Tracking for warming-up stabilization detection (can't heat above ambient)
608 // Temperature when the ramp was initiated, used to compute expected ramp duration
610
611 // Threading
612 std::mutex ccdBufferLock;
613
614 std::vector<std::string> FilterNames;
616
617 std::vector<CaptureFormat> m_CaptureFormats;
618
619 std::unique_ptr<StreamManager> Streamer;
620 std::unique_ptr<DSP::Manager> DSP;
623
627
628
635
642 enum
643 {
646 };
647
657 enum
658 {
664 };
665
670
675 enum
676 {
679 };
680
685 enum
686 {
690 };
697
700
703 enum
704 {
708 };
709
711
713 enum
714 {
717 };
718
719 // Telescope Information
721 enum
722 {
725 };
726
727 // WCS
729 enum
730 {
733 };
734 // WCS CCD Rotation
736
737 // Fast Exposure Toggle
739
740 // Fast Exposure Frame Count
742 double m_UploadTime = { 0 };
743 std::chrono::system_clock::time_point FastExposureToggleStartup;
744
746 enum
747 {
751 };
752
753 private:
754 uint32_t capability;
755
756 bool m_ValidCCDRotation {false};
757 std::string m_ConfigCaptureFormatName;
758 int m_ConfigEncodeFormatIndex {-1};
759 int m_ConfigFastExposureIndex {INDI_DISABLED};
760
761 std::map<std::string, FITSRecord> m_CustomFITSKeywords;
762
766 bool uploadFile(CCDChip * targetChip, const void * fitsData, size_t totalBytes, bool sendImage, bool saveImage);
767 void getMinMax(double * min, double * max, CCDChip * targetChip);
768 int getFileIndex(const std::string &dir, const std::string &prefix, const std::string &ext);
769 bool ExposureCompletePrivate(CCDChip * targetChip);
770
774 friend class StreamManager;
776};
777}
double temperature
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition indiccdchip.h:39
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition indiccd.h:108
bool InGuideExposure
Definition indiccd.h:567
static constexpr const char * WCS_TAB
Definition indiccd.h:154
double m_InitialRampTemperature
Definition indiccd.h:609
virtual bool StartExposure(float duration)
Start exposing primary CCD chip.
Definition indiccd.cpp:1952
virtual bool processFastExposure(CCDChip *targetChip)
processFastExposure After an exposure is complete, check if fast exposure was enabled....
Definition indiccd.cpp:2818
std::chrono::system_clock::time_point FastExposureToggleStartup
Definition indiccd.h:743
double Longitude
Definition indiccd.h:597
CCDChip PrimaryCCD
Definition indiccd.h:621
INDI::PropertySwitch UploadSP
Definition indiccd.h:710
uint32_t GetCCDCapability() const
GetCCDCapability returns the CCD capabilities.
Definition indiccd.h:161
INDI::PropertySwitch WorldCoordSP
Definition indiccd.h:728
@ RAMP_THRESHOLD
Definition indiccd.h:678
@ RAMP_SLOPE
Definition indiccd.h:677
bool HasGuideHead()
Definition indiccd.h:199
@ UPLOAD_DIR
Definition indiccd.h:715
@ UPLOAD_PREFIX
Definition indiccd.h:716
std::unique_ptr< StreamManager > Streamer
Definition indiccd.h:619
bool HasCooler()
Definition indiccd.h:223
double J2000RA
Definition indiccd.h:557
@ KEYWORD_VALUE
Definition indiccd.h:749
@ KEYWORD_NAME
Definition indiccd.h:748
@ KEYWORD_COMMENT
Definition indiccd.h:750
bool InExposure
Definition indiccd.h:566
@ FOCAL_LENGTH
Definition indiccd.h:723
double GuiderExposureTime
Definition indiccd.h:579
void fits_update_key_s(fitsfile *fptr, int type, std::string name, void *p, std::string explanation, int *status)
Definition indiccd.cpp:2351
double Airmass
Definition indiccd.h:595
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override
Process the client newBLOB command.
Definition indiccd.cpp:1929
double m_TemperatureStabilizationValue
Definition indiccd.h:606
INDI::PropertyNumber EqNP
Properties.
Definition indiccd.h:634
bool CanAbort()
Definition indiccd.h:175
@ CFA_OFFSET_Y
Definition indiccd.h:688
@ CFA_OFFSET_X
Definition indiccd.h:687
INDI::Timer m_TemperatureCheckTimer
Definition indiccd.h:603
static constexpr const char * GUIDE_CONTROL_TAB
Group Names.
Definition indiccd.h:153
bool HasST4Port()
Definition indiccd.h:215
INDI::PropertyNumber CCDRotationNP
Definition indiccd.h:735
bool CanBin()
Definition indiccd.h:183
virtual void activeDevicesUpdated()
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
Definition indiccd.h:503
INDI::PropertyNumber FastExposureCountNP
Definition indiccd.h:741
INDI::PropertyText ActiveDeviceTP
ActiveDeviceTP defines 4 devices the camera driver can listen to (snoop) for properties of interest s...
Definition indiccd.h:656
virtual bool UpdateCCDFrame(int x, int y, int w, int h)
CCD calls this function when CCD Frame dimension needs to be updated in the hardware....
Definition indiccd.cpp:1988
virtual void addFITSKeywords(CCDChip *targetChip, std::vector< FITSRecord > &fitsKeywords)
Generate FITS keywords that will be added to FIST/XISF file.
Definition indiccd.cpp:2055
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition indiccd.cpp:1554
INDI::PropertyNumber TemperatureRampNP
Temperature Ramp in C/Min with configurable threshold.
Definition indiccd.h:674
bool SendImage
Definition indiccd.h:573
@ CCD_CAN_SUBFRAME
Definition indiccd.h:116
@ CCD_HAS_DSP
Definition indiccd.h:124
@ CCD_CAN_ABORT
Definition indiccd.h:117
@ CCD_HAS_GUIDE_HEAD
Definition indiccd.h:118
@ CCD_HAS_SHUTTER
Definition indiccd.h:120
@ CCD_HAS_BAYER
Definition indiccd.h:122
@ CCD_CAN_BIN
Definition indiccd.h:115
@ CCD_HAS_STREAMING
Definition indiccd.h:123
@ CCD_HAS_ST4_PORT
Definition indiccd.h:119
@ CCD_HAS_COOLER
Definition indiccd.h:121
double RotatorPosition
Definition indiccd.h:588
int CurrentFilterSlot
Definition indiccd.h:615
virtual bool ExposureComplete(CCDChip *targetChip)
Uploads target Chip exposed buffer as FITS to the client. Derived classes should class this function ...
Definition indiccd.cpp:2361
bool ShowMarker
Definition indiccd.h:575
virtual IPState GuideWest(uint32_t ms) override
Guide westward for ms milliseconds.
Definition indiccd.cpp:2995
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition indiccd.cpp:525
INDI::PropertyNumber TemperatureNP
TemperatureNP Camera Temperature in Celcius.
Definition indiccd.h:669
std::mutex ccdBufferLock
Definition indiccd.h:612
virtual int SetTemperature(double temperature)
Set CCD temperature.
Definition indiccd.cpp:1942
INDI::PropertyNumber ScopeInfoNP
Definition indiccd.h:720
INDI::PropertyNumber J2000EqNP
J200EqNP Snoop property to read the equatorial J2000 coordinates of the mount. ActiveDeviceTP defines...
Definition indiccd.h:641
INDI::PropertyText FITSHeaderTP
Definition indiccd.h:745
virtual bool UpdateGuiderFrame(int x, int y, int w, int h)
CCD calls this function when Guide head frame dimension is updated by the client. Derived classes sho...
Definition indiccd.cpp:1998
virtual bool UpdateCCDBin(int hor, int ver)
CCD calls this function when CCD Binning needs to be updated in the hardware. Derived classes should ...
Definition indiccd.cpp:2007
INDI::PropertySwitch FastExposureToggleSP
Definition indiccd.h:738
INDI::PropertySwitch EncodeFormatSP
Specifies Driver image encoding format (FITS, Native, JPG, ..etc)
Definition indiccd.h:702
double exposureDuration
Definition indiccd.h:563
virtual IPState GuideSouth(uint32_t ms) override
Guide southward for ms milliseconds.
Definition indiccd.cpp:2975
virtual bool SetCaptureFormat(uint8_t index)
SetCaptureFormat Set Active Capture format.
Definition indiccd.cpp:3286
bool GuiderAutoLoop
Definition indiccd.h:572
long FocuserPos
Definition indiccd.h:591
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition indiccd.cpp:157
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition indiccd.cpp:910
double snoopedAperture
Definition indiccd.h:565
virtual bool StartGuideExposure(float duration)
Start exposing guide CCD chip.
Definition indiccd.cpp:1961
double J2000DE
Definition indiccd.h:558
virtual bool AbortExposure()
Abort ongoing exposure.
Definition indiccd.cpp:1970
bool GuiderSendImage
Definition indiccd.h:574
CCD_UPLOAD_MODE
Definition indiccd.h:127
@ UPLOAD_BOTH
Definition indiccd.h:127
@ UPLOAD_LOCAL
Definition indiccd.h:127
@ UPLOAD_CLIENT
Definition indiccd.h:127
int pierSide
Definition indiccd.h:554
virtual IPState GuideNorth(uint32_t ms) override
Guide northward for ms milliseconds.
Definition indiccd.cpp:2965
INDI::PropertyText BayerTP
BayerTP Bayer pattern offset and type.
Definition indiccd.h:684
char exposureStartTime[MAXINDINAME]
Definition indiccd.h:562
virtual bool StartStreaming()
StartStreaming Start live video streaming.
Definition indiccd.cpp:3166
std::unique_ptr< DSP::Manager > DSP
Definition indiccd.h:620
virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType)
CCD calls this function when Guide frame type is updated by the client.
Definition indiccd.cpp:2045
INDI::PropertyText UploadSettingsTP
Definition indiccd.h:712
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition indiccd.cpp:540
virtual IPState GuideEast(uint32_t ms) override
Guide easward for ms milliseconds.
Definition indiccd.cpp:2985
virtual void addCaptureFormat(const CaptureFormat &format)
addCaptureFormat Add a supported camera native capture format (e.g. Mono, Bayer8.....
Definition indiccd.cpp:3264
friend class StreamManager
Misc.
Definition indiccd.h:774
double Azimuth
Definition indiccd.h:598
virtual void checkTemperatureTarget()
checkTemperatureTarget Checks the current temperature against target temperature and calculates the n...
Definition indiccd.cpp:3185
bool J2000Valid
Definition indiccd.h:559
double RotatorAngle
Definition indiccd.h:585
INDI::PropertyText FileNameTP
FileNameTP File name of locally-saved images. By default, images are uploaded to the client but when ...
Definition indiccd.h:696
std::vector< std::string > FilterNames
Definition indiccd.h:614
virtual void SetGuiderParams(int x, int y, int bpp, float xf, float yf)
Setup CCD parameters for guide head CCD. Child classes call this function to update CCD parameters.
Definition indiccd.cpp:2901
INDI::ElapsedTimer m_TemperatureElapsedTimer
Definition indiccd.h:604
virtual bool UpdateGuiderBin(int hor, int ver)
CCD calls this function when Guide head binning is updated by the client. Derived classes should impl...
Definition indiccd.cpp:2025
bool HasDSP()
Definition indiccd.h:257
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save configuration items in XML file.
Definition indiccd.cpp:2914
bool CanSubFrame()
Definition indiccd.h:191
bool HasStreaming()
Definition indiccd.h:239
virtual void GuideComplete(INDI_EQ_AXIS axis) override
GuideComplete Signal guide pulse completion.
Definition indiccd.cpp:3158
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition indiccd.cpp:729
virtual void UploadComplete(CCDChip *)
UploadComplete Signal that capture is completed and image was uploaded and/or saved successfully.
Definition indiccd.h:523
bool GuiderShowMarker
Definition indiccd.h:576
INDI::PropertySwitch CaptureFormatSP
Specifies Camera NATIVE capture format (e.g. Mono, RGB, RAW8..etc).
Definition indiccd.h:699
enum INDI::CCD::@421 CCDCapability
void SetCCDCapability(uint32_t cap)
SetCCDCapability Set the CCD capabilities. All fields must be initialized.
Definition indiccd.cpp:140
bool AutoLoop
Definition indiccd.h:571
@ WCS_DISABLE
Definition indiccd.h:732
@ WCS_ENABLE
Definition indiccd.h:731
bool HasBayer()
Definition indiccd.h:231
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition indiccd.cpp:1143
@ ACTIVE_TELESCOPE
Definition indiccd.h:659
@ ACTIVE_FILTER
Definition indiccd.h:662
@ ACTIVE_FOCUSER
Definition indiccd.h:661
@ ACTIVE_SKYQUALITY
Definition indiccd.h:663
@ ACTIVE_ROTATOR
Definition indiccd.h:660
double Latitude
Definition indiccd.h:596
bool HasShutter()
Definition indiccd.h:207
double MPSAS
Definition indiccd.h:582
CCDChip GuideCCD
Definition indiccd.h:622
static void wsThreadHelper(void *context)
virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType)
CCD calls this function when CCD frame type needs to be updated in the hardware.
Definition indiccd.cpp:2035
@ FORMAT_NATIVE
Definition indiccd.h:706
@ FORMAT_XISF
Definition indiccd.h:707
@ FORMAT_FITS
Definition indiccd.h:705
double RA
Definition indiccd.h:551
virtual void SetCCDParams(int x, int y, int bpp, float xf, float yf)
Setup CCD parameters for primary CCD. Child classes call this function to update CCD parameters.
Definition indiccd.cpp:2888
virtual bool UpdateCCDUploadMode(CCD_UPLOAD_MODE mode)
CCD calls this function when client upload mode switch is updated.
Definition indiccd.h:384
virtual ~CCD()
Definition indiccd.cpp:130
virtual bool StopStreaming()
StopStreaming Stop live video streaming.
Definition indiccd.cpp:3175
double snoopedFocalLength
Definition indiccd.h:565
double FocuserTemp
Definition indiccd.h:592
std::vector< CaptureFormat > m_CaptureFormats
Definition indiccd.h:617
double m_UploadTime
Definition indiccd.h:742
double m_TargetTemperature
Definition indiccd.h:602
INDI::ElapsedTimer m_TemperatureStabilizationTimer
Definition indiccd.h:607
virtual bool AbortGuideExposure()
Abort ongoing exposure.
Definition indiccd.cpp:1979
double Altitude
Definition indiccd.h:599
double Dec
Definition indiccd.h:551
double ExposureTime
Definition indiccd.h:578
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
The ElapsedTimer class provides a fast way to calculate elapsed times.
The Timer class provides repetitive and single-shot timers.
Definition inditimer.h:41
Class to provide video streaming and recording functionality.
double max(void)
#define min(a, b)
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
#define MAXINDINAME
Definition indiapi.h:189
INDI_EQ_AXIS
const char * IMAGE_SETTINGS_TAB
Definition indiccd.cpp:62
const char * IMAGE_INFO_TAB
Definition indiccd.cpp:63
const char * GUIDE_HEAD_TAB
Definition indiccd.cpp:64
#define INDI_UNUSED(x)
Definition indidevapi.h:132
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