Instrument Neutral Distributed Interface INDI 2.2.5
focuslynx.cpp
Go to the documentation of this file.
1/*
2 Focus Lynx/Focus Boss II INDI driver
3 Copyright (C) 2015 Jasem Mutlaq ([email protected])
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#include "focuslynx.h"
21
22#include "indicom.h"
24
25#include <memory>
26#include <cstring>
27#include <termios.h>
28
29#define FOCUSNAMEF1 "FocusLynx F1"
30#define FOCUSNAMEF2 "FocusLynx F2"
31
32static std::unique_ptr<FocusLynxF1> lynxDriveF1(new FocusLynxF1("F1"));
33static std::unique_ptr<FocusLynxF2> lynxDriveF2(new FocusLynxF2("F2"));
34
35/************************************************************************************
36*
37* First Focuser (F1)
38*
39*************************************************************************************/
40
41/************************************************************************************
42 *
43* ***********************************************************************************/
44FocusLynxF1::FocusLynxF1(const char *target)
45{
46 /* Override the original constructor
47 * and give the Focuser target
48 * F1 or F2 to set the target of the created instance
49 */
50 setFocusTarget(target);
51 // set the focuser name to a fixed value to ensure that both focusers are visible
53
54 // Both communication available, Serial and network (tcp/ip)
56
57 // explain in connect() function Only set on the F1 constructor, not on the F2 one
58 PortFD = -1;
59}
60
61/************************************************************************************
62 *
63* ***********************************************************************************/
67
68/**************************************************************************************
69*
70***************************************************************************************/
72/* New properties
73 * Common properties for both focusers, Hub setting
74 * Only display and managed by Focuser F1
75 * TODO:
76 * Make this properties writable to give possibility to set these via IndiDriver
77 */
78{
80
81 // General info
82 IUFillText(&HubT[0], "Firmware", "", "");
83 IUFillText(&HubT[1], "Sleeping", "", "");
84 IUFillTextVector(&HubTP, HubT, 2, getDeviceName(), "HUB-INFO", "Hub", HUB_SETTINGS_TAB, IP_RO, 0, IPS_IDLE);
85
86 // Wired network
87 IUFillText(&WiredT[0], "IP address", "", "");
88 IUFillText(&WiredT[1], "DHCP active", "", "");
89 IUFillTextVector(&WiredTP, WiredT, 2, getDeviceName(), "WIRED-INFO", "Wired", HUB_SETTINGS_TAB, IP_RO, 0, IPS_IDLE);
90
91 // Wifi network
92 IUFillText(&WifiT[0], "Installed", "", "");
93 IUFillText(&WifiT[1], "Connected", "", "");
94 IUFillText(&WifiT[2], "Firmware", "", "");
95 IUFillText(&WifiT[3], "Firm. Version OK", "", "");
96 IUFillText(&WifiT[4], "SSID", "", "");
97 IUFillText(&WifiT[5], "Ip address", "", "");
98 IUFillText(&WifiT[6], "Security mode", "", "");
99 IUFillText(&WifiT[7], "Security key", "", "");
100 IUFillText(&WifiT[8], "Wep key", "", "");
101 IUFillTextVector(&WifiTP, WifiT, 9, getDeviceName(), "WIFI-INFO", "Wifi", HUB_SETTINGS_TAB, IP_RO, 0, IPS_IDLE);
102
105 // To avoid confusion has Debug levels only visible on F2 remove it from F1
106 // Simultation option and Debug option present only on F2
107 // deleteProperty("DEBUG");
108 return true;
109}
110
111/************************************************************************************
112 *
113* ***********************************************************************************/
115{
116 return FOCUSNAMEF1;
117}
118
119/************************************************************************************
120 *
121* ***********************************************************************************/
123/* Override of connect() function
124 * different for F1 or F2 focuser
125 * F1 connect only himself to the driver and
126 * it is the only one who's connect to the communication port to establish the physical communication
127 */
128{
129 configurationComplete = false;
130 if (isSimulation())
131 {
132 /* PortFD value used to give the /dev/ttyUSBx or TCP descriptor
133 * if -1 = no physical port selected or simulation mode
134 * if 0 = no descriptor created, F1 not connected (error)
135 * other value = descriptor number
136 */
137 PortFD = -1;
139 }
140 else if (!INDI::Focuser::Connect())
141 return false;
142 return Handshake();
143}
144
145/************************************************************************************
146 *
147* ***********************************************************************************/
149{
150 // If we disconnect F1, the socket would be close.
152
153 // Get value of PortFD, should be -1
158 // Then we have to disconnect the second focuser F2
159 lynxDriveF2->RemoteDisconnect();
160
161 LOGF_INFO("Value of PortFD = %d", PortFD);
162 return true;
163}
164
165/************************************************************************************
166 *
167* ***********************************************************************************/
169// Would be used by F2 instance to communicate with the HUB
170{
171 LOGF_INFO("F1 PortFD : %d", PortFD);
172 return PortFD;
173}
174
175/************************************************************************************
176 *
177* ***********************************************************************************/
179/* Add the HUB properties on the driver
180 * Only displayed and used by the first focuser F1
181 */
182{
184
185 if (isConnected())
186 {
187 defineProperty(&HubTP);
188 defineProperty(&WiredTP);
189 defineProperty(&WifiTP);
191
192 if (getHubConfig())
193 LOG_INFO("HUB parameters updated.");
194 else
195 {
196 LOG_ERROR("Failed to retrieve HUB configuration settings...");
197 return false;
198 }
199 }
200 else
201 {
202 deleteProperty(HubTP.name);
203 deleteProperty(WiredTP.name);
204 deleteProperty(WifiTP.name);
206 }
207 return true;
208}
209
210/************************************************************************************
211 *
212* ***********************************************************************************/
213bool FocusLynxF1::getHubConfig()
214{
215 char cmd[32] = {0};
216 int errcode = 0;
217 char errmsg[MAXRBUF];
218 char response[32] = {0};
219 int nbytes_read = 0;
220 int nbytes_written = 0;
221 char key[16] = {0};
222 char text[32] = {0};
223
224 /* Answer from the HUB
225 <FHGETHUBINFO>!
226 HUB INFO
227 Hub FVer = 2.0.4
228 Sleeping = 0
229 Wired IP = 169.254.190.196
230 DHCPisOn = 1
231 WF Atchd = 0
232 WF Conn = 0
233 WF FVer = 0.0.0
234 WF FV OK = 0
235 WF SSID =
236 WF IP = 0.0.0.0
237 WF SecMd = A
238 WF SecKy =
239 WF WepKI = 0
240 END
241
242 * */
243
244 memset(response, 0, sizeof(response));
245
246 strncpy(cmd, "<FHGETHUBINFO>", 16);
247 LOGF_DEBUG("CMD <%s>", cmd);
248
249 if (isSimulation())
250 {
251 strncpy(response, "HUB INFO\n", 16);
252 nbytes_read = strlen(response);
253 }
254 else
255 {
256 if ((errcode = tty_write(PortFD, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
257 {
258 tty_error_msg(errcode, errmsg, MAXRBUF);
259 LOGF_ERROR("%s", errmsg);
260 return false;
261 }
262
263 if (!isResponseOK())
264 return false;
265
266 if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
267 {
268 tty_error_msg(errcode, errmsg, MAXRBUF);
269 LOGF_ERROR("%s", errmsg);
270 return false;
271 }
272 }
273
274 if (nbytes_read > 0)
275 {
276 response[nbytes_read - 1] = '\0';
277 LOGF_DEBUG("RES <%s>", response);
278
279 if (strcmp(response, "HUB INFO"))
280 return false;
281 }
282
283 memset(response, 0, sizeof(response));
284
285 // Hub Version
286 if (isSimulation())
287 {
288 strncpy(response, "Hub FVer = 2.0.4\n", 32);
289 nbytes_read = strlen(response);
290 }
291 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
292 {
293 tty_error_msg(errcode, errmsg, MAXRBUF);
294 LOGF_ERROR("%s", errmsg);
295 return false;
296 }
297 response[nbytes_read - 1] = '\0';
298 LOGF_DEBUG("RES <%s>", response);
299
300 int rc = sscanf(response, "%15[^=]=%15[^\n]s", key, text);
301 if (rc == 2)
302 {
303 HubTP.s = IPS_OK;
304 IUSaveText(&HubT[0], text);
305 IDSetText(&HubTP, nullptr);
306
307 //Save locally the Version of the firmware's Hub
308 snprintf(version, sizeof(version), "%s", text);
309
310 LOGF_DEBUG("Text = %s, Key = %s", text, key);
311 }
312 else if (rc != 1)
313 return false;
314
315 memset(response, 0, sizeof(response));
316 memset(text, 0, sizeof(text));
317
318 // Sleeping status
319 if (isSimulation())
320 {
321 strncpy(response, "Sleeping = 0\n", 16);
322 nbytes_read = strlen(response);
323 }
324 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
325 {
326 tty_error_msg(errcode, errmsg, MAXRBUF);
327 LOGF_ERROR("%s", errmsg);
328 return false;
329 }
330 response[nbytes_read - 1] = '\0';
331 LOGF_DEBUG("RES <%s>", response);
332
333 rc = sscanf(response, "%15[^=]=%s", key, text);
334 if (rc == 2)
335 {
336 HubTP.s = IPS_OK;
337 IUSaveText(&HubT[1], text);
338 IDSetText(&HubTP, nullptr);
339
340 LOGF_DEBUG("Text = %s, Key = %s", text, key);
341 }
342 else if (rc != 1)
343 return false;
344
345 memset(response, 0, sizeof(response));
346 memset(text, 0, sizeof(text));
347
348 // Wired IP address
349 if (isSimulation())
350 {
351 strncpy(response, "Wired IP = 169.168.1.10\n", 32);
352 nbytes_read = strlen(response);
353 }
354 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
355 {
356 tty_error_msg(errcode, errmsg, MAXRBUF);
357 LOGF_ERROR("%s", errmsg);
358 return false;
359 }
360 response[nbytes_read - 1] = '\0';
361 LOGF_DEBUG("RES <%s>", response);
362
363 rc = sscanf(response, "%15[^=]=%s", key, text);
364 if (rc == 2)
365 {
366 WiredTP.s = IPS_OK;
367 IUSaveText(&WiredT[0], text);
368 IDSetText(&WiredTP, nullptr);
369
370 LOGF_DEBUG("Text = %s, Key = %s", text, key);
371 }
372 else if (rc != 1)
373 return false;
374
375 memset(response, 0, sizeof(response));
376 memset(text, 0, sizeof(text));
377
378 // DHCP on/off
379 if (isSimulation())
380 {
381 strncpy(response, "DHCPisOn = 1\n", 32);
382 nbytes_read = strlen(response);
383 }
384 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
385 {
386 tty_error_msg(errcode, errmsg, MAXRBUF);
387 LOGF_ERROR("%s", errmsg);
388 return false;
389 }
390 response[nbytes_read - 1] = '\0';
391 LOGF_DEBUG("RES <%s>", response);
392
393 rc = sscanf(response, "%15[^=]=%15[^\n]s", key, text);
394 if (rc == 2)
395 {
396 WiredTP.s = IPS_OK;
397 IUSaveText(&WiredT[1], text);
398 IDSetText(&WiredTP, nullptr);
399
400 LOGF_DEBUG("Text = %s, Key = %s", text, key);
401 }
402 else if (rc != 1)
403 return false;
404
405 memset(response, 0, sizeof(response));
406 memset(text, 0, sizeof(text));
407
408 // Is WIFI module present
409 if (isSimulation())
410 {
411 strncpy(response, "WF Atchd = 1\n", 32);
412 nbytes_read = strlen(response);
413 }
414 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
415 {
416 tty_error_msg(errcode, errmsg, MAXRBUF);
417 LOGF_ERROR("%s", errmsg);
418 return false;
419 }
420 response[nbytes_read - 1] = '\0';
421 LOGF_DEBUG("RES <%s>", response);
422
423 rc = sscanf(response, "%15[^=]=%s", key, text);
424 if (rc == 2)
425 {
426 WifiTP.s = IPS_OK;
427 IUSaveText(&WifiT[0], text);
428
429 LOGF_DEBUG("Text = %s, Key = %s", text, key);
430 }
431 else if (rc != 1)
432 return false;
433
434 memset(response, 0, sizeof(response));
435 memset(text, 0, sizeof(text));
436
437 // Is WIFI connected
438 if (isSimulation())
439 {
440 strncpy(response, "WF Conn = 1\n", 32);
441 nbytes_read = strlen(response);
442 }
443 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
444 {
445 tty_error_msg(errcode, errmsg, MAXRBUF);
446 LOGF_ERROR("%s", errmsg);
447 return false;
448 }
449 response[nbytes_read - 1] = '\0';
450 LOGF_DEBUG("RES <%s>", response);
451
452 rc = sscanf(response, "%15[^=]=%s", key, text);
453 if (rc == 2)
454 {
455 WifiTP.s = IPS_OK;
456 IUSaveText(&WifiT[1], text);
457
458 LOGF_DEBUG("Text = %s, Key = %s", text, key);
459 }
460 else if (rc != 1)
461 return false;
462
463 memset(response, 0, sizeof(response));
464 memset(text, 0, sizeof(text));
465
466 // WIFI Version firmware
467 if (isSimulation())
468 {
469 strncpy(response, "WF FVer = 1.0.0\n", 32);
470 nbytes_read = strlen(response);
471 }
472 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
473 {
474 tty_error_msg(errcode, errmsg, MAXRBUF);
475 LOGF_ERROR("%s", errmsg);
476 return false;
477 }
478 response[nbytes_read - 1] = '\0';
479 LOGF_DEBUG("RES <%s>", response);
480
481 rc = sscanf(response, "%15[^=]=%s", key, text);
482 if (rc == 2)
483 {
484 WifiTP.s = IPS_OK;
485 IUSaveText(&WifiT[2], text);
486
487 LOGF_DEBUG("Text = %s, Key = %s", text, key);
488 }
489 else if (rc != 1)
490 return false;
491
492 memset(response, 0, sizeof(response));
493 memset(text, 0, sizeof(text));
494
495 // WIFI OK
496 if (isSimulation())
497 {
498 strncpy(response, "WF FV OK = 1\n", 32);
499 nbytes_read = strlen(response);
500 }
501 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
502 {
503 tty_error_msg(errcode, errmsg, MAXRBUF);
504 LOGF_ERROR("%s", errmsg);
505 return false;
506 }
507 response[nbytes_read - 1] = '\0';
508 LOGF_DEBUG("RES <%s>", response);
509
510 rc = sscanf(response, "%15[^=]=%s", key, text);
511 if (rc == 2)
512 {
513 WifiTP.s = IPS_OK;
514 IUSaveText(&WifiT[3], text);
515
516 LOGF_DEBUG("Text = %s, Key = %s", text, key);
517 }
518 else if (rc != 1)
519 return false;
520
521 memset(response, 0, sizeof(response));
522 memset(text, 0, sizeof(text));
523
524 // WIFI SSID
525 if (isSimulation())
526 {
527 strncpy(response, "WF SSID = FocusLynxConfig\n", 32);
528 nbytes_read = strlen(response);
529 }
530 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
531 {
532 tty_error_msg(errcode, errmsg, MAXRBUF);
533 LOGF_ERROR("%s", errmsg);
534 return false;
535 }
536 response[nbytes_read - 1] = '\0';
537 LOGF_DEBUG("RES <%s>", response);
538
539 rc = sscanf(response, "%15[^=]=%s", key, text);
540 if (rc == 2)
541 {
542 WifiTP.s = IPS_OK;
543 IUSaveText(&WifiT[4], text);
544
545 LOGF_DEBUG("Text = %s, Key = %s", text, key);
546 }
547 else if (rc != 1)
548 return false;
549
550 memset(response, 0, sizeof(response));
551 memset(text, 0, sizeof(text));
552
553 // WIFI IP address
554 if (isSimulation())
555 {
556 strncpy(response, "WF IP = 192.168.1.11\n", 32);
557 nbytes_read = strlen(response);
558 }
559 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
560 {
561 tty_error_msg(errcode, errmsg, MAXRBUF);
562 LOGF_ERROR("%s", errmsg);
563 return false;
564 }
565 response[nbytes_read - 1] = '\0';
566 LOGF_DEBUG("RES <%s>", response);
567
568 rc = sscanf(response, "%15[^=]=%s", key, text);
569 if (rc == 2)
570 {
571 WifiTP.s = IPS_OK;
572 IUSaveText(&WifiT[5], text);
573
574 LOGF_DEBUG("Text = %s, Key = %s", text, key);
575 }
576 else if (rc != 1)
577 return false;
578
579 memset(response, 0, sizeof(response));
580 memset(text, 0, sizeof(text));
581
582 // WIFI Security mode
583 if (isSimulation())
584 {
585 strncpy(response, "WF SecMd = A\n", 32);
586 nbytes_read = strlen(response);
587 }
588 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
589 {
590 tty_error_msg(errcode, errmsg, MAXRBUF);
591 LOGF_ERROR("%s", errmsg);
592 return false;
593 }
594 response[nbytes_read - 1] = '\0';
595 LOGF_DEBUG("RES <%s>", response);
596
597 rc = sscanf(response, "%15[^=]= %s", key, text);
598 if (rc == 2)
599 {
600 WifiTP.s = IPS_OK;
601 IUSaveText(&WifiT[6], text);
602
603 LOGF_DEBUG("Text = %s, Key = %s", text, key);
604 }
605 else if (rc != 1)
606 return false;
607
608 memset(response, 0, sizeof(response));
609 memset(text, 0, sizeof(text));
610
611 // WF Security key
612 if (isSimulation())
613 {
614 strncpy(response, "WF SecKy =\n", 32);
615 nbytes_read = strlen(response);
616 }
617 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
618 {
619 tty_error_msg(errcode, errmsg, MAXRBUF);
620 LOGF_ERROR("%s", errmsg);
621 return false;
622 }
623 response[nbytes_read - 1] = '\0';
624 LOGF_DEBUG("RES <%s>", response);
625
626 rc = sscanf(response, "%15[^=]=%s", key, text);
627 if (rc == 2)
628 {
629 WifiTP.s = IPS_OK;
630 IUSaveText(&WifiT[7], text);
631
632 LOGF_DEBUG("Text = %s, Key = %s", text, key);
633 }
634 else if (rc != 1)
635 return false;
636
637 memset(response, 0, sizeof(response));
638 memset(text, 0, sizeof(text));
639
640 // WIFI Wep
641 if (isSimulation())
642 {
643 strncpy(response, "WF WepKI = 0\n", 32);
644 nbytes_read = strlen(response);
645 }
646 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
647 {
648 tty_error_msg(errcode, errmsg, MAXRBUF);
649 LOGF_ERROR("%s", errmsg);
650 return false;
651 }
652 response[nbytes_read - 1] = '\0';
653 LOGF_DEBUG("RES <%s>", response);
654
655 rc = sscanf(response, "%15[^=]=%s", key, text);
656 if (rc == 2)
657 {
658 WifiTP.s = IPS_OK;
659 IUSaveText(&WifiT[8], text);
660
661 LOGF_DEBUG("Text = %s, Key = %s", text, key);
662 }
663 else if (rc != 1)
664 return false;
665
666 memset(response, 0, sizeof(response));
667 memset(text, 0, sizeof(text));
668
669 // Set the light to ILDE if no module WIFI detected
670 if (!strcmp(WifiT[0].text, "0"))
671 {
672 LOGF_INFO("Wifi module = %s", WifiT[0].text);
673 WifiTP.s = IPS_IDLE;
674 }
675 IDSetText(&WifiTP, nullptr);
676
677 // END is reached
678 if (isSimulation())
679 {
680 strncpy(response, "END\n", 16);
681 nbytes_read = strlen(response);
682 }
683 else if ( (errcode = tty_read_section(PortFD, response, 0xA, LYNXFOCUS_TIMEOUT, &nbytes_read)) != TTY_OK)
684 {
685 tty_error_msg(errcode, errmsg, MAXRBUF);
686 LOGF_ERROR("%s", errmsg);
687 return false;
688 }
689
690 if (nbytes_read > 0)
691 {
692 response[nbytes_read - 1] = '\0';
693
694 // Display the response to be sure to have read the complete TTY Buffer.
695 LOGF_DEBUG("RES <%s>", response);
696
697 if (strcmp(response, "END"))
698 return false;
699 }
700
701 tcflush(PortFD, TCIFLUSH);
702
704
705 int a, b, c, temp;
706 temp = getVersion(&a, &b, &c);
707 if (temp != 0)
708 LOGF_INFO("Version major: %d, minor: %d, subversion: %d", a, b, c);
709 else
710 LOG_INFO("Couldn't get version information");
711
712 return true;
713}
714
715/************************************************************************************
716 *
717* ***********************************************************************************/
719{
721 // Set the simultation mode on F1 as selected by the user
722 lynxDriveF2->setSimulation(enable);
723}
724
725/************************************************************************************
726 *
727* ***********************************************************************************/
729{
731 // Set the Debug mode on F2 as selected by the user in EKOS
732 lynxDriveF2->setDebug(enable);
733}
734
735/************************************************************************************
736 *
737* ***********************************************************************************/
738void FocusLynxF1::setDebug(bool enable)
739{
740 // Call by F2 to set the Debug option
741 // INDI::DefaultDevice::setDebug(enable);
742 INDI_UNUSED(enable);
743}
744
745/************************************************************************************
746*
747* Second Focuser (F2)
748*
749*************************************************************************************/
750
751/************************************************************************************
752 *
753* ***********************************************************************************/
754FocusLynxF2::FocusLynxF2(const char *target)
755{
756 setFocusTarget(target);
757 // set the focuser name to a fixed value to ensure that both focusers are visible
759
760 // The second focuser has no direct communication with the hub
762}
763/************************************************************************************
764 *
765* ***********************************************************************************/
769
770/**************************************************************************************
771*
772***************************************************************************************/
774{
776 // Remove from F2 to avoid confusion, already present on F1
777 deleteProperty("SIMULATION");
778 // deleteProperty("POLLING_PERIOD");
779 return true;
780}
781
782/************************************************************************************
783 *
784* ***********************************************************************************/
786{
787 return FOCUSNAMEF2;
788}
789
790/************************************************************************************
791 *
792* ***********************************************************************************/
794/* Override of connect() function
795 * different for F2 or F1 focuser
796 * F2 don't connect himself to the hub
797 */
798{
799 configurationComplete = false;
800
801 if (!lynxDriveF1->isConnected())
802 {
803 if (!lynxDriveF1->Connect())
804 {
805 LOG_INFO("Focus F1 should be connected before try to connect F2");
806 return false;
807 }
808 lynxDriveF1->setConnected(true, IPS_OK);
809 lynxDriveF1->updateProperties();
810 }
811 PortFD = lynxDriveF1->getPortFD(); //Get the socket descriptor open by focuser F1 connect()
812 LOGF_INFO("F2 PortFD : %d", PortFD);
813
814 if (ack())
815 {
816 LOG_INFO("FocusLynx is online. Getting focus parameters...");
817 // as DefaultDevice::Connect() is not involved, initiate the timer.
819 return true;
820 }
821
822 LOG_INFO("Error retrieving data from FocusLynx, please ensure FocusLynx controller is powered and the port is correct.");
823 return false;
824}
825
826/************************************************************************************
827 *
828* ***********************************************************************************/
830{
831 // If we disconnect F2, No socket to close, set local PortFD to -1
832 PortFD = -1;
833 LOGF_INFO("%s is offline.", getDeviceName());
834 LOGF_INFO("Value of F2 PortFD = %d", PortFD);
835 return true;
836}
837
838/************************************************************************************
839 *
840* ***********************************************************************************/
842{
843 if (isConnected())
844 {
845 setConnected(false, IPS_IDLE);
847 }
848
849 // When called by F1, the PortFD should be -1; For debug purposes
850 PortFD = lynxDriveF1->getPortFD();
851 LOGF_INFO("Remote disconnection: %s is offline.", getDeviceName());
852 LOGF_INFO("Value of F2 PortFD = %d", PortFD);
853 return true;
854}
855
856/************************************************************************************
857 *
858* ***********************************************************************************/
860{
861 // call by F2 to set the Simulation option
863}
864
865/************************************************************************************
866 *
867* ***********************************************************************************/
869{
871 // Set the Debug mode on F1 as selected by the user
872 //lynxDriveF1->setDebug(enable);
873}
874
875/************************************************************************************
876 *
877* ***********************************************************************************/
878void FocusLynxF2::setDebug(bool enable)
879{
880 // Call by F1 to set the Debug option via EKOS
882}
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
void setDefaultPort(uint32_t addressPort)
int getPortFD() const
INumberVectorProperty LedNP
virtual int getVersion(int *major, int *minor, int *sub)
bool configurationComplete
void setFocusTarget(const char *target)
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
int getPortFD()
virtual void setDebug(bool enable)
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool Disconnect() override
Disconnect from device.
FocusLynxF1(const char *target)
Definition focuslynx.cpp:44
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
Definition focuslynx.cpp:71
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
const char * getDefaultName() override
virtual void simulationTriggered(bool enable) override
Inform driver that the simulation option was triggered. This function is called after setSimulation i...
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool RemoteDisconnect()
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
FocusLynxF2(const char *target)
virtual void setDebug(bool enable)
virtual void setSimulation(bool enable)
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
const char * getDefaultName() override
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool Disconnect() override
Disconnect from device.
bool isConnected() const
void setDeviceName(const char *dev)
Set the device name.
void setSimulation(bool enable)
Toggle driver simulation status A driver can run in simulation mode if Simulation option is enabled b...
virtual bool Disconnect()
Disconnect from device.
virtual void setConnected(bool status, IPState state=IPS_OK, const char *msg=nullptr)
Set connection switch status in the client.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
virtual void simulationTriggered(bool enable)
Inform driver that the simulation option was triggered. This function is called after setSimulation i...
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
void setDebug(bool enable)
Toggle driver debug status A driver can be more verbose if Debug option is enabled by the client.
bool isSimulation() const
virtual void debugTriggered(bool enable)
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
Connection::Interface * getActiveConnection()
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
virtual bool Connect()
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Connection::TCP * tcpConnection
Connection::Serial * serialConnection
void setSupportedConnections(const uint8_t &value)
#define FOCUSNAMEF2
Definition focuslynx.h:25
#define FOCUSNAMEF1
Definition focuslynx.h:24
#define HUB_SETTINGS_TAB
#define LYNXFOCUS_TIMEOUT
@ IP_RO
Definition indiapi.h:182
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Definition indicom.c:653
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
Definition indicom.c:418
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
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:509
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
Definition indidevapi.c:44
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
Definition indidevapi.c:416
#define INDI_UNUSED(x)
Definition indidevapi.h:132
#define MAXRBUF
Definition indidriver.c:52
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#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
uint8_t cmd[4]
Definition pwc-ioctl.h:2
char name[MAXINDINAME]
Definition indiapi.h:321
char name[MAXINDINAME]
Definition indiapi.h:248