Skip to content

Commit

Permalink
Add custom download timeout that defaults to 60 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Nov 3, 2024
1 parent b9a85d7 commit a3fb055
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
21 changes: 21 additions & 0 deletions indi-gphoto/gphoto_ccd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -423,6 +428,7 @@ bool GPhotoCCD::updateProperties()
}

defineProperty(ForceBULBSP);
defineProperty(DownloadTimeoutNP);
}
else
{
Expand All @@ -448,6 +454,7 @@ bool GPhotoCCD::updateProperties()
deleteProperty(SDCardImageSP);

deleteProperty(ForceBULBSP);
deleteProperty(DownloadTimeoutNP);

HideExtendedOptions();
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions indi-gphoto/gphoto_ccd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()};
Expand Down
30 changes: 12 additions & 18 deletions indi-gphoto/gphoto_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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 <getopt.h>

Expand Down
1 change: 1 addition & 0 deletions indi-gphoto/gphoto_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit a3fb055

Please sign in to comment.