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