Instrument Neutral Distributed Interface INDI 2.2.5
indiccd.cpp
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// use 64-bit values when calling stat()
28#define _FILE_OFFSET_BITS 64
29
30#include "indiccd.h"
31
32#include "fpack/fpack.h"
33#include "indicom.h"
34#include "locale_compat.h"
35#include "indiutility.h"
36
37#ifdef HAVE_XISF
38#include <libxisf.h>
39#endif
40
41#include <fitsio.h>
42
43#include <libnova/julian_day.h>
44#include <libnova/precession.h>
45#include <libnova/airmass.h>
46#include <libnova/transform.h>
47#include <libnova/ln_types.h>
48#include <libastro.h>
49
50#include <iomanip>
51#include <cmath>
52#include <regex>
53#include <iterator>
54#include <variant>
55
56#include <dirent.h>
57#include <cerrno>
58#include <cstdlib>
59#include <zlib.h>
60#include <sys/stat.h>
61
62const char * IMAGE_SETTINGS_TAB = "Image Settings";
63const char * IMAGE_INFO_TAB = "Image Info";
64const char * GUIDE_HEAD_TAB = "Guider Head";
65//const char * RAPIDGUIDE_TAB = "Rapid Guide";
66
67
68std::string join(std::vector<std::string> const &strings, std::string delim)
69{
70 std::stringstream ss;
71 std::copy(strings.begin(), strings.end(),
72 std::ostream_iterator<std::string>(ss, delim.c_str()));
73 return ss.str();
74}
75
76namespace INDI
77{
78
79CCD::CCD() : GI(this)
80{
81 //ctor
82 capability = 0;
83
84 InExposure = false;
85 InGuideExposure = false;
86 //RapidGuideEnabled = false;
87 //GuiderRapidGuideEnabled = false;
88 m_ValidCCDRotation = false;
89
90 AutoLoop = false;
91 SendImage = false;
92 ShowMarker = false;
93 GuiderAutoLoop = false;
94 GuiderSendImage = false;
95 GuiderShowMarker = false;
96
97 ExposureTime = 0.0;
100
101 RA = std::numeric_limits<double>::quiet_NaN();
102 Dec = std::numeric_limits<double>::quiet_NaN();
103 pierSide = -1;
104 J2000RA = std::numeric_limits<double>::quiet_NaN();
105 J2000DE = std::numeric_limits<double>::quiet_NaN();
106 J2000Valid = false;
107 MPSAS = std::numeric_limits<double>::quiet_NaN();
108 RotatorAngle = std::numeric_limits<double>::quiet_NaN();
109 RotatorPosition = std::numeric_limits<double>::quiet_NaN();
110 // JJ ed 2019-12-10
111 FocuserPos = -1;
112 FocuserTemp = std::numeric_limits<double>::quiet_NaN();
113
114 Airmass = std::numeric_limits<double>::quiet_NaN();
115 Latitude = std::numeric_limits<double>::quiet_NaN();
116 Longitude = std::numeric_limits<double>::quiet_NaN();
117 Azimuth = std::numeric_limits<double>::quiet_NaN();
118 Altitude = std::numeric_limits<double>::quiet_NaN();
119 snoopedAperture = std::numeric_limits<double>::quiet_NaN();
120 snoopedFocalLength = std::numeric_limits<double>::quiet_NaN();
121
122 // Check temperature every 5 seconds.
123 m_TemperatureCheckTimer.setInterval(5000);
124 m_TemperatureCheckTimer.callOnTimeout(std::bind(&CCD::checkTemperatureTarget, this));
125
126 exposureStartTime[0] = 0;
127 exposureDuration = 0.0;
128}
129
131{
132 // Only update if index is different.
133 if (m_ConfigFastExposureIndex != FastExposureToggleSP.findOnSwitchIndex())
135}
136
138//
140void CCD::SetCCDCapability(uint32_t cap)
141{
142 capability = cap;
143
144 if (HasST4Port())
146 else
148
150 HasStreaming();
151 HasDSP();
152}
153
155//
158{
160
161 // CCD Temperature
162 // @INDI_STANDARD_PROPERTY@
163 TemperatureNP[0].fill("CCD_TEMPERATURE_VALUE", "Temperature (C)", "%5.2f", -50.0, 50.0, 0., 0.);
164 TemperatureNP.fill(getDeviceName(), "CCD_TEMPERATURE", "Temperature",
166
167 // Camera temperature ramp
168 // @INDI_STANDARD_PROPERTY@
169 TemperatureRampNP[RAMP_SLOPE].fill("RAMP_SLOPE", "Max. dT (C/min)", "%.f", 0, 30, 1, 0);
170 TemperatureRampNP[RAMP_THRESHOLD].fill("RAMP_THRESHOLD", "Threshold (C)", "%.1f", 0.1, 2, 0.1, 0.2);
171 TemperatureRampNP.fill(getDeviceName(), "CCD_TEMP_RAMP", "Temp. Ramp", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
172
173 /**********************************************/
174 /**************** Primary Chip ****************/
175 /**********************************************/
176
177 // Primary CCD Region-Of-Interest (ROI)
178 // @INDI_STANDARD_PROPERTY@
179 PrimaryCCD.ImageFrameNP[CCDChip::FRAME_X].fill("X", "Left ", "%4.0f", 0, 0.0, 0, 0);
180 PrimaryCCD.ImageFrameNP[CCDChip::FRAME_Y].fill("Y", "Top", "%4.0f", 0, 0, 0, 0);
181 PrimaryCCD.ImageFrameNP[CCDChip::FRAME_W].fill("WIDTH", "Width", "%4.0f", 0, 0.0, 0, 0.0);
182 PrimaryCCD.ImageFrameNP[CCDChip::FRAME_H].fill("HEIGHT", "Height", "%4.0f", 0, 0, 0, 0.0);
183 PrimaryCCD.ImageFrameNP.fill(getDeviceName(), "CCD_FRAME", "Frame",
185
186 // Primary CCD Frame Type
187 // @INDI_STANDARD_PROPERTY@
188 PrimaryCCD.FrameTypeSP[CCDChip::LIGHT_FRAME].fill("FRAME_LIGHT", "Light", ISS_ON);
189 PrimaryCCD.FrameTypeSP[CCDChip::BIAS_FRAME].fill("FRAME_BIAS", "Bias", ISS_OFF);
190 PrimaryCCD.FrameTypeSP[CCDChip::DARK_FRAME].fill("FRAME_DARK", "Dark", ISS_OFF);
191 PrimaryCCD.FrameTypeSP[CCDChip::FLAT_FRAME].fill("FRAME_FLAT", "Flat", ISS_OFF);
192 PrimaryCCD.FrameTypeSP.fill(getDeviceName(), "CCD_FRAME_TYPE",
194
195 // Primary CCD Exposure
196 // @INDI_STANDARD_PROPERTY@
197 PrimaryCCD.ImageExposureNP[0].fill("CCD_EXPOSURE_VALUE", "Duration (s)", "%5.2f", 0.01, 3600, 1.0, 1.0);
198 PrimaryCCD.ImageExposureNP.fill(getDeviceName(), "CCD_EXPOSURE",
199 "Expose", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
200
201 // Primary CCD Abort
202 // @INDI_STANDARD_PROPERTY@
203 PrimaryCCD.AbortExposureSP[0].fill("ABORT", "Abort", ISS_OFF);
204 PrimaryCCD.AbortExposureSP.fill(getDeviceName(), "CCD_ABORT_EXPOSURE",
206
207 // Primary CCD Binning
208 // @INDI_STANDARD_PROPERTY@
209 PrimaryCCD.ImageBinNP[CCDChip::HOR_BIN].fill("HOR_BIN", "X", "%2.0f", 1, 4, 1, 1);
210 PrimaryCCD.ImageBinNP[CCDChip::VER_BIN].fill("VER_BIN", "Y", "%2.0f", 1, 4, 1, 1);
211 PrimaryCCD.ImageBinNP.fill(getDeviceName(), "CCD_BINNING", "Binning",
213
214 // Primary CCD Info
215 // @INDI_STANDARD_PROPERTY@
216 PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_MAX_X].fill("CCD_MAX_X", "Max. Width", "%.f", 1, 16000, 0, 0);
217 PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_MAX_Y].fill("CCD_MAX_Y", "Max. Height", "%.f", 1, 16000, 0, 0);
218 PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE].fill("CCD_PIXEL_SIZE", "Pixel size (um)", "%.2f", 1,
219 40, 0, 0);
220 PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE_X].fill("CCD_PIXEL_SIZE_X", "Pixel size X", "%.2f", 1,
221 40, 0, 0);
222 PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE_Y].fill("CCD_PIXEL_SIZE_Y", "Pixel size Y", "%.2f", 1,
223 40, 0, 0);
224 PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_BITSPERPIXEL].fill("CCD_BITSPERPIXEL", "Bits per pixel", "%.f",
225 8, 64, 0, 0);
226 PrimaryCCD.ImagePixelSizeNP.fill(getDeviceName(), "CCD_INFO",
227 "CCD Information", IMAGE_INFO_TAB, IP_RO, 60, IPS_IDLE);
228
229 // Primary CCD Compression Options
230 // @INDI_STANDARD_PROPERTY@
231 PrimaryCCD.CompressSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_OFF);
232 PrimaryCCD.CompressSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled", ISS_ON);
233 PrimaryCCD.CompressSP.fill(getDeviceName(), "CCD_COMPRESSION", "Compression",
235 PrimaryCCD.SendCompressed = false;
236
237 // Primary CCD Chip Data Blob
238 // @INDI_STANDARD_PROPERTY@
239 PrimaryCCD.FitsBP[0].fill("CCD1", "Image", "");
240 PrimaryCCD.FitsBP.fill(getDeviceName(), "CCD1", "Image Data", IMAGE_INFO_TAB,
241 IP_RO, 60, IPS_IDLE);
242
243 // Bayer
244 // @INDI_STANDARD_PROPERTY@
245 BayerTP[CFA_OFFSET_X].fill("CFA_OFFSET_X", "X Offset", "0");
246 BayerTP[CFA_OFFSET_Y].fill("CFA_OFFSET_Y", "Y Offset", "0");
247 BayerTP[CFA_TYPE].fill("CFA_TYPE", "Filter", nullptr);
248 BayerTP.fill(getDeviceName(), "CCD_CFA", "Bayer Info", IMAGE_INFO_TAB, IP_RW, 60,
249 IPS_IDLE);
250
251 // Reset Frame Settings
252 // @INDI_STANDARD_PROPERTY@
253 PrimaryCCD.ResetSP[0].fill("RESET", "Reset", ISS_OFF);
254 PrimaryCCD.ResetSP.fill(getDeviceName(), "CCD_FRAME_RESET", "Frame Values",
256
257 /**********************************************/
258 /********* Primary Chip Rapid Guide **********/
259 /**********************************************/
260#if 0
261 IUFillSwitch(&PrimaryCCD.RapidGuideS[0], "ENABLE", "Enable", ISS_OFF);
262 IUFillSwitch(&PrimaryCCD.RapidGuideS[1], "DISABLE", "Disable", ISS_ON);
263 IUFillSwitchVector(&PrimaryCCD.RapidGuideSP, PrimaryCCD.RapidGuideS, 2, getDeviceName(), "CCD_RAPID_GUIDE",
264 "Rapid Guide", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
265
266 IUFillSwitch(&PrimaryCCD.RapidGuideSetupS[0], "AUTO_LOOP", "Auto loop", ISS_ON);
267 IUFillSwitch(&PrimaryCCD.RapidGuideSetupS[1], "SEND_IMAGE", "Send image", ISS_OFF);
268 IUFillSwitch(&PrimaryCCD.RapidGuideSetupS[2], "SHOW_MARKER", "Show marker", ISS_OFF);
269 IUFillSwitchVector(&PrimaryCCD.RapidGuideSetupSP, PrimaryCCD.RapidGuideSetupS, 3, getDeviceName(),
270 "CCD_RAPID_GUIDE_SETUP", "Rapid Guide Setup", RAPIDGUIDE_TAB, IP_RW, ISR_NOFMANY, 0, IPS_IDLE);
271
272 IUFillNumber(&PrimaryCCD.RapidGuideDataN[0], "GUIDESTAR_X", "Guide star position X", "%5.2f", 0, 1024, 0, 0);
273 IUFillNumber(&PrimaryCCD.RapidGuideDataN[1], "GUIDESTAR_Y", "Guide star position Y", "%5.2f", 0, 1024, 0, 0);
274 IUFillNumber(&PrimaryCCD.RapidGuideDataN[2], "GUIDESTAR_FIT", "Guide star fit", "%5.2f", 0, 1024, 0, 0);
275 IUFillNumberVector(&PrimaryCCD.RapidGuideDataNP, PrimaryCCD.RapidGuideDataN, 3, getDeviceName(),
276 "CCD_RAPID_GUIDE_DATA", "Rapid Guide Data", RAPIDGUIDE_TAB, IP_RO, 60, IPS_IDLE);
277#endif
278
279 /**********************************************/
280 /***************** Guide Chip *****************/
281 // Deprecated. Will be removed in future
282 /**********************************************/
283 GuideCCD.ImageFrameNP[CCDChip::FRAME_X].fill("X", "Left ", "%4.0f", 0, 0, 0, 0);
284 GuideCCD.ImageFrameNP[CCDChip::FRAME_Y].fill("Y", "Top", "%4.0f", 0, 0, 0, 0);
285 GuideCCD.ImageFrameNP[CCDChip::FRAME_W].fill("WIDTH", "Width", "%4.0f", 0, 0, 0, 0);
286 GuideCCD.ImageFrameNP[CCDChip::FRAME_H].fill("HEIGHT", "Height", "%4.0f", 0, 0, 0, 0);
287 GuideCCD.ImageFrameNP.fill(getDeviceName(), "GUIDER_FRAME", "Frame",
289
290 GuideCCD.ImageBinNP[CCDChip::HOR_BIN].fill("HOR_BIN", "X", "%2.0f", 1, 4, 1, 1);
291 GuideCCD.ImageBinNP[CCDChip::VER_BIN].fill("VER_BIN", "Y", "%2.0f", 1, 4, 1, 1);
292 GuideCCD.ImageBinNP.fill(getDeviceName(), "GUIDER_BINNING", "Binning",
294
295 GuideCCD.ImagePixelSizeNP[CCDChip::CCD_MAX_X].fill("CCD_MAX_X", "Max. Width", "%4.0f", 1, 16000, 0, 0);
296 GuideCCD.ImagePixelSizeNP[CCDChip::CCD_MAX_Y].fill("CCD_MAX_Y", "Max. Height", "%4.0f", 1, 16000, 0, 0);
297 GuideCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE].fill("CCD_PIXEL_SIZE", "Pixel size (um)", "%5.2f", 1,
298 40, 0, 0);
299 GuideCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE_X].fill("CCD_PIXEL_SIZE_X", "Pixel size X", "%5.2f", 1,
300 40, 0, 0);
301 GuideCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE_Y].fill("CCD_PIXEL_SIZE_Y", "Pixel size Y", "%5.2f", 1,
302 40, 0, 0);
303 GuideCCD.ImagePixelSizeNP[CCDChip::CCD_BITSPERPIXEL].fill("CCD_BITSPERPIXEL", "Bits per pixel", "%3.0f", 8,
304 64, 0, 0);
305 GuideCCD.ImagePixelSizeNP.fill(getDeviceName(), "GUIDER_INFO",
306 "Info", IMAGE_INFO_TAB, IP_RO, 60, IPS_IDLE);
307
308 GuideCCD.FrameTypeSP[CCDChip::LIGHT_FRAME].fill("FRAME_LIGHT", "Light", ISS_ON);
309 GuideCCD.FrameTypeSP[CCDChip::BIAS_FRAME].fill("FRAME_BIAS", "Bias", ISS_OFF);
310 GuideCCD.FrameTypeSP[CCDChip::DARK_FRAME].fill("FRAME_DARK", "Dark", ISS_OFF);
311 GuideCCD.FrameTypeSP[CCDChip::FLAT_FRAME].fill("FRAME_FLAT", "Flat", ISS_OFF);
312 GuideCCD.FrameTypeSP.fill(getDeviceName(), "GUIDER_FRAME_TYPE",
314
315 GuideCCD.ImageExposureNP[0].fill("GUIDER_EXPOSURE_VALUE", "Duration (s)", "%5.2f", 0.01, 3600, 1.0, 1.0);
316 GuideCCD.ImageExposureNP.fill(getDeviceName(), "GUIDER_EXPOSURE",
317 "Guide Head", MAIN_CONTROL_TAB, IP_RW, 60, IPS_IDLE);
318
319 GuideCCD.AbortExposureSP[0].fill("ABORT", "Abort", ISS_OFF);
320 GuideCCD.AbortExposureSP.fill(getDeviceName(), "GUIDER_ABORT_EXPOSURE",
322
323 GuideCCD.CompressSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_OFF);
324 GuideCCD.CompressSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled", ISS_ON);
325 GuideCCD.CompressSP.fill(getDeviceName(), "GUIDER_COMPRESSION", "Compression",
327 GuideCCD.SendCompressed = false;
328
329 GuideCCD.FitsBP[0].fill("CCD2", "Guider Image", "");
330 GuideCCD.FitsBP.fill(getDeviceName(), "CCD2", "Image Data", IMAGE_INFO_TAB, IP_RO,
331 60, IPS_IDLE);
332
333 /**********************************************/
334 /********* Guider Chip Rapid Guide ***********/
335 // Deprecated. Will be removed in future release
336 /**********************************************/
337
338#if 0
339 IUFillSwitch(&GuideCCD.RapidGuideS[0], "ENABLE", "Enable", ISS_OFF);
340 IUFillSwitch(&GuideCCD.RapidGuideS[1], "DISABLE", "Disable", ISS_ON);
341 IUFillSwitchVector(&GuideCCD.RapidGuideSP, GuideCCD.RapidGuideS, 2, getDeviceName(), "GUIDER_RAPID_GUIDE",
342 "Guider Head Rapid Guide", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
343
344 IUFillSwitch(&GuideCCD.RapidGuideSetupS[0], "AUTO_LOOP", "Auto loop", ISS_ON);
345 IUFillSwitch(&GuideCCD.RapidGuideSetupS[1], "SEND_IMAGE", "Send image", ISS_OFF);
346 IUFillSwitch(&GuideCCD.RapidGuideSetupS[2], "SHOW_MARKER", "Show marker", ISS_OFF);
347 IUFillSwitchVector(&GuideCCD.RapidGuideSetupSP, GuideCCD.RapidGuideSetupS, 3, getDeviceName(),
348 "GUIDER_RAPID_GUIDE_SETUP", "Rapid Guide Setup", RAPIDGUIDE_TAB, IP_RW, ISR_NOFMANY, 0,
349 IPS_IDLE);
350
351 IUFillNumber(&GuideCCD.RapidGuideDataN[0], "GUIDESTAR_X", "Guide star position X", "%5.2f", 0, 1024, 0, 0);
352 IUFillNumber(&GuideCCD.RapidGuideDataN[1], "GUIDESTAR_Y", "Guide star position Y", "%5.2f", 0, 1024, 0, 0);
353 IUFillNumber(&GuideCCD.RapidGuideDataN[2], "GUIDESTAR_FIT", "Guide star fit", "%5.2f", 0, 1024, 0, 0);
354 IUFillNumberVector(&GuideCCD.RapidGuideDataNP, GuideCCD.RapidGuideDataN, 3, getDeviceName(),
355 "GUIDER_RAPID_GUIDE_DATA", "Rapid Guide Data", RAPIDGUIDE_TAB, IP_RO, 60, IPS_IDLE);
356
357#endif
358
359 /**********************************************/
360 /******************** WCS *********************/
361 /**********************************************/
362
363 // WCS Enable/Disable
364 // @INDI_STANDARD_PROPERTY@
365 WorldCoordSP[WCS_ENABLE].fill("WCS_ENABLE", "Enable", ISS_OFF);
366 WorldCoordSP[WCS_DISABLE].fill("WCS_DISABLE", "Disable", ISS_ON);
367 WorldCoordSP.fill(getDeviceName(), "WCS_CONTROL", "WCS", WCS_TAB, IP_RW,
369
370 // Camera Rotation E of N in degrees following Astrometry notation with row order Down - Top
371 // TS 06-2025: Has to be transformed accordingly for KSTARS Top - Down, see KSUtils::rotationToPositionAngle(orientation)
372 // @INDI_STANDARD_PROPERTY@
373 CCDRotationNP[0].fill("CCD_ROTATION_VALUE", "Angle", "%.2f", -360, 360, 1, 0);
374 CCDRotationNP.fill(getDeviceName(), "CCD_ROTATION", "Orientation", WCS_TAB, IP_RW, 60,
375 IPS_IDLE);
376
377 // Scope focal length and aperture
378 // @INDI_STANDARD_PROPERTY@
379 ScopeInfoNP[FOCAL_LENGTH].fill("FOCAL_LENGTH", "Focal Length (mm)", "%g", 0, 10000, 1, 0);
380 ScopeInfoNP[APERTURE].fill("APERTURE", "Aperture (mm)", "%g", 0, 3000, 1, 0);
381 ScopeInfoNP.fill(getDeviceName(), "SCOPE_INFO", "Scope", OPTIONS_TAB, IP_RW, 60, IPS_IDLE);
382
383 /**********************************************/
384 /************** Capture Format ***************/
385 /**********************************************/
386 char configName[64] = {0};
387 if (IUGetConfigOnSwitchName(getDeviceName(), "CCD_CAPTURE_FORMAT", configName, MAXINDINAME) == 0)
388 m_ConfigCaptureFormatName = configName;
389 // @INDI_STANDARD_PROPERTY@
390 CaptureFormatSP.fill(getDeviceName(), "CCD_CAPTURE_FORMAT", "Format", IMAGE_SETTINGS_TAB, IP_RW, ISR_1OFMANY, 60,
391 IPS_IDLE);
392
393 m_ConfigEncodeFormatIndex = FORMAT_FITS;
394 IUGetConfigOnSwitchIndex(getDeviceName(), "CCD_TRANSFER_FORMAT", &m_ConfigEncodeFormatIndex);
395 EncodeFormatSP[FORMAT_FITS].fill("FORMAT_FITS", "FITS",
396 m_ConfigEncodeFormatIndex == FORMAT_FITS ? ISS_ON : ISS_OFF);
397 EncodeFormatSP[FORMAT_NATIVE].fill("FORMAT_NATIVE", "Native",
398 m_ConfigEncodeFormatIndex == FORMAT_NATIVE ? ISS_ON : ISS_OFF);
399#ifdef HAVE_XISF
400 EncodeFormatSP[FORMAT_XISF].fill("FORMAT_XISF", "XISF",
401 m_ConfigEncodeFormatIndex == FORMAT_XISF ? ISS_ON : ISS_OFF);
402#endif
403 EncodeFormatSP.fill(getDeviceName(), "CCD_TRANSFER_FORMAT", "Encode", IMAGE_SETTINGS_TAB, IP_RW, ISR_1OFMANY, 60,
404 IPS_IDLE);
405
406 /**********************************************/
407 /************** Upload Settings ***************/
408 /**********************************************/
409
410 // Upload Mode
411 // @INDI_STANDARD_PROPERTY@
412 UploadSP[UPLOAD_CLIENT].fill("UPLOAD_CLIENT", "Client", ISS_ON);
413 UploadSP[UPLOAD_LOCAL].fill("UPLOAD_LOCAL", "Local", ISS_OFF);
414 UploadSP[UPLOAD_BOTH].fill("UPLOAD_BOTH", "Both", ISS_OFF);
415 UploadSP.fill(getDeviceName(), "UPLOAD_MODE", "Upload", OPTIONS_TAB, IP_RW, ISR_1OFMANY,
416 0, IPS_IDLE);
417
418 // Upload Settings
419 // @INDI_STANDARD_PROPERTY@
420 UploadSettingsTP[UPLOAD_DIR].fill("UPLOAD_DIR", "Dir", "");
421 UploadSettingsTP[UPLOAD_PREFIX].fill("UPLOAD_PREFIX", "Prefix", "IMAGE_XXX");
422 UploadSettingsTP.fill(getDeviceName(), "UPLOAD_SETTINGS", "Upload Settings",
424
425 // Upload File Path
426 // @INDI_STANDARD_PROPERTY@
427 FileNameTP[0].fill("FILE_PATH", "Path", "");
428 FileNameTP.fill(getDeviceName(), "CCD_FILE_PATH", "Filename", IMAGE_INFO_TAB, IP_RO, 60,
429 IPS_IDLE);
430
431 /**********************************************/
432 /****************** FITS Header****************/
433 /**********************************************/
434
435 // @INDI_STANDARD_PROPERTY@
436 FITSHeaderTP[KEYWORD_NAME].fill("KEYWORD_NAME", "Name", nullptr);
437 FITSHeaderTP[KEYWORD_VALUE].fill("KEYWORD_VALUE", "Value", nullptr);
438 FITSHeaderTP[KEYWORD_COMMENT].fill("KEYWORD_COMMENT", "Comment", nullptr);
439 FITSHeaderTP.fill(getDeviceName(), "FITS_HEADER", "FITS Header", INFO_TAB, IP_WO, 60, IPS_IDLE);
440
441 /**********************************************/
442 /****************** Exposure Looping **********/
443 /***************** Primary CCD Only ***********/
444 IUGetConfigOnSwitchIndex(getDeviceName(), FastExposureToggleSP.getName(), &m_ConfigFastExposureIndex);
445 // @INDI_STANDARD_PROPERTY@
446 FastExposureToggleSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled",
447 m_ConfigFastExposureIndex == INDI_ENABLED ? ISS_ON : ISS_OFF);
448 FastExposureToggleSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled",
449 m_ConfigFastExposureIndex == INDI_DISABLED ? ISS_ON : ISS_OFF);
450 FastExposureToggleSP.fill(getDeviceName(), "CCD_FAST_TOGGLE", "Fast Exposure",
452
453 // CCD Should loop until the number of frames specified in this property is completed
454 // @INDI_STANDARD_PROPERTY@
455 FastExposureCountNP[0].fill("FRAMES", "Frames", "%.f", 0, 100000, 1, 1);
456 FastExposureCountNP.fill(getDeviceName(), "CCD_FAST_COUNT", "Fast Count",
458
459 /**********************************************/
460 /**************** Snooping ********************/
461 /**********************************************/
462
463 // Snooped Devices
464 // @INDI_STANDARD_PROPERTY@
465 ActiveDeviceTP[ACTIVE_TELESCOPE].fill("ACTIVE_TELESCOPE", "Telescope", "Telescope Simulator");
466 ActiveDeviceTP[ACTIVE_ROTATOR].fill("ACTIVE_ROTATOR", "Rotator", "Rotator Simulator");
467 ActiveDeviceTP[ACTIVE_FOCUSER].fill("ACTIVE_FOCUSER", "Focuser", "Focuser Simulator");
468 ActiveDeviceTP[ACTIVE_FILTER].fill("ACTIVE_FILTER", "Filter", "CCD Simulator");
469 ActiveDeviceTP[ACTIVE_SKYQUALITY].fill("ACTIVE_SKYQUALITY", "Sky Quality", "SQM");
470 ActiveDeviceTP.fill(getDeviceName(), "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB, IP_RW, 60, IPS_IDLE);
471 ActiveDeviceTP.load();
472
473 auto mount = ActiveDeviceTP[ACTIVE_TELESCOPE].getText() ? ActiveDeviceTP[ACTIVE_TELESCOPE].getText() : "";
474 // Snooped RA/DEC Property
475 EqNP[Ra].fill("RA", "Ra (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
476 EqNP[DEC].fill("DEC", "Dec (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
477 EqNP.fill(mount, "EQUATORIAL_EOD_COORD", "EQ Coord", "Main Control", IP_RW, 60, IPS_IDLE);
478
479 // Snooped J2000 RA/DEC Property
480 J2000EqNP[Ra].fill("RA", "Ra (hh:mm:ss)", "%010.6m", 0, 24, 0, 0);
481 J2000EqNP[DEC].fill("DEC", "Dec (dd:mm:ss)", "%010.6m", -90, 90, 0, 0);
482 J2000EqNP.fill(mount, "EQUATORIAL_COORD", "J2000 EQ Coord",
483 "Main Control", IP_RW,
484 60, IPS_IDLE);
485
486 // Snoop properties of interest
487
488 // Snoop mount
489 IDSnoopDevice(mount, "EQUATORIAL_EOD_COORD");
490 IDSnoopDevice(mount, "EQUATORIAL_COORD");
491 IDSnoopDevice(mount, "TELESCOPE_INFO");
492 IDSnoopDevice(mount, "GEOGRAPHIC_COORD");
493 IDSnoopDevice(mount, "TELESCOPE_PIER_SIDE");
494
495 // Snoop Rotator
496 IDSnoopDevice(ActiveDeviceTP[ACTIVE_ROTATOR].getText(), "ABS_ROTATOR_ANGLE");
497 IDSnoopDevice(ActiveDeviceTP[ACTIVE_ROTATOR].getText(), "ABS_ROTATOR_POSITION");
498
499 // JJ ed 2019-12-10
500 // Snoop Focuser
501 IDSnoopDevice(ActiveDeviceTP[ACTIVE_FOCUSER].getText(), "ABS_FOCUS_POSITION");
502 IDSnoopDevice(ActiveDeviceTP[ACTIVE_FOCUSER].getText(), "FOCUS_TEMPERATURE");
503 //
504
505 // Snoop Filter Wheel
508
509 // Snoop Sky Quality Meter
511
512 // Guider Interface
514
516
518
519 return true;
520}
521
523//
525void CCD::ISGetProperties(const char * dev)
526{
529
530 if (HasStreaming())
531 Streamer->ISGetProperties(dev);
532
533 if (HasDSP())
534 DSP->ISGetProperties(dev);
535}
536
538//
541{
542 //IDLog("CCD UpdateProperties isConnected returns %d %d\n",isConnected(),Connected);
543 if (isConnected())
544 {
545 defineProperty(PrimaryCCD.ImageExposureNP);
546
547 if (CanAbort())
548 defineProperty(PrimaryCCD.AbortExposureSP);
549 if (CanSubFrame() == false)
550 PrimaryCCD.ImageFrameNP.setPermission(IP_RO);
551
552 defineProperty(PrimaryCCD.ImageFrameNP);
553 if (CanBin() || CanSubFrame())
554 defineProperty(PrimaryCCD.ResetSP);
555
556 if (CanBin())
557 defineProperty(PrimaryCCD.ImageBinNP);
558
560
561 if (HasGuideHead())
562 {
563 defineProperty(GuideCCD.ImageExposureNP);
564 if (CanAbort())
565 defineProperty(GuideCCD.AbortExposureSP);
566 if (CanSubFrame() == false)
567 GuideCCD.ImageFrameNP.setPermission(IP_RO);
568 defineProperty(GuideCCD.ImageFrameNP);
569 }
570
571 if (HasCooler())
572 {
575 }
576
579
580 defineProperty(PrimaryCCD.ImagePixelSizeNP);
581 if (HasGuideHead())
582 {
583 defineProperty(GuideCCD.ImagePixelSizeNP);
584 if (CanBin())
585 defineProperty(GuideCCD.ImageBinNP);
586 }
587 defineProperty(PrimaryCCD.CompressSP);
589 if (HasGuideHead())
590 {
591 defineProperty(GuideCCD.CompressSP);
592 defineProperty(GuideCCD.FitsBP);
593 }
594 if (HasST4Port())
595 {
597 }
598 defineProperty(PrimaryCCD.FrameTypeSP);
599
600 if (HasGuideHead())
601 defineProperty(GuideCCD.FrameTypeSP);
602
603 if (HasBayer())
605
606#if 0
607 defineProperty(&PrimaryCCD.RapidGuideSP);
608
609 if (HasGuideHead())
610 defineProperty(&GuideCCD.RapidGuideSP);
611
612 if (RapidGuideEnabled)
613 {
614 defineProperty(&PrimaryCCD.RapidGuideSetupSP);
615 defineProperty(&PrimaryCCD.RapidGuideDataNP);
616 }
617 if (GuiderRapidGuideEnabled)
618 {
619 defineProperty(&GuideCCD.RapidGuideSetupSP);
620 defineProperty(&GuideCCD.RapidGuideDataNP);
621 }
622#endif
624
627
628 if (UploadSettingsTP[UPLOAD_DIR].isEmpty())
629 UploadSettingsTP[UPLOAD_DIR].setText(getenv("HOME"));
631
634 }
635 else
636 {
637 deleteProperty(PrimaryCCD.ImageFrameNP);
638 if (CanBin() || CanSubFrame())
639 deleteProperty(PrimaryCCD.ResetSP);
640
641 deleteProperty(PrimaryCCD.ImagePixelSizeNP);
642
645
646 if (CanBin())
647 deleteProperty(PrimaryCCD.ImageBinNP);
648
649 deleteProperty(PrimaryCCD.ImageExposureNP);
650 if (CanAbort())
651 deleteProperty(PrimaryCCD.AbortExposureSP);
653 deleteProperty(PrimaryCCD.CompressSP);
654
655#if 0
656 deleteProperty(PrimaryCCD.RapidGuideSP.name);
657 if (RapidGuideEnabled)
658 {
659 deleteProperty(PrimaryCCD.RapidGuideSetupSP.name);
660 deleteProperty(PrimaryCCD.RapidGuideDataNP.name);
661 }
662#endif
663
665
666 if (HasGuideHead())
667 {
668 deleteProperty(GuideCCD.ImageExposureNP);
669 if (CanAbort())
670 deleteProperty(GuideCCD.AbortExposureSP);
671 deleteProperty(GuideCCD.ImageFrameNP);
672 deleteProperty(GuideCCD.ImagePixelSizeNP);
673
674 deleteProperty(GuideCCD.FitsBP);
675 if (CanBin())
676 deleteProperty(GuideCCD.ImageBinNP);
677 deleteProperty(GuideCCD.CompressSP);
678 deleteProperty(GuideCCD.FrameTypeSP);
679
680#if 0
681 deleteProperty(GuideCCD.RapidGuideSP.name);
682 if (GuiderRapidGuideEnabled)
683 {
684 deleteProperty(GuideCCD.RapidGuideSetupSP.name);
685 deleteProperty(GuideCCD.RapidGuideDataNP.name);
686 }
687#endif
688 }
689 if (HasCooler())
690 {
693 }
694 if (HasST4Port())
695 {
697 }
698 deleteProperty(PrimaryCCD.FrameTypeSP);
699 if (HasBayer())
702
703 if (WorldCoordSP[WCS_ENABLE].getState() == ISS_ON)
704 {
706 }
710
713 }
714
715 // Streamer
716 if (HasStreaming())
717 Streamer->updateProperties();
718
719 // DSP
720 if (HasDSP())
721 DSP->updateProperties();
722
723 return true;
724}
725
727//
730{
731 XMLEle * ep = nullptr;
732 auto propName = findXMLAttValu(root, "name");
733 auto deviceName = std::string(findXMLAttValu(root, "device"));
734
735 if ((EqNP.snoop(root)))
736 {
737 double newra, newdec;
738 newra = EqNP[Ra].getValue();
739 newdec = EqNP[DEC].getValue();
740 if ((newra != RA) || (newdec != Dec))
741 {
742 //IDLog("RA %4.2f Dec %4.2f Snooped RA %4.2f Dec %4.2f\n",RA,Dec,newra,newdec);
743 RA = newra;
744 Dec = newdec;
745 }
746 }
747 else if (J2000EqNP.snoop(root))
748 {
749 float newra, newdec;
750 newra = J2000EqNP[Ra].getValue();
751 newdec = J2000EqNP[DEC].getValue();
752 if ((newra != J2000RA) || (newdec != J2000DE))
753 {
754 // IDLog("J2000 RA %4.2f Dec %4.2f Snooped RA %4.2f Dec %4.2f\n",J2000RA,J2000DE,newra,newdec);
755 J2000RA = newra;
756 J2000DE = newdec;
757 }
758 J2000Valid = true;
759 }
760 else if (!strcmp("TELESCOPE_PIER_SIDE", propName) && deviceName == ActiveDeviceTP[ACTIVE_TELESCOPE].getText())
761 {
762 // set default to say we have no valid information from mount
763 pierSide = -1;
764 // crack the message
765 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
766 {
767 const char * elemName = findXMLAttValu(ep, "name");
768
769 if (!strcmp(elemName, "PIER_EAST") && !strcmp(pcdataXMLEle(ep), "On"))
770 pierSide = 1;
771 else if (!strcmp(elemName, "PIER_WEST") && !strcmp(pcdataXMLEle(ep), "On"))
772 pierSide = 0;
773 }
774 }
775 // Deprecated
776 else if (!strcmp(propName, "TELESCOPE_INFO") && deviceName == ActiveDeviceTP[ACTIVE_TELESCOPE].getText())
777 {
778 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
779 {
780 const char * name = findXMLAttValu(ep, "name");
781
782 if (!strcmp(name, "TELESCOPE_APERTURE"))
783 {
784 snoopedAperture = atof(pcdataXMLEle(ep));
785 }
786 else if (!strcmp(name, "TELESCOPE_FOCAL_LENGTH"))
787 {
789 }
790 }
791 }
792 else if (!strcmp(propName, "FILTER_NAME") && deviceName == ActiveDeviceTP[ACTIVE_FILTER].getText())
793 {
794 auto newFilterNames = std::vector<std::string>();
795 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
796 newFilterNames.push_back(pcdataXMLEle(ep));
797 if (newFilterNames != FilterNames)
798 {
799 FilterNames = newFilterNames;
800 LOGF_DEBUG("SNOOP: FILTER_NAME -> %s", join(FilterNames, ", ").c_str());
801 }
802
803 }
804 else if (!strcmp(propName, "FILTER_SLOT") && deviceName == ActiveDeviceTP[ACTIVE_FILTER].getText())
805 {
806 auto newFilterSlot = -1;
807 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
808 newFilterSlot = atoi(pcdataXMLEle(ep));
809 if (newFilterSlot != CurrentFilterSlot)
810 {
811 CurrentFilterSlot = newFilterSlot;
812 LOGF_DEBUG("SNOOP: FILTER_SLOT is %d", CurrentFilterSlot);
813 }
814 }
815 else if (!strcmp(propName, "SKY_QUALITY") && deviceName == ActiveDeviceTP[ACTIVE_SKYQUALITY].getText())
816 {
817 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
818 {
819 const char * name = findXMLAttValu(ep, "name");
820
821 if (!strcmp(name, "SKY_BRIGHTNESS"))
822 {
823 MPSAS = atof(pcdataXMLEle(ep));
824 break;
825 }
826 }
827 }
828 else if (!strcmp(propName, "ABS_ROTATOR_ANGLE") && deviceName == ActiveDeviceTP[ACTIVE_ROTATOR].getText())
829 {
830 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
831 {
832 const char * name = findXMLAttValu(ep, "name");
833
834 if (!strcmp(name, "ANGLE"))
835 {
836 RotatorAngle = atof(pcdataXMLEle(ep));
837 break;
838 }
839 }
840 }
841
842 // JJ ed 2019-12-10
843 else if (!strcmp(propName, "ABS_ROTATOR_POSITION") && deviceName == ActiveDeviceTP[ACTIVE_ROTATOR].getText())
844 {
845 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
846 {
847 const char * name = findXMLAttValu(ep, "name");
848
849 if (!strcmp(name, "ROTATOR_ABSOLUTE_POSITION"))
850 {
851 RotatorPosition = atof(pcdataXMLEle(ep));
852 break;
853 }
854 }
855 }
856
857 else if (!strcmp(propName, "ABS_FOCUS_POSITION") && deviceName == ActiveDeviceTP[ACTIVE_FOCUSER].getText())
858 {
859 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
860 {
861 const char * name = findXMLAttValu(ep, "name");
862
863 if (!strcmp(name, "FOCUS_ABSOLUTE_POSITION"))
864 {
865 FocuserPos = atol(pcdataXMLEle(ep));
866 break;
867 }
868 }
869 }
870 else if (!strcmp(propName, "FOCUS_TEMPERATURE") && deviceName == ActiveDeviceTP[ACTIVE_FOCUSER].getText())
871 {
872 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
873 {
874 const char * name = findXMLAttValu(ep, "name");
875
876 if (!strcmp(name, "TEMPERATURE"))
877 {
878 FocuserTemp = atof(pcdataXMLEle(ep));
879 break;
880 }
881 }
882 }
883 //
884
885 else if (!strcmp(propName, "GEOGRAPHIC_COORD") && deviceName == ActiveDeviceTP[ACTIVE_TELESCOPE].getText())
886 {
887 for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0))
888 {
889 const char * name = findXMLAttValu(ep, "name");
890
891 if (!strcmp(name, "LONG"))
892 {
893 Longitude = atof(pcdataXMLEle(ep));
894 if (Longitude > 180)
895 Longitude -= 360;
896 }
897 else if (!strcmp(name, "LAT"))
898 {
899 Latitude = atof(pcdataXMLEle(ep));
900 }
901 }
902 }
903
904 return DefaultDevice::ISSnoopDevice(root);
905}
906
908//
910bool CCD::ISNewText(const char * dev, const char * name, char * texts[], char * names[], int n)
911{
912 // first check if it's for our device
913 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
914 {
915 // Now lets see if it's something we process here
916 if (ActiveDeviceTP.isNameMatch(name))
917 {
918 std::vector<std::string> prevValues;
919 prevValues.reserve(n);
920
921 // Store all previous values
922 for (int i = 0; i < n; i++)
923 prevValues.push_back(ActiveDeviceTP[i].getText());
924
925 // Check if any values actually changed
926 bool hasChanged = false;
927 for (int i = 0; i < n; i++)
928 {
929 if (prevValues[i] != texts[i])
930 {
931 hasChanged = true;
932 break;
933 }
934 }
935
936 if (!hasChanged)
937 {
938 ActiveDeviceTP.setState(IPS_OK);
939 ActiveDeviceTP.apply();
940 return true;
941 }
942
943 // Update the properties since we have changes
944 ActiveDeviceTP.setState(IPS_OK);
945 ActiveDeviceTP.update(texts, names, n);
946 ActiveDeviceTP.apply();
947
948 // Mount
949 auto newMount = ActiveDeviceTP[ACTIVE_TELESCOPE].getText();
950 if (newMount != prevValues[ACTIVE_TELESCOPE])
951 {
952 EqNP.setDeviceName(newMount);
953 J2000EqNP.setDeviceName(newMount);
954 if (strlen(newMount) > 0)
955 {
956 LOGF_DEBUG("Snopping on Mount %s", newMount);
957 IDSnoopDevice(newMount, "EQUATORIAL_EOD_COORD");
958 IDSnoopDevice(newMount, "EQUATORIAL_COORD");
959 IDSnoopDevice(newMount, "TELESCOPE_INFO");
960 IDSnoopDevice(newMount, "GEOGRAPHIC_COORD");
961 }
962 else if (!std::isnan(RA))
963 {
964 LOG_DEBUG("No mount is set. Clearing all mount watchers.");
966 std::numeric_limits<double>::quiet_NaN();
967 }
968 }
969
970 // Rotator
971 auto newRotator = ActiveDeviceTP[ACTIVE_ROTATOR].getText();
972 if (newRotator != prevValues[ACTIVE_ROTATOR])
973 {
974 if (strlen(newRotator) > 0)
975 {
976 LOGF_DEBUG("Snopping on Rotator %s", newRotator);
977 IDSnoopDevice(newRotator, "ABS_ROTATOR_ANGLE");
978 IDSnoopDevice(newRotator, "ABS_ROTATOR_POSITION");
979 }
980 else if (!std::isnan(MPSAS))
981 {
982 LOG_DEBUG("No rotator is set. Clearing all rotator watchers.");
983 MPSAS = std::numeric_limits<double>::quiet_NaN();
984 }
985 }
986
987 // Focuser
988 auto newFocuser = ActiveDeviceTP[ACTIVE_FOCUSER].getText();
989 if (newFocuser != prevValues[ACTIVE_FOCUSER])
990 {
991 if (strlen(newFocuser) > 0)
992 {
993 LOGF_DEBUG("Snopping on Focuser %s", newFocuser);
994 IDSnoopDevice(newFocuser, "ABS_FOCUS_POSITION");
995 IDSnoopDevice(newFocuser, "FOCUS_TEMPERATURE");
996 }
997 else if (!std::isnan(FocuserTemp))
998 {
999 LOG_DEBUG("No focuser is set. Clearing all focuser watchers.");
1000 FocuserPos = -1;
1001 FocuserTemp = std::numeric_limits<double>::quiet_NaN();
1002 }
1003 }
1004
1005 // Filter Wheel
1006 auto newFilterWheel = ActiveDeviceTP[ACTIVE_FILTER].getText();
1007 if (newFilterWheel != prevValues[ACTIVE_FILTER])
1008 {
1009 if (strlen(newFilterWheel) > 0)
1010 {
1011 LOGF_DEBUG("Snopping on Filter Wheel %s", newFilterWheel);
1012 IDSnoopDevice(newFilterWheel, "FILTER_SLOT");
1013 IDSnoopDevice(newFilterWheel, "FILTER_NAME");
1014 }
1015 else if (CurrentFilterSlot != -1)
1016 {
1017 LOG_DEBUG("No filter wheel is set. Clearing All filter wheel watchers.");
1018 CurrentFilterSlot = -1;
1019 }
1020 }
1021
1022 // Sky Quality
1023 auto newSkyQuality = ActiveDeviceTP[ACTIVE_SKYQUALITY].getText();
1024 if (newSkyQuality != prevValues[ACTIVE_SKYQUALITY] && strlen(newSkyQuality) > 0)
1025 IDSnoopDevice(newSkyQuality, "SKY_QUALITY");
1026
1029 return true;
1030 }
1031
1032 if (BayerTP.isNameMatch(name))
1033 {
1034 BayerTP.update(texts, names, n);
1035 BayerTP.setState(IPS_OK);
1036 BayerTP.apply();
1037 return true;
1038 }
1039
1040 // FITS Header
1041 if (FITSHeaderTP.isNameMatch(name))
1042 {
1043 FITSHeaderTP.update(texts, names, n);
1044
1045 std::string name = FITSHeaderTP[KEYWORD_NAME].getText();
1046 std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c)
1047 {
1048 return std::toupper(c);
1049 });
1050 std::string value = FITSHeaderTP[KEYWORD_VALUE].getText();
1051 std::string comment = FITSHeaderTP[KEYWORD_COMMENT].getText();
1052
1053 if (name.empty() && value.empty() && comment.empty())
1054 {
1055 LOG_ERROR("Cannot add an empty FITS record.");
1056 FITSHeaderTP.setState(IPS_ALERT);
1057 }
1058 else
1059 {
1060 FITSHeaderTP.setState(IPS_OK);
1061 // Special keyword
1062 if (name == "INDI_CLEAR")
1063 {
1064 m_CustomFITSKeywords.clear();
1065 LOG_INFO("Custom FITS headers cleared.");
1066 }
1067 else if (name.empty() == false && value.empty() == false)
1068 {
1069 // Double regex
1070 std::regex checkDouble("^[-+]?([0-9]*?[.,][0-9]+|[0-9]+)$");
1071 // Integer regex
1072 std::regex checkInteger("^[-+]?([0-9]*)$");
1073
1074 try
1075 {
1076 // Try long
1077 if (std::regex_match(value, checkInteger))
1078 {
1079 auto lValue = std::stol(value);
1080 FITSRecord record(name.c_str(), lValue, comment.c_str());
1081 m_CustomFITSKeywords[name] = record;
1082 }
1083 // Try double
1084 else if (std::regex_match(value, checkDouble))
1085 {
1086 auto dValue = std::stod(value);
1087 FITSRecord record(name.c_str(), dValue, 6, comment.c_str());
1088 m_CustomFITSKeywords[name] = record;
1089 }
1090 // Store as text
1091 else
1092 {
1093 // String
1094 // Escape the value since backslashes are reserved /
1095 std::replace(value.begin(), value.end(), '/', '\\');
1096 FITSRecord record(name.c_str(), value.c_str(), comment.c_str());
1097 m_CustomFITSKeywords[name] = record;
1098 }
1099 }
1100 // In case conversion fails
1101 catch (std::exception &e)
1102 {
1103 // String
1104 std::replace(value.begin(), value.end(), '/', '\\');
1105 FITSRecord record(name.c_str(), value.c_str(), comment.c_str());
1106 m_CustomFITSKeywords[name] = record;
1107 }
1108 }
1109 else if (comment.empty() == false)
1110 {
1111 FITSRecord record(comment.c_str());
1112 m_CustomFITSKeywords[comment] = record;
1113 }
1114 }
1115
1116 FITSHeaderTP.apply();
1117 return true;
1118 }
1119
1120 if (UploadSettingsTP.isNameMatch(name))
1121 {
1122 UploadSettingsTP.update(texts, names, n);
1123 UploadSettingsTP.setState(IPS_OK);
1124 UploadSettingsTP.apply();
1125 return true;
1126 }
1127 }
1128
1129 // Streamer
1130 if (HasStreaming())
1131 Streamer->ISNewText(dev, name, texts, names, n);
1132
1133 // DSP
1134 if (HasDSP())
1135 DSP->ISNewText(dev, name, texts, names, n);
1136
1137 return DefaultDevice::ISNewText(dev, name, texts, names, n);
1138}
1139
1141//
1143bool CCD::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n)
1144{
1145 // Check guider interface
1146 if (GI::processNumber(dev, name, values, names, n))
1147 return true;
1148
1149 // first check if it's for our device
1150 //IDLog("CCD::ISNewNumber %s\n",name);
1151 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
1152 {
1153 if (PrimaryCCD.ImageExposureNP.isNameMatch(name))
1154 {
1155 if (PrimaryCCD.getFrameType() != CCDChip::BIAS_FRAME &&
1156 (values[0] < PrimaryCCD.ImageExposureNP[0].getMin() || values[0] > PrimaryCCD.ImageExposureNP[0].getMax()))
1157 {
1158 LOGF_ERROR("Requested exposure value (%g) seconds out of bounds [%g,%g].",
1159 values[0], PrimaryCCD.ImageExposureNP[0].getMin(), PrimaryCCD.ImageExposureNP[0].getMax());
1160 PrimaryCCD.ImageExposureNP.setState(IPS_ALERT);
1161 PrimaryCCD.ImageExposureNP.apply();
1162 return false;
1163 }
1164
1165 if (PrimaryCCD.getFrameType() == CCDChip::BIAS_FRAME)
1166 {
1167 ExposureTime = PrimaryCCD.ImageExposureNP[0].getMin();
1168 PrimaryCCD.ImageExposureNP[0].setValue(PrimaryCCD.ImageExposureNP[0].getMin());
1169 }
1170 else
1171 {
1172 ExposureTime = values[0];
1173 PrimaryCCD.ImageExposureNP[0].setValue(values[0]);
1174 }
1175
1176 // Only abort when busy if we are not already in an exposure loops
1177 //if (PrimaryCCD.ImageExposureNP.s == IPS_BUSY && FastExposureToggleS[INDI_DISABLED].s == ISS_ON)
1178 if (PrimaryCCD.ImageExposureNP.getState() == IPS_BUSY)
1179 {
1180 if (CanAbort() && AbortExposure() == false)
1181 DEBUG(Logger::DBG_WARNING, "Warning: Aborting exposure failed.");
1182 }
1183
1185 {
1186 PrimaryCCD.ImageExposureNP.setState(IPS_BUSY);
1189 }
1190 else
1191 PrimaryCCD.ImageExposureNP.setState(IPS_ALERT);
1192 PrimaryCCD.ImageExposureNP.apply();
1193 return true;
1194 }
1195
1196 if (GuideCCD.ImageExposureNP.isNameMatch(name))
1197 {
1198 if (GuideCCD.getFrameType() != CCDChip::BIAS_FRAME &&
1199 (values[0] < GuideCCD.ImageExposureNP[0].getMin() || values[0] > GuideCCD.ImageExposureNP[0].getMax()))
1200 {
1201 LOGF_ERROR("Requested guide exposure value (%g) seconds out of bounds [%g,%g].",
1202 values[0], GuideCCD.ImageExposureNP[0].getMin(), GuideCCD.ImageExposureNP[0].getMax());
1203 GuideCCD.ImageExposureNP.setState(IPS_ALERT);
1204 GuideCCD.ImageExposureNP.apply();
1205 return false;
1206 }
1207
1208 if (GuideCCD.getFrameType() == CCDChip::BIAS_FRAME)
1209 {
1210 GuiderExposureTime = GuideCCD.ImageExposureNP[0].getMin();
1211 GuideCCD.ImageExposureNP[0].setValue(GuideCCD.ImageExposureNP[0].getMin());
1212 }
1213 else
1214 {
1215 GuiderExposureTime = values[0];
1216 GuideCCD.ImageExposureNP[0].setValue(values[0]);
1217 }
1218
1219 GuideCCD.ImageExposureNP.setState(IPS_BUSY);
1221 GuideCCD.ImageExposureNP.setState(IPS_BUSY);
1222 else
1223 GuideCCD.ImageExposureNP.setState(IPS_ALERT);
1224 GuideCCD.ImageExposureNP.apply();
1225 return true;
1226 }
1227
1228 if (PrimaryCCD.ImageBinNP.isNameMatch(name))
1229 {
1230 // We are being asked to set camera binning
1231 auto np = PrimaryCCD.ImageBinNP.findWidgetByName(names[0]);
1232 // auto np =
1233 if (np == nullptr)
1234 {
1235 PrimaryCCD.ImageBinNP.setState(IPS_ALERT);
1236 PrimaryCCD.ImageBinNP.apply();
1237 return false;
1238 }
1239 else if (values[0] == 0 || values[1] == 0)
1240 {
1241 PrimaryCCD.ImageBinNP.setState(IPS_ALERT);
1242 PrimaryCCD.ImageBinNP.apply();
1243 LOGF_ERROR("%.fx%.f binning is invalid.", values[0], values[1]);
1244 return false;
1245 }
1246
1247 int binx, biny;
1248 if (!strcmp(np->name, "HOR_BIN"))
1249 {
1250 binx = values[0];
1251 biny = values[1];
1252 }
1253 else
1254 {
1255 binx = values[1];
1256 biny = values[0];
1257 }
1258
1259 if (UpdateCCDBin(binx, biny))
1260 {
1261 PrimaryCCD.ImageBinNP.update(values, names, n);
1262 PrimaryCCD.ImageBinNP.setState(IPS_OK);
1263 }
1264 else
1265 PrimaryCCD.ImageBinNP.setState(IPS_ALERT);
1266
1267 PrimaryCCD.ImageBinNP.apply();
1268
1269 return true;
1270 }
1271
1272 if (GuideCCD.ImageBinNP.isNameMatch(name))
1273 {
1274 // We are being asked to set camera binning
1275 // INumber * np = IUFindNumber(&GuideCCD.ImageBinNP, names[0]);
1276 auto np = GuideCCD.ImageBinNP.findWidgetByName(names[0]);
1277 if (np == nullptr)
1278 {
1279 GuideCCD.ImageBinNP.setState(IPS_ALERT);
1280 GuideCCD.ImageBinNP.apply();
1281 return false;
1282 }
1283 else if (values[0] == 0 || values[1] == 0)
1284 {
1285 PrimaryCCD.ImageBinNP.setState(IPS_ALERT);
1286 PrimaryCCD.ImageBinNP.apply();
1287 LOGF_ERROR("%.fx%.f binning is invalid.", values[0], values[1]);
1288 return false;
1289 }
1290
1291 int binx, biny;
1292 if (!strcmp(np->name, "HOR_BIN"))
1293 {
1294 binx = values[0];
1295 biny = values[1];
1296 }
1297 else
1298 {
1299 binx = values[1];
1300 biny = values[0];
1301 }
1302
1303 if (UpdateGuiderBin(binx, biny))
1304 {
1305 GuideCCD.ImageBinNP.update(values, names, n);
1306 GuideCCD.ImageBinNP.setState(IPS_OK);
1307 }
1308 else
1309 GuideCCD.ImageBinNP.setState(IPS_ALERT);
1310
1311 GuideCCD.ImageBinNP.apply();
1312
1313 return true;
1314 }
1315
1316 // Scope Information
1317 if (ScopeInfoNP.isNameMatch(name))
1318 {
1319 if (ScopeInfoNP.update(values, names, n))
1320 {
1321 ScopeInfoNP.setState(IPS_OK);
1322 ScopeInfoNP.apply();
1324 }
1325 else
1326 {
1327 ScopeInfoNP.setState(IPS_ALERT);
1328 }
1329
1330 return true;
1331 }
1332
1333 // Image Frame Region of Interest
1334 if (PrimaryCCD.ImageFrameNP.isNameMatch(name))
1335 {
1336 int x = -1, y = -1, w = -1, h = -1;
1337 for (int i = 0; i < n; i++)
1338 {
1339 if (!strcmp(names[i], "X"))
1340 x = values[i];
1341 else if (!strcmp(names[i], "Y"))
1342 y = values[i];
1343 else if (!strcmp(names[i], "WIDTH"))
1344 w = values[i];
1345 else if (!strcmp(names[i], "HEIGHT"))
1346 h = values[i];
1347 }
1348
1349 DEBUGF(Logger::DBG_DEBUG, "Requested CCD Frame is (%d,%d) (%d x %d)", x, y, w, h);
1350
1351 if (x < 0 || y < 0 || w <= 0 || h <= 0)
1352 {
1353 LOGF_ERROR("Invalid frame requested (%d,%d) (%d x %d)", x, y, w, h);
1354 PrimaryCCD.ImageFrameNP.setState(IPS_ALERT);
1355 PrimaryCCD.ImageFrameNP.apply();
1356 return true;
1357 }
1358
1359 if (UpdateCCDFrame(x, y, w, h))
1360 {
1361 PrimaryCCD.ImageFrameNP.setState(IPS_OK);
1362 PrimaryCCD.ImageFrameNP.update(values, names, n);
1363 }
1364 else
1365 PrimaryCCD.ImageFrameNP.setState(IPS_ALERT);
1366
1367 PrimaryCCD.ImageFrameNP.apply();
1368 return true;
1369 }
1370
1371 if (GuideCCD.ImageFrameNP.isNameMatch(name))
1372 {
1373 // We are being asked to set guide frame
1374 if (GuideCCD.ImageFrameNP.update(values, names, n) == false)
1375 return false;
1376
1377 GuideCCD.ImageFrameNP.setState(IPS_OK);
1378
1379 DEBUGF(Logger::DBG_DEBUG, "Requested Guide Frame is %4.0f,%4.0f %4.0f x %4.0f", values[0], values[1],
1380 values[2], values[4]);
1381
1382 if (UpdateGuiderFrame(GuideCCD.ImageFrameNP[CCDChip::FRAME_X].getValue(),
1383 GuideCCD.ImageFrameNP[CCDChip::FRAME_Y].getValue(),
1384 GuideCCD.ImageFrameNP[CCDChip::FRAME_W].getValue(), GuideCCD.ImageFrameNP[CCDChip::FRAME_H].getValue()) == false)
1385 GuideCCD.ImageFrameNP.setState(IPS_ALERT);
1386
1387 GuideCCD.ImageFrameNP.apply();
1388
1389 return true;
1390 }
1391
1392#if 0
1393 if (!strcmp(name, "CCD_GUIDESTAR"))
1394 {
1395 PrimaryCCD.RapidGuideDataNP.s = IPS_OK;
1396 IUUpdateNumber(&PrimaryCCD.RapidGuideDataNP, values, names, n);
1397 IDSetNumber(&PrimaryCCD.RapidGuideDataNP, nullptr);
1398 return true;
1399 }
1400
1401 if (!strcmp(name, "GUIDER_GUIDESTAR"))
1402 {
1403 GuideCCD.RapidGuideDataNP.s = IPS_OK;
1404 IUUpdateNumber(&GuideCCD.RapidGuideDataNP, values, names, n);
1405 IDSetNumber(&GuideCCD.RapidGuideDataNP, nullptr);
1406 return true;
1407 }
1408#endif
1409 // Fast Exposure Count
1410 if (FastExposureCountNP.isNameMatch(name))
1411 {
1412 FastExposureCountNP.update(values, names, n);
1413 FastExposureCountNP.setState(IPS_OK);
1414 FastExposureCountNP.apply();
1415 return true;
1416 }
1417
1418 // CCD TEMPERATURE
1419 if (TemperatureNP.isNameMatch(name))
1420 {
1421 if (values[0] < TemperatureNP[0].getMin() || values[0] > TemperatureNP[0].getMax())
1422 {
1423 TemperatureNP.setState(IPS_ALERT);
1424 LOGF_ERROR("Error: Bad temperature value! Range is [%.1f, %.1f] [C].",
1425 TemperatureNP[0].getMin(), TemperatureNP[0].getMax());
1426 TemperatureNP.apply();
1427 return false;
1428 }
1429
1430 double nextTemperature = values[0];
1431 // If temperature ramp is enabled, find
1432 if (TemperatureRampNP[RAMP_SLOPE].getValue() != 0)
1433 {
1434 if (values[0] < TemperatureNP[0].getValue())
1435 {
1436 nextTemperature = std::max(values[0], TemperatureNP[0].getValue() - TemperatureRampNP[RAMP_SLOPE].getValue());
1437 }
1438 // Going up
1439 else
1440 {
1441 nextTemperature = std::min(values[0], TemperatureNP[0].getValue() + TemperatureRampNP[RAMP_SLOPE].getValue());
1442 }
1443 }
1444
1445 int rc = SetTemperature(nextTemperature);
1446
1447 if (rc == 0)
1448 {
1449 if (TemperatureRampNP[RAMP_SLOPE].getValue() != 0)
1450 {
1452 m_TemperatureRampTimer.start();
1454 }
1455
1456 m_TargetTemperature = values[0];
1458 // Initialize stabilization tracking for warming-up case (can't heat above ambient)
1461 TemperatureNP.setState(IPS_BUSY);
1462 }
1463 else if (rc == 1)
1464 TemperatureNP.setState(IPS_OK);
1465 else
1466 TemperatureNP.setState(IPS_ALERT);
1467
1468 TemperatureNP.apply();
1469 return true;
1470 }
1471
1472 // Camera Temperature Ramp
1473 if (TemperatureRampNP.isNameMatch(name))
1474 {
1475 double previousSlope = TemperatureRampNP[RAMP_SLOPE].getValue();
1476 double previousThreshold = TemperatureRampNP[RAMP_THRESHOLD].getValue();
1477 TemperatureRampNP.update(values, names, n);
1478 TemperatureRampNP.setState(IPS_OK);
1479 TemperatureRampNP.apply();
1480 if (TemperatureRampNP[0].getValue() == 0)
1481 LOG_INFO("Temperature ramp is disabled.");
1482 else
1483 LOGF_INFO("Temperature ramp is enabled. Gradual cooling and warming is regulated at %.f Celsius per minute.",
1484 TemperatureRampNP[0].getValue());
1485
1486 // Save config if there is a change
1487 if (std::abs(previousSlope - TemperatureRampNP[RAMP_SLOPE].getValue()) > 0 ||
1488 std::abs(previousThreshold - TemperatureRampNP[RAMP_THRESHOLD].getValue()) > 0.01)
1490 return true;
1491 }
1492
1493 // Primary CCD Info
1494 if (PrimaryCCD.ImagePixelSizeNP.isNameMatch(name))
1495 {
1496 if (PrimaryCCD.ImagePixelSizeNP.update(values, names, n))
1497 {
1498 PrimaryCCD.ImagePixelSizeNP.setState(IPS_OK);
1499 SetCCDParams(PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_MAX_X].getValue(),
1500 PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_MAX_Y].getValue(),
1501 PrimaryCCD.getBPP(),
1502 PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE_X].getValue(),
1503 PrimaryCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE_Y].getValue());
1504 saveConfig(PrimaryCCD.ImagePixelSizeNP);
1505 }
1506 else
1507 PrimaryCCD.ImagePixelSizeNP.setState(IPS_ALERT);
1508
1509 PrimaryCCD.ImagePixelSizeNP.apply();
1510 return true;
1511 }
1512
1513 // Guide CCD Info
1514 if (GuideCCD.ImagePixelSizeNP.isNameMatch(name))
1515 {
1516 GuideCCD.ImagePixelSizeNP.update(values, names, n);
1517 GuideCCD.ImagePixelSizeNP.setState(IPS_OK);
1518 SetGuiderParams(GuideCCD.ImagePixelSizeNP[CCDChip::CCD_MAX_X].getValue(),
1519 GuideCCD.ImagePixelSizeNP[CCDChip::CCD_MAX_Y].getValue(), GuideCCD.getBPP(),
1520 GuideCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE_X].getValue(),
1521 GuideCCD.ImagePixelSizeNP[CCDChip::CCD_PIXEL_SIZE_Y].getValue());
1522 GuideCCD.ImagePixelSizeNP.apply();
1523 saveConfig(GuideCCD.ImagePixelSizeNP);
1524 return true;
1525 }
1526
1527 // CCD Rotation
1528 if (CCDRotationNP.isNameMatch(name))
1529 {
1530 CCDRotationNP.update(values, names, n);
1531 CCDRotationNP.setState(IPS_OK);
1532 CCDRotationNP.apply();
1533 m_ValidCCDRotation = true;
1534
1535 LOGF_INFO("Camera Orientation updated to %.2f degrees.", CCDRotationNP[0].getValue());
1536
1537 return true;
1538 }
1539 }
1540
1541 // Streamer
1542 if (HasStreaming())
1543 Streamer->ISNewNumber(dev, name, values, names, n);
1544
1545 // DSP
1546 if (HasDSP())
1547 DSP->ISNewNumber(dev, name, values, names, n);
1548
1549 return DefaultDevice::ISNewNumber(dev, name, values, names, n);
1550}
1551
1553//
1555bool CCD::ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n)
1556{
1557 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
1558 {
1559 // Upload Mode
1560 if (UploadSP.isNameMatch(name))
1561 {
1562 int prevMode = UploadSP.findOnSwitchIndex();
1563 UploadSP.update(states, names, n);
1564
1565 if (UpdateCCDUploadMode(static_cast<CCD_UPLOAD_MODE>(UploadSP.findOnSwitchIndex())))
1566 {
1567 if (UploadSP[UPLOAD_CLIENT].getState() == ISS_ON)
1568 {
1569 LOG_INFO("Upload settings set to client only.");
1570 if (prevMode != 0)
1572 }
1573 else if (UploadSP[UPLOAD_LOCAL].getState() == ISS_ON)
1574 {
1575 LOG_INFO("Upload settings set to local only.");
1577 }
1578 else
1579 {
1580 LOG_INFO("Upload settings set to client and local.");
1582 }
1583
1584 UploadSP.setState(IPS_OK);
1585 }
1586 else
1587 {
1588 UploadSP.reset();
1589 UploadSP[prevMode].setState(ISS_ON);
1590 UploadSP.setState(IPS_ALERT);
1591 }
1592
1593 UploadSP.apply();
1594
1595 return true;
1596 }
1597
1598 // Fast Exposure Toggle
1599 if (FastExposureToggleSP.isNameMatch(name))
1600 {
1601 FastExposureToggleSP.update(states, names, n);
1602
1603 // Only display warning for the first time this is enabled.
1604 if (FastExposureToggleSP.getState() == IPS_IDLE && FastExposureToggleSP[INDI_ENABLED].getState() == ISS_ON)
1605 LOG_WARN("Experimental Feature: After a frame is downloaded, the next frame capture immediately starts to avoid any delays.");
1606
1607 if (FastExposureToggleSP[INDI_DISABLED].getState() == ISS_ON)
1608 {
1609 FastExposureCountNP.setState(IPS_IDLE);
1610 FastExposureCountNP.apply();
1611 m_UploadTime = 0;
1612 if (PrimaryCCD.isExposing())
1613 AbortExposure();
1614 }
1615
1616 FastExposureToggleSP.setState(IPS_OK);
1617 FastExposureToggleSP.apply();
1618 return true;
1619 }
1620
1621 // WCS Enable/Disable
1622 if (WorldCoordSP.isNameMatch(name))
1623 {
1624 WorldCoordSP.update(states, names, n);
1625 WorldCoordSP.setState(IPS_OK);
1626
1627 if (WorldCoordSP[0].getState() == ISS_ON)
1628 {
1629 LOG_INFO("World Coordinate System is enabled.");
1631 }
1632 else
1633 {
1634 LOG_INFO("World Coordinate System is disabled.");
1636 }
1637
1638 m_ValidCCDRotation = false;
1639 WorldCoordSP.apply();
1640 }
1641
1642 // Primary Chip Frame Reset
1643 if (PrimaryCCD.ResetSP.isNameMatch(name))
1644 {
1645 PrimaryCCD.ResetSP.reset();
1646 PrimaryCCD.ResetSP.setState(IPS_OK);
1647 if (CanBin())
1648 UpdateCCDBin(1, 1);
1649 if (CanSubFrame())
1650 UpdateCCDFrame(0, 0, PrimaryCCD.getXRes(), PrimaryCCD.getYRes());
1651
1652 PrimaryCCD.ResetSP.apply();
1653 return true;
1654 }
1655
1656 // Primary Chip Abort Expsoure
1657 if (PrimaryCCD.AbortExposureSP.isNameMatch(name))
1658 {
1659 PrimaryCCD.AbortExposureSP.reset();
1660
1661 if (AbortExposure())
1662 {
1663 PrimaryCCD.AbortExposureSP.setState(IPS_OK);
1664 PrimaryCCD.ImageExposureNP.setState(IPS_IDLE);
1665 PrimaryCCD.ImageExposureNP[0].setValue(0);
1666 }
1667 else
1668 {
1669 PrimaryCCD.AbortExposureSP.setState(IPS_ALERT);
1670 PrimaryCCD.ImageExposureNP.setState(IPS_ALERT);
1671 }
1672
1674
1675 // Fast Exposure Count
1676 if (FastExposureCountNP.getState() == IPS_BUSY)
1677 {
1678 m_UploadTime = 0;
1679 FastExposureCountNP.setState(IPS_IDLE);
1680 FastExposureCountNP[0].setValue(1);
1681 FastExposureCountNP.apply();
1682 }
1683
1684 PrimaryCCD.AbortExposureSP.apply();
1685 PrimaryCCD.ImageExposureNP.apply();
1686
1687 return true;
1688 }
1689
1690 // Guide Chip Abort Exposure
1691 if (GuideCCD.AbortExposureSP.isNameMatch(name))
1692 {
1693 GuideCCD.AbortExposureSP.reset();
1694
1695 if (AbortGuideExposure())
1696 {
1697 GuideCCD.AbortExposureSP.setState(IPS_OK);
1698 GuideCCD.ImageExposureNP.setState(IPS_IDLE);
1699 GuideCCD.ImageExposureNP[0].setValue(0);
1700 }
1701 else
1702 {
1703 GuideCCD.AbortExposureSP.setState(IPS_ALERT);
1704 GuideCCD.ImageExposureNP.setState(IPS_ALERT);
1705 }
1706
1707 GuideCCD.AbortExposureSP.apply();
1708 GuideCCD.ImageExposureNP.apply();
1709
1710 return true;
1711 }
1712
1713 // Primary Chip Compression
1714 if (PrimaryCCD.CompressSP.isNameMatch(name))
1715 {
1716 PrimaryCCD.CompressSP.update(states, names, n);
1717 PrimaryCCD.CompressSP.setState(IPS_OK);
1718 PrimaryCCD.CompressSP.apply();
1719 PrimaryCCD.SendCompressed = PrimaryCCD.CompressSP[INDI_ENABLED].getState() == ISS_ON;
1720 return true;
1721 }
1722
1723 // Guide Chip Compression
1724 if (GuideCCD.CompressSP.isNameMatch(name))
1725 {
1726 GuideCCD.CompressSP.update(states, names, n);
1727 GuideCCD.CompressSP.setState(IPS_OK);
1728 GuideCCD.CompressSP.apply();
1729 GuideCCD.SendCompressed = GuideCCD.CompressSP[INDI_ENABLED].getState() == ISS_ON;
1730 return true;
1731 }
1732
1733 // Primary Chip Frame Type
1734 if (PrimaryCCD.FrameTypeSP.isNameMatch(name))
1735 {
1736 PrimaryCCD.FrameTypeSP.update(states, names, n);
1737 PrimaryCCD.FrameTypeSP.setState(IPS_OK);
1738 if (PrimaryCCD.FrameTypeSP[CCDChip::LIGHT_FRAME].getState() == ISS_ON)
1739 PrimaryCCD.setFrameType(CCDChip::LIGHT_FRAME);
1740 else if (PrimaryCCD.FrameTypeSP[CCDChip::BIAS_FRAME].getState() == ISS_ON)
1741 {
1742 PrimaryCCD.setFrameType(CCDChip::BIAS_FRAME);
1743 if (HasShutter() == false)
1745 "The CCD does not have a shutter. Cover the camera in order to take a bias frame.");
1746 }
1747 else if (PrimaryCCD.FrameTypeSP[CCDChip::DARK_FRAME].getState() == ISS_ON)
1748 {
1749 PrimaryCCD.setFrameType(CCDChip::DARK_FRAME);
1750 if (HasShutter() == false)
1752 "The CCD does not have a shutter. Cover the camera in order to take a dark frame.");
1753 }
1754 else if (PrimaryCCD.FrameTypeSP[CCDChip::FLAT_FRAME].getState() == ISS_ON)
1755 PrimaryCCD.setFrameType(CCDChip::FLAT_FRAME);
1756
1757 if (UpdateCCDFrameType(PrimaryCCD.getFrameType()) == false)
1758 PrimaryCCD.FrameTypeSP.setState(IPS_ALERT);
1759
1760 PrimaryCCD.FrameTypeSP.apply();
1761
1762 return true;
1763 }
1764
1765 // Guide Chip Frame Type
1766 if (GuideCCD.FrameTypeSP.isNameMatch(name))
1767 {
1768 // Compression Update
1769 GuideCCD.FrameTypeSP.update(states, names, n);
1770 GuideCCD.FrameTypeSP.setState(IPS_OK);
1771 if (GuideCCD.FrameTypeSP[CCDChip::LIGHT_FRAME].getState() == ISS_ON)
1772 GuideCCD.setFrameType(CCDChip::LIGHT_FRAME);
1773 else if (GuideCCD.FrameTypeSP[CCDChip::BIAS_FRAME].getState() == ISS_ON)
1774 {
1775 GuideCCD.setFrameType(CCDChip::BIAS_FRAME);
1776 if (HasShutter() == false)
1778 "The CCD does not have a shutter. Cover the camera in order to take a bias frame.");
1779 }
1780 else if (GuideCCD.FrameTypeSP[CCDChip::DARK_FRAME].getState() == ISS_ON)
1781 {
1782 GuideCCD.setFrameType(CCDChip::DARK_FRAME);
1783 if (HasShutter() == false)
1785 "The CCD does not have a shutter. Cover the camera in order to take a dark frame.");
1786 }
1787 else if (GuideCCD.FrameTypeSP[CCDChip::FLAT_FRAME].getState() == ISS_ON)
1788 GuideCCD.setFrameType(CCDChip::FLAT_FRAME);
1789
1790 if (UpdateGuiderFrameType(GuideCCD.getFrameType()) == false)
1791 GuideCCD.FrameTypeSP.setState(IPS_ALERT);
1792
1793 GuideCCD.FrameTypeSP.apply();
1794
1795 return true;
1796 }
1797
1798 // Capture Format
1799 if (CaptureFormatSP.isNameMatch(name))
1800 {
1801 int previousIndex = CaptureFormatSP.findOnSwitchIndex();
1802 CaptureFormatSP.update(states, names, n);
1803
1804 if (SetCaptureFormat(CaptureFormatSP.findOnSwitchIndex()))
1805 CaptureFormatSP.setState(IPS_OK);
1806 else
1807 {
1808 if (previousIndex >= 0)
1809 {
1810 CaptureFormatSP.reset();
1811 CaptureFormatSP[previousIndex].setState(ISS_ON);
1812 }
1813 CaptureFormatSP.setState(IPS_ALERT);
1814 }
1815 CaptureFormatSP.apply();
1816
1817 if (previousIndex >= 0 && m_ConfigCaptureFormatName != CaptureFormatSP.findOnSwitch()->getName())
1818 {
1819 m_ConfigCaptureFormatName = CaptureFormatSP.findOnSwitch()->getName();
1821 }
1822
1823 return true;
1824 }
1825
1826 // Encode Format
1827 if (EncodeFormatSP.isNameMatch(name))
1828 {
1829 EncodeFormatSP.update(states, names, n);
1830 EncodeFormatSP.setState(IPS_OK);
1831 EncodeFormatSP.apply();
1832
1833 if (m_ConfigEncodeFormatIndex != EncodeFormatSP.findOnSwitchIndex())
1834 {
1835 m_ConfigEncodeFormatIndex = EncodeFormatSP.findOnSwitchIndex();
1837 }
1838
1839 return true;
1840 }
1841
1842#if 0
1843 // Primary Chip Rapid Guide Enable/Disable
1844 if (strcmp(name, PrimaryCCD.RapidGuideSP.name) == 0)
1845 {
1846 IUUpdateSwitch(&PrimaryCCD.RapidGuideSP, states, names, n);
1847 PrimaryCCD.RapidGuideSP.s = IPS_OK;
1848 RapidGuideEnabled = (PrimaryCCD.RapidGuideS[0].s == ISS_ON);
1849
1850 if (RapidGuideEnabled)
1851 {
1852 defineProperty(&PrimaryCCD.RapidGuideSetupSP);
1853 defineProperty(&PrimaryCCD.RapidGuideDataNP);
1854 }
1855 else
1856 {
1857 deleteProperty(PrimaryCCD.RapidGuideSetupSP.name);
1858 deleteProperty(PrimaryCCD.RapidGuideDataNP.name);
1859 }
1860
1861 IDSetSwitch(&PrimaryCCD.RapidGuideSP, nullptr);
1862 return true;
1863 }
1864
1865 // Guide Chip Rapid Guide Enable/Disable
1866 if (strcmp(name, GuideCCD.RapidGuideSP.name) == 0)
1867 {
1868 IUUpdateSwitch(&GuideCCD.RapidGuideSP, states, names, n);
1869 GuideCCD.RapidGuideSP.s = IPS_OK;
1870 GuiderRapidGuideEnabled = (GuideCCD.RapidGuideS[0].s == ISS_ON);
1871
1872 if (GuiderRapidGuideEnabled)
1873 {
1874 defineProperty(&GuideCCD.RapidGuideSetupSP);
1875 defineProperty(&GuideCCD.RapidGuideDataNP);
1876 }
1877 else
1878 {
1879 deleteProperty(GuideCCD.RapidGuideSetupSP.name);
1880 deleteProperty(GuideCCD.RapidGuideDataNP.name);
1881 }
1882
1883 IDSetSwitch(&GuideCCD.RapidGuideSP, nullptr);
1884 return true;
1885 }
1886
1887 // Primary CCD Rapid Guide Setup
1888 if (strcmp(name, PrimaryCCD.RapidGuideSetupSP.name) == 0)
1889 {
1890 IUUpdateSwitch(&PrimaryCCD.RapidGuideSetupSP, states, names, n);
1891 PrimaryCCD.RapidGuideSetupSP.s = IPS_OK;
1892
1893 AutoLoop = (PrimaryCCD.RapidGuideSetupS[0].s == ISS_ON);
1894 SendImage = (PrimaryCCD.RapidGuideSetupS[1].s == ISS_ON);
1895 ShowMarker = (PrimaryCCD.RapidGuideSetupS[2].s == ISS_ON);
1896
1897 IDSetSwitch(&PrimaryCCD.RapidGuideSetupSP, nullptr);
1898 return true;
1899 }
1900
1901 // Guide Chip Rapid Guide Setup
1902 if (strcmp(name, GuideCCD.RapidGuideSetupSP.name) == 0)
1903 {
1904 IUUpdateSwitch(&GuideCCD.RapidGuideSetupSP, states, names, n);
1905 GuideCCD.RapidGuideSetupSP.s = IPS_OK;
1906
1907 GuiderAutoLoop = (GuideCCD.RapidGuideSetupS[0].s == ISS_ON);
1908 GuiderSendImage = (GuideCCD.RapidGuideSetupS[1].s == ISS_ON);
1909 GuiderShowMarker = (GuideCCD.RapidGuideSetupS[2].s == ISS_ON);
1910
1911 IDSetSwitch(&GuideCCD.RapidGuideSetupSP, nullptr);
1912 return true;
1913 }
1914#endif
1915 }
1916
1917 if (HasStreaming())
1918 Streamer->ISNewSwitch(dev, name, states, names, n);
1919
1920 // DSP
1921 if (HasDSP())
1922 DSP->ISNewSwitch(dev, name, states, names, n);
1923
1924 return DefaultDevice::ISNewSwitch(dev, name, states, names, n);
1925}
1926
1928//
1930bool CCD::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
1931 char *formats[], char *names[], int n)
1932{
1933 // DSP
1934 if (HasDSP())
1935 DSP->ISNewBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
1936
1937 return DefaultDevice::ISNewBLOB(dev, name, sizes, blobsizes, blobs, formats, names, n);
1938}
1939
1941//
1944{
1946 DEBUGF(Logger::DBG_WARNING, "CCD::SetTemperature %4.2f - Should never get here", temperature);
1947 return -1;
1948}
1949
1951//
1953bool CCD::StartExposure(float duration)
1954{
1955 DEBUGF(Logger::DBG_WARNING, "CCD::StartExposure %4.2f - Should never get here", duration);
1956 return false;
1957}
1958
1960//
1962bool CCD::StartGuideExposure(float duration)
1963{
1964 DEBUGF(Logger::DBG_WARNING, "CCD::StartGuide Exposure %4.2f - Should never get here", duration);
1965 return false;
1966}
1967
1969//
1972{
1973 DEBUG(Logger::DBG_WARNING, "CCD::AbortExposure - Should never get here");
1974 return false;
1975}
1976
1978//
1981{
1982 DEBUG(Logger::DBG_WARNING, "CCD::AbortGuideExposure - Should never get here");
1983 return false;
1984}
1985
1987//
1989bool CCD::UpdateCCDFrame(int x, int y, int w, int h)
1990{
1991 // Just set value, unless HW layer overrides this and performs its own processing
1992 PrimaryCCD.setFrame(x, y, w, h);
1993 return true;
1994}
1995
1997//
1999bool CCD::UpdateGuiderFrame(int x, int y, int w, int h)
2000{
2001 GuideCCD.setFrame(x, y, w, h);
2002 return true;
2003}
2004
2006//
2008bool CCD::UpdateCCDBin(int hor, int ver)
2009{
2010 // Just set value, unless HW layer overrides this and performs its own processing
2011 PrimaryCCD.setBin(hor, ver);
2012 // Reset size
2013 if (HasStreaming())
2014 Streamer->setSize(PrimaryCCD.getSubW() / hor, PrimaryCCD.getSubH() / ver);
2015
2016 // DSP
2017 if (HasDSP())
2018 DSP->setSizes(2, new int[2] { PrimaryCCD.getSubW() / hor, PrimaryCCD.getSubH() / ver });
2019
2020 return true;
2021}
2022
2024//
2026bool CCD::UpdateGuiderBin(int hor, int ver)
2027{
2028 // Just set value, unless HW layer overrides this and performs its own processing
2029 GuideCCD.setBin(hor, ver);
2030 return true;
2031}
2032
2034//
2037{
2038 INDI_UNUSED(fType);
2039 // Child classes can override this
2040 return true;
2041}
2042
2044//
2047{
2048 INDI_UNUSED(fType);
2049 // Child classes can override this
2050 return true;
2051}
2052
2054//
2056void CCD::addFITSKeywords(CCDChip * targetChip, std::vector<FITSRecord> &fitsKeywords)
2057{
2058 char dev_name[MAXINDINAME] = {0};
2059 double effectiveFocalLength = std::numeric_limits<double>::quiet_NaN();
2060 double effectiveAperture = std::numeric_limits<double>::quiet_NaN();
2061
2062 AutoCNumeric locale;
2063 fitsKeywords.push_back({"ROWORDER", "TOP-DOWN", "Row Order"});
2064 fitsKeywords.push_back({"INSTRUME", getDeviceName(), "Camera Name"});
2065
2066 // Telescope
2067 // Only add keyword if not already exists in custom keywords
2068 if (m_CustomFITSKeywords.count("TELESCOP") == 0 && strlen(ActiveDeviceTP[ACTIVE_TELESCOPE].getText()) > 0)
2069 {
2070 fitsKeywords.push_back({"TELESCOP", ActiveDeviceTP[ACTIVE_TELESCOPE].getText(), "Telescope name"});
2071 }
2072
2073
2074 // Which scope is in effect
2075 // Prefer Scope Info over snooped property which should be deprecated.
2076 effectiveFocalLength = ScopeInfoNP[FOCAL_LENGTH].getValue() > 0 ? ScopeInfoNP[FOCAL_LENGTH].getValue() :
2078 effectiveAperture = ScopeInfoNP[APERTURE].getValue() > 0 ? ScopeInfoNP[APERTURE].getValue() : snoopedAperture;
2079
2080 if (std::isnan(effectiveFocalLength))
2081 LOG_WARN("Telescope focal length is missing.");
2082 if (std::isnan(effectiveAperture))
2083 LOG_WARN("Telescope aperture is missing.");
2084
2085 double subPixSize1 = static_cast<double>(targetChip->getPixelSizeX());
2086 double subPixSize2 = static_cast<double>(targetChip->getPixelSizeY());
2087 uint32_t subW = targetChip->getSubW();
2088 uint32_t subH = targetChip->getSubH();
2089 uint32_t subBinX = targetChip->getBinX();
2090 uint32_t subBinY = targetChip->getBinY();
2091
2092 snprintf(dev_name, sizeof(dev_name), "%s", getDeviceName());
2093
2094 fitsKeywords.push_back({"EXPTIME", exposureDuration, 6, "Total Exposure Time (s)"});
2095
2096 if (targetChip->getFrameType() == CCDChip::DARK_FRAME)
2097 fitsKeywords.push_back({"DARKTIME", exposureDuration, 6, "Total Dark Exposure Time (s)"});
2098
2099 // If the camera has a cooler OR if the temperature permission was explicitly set to Read-Only, then record the temperature
2100 if (HasCooler() || TemperatureNP.getPermission() == IP_RO)
2101 fitsKeywords.push_back({"CCD-TEMP", TemperatureNP[0].getValue(), 3, "CCD Temperature (Celsius)"});
2102
2103 fitsKeywords.push_back({"PIXSIZE1", subPixSize1, 6, "Pixel Size 1 (microns)"});
2104 fitsKeywords.push_back({"PIXSIZE2", subPixSize2, 6, "Pixel Size 2 (microns)"});
2105 fitsKeywords.push_back({"XBINNING", targetChip->getBinX(), "Binning factor in width"});
2106 fitsKeywords.push_back({"YBINNING", targetChip->getBinY(), "Binning factor in height"});
2107 // XPIXSZ and YPIXSZ are logical sizes including the binning factor
2108 double xpixsz = subPixSize1 * subBinX;
2109 double ypixsz = subPixSize2 * subBinY;
2110 fitsKeywords.push_back({"XPIXSZ", xpixsz, 6, "X binned pixel size in microns"});
2111 fitsKeywords.push_back({"YPIXSZ", ypixsz, 6, "Y binned pixel size in microns"});
2112
2113 switch (targetChip->getFrameType())
2114 {
2116 fitsKeywords.push_back({"FRAME", "Light", "Frame Type"});
2117 fitsKeywords.push_back({"IMAGETYP", "Light Frame", "Frame Type"});
2118 break;
2120 fitsKeywords.push_back({"FRAME", "Bias", "Frame Type"});
2121 fitsKeywords.push_back({"IMAGETYP", "Bias Frame", "Frame Type"});
2122 break;
2124 fitsKeywords.push_back({"FRAME", "Flat", "Frame Type"});
2125 fitsKeywords.push_back({"IMAGETYP", "Flat Frame", "Frame Type"});
2126 break;
2128 fitsKeywords.push_back({"FRAME", "Dark", "Frame Type"});
2129 fitsKeywords.push_back({"IMAGETYP", "Dark Frame", "Frame Type"});
2130 break;
2131 }
2132
2133 if (CurrentFilterSlot != -1 && CurrentFilterSlot <= static_cast<int>(FilterNames.size()))
2134 {
2135 fitsKeywords.push_back({"FILTER", FilterNames.at(CurrentFilterSlot - 1).c_str(), "Filter"});
2136 }
2137
2138#ifdef WITH_MINMAX
2139 if (targetChip->getNAxis() == 2)
2140 {
2141 double min_val, max_val;
2142 getMinMax(&min_val, &max_val, targetChip);
2143
2144 fitsKeywords.push_back({"DATAMIN", min_val, 6, "Minimum value"});
2145 fitsKeywords.push_back({"DATAMAX", max_val, 6, "Maximum value"});
2146 }
2147#endif
2148
2149 if (HasBayer() && targetChip->getNAxis() == 2)
2150 {
2151 fitsKeywords.push_back({"XBAYROFF", atoi(BayerTP[CFA_OFFSET_X].getText()), "X offset of Bayer array"});
2152 fitsKeywords.push_back({"YBAYROFF", atoi(BayerTP[CFA_OFFSET_Y].getText()), "Y offset of Bayer array"});
2153 fitsKeywords.push_back({"BAYERPAT", BayerTP[CFA_TYPE].getText(), "Bayer color pattern"});
2154 }
2155
2156 if (!std::isnan(effectiveFocalLength))
2157 fitsKeywords.push_back({"FOCALLEN", effectiveFocalLength, 3, "Focal Length (mm)"});
2158
2159 if (!std::isnan(effectiveAperture))
2160 fitsKeywords.push_back({"APTDIA", effectiveAperture, 3, "Telescope diameter (mm)"});
2161
2162 if (!std::isnan(MPSAS))
2163 {
2164 fitsKeywords.push_back({"MPSAS", MPSAS, 6, "Sky Quality (mag per arcsec^2)"});
2165 }
2166
2167 if (!std::isnan(RotatorAngle))
2168 {
2169 fitsKeywords.push_back({"ROTATANG", RotatorAngle, 3, "Rotator angle in degrees"});
2170 }
2171
2172 if (!std::isnan(RotatorPosition))
2173 {
2174 fitsKeywords.push_back({"ROTSTEPS", RotatorPosition, 0, "Rotator absolute position in steps"});
2175 }
2176
2177 // JJ ed 2020-03-28
2178 // If the focus position or temperature is set, add the information to the FITS header
2179 if (FocuserPos != -1)
2180 {
2181 fitsKeywords.push_back({"FOCUSPOS", FocuserPos, "Focus position in steps"});
2182 }
2183 if (!std::isnan(FocuserTemp))
2184 {
2185 fitsKeywords.push_back({"FOCUSTEM", FocuserTemp, 3, "Focuser temperature in degrees C"});
2186 }
2187
2188 // SCALE assuming square-pixels
2189 if (!std::isnan(effectiveFocalLength))
2190 {
2191 double pixScale = subPixSize1 / effectiveFocalLength * 206.3 * subBinX;
2192 fitsKeywords.push_back({"SCALE", pixScale, 6, "arcsecs per pixel"});
2193 }
2194
2195
2196 if ( targetChip->getFrameType() == CCDChip::LIGHT_FRAME && !std::isnan(RA) && !std::isnan(Dec) && (std::isnan(J2000RA)
2197 || std::isnan(J2000DE) || !J2000Valid) )
2198 {
2199 INDI::IEquatorialCoordinates epochPos { 0, 0 }, J2000Pos { 0, 0 };
2200 epochPos.rightascension = RA;
2201 epochPos.declination = Dec;
2202
2203 // Convert from JNow to J2000
2204 INDI::ObservedToJ2000(&epochPos, ln_get_julian_from_sys(), &J2000Pos);
2205
2206 J2000RA = J2000Pos.rightascension;
2207 J2000DE = J2000Pos.declination;
2208 }
2209 J2000Valid = false; // enforce usage of EOD position if we receive no new epoch position
2210
2211 if ( targetChip->getFrameType() == CCDChip::LIGHT_FRAME && !std::isnan(J2000RA) && !std::isnan(J2000DE) )
2212 {
2213 if (!std::isnan(Latitude) && !std::isnan(Longitude))
2214 {
2215 INDI::IEquatorialCoordinates epochPos { 0, 0 }, J2000Pos { 0, 0 };
2216
2217 J2000Pos.rightascension = J2000RA;
2218 J2000Pos.declination = J2000DE;
2219
2220 // Convert from JNow to J2000
2221 INDI::J2000toObserved(&J2000Pos, ln_get_julian_from_sys(), &epochPos);
2222
2223 // Horizontal Coords
2224 INDI::IHorizontalCoordinates horizontalPos;
2225 IGeographicCoordinates observer;
2226 observer.latitude = Latitude;
2227 observer.longitude = Longitude;
2228
2229 EquatorialToHorizontal(&epochPos, &observer, ln_get_julian_from_sys(), &horizontalPos);
2230 Azimuth = horizontalPos.azimuth;
2231 Altitude = horizontalPos.altitude;
2232 Airmass = ln_get_airmass(Altitude, 750);
2233 }
2234
2235 char ra_str[32] = {0}, de_str[32] = {0};
2236
2237 fs_sexa(ra_str, J2000RA, 2, 360000);
2238 fs_sexa(de_str, J2000DE, 2, 360000);
2239
2240 char * raPtr = ra_str, *dePtr = de_str;
2241 while (*raPtr != '\0')
2242 {
2243 if (*raPtr == ':')
2244 *raPtr = ' ';
2245 raPtr++;
2246 }
2247 while (*dePtr != '\0')
2248 {
2249 if (*dePtr == ':')
2250 *dePtr = ' ';
2251 dePtr++;
2252 }
2253
2254 if (!std::isnan(Latitude) && !std::isnan(Longitude))
2255 {
2256 fitsKeywords.push_back({"SITELAT", Latitude, 6, "Latitude of the imaging site in degrees"});
2257 fitsKeywords.push_back({"SITELONG", Longitude, 6, "Longitude of the imaging site in degrees"});
2258 }
2259 if (!std::isnan(Airmass))
2260 {
2261 //fits_update_key_s(fptr, TDOUBLE, "AIRMASS", &Airmass, "Airmass", &status);
2262 fitsKeywords.push_back({"AIRMASS", Airmass, 6, "Airmass"});
2263 fitsKeywords.push_back({"OBJCTAZ", Azimuth, 6, "Azimuth of center of image in Degrees"});
2264 fitsKeywords.push_back({"OBJCTALT", Altitude, 6, "Altitude of center of image in Degrees"});
2265 }
2266 fitsKeywords.push_back({"OBJCTRA", ra_str, "Object J2000 RA in Hours"});
2267 fitsKeywords.push_back({"OBJCTDEC", de_str, "Object J2000 DEC in Degrees"});
2268
2269 fitsKeywords.push_back({"RA", J2000RA * 15, 6, "Object J2000 RA in Degrees"});
2270 fitsKeywords.push_back({"DEC", J2000DE, 6, "Object J2000 DEC in Degrees"});
2271
2272 // pier side
2273 switch (pierSide)
2274 {
2275 case 0:
2276 fitsKeywords.push_back({"PIERSIDE", "WEST", "West, looking East"});
2277 break;
2278 case 1:
2279 fitsKeywords.push_back({"PIERSIDE", "EAST", "East, looking West"});
2280 break;
2281 }
2282
2283 //fits_update_key_s(fptr, TINT, "EPOCH", &epoch, "Epoch", &status);
2284 fitsKeywords.push_back({"EQUINOX", 2000, "Equinox"});
2285
2286 // Add WCS Info
2287 if (WorldCoordSP[WCS_ENABLE].getState() == ISS_ON && m_ValidCCDRotation && !std::isnan(effectiveFocalLength))
2288 {
2289 double J2000RAHours = J2000RA * 15;
2290 fitsKeywords.push_back({"CRVAL1", J2000RAHours, 10, "CRVAL1"});
2291 fitsKeywords.push_back({"CRVAL2", J2000DE, 10, "CRVAL1"});
2292
2293 char radecsys[8] = "FK5";
2294 char ctype1[16] = "RA---TAN";
2295 char ctype2[16] = "DEC--TAN";
2296
2297 fitsKeywords.push_back({"RADECSYS", radecsys, "RADECSYS"});
2298 fitsKeywords.push_back({"CTYPE1", ctype1, "CTYPE1"});
2299 fitsKeywords.push_back({"CTYPE2", ctype2, "CTYPE2"});
2300
2301 double crpix1 = subW / subBinX / 2.0;
2302 double crpix2 = subH / subBinY / 2.0;
2303
2304 fitsKeywords.push_back({"CRPIX1", crpix1, 10, "CRPIX1"});
2305 fitsKeywords.push_back({"CRPIX2", crpix2, 10, "CRPIX2"});
2306
2307 double secpix1 = subPixSize1 / effectiveFocalLength * 206.3 * subBinX;
2308 double secpix2 = subPixSize2 / effectiveFocalLength * 206.3 * subBinY;
2309
2310 fitsKeywords.push_back({"SECPIX1", secpix1, 10, "SECPIX1"});
2311 fitsKeywords.push_back({"SECPIX2", secpix2, 10, "SECPIX2"});
2312
2313 double degpix1 = secpix1 / 3600.0;
2314 double degpix2 = secpix2 / 3600.0;
2315
2316 fitsKeywords.push_back({"CDELT1", degpix1, 10, "CDELT1"});
2317 fitsKeywords.push_back({"CDELT2", degpix2, 10, "CDELT2"});
2318
2319 // Rotation is CW, we need to convert it to CCW per CROTA1 definition
2320 double rotation = 360 - CCDRotationNP[0].getValue();
2321 if (rotation > 360)
2322 rotation -= 360;
2323
2324 fitsKeywords.push_back({"CROTA1", rotation, 10, "CROTA1"});
2325 fitsKeywords.push_back({"CROTA2", rotation, 10, "CROTA2"});
2326
2327 double rotationRad = rotation / 180.0 * M_PI;
2328 fitsKeywords.push_back({"CD1_1", std::cos(rotationRad) * degpix1, 10, "CD1_1"});
2329 fitsKeywords.push_back({"CD1_2",-std::sin(rotationRad) * degpix2, 10, "CD1_2"});
2330 fitsKeywords.push_back({"CD2_1", std::sin(rotationRad) * degpix1, 10, "CD2_1"});
2331 fitsKeywords.push_back({"CD2_2", std::cos(rotationRad) * degpix2, 10, "CD2_2"});
2332 }
2333 }
2334
2335 fitsKeywords.push_back({"DATE-OBS", exposureStartTime, "UTC start date of observation"});
2336
2337 // Add all custom keywords next
2338 for (auto &record : m_CustomFITSKeywords)
2339 fitsKeywords.push_back(record.second);
2340
2341 fitsKeywords.push_back(FITSRecord("Generated by INDI"));
2342}
2343
2345//
2347void CCD::fits_update_key_s(fitsfile * fptr, int type, std::string name, void * p, std::string explanation,
2348 int * status)
2349{
2350 // this function is for removing warnings about deprecated string conversion to char* (from arg 5)
2351 fits_update_key(fptr, type, name.c_str(), p, const_cast<char *>(explanation.c_str()), status);
2352}
2353
2355//
2358{
2359 // Reset POLLMS to default value
2361
2362 // Run async
2363 std::thread(&CCD::ExposureCompletePrivate, this, targetChip).detach();
2364
2365 return true;
2366}
2367
2369//
2371bool CCD::ExposureCompletePrivate(CCDChip * targetChip)
2372{
2373 LOG_DEBUG("Exposure complete");
2374
2375 // save information used for the fits header
2376 exposureDuration = targetChip->getExposureDuration();
2377 snprintf(exposureStartTime, sizeof(exposureStartTime), "%s", targetChip->getExposureStartTime());
2378
2379 if(HasDSP())
2380 {
2381 uint8_t* buf = static_cast<uint8_t*>(malloc(targetChip->getFrameBufferSize()));
2382 memcpy(buf, targetChip->getFrameBuffer(), targetChip->getFrameBufferSize());
2383 DSP->processBLOB(buf, 2, new int[2] { targetChip->getXRes() / targetChip->getBinX(), targetChip->getYRes() / targetChip->getBinY() },
2384 targetChip->getBPP());
2385 free(buf);
2386 }
2387
2388 if (processFastExposure(targetChip) == false)
2389 return false;
2390
2391 bool sendImage = (UploadSP[UPLOAD_CLIENT].getState() == ISS_ON || UploadSP[UPLOAD_BOTH].getState() == ISS_ON);
2392 bool saveImage = (UploadSP[UPLOAD_LOCAL].getState() == ISS_ON || UploadSP[UPLOAD_BOTH].getState() == ISS_ON);
2393
2394 // Do not send or save an empty image.
2395 if (targetChip->getFrameBufferSize() == 0)
2396 sendImage = saveImage = false;
2397
2398 if (sendImage || saveImage)
2399 {
2400 if (EncodeFormatSP[FORMAT_FITS].getState() == ISS_ON)
2401 {
2402 targetChip->setImageExtension("fits");
2403
2404 int img_type = 0;
2405 int byte_type = 0;
2406 int status = 0;
2407 long naxis = targetChip->getNAxis();
2408 long naxes[3];
2409 int nelements = 0;
2410 char error_status[MAXRBUF];
2411
2412 naxes[0] = targetChip->getSubW() / targetChip->getBinX();
2413 naxes[1] = targetChip->getSubH() / targetChip->getBinY();
2414
2415 switch (targetChip->getBPP())
2416 {
2417 case 8:
2418 byte_type = TBYTE;
2419 img_type = BYTE_IMG;
2420 break;
2421
2422 case 16:
2423 byte_type = TUSHORT;
2424 img_type = USHORT_IMG;
2425 break;
2426
2427 case 32:
2428 byte_type = TULONG;
2429 img_type = ULONG_IMG;
2430 break;
2431
2432 default:
2433 LOGF_ERROR("Unsupported bits per pixel value %d", targetChip->getBPP());
2434 return false;
2435 }
2436
2437 nelements = naxes[0] * naxes[1];
2438 if (naxis == 3)
2439 {
2440 nelements *= 3;
2441 naxes[2] = 3;
2442 }
2443
2444 /*DEBUGF(Logger::DBG_DEBUG, "Exposure complete. Image Depth: %s. Width: %d Height: %d nelements: %d", bit_depth.c_str(), naxes[0],
2445 naxes[1], nelements);*/
2446
2447 std::unique_lock<std::mutex> guard(ccdBufferLock);
2448
2449 // 8640 = 2880 * 3 which is sufficient for most cases.
2450 uint32_t size = 8640 + nelements * (targetChip->getBPP() / 8);
2451 // Initialize FITS file.
2452 if (targetChip->openFITSFile(size, status) == false)
2453 {
2454 fits_report_error(stderr, status); /* print out any error messages */
2455 fits_get_errstatus(status, error_status);
2456 LOGF_ERROR("FITS Error: %s", error_status);
2457 return false;
2458 }
2459
2460 auto fptr = *targetChip->fitsFilePointer();
2461
2462 fits_create_img(fptr, img_type, naxis, naxes, &status);
2463
2464 if (status)
2465 {
2466 fits_report_error(stderr, status); /* print out any error messages */
2467 fits_get_errstatus(status, error_status);
2468 LOGF_ERROR("FITS Error: %s", error_status);
2469 targetChip->closeFITSFile();
2470 return false;
2471 }
2472
2473 std::vector<FITSRecord> fitsKeywords;
2474
2475 addFITSKeywords(targetChip, fitsKeywords);
2476
2477 for (auto &keyword : fitsKeywords)
2478 {
2479 int key_status = 0;
2480 switch(keyword.type())
2481 {
2483 break;
2485 fits_write_comment(fptr, keyword.comment().c_str(), &key_status);
2486 break;
2488 fits_update_key_str(fptr, keyword.key().c_str(), keyword.valueString().c_str(), keyword.comment().c_str(), &key_status);
2489 break;
2491 fits_update_key_lng(fptr, keyword.key().c_str(), keyword.valueInt(), keyword.comment().c_str(), &key_status);
2492 break;
2494 fits_update_key_dbl(fptr, keyword.key().c_str(), keyword.valueDouble(), keyword.decimal(), keyword.comment().c_str(),
2495 &key_status);
2496 break;
2497 }
2498 if (key_status)
2499 {
2500 fits_get_errstatus(key_status, error_status);
2501 LOGF_ERROR("FITS key %s Error: %s", keyword.key().c_str(), error_status);
2502 }
2503 }
2504
2505 fits_write_img(fptr, byte_type, 1, nelements, targetChip->getFrameBuffer(), &status);
2506 targetChip->finishFITSFile(status);
2507 if (status)
2508 {
2509 fits_report_error(stderr, status); /* print out any error messages */
2510 fits_get_errstatus(status, error_status);
2511 LOGF_ERROR("FITS Error: %s", error_status);
2512 targetChip->closeFITSFile();
2513 return false;
2514 }
2515
2516
2517 bool rc = uploadFile(targetChip, *(targetChip->fitsMemoryBlockPointer()), *(targetChip->fitsMemorySizePointer()), sendImage,
2518 saveImage);
2519
2520 targetChip->closeFITSFile();
2521
2522 guard.unlock();
2523
2524 if (rc == false)
2525 {
2526 targetChip->setExposureFailed();
2527 return false;
2528 }
2529 }
2530#ifdef HAVE_XISF
2531 else if (EncodeFormatSP[FORMAT_XISF].getState() == ISS_ON)
2532 {
2533 std::vector<FITSRecord> fitsKeywords;
2534 addFITSKeywords(targetChip, fitsKeywords);
2535 targetChip->setImageExtension("xisf");
2536
2537 try
2538 {
2539 AutoCNumeric locale;
2540 LibXISF::Image image;
2541 LibXISF::XISFWriter xisfWriter;
2542
2543 for (auto &keyword : fitsKeywords)
2544 {
2545 image.addFITSKeyword({keyword.key().c_str(), keyword.valueString().c_str(), keyword.comment().c_str()});
2546 image.addFITSKeywordAsProperty(keyword.key().c_str(), keyword.valueString());
2547 }
2548
2549 image.setGeometry(targetChip->getSubW() / targetChip->getBinX(),
2550 targetChip->getSubH() / targetChip->getBinY(),
2551 targetChip->getNAxis() == 2 ? 1 : 3);
2552 switch(targetChip->getBPP())
2553 {
2554 case 8:
2555 image.setSampleFormat(LibXISF::Image::UInt8);
2556 break;
2557 case 16:
2558 image.setSampleFormat(LibXISF::Image::UInt16);
2559 break;
2560 case 32:
2561 image.setSampleFormat(LibXISF::Image::UInt32);
2562 break;
2563 default:
2564 LOGF_ERROR("Unsupported bits per pixel value %d", targetChip->getBPP());
2565 return false;
2566 }
2567
2568 switch(targetChip->getFrameType())
2569 {
2571 image.setImageType(LibXISF::Image::Light);
2572 break;
2574 image.setImageType(LibXISF::Image::Bias);
2575 break;
2577 image.setImageType(LibXISF::Image::Dark);
2578 break;
2580 image.setImageType(LibXISF::Image::Flat);
2581 break;
2582 }
2583
2584 if (targetChip->SendCompressed)
2585 {
2586 if(LibXISF::DataBlock::CompressionCodecSupported(LibXISF::DataBlock::ZSTD))
2587 image.setCompression(LibXISF::DataBlock::ZSTD);
2588 else
2589 image.setCompression(LibXISF::DataBlock::LZ4);
2590 image.setByteshuffling(targetChip->getBPP() / 8);
2591 }
2592
2593 if (HasBayer())
2594 image.setColorFilterArray({2, 2, BayerTP[2].getText()});
2595
2596 if (targetChip->getNAxis() == 3)
2597 {
2598 image.setColorSpace(LibXISF::Image::RGB);
2599 }
2600
2601 std::unique_lock<std::mutex> guard(ccdBufferLock);
2602 std::memcpy(image.imageData(), targetChip->getFrameBuffer(), image.imageDataSize());
2603#ifdef HAVE_XISF_ASTROMETRIC_SOLUTION
2604 image.convertWCSToAstrometricSolution();
2605#endif
2606 xisfWriter.writeImage(image);
2607
2608 LibXISF::ByteArray xisfFile;
2609 xisfWriter.save(xisfFile);
2610 bool rc = uploadFile(targetChip, xisfFile.data(), xisfFile.size(), sendImage, saveImage);
2611 if (rc == false)
2612 {
2613 targetChip->setExposureFailed();
2614 return false;
2615 }
2616 }
2617 catch (LibXISF::Error &error)
2618 {
2619 LOGF_ERROR("XISF Error: %s", error.what());
2620 return false;
2621 }
2622 }
2623#endif
2624 else
2625 {
2626 // If image extension was set to fits (default), change if bin if not already set to another format by the driver.
2627 if (!strcmp(targetChip->getImageExtension(), "fits"))
2628 targetChip->setImageExtension("bin");
2629 std::unique_lock<std::mutex> guard(ccdBufferLock);
2630 bool rc = uploadFile(targetChip, targetChip->getFrameBuffer(), targetChip->getFrameBufferSize(), sendImage,
2631 saveImage);
2632 guard.unlock();
2633
2634 if (rc == false)
2635 {
2636 targetChip->setExposureFailed();
2637 return false;
2638 }
2639 }
2640 }
2641
2642 if (FastExposureToggleSP[INDI_ENABLED].getState() != ISS_ON)
2643 targetChip->setExposureComplete();
2644
2645 UploadComplete(targetChip);
2646 return true;
2647}
2648
2650//
2652bool CCD::uploadFile(CCDChip * targetChip, const void * fitsData, size_t totalBytes, bool sendImage,
2653 bool saveImage)
2654{
2655 uint8_t * compressedData = nullptr;
2656
2657 DEBUGF(Logger::DBG_DEBUG, "Uploading file. Ext: %s, Size: %d, sendImage? %s, saveImage? %s",
2658 targetChip->getImageExtension(), totalBytes, sendImage ? "Yes" : "No", saveImage ? "Yes" : "No");
2659
2660 if (saveImage)
2661 {
2662 targetChip->FitsBP[0].setBlob(const_cast<void *>(fitsData));
2663 targetChip->FitsBP[0].setBlobLen(totalBytes);
2664 std::string format = "." + std::string(targetChip->getImageExtension());
2665 targetChip->FitsBP[0].setFormat(format);
2666 FILE * fp = nullptr;
2667
2668 std::string prefix = UploadSettingsTP[UPLOAD_PREFIX].getText();
2669 std::string directory = UploadSettingsTP[UPLOAD_DIR].getText();
2670
2671 // Expand _HOME_ to this machine's home directory. Clients (e.g. Ekos) cannot
2672 // know in advance what the home directory of a remote INDI server is, so they
2673 // send the _HOME_ token literally and let the driver resolve it locally.
2674 if (const char * home = getenv("HOME"))
2675 replace_all(directory, "_HOME_", home);
2676
2677 int maxIndex = getFileIndex(directory, prefix,
2678 targetChip->FitsBP[0].getFormat());
2679
2680 if (maxIndex < 0)
2681 {
2682 LOGF_ERROR("Error iterating directory %s. %s", directory.c_str(),
2683 strerror(errno));
2684 return false;
2685 }
2686
2687 if (maxIndex > 0)
2688 {
2689 auto now = std::chrono::system_clock::now();
2690 std::time_t time = std::chrono::system_clock::to_time_t(now);
2691 std::tm* now_tm = std::localtime(&time);
2692 long long timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
2693
2694 std::stringstream stream;
2695 // JM 2023.08.31 Make timestamps OS friendly (Windows)
2696 stream << std::setfill('0')
2697 << std::put_time(now_tm, "%FT%H-%M-")
2698 << std::setw(2) << (timestamp / 1000) % 60 << '.'
2699 << std::setw(3) << timestamp % 1000;
2700
2701 prefix = std::regex_replace(prefix, std::regex("ISO8601"), stream.str());
2702
2703 char indexString[8];
2704 snprintf(indexString, 8, "%03d", maxIndex);
2705 std::string prefixIndex = indexString;
2706 //prefix.replace(prefix.find("XXX"), std::string::npos, prefixIndex);
2707 prefix = std::regex_replace(prefix, std::regex("XXX"), prefixIndex);
2708 }
2709
2710 std::string imageFileName = directory + "/" + prefix + std::string(
2711 targetChip->FitsBP[0].getFormat());
2712
2713 fp = fopen(imageFileName.c_str(), "w");
2714 if (fp == nullptr)
2715 {
2716 LOGF_ERROR("Unable to save image file (%s). %s", imageFileName.c_str(), strerror(errno));
2717 return false;
2718 }
2719
2720 int n = 0;
2721 auto len = targetChip->FitsBP[0].getBlobLen();
2722 auto buffer = static_cast<char *>(targetChip->FitsBP[0].getBlob());
2723 for (int nr = 0; nr < len; nr += n)
2724 n = fwrite(buffer + nr, 1, len - nr, fp);
2725
2726 fclose(fp);
2727
2728 // Save image file path
2729 FileNameTP[0].setText(imageFileName);
2730
2731 LOGF_INFO("Image saved to %s", imageFileName.c_str());
2732 FileNameTP.setState(IPS_OK);
2733 FileNameTP.apply();
2734 }
2735
2736 if (targetChip->SendCompressed && EncodeFormatSP[FORMAT_XISF].getState() != ISS_ON)
2737 {
2738 if (EncodeFormatSP[FORMAT_FITS].getState() == ISS_ON && !strcmp(targetChip->getImageExtension(), "fits"))
2739 {
2740 fpstate fpvar;
2741 fp_init (&fpvar);
2742 size_t compressedBytes = 0;
2743 int islossless = 0;
2744 if (fp_pack_data_to_data(reinterpret_cast<const char *>(fitsData), totalBytes, &compressedData, &compressedBytes, fpvar,
2745 &islossless) < 0)
2746 {
2747 free(compressedData);
2748 LOG_ERROR("Error: Ran out of memory compressing image");
2749 return false;
2750 }
2751
2752 targetChip->FitsBP[0].setBlob(compressedData);
2753 targetChip->FitsBP[0].setBlobLen(compressedBytes);
2754 std::string format = "." + std::string(targetChip->getImageExtension()) + ".fz";
2755 targetChip->FitsBP[0].setFormat(format);
2756 }
2757 else
2758 {
2759 uLong compressedBytes = sizeof(char) * totalBytes + totalBytes / 64 + 16 + 3;
2760 compressedData = new uint8_t[compressedBytes];
2761
2762 if (fitsData == nullptr || compressedData == nullptr)
2763 {
2764 if (compressedData)
2765 delete [] compressedData;
2766 LOG_ERROR("Error: Ran out of memory compressing image");
2767 return false;
2768 }
2769
2770 int r = compress2(compressedData, &compressedBytes, (const Bytef *)fitsData, totalBytes, 9);
2771 if (r != Z_OK)
2772 {
2773 /* this should NEVER happen */
2774 LOG_ERROR("Error: Failed to compress image");
2775 delete [] compressedData;
2776 return false;
2777 }
2778
2779 targetChip->FitsBP[0].setBlob(compressedData);
2780 targetChip->FitsBP[0].setBlobLen(compressedBytes);
2781 std::string format = "." + std::string(targetChip->getImageExtension()) + ".z";
2782 targetChip->FitsBP[0].setFormat(format);
2783
2784 }
2785 }
2786 else
2787 {
2788 targetChip->FitsBP[0].setBlob(const_cast<void *>(fitsData));
2789 targetChip->FitsBP[0].setBlobLen(totalBytes);
2790 std::string format = "." + std::string(targetChip->getImageExtension());
2791 targetChip->FitsBP[0].setFormat(format);
2792 }
2793
2794 targetChip->FitsBP[0].setSize(totalBytes);
2795 targetChip->FitsBP.setState(IPS_OK);
2796
2797 if (sendImage)
2798 {
2799 auto start = std::chrono::high_resolution_clock::now();
2800 targetChip->FitsBP.apply();
2801 auto end = std::chrono::high_resolution_clock::now();
2802 std::chrono::duration<double> diff = end - start;
2803 LOGF_DEBUG("BLOB transfer took %g seconds", diff.count());
2804 }
2805
2806 if (compressedData)
2807 delete [] compressedData;
2808
2809 DEBUG(Logger::DBG_DEBUG, "Upload complete");
2810
2811 return true;
2812}
2813
2815//
2818{
2819 // If fast exposure is on, let's immediately take another capture
2820 if (FastExposureToggleSP[INDI_ENABLED].getState() == ISS_ON)
2821 {
2822 targetChip->setExposureComplete();
2823 double duration = targetChip->getExposureDuration();
2824
2825 // Check fast exposure count
2826 if (FastExposureCountNP[0].getValue() > 1)
2827 {
2828 if (UploadSP[UPLOAD_LOCAL].getState() != ISS_ON)
2829 {
2830 if (FastExposureCountNP.getState() != IPS_BUSY)
2831 {
2832 FastExposureToggleStartup = std::chrono::system_clock::now();
2833 }
2834 else
2835 {
2836 auto end = std::chrono::system_clock::now();
2837
2838 m_UploadTime = (std::chrono::duration_cast<std::chrono::milliseconds>(end - FastExposureToggleStartup)).count() / 1000.0 -
2839 duration;
2840 LOGF_DEBUG("Image download and upload/save took %.3f seconds.", m_UploadTime);
2841
2843 }
2844 }
2845
2846 FastExposureCountNP.setState(IPS_BUSY);
2847 FastExposureCountNP[0].setValue(FastExposureCountNP[0].getValue() - 1);
2848 FastExposureCountNP.apply();
2849
2850 if (UploadSP[UPLOAD_LOCAL].getState() == ISS_ON || m_UploadTime < duration)
2851 {
2852 if (StartExposure(duration))
2853 PrimaryCCD.ImageExposureNP.setState(IPS_BUSY);
2854 else
2855 PrimaryCCD.ImageExposureNP.setState(IPS_ALERT);
2856 if (duration * 1000 < getCurrentPollingPeriod())
2857 setCurrentPollingPeriod(duration * 950);
2858 }
2859 else
2860 {
2861 LOGF_ERROR("Rapid exposure not possible since upload time is %.2f seconds while exposure time is %.2f seconds.",
2863 duration);
2864 PrimaryCCD.ImageExposureNP.setState(IPS_ALERT);
2865 PrimaryCCD.ImageExposureNP.apply();
2866 FastExposureCountNP[0].setValue(1);
2867 FastExposureCountNP.setState(IPS_IDLE);
2868 FastExposureCountNP.apply();
2869 m_UploadTime = 0;
2870 return false;
2871 }
2872 }
2873 else
2874 {
2875 m_UploadTime = 0;
2876 FastExposureCountNP.setState(IPS_IDLE);
2877 FastExposureCountNP.apply();
2878 }
2879 }
2880
2881 return true;
2882}
2883
2885//
2887void CCD::SetCCDParams(int x, int y, int bpp, float xf, float yf)
2888{
2889 PrimaryCCD.setResolution(x, y);
2890 PrimaryCCD.setFrame(0, 0, x, y);
2891 if (CanBin())
2892 PrimaryCCD.setBin(1, 1);
2893 PrimaryCCD.setPixelSize(xf, yf);
2894 PrimaryCCD.setBPP(bpp);
2895}
2896
2898//
2900void CCD::SetGuiderParams(int x, int y, int bpp, float xf, float yf)
2901{
2902 capability |= CCD_HAS_GUIDE_HEAD;
2903
2904 GuideCCD.setResolution(x, y);
2905 GuideCCD.setFrame(0, 0, x, y);
2906 GuideCCD.setPixelSize(xf, yf);
2907 GuideCCD.setBPP(bpp);
2908}
2909
2911//
2914{
2916
2917 ActiveDeviceTP.save(fp);
2918 UploadSP.save(fp);
2919 UploadSettingsTP.save(fp);
2920 FastExposureToggleSP.save(fp);
2921
2922 PrimaryCCD.CompressSP.save(fp);
2923
2924 if (PrimaryCCD.getCCDInfo().getPermission() != IP_RO)
2925 PrimaryCCD.getCCDInfo().save(fp);
2926
2927 if (!CaptureFormatSP.isEmpty())
2928 CaptureFormatSP.save(fp);
2929 if (!EncodeFormatSP.isEmpty())
2930 EncodeFormatSP.save(fp);
2931
2932 if (HasCooler())
2933 TemperatureRampNP.save(fp);
2934
2935 if (HasGuideHead())
2936 {
2937 GuideCCD.CompressSP.save(fp);
2938 GuideCCD.ImageBinNP.save(fp);
2939 }
2940
2941 if (CanSubFrame() && PrimaryCCD.ImageFrameNP[CCDChip::FRAME_W].getValue() > 0)
2942 PrimaryCCD.ImageFrameNP.save(fp);
2943
2944 if (CanBin())
2945 PrimaryCCD.ImageBinNP.save(fp);
2946
2947 if (HasBayer())
2948 BayerTP.save(fp);
2949
2950 if (HasStreaming())
2951 Streamer->saveConfigItems(fp);
2952
2953 if (HasDSP())
2954 DSP->saveConfigItems(fp);
2955
2956 ScopeInfoNP.save(fp);
2957
2958 return true;
2959}
2960
2962//
2965{
2966 INDI_UNUSED(ms);
2967 LOG_ERROR("The CCD does not support guiding.");
2968 return IPS_ALERT;
2969}
2970
2972//
2975{
2976 INDI_UNUSED(ms);
2977 LOG_ERROR("The CCD does not support guiding.");
2978 return IPS_ALERT;
2979}
2980
2982//
2985{
2986 INDI_UNUSED(ms);
2987 LOG_ERROR("The CCD does not support guiding.");
2988 return IPS_ALERT;
2989}
2990
2992//
2995{
2996 INDI_UNUSED(ms);
2997 LOG_ERROR("The CCD does not support guiding.");
2998 return IPS_ALERT;
2999}
3000
3002//
3004void CCD::getMinMax(double * min, double * max, CCDChip * targetChip)
3005{
3006 int ind = 0, i, j;
3007 int imageHeight = targetChip->getSubH() / targetChip->getBinY();
3008 int imageWidth = targetChip->getSubW() / targetChip->getBinX();
3009 double lmin = 0, lmax = 0;
3010
3011 switch (targetChip->getBPP())
3012 {
3013 case 8:
3014 {
3015 uint8_t * imageBuffer = targetChip->getFrameBuffer();
3016 lmin = lmax = imageBuffer[0];
3017
3018 for (i = 0; i < imageHeight; i++)
3019 for (j = 0; j < imageWidth; j++)
3020 {
3021 ind = (i * imageWidth) + j;
3022 if (imageBuffer[ind] < lmin)
3023 lmin = imageBuffer[ind];
3024 else if (imageBuffer[ind] > lmax)
3025 lmax = imageBuffer[ind];
3026 }
3027 }
3028 break;
3029
3030 case 16:
3031 {
3032 uint16_t * imageBuffer = reinterpret_cast<uint16_t*>(targetChip->getFrameBuffer());
3033 lmin = lmax = imageBuffer[0];
3034
3035 for (i = 0; i < imageHeight; i++)
3036 for (j = 0; j < imageWidth; j++)
3037 {
3038 ind = (i * imageWidth) + j;
3039 if (imageBuffer[ind] < lmin)
3040 lmin = imageBuffer[ind];
3041 else if (imageBuffer[ind] > lmax)
3042 lmax = imageBuffer[ind];
3043 }
3044 }
3045 break;
3046
3047 case 32:
3048 {
3049 uint32_t * imageBuffer = reinterpret_cast<uint32_t*>(targetChip->getFrameBuffer());
3050 lmin = lmax = imageBuffer[0];
3051
3052 for (i = 0; i < imageHeight; i++)
3053 for (j = 0; j < imageWidth; j++)
3054 {
3055 ind = (i * imageWidth) + j;
3056 if (imageBuffer[ind] < lmin)
3057 lmin = imageBuffer[ind];
3058 else if (imageBuffer[ind] > lmax)
3059 lmax = imageBuffer[ind];
3060 }
3061 }
3062 break;
3063 }
3064 *min = lmin;
3065 *max = lmax;
3066}
3067
3069//
3071std::string regex_replace_compat(const std::string &input, const std::string &pattern, const std::string &replace)
3072{
3073 std::stringstream s;
3074 std::regex_replace(std::ostreambuf_iterator<char>(s), input.begin(), input.end(), std::regex(pattern), replace);
3075 return s.str();
3076}
3077
3079//
3081int CCD::getFileIndex(const std::string &dir, const std::string &prefix, const std::string &ext)
3082{
3083 INDI_UNUSED(ext);
3084
3085 // Refuse to operate on an empty directory path — would crash mkpath via unsigned underflow.
3086 if (dir.empty())
3087 {
3088 LOG_ERROR("Upload directory is not set. Please configure the upload directory.");
3089 return -1;
3090 }
3091
3092 DIR * dpdf = nullptr;
3093 struct dirent * epdf = nullptr;
3094 std::vector<std::string> files = std::vector<std::string>();
3095
3096 std::string prefixIndex = prefix;
3097 prefixIndex = regex_replace_compat(prefixIndex, "_ISO8601", "");
3098 prefixIndex = regex_replace_compat(prefixIndex, "_XXX", "");
3099
3100 // Create directory if does not exist
3101 struct stat st;
3102
3103 if (stat(dir.c_str(), &st) == -1)
3104 {
3105 if (errno == ENOENT)
3106 {
3107 LOGF_INFO("Creating directory %s...", dir.c_str());
3108 if (INDI::mkpath(dir, 0755) == -1)
3109 LOGF_ERROR("Error creating directory %s (%s)", dir.c_str(), strerror(errno));
3110 }
3111 else
3112 {
3113 LOGF_ERROR("Couldn't stat directory %s: %s", dir.c_str(), strerror(errno));
3114 return -1;
3115 }
3116 }
3117
3118 dpdf = opendir(dir.c_str());
3119 if (dpdf != nullptr)
3120 {
3121 while ((epdf = readdir(dpdf)))
3122 {
3123 // Skip the current and parent directory entries.
3124 if (strcmp(epdf->d_name, ".") == 0 || strcmp(epdf->d_name, "..") == 0)
3125 continue;
3126 // Only collect files whose name contains the (possibly empty) prefix.
3127 if (prefixIndex.empty() || strstr(epdf->d_name, prefixIndex.c_str()))
3128 files.push_back(epdf->d_name);
3129 }
3130 }
3131 else
3132 return -1;
3133 int maxIndex = 0;
3134
3135 for (uint32_t i = 0; i < files.size(); i++)
3136 {
3137 int index = -1;
3138
3139 std::string file = files.at(i);
3140 std::size_t start = file.find_last_of("_");
3141 std::size_t end = file.find_last_of(".");
3142 if (start != std::string::npos && end != std::string::npos && end > start)
3143 {
3144 index = atoi(file.substr(start + 1, end - start - 1).c_str());
3145 if (index > maxIndex)
3146 maxIndex = index;
3147 }
3148 }
3149
3150 closedir(dpdf);
3151 return (maxIndex + 1);
3152}
3153
3155//
3161
3163//
3166{
3167 LOG_ERROR("Streaming is not supported.");
3168 return false;
3169}
3170
3172//
3175{
3176 LOG_ERROR("Streaming is not supported.");
3177 return false;
3178}
3179
3180
3185{
3186 if (TemperatureNP.getState() == IPS_BUSY)
3187 {
3188 if (std::abs(m_TargetTemperature - TemperatureNP[0].getValue()) <= TemperatureRampNP[RAMP_THRESHOLD].getValue())
3189 {
3190 TemperatureNP.setState(IPS_OK);
3192 TemperatureNP.apply();
3193 }
3194 // When warming up, check if temperature has stabilized at ambient limit
3195 // TEC coolers cannot heat above ambient, so if the target is warmer and
3196 // the temperature stops changing, we declare it stable.
3197 else if (m_TargetTemperature > TemperatureNP[0].getValue())
3198 {
3199 double rampSlope = TemperatureRampNP[RAMP_SLOPE].getValue();
3200 if (rampSlope > 0)
3201 {
3202 // Advance temperature by one step every minute until the target is reached
3203 if (m_TemperatureElapsedTimer.elapsed() >= 60000)
3204 {
3205 double nextTemperature = std::min(m_TargetTemperature, TemperatureNP[0].getValue() + rampSlope);
3206 m_TemperatureElapsedTimer.restart();
3207 SetTemperature(nextTemperature);
3208 }
3209
3210 // Calculate minimum expected time to traverse the full temperature range. Use the total
3211 // ramp time here since m_TemperatureElapsedTimer is restarted on every step above.
3212 double tempDelta = std::abs(m_TargetTemperature - m_InitialRampTemperature);
3213 long minTimeToTarget_ms = static_cast<long>((tempDelta / rampSlope) * 60000);
3214 if (m_TemperatureRampTimer.elapsed() < minTimeToTarget_ms)
3215 return;
3216 }
3217
3218 // After expected ramp time has elapsed (or no ramp configured),
3219 // check if temperature has stabilized at ambient limit.
3220 if (std::abs(TemperatureNP[0].getValue() - m_TemperatureStabilizationValue) <= TemperatureRampNP[RAMP_THRESHOLD].getValue())
3221 {
3222 // If stable for 2+ minutes, declare success (ambient limit reached)
3223 if (m_TemperatureStabilizationTimer.elapsed() >= 120000)
3224 {
3225 LOGF_INFO("Temperature stabilized at %.2f°C (target %.2f°C not reachable, likely limited by ambient temperature).",
3226 TemperatureNP[0].getValue(), m_TargetTemperature);
3227 TemperatureNP.setState(IPS_OK);
3229 TemperatureNP.apply();
3230 }
3231 }
3232 else
3233 {
3234 // Temperature still changing — reset stabilization tracking
3237 }
3238 }
3239 // If we are beyond a minute, check for next step (cooling ramp)
3240 else if (TemperatureRampNP[RAMP_SLOPE].getValue() > 0 && m_TemperatureElapsedTimer.elapsed() >= 60000)
3241 {
3242 double nextTemperature = 0;
3243 // Going down
3244 if (m_TargetTemperature < TemperatureNP[0].getValue())
3245 {
3246 nextTemperature = std::max(m_TargetTemperature, TemperatureNP[0].getValue() - TemperatureRampNP[RAMP_SLOPE].getValue());
3247 }
3248 // Going up
3249 else
3250 {
3251 nextTemperature = std::min(m_TargetTemperature, TemperatureNP[0].getValue() + TemperatureRampNP[RAMP_SLOPE].getValue());
3252 }
3253
3254 m_TemperatureElapsedTimer.restart();
3255 SetTemperature(nextTemperature);
3256 }
3257 }
3258}
3259
3261//
3264{
3265 // Avoid duplicates.
3266 auto pos = std::find_if(m_CaptureFormats.begin(), m_CaptureFormats.end(), [format](auto & oneFormat)
3267 {
3268 return format.name == oneFormat.name;
3269 });
3270 if (pos != m_CaptureFormats.end())
3271 return;
3272
3273 // Add NEW format.
3274 auto count = CaptureFormatSP.size();
3275 CaptureFormatSP.resize(count + 1);
3276 // Format is ON if the label matches the configuration label OR if there is no configuration saved and isDefault is true.
3277 const bool isOn = (format.name == m_ConfigCaptureFormatName) || (m_ConfigCaptureFormatName.empty() && format.isDefault);
3278 CaptureFormatSP[count].fill(format.name.c_str(), format.label.c_str(), isOn ? ISS_ON : ISS_OFF);
3279 m_CaptureFormats.push_back(format);
3280}
3281
3283//
3285bool CCD::SetCaptureFormat(uint8_t index)
3286{
3287 INDI_UNUSED(index);
3288 return true;
3289}
3290
3291}
double temperature
bool isConnected() const
const char * getDeviceName() const
INDI::PropertyText getText(const char *name) const
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition indiccdchip.h:39
void setExposureComplete()
setExposureComplete Mark exposure as complete by setting ImageExposure property to IPS_OK
char * getImageExtension()
bool finishFITSFile(int &status)
Finish any pending write to fits file.
float getPixelSizeY() const
getPixelSizeY Get vertical pixel size in microns.
int getSubH() const
getSubH Get the height of the frame
double getExposureDuration() const
getExposureDuration Get requested exposure duration for the CCD chip in seconds.
int getBPP() const
getBPP Get CCD Chip depth (bits per pixel).
const char * getExposureStartTime()
getExposureStartTime
CCD_FRAME getFrameType() const
isInterlaced
int getBinY() const
getBinY Get vertical binning of the CCD chip.
void closeFITSFile()
closeFITSFile Close the in-memory FITS File.
float getPixelSizeX() const
getPixelSizeX Get horizontal pixel size in microns.
int getXRes() const
getXRes Get the horizontal resolution in pixels of the CCD Chip.
Definition indiccdchip.h:81
int getBinX() const
getBinX Get horizontal binning of the CCD chip.
void setImageExtension(const char *ext)
setImageExtension Set image extension
size_t * fitsMemorySizePointer()
uint8_t * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
int getSubW() const
getSubW Get the width of the frame
int getFrameBufferSize() const
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
void ** fitsMemoryBlockPointer()
int getNAxis() const
int getYRes() const
Get the vertical resolution in pixels of the CCD Chip.
Definition indiccdchip.h:90
fitsfile ** fitsFilePointer()
bool openFITSFile(uint32_t size, int &status)
openFITSFile Allocate memory buffer for internal FITS file structure and open
@ WCS_DISABLE
Definition indiccd.h:735
@ WCS_ENABLE
Definition indiccd.h:734
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:1953
virtual bool processFastExposure(CCDChip *targetChip)
processFastExposure After an exposure is complete, check if fast exposure was enabled....
Definition indiccd.cpp:2817
std::chrono::system_clock::time_point FastExposureToggleStartup
Definition indiccd.h:746
double Longitude
Definition indiccd.h:597
CCDChip PrimaryCCD
Definition indiccd.h:624
INDI::PropertySwitch UploadSP
Definition indiccd.h:713
INDI::PropertySwitch WorldCoordSP
Definition indiccd.h:731
bool HasGuideHead()
Definition indiccd.h:199
std::unique_ptr< StreamManager > Streamer
Definition indiccd.h:622
bool HasCooler()
Definition indiccd.h:223
double J2000RA
Definition indiccd.h:557
bool InExposure
Definition indiccd.h:566
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:2347
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:1930
double m_TemperatureStabilizationValue
Definition indiccd.h:606
INDI::PropertyNumber EqNP
Properties.
Definition indiccd.h:637
bool CanAbort()
Definition indiccd.h:175
@ CFA_OFFSET_Y
Definition indiccd.h:691
@ CFA_OFFSET_X
Definition indiccd.h:690
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:738
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:744
INDI::PropertyText ActiveDeviceTP
ActiveDeviceTP defines 4 devices the camera driver can listen to (snoop) for properties of interest s...
Definition indiccd.h:659
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:1989
virtual void addFITSKeywords(CCDChip *targetChip, std::vector< FITSRecord > &fitsKeywords)
Generate FITS keywords that will be added to FIST/XISF file.
Definition indiccd.cpp:2056
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition indiccd.cpp:1555
INDI::PropertyNumber TemperatureRampNP
Temperature Ramp in C/Min with configurable threshold.
Definition indiccd.h:677
bool SendImage
Definition indiccd.h:573
double RotatorPosition
Definition indiccd.h:588
int CurrentFilterSlot
Definition indiccd.h:618
virtual bool ExposureComplete(CCDChip *targetChip)
Uploads target Chip exposed buffer as FITS to the client. Derived classes should class this function ...
Definition indiccd.cpp:2357
bool ShowMarker
Definition indiccd.h:575
virtual IPState GuideWest(uint32_t ms) override
Guide westward for ms milliseconds.
Definition indiccd.cpp:2994
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:672
std::mutex ccdBufferLock
Definition indiccd.h:615
@ ACTIVE_TELESCOPE
Definition indiccd.h:662
@ ACTIVE_FILTER
Definition indiccd.h:665
@ ACTIVE_FOCUSER
Definition indiccd.h:664
@ ACTIVE_SKYQUALITY
Definition indiccd.h:666
@ ACTIVE_ROTATOR
Definition indiccd.h:663
virtual int SetTemperature(double temperature)
Set CCD temperature.
Definition indiccd.cpp:1943
INDI::PropertyNumber ScopeInfoNP
Definition indiccd.h:723
@ KEYWORD_VALUE
Definition indiccd.h:752
@ KEYWORD_NAME
Definition indiccd.h:751
@ KEYWORD_COMMENT
Definition indiccd.h:753
INDI::PropertyNumber J2000EqNP
J200EqNP Snoop property to read the equatorial J2000 coordinates of the mount. ActiveDeviceTP defines...
Definition indiccd.h:644
INDI::PropertyText FITSHeaderTP
Definition indiccd.h:748
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:1999
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:2008
INDI::PropertySwitch FastExposureToggleSP
Definition indiccd.h:741
INDI::PropertySwitch EncodeFormatSP
Specifies Driver image encoding format (FITS, Native, JPG, ..etc).
Definition indiccd.h:705
double exposureDuration
Definition indiccd.h:563
virtual IPState GuideSouth(uint32_t ms) override
Guide southward for ms milliseconds.
Definition indiccd.cpp:2974
virtual bool SetCaptureFormat(uint8_t index)
SetCaptureFormat Set Active Capture format.
Definition indiccd.cpp:3285
bool GuiderAutoLoop
Definition indiccd.h:572
@ FOCAL_LENGTH
Definition indiccd.h:726
long FocuserPos
Definition indiccd.h:591
@ CCD_HAS_GUIDE_HEAD
Definition indiccd.h:118
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:1962
double J2000DE
Definition indiccd.h:558
virtual bool AbortExposure()
Abort ongoing exposure.
Definition indiccd.cpp:1971
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:2964
INDI::PropertyText BayerTP
BayerTP Bayer pattern offset and type.
Definition indiccd.h:687
char exposureStartTime[MAXINDINAME]
Definition indiccd.h:562
virtual bool StartStreaming()
StartStreaming Start live video streaming.
Definition indiccd.cpp:3165
virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType)
CCD calls this function when Guide frame type is updated by the client.
Definition indiccd.cpp:2046
INDI::PropertyText UploadSettingsTP
Definition indiccd.h:715
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:2984
virtual void addCaptureFormat(const CaptureFormat &format)
addCaptureFormat Add a supported camera native capture format (e.g. Mono, Bayer8.....
Definition indiccd.cpp:3263
double Azimuth
Definition indiccd.h:598
virtual void checkTemperatureTarget()
checkTemperatureTarget Checks the current temperature against target temperature and calculates the n...
Definition indiccd.cpp:3184
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:699
std::vector< std::string > FilterNames
Definition indiccd.h:617
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:2900
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:2026
bool HasDSP()
Definition indiccd.h:257
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save configuration items in XML file.
Definition indiccd.cpp:2913
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:3157
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:702
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
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
double Latitude
Definition indiccd.h:596
bool HasShutter()
Definition indiccd.h:207
@ RAMP_THRESHOLD
Definition indiccd.h:681
@ RAMP_SLOPE
Definition indiccd.h:680
double MPSAS
Definition indiccd.h:582
CCDChip GuideCCD
Definition indiccd.h:625
@ UPLOAD_DIR
Definition indiccd.h:718
@ UPLOAD_PREFIX
Definition indiccd.h:719
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:2036
double RA
Definition indiccd.h:551
INDI::ElapsedTimer m_TemperatureRampTimer
Definition indiccd.h:612
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:2887
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:3174
double snoopedFocalLength
Definition indiccd.h:565
double FocuserTemp
Definition indiccd.h:592
@ FORMAT_NATIVE
Definition indiccd.h:709
@ FORMAT_XISF
Definition indiccd.h:710
@ FORMAT_FITS
Definition indiccd.h:708
std::vector< CaptureFormat > m_CaptureFormats
Definition indiccd.h:620
double m_UploadTime
Definition indiccd.h:745
double m_TargetTemperature
Definition indiccd.h:602
INDI::ElapsedTimer m_TemperatureStabilizationTimer
Definition indiccd.h:607
virtual bool AbortGuideExposure()
Abort ongoing exposure.
Definition indiccd.cpp:1980
double Altitude
Definition indiccd.h:599
double Dec
Definition indiccd.h:551
double ExposureTime
Definition indiccd.h:578
void addPollPeriodControl()
Add Polling period control to the driver.
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
void setCurrentPollingPeriod(uint32_t msec)
setCurrentPollingPeriod Change the current polling period to call TimerHit() function in the driver.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
uint32_t getPollingPeriod() const
getPollingPeriod Return the polling period.
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
void syncDriverInfo()
syncDriverInfo sends the current driver information to the client.
uint32_t getDriverInterface() const
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Process the client newBLOB command.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
virtual void GuideComplete(INDI_EQ_AXIS axis)
Call GuideComplete once the guiding pulse is complete.
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
void initProperties(const char *groupName)
Initialize guider properties. It is recommended to call this function within initProperties() of your...
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Call this function whenever client updates GuideNSNP or GuideWSP properties in the primary device....
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * INFO_TAB
INFO_TAB Where all the properties for general information are located.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
#define M_PI
Definition dsp.h:52
double max(void)
int errno
int fp_pack_data_to_data(const char *inputBuffer, size_t inputBufferSize, unsigned char **outputBuffer, size_t *outputBufferSize, fpstate fpvar, int *islossless)
Definition fpackutil.c:1027
int fp_init(fpstate *fpptr)
Definition fpackutil.c:160
#define min(a, b)
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
@ IP_WO
Definition indiapi.h:183
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
@ ISR_NOFMANY
Definition indiapi.h:173
@ ISR_ATMOST1
Definition indiapi.h:172
#define MAXINDINAME
Definition indiapi.h:189
INDI_EQ_AXIS
const char * IMAGE_SETTINGS_TAB
Definition indiccd.cpp:62
std::string join(std::vector< std::string > const &strings, std::string delim)
Definition indiccd.cpp:68
const char * IMAGE_INFO_TAB
Definition indiccd.cpp:63
const char * GUIDE_HEAD_TAB
Definition indiccd.cpp:64
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Definition indicom.c:130
Implementations for common driver routines.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:490
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition indidevapi.c:376
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition indidevapi.c:398
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:453
#define INDI_UNUSED(x)
Definition indidevapi.h:132
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
#define MAXRBUF
Definition indidriver.c:52
int IUGetConfigOnSwitchName(const char *dev, const char *property, char *name, size_t size)
IUGetConfigOnSwitchLabel Opens configuration file and returns the name of the ON switch property,...
Definition indidriver.c:783
void IDSnoopDevice(const char *snooped_device, const char *snooped_property)
Function a Driver calls to snoop on another Device. Snooped messages will then arrive via ISSnoopDevi...
Definition indidriver.c:143
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
int IUGetConfigOnSwitchIndex(const char *dev, const char *property, int *index)
IUGetConfigOnSwitchIndex Opens configuration file and reads single switch property to find ON switch ...
Definition indidriver.c:719
INDI::GuiderInterface GI
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_DEBUG(txt)
Definition indilogger.h:75
#define DEBUG(priority, msg)
Macro to print log messages. Example of usage of the Logger: DEBUG(DBG_DEBUG, "hello " << "world");.
Definition indilogger.h:56
#define LOG_WARN(txt)
Definition indilogger.h:73
#define LOGF_DEBUG(fmt,...)
Definition indilogger.h:83
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Definition indilogger.h:72
#define LOGF_ERROR(fmt,...)
Definition indilogger.h:80
#define LOG_INFO(txt)
Definition indilogger.h:74
#define DEBUGF(priority, msg,...)
Definition indilogger.h:57
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
Definition lilxml.cpp:644
XMLEle * nextXMLEle(XMLEle *ep, int init)
Iterate an XML element for a list of nesetd XML elements.
Definition lilxml.cpp:555
char * pcdataXMLEle(XMLEle *ep)
Return the pcdata of an XML element.
Definition lilxml.cpp:606
struct xml_ele_ XMLEle
Definition lilxml.h:81
std::vector< uint8_t > buffer
The DSP Namespace adds signal processing to INDI drivers. Primarily written for sensors and detectors...
Namespace to encapsulate INDI client, drivers, and mediator classes.
void J2000toObserved(IEquatorialCoordinates *J2000pos, double jd, IEquatorialCoordinates *observed)
*J2000toObserved converts catalogue to observed
Definition libastro.cpp:81
void EquatorialToHorizontal(IEquatorialCoordinates *object, IGeographicCoordinates *observer, double JD, IHorizontalCoordinates *position)
EquatorialToHorizontal Calculate horizontal coordinates from equatorial coordinates.
Definition libastro.cpp:141
void ObservedToJ2000(IEquatorialCoordinates *observed, double jd, IEquatorialCoordinates *J2000pos)
ObservedToJ2000 converts an observed position to a J2000 catalogue position removes aberration,...
Definition libastro.cpp:51
std::string regex_replace_compat(const std::string &input, const std::string &pattern, const std::string &replace)
Definition indiccd.cpp:3071
void replace_all(std::string &subject, const std::string &search, const std::string &replace)
int mkpath(std::string s, mode_t mode)
@ error
throw a parse_error exception in case of a tag
*brief create JSON pointer *sa reference_tokens end()
uint16_t type
Definition pwc-ioctl.h:0