Debian Codegraph @

kepler.cpp

raw
1 /*
2 INDI Driver for Kepler sCMOS camera.
3 Copyright (C) 2022 Jasem Mutlaq ([email protected])
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "config.h"
21 #include "kepler.h"
22
23 #include <unistd.h>
24 #include <memory>
25 #include <map>
26 #include <locale>
27 #include <codecvt>
28 #include <indielapsedtimer.h>
29
30 #define FLI_MAX_SUPPORTED_CAMERAS 4
31 #define VERBOSE_EXPOSURE 3
32
33 /********************************************************************************
34 *
35 ********************************************************************************/
36 static class Loader
37 {
38 INDI::Timer hotPlugTimer;
39 FPRODEVICEINFO camerasDeviceInfo[FLI_MAX_SUPPORTED_CAMERAS];
40 // Serial / Camera Object
41 std::map<std::wstring, std::shared_ptr<Kepler>> cameras;
42 public:
43 Loader()
44 {
45 load(false);
46 }
47
48 public:
49 size_t getCountOfConnectedCameras()
50 {
51 uint32_t detectedCamerasCount = FLI_MAX_SUPPORTED_CAMERAS;
52 int32_t result = FPROCam_GetCameraList(camerasDeviceInfo, &detectedCamerasCount);
53 return (result >= 0 ? detectedCamerasCount : 0);
54
55 }
56
57 public:
58 void load(bool isHotPlug)
59 {
60 auto usedCameras = std::move(cameras);
61 auto detectedCamerasCount = getCountOfConnectedCameras();
62
63 UniqueName uniqueName(usedCameras);
64
65 for(uint32_t i = 0; i < detectedCamerasCount; i++)
66 {
67 const auto serialID = camerasDeviceInfo[i].cSerialNo;
68
69 // camera already created
70 if (usedCameras.find(serialID) != usedCameras.end())
71 {
72 std::swap(cameras[serialID], usedCameras[serialID]);
73 continue;
74 }
75
76 #ifdef LEGACY_MODE
77 Kepler *kepler = new Kepler(camerasDeviceInfo[i], L"CMOSCam");
78 #else
79 Kepler *kepler = new Kepler(camerasDeviceInfo[i], uniqueName.make(camerasDeviceInfo[i]));
80 #endif
81 cameras[serialID] = std::shared_ptr<Kepler>(kepler);
82 if (isHotPlug)
83 kepler->ISGetProperties(nullptr);
84 }
85 }
86
87 public:
88 class UniqueName
89 {
90 std::map<std::wstring, bool> used;
91 public:
92 UniqueName() = default;
93 explicit UniqueName(const std::map<std::wstring, std::shared_ptr<Kepler>> &usedCameras)
94 {
95
96 for (const auto &camera : usedCameras)
97 {
98 auto name = std::string(camera.second->getDeviceName());
99 auto wname = std::wstring(name.begin(), name.end());
100 used[wname] = true;
101 }
102 }
103
104 std::wstring make(const FPRODEVICEINFO &cameraInfo)
105 {
106 std::wstring cameraName = std::wstring(L"FLI ") + std::wstring(cameraInfo.cFriendlyName);
107 std::wstring uniqueName = cameraName;
108
109 for (int index = 0; used[uniqueName] == true; )
110 uniqueName = cameraName + std::wstring(L" ") + std::to_wstring(++index);
111
112 used[uniqueName] = true;
113 return uniqueName;
114 }
115 };
116 } loader;
117
118 // Map of device type --> Pixel sizes.
119 // Pixel sizes 99 means I couldn't find information on them.
120 std::map<FPRODEVICETYPE, double> Kepler::SensorPixelSize
121 {
122 {FPRO_CAM_DEVICE_TYPE_GSENSE400, 11},
123 {FPRO_CAM_DEVICE_TYPE_GSENSE2020, 6.5},
124 {FPRO_CAM_DEVICE_TYPE_GSENSE4040, 9},
125 {FPRO_CAM_DEVICE_TYPE_GSENSE6060, 10},
126 {FPRO_CAM_DEVICE_TYPE_KODAK47051, 99},
127 {FPRO_CAM_DEVICE_TYPE_KODAK29050, 99},
128 {FPRO_CAM_DEVICE_TYPE_DC230_42, 15},
129 {FPRO_CAM_DEVICE_TYPE_DC230_84, 15},
130 {FPRO_CAM_DEVICE_TYPE_DC4320, 24},
131 {FPRO_CAM_DEVICE_TYPE_SONYIMX183, 2.4},
132 {FPRO_CAM_DEVICE_TYPE_FTM, 99}
133 };
134
135 /********************************************************************************
136 *
137 ********************************************************************************/
138 void Kepler::workerStreamVideo(const std::atomic_bool &isAboutToQuit)
139 {
140
141 }
142
143 /********************************************************************************
144 *
145 ********************************************************************************/
146 void Kepler::workerExposure(const std::atomic_bool &isAboutToQuit, float duration)
147 {
148 int32_t result = FPROCtrl_SetExposure(m_CameraHandle, duration * 1e9, 0, false);
149 if (result != 0)
150 {
151 LOGF_ERROR("%s: Failed to start exposure: %d", __PRETTY_FUNCTION__, result);
152 return;
153 }
154
155 PrimaryCCD.setExposureDuration(duration);
156 LOGF_DEBUG("StartExposure->setexp : %.3fs", duration);
157
158 // Try exposure for 3 times
159 for (int i = 0; i < 3; i++)
160 {
161 result = FPROFrame_CaptureStart(m_CameraHandle, 1);
162 if (result == 0)
163 break;
164
165 // Wait 100ms before trying again
166 usleep(100 * 1000);
167 }
168
169 if (result != 0)
170 {
171 LOGF_ERROR("Failed to start exposure: %d", result);
172 return;
173 }
174
175 INDI::ElapsedTimer exposureTimer;
176
177 if (duration > VERBOSE_EXPOSURE)
178 LOGF_INFO("Taking a %.2f seconds frame...", duration);
179
180 // Countdown if we have a multi-second exposure.
181 // For expsures less than a second, we skip this entirely.
182 double timeLeft = 0.0;
183 do
184 {
185 timeLeft = std::max(duration - exposureTimer.elapsed() / 1000.0, 0.0);
186 if (isAboutToQuit)
187 return;
188
189 auto delay = std::max(timeLeft - std::trunc(timeLeft), 0.005);
190 timeLeft = std::round(timeLeft);
191 PrimaryCCD.setExposureLeft(timeLeft);
192 std::this_thread::sleep_for(std::chrono::microseconds(static_cast<int>(delay * 1e6)));
193 }
194 while (timeLeft > 0);
195
196 uint32_t grabSize = m_TotalFrameBufferSize;
197
198 // This is blocking?
199 std::unique_lock<std::mutex> guard(ccdBufferLock);
200 prepareUnpacked();
201 result = FPROFrame_GetVideoFrameUnpacked(m_CameraHandle,
202 m_FrameBuffer,
203 &grabSize,
204 timeLeft * 1000,
205 &fproUnpacked,
206 RequestStatSP.findOnSwitchIndex() == INDI_ENABLED ? &fproStats : nullptr);
207
208 if (result >= 0)
209 {
210 FPROFrame_CaptureAbort(m_CameraHandle);
211
212 // Send the merged image.
213 switch (IUFindOnSwitchIndex(&MergePlanesSP))
214 {
215 case HWMERGE_FRAME_BOTH:
216 PrimaryCCD.setFrameBuffer(reinterpret_cast<uint8_t*>(fproUnpacked.pMergedImage));
217 PrimaryCCD.setFrameBufferSize(fproUnpacked.uiMergedBufferSize, false);
218 break;
219 case HWMERGE_FRAME_HIGHONLY:
220 PrimaryCCD.setFrameBuffer(reinterpret_cast<uint8_t*>(fproUnpacked.pHighImage));
221 PrimaryCCD.setFrameBufferSize(fproUnpacked.uiHighBufferSize, false);
222 break;
223 case HWMERGE_FRAME_LOWONLY:
224 PrimaryCCD.setFrameBuffer(reinterpret_cast<uint8_t*>(fproUnpacked.pLowImage));
225 PrimaryCCD.setFrameBufferSize(fproUnpacked.uiLowBufferSize, false);
226 break;
227 }
228
229 PrimaryCCD.setExposureLeft(0.0);
230 if (PrimaryCCD.getExposureDuration() > VERBOSE_EXPOSURE)
231 LOG_INFO("Exposure done, downloading image...");
232
233 ExposureComplete(&PrimaryCCD);
234 }
235 else
236 {
237 PrimaryCCD.setExposureFailed();
238 LOGF_ERROR("Failed to grab frame: %d", result);
239 }
240 }
241
242 Kepler::Kepler(const FPRODEVICEINFO &info, std::wstring name) : m_CameraInfo(info)
243 {
244 setVersion(FLI_CCD_VERSION_MAJOR, FLI_CCD_VERSION_MINOR);
245
246 std::wstring_convert<std::codecvt_utf8<wchar_t>> convert;
247 auto byteName = convert.to_bytes(name);
248 setDeviceName(byteName.c_str());
249
250 memset(&fproUnpacked, 0, sizeof(fproUnpacked));
251 memset(&fproStats, 0, sizeof(fproStats));
252
253 m_TemperatureTimer.callOnTimeout(std::bind(&Kepler::readTemperature, this));
254 m_TemperatureTimer.setInterval(TEMPERATURE_FREQUENCY_IDLE);
255
256 m_GPSTimer.callOnTimeout(std::bind(&Kepler::readGPS, this));
257 m_GPSTimer.setInterval(GPS_TIMER_PERIOD);
258 }
259
260 Kepler::~Kepler()
261 {
262
263 }
264
265 const char *Kepler::getDefaultName()
266 {
267 return "FLI Kepler";
268 }
269
270 bool Kepler::initProperties()
271 {
272 // Initialize parent camera properties.
273 INDI::CCD::initProperties();
274
275 // Set Camera capabilities
276 SetCCDCapability(CCD_CAN_ABORT | CCD_CAN_BIN | CCD_CAN_SUBFRAME | CCD_HAS_COOLER | CCD_HAS_SHUTTER);
277
278 // Add capture format
279 CaptureFormat mono = {"INDI_MONO", "Mono", 16, true};
280 addCaptureFormat(mono);
281
282 // Set exposure range
283 // TODO double check this is the supported range.
284 PrimaryCCD.setMinMaxStep("CCD_EXPOSURE", "CCD_EXPOSURE_VALUE", 0.001, 3600, 1, false);
285
286 /*****************************************************************************************************
287 // Properties
288 ******************************************************************************************************/
289
290 // Communication Method
291 CommunicationMethodSP[FPRO_CONNECTION_USB].fill("FPRO_CONNECTION_USB", "USB", ISS_ON);
292 CommunicationMethodSP[FPRO_CONNECTION_FIBRE].fill("FPRO_CONNECTION_FIBRE", "Fiber", ISS_OFF);
293 CommunicationMethodSP.fill(getDeviceName(), "COMMUNICATION_METHOD", "Connect Via", OPTIONS_TAB, IP_RO, ISR_1OFMANY, 60,
294 IPS_IDLE);
295
296 // Merge Method
297 MergeMethodSP[FPROMERGE_ALGO].fill("FPROMERGE_ALGO", "Default", ISS_ON);
298 MergeMethodSP[FPROMERGE_ALGO_REF_FRAME].fill("FPROMERGE_ALGO_REF_FRAME", "Hardware", ISS_OFF);
299 MergeMethodSP.fill(getDeviceName(), "MERGE_METHOD", "Merging", IMAGE_SETTINGS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
300
301 // Merge Planes
302 MergePlanesSP[HWMERGE_FRAME_BOTH].fill("HWMERGE_FRAME_BOTH", "Both", ISS_ON);
303 MergePlanesSP[HWMERGE_FRAME_LOWONLY].fill("HWMERGE_FRAME_LOWONLY", "Low Only", ISS_OFF);
304 MergePlanesSP[HWMERGE_FRAME_HIGHONLY].fill("HWMERGE_FRAME_HIGHONLYE", "High Only", ISS_OFF);
305 MergePlanesSP.fill(getDeviceName(), "MERGE_PLANES", "Merging", IMAGE_SETTINGS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
306
307 // Calibration Frames (for MERGE_HARDWARE)
308 MergeCalibrationFilesTP[CALIBRATION_DARK].fill("CALIBRATION_DARK", "Dark", "");
309 MergeCalibrationFilesTP[CALIBRATION_FLAT].fill("CALIBRATION_FLAT", "Flat", "");
310 MergeCalibrationFilesTP.fill(getDeviceName(), "MERGE_CALIBRATION_FRAMES", "Calibration", IMAGE_SETTINGS_TAB, IP_RW, 60,
311 IPS_IDLE);
312
313 // Cooler Duty Cycle
314 CoolerDutyNP[0].fill("CCD_COOLER_VALUE", "Cooling Power (%)", "%+06.2f", 0., 100., 5, 0.0);
315 CoolerDutyNP.fill(getDeviceName(), "CCD_COOLER_POWER", "Cooling Power", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE);
316
317 // Fan
318 FanSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_OFF);
319 FanSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled", ISS_ON);
320 FanSP.fill(getDeviceName(), "FAN_CONTROL", "Fan", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
321
322 // Black Level
323 BlackLevelNP[0].fill("VALUE", "Value", "%.f", 0, 1000, 10, 0);
324 BlackLevelNP.fill(getDeviceName(), "BLACK_LEVEL", "Black Level", IMAGE_SETTINGS_TAB, IP_RW, 60, IPS_IDLE);
325
326 // GPS
327 GPSStateLP[FPRO_GPS_NOT_DETECTED].fill("FPRO_GPS_NOT_DETECTED", "Not detected", IPS_IDLE);
328 GPSStateLP[FPRO_GPS_DETECTED_NO_SAT_LOCK].fill("FPRO_GPS_DETECTED_NO_SAT_LOCK", "No Sat lock", IPS_IDLE);
329 GPSStateLP[FPRO_GPS_DETECTED_AND_SAT_LOCK].fill("FPRO_GPS_DETECTED_AND_SAT_LOCK", "Sat locked", IPS_IDLE);
330 GPSStateLP.fill(getDeviceName(), "GPS_STATE", "GPS", GPS_TAB, IPS_IDLE);
331
332 // Request Stats
333 RequestStatSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_ON);
334 RequestStatSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled", ISS_OFF);
335 RequestStatSP.fill(getDeviceName(), "REQUEST_STATS", "Statistics", IMAGE_SETTINGS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
336
337 /*****************************************************************************************************
338 // Legacy Properties
339 ******************************************************************************************************/
340 #ifdef LEGACY_MODE
341 ExpValuesNP[ExpTime].fill("ExpTime", "ExpTime", "%.f", 0, 3600, 1, 1);
342 ExpValuesNP[ROIW].fill("ROIW", "ROIW", "%.f", 0, 4096, 1, 4096);
343 ExpValuesNP[ROIH].fill("ROIH", "ROIH", "%.f", 0, 4096, 1, 4096);
344 ExpValuesNP[OSW].fill("OSW", "OSW", "%.f", 0, 1, 1, 0);
345 ExpValuesNP[OSH].fill("OSH", "OSH", "%.f", 0, 1, 1, 0);
346 ExpValuesNP[BinW].fill("BinW", "BinW", "%.f", 1, 4, 1, 1);
347 ExpValuesNP[BinH].fill("BinH", "BinH", "%.f", 1, 4, 1, 1);
348 ExpValuesNP[ROIX].fill("ROIX", "ROIX", "%.f", 0, 100, 1, 0);
349 ExpValuesNP[ROIY].fill("ROIY", "ROIY", "%.f", 0, 100, 1, 0);
350 ExpValuesNP[Shutter].fill("Shutter", "Shutter", "%.f", 0, 1, 1, 1);
351 ExpValuesNP[Type].fill("Type", "Type", "%.f", 0, 4, 1, 4);
352 ExpValuesNP.fill(getDeviceName(), "ExpValues", "ExpValues", LEGACY_TAB, IP_RW, 60, IPS_IDLE);
353 // Trigger
354 ExposureTriggerSP[0].fill("Go", "Start Exposure", ISS_OFF);
355 ExposureTriggerSP.fill(getDeviceName(), "ExpGo", "Control Exposure", LEGACY_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
356 // Set Point
357 TemperatureSetNP[0].fill("Target", "Target", "%.f", -40, 20, 5, 0);
358 TemperatureSetNP.fill(getDeviceName(), "SetTemp", "Set Temperature", LEGACY_TAB, IP_RW, 60, IPS_IDLE);
359 // Temperature readout and cooler value
360 TemperatureReadNP[0].fill("Temp", "Temp", "%.f", -40, 40, 10, 0);
361 TemperatureReadNP[1].fill("Drive", "Cooler", "%.f", 0, 100, 10, 0);
362 TemperatureReadNP.fill(getDeviceName(), "TempNow", "Cooler Temp.", LEGACY_TAB, IP_RO, 60, IPS_IDLE);
363
364
365 #endif
366 addAuxControls();
367
368 return true;
369 }
370
371 /********************************************************************************
372 *
373 ********************************************************************************/
374 void Kepler::ISGetProperties(const char *dev)
375 {
376 INDI::CCD::ISGetProperties(dev);
377 defineProperty(&CommunicationMethodSP);
378
379 #ifdef LEGACY_MODE
380 defineProperty(ExpValuesNP);
381 defineProperty(ExposureTriggerSP);
382 defineProperty(TemperatureSetNP);
383 defineProperty(TemperatureReadNP);
384 #endif
385
386 }
387
388 /********************************************************************************
389 *
390 ********************************************************************************/
391 bool Kepler::updateProperties()
392 {
393 INDI::CCD::updateProperties();
394
395 if (isConnected())
396 {
397 setup();
398
399 defineProperty(CoolerDutyNP);
400 defineProperty(MergeMethodSP);
401 defineProperty(MergePlanesSP);
402 defineProperty(MergeCalibrationFilesTP);
403 defineProperty(LowGainSP);
404 defineProperty(HighGainSP);
405 defineProperty(FanSP);
406 defineProperty(BlackLevelNP);
407 defineProperty(GPSStateLP);
408 defineProperty(RequestStatSP);
409 }
410 else
411 {
412 deleteProperty(CoolerDutyNP);
413 deleteProperty(MergeMethodSP);
414 deleteProperty(MergePlanesSP);
415 deleteProperty(MergeCalibrationFilesTP);
416 deleteProperty(LowGainSP);
417 deleteProperty(HighGainSP);
418 deleteProperty(FanSP);
419 deleteProperty(BlackLevelNP);
420 deleteProperty(GPSStateLP);
421 deleteProperty(RequestStatSP);
422 }
423
424 return true;
425 }
426
427 /********************************************************************************
428 *
429 ********************************************************************************/
430 bool Kepler::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
431 {
432 if (dev != nullptr && !strcmp(dev, getDeviceName()))
433 {
434 // Black Level
435 if (BlackLevelNP.isNameMatch(name))
436 {
437 if (FPROSensor_SetBlackLevelAdjust(m_CameraHandle, values[0]) >= 0)
438 {
439 BlackLevelNP.update(values, names, n);
440 BlackLevelNP.setState(IPS_OK);
441 }
442 else
443 BlackLevelNP.setState(IPS_ALERT);
444 BlackLevelNP.apply();
445 return true;
446 }
447
448 // Legacy Exposure Values
449 #ifdef LEGACY_MODE
450 if (ExpValuesNP.isNameMatch(name))
451 {
452 ExpValuesNP.update(values, names, n);
453 m_ExposureRequest = ExpValuesNP[ExpTime].value;
454
455 // ROI
456 {
457 double tvalues[4] = {ExpValuesNP[ROIX].value, ExpValuesNP[ROIY].value, ExpValuesNP[ROIW].value, ExpValuesNP[ROIH].value};
458 const char *tnames[4] = {"X", "Y", "WIDTH", "HEIGHT"};
459 ISNewNumber(getDeviceName(), "CCD_FRAME", tvalues, const_cast<char **>(tnames), 4);
460 }
461
462 // Binning
463 {
464 double tvalues[2] = {ExpValuesNP[BinW].value, ExpValuesNP[BinH].value};
465 const char *tnames[2] = {"HOR_BIN", "VER_BIN"};
466 ISNewNumber(getDeviceName(), "CCD_BINNING", tvalues, const_cast<char **>(tnames), 2);
467 }
468
469 // Frame Type
470 {
471 ISState tstates[4] = {ISS_OFF, ISS_OFF, ISS_OFF, ISS_OFF};
472 const char *tnames[4] = {"FRAME_LIGHT", "FRAME_BIAS", "FRAME_DARK", "FRAME_FLAT"};
473
474 int frameType = ExpValuesNP[Type].value;
475 if (frameType == 0 || frameType == 4)
476 tstates[0] = ISS_ON;
477 else
478 tstates[frameType] = ISS_ON;
479 ISNewSwitch(getDeviceName(), "CCD_FRAME_TYPE", tstates, const_cast<char **>(tnames), 4);
480 }
481
482 ExpValuesNP.setState(IPS_OK);
483 ExpValuesNP.apply();
484 return true;
485 }
486
487 if (TemperatureSetNP.isNameMatch(name))
488 {
489 TemperatureSetNP.update(values, names, n);
490 double tvalues[1] = {TemperatureSetNP[0].value};
491 const char *tnames[1] = {TemperatureN[0].name};
492 ISNewNumber(getDeviceName(), "CCD_TEMPERATURE", tvalues, const_cast<char **>(tnames), 1);
493 TemperatureSetNP.setState(IPS_OK);
494 TemperatureSetNP.apply();
495 return true;
496 }
497
498 #endif
499 }
500
501 return INDI::CCD::ISNewNumber(dev, name, values, names, n);
502 }
503
504 /********************************************************************************
505 *
506 ********************************************************************************/
507 bool Kepler::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
508 {
509 if (dev != nullptr && !strcmp(dev, getDeviceName()))
510 {
511 // Merge Planes
512 if (MergePlanesSP.isNameMatch(name))
513 {
514 MergePlanesSP.update(states, names, n);
515 MergePlanesSP.setState(IPS_OK);
516
517 int index = IUFindOnSwitchIndex(&MergePlanesSP);
518 fproUnpacked.bLowImageRequest = index == HWMERGE_FRAME_LOWONLY || index == HWMERGE_FRAME_BOTH;
519 fproUnpacked.bHighImageRequest = index == HWMERGE_FRAME_HIGHONLY || index == HWMERGE_FRAME_BOTH;
520 fproUnpacked.bMergedImageRequest = index == HWMERGE_FRAME_BOTH;
521 fproUnpacked.bMetaDataRequest = true;
522 fproStats.bLowRequest = index == HWMERGE_FRAME_LOWONLY || index == HWMERGE_FRAME_BOTH;
523 fproStats.bHighRequest = index == HWMERGE_FRAME_HIGHONLY || index == HWMERGE_FRAME_BOTH;
524 fproStats.bMergedRequest = index == HWMERGE_FRAME_BOTH;
525
526 MergePlanesSP.apply();
527 saveConfig(MergePlanesSP);
528 return true;
529 }
530
531 // Merge Methods
532 if (MergeMethodSP.isNameMatch(name))
533 {
534 int previousIndex = IUFindOnSwitchIndex(&MergeMethodSP);
535 MergeMethodSP.update(states, names, n);
536
537 switch (IUFindOnSwitchIndex(&MergeMethodSP))
538 {
539 case FPROMERGE_ALGO:
540 mergeEnables.bMergeEnable = true;
541 mergeEnables.eMergeFrames = static_cast<FPRO_HWMERGEFRAMES>(IUFindOnSwitchIndex(&MergePlanesSP));
542 mergeEnables.eMergeFormat = IFORMAT_RCD;
543 break;
544 case FPROMERGE_ALGO_REF_FRAME:
545 // TODO
546 break;
547 }
548
549
550 int result = FPROAlgo_SetHardwareMergeEnables(m_CameraHandle, mergeEnables);
551 if (result >= 0)
552 {
553 MergeMethodSP.setState(IPS_OK);
554 }
555 else
556 {
557 MergeMethodSP.setState(IPS_ALERT);
558 IUResetSwitch(&MergeMethodSP);
559 MergeMethodSP[previousIndex].setState(ISS_ON);
560 LOGF_ERROR("Error setting hardware merge enables: %d", result);
561 }
562
563 MergeMethodSP.apply();
564 saveConfig(MergeMethodSP);
565 return true;
566 }
567
568 // Low Gain
569 if (LowGainSP.isNameMatch(name))
570 {
571 LowGainSP.update(states, names, n);
572 int index = LowGainSP.findOnSwitchIndex();
573 if (FPROSensor_SetGainIndex(m_CameraHandle, FPRO_GAIN_TABLE_LOW_CHANNEL, m_LowGainTable[index].uiDeviceIndex) >= 0)
574 LowGainSP.setState(IPS_OK);
575 else
576 LowGainSP.setState(IPS_ALERT);
577 LowGainSP.apply();
578 saveConfig(true, LowGainSP.getName());
579 return true;
580 }
581
582 // High Gain
583 if (HighGainSP.isNameMatch(name))
584 {
585 HighGainSP.update(states, names, n);
586 int index = HighGainSP.findOnSwitchIndex();
587 if (FPROSensor_SetGainIndex(m_CameraHandle, FPRO_GAIN_TABLE_HIGH_CHANNEL, m_HighGainTable[index].uiDeviceIndex) >= 0)
588 HighGainSP.setState(IPS_OK);
589 else
590 HighGainSP.setState(IPS_ALERT);
591 HighGainSP.apply();
592 saveConfig(true, HighGainSP.getName());
593 return true;
594 }
595
596 // Fan
597 if (FanSP.isNameMatch(name))
598 {
599 FanSP.update(states, names, n);
600 FanSP.setState(FPROCtrl_SetFanEnable(m_CameraHandle, FanSP.findOnSwitchIndex() == INDI_ENABLED) >= 0 ? IPS_OK : IPS_ALERT);
601 FanSP.apply();
602 return true;
603 }
604
605 // Request Stats
606 if (RequestStatSP.isNameMatch(name))
607 {
608 RequestStatSP.update(states, names, n);
609 RequestStatSP.setState(IPS_OK);
610 RequestStatSP.apply();
611 if (RequestStatSP.findOnSwitchIndex() == INDI_ENABLED)
612 LOG_INFO("Statistics are enabled. Merged images would take longer to download.");
613 else
614 LOG_INFO("Statistics are disabled. Merged images would be faster to download.");
615 saveConfig(true, RequestStatSP.getName());
616 return true;
617 }
618
619 // Legacy Trigger Exposure
620 #ifdef LEGACY_MODE
621 if (ExposureTriggerSP.isNameMatch(name))
622 {
623 ExposureTriggerSP.update(states, names, n);
624 if (ExposureTriggerSP[0].getState() == ISS_ON)
625 {
626 double values[1] = {m_ExposureRequest};
627 const char *names[1] = {"CCD_EXPOSURE_VALUE"};
628 ISNewNumber(getDeviceName(), "CCD_EXPOSURE", values, const_cast<char **>(names), 1);
629 ExposureTriggerSP.setState(IPS_BUSY);
630 }
631 else
632 {
633 ISState states[1] = {ISS_ON};
634 const char *names[1] = {"ABORT"};
635 ISNewSwitch(getDeviceName(), "CCD_ABORT_EXPOSURE", states, const_cast<char **>(names), 1);
636 ExposureTriggerSP.reset();
637 ExposureTriggerSP.setState(IPS_IDLE);
638 }
639
640 ExposureTriggerSP.apply();
641 return true;
642 }
643 #endif
644
645 }
646
647 return INDI::CCD::ISNewSwitch(dev, name, states, names, n);
648 }
649
650 /********************************************************************************
651 *
652 ********************************************************************************/
653 bool Kepler::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
654 {
655 if (dev != nullptr && !strcmp(dev, getDeviceName()))
656 {
657 if (MergeCalibrationFilesTP.isNameMatch(name))
658 {
659 MergeCalibrationFilesTP.update(texts, names, n);
660 MergeCalibrationFilesTP.setState(IPS_OK);
661 MergeCalibrationFilesTP.apply();
662 saveConfig(MergeCalibrationFilesTP);
663 return true;
664 }
665
666 }
667
668 return INDI::CCD::ISNewText(dev, name, texts, names, n);
669 }
670
671 /********************************************************************************
672 *
673 ********************************************************************************/
674 bool Kepler::Connect()
675 {
676 int32_t result = FPROCam_Open(&m_CameraInfo, &m_CameraHandle);
677 if ((result >= 0) && (m_CameraHandle >= 0))
678 {
679 // Different camera models support a different set of capabilities.
680 // The API allows you to retrieve the capabilities so that you can obtain
681 // images properly and configure your applications accordingly. In all cases,
682 // you need to know the size of the Meta Data supplied by the camera that is
683 // prepended to every image. This size is contained in the capabilities structure.
684 m_CameraCapabilitiesSize = sizeof(FPROCAP);
685 result = FPROSensor_GetCapabilities(m_CameraHandle, &m_CameraCapabilities, &m_CameraCapabilitiesSize);
686
687 CommunicationMethodSP[FPRO_CONNECTION_USB].setState(m_CameraInfo.eConnType == FPRO_CONNECTION_USB ? ISS_ON : ISS_OFF);
688 CommunicationMethodSP[FPRO_CONNECTION_FIBRE].setState(m_CameraInfo.eConnType == FPRO_CONNECTION_FIBRE ? ISS_ON : ISS_OFF);
689 CommunicationMethodSP.setState(IPS_OK);
690 CommunicationMethodSP.apply();
691
692 LOGF_INFO("Established connection to camera via %s", m_CameraInfo.eConnType == FPRO_CONNECTION_USB ? "USB" : "Fiber");
693
694 return (result == 0);
695 }
696
697 LOGF_ERROR("Failed to established connection with the camera: %d", result);
698 return false;
699 }
700
701 /********************************************************************************
702 *
703 ********************************************************************************/
704 bool Kepler::Disconnect()
705 {
706 free(m_FrameBuffer);
707 m_FrameBuffer = nullptr;
708 FPROCam_Close(m_CameraHandle);
709 m_TemperatureTimer.stop();
710 delete [] m_LowGainTable;
711 delete [] m_HighGainTable;
712 return true;
713 }
714
715 /********************************************************************************
716 *
717 ********************************************************************************/
718 bool Kepler::setup()
719 {
720 // We need image data
721 FPROFrame_SetImageDataEnable(m_CameraHandle, true);
722
723 uint32_t pixelDepth = 16, pixelLSB = 1;
724 int32_t result = FPROFrame_GetPixelConfig(m_CameraHandle, &pixelDepth, &pixelLSB);
725 if (result != 0)
726 {
727 LOGF_ERROR("%s: Failed to query camera pixel depth: %d", __PRETTY_FUNCTION__, result);
728 return false;
729 }
730
731 pixelDepth = (pixelDepth > 8) ? 16 : 8;
732
733 auto pixelSize = SensorPixelSize[static_cast<FPRODEVICETYPE>(m_CameraCapabilities.uiDeviceType)];
734
735 if (pixelSize > 90)
736 LOG_WARN("Pixel size is unkown for this camera model! Contact INDI to supply correct pixel information.");
737
738 SetCCDParams(m_CameraCapabilities.uiMaxPixelImageWidth, m_CameraCapabilities.uiMaxPixelImageHeight, pixelDepth, pixelSize,
739 pixelSize);
740
741 FPROFrame_SetImageArea(m_CameraHandle, 0, 0, m_CameraCapabilities.uiMaxPixelImageWidth,
742 m_CameraCapabilities.uiMaxPixelImageHeight);
743
744 // Get required frame buffer size including all the metadata and extra bits added by the SDK.
745 // We need to only
746 m_TotalFrameBufferSize = FPROFrame_ComputeFrameSize(m_CameraHandle);
747
748 m_FrameBuffer = static_cast<uint8_t*>(malloc(m_TotalFrameBufferSize));
749 // This would allocate memory
750 //PrimaryCCD.setFrameBufferSize(m_TotalFrameBufferSize);
751 // // This is actual image data size
752 // uint32_t rawFrameSize = PrimaryCCD.getXRes() * PrimaryCCD.getYRes() * PrimaryCCD.getBPP() / 8;
753 // // We set it again, but without allocating memory.
754 // PrimaryCCD.setFrameBufferSize(rawFrameSize, false);
755
756
757 fproUnpacked.bLowImageRequest = true;
758 fproUnpacked.bHighImageRequest = true;
759 fproUnpacked.bMergedImageRequest = true;
760 fproUnpacked.bMetaDataRequest = true;
761 fproStats.bLowRequest = true;
762 fproStats.bHighRequest = true;
763 fproStats.bMergedRequest = true;
764 fproUnpacked.eMergAlgo = FPROMERGE_ALGO;
765
766 // Low Gain tables
767 if (m_CameraCapabilities.uiLowGain > 0)
768 {
769 uint32_t count = m_CameraCapabilities.uiLowGain;
770 m_LowGainTable = new FPROGAINVALUE[count];
771 if (FPROSensor_GetGainTable(m_CameraHandle, FPRO_GAIN_TABLE_LOW_CHANNEL, m_LowGainTable, &count) >= 0)
772 {
773 LowGainSP.resize(count);
774 char name[MAXINDINAME] = {0}, label[MAXINDILABEL] = {0};
775 for (uint32_t i = 0; i < count; i++)
776 {
777 auto gain = static_cast<double>(m_LowGainTable[i].uiValue) / FPRO_GAIN_SCALE_FACTOR;
778 snprintf(name, MAXINDINAME, "LOW_GAIN_%u", i);
779 snprintf(name, MAXINDILABEL, "%.2f", gain);
780 LowGainSP[i].fill(name, label, ISS_OFF);
781 }
782 }
783
784 uint32_t index = 0;
785 FPROSensor_GetGainIndex(m_CameraHandle, FPRO_GAIN_TABLE_LOW_CHANNEL, &index);
786 LowGainSP[index].setState(ISS_ON);
787 LowGainSP.fill(getDeviceName(), "LOW_GAIN", "Low Gain", IMAGE_SETTINGS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
788 }
789
790 // High gain tables
791 if (m_CameraCapabilities.uiHighGain > 0)
792 {
793 uint32_t count = m_CameraCapabilities.uiHighGain;
794 m_HighGainTable = new FPROGAINVALUE[count];
795 if (FPROSensor_GetGainTable(m_CameraHandle, FPRO_GAIN_TABLE_HIGH_CHANNEL, m_HighGainTable, &count) >= 0)
796 {
797 HighGainSP.resize(count);
798 char name[MAXINDINAME] = {0}, label[MAXINDILABEL] = {0};
799 for (uint32_t i = 0; i < count; i++)
800 {
801 auto gain = static_cast<double>(m_HighGainTable[i].uiValue) / FPRO_GAIN_SCALE_FACTOR;
802 snprintf(name, MAXINDINAME, "HIGH_GAIN_%u", i);
803 snprintf(name, MAXINDILABEL, "%.2f", gain);
804 HighGainSP[i].fill(name, label, ISS_OFF);
805 }
806 }
807
808 uint32_t index = 0;
809 FPROSensor_GetGainIndex(m_CameraHandle, FPRO_GAIN_TABLE_HIGH_CHANNEL, &index);
810 HighGainSP[index].setState(ISS_ON);
811 HighGainSP.fill(getDeviceName(), "HIGH_GAIN", "High Gain", IMAGE_SETTINGS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
812 }
813
814 // Fan
815 bool fanOn = false;
816 if (FPROCtrl_GetFanEnable(m_CameraHandle, &fanOn) >= 0)
817 {
818 FanSP[INDI_ENABLED].setState(fanOn ? ISS_ON : ISS_OFF);
819 FanSP[INDI_DISABLED].setState(fanOn ? ISS_OFF : ISS_ON);
820 FanSP.setState(IPS_OK);
821 }
822
823 // Black level
824 uint32_t blackLevel = 0;
825 if (FPROSensor_GetBlackLevelAdjust(m_CameraHandle, &blackLevel))
826 {
827 BlackLevelNP[0].setValue(blackLevel);
828 BlackLevelNP.setState(IPS_OK);
829 }
830
831 m_TemperatureTimer.start();
832 m_GPSTimer.start();
833 return true;
834 }
835
836 /********************************************************************************
837 *
838 ********************************************************************************/
839 void Kepler::prepareUnpacked()
840 {
841 memset(&fproUnpacked, 0, sizeof(fproUnpacked));
842
843 // Merging Planes
844 int index = IUFindOnSwitchIndex(&MergePlanesSP);
845 fproUnpacked.bLowImageRequest = index == HWMERGE_FRAME_LOWONLY || index == HWMERGE_FRAME_BOTH;
846 fproUnpacked.bHighImageRequest = index == HWMERGE_FRAME_HIGHONLY || index == HWMERGE_FRAME_BOTH;
847 fproUnpacked.bMergedImageRequest = index == HWMERGE_FRAME_BOTH;
848 fproUnpacked.bMetaDataRequest = true;
849
850 // Statistics
851 fproStats.bLowRequest = index == HWMERGE_FRAME_LOWONLY || index == HWMERGE_FRAME_BOTH;
852 fproStats.bHighRequest = index == HWMERGE_FRAME_HIGHONLY || index == HWMERGE_FRAME_BOTH;
853 fproStats.bMergedRequest = index == HWMERGE_FRAME_BOTH;
854
855 // Merging Method
856 fproUnpacked.eMergAlgo = static_cast<FPRO_MERGEALGO>(IUFindOnSwitchIndex(&MergeMethodSP));
857
858 }
859 /********************************************************************************
860 *
861 ********************************************************************************/
862 int Kepler::SetTemperature(double temperature)
863 {
864 // Return OK for
865 if (std::abs(temperature - TemperatureN[0].value) < TEMPERATURE_THRESHOLD)
866 return 1;
867 int result = FPROCtrl_SetTemperatureSetPoint(m_CameraHandle, temperature);
868 if (result >= 0)
869 {
870 m_TargetTemperature = temperature;
871 m_TemperatureTimer.start(TEMPERATURE_FREQUENCY_BUSY);
872
873 #ifdef LEGACY_MODE
874 TemperatureReadNP.setState(IPS_BUSY);
875 TemperatureReadNP.apply();
876 #endif
877
878 return 0;
879 }
880
881 return -1;
882 }
883
884 /********************************************************************************
885 *
886 ********************************************************************************/
887 bool Kepler::StartExposure(float duration)
888 {
889 m_Worker.start(std::bind(&Kepler::workerExposure, this, std::placeholders::_1, duration));
890 return true;
891 }
892
893 bool Kepler::AbortExposure()
894 {
895 LOG_DEBUG("Aborting exposure...");
896 m_Worker.quit();
897 return (FPROFrame_CaptureStop(m_CameraHandle) == 0);
898 }
899
900 /********************************************************************************
901 *
902 ********************************************************************************/
903 bool Kepler::UpdateCCDFrameType(INDI::CCDChip::CCD_FRAME fType)
904 {
905 int result = 0;
906 switch (fType)
907 {
908 case INDI::CCDChip::LIGHT_FRAME:
909 result = FPROFrame_SetFrameType(m_CameraHandle, FPRO_FRAME_TYPE::FPRO_FRAMETYPE_NORMAL);
910 break;
911 case INDI::CCDChip::BIAS_FRAME:
912 result = FPROFrame_SetFrameType(m_CameraHandle, FPRO_FRAME_TYPE::FPRO_FRAMETYPE_BIAS);
913 break;
914 case INDI::CCDChip::DARK_FRAME:
915 result = FPROFrame_SetFrameType(m_CameraHandle, FPRO_FRAME_TYPE::FPRO_FRAMETYPE_DARK);
916 break;
917 case INDI::CCDChip::FLAT_FRAME:
918 result = FPROFrame_SetFrameType(m_CameraHandle, FPRO_FRAME_TYPE::FPRO_FRAMETYPE_LIGHTFLASH);
919 break;
920 }
921
922 return (result >= 0);
923 }
924
925 /********************************************************************************
926 *
927 ********************************************************************************/
928 bool Kepler::UpdateCCDFrame(int x, int y, int w, int h)
929 {
930 int result = FPROFrame_SetImageArea(m_CameraHandle, x, y, w, h);
931 if (result >= 0)
932 {
933 // Set UNBINNED coords
934 PrimaryCCD.setFrame(x, y, w, h);
935
936 // Get required frame buffer size including all the metadata and extra bits added by the SDK.
937 // We need to only
938 m_TotalFrameBufferSize = FPROFrame_ComputeFrameSize(m_CameraHandle);
939 m_FrameBuffer = static_cast<uint8_t*>(realloc(m_FrameBuffer, m_TotalFrameBufferSize));
940 return true;
941 }
942 else
943 {
944 LOGF_ERROR("Failed to update frame ROI: %d", result);
945 return false;
946 }
947 }
948
949 /********************************************************************************
950 *
951 ********************************************************************************/
952 bool Kepler::UpdateCCDBin(int binx, int biny)
953 {
954 int result = FPROSensor_SetBinning(m_CameraHandle, binx, biny);
955 if (result >= 0)
956 {
957 PrimaryCCD.setBin(binx, biny);
958 return UpdateCCDFrame(PrimaryCCD.getSubX(), PrimaryCCD.getSubY(), PrimaryCCD.getSubW(), PrimaryCCD.getSubH());
959 }
960 else
961 {
962 LOGF_ERROR("Error updating bin: %d", result);
963 return false;
964 }
965 }
966
967 /********************************************************************************
968 *
969 ********************************************************************************/
970 void Kepler::readTemperature()
971 {
972 double ambient = 0, base = 0, cooler = 0;
973 int result = FPROCtrl_GetTemperatures(m_CameraHandle, &ambient, &base, &cooler);
974 if (result < 0)
975 {
976 TemperatureNP.s = IPS_ALERT;
977 IDSetNumber(&TemperatureNP, nullptr);
978
979 #ifdef LEGACY_MODE
980 TemperatureReadNP.setState(IPS_ALERT);
981 TemperatureReadNP.apply();
982 #endif
983 LOGF_WARN("FPROCtrl_GetTemperatures failed: %d", result);
984 }
985
986 switch (TemperatureNP.s)
987 {
988 case IPS_IDLE:
989 case IPS_OK:
990 if (std::abs(cooler - TemperatureN[0].value) > TEMPERATURE_THRESHOLD)
991 {
992 TemperatureN[0].value = cooler;
993 IDSetNumber(&TemperatureNP, nullptr);
994
995 #ifdef LEGACY_MODE
996 TemperatureReadNP.setState(IPS_OK);
997 TemperatureReadNP[0].value = cooler;
998 TemperatureReadNP.apply();
999 #endif
1000 }
1001 break;
1002
1003 case IPS_BUSY:
1004 if (std::abs(cooler - m_TargetTemperature) <= TEMPERATURE_THRESHOLD)
1005 {
1006 TemperatureNP.s = IPS_OK;
1007 #ifdef LEGACY_MODE
1008 TemperatureReadNP.setState(IPS_OK);
1009 #endif
1010 // Reset now to idle frequency checks.
1011 m_TemperatureTimer.setInterval(TEMPERATURE_FREQUENCY_IDLE);
1012 }
1013 TemperatureN[0].value = cooler;
1014 IDSetNumber(&TemperatureNP, nullptr);
1015 #ifdef LEGACY_MODE
1016 TemperatureReadNP[0].value = cooler;
1017 TemperatureReadNP.apply();
1018 #endif
1019 break;
1020
1021 case IPS_ALERT:
1022 break;
1023 }
1024
1025 uint32_t dutycycle = 0;
1026 result = FPROCtrl_GetCoolerDutyCycle(m_CameraHandle, &dutycycle);
1027 // Set alert, if not set already in case there is SDK error.
1028 if (result < 0 && CoolerDutyNP.getState() != IPS_ALERT)
1029 {
1030 CoolerDutyNP.setState(IPS_ALERT);
1031 CoolerDutyNP.apply();
1032
1033 #ifdef LEGACY_MODE
1034 TemperatureReadNP.setState(IPS_ALERT);
1035 TemperatureReadNP.apply();
1036 #endif
1037 }
1038 // Only send updates if we are above 1 percent threshold
1039 else if (std::abs(dutycycle - CoolerDutyNP[0].getValue()) >= 1)
1040 {
1041 CoolerDutyNP[0].setValue(dutycycle);
1042 CoolerDutyNP.setState(dutycycle > 0 ? IPS_BUSY : IPS_IDLE);
1043 CoolerDutyNP.apply();
1044
1045 #ifdef LEGACY_MODE
1046 TemperatureReadNP[1].value = dutycycle;
1047 TemperatureReadNP.apply();
1048 #endif
1049 }
1050 }
1051
1052 /********************************************************************************
1053 *
1054 ********************************************************************************/
1055 void Kepler::readGPS()
1056 {
1057 FPROGPSSTATE state;
1058 int result = 0;
1059 if ( (result = FPROCtrl_GetGPSState(m_CameraHandle, &state)) >= 0)
1060 {
1061 if (state != m_LastGPSState)
1062 {
1063 m_LastGPSState = state;
1064 for (auto &lp : GPSStateLP)
1065 lp.setState(IPS_IDLE);
1066 GPSStateLP[state].setState(IPS_OK);
1067 GPSStateLP.setState(IPS_OK);
1068 GPSStateLP.apply();
1069 }
1070 }
1071 else
1072 {
1073 GPSStateLP.setState(IPS_ALERT);
1074 GPSStateLP.apply();
1075 LOGF_WARN("FPROCtrl_GetGPSState failed: %d", result);
1076 }
1077 }
1078 /********************************************************************************
1079 *
1080 ********************************************************************************/
1081 bool Kepler::saveConfigItems(FILE * fp)
1082 {
1083 INDI::CCD::saveConfigItems(fp);
1084
1085 IUSaveConfigSwitch(fp, &MergeMethodSP);
1086 IUSaveConfigSwitch(fp, &MergePlanesSP);
1087 IUSaveConfigText(fp, &MergeCalibrationFilesTP);
1088 IUSaveConfigSwitch(fp, &RequestStatSP);
1089 if (LowGainSP.size() > 0)
1090 IUSaveConfigSwitch(fp, &LowGainSP);
1091 if (HighGainSP.size() > 0)
1092 IUSaveConfigSwitch(fp, &HighGainSP);
1093
1094
1095 return true;
1096 }
1097
1098 /********************************************************************************
1099 *
1100 ********************************************************************************/
1101 void Kepler::debugTriggered(bool enable)
1102 {
1103 FPRODebug_EnableLevel(true, enable ? FPRO_DEBUG_DEBUG : FPRO_DEBUG_NONE);
1104 }
1105
1106 /********************************************************************************
1107 *
1108 ********************************************************************************/
1109 void Kepler::addFITSKeywords(INDI::CCDChip *targetChip)
1110 {
1111 INDI::CCD::addFITSKeywords(targetChip);
1112
1113 auto fptr = *targetChip->fitsFilePointer();
1114
1115 if (RequestStatSP.findOnSwitchIndex() == INDI_ENABLED)
1116 {
1117 if (fproStats.bLowRequest)
1118 {
1119 int status = 0;
1120 fits_update_key_dbl(fptr, "LOW_MEAN", fproStats.statsLowImage.dblMean, 3, "Low Mean", &status);
1121 fits_update_key_dbl(fptr, "LOW_MEDIAN", fproStats.statsLowImage.dblMedian, 3, "Low Median", &status);
1122 fits_update_key_dbl(fptr, "LOW_STDDEV", fproStats.statsLowImage.dblStandardDeviation, 3, "Low Standard Deviation", &status);
1123 }
1124 if (fproStats.bHighRequest)
1125 {
1126 int status = 0;
1127 fits_update_key_dbl(fptr, "HIGH_MEAN", fproStats.statsHighImage.dblMean, 3, "High Mean", &status);
1128 fits_update_key_dbl(fptr, "HIGH_MEDIAN", fproStats.statsHighImage.dblMedian, 3, "High Median", &status);
1129 fits_update_key_dbl(fptr, "HIGH_STDDEV", fproStats.statsHighImage.dblStandardDeviation, 3, "High Standard Deviation",
1130 &status);
1131 }
1132 if (fproStats.bMergedRequest)
1133 {
1134 int status = 0;
1135 fits_update_key_dbl(fptr, "MERGED_MEAN", fproStats.statsMergedImage.dblMean, 3, "Merged Mean", &status);
1136 fits_update_key_dbl(fptr, "MERGED_MEDIAN", fproStats.statsMergedImage.dblMedian, 3, "Merged Median", &status);
1137 fits_update_key_dbl(fptr, "MERGED_STDDEV", fproStats.statsMergedImage.dblStandardDeviation, 3, "Merged Standard Deviation",
1138 &status);
1139 }
1140 }
1141 }
1142
1143 /********************************************************************************
1144 *
1145 ********************************************************************************/
1146 void Kepler::UploadComplete(INDI::CCDChip *targetChip)
1147 {
1148 INDI_UNUSED(targetChip);
1149 #ifdef LEGACY_MODE
1150 ExposureTriggerSP[0].setState(ISS_OFF);
1151 ExposureTriggerSP.setState(IPS_OK);
1152 ExposureTriggerSP.apply();
1153 #endif
1154
1155 if (RequestStatSP.findOnSwitchIndex() == INDI_ENABLED)
1156 FPROFrame_FreeUnpackedBuffers(&fproUnpacked);
1157 FPROFrame_FreeUnpackedStatistics(&fproStats);
1158 }