Skip to content

Commit

Permalink
Add one more check to ensure minimum count is met (#1903)
Browse files Browse the repository at this point in the history
  • Loading branch information
knro authored Oct 2, 2023
1 parent f5ad792 commit 769623a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 11 additions & 6 deletions drivers/telescope/ioptronv3driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ bool Driver::sendCommandOk(const char *command)
return false;
}

bool Driver::sendCommand(const char *command, int count, char *response, uint8_t timeout, uint8_t debugLog)
bool Driver::sendCommand(const char *command,
int count,
char *response,
int minimumCount,
uint8_t timeout,
uint8_t debugLog)
{
int errCode = 0;
int nbytes_read = 0;
Expand Down Expand Up @@ -123,7 +128,7 @@ bool Driver::sendCommand(const char *command, int count, char *response, uint8_t
else
errCode = tty_read(PortFD, res, count, timeout, &nbytes_read);

if (errCode == TTY_OK)
if (errCode == TTY_OK && (minimumCount < 0 || minimumCount <= count))
break;
}

Expand Down Expand Up @@ -163,7 +168,7 @@ bool Driver::checkConnection(int fd)

for (int i = 0; i < 2; i++)
{
if (sendCommand(":MountInfo#", 4, res, 3) == false)
if (sendCommand(":MountInfo#", 4, res, -1, 3) == false)
{
usleep(50000);
continue;
Expand Down Expand Up @@ -268,7 +273,7 @@ bool Driver::getStatus(IOPInfo *info)
iopLongitude, iopLatitude, simData.simInfo.gpsStatus, simData.simInfo.systemStatus, simData.simInfo.trackRate,
simData.simInfo.slewRate, simData.simInfo.timeSource, simData.simInfo.hemisphere);
}
else if (sendCommand(":GLS#", -1, res) == false)
else if (sendCommand(":GLS#", -1, res, 23) == false)
return false;


Expand Down Expand Up @@ -730,7 +735,7 @@ bool Driver::getCoords(double *ra, double *de, IOP_PIER_STATE *pierState, IOP_CW
static_cast<uint32_t>(fabs(simData.de) * 60 * 60 * 100),
static_cast<uint32_t>(simData.ra * 15 * 60 * 60 * 100), simData.pier_state, simData.cw_state);
}
else if (sendCommand(":GEP#", -1, res, IOP_TIMEOUT, INDI::Logger::DBG_EXTRA_1) == false)
else if (sendCommand(":GEP#", -1, res, 20, IOP_TIMEOUT, INDI::Logger::DBG_EXTRA_1) == false)
return false;

if (strlen(res) != 20)
Expand Down Expand Up @@ -771,7 +776,7 @@ bool Driver::getUTCDateTime(double *JD, int *utcOffsetMinutes, bool *dayLightSav
abs(simData.utc_offset_minutes),
(simData.day_light_saving ? '1' : '0'), static_cast<uint64_t>((simData.JD - J2000) * 8.64e+7));
}
else if (sendCommand(":GUT#", -1, res) == false)
else if (sendCommand(":GUT#", -1, res, 18) == false)
return false;

if (strlen(res) != 18)
Expand Down
6 changes: 5 additions & 1 deletion drivers/telescope/ioptronv3driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ class Driver
/**************************************************************************
Communication
**************************************************************************/
bool sendCommand(const char *command, int count = 1, char *response = nullptr, uint8_t timeout = IOP_TIMEOUT,
bool sendCommand(const char *command,
int count = 1,
char *response = nullptr,
int minimumCount = -1,
uint8_t timeout = IOP_TIMEOUT,
uint8_t debugLog = INDI::Logger::DBG_DEBUG);
bool sendCommandOk(const char *command);
bool checkConnection(int fd);
Expand Down

0 comments on commit 769623a

Please sign in to comment.