36static std::unique_ptr<EFA> steelDrive(
new EFA());
59 InfoTP[INFO_VERSION].fill(
"INFO_VERSION",
"Version",
"NA");
63 TemperatureNP[TEMPERATURE_PRIMARY].fill(
"TEMPERATURE_PRIMARY",
"Primary (c)",
"%.2f", -50, 70., 0., 0.);
64 TemperatureNP[TEMPERATURE_AMBIENT].fill(
"TEMPERATURE_AMBIENT",
"Ambient (c)",
"%.2f", -50, 70., 0., 0.);
65 TemperatureNP.fill(
getDeviceName(),
"FOCUS_TEMPERATURE",
"Temperature",
69 FanStateSP[FAN_ON].fill(
"FAN_ON",
"On",
ISS_OFF);
70 FanStateSP[FAN_OFF].fill(
"FAN_OFF",
"Off",
ISS_ON);
75 FanControlSP[FAN_MANUAL].fill(
"FAN_MANUAL",
"Manual",
ISS_ON);
76 FanControlSP[FAN_AUTOMATIC_ABSOLUTE].fill(
"FAN_AUTOMATIC_ABSOLUTE",
"Auto. Absolute",
ISS_OFF);
77 FanControlSP[FAN_AUTOMATIC_RELATIVE].fill(
"FAN_AUTOMATIC_RELATIVE",
"Auto. Relative",
ISS_OFF);
78 FanControlSP.fill(
getDeviceName(),
"FOCUS_FAN_CONTROL",
"Control Mode", FAN_TAB,
IP_RW,
82 FanControlNP[FAN_MAX_ABSOLUTE].fill(
"FAN_MAX_ABSOLUTE",
"Max Primary (c)",
"%.2f", 0, 50., 5., 25.);
83 FanControlNP[FAN_MAX_RELATIVE].fill(
"FAN_MAX_RELATIVE",
"Max Relative (c)",
"%.2f", 0., 30., 1., 2.5);
84 FanControlNP[FAN_DEADZONE].fill(
"FAN_DEADZONE",
"Deadzone (c)",
"%.2f", 0.1, 10, 0.5, 0.5);
85 FanControlNP.fill(
getDeviceName(),
"FOCUS_FAN_PARAMS",
"Control Params",
89 FanDisconnectSP[FAN_OFF_ON_DISCONNECT].fill(
"FAN_OFF_ON_DISCONNECT",
"Switch Off",
ISS_ON);
90 FanDisconnectSP.fill(
getDeviceName(),
"FOCUS_FAN_DISCONNECT",
"On Disconnect", FAN_TAB,
94 CalibrationStateSP[CALIBRATION_ON].fill(
"CALIBRATION_ON",
"Calibrated",
ISS_OFF);
95 CalibrationStateSP[CALIBRATION_OFF].fill(
"CALIBRATION_OFF",
"Not Calibrated",
ISS_ON);
96 CalibrationStateSP.fill(
getDeviceName(),
"FOCUS_CALIBRATION",
"Calibration",
101 ApproachDirectionSP[APPROACH_POSITIVE].fill(
"APPROACH_POSITIVE",
"Positive (Outward)",
ISS_ON);
102 ApproachDirectionSP[APPROACH_NEGATIVE].fill(
"APPROACH_NEGATIVE",
"Negative (Inward)",
ISS_OFF);
103 ApproachDirectionSP.fill(
getDeviceName(),
"FOCUS_APPROACH",
"Approach Direction",
107 StopDetectSP[STOP_DETECT_ON].fill(
"STOP_DETECT_ON",
"Enabled",
ISS_ON);
108 StopDetectSP[STOP_DETECT_OFF].fill(
"STOP_DETECT_OFF",
"Disabled",
ISS_OFF);
109 StopDetectSP.fill(
getDeviceName(),
"FOCUS_STOP_DETECT",
"Stop Detection",
183 if (FanDisconnectSP[FAN_OFF_ON_DISCONNECT].getState() ==
ISS_ON)
184 setFanEnabled(
false);
198 int bits = TIOCM_RTS;
201 uint8_t
cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 6;
208 cmd[5] = calculateCheckSum(
cmd, len);
210 if (!validateLengths(
cmd, len))
213 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
216 version = std::to_string(res[5]) +
"." + std::to_string(res[6]);
217 InfoTP[INFO_VERSION].setText(version.c_str());
219 LOGF_INFO(
"Detected version %s", version.c_str());
229 return "PlaneWave EFA";
240 if (CalibrationStateSP.isNameMatch(name))
242 bool enabled = strcmp(CalibrationStateSP[CALIBRATION_ON].getName(),
IUFindOnSwitchName(states, names,
n)) == 0;
243 if (setCalibrationEnabled(enabled))
245 CalibrationStateSP.update(states, names,
n);
246 CalibrationStateSP.setState(
IPS_OK);
253 CalibrationStateSP.apply();
257 else if (FanStateSP.isNameMatch(name))
259 if (FanControlSP[FAN_MANUAL].getState() ==
ISS_OFF)
262 LOG_WARN(
"Cannot control fan while manual control is turned off.");
263 FanControlSP.apply();
267 bool enabled = strcmp(FanStateSP[FAN_ON].getName(),
IUFindOnSwitchName(states, names,
n)) == 0;
268 if (setFanEnabled(enabled))
270 FanStateSP.update(states, names,
n);
282 else if (FanControlSP.isNameMatch(name))
284 FanControlSP.update(states, names,
n);
285 if (FanControlSP[FAN_MANUAL].getState() ==
ISS_ON)
288 LOG_INFO(
"Fan is now controlled manually.");
292 LOG_INFO(
"Fan is now controlled automatically per the control parameters.");
296 FanControlSP.setState(
IPS_OK);
297 FanControlSP.apply();
301 else if (FanDisconnectSP.isNameMatch(name))
303 FanDisconnectSP.update(states, names,
n);
305 if (FanDisconnectSP[FAN_OFF_ON_DISCONNECT].getState() ==
ISS_ON)
306 LOG_INFO(
"Fan shall be turned off upon device disconnection.");
308 LOG_INFO(
"Fan shall left as-is upon device disconnection.");
310 FanDisconnectSP.setState(
IPS_OK);
311 FanDisconnectSP.apply();
315 else if (ApproachDirectionSP.isNameMatch(name))
317 const bool positiveApproach =
318 strcmp(ApproachDirectionSP[APPROACH_POSITIVE].getName(),
IUFindOnSwitchName(states, names,
n)) == 0;
322 const bool currentPositive = (ApproachDirectionSP[APPROACH_POSITIVE].getState() ==
ISS_ON);
323 if (positiveApproach == currentPositive)
325 LOGF_DEBUG(
"Approach direction already %s; skipping hardware command.",
326 positiveApproach ?
"Positive (Outward)" :
"Negative (Inward)");
327 ApproachDirectionSP.setState(
IPS_OK);
328 ApproachDirectionSP.apply();
332 if (setApproachDirection(positiveApproach ? 0 : 1))
334 ApproachDirectionSP.update(states, names,
n);
335 ApproachDirectionSP.setState(
IPS_OK);
336 LOGF_INFO(
"Approach direction set to %s.", positiveApproach ?
"Positive (Outward)" :
"Negative (Inward)");
342 ApproachDirectionSP.apply();
346 else if (StopDetectSP.isNameMatch(name))
353 const bool currentEnabled = (StopDetectSP[STOP_DETECT_ON].getState() ==
ISS_ON);
354 if (enabled == currentEnabled)
356 LOGF_DEBUG(
"Stop detection already %s; skipping hardware command.",
357 enabled ?
"enabled" :
"disabled");
358 StopDetectSP.setState(
IPS_OK);
359 StopDetectSP.apply();
363 if (setStopDetect(enabled))
365 StopDetectSP.update(states, names,
n);
366 StopDetectSP.setState(
IPS_OK);
367 LOGF_INFO(
"Stop detection %s.", enabled ?
"enabled" :
"disabled");
373 StopDetectSP.apply();
389 if (FanControlNP.isNameMatch(name))
391 FanControlNP.update(values, names,
n);
392 FanControlNP.setState(
IPS_OK);
393 FanControlNP.apply();
406 uint8_t
cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 9;
413 cmd[5] = (ticks >> 16) & 0xFF;
414 cmd[6] = (ticks >> 8) & 0xFF;
415 cmd[7] = (ticks >> 0) & 0xFF;
416 cmd[8] = calculateCheckSum(
cmd, len);
418 if (!validateLengths(
cmd, len))
421 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
424 return (res[5] == 1);
432 uint8_t
cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 9;
439 cmd[5] = (targetTicks >> 16) & 0xFF;
440 cmd[6] = (targetTicks >> 8) & 0xFF;
441 cmd[7] = (targetTicks >> 0) & 0xFF;
442 cmd[8] = calculateCheckSum(
cmd, len);
444 if (!validateLengths(
cmd, len))
447 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
460 int relative =
static_cast<int>(ticks);
461 int targetAbsPosition =
FocusAbsPosNP[0].getValue() + (relative * direction * reversed);
463 targetAbsPosition = std::min(
static_cast<uint32_t
>(
FocusAbsPosNP[0].getMax()),
464 static_cast<uint32_t
>(std::max(
static_cast<int>(
FocusAbsPosNP[0].getMin()), targetAbsPosition)));
477 uint32_t currentPos =
static_cast<uint32_t
>(
FocusAbsPosNP[0].getValue());
493 if (readTemperature())
496 bool aboveThreshold =
false;
497 for (
size_t i = 0; i < TemperatureNP.count(); i++)
500 if (std::fabs(TemperatureNP[i].getValue() - TEMPERATURE_INVALID) < 0.1)
503 if (std::fabs(TemperatureNP[i].getValue() - m_LastTemperature[i]) > TEMPERATURE_THRESHOLD)
505 aboveThreshold =
true;
506 m_LastTemperature[i] = TemperatureNP[i].getValue();
511 TemperatureNP.apply();
514 if (FanControlSP[FAN_MANUAL].getState() ==
ISS_OFF)
516 bool turnOn =
false, turnOff =
false;
517 const bool isFanOn = FanStateSP[FAN_ON].getState() ==
ISS_ON;
520 if (FanControlSP[FAN_AUTOMATIC_ABSOLUTE].getState() ==
ISS_ON)
523 if (std::fabs(TemperatureNP[TEMPERATURE_PRIMARY].getValue() - TEMPERATURE_INVALID) > 0.1)
526 double min_delta = FanControlNP[FAN_MAX_ABSOLUTE].getValue() - FanControlNP[FAN_DEADZONE].getValue();
527 double max_delta = FanControlNP[FAN_MAX_ABSOLUTE].getValue() + FanControlNP[FAN_DEADZONE].getValue();
529 turnOn = TemperatureNP[TEMPERATURE_PRIMARY].getValue() > max_delta;
530 turnOff = TemperatureNP[TEMPERATURE_PRIMARY].getValue() < min_delta;
533 else if (FanControlSP[FAN_AUTOMATIC_RELATIVE].getState() ==
ISS_ON)
536 if (std::fabs(TemperatureNP[TEMPERATURE_PRIMARY].getValue() - TEMPERATURE_INVALID) > 0.1 &&
537 std::fabs(TemperatureNP[TEMPERATURE_AMBIENT].getValue() - TEMPERATURE_INVALID) > 0.1)
540 double tDiff = TemperatureNP[TEMPERATURE_PRIMARY].getValue() - TemperatureNP[TEMPERATURE_AMBIENT].getValue();
542 double min_delta = FanControlNP[FAN_MAX_RELATIVE].getValue() - FanControlNP[FAN_DEADZONE].getValue();
543 double max_delta = FanControlNP[FAN_MAX_RELATIVE].getValue() + FanControlNP[FAN_DEADZONE].getValue();
546 turnOn = tDiff > max_delta;
547 turnOff = tDiff < min_delta;
551 if (isFanOn && turnOff)
553 setFanEnabled(
false);
554 FanStateSP[FAN_ON].setState(
ISS_OFF);
555 FanStateSP[FAN_OFF].setState(
ISS_ON);
559 else if (!isFanOn && turnOn)
562 FanStateSP[FAN_ON].setState(
ISS_ON);
563 FanStateSP[FAN_OFF].setState(
ISS_OFF);
564 FanStateSP.setState(
IPS_OK);
572 if (isGOTOComplete())
578 LOG_INFO(
"Focuser reached requested position.");
583 else if (std::fabs(
FocusAbsPosNP[0].getValue() - m_LastPosition) > 0)
599 uint8_t
cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 9;
606 cmd[5] = (ticks >> 16) & 0xFF;
607 cmd[6] = (ticks >> 8) & 0xFF;
608 cmd[7] = (ticks >> 0) & 0xFF;
609 cmd[8] = calculateCheckSum(
cmd, len);
611 if (!validateLengths(
cmd, len))
614 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
617 return (res[5] == 1);
636 FanControlSP.save(fp);
637 if (FanControlNP.getState() ==
IPS_OK)
638 FanControlNP.save(fp);
639 FanDisconnectSP.save(fp);
650void EFA::getStartupValues()
653 readCalibrationState();
656 readApproachDirection();
659 if (readMaxSlewLimit())
680inline int EFA::readByte(
int fd, uint8_t *buf,
int timeout,
int *nbytes_read)
682 return tty_read(
fd, (
char *)buf, 1, timeout, nbytes_read);
688inline int EFA::readBytes(
int fd, uint8_t *buf,
int nbytes,
int timeout,
int *nbytes_read)
690 return tty_read(
fd, (
char *)buf, nbytes, timeout, nbytes_read);
696inline int EFA::writeBytes(
int fd,
const uint8_t *buf,
int nbytes,
int *nbytes_written)
698 return tty_write(
fd, (
const char *)buf, nbytes, nbytes_written);
704int EFA::readPacket(
int fd, uint8_t *buf,
int nbytes,
int timeout,
int *nbytes_read)
706 int len = 0, rc = 0, read_bytes = *nbytes_read = 0;
710 LOGF_ERROR(
"Read needs at least 6 bytes; exceeds supplied buffer size (%d)", nbytes);
714 for (
int i = 0; i < 10; i++)
717 rc = readByte(
fd, &buf[0], timeout, &read_bytes);
718 if (rc ==
TTY_OK && read_bytes == 1)
720 if (buf[0] == DRIVER_SOM)
726 LOGF_DEBUG(
"Looking for SOM (%02X); found %d byte (%02X)", DRIVER_SOM, read_bytes, buf[0]);
733 LOGF_DEBUG(
"Looking for SOM (%02X); found %s", DRIVER_SOM, errstr);
739 if (rc !=
TTY_OK || read_bytes != 1 || buf[0] != DRIVER_SOM)
747 if ((rc = readByte(
fd, &buf[1], timeout, &read_bytes)) !=
TTY_OK)
755 if ((rc = readByte(
fd, &buf[2], timeout, &read_bytes)) !=
TTY_OK)
761 if ((rc = readByte(
fd, &buf[3], timeout, &read_bytes)) !=
TTY_OK)
767 if ((rc = readByte(
fd, &buf[4], timeout, &read_bytes)) !=
TTY_OK)
773 if ((len + 3) > nbytes)
775 LOGF_ERROR(
"Read (%d) will exceed supplied buffer size (%d) for command %02X", (len + 3), nbytes, buf[4]);
781 for (
n = 0;
n < (len - 3); ++
n)
783 if ((rc = readByte(
fd, &buf[5 +
n], timeout, &read_bytes)) !=
TTY_OK)
785 LOGF_DEBUG(
"%s byte not encountered",
"DATA");
790 if ((rc = readByte(
fd, &buf[5 +
n], timeout, &read_bytes)) !=
TTY_OK)
792 LOGF_DEBUG(
"%s byte not encountered",
"DATA");
796 uint8_t chk = calculateCheckSum(buf, (len + 3));
798 if (chk != buf[len + 2])
804 *nbytes_read = len + 3;
812bool EFA::sendCommand(
const uint8_t *
cmd, uint8_t *res, uint32_t cmd_len, uint32_t res_len)
814 int nbytes_written = 0, nbytes_read = 0, bits = 0, rc = 0, hexbuflen = (DRIVER_LEN * 3 + 4);
815 char hexbuf[DRIVER_LEN * 3 + 4];
817 for (
int j = 0; j < 3; usleep(100000), j++)
825 for (
int i = 0; i < 10; i++)
827 if ((rc =
ioctl(
PortFD, TIOCMGET, &bits)) == 0 && (bits & TIOCM_CTS) == 0)
837 else if ((bits & TIOCM_CTS) != 0)
839 LOG_ERROR(
"CTS timed out: serial bus is still busy.");
847 if (!IN_TIMER && efaDump(hexbuf, hexbuflen,
cmd, cmd_len) != NULL)
852 tcflush(
PortFD, TCIFLUSH);
853 rc = writeBytes(
PortFD,
cmd, cmd_len, &nbytes_written);
860 rc = readPacket(
PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
862 if (rc !=
TTY_OK || nbytes_read == 0)
867 if ((
int)cmd_len == nbytes_read && memcmp(
cmd, res, cmd_len) == 0)
875 rc = readPacket(
PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
877 if (rc !=
TTY_OK || nbytes_read == 0)
882 else if (efaDump(hexbuf, hexbuflen,
cmd, cmd_len) != NULL)
885 LOGF_DEBUG(
"no echo for command packet: %s", hexbuf);
888 if (!IN_TIMER && efaDump(hexbuf, hexbuflen, res, nbytes_read) != NULL)
893 if (
cmd[2] != res[3] ||
cmd[3] != res[2] ||
cmd[4] != res[4])
895 LOGF_DEBUG(
"Send/Receive mismatch - %s!",
"packet not for us");
913 if (
cmd[2] != res[3] ||
cmd[3] != res[2] ||
cmd[4] != res[4])
915 LOGF_ERROR(
"Send/Receive mismatch and %s",
"timeout");
925bool EFA::readPosition()
927 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 6;
934 cmd[5] = calculateCheckSum(
cmd, len);
936 if (!validateLengths(
cmd, len))
939 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
942 FocusAbsPosNP[0].setValue(res[5] << 16 | res[6] << 8 | res[7]);
949bool EFA::readMaxSlewLimit()
951 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 6;
958 cmd[5] = calculateCheckSum(
cmd, len);
960 if (!validateLengths(
cmd, len))
963 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
966 uint32_t limit =
res[5] << 16 |
res[6] << 8 |
res[7];
979bool EFA::readApproachDirection()
981 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 6;
988 cmd[5] = calculateCheckSum(
cmd, len);
990 if (!validateLengths(
cmd, len))
993 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
997 bool positiveApproach = (
res[5] == 0);
998 ApproachDirectionSP[APPROACH_POSITIVE].setState(positiveApproach ?
ISS_ON :
ISS_OFF);
999 ApproachDirectionSP[APPROACH_NEGATIVE].setState(positiveApproach ?
ISS_OFF :
ISS_ON);
1009bool EFA::setApproachDirection(uint8_t direction)
1011 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 7;
1013 cmd[0] = DRIVER_SOM;
1019 cmd[6] = calculateCheckSum(
cmd, len);
1021 if (!validateLengths(
cmd, len))
1024 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
1027 return (res[5] == 1);
1033bool EFA::readStopDetect()
1035 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 6;
1037 cmd[0] = DRIVER_SOM;
1042 cmd[5] = calculateCheckSum(
cmd, len);
1044 if (!validateLengths(
cmd, len))
1047 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
1050 bool enabled = (
res[5] == 1);
1051 StopDetectSP[STOP_DETECT_ON].setState(enabled ?
ISS_ON :
ISS_OFF);
1052 StopDetectSP[STOP_DETECT_OFF].setState(enabled ?
ISS_OFF :
ISS_ON);
1060bool EFA::setStopDetect(
bool enabled)
1062 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 7;
1064 cmd[0] = DRIVER_SOM;
1069 cmd[5] = enabled ? 1 : 0;
1070 cmd[6] = calculateCheckSum(
cmd, len);
1072 if (!validateLengths(
cmd, len))
1075 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
1078 return (res[5] == 1);
1084bool EFA::isGOTOComplete()
1086 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 6;
1088 cmd[0] = DRIVER_SOM;
1093 cmd[5] = calculateCheckSum(
cmd, len);
1095 if (!validateLengths(
cmd, len))
1098 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
1101 return (res[5] != 0);
1107bool EFA::setFanEnabled(
bool enabled)
1109 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 7;
1111 cmd[0] = DRIVER_SOM;
1116 cmd[5] = enabled ? 1 : 0;
1117 cmd[6] = calculateCheckSum(
cmd, len);
1119 if (!validateLengths(
cmd, len))
1122 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
1125 return (res[5] == 1);
1132bool EFA::readFanState()
1134 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 6;
1136 cmd[0] = DRIVER_SOM;
1141 cmd[5] = calculateCheckSum(
cmd, len);
1143 if (!validateLengths(
cmd, len))
1146 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
1150 bool enabled = (
res[5] == 1);
1161bool EFA::setCalibrationEnabled(
bool enabled)
1163 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 8;
1165 cmd[0] = DRIVER_SOM;
1171 cmd[6] = enabled ? 1 : 0;
1172 cmd[7] = calculateCheckSum(
cmd, len);
1174 if (!validateLengths(
cmd, len))
1177 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
1180 return (res[5] == 1);
1186bool EFA::readCalibrationState()
1188 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 7;
1190 cmd[0] = DRIVER_SOM;
1196 cmd[6] = calculateCheckSum(
cmd, len);
1198 if (!validateLengths(
cmd, len))
1201 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
1204 bool enabled = (
res[5] == 1);
1206 CalibrationStateSP[CALIBRATION_ON].setState(enabled ?
ISS_ON :
ISS_OFF);
1207 CalibrationStateSP[CALIBRATION_OFF].setState(enabled ?
ISS_OFF :
ISS_ON);
1217bool EFA::readTemperature()
1219 uint8_t
cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0}, len = 7;
1221 for (uint8_t i = 0; i < 2; i++)
1223 cmd[0] = DRIVER_SOM;
1229 cmd[6] = calculateCheckSum(
cmd, len);
1231 if (!validateLengths(
cmd, len))
1234 if (!sendCommand(
cmd, res, len, DRIVER_LEN))
1237 double temperature = calculateTemperature(res[5], res[6]);
1239 if (std::fabs(
temperature - TEMPERATURE_INVALID) < 0.1)
1242 LOGF_DEBUG(
"Temperature sensor %d returned invalid data.", i);
1257double EFA::calculateTemperature(uint8_t byte2, uint8_t byte3)
1259 if (byte2 == 0x7F && byte3 == 0x7F)
1260 return TEMPERATURE_INVALID;
1262 int raw_temperature = byte3 << 8 | byte2;
1263 if (raw_temperature & 0x8000)
1264 raw_temperature = raw_temperature - 0x10000;
1266 return raw_temperature / 16.0;
1272char * EFA::efaDump(
char * buf,
int buflen,
const uint8_t * data, uint32_t size)
1274 int needed = 0, idx = 0;
1276 needed = size * 3 + 4;
1278 if (needed > buflen)
1283 for (uint32_t i = 0; i < size; i++)
1287 (void) sprintf(buf + idx,
"<%02X> ", data[i]);
1290 else if (i == 5 && i < (size - 1))
1293 for (uint32_t j = i, k = 3; j < (size - 1) && k < data[1]; j++, k++)
1295 (void) sprintf(buf + idx,
"%02X ", data[j]);
1304 (void) sprintf(buf + idx,
"%02X ", data[i]);
1309 buf[idx - 1] =
'\0';
1317std::vector<std::string> EFA::split(
const std::string &input,
const std::string ®ex)
1320 std::regex re(regex);
1321 std::sregex_token_iterator
1322 first{input.begin(), input.end(), re, -1},
1324 return {first, last};
1330template <
typename T>
1331std::string EFA::to_string(
const T a_value,
const int n)
1333 std::ostringstream out;
1335 out << std::fixed << a_value;
1342bool EFA::validateLengths(
const uint8_t *
cmd, uint32_t len)
1346 LOGF_ERROR(
"packet length (%d) is too short for command %02X", len,
cmd[4]);
1349 if (
cmd[1] + 3 != (
int)len)
1351 LOGF_ERROR(
"packet length (%d) and data length (%d) discrepancy for command %02X", len,
cmd[1],
cmd[4]);
1361uint8_t EFA::calculateCheckSum(
const uint8_t *
cmd, uint32_t len)
1365 for (uint32_t i = 1; i < len - 1; i++)
1368 return ((-sum) & 0xFF);
virtual bool SyncFocuser(uint32_t ticks) override
Sync focuser.
virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override
Move Focuser relatively.
virtual bool ReverseFocuser(bool enabled) override
Reverse Focuser Motion.
virtual bool saveConfigItems(FILE *fp) override
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
Set Maximum Position.
const char * getDefaultName() override
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
Move Absolute Focuser.
virtual bool AbortFocuser() override
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
@ MTR_GET_APPROACH_DIRECTION
@ MTR_SET_CALIBRATION_STATE
@ MTR_GET_CALIBRATION_STATE
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
virtual bool Disconnect() override
Disconnect from device.
virtual bool Disconnect()
Disconnect from device.
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
INDI::PropertyNumber FocusRelPosNP
INDI::PropertySwitch FocusReverseSP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INDI::PropertyNumber FocusSyncNP
INDI::PropertyNumber FocusMaxPosNP
INDI::PropertyNumber FocusAbsPosNP
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
virtual bool saveConfigItems(FILE *fp) override
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
Connection::Serial * serialConnection
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Implementations for common driver routines.
const char * IUFindOnSwitchName(ISState *states, char *names[], int n)
Returns the name of the first ON switch it finds in the supplied arguments.
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)
int ioctl(int fd, unsigned long request,...) __THROW