diff --git a/indi-gphoto/gphoto_ccd.cpp b/indi-gphoto/gphoto_ccd.cpp index 0b6399088..9ce0a836a 100644 --- a/indi-gphoto/gphoto_ccd.cpp +++ b/indi-gphoto/gphoto_ccd.cpp @@ -291,6 +291,11 @@ bool GPhotoCCD::initProperties() SDCardImageSP[SD_CARD_IGNORE_IMAGE].fill("Ignore", "Ignore", ISS_OFF); SDCardImageSP.fill(getDeviceName(), "CCD_SD_CARD_ACTION", "SD Image", IMAGE_SETTINGS_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); + // Download Timeout + DownloadTimeoutNP[0].fill("VALUE", "Seconds", "%.f", 0, 300, 30, 60); + DownloadTimeoutNP.fill(getDeviceName(), "CCD_DOWNLOAD_TIMEOUT", "Download Timeout", OPTIONS_TAB, IP_RW, 60, IPS_IDLE); + DownloadTimeoutNP.load(); + // Nikon should have force bulb off by default. ForceBULBSP[INDI_ENABLED].fill("On", "On", isNikon ? ISS_OFF : ISS_ON); ForceBULBSP[INDI_DISABLED].fill("Off", "Off", isNikon ? ISS_ON : ISS_OFF); @@ -423,6 +428,7 @@ bool GPhotoCCD::updateProperties() } defineProperty(ForceBULBSP); + defineProperty(DownloadTimeoutNP); } else { @@ -448,6 +454,7 @@ bool GPhotoCCD::updateProperties() deleteProperty(SDCardImageSP); deleteProperty(ForceBULBSP); + deleteProperty(DownloadTimeoutNP); HideExtendedOptions(); } @@ -777,6 +784,17 @@ bool GPhotoCCD::ISNewNumber(const char * dev, const char * name, double values[] return true; } + // Download Timeout + if (DownloadTimeoutNP.isNameMatch(name)) + { + DownloadTimeoutNP.update(values, names, n); + DownloadTimeoutNP.setState(IPS_OK); + DownloadTimeoutNP.apply(); + saveConfig(DownloadTimeoutNP); + gphoto_set_download_timeout(gphotodrv, DownloadTimeoutNP[0].getValue()); + return true; + } + if (CamOptions.find(name) != CamOptions.end()) { cam_opt * opt = CamOptions[name]; @@ -2034,6 +2052,9 @@ bool GPhotoCCD::saveConfigItems(FILE * fp) // Mirror Locking MirrorLockNP.save(fp); + // Download Timeout + DownloadTimeoutNP.save(fp); + // Capture Target if (CaptureTargetSP.getState() == IPS_OK) { diff --git a/indi-gphoto/gphoto_ccd.h b/indi-gphoto/gphoto_ccd.h index 510bfa571..cb871ba3c 100644 --- a/indi-gphoto/gphoto_ccd.h +++ b/indi-gphoto/gphoto_ccd.h @@ -203,6 +203,8 @@ class GPhotoCCD : public INDI::CCD, public INDI::FocuserInterface INDI::PropertySwitch ExposurePresetSP {0}; // Force BULB mode (vs predefined exposure indexes) when capturing INDI::PropertySwitch ForceBULBSP {2}; + // Wait this many seconds before giving up on exposure download + INDI::PropertyNumber DownloadTimeoutNP {1}; // Upload file, used for testing purposes under simulation under native mode INDI::PropertyText UploadFileTP {1}; INDI::PropertyBlob imageBP {INDI::Property()}; diff --git a/indi-gphoto/gphoto_driver.cpp b/indi-gphoto/gphoto_driver.cpp index be9d2478e..1932f5d8e 100644 --- a/indi-gphoto/gphoto_driver.cpp +++ b/indi-gphoto/gphoto_driver.cpp @@ -148,6 +148,7 @@ struct _gphoto_driver int bulb_exposure_index; double max_exposure, min_exposure; bool force_bulb; + int download_timeout {60}; int iso; int format; @@ -1382,9 +1383,8 @@ int gphoto_read_exposure_fd(gphoto_driver *gphoto, int fd) } //Bulb mode - int timeoutCounter = 0; gphoto->command = 0; - uint32_t waitMS = 1000; + uint32_t waitMS = gphoto->download_timeout * 1000; bool downloadComplete = false; while (1) @@ -1395,15 +1395,8 @@ int gphoto_read_exposure_fd(gphoto_driver *gphoto, int fd) if (result != GP_OK) { DEBUGDEVICE(device, INDI::Logger::DBG_WARNING, "Could not wait for event."); - timeoutCounter++; - if (timeoutCounter >= 10) - { - pthread_mutex_unlock(&gphoto->mutex); - return -1; - } - - std::this_thread::sleep_for(std::chrono::seconds(1)); - continue; + pthread_mutex_unlock(&gphoto->mutex); + return -1; } switch (event) @@ -1430,13 +1423,9 @@ int gphoto_read_exposure_fd(gphoto_driver *gphoto, int fd) pthread_mutex_unlock(&gphoto->mutex); return GP_OK; } - DEBUGFDEVICE(device, INDI::Logger::DBG_DEBUG, "Event timed out #%d, retrying...", ++timeoutCounter); - // So retry for 5 seconds before giving up - if (timeoutCounter >= 10) - { - pthread_mutex_unlock(&gphoto->mutex); - return -1; - } + DEBUGDEVICE(device, INDI::Logger::DBG_DEBUG, "Event timed out."); + pthread_mutex_unlock(&gphoto->mutex); + return -1; break; default: @@ -2405,6 +2394,11 @@ void gphoto_force_bulb(gphoto_driver *gphoto, bool enabled) gphoto->force_bulb = enabled; } +void gphoto_set_download_timeout(gphoto_driver *gphoto, int timeout) +{ + gphoto->download_timeout = timeout; +} + #ifdef GPHOTO_TEST #include diff --git a/indi-gphoto/gphoto_driver.h b/indi-gphoto/gphoto_driver.h index f723d18b7..cf0ab2dec 100644 --- a/indi-gphoto/gphoto_driver.h +++ b/indi-gphoto/gphoto_driver.h @@ -125,3 +125,4 @@ bool gphoto_supports_temperature(gphoto_driver *gphoto); float gphoto_get_last_sensor_temperature(gphoto_driver *gphoto); void gphoto_force_bulb(gphoto_driver *gphoto, bool enabled); void gphoto_set_view_finder(gphoto_driver *gphoto, bool enabled); +void gphoto_set_download_timeout(gphoto_driver *gphoto, int timeout);