Instrument Neutral Distributed Interface INDI 2.2.5
planewave_efa.cpp
Go to the documentation of this file.
1/*
2 PlaneWave EFA Protocol
3
4 Hendrick Focuser
5
6 Copyright (C) 2020-2027 Jasem Mutlaq ([email protected])
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22*/
23
24#include "planewave_efa.h"
25#include "indicom.h"
27
28#include <cmath>
29#include <memory>
30#include <cstring>
31#include <termios.h>
32#include <unistd.h>
33#include <regex>
34#include <sys/ioctl.h>
35
36static std::unique_ptr<EFA> steelDrive(new EFA());
37
42{
43 setVersion(1, 5);
44
45 // Focuser Capabilities
46 // No variable speed: the EFA has no speed setting. MTR_PMSLEW_RATE / MTR_NMSLEW_RATE start a move.
52}
53
55{
57
58 // Focuser Information
59 InfoTP[INFO_VERSION].fill("INFO_VERSION", "Version", "NA");
60 InfoTP.fill(getDeviceName(), "INFO", "Info", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE);
61
62 // Focuser temperature
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",
67
68 // Fan Control
69 FanStateSP[FAN_ON].fill("FAN_ON", "On", ISS_OFF);
70 FanStateSP[FAN_OFF].fill("FAN_OFF", "Off", ISS_ON);
71 FanStateSP.fill(getDeviceName(), "FOCUS_FAN", "Fans", FAN_TAB, IP_RW, ISR_1OFMANY, 0,
72 IPS_IDLE);
73
74 // Fan Control Mode
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,
80
81 // Fan Control Parameters
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",
86 FAN_TAB, IP_RW, 0, IPS_IDLE);
87
88 // Fan Off on Disconnect
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,
92
93 // Calibration Control
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",
98
99 // Approach Direction: determines from which direction the focuser always reaches a target.
100 // This provides consistent positioning and effective hardware-level backlash compensation.
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",
105
106 // Stop Detection: enables hardware end-of-travel limit-switch detection.
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",
111
112 // Setup limits
113 FocusMaxPosNP[0].setValue(1e7);
114 FocusMaxPosNP[0].setMax(1e7);
115 FocusMaxPosNP[0].setStep(FocusMaxPosNP[0].getMax() / 50);
116
117 FocusAbsPosNP[0].setMax(1e7);
118 FocusAbsPosNP[0].setStep(FocusAbsPosNP[0].getMax() / 50);
119
120 FocusSyncNP[0].setMax(1e7);
121 FocusSyncNP[0].setStep(FocusSyncNP[0].getMax() / 50);
122
123 FocusRelPosNP[0].setMax(FocusAbsPosNP[0].getMax() / 2);
124 FocusRelPosNP[0].setStep(FocusRelPosNP[0].getMax() / 50);
125
129
130 return true;
131}
132
137{
139
140 if (isConnected())
141 {
142 getStartupValues();
143
144 defineProperty(InfoTP);
145 defineProperty(CalibrationStateSP);
146
147 // Fan
148 defineProperty(FanStateSP);
149 defineProperty(FanControlSP);
150 FanControlSP.load();
151 defineProperty(FanDisconnectSP);
152
153 defineProperty(TemperatureNP);
154
155 // Options
156 defineProperty(ApproachDirectionSP);
157 defineProperty(StopDetectSP);
158 }
159 else
160 {
161 deleteProperty(InfoTP);
162 deleteProperty(CalibrationStateSP);
163
164 deleteProperty(FanStateSP);
165 deleteProperty(FanControlSP);
166 deleteProperty(FanControlNP);
167 deleteProperty(FanDisconnectSP);
168
169 deleteProperty(TemperatureNP);
170
171 deleteProperty(ApproachDirectionSP);
172 deleteProperty(StopDetectSP);
173 }
174
175 return true;
176}
177
182{
183 if (FanDisconnectSP[FAN_OFF_ON_DISCONNECT].getState() == ISS_ON)
184 setFanEnabled(false);
185
187}
188
193{
194 std::string version;
195
196 // Lower RTS so the serial port is not monopolized and the hand controller can work.
197 // This must be done AFTER the port is open (i.e. here in Handshake, not in initProperties).
198 int bits = TIOCM_RTS;
199 (void) ioctl(PortFD, TIOCMBIC, &bits);
200
201 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 6;
202
203 cmd[0] = DRIVER_SOM;
204 cmd[1] = 0x03;
205 cmd[2] = DEVICE_PC;
206 cmd[3] = DEVICE_FOC;
207 cmd[4] = GET_VERSION;
208 cmd[5] = calculateCheckSum(cmd, len);
209
210 if (!validateLengths(cmd, len))
211 return false;
212
213 if (!sendCommand(cmd, res, len, DRIVER_LEN))
214 return false;
215
216 version = std::to_string(res[5]) + "." + std::to_string(res[6]);
217 InfoTP[INFO_VERSION].setText(version.c_str());
218
219 LOGF_INFO("Detected version %s", version.c_str());
220
221 return true;
222}
223
228{
229 return "PlaneWave EFA";
230}
231
235bool EFA::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
236{
237 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
238 {
239 // Calibration State
240 if (CalibrationStateSP.isNameMatch(name))
241 {
242 bool enabled = strcmp(CalibrationStateSP[CALIBRATION_ON].getName(), IUFindOnSwitchName(states, names, n)) == 0;
243 if (setCalibrationEnabled(enabled))
244 {
245 CalibrationStateSP.update(states, names, n);
246 CalibrationStateSP.setState(IPS_OK);
247 }
248 else
249 {
250 CalibrationStateSP.setState(IPS_ALERT);
251 }
252
253 CalibrationStateSP.apply();
254 return true;
255 }
256 // Fan State
257 else if (FanStateSP.isNameMatch(name))
258 {
259 if (FanControlSP[FAN_MANUAL].getState() == ISS_OFF)
260 {
261 FanStateSP.setState(IPS_IDLE);
262 LOG_WARN("Cannot control fan while manual control is turned off.");
263 FanControlSP.apply();
264 return true;
265 }
266
267 bool enabled = strcmp(FanStateSP[FAN_ON].getName(), IUFindOnSwitchName(states, names, n)) == 0;
268 if (setFanEnabled(enabled))
269 {
270 FanStateSP.update(states, names, n);
271 FanStateSP.setState(enabled ? IPS_OK : IPS_IDLE);
272 }
273 else
274 {
275 FanStateSP.setState(IPS_ALERT);
276 }
277
278 FanStateSP.apply();
279 return true;
280 }
281 // Fan Control
282 else if (FanControlSP.isNameMatch(name))
283 {
284 FanControlSP.update(states, names, n);
285 if (FanControlSP[FAN_MANUAL].getState() == ISS_ON)
286 {
287 deleteProperty(FanControlNP);
288 LOG_INFO("Fan is now controlled manually.");
289 }
290 else
291 {
292 LOG_INFO("Fan is now controlled automatically per the control parameters.");
293 defineProperty(FanControlNP);
294 }
295
296 FanControlSP.setState(IPS_OK);
297 FanControlSP.apply();
298 return true;
299 }
300 // Fan Disconnect
301 else if (FanDisconnectSP.isNameMatch(name))
302 {
303 FanDisconnectSP.update(states, names, n);
304
305 if (FanDisconnectSP[FAN_OFF_ON_DISCONNECT].getState() == ISS_ON)
306 LOG_INFO("Fan shall be turned off upon device disconnection.");
307 else
308 LOG_INFO("Fan shall left as-is upon device disconnection.");
309
310 FanDisconnectSP.setState(IPS_OK);
311 FanDisconnectSP.apply();
312 return true;
313 }
314 // Approach Direction
315 else if (ApproachDirectionSP.isNameMatch(name))
316 {
317 const bool positiveApproach =
318 strcmp(ApproachDirectionSP[APPROACH_POSITIVE].getName(), IUFindOnSwitchName(states, names, n)) == 0;
319
320 // Skip redundant hardware write if the requested direction already matches
321 // what was read from hardware at startup (getStartupValues→readApproachDirection).
322 const bool currentPositive = (ApproachDirectionSP[APPROACH_POSITIVE].getState() == ISS_ON);
323 if (positiveApproach == currentPositive)
324 {
325 LOGF_DEBUG("Approach direction already %s; skipping hardware command.",
326 positiveApproach ? "Positive (Outward)" : "Negative (Inward)");
327 ApproachDirectionSP.setState(IPS_OK);
328 ApproachDirectionSP.apply();
329 return true;
330 }
331
332 if (setApproachDirection(positiveApproach ? 0 : 1))
333 {
334 ApproachDirectionSP.update(states, names, n);
335 ApproachDirectionSP.setState(IPS_OK);
336 LOGF_INFO("Approach direction set to %s.", positiveApproach ? "Positive (Outward)" : "Negative (Inward)");
337 }
338 else
339 {
340 ApproachDirectionSP.setState(IPS_ALERT);
341 }
342 ApproachDirectionSP.apply();
343 return true;
344 }
345 // Stop Detection
346 else if (StopDetectSP.isNameMatch(name))
347 {
348 const bool enabled =
349 strcmp(StopDetectSP[STOP_DETECT_ON].getName(), IUFindOnSwitchName(states, names, n)) == 0;
350
351 // Skip redundant hardware write if the requested state already matches
352 // what was read from hardware at startup (getStartupValues→readStopDetect).
353 const bool currentEnabled = (StopDetectSP[STOP_DETECT_ON].getState() == ISS_ON);
354 if (enabled == currentEnabled)
355 {
356 LOGF_DEBUG("Stop detection already %s; skipping hardware command.",
357 enabled ? "enabled" : "disabled");
358 StopDetectSP.setState(IPS_OK);
359 StopDetectSP.apply();
360 return true;
361 }
362
363 if (setStopDetect(enabled))
364 {
365 StopDetectSP.update(states, names, n);
366 StopDetectSP.setState(IPS_OK);
367 LOGF_INFO("Stop detection %s.", enabled ? "enabled" : "disabled");
368 }
369 else
370 {
371 StopDetectSP.setState(IPS_ALERT);
372 }
373 StopDetectSP.apply();
374 return true;
375 }
376 }
377
378 return INDI::Focuser::ISNewSwitch(dev, name, states, names, n);
379}
380
384bool EFA::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
385{
386 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
387 {
388 // Fan Params
389 if (FanControlNP.isNameMatch(name))
390 {
391 FanControlNP.update(values, names, n);
392 FanControlNP.setState(IPS_OK);
393 FanControlNP.apply();
394 return true;
395 }
396 }
397
398 return INDI::Focuser::ISNewNumber(dev, name, values, names, n);
399}
400
404bool EFA::SyncFocuser(uint32_t ticks)
405{
406 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 9;
407
408 cmd[0] = DRIVER_SOM;
409 cmd[1] = 0x06;
410 cmd[2] = DEVICE_PC;
411 cmd[3] = DEVICE_FOC;
412 cmd[4] = MTR_OFFSET_CNT;
413 cmd[5] = (ticks >> 16) & 0xFF;
414 cmd[6] = (ticks >> 8) & 0xFF;
415 cmd[7] = (ticks >> 0) & 0xFF;
416 cmd[8] = calculateCheckSum(cmd, len);
417
418 if (!validateLengths(cmd, len))
419 return false;
420
421 if (!sendCommand(cmd, res, len, DRIVER_LEN))
422 return false;
423
424 return (res[5] == 1);
425}
426
430IPState EFA::MoveAbsFocuser(uint32_t targetTicks)
431{
432 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 9;
433
434 cmd[0] = DRIVER_SOM;
435 cmd[1] = 0x06;
436 cmd[2] = DEVICE_PC;
437 cmd[3] = DEVICE_FOC;
438 cmd[4] = MTR_GOTO_POS2;
439 cmd[5] = (targetTicks >> 16) & 0xFF;
440 cmd[6] = (targetTicks >> 8) & 0xFF;
441 cmd[7] = (targetTicks >> 0) & 0xFF;
442 cmd[8] = calculateCheckSum(cmd, len);
443
444 if (!validateLengths(cmd, len))
445 return IPS_ALERT;
446
447 if (!sendCommand(cmd, res, len, DRIVER_LEN))
448 return IPS_ALERT;
449
450 return (res[5] == 1) ? IPS_BUSY : IPS_ALERT;
451}
452
457{
458 int direction = (dir == FOCUS_INWARD) ? -1 : 1;
459 int reversed = (FocusReverseSP[INDI_ENABLED].getState() == ISS_ON) ? -1 : 1;
460 int relative = static_cast<int>(ticks);
461 int targetAbsPosition = FocusAbsPosNP[0].getValue() + (relative * direction * reversed);
462
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)));
465
466 return MoveAbsFocuser(targetAbsPosition);
467}
468
474{
475 // Re-read current position to make sure we have the latest value
476 readPosition();
477 uint32_t currentPos = static_cast<uint32_t>(FocusAbsPosNP[0].getValue());
478 return MoveAbsFocuser(currentPos) != IPS_ALERT;
479}
480
485{
486 if (!isConnected())
487 return;
488
489 IN_TIMER = true;
490
491 readPosition();
492
493 if (readTemperature())
494 {
495 // Send temperature is above threshold
496 bool aboveThreshold = false;
497 for (size_t i = 0; i < TemperatureNP.count(); i++)
498 {
499 // Skip invalid sentinel temperature values
500 if (std::fabs(TemperatureNP[i].getValue() - TEMPERATURE_INVALID) < 0.1)
501 continue;
502
503 if (std::fabs(TemperatureNP[i].getValue() - m_LastTemperature[i]) > TEMPERATURE_THRESHOLD)
504 {
505 aboveThreshold = true;
506 m_LastTemperature[i] = TemperatureNP[i].getValue();
507 }
508 }
509
510 if (aboveThreshold)
511 TemperatureNP.apply();
512
513
514 if (FanControlSP[FAN_MANUAL].getState() == ISS_OFF)
515 {
516 bool turnOn = false, turnOff = false;
517 const bool isFanOn = FanStateSP[FAN_ON].getState() == ISS_ON;
518
519 // Check if we need to do automatic regulation of fan
520 if (FanControlSP[FAN_AUTOMATIC_ABSOLUTE].getState() == ISS_ON)
521 {
522 // Only regulate if primary temperature is valid
523 if (std::fabs(TemperatureNP[TEMPERATURE_PRIMARY].getValue() - TEMPERATURE_INVALID) > 0.1)
524 {
525 // Adjust delta for deadzone
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();
528
529 turnOn = TemperatureNP[TEMPERATURE_PRIMARY].getValue() > max_delta;
530 turnOff = TemperatureNP[TEMPERATURE_PRIMARY].getValue() < min_delta;
531 }
532 }
533 else if (FanControlSP[FAN_AUTOMATIC_RELATIVE].getState() == ISS_ON)
534 {
535 // Only regulate if both temperatures are valid
536 if (std::fabs(TemperatureNP[TEMPERATURE_PRIMARY].getValue() - TEMPERATURE_INVALID) > 0.1 &&
537 std::fabs(TemperatureNP[TEMPERATURE_AMBIENT].getValue() - TEMPERATURE_INVALID) > 0.1)
538 {
539 // Temperature delta
540 double tDiff = TemperatureNP[TEMPERATURE_PRIMARY].getValue() - TemperatureNP[TEMPERATURE_AMBIENT].getValue();
541 // Adjust delta for deadzone
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();
544
545 // Check if we need to turn off/on fan
546 turnOn = tDiff > max_delta;
547 turnOff = tDiff < min_delta;
548 }
549 }
550
551 if (isFanOn && turnOff)
552 {
553 setFanEnabled(false);
554 FanStateSP[FAN_ON].setState(ISS_OFF);
555 FanStateSP[FAN_OFF].setState(ISS_ON);
556 FanStateSP.setState(IPS_IDLE);
557 FanStateSP.apply();
558 }
559 else if (!isFanOn && turnOn)
560 {
561 setFanEnabled(true);
562 FanStateSP[FAN_ON].setState(ISS_ON);
563 FanStateSP[FAN_OFF].setState(ISS_OFF);
564 FanStateSP.setState(IPS_OK);
565 FanStateSP.apply();
566 }
567 }
568 }
569
570 if (FocusAbsPosNP.getState() == IPS_BUSY || FocusRelPosNP.getState() == IPS_BUSY)
571 {
572 if (isGOTOComplete())
573 {
574 FocusAbsPosNP.setState(IPS_OK);
575 FocusRelPosNP.setState(IPS_OK);
576 FocusAbsPosNP.apply();
577 FocusRelPosNP.apply();
578 LOG_INFO("Focuser reached requested position.");
579 }
580 else
581 FocusAbsPosNP.apply();
582 }
583 else if (std::fabs(FocusAbsPosNP[0].getValue() - m_LastPosition) > 0)
584 {
585 m_LastPosition = FocusAbsPosNP[0].getValue();
586 FocusAbsPosNP.apply();
587 }
588
589 IN_TIMER = false;
590
592}
593
597bool EFA::SetFocuserMaxPosition(uint32_t ticks)
598{
599 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 9;
600
601 cmd[0] = DRIVER_SOM;
602 cmd[1] = 0x06;
603 cmd[2] = DEVICE_PC;
604 cmd[3] = DEVICE_FOC;
606 cmd[5] = (ticks >> 16) & 0xFF;
607 cmd[6] = (ticks >> 8) & 0xFF;
608 cmd[7] = (ticks >> 0) & 0xFF;
609 cmd[8] = calculateCheckSum(cmd, len);
610
611 if (!validateLengths(cmd, len))
612 return false;
613
614 if (!sendCommand(cmd, res, len, DRIVER_LEN))
615 return false;
616
617 return (res[5] == 1);
618}
619
623bool EFA::ReverseFocuser(bool enabled)
624{
625 INDI_UNUSED(enabled);
626 return true;
627}
628
632bool EFA::saveConfigItems(FILE * fp)
633{
635
636 FanControlSP.save(fp);
637 if (FanControlNP.getState() == IPS_OK)
638 FanControlNP.save(fp);
639 FanDisconnectSP.save(fp);
640 // ApproachDirectionSP and StopDetectSP are stored in hardware EEPROM.
641 // They are read back at startup via getStartupValues() and should not
642 // be saved to or restored from config to avoid sending redundant
643 // configuration commands that could trigger focuser movement.
644 return true;
645}
646
650void EFA::getStartupValues()
651{
652 readPosition();
653 readCalibrationState();
654 readFanState();
655 readTemperature();
656 readApproachDirection();
657 readStopDetect();
658
659 if (readMaxSlewLimit())
660 {
661 FocusAbsPosNP[0].setMax(FocusMaxPosNP[0].getMax());
662 FocusAbsPosNP[0].setStep(FocusAbsPosNP[0].getMax() / 50);
663
664 FocusRelPosNP[0].setValue(FocusAbsPosNP[0].getMax() / 50);
665 FocusRelPosNP[0].setMax(FocusAbsPosNP[0].getMax() / 2);
666 FocusRelPosNP[0].setStep(FocusRelPosNP[0].getMax() / 50);
667
668 FocusMaxPosNP[0].setValue(FocusMaxPosNP[0].getMax());
669 FocusMaxPosNP[0].setStep(FocusMaxPosNP[0].getMax() / 50);
670
674 }
675}
676
680inline int EFA::readByte(int fd, uint8_t *buf, int timeout, int *nbytes_read)
681{
682 return tty_read(fd, (char *)buf, 1, timeout, nbytes_read);
683}
684
688inline int EFA::readBytes(int fd, uint8_t *buf, int nbytes, int timeout, int *nbytes_read)
689{
690 return tty_read(fd, (char *)buf, nbytes, timeout, nbytes_read);
691}
692
696inline int EFA::writeBytes(int fd, const uint8_t *buf, int nbytes, int *nbytes_written)
697{
698 return tty_write(fd, (const char *)buf, nbytes, nbytes_written);
699}
700
704int EFA::readPacket(int fd, uint8_t *buf, int nbytes, int timeout, int *nbytes_read)
705{
706 int len = 0, rc = 0, read_bytes = *nbytes_read = 0;
707
708 if (nbytes < 6) // smallest packet is 6 bytes
709 {
710 LOGF_ERROR("Read needs at least 6 bytes; exceeds supplied buffer size (%d)", nbytes);
711 return TTY_READ_ERROR;
712 }
713
714 for (int i = 0; i < 10; i++)
715 {
716 // look for SOM byte
717 rc = readByte(fd, &buf[0], timeout, &read_bytes);
718 if (rc == TTY_OK && read_bytes == 1)
719 {
720 if (buf[0] == DRIVER_SOM)
721 {
722 break;
723 }
724 else
725 {
726 LOGF_DEBUG("Looking for SOM (%02X); found %d byte (%02X)", DRIVER_SOM, read_bytes, buf[0]);
727 }
728 }
729 else
730 {
731 char errstr[MAXRBUF] = {0};
732 tty_error_msg(rc, errstr, MAXRBUF);
733 LOGF_DEBUG("Looking for SOM (%02X); found %s", DRIVER_SOM, errstr);
734 // Only keep scanning past non-SOM bytes. A timeout means nothing more is coming,
735 // so waiting out the timeout again would just block the driver for longer.
736 break;
737 }
738 }
739 if (rc != TTY_OK || read_bytes != 1 || buf[0] != DRIVER_SOM)
740 {
741 LOGF_DEBUG("%s byte not encountered", "SOM");
742 if (rc == TTY_OK)
743 return TTY_TIME_OUT;
744 return rc;
745 }
746
747 if ((rc = readByte(fd, &buf[1], timeout, &read_bytes)) != TTY_OK)
748 {
749 LOGF_DEBUG("%s byte not encountered", "LEN");
750 return rc;
751 }
752 len = buf[1];
753
754 // read source
755 if ((rc = readByte(fd, &buf[2], timeout, &read_bytes)) != TTY_OK)
756 {
757 LOGF_DEBUG("%s byte not encountered", "SRC");
758 return rc;
759 }
760 // read receiver
761 if ((rc = readByte(fd, &buf[3], timeout, &read_bytes)) != TTY_OK)
762 {
763 LOGF_DEBUG("%s byte not encountered", "RCV");
764 return rc;
765 }
766 // read command
767 if ((rc = readByte(fd, &buf[4], timeout, &read_bytes)) != TTY_OK)
768 {
769 LOGF_DEBUG("%s byte not encountered", "CMD");
770 return rc;
771 }
772
773 if ((len + 3) > nbytes)
774 {
775 LOGF_ERROR("Read (%d) will exceed supplied buffer size (%d) for command %02X", (len + 3), nbytes, buf[4]);
776 return TTY_READ_ERROR;
777 }
778
779 // read data
780 int n;
781 for (n = 0; n < (len - 3); ++n)
782 {
783 if ((rc = readByte(fd, &buf[5 + n], timeout, &read_bytes)) != TTY_OK)
784 {
785 LOGF_DEBUG("%s byte not encountered", "DATA");
786 return rc;
787 }
788 }
789 // read checksum
790 if ((rc = readByte(fd, &buf[5 + n], timeout, &read_bytes)) != TTY_OK)
791 {
792 LOGF_DEBUG("%s byte not encountered", "DATA");
793 return rc;
794 }
795
796 uint8_t chk = calculateCheckSum(buf, (len + 3));
797
798 if (chk != buf[len + 2])
799 {
800 LOG_ERROR("Invalid checksum!");
801 return TTY_OK; // not a tty error, nbytes_read is still zero and it is used to indicate there was this problem
802 }
803
804 *nbytes_read = len + 3;
805
806 return rc;
807}
808
812bool EFA::sendCommand(const uint8_t * cmd, uint8_t *res, uint32_t cmd_len, uint32_t res_len)
813{
814 int nbytes_written = 0, nbytes_read = 0, bits = 0, rc = 0, hexbuflen = (DRIVER_LEN * 3 + 4);
815 char hexbuf[DRIVER_LEN * 3 + 4];
816
817 for (int j = 0; j < 3; usleep(100000), j++)
818 {
819 // make sure RTS is lowered
820 bits = TIOCM_RTS;
821 (void) ioctl(PortFD, TIOCMBIC, &bits);
822 bits = 0;
823
824 // Wait until CTS is cleared.
825 for (int i = 0; i < 10; i++)
826 {
827 if ((rc = ioctl(PortFD, TIOCMGET, &bits)) == 0 && (bits & TIOCM_CTS) == 0)
828 break;
829 usleep(100000);
830 }
831
832 if (rc < 0)
833 {
834 LOGF_ERROR("Failed to read CTS state: %s", strerror(errno));
835 return false;
836 }
837 else if ((bits & TIOCM_CTS) != 0)
838 {
839 LOG_ERROR("CTS timed out: serial bus is still busy.");
840 return false;
841 }
842
843 // Now raise RTS
844 bits = TIOCM_RTS;
845 ioctl(PortFD, TIOCMBIS, &bits); // was TIOCMSET
846
847 if (!IN_TIMER && efaDump(hexbuf, hexbuflen, cmd, cmd_len) != NULL)
848 {
849 LOGF_DEBUG("CMD: %s", hexbuf);
850 }
851 // Discard any stale input so a late response to an earlier command is not taken as ours
852 tcflush(PortFD, TCIFLUSH);
853 rc = writeBytes(PortFD, cmd, cmd_len, &nbytes_written);
854
855 if (rc != TTY_OK)
856 {
857 continue;
858 }
859
860 rc = readPacket(PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
861
862 if (rc != TTY_OK || nbytes_read == 0)
863 {
864 continue;
865 }
866
867 if ((int)cmd_len == nbytes_read && memcmp(cmd, res, cmd_len) == 0)
868 {
869 // received an echo
870
871 bits = TIOCM_RTS;
872 ioctl(PortFD, TIOCMBIC, &bits);
873
874 // Next read the actual response from EFA
875 rc = readPacket(PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
876
877 if (rc != TTY_OK || nbytes_read == 0)
878 {
879 continue;
880 }
881 }
882 else if (efaDump(hexbuf, hexbuflen, cmd, cmd_len) != NULL)
883 {
884 // expected there to always be an echo, so note this occurrence
885 LOGF_DEBUG("no echo for command packet: %s", hexbuf);
886 }
887
888 if (!IN_TIMER && efaDump(hexbuf, hexbuflen, res, nbytes_read) != NULL)
889 {
890 LOGF_DEBUG("RESP: %s", hexbuf);
891 }
892
893 if (cmd[2] != res[3] || cmd[3] != res[2] || cmd[4] != res[4])
894 {
895 LOGF_DEBUG("Send/Receive mismatch - %s!", "packet not for us");
896 continue;
897 }
898 break;
899 }
900
901 // Extra lowering of RTS to make sure hand controller is made available
902 bits = TIOCM_RTS;
903 ioctl(PortFD, TIOCMBIC, &bits);
904
905 if (rc != TTY_OK)
906 {
907 char errstr[MAXRBUF] = {0};
908 tty_error_msg(rc, errstr, MAXRBUF);
909 LOGF_ERROR("Serial I/O error: %s.", errstr);
910 return false;
911 }
912
913 if (cmd[2] != res[3] || cmd[3] != res[2] || cmd[4] != res[4])
914 {
915 LOGF_ERROR("Send/Receive mismatch and %s", "timeout");
916 return false;
917 }
918
919 return true;
920}
921
925bool EFA::readPosition()
926{
927 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 6;
928
929 cmd[0] = DRIVER_SOM;
930 cmd[1] = 0x03;
931 cmd[2] = DEVICE_PC;
932 cmd[3] = DEVICE_FOC;
933 cmd[4] = MTR_GET_POS;
934 cmd[5] = calculateCheckSum(cmd, len);
935
936 if (!validateLengths(cmd, len))
937 return false;
938
939 if (!sendCommand(cmd, res, len, DRIVER_LEN))
940 return false;
941
942 FocusAbsPosNP[0].setValue(res[5] << 16 | res[6] << 8 | res[7]);
943 return true;
944}
945
949bool EFA::readMaxSlewLimit()
950{
951 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 6;
952
953 cmd[0] = DRIVER_SOM;
954 cmd[1] = 0x03;
955 cmd[2] = DEVICE_PC;
956 cmd[3] = DEVICE_FOC;
958 cmd[5] = calculateCheckSum(cmd, len);
959
960 if (!validateLengths(cmd, len))
961 return false;
962
963 if (!sendCommand(cmd, res, len, DRIVER_LEN))
964 return false;
965
966 uint32_t limit = res[5] << 16 | res[6] << 8 | res[7];
967 if (limit > 0)
968 {
969 FocusMaxPosNP[0].setMax(limit);
970 return true;
971 }
972
973 return false;
974}
975
979bool EFA::readApproachDirection()
980{
981 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 6;
982
983 cmd[0] = DRIVER_SOM;
984 cmd[1] = 0x03;
985 cmd[2] = DEVICE_PC;
986 cmd[3] = DEVICE_FOC;
988 cmd[5] = calculateCheckSum(cmd, len);
989
990 if (!validateLengths(cmd, len))
991 return false;
992
993 if (!sendCommand(cmd, res, len, DRIVER_LEN))
994 return false;
995
996 // 0 = positive (outward) approach, 1 = negative (inward) approach
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);
1000
1001 return true;
1002}
1003
1009bool EFA::setApproachDirection(uint8_t direction)
1010{
1011 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 7;
1012
1013 cmd[0] = DRIVER_SOM;
1014 cmd[1] = 0x04;
1015 cmd[2] = DEVICE_PC;
1016 cmd[3] = DEVICE_FOC;
1018 cmd[5] = direction;
1019 cmd[6] = calculateCheckSum(cmd, len);
1020
1021 if (!validateLengths(cmd, len))
1022 return false;
1023
1024 if (!sendCommand(cmd, res, len, DRIVER_LEN))
1025 return false;
1026
1027 return (res[5] == 1);
1028}
1029
1033bool EFA::readStopDetect()
1034{
1035 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 6;
1036
1037 cmd[0] = DRIVER_SOM;
1038 cmd[1] = 0x03;
1039 cmd[2] = DEVICE_PC;
1040 cmd[3] = DEVICE_FOC;
1042 cmd[5] = calculateCheckSum(cmd, len);
1043
1044 if (!validateLengths(cmd, len))
1045 return false;
1046
1047 if (!sendCommand(cmd, res, len, DRIVER_LEN))
1048 return false;
1049
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);
1053
1054 return true;
1055}
1056
1060bool EFA::setStopDetect(bool enabled)
1061{
1062 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 7;
1063
1064 cmd[0] = DRIVER_SOM;
1065 cmd[1] = 0x04;
1066 cmd[2] = DEVICE_PC;
1067 cmd[3] = DEVICE_FOC;
1068 cmd[4] = MTR_STOP_DETECT;
1069 cmd[5] = enabled ? 1 : 0;
1070 cmd[6] = calculateCheckSum(cmd, len);
1071
1072 if (!validateLengths(cmd, len))
1073 return false;
1074
1075 if (!sendCommand(cmd, res, len, DRIVER_LEN))
1076 return false;
1077
1078 return (res[5] == 1);
1079}
1080
1084bool EFA::isGOTOComplete()
1085{
1086 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 6;
1087
1088 cmd[0] = DRIVER_SOM;
1089 cmd[1] = 0x03;
1090 cmd[2] = DEVICE_PC;
1091 cmd[3] = DEVICE_FOC;
1092 cmd[4] = MTR_GOTO_OVER;
1093 cmd[5] = calculateCheckSum(cmd, len);
1094
1095 if (!validateLengths(cmd, len))
1096 return false;
1097
1098 if (!sendCommand(cmd, res, len, DRIVER_LEN))
1099 return false;
1100
1101 return (res[5] != 0);
1102}
1103
1107bool EFA::setFanEnabled(bool enabled)
1108{
1109 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 7;
1110
1111 cmd[0] = DRIVER_SOM;
1112 cmd[1] = 0x04;
1113 cmd[2] = DEVICE_PC;
1114 cmd[3] = DEVICE_FAN;
1115 cmd[4] = FANS_SET;
1116 cmd[5] = enabled ? 1 : 0;
1117 cmd[6] = calculateCheckSum(cmd, len);
1118
1119 if (!validateLengths(cmd, len))
1120 return false;
1121
1122 if (!sendCommand(cmd, res, len, DRIVER_LEN))
1123 return false;
1124
1125 return (res[5] == 1);
1126}
1127
1132bool EFA::readFanState()
1133{
1134 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 6;
1135
1136 cmd[0] = DRIVER_SOM;
1137 cmd[1] = 0x03;
1138 cmd[2] = DEVICE_PC;
1139 cmd[3] = DEVICE_FAN;
1140 cmd[4] = FANS_GET;
1141 cmd[5] = calculateCheckSum(cmd, len);
1142
1143 if (!validateLengths(cmd, len))
1144 return false;
1145
1146 if (!sendCommand(cmd, res, len, DRIVER_LEN))
1147 return false;
1148
1149 // Protocol: 1 = fan is ON, 0 = fan is OFF (consistent with FANS_SET command)
1150 bool enabled = (res[5] == 1);
1151
1152 FanStateSP[FAN_ON].setState(enabled ? ISS_ON : ISS_OFF);
1153 FanStateSP[FAN_OFF].setState(enabled ? ISS_OFF : ISS_ON);
1154
1155 return true;
1156}
1157
1161bool EFA::setCalibrationEnabled(bool enabled)
1162{
1163 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 8;
1164
1165 cmd[0] = DRIVER_SOM;
1166 cmd[1] = 0x05;
1167 cmd[2] = DEVICE_PC;
1168 cmd[3] = DEVICE_FOC;
1170 cmd[5] = 0x40;
1171 cmd[6] = enabled ? 1 : 0;
1172 cmd[7] = calculateCheckSum(cmd, len);
1173
1174 if (!validateLengths(cmd, len))
1175 return false;
1176
1177 if (!sendCommand(cmd, res, len, DRIVER_LEN))
1178 return false;
1179
1180 return (res[5] == 1);
1181}
1182
1186bool EFA::readCalibrationState()
1187{
1188 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 7;
1189
1190 cmd[0] = DRIVER_SOM;
1191 cmd[1] = 0x04;
1192 cmd[2] = DEVICE_PC;
1193 cmd[3] = DEVICE_FOC;
1195 cmd[5] = 0x40;
1196 cmd[6] = calculateCheckSum(cmd, len);
1197
1198 if (!validateLengths(cmd, len))
1199 return false;
1200
1201 if (!sendCommand(cmd, res, len, DRIVER_LEN))
1202 return false;
1203
1204 bool enabled = (res[5] == 1);
1205
1206 CalibrationStateSP[CALIBRATION_ON].setState(enabled ? ISS_ON : ISS_OFF);
1207 CalibrationStateSP[CALIBRATION_OFF].setState(enabled ? ISS_OFF : ISS_ON);
1208
1209 return true;
1210}
1211
1217bool EFA::readTemperature()
1218{
1219 uint8_t cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0}, len = 7;
1220
1221 for (uint8_t i = 0; i < 2; i++)
1222 {
1223 cmd[0] = DRIVER_SOM;
1224 cmd[1] = 0x04;
1225 cmd[2] = DEVICE_PC;
1226 cmd[3] = DEVICE_TEMP;
1227 cmd[4] = TEMP_GET;
1228 cmd[5] = i;
1229 cmd[6] = calculateCheckSum(cmd, len);
1230
1231 if (!validateLengths(cmd, len))
1232 return false;
1233
1234 if (!sendCommand(cmd, res, len, DRIVER_LEN))
1235 return false;
1236
1237 double temperature = calculateTemperature(res[5], res[6]);
1238
1239 if (std::fabs(temperature - TEMPERATURE_INVALID) < 0.1)
1240 {
1241 // Sensor reports invalid data (0x7F 0x7F) — mark as alert but do not update the value
1242 LOGF_DEBUG("Temperature sensor %d returned invalid data.", i);
1243 TemperatureNP.setState(IPS_ALERT);
1244 }
1245 else
1246 {
1247 TemperatureNP[i].setValue(temperature);
1248 }
1249 }
1250
1251 return true;
1252}
1253
1257double EFA::calculateTemperature(uint8_t byte2, uint8_t byte3)
1258{
1259 if (byte2 == 0x7F && byte3 == 0x7F)
1260 return TEMPERATURE_INVALID;
1261
1262 int raw_temperature = byte3 << 8 | byte2;
1263 if (raw_temperature & 0x8000)
1264 raw_temperature = raw_temperature - 0x10000;
1265
1266 return raw_temperature / 16.0;
1267}
1268
1272char * EFA::efaDump(char * buf, int buflen, const uint8_t * data, uint32_t size)
1273{
1274 int needed = 0, idx = 0;
1275
1276 needed = size * 3 + 4; // each byte goes to 2 chars plus 1 space (or trailing null char) plus 4 marker characters
1277
1278 if (needed > buflen)
1279 {
1280 return NULL;
1281 }
1282
1283 for (uint32_t i = 0; i < size; i++)
1284 {
1285 if (i == 4)
1286 {
1287 (void) sprintf(buf + idx, "<%02X> ", data[i]);
1288 idx += 5;
1289 }
1290 else if (i == 5 && i < (size - 1))
1291 {
1292 buf[idx++] = '[';
1293 for (uint32_t j = i, k = 3; j < (size - 1) && k < data[1]; j++, k++)
1294 {
1295 (void) sprintf(buf + idx, "%02X ", data[j]);
1296 idx += 3;
1297 i = j;
1298 }
1299 buf[idx - 1] = ']';
1300 buf[idx++] = ' ';
1301 }
1302 else
1303 {
1304 (void) sprintf(buf + idx, "%02X ", data[i]);
1305 idx += 3;
1306 }
1307 }
1308
1309 buf[idx - 1] = '\0';
1310
1311 return buf;
1312}
1313
1317std::vector<std::string> EFA::split(const std::string &input, const std::string &regex)
1318{
1319 // passing -1 as the submatch index parameter performs splitting
1320 std::regex re(regex);
1321 std::sregex_token_iterator
1322 first{input.begin(), input.end(), re, -1},
1323 last;
1324 return {first, last};
1325}
1326
1330template <typename T>
1331std::string EFA::to_string(const T a_value, const int n)
1332{
1333 std::ostringstream out;
1334 out.precision(n);
1335 out << std::fixed << a_value;
1336 return out.str();
1337}
1338
1342bool EFA::validateLengths(const uint8_t *cmd, uint32_t len)
1343{
1344 if (len < 6)
1345 {
1346 LOGF_ERROR("packet length (%d) is too short for command %02X", len, cmd[4]);
1347 return false;
1348 }
1349 if (cmd[1] + 3 != (int)len)
1350 {
1351 LOGF_ERROR("packet length (%d) and data length (%d) discrepancy for command %02X", len, cmd[1], cmd[4]);
1352 return false;
1353 }
1354
1355 return true;
1356}
1357
1361uint8_t EFA::calculateCheckSum(const uint8_t *cmd, uint32_t len)
1362{
1363 int32_t sum = 0;
1364
1365 for (uint32_t i = 1; i < len - 1; i++)
1366 sum += cmd[i];
1367
1368 return ((-sum) & 0xFF);
1369}
double temperature
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
@ DEVICE_PC
@ DEVICE_FOC
@ DEVICE_TEMP
@ DEVICE_FAN
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_SLEWLIMITMAX
@ MTR_SLEWLIMITGETMAX
@ MTR_GET_APPROACH_DIRECTION
@ GET_VERSION
@ TEMP_GET
@ MTR_GET_STOP_DETECT
@ FANS_GET
@ MTR_GOTO_OVER
@ MTR_GOTO_POS2
@ MTR_OFFSET_CNT
@ FANS_SET
@ MTR_STOP_DETECT
@ MTR_SET_CALIBRATION_STATE
@ MTR_APPROACH_DIRECTION
@ MTR_GET_CALIBRATION_STATE
@ MTR_GET_POS
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.
bool isConnected() const
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 errno
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
@ ISR_NOFMANY
Definition indiapi.h:173
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
Definition indicom.c:418
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition indicom.c:548
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Definition indicom.c:1243
Implementations for common driver routines.
@ TTY_OK
Definition indicom.h:54
@ TTY_READ_ERROR
Definition indicom.h:55
@ TTY_TIME_OUT
Definition indicom.h:58
const char * IUFindOnSwitchName(ISState *states, char *names[], int n)
Returns the name of the first ON switch it finds in the supplied arguments.
Definition indidevapi.c:355
#define INDI_UNUSED(x)
Definition indidevapi.h:132
#define MAXRBUF
Definition indidriver.c:52
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_WARN(txt)
Definition indilogger.h:73
#define LOGF_DEBUG(fmt,...)
Definition indilogger.h:83
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Definition indilogger.h:72
#define LOGF_ERROR(fmt,...)
Definition indilogger.h:80
#define LOG_INFO(txt)
Definition indilogger.h:74
#define getDeviceName
int fd
json_pointer res
uint8_t cmd[4]
Definition pwc-ioctl.h:2
int ioctl(int fd, unsigned long request,...) __THROW