-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindi_ipx800.cpp
1162 lines (991 loc) · 39.7 KB
/
indi_ipx800.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
This file is part of the IPX800 INDI Driver.
A driver for the IPX800 (GCE Electronics - https://www.gce-electronics.com)
Copyright (C) 2024 Arnaud Dupont ([email protected])
IPX800 INDI Driver is free software : you can redistribute it
and / or modify it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
IPX800 INDI Driver is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with IPX800 INDI Driver. If not, see
< http : //www.gnu.org/licenses/>.
This driver is adapted from RollOff ino drivers developped by Jasem Mutlaq.
The main purpose of this driver is to connect to IPX to driver, communicate, and manage
opening and closing of roof.
It is able to read IPX800 digital datas to check status and position of the roof.
User can select, partially, for this first release, how IPX 800 is configured
*******************************************************************************/
#include "indi_ipx800.h"
#include "indicom.h"
#include "config.h"
#include "connectionplugins/connectiontcp.h"
#include <cmath>
#include <cstring>
#include <ctime>
#include <memory>
#include <stdlib.h>
#include <stdio.h>
#include <cstdlib>
#include <string.h>
#include <algorithm>
#include <chrono>
#include <thread>
#include <functional>
#include <regex>
//Network related includes:
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <unistd.h>
#define DEFAULT_POLLING_TIMER 2000
// Read only
#define ROOF_OPENED_SWITCH 0
#define ROOF_CLOSED_SWITCH 1
// Write only
#define ROOF_OPEN_RELAY "OPEN"
#define ROOF_CLOSE_RELAY "CLOSE"
#define ROOF_ABORT_RELAY "ABORT"
// Rollfino
#define INACTIVE_STATUS 5
// We declare an auto pointer to ipx800.
std::unique_ptr<Ipx800> ipx800(new Ipx800());
void ISPoll(void *p);
/*************************************************************************/
/** Constructor **/
/*************************************************************************/
Ipx800::Ipx800() : INDI::InputInterface(this), INDI::OutputInterface(this)
{
Roof_Status = UNKNOWN_STATUS;
Mount_Status = NONE_PARKED;
setVersion(IPX800_VERSION_MAJOR,IPX800_VERSION_MINOR);
}
/************************************************************************************
*
************************************************************************************/
bool Ipx800::initProperties()
{
LOG_INFO("Starting device...");
INDI::DefaultDevice::initProperties();
INDI::InputInterface::initProperties("Inputs&Outputs", DIGITAL_INTPUTS, 0, "Digital");
INDI::OutputInterface::initProperties("Inputs&Outputs", RELAYS_OUTPUTS, "Relay");
// SetParkDataType(PARK_NONE);
//addDebugControl();
addAuxControls(); // This is for standard controls not the local auxiliary switch
addConfigurationControl();
//Rolling list of possible functions managed by relays
IUFillSwitch(&RelaisInfoS[0], "Unused", "",ISS_ON);
IUFillSwitch(&RelaisInfoS[1], "Roof Engine Power", "", ISS_OFF);
IUFillSwitch(&RelaisInfoS[2], "Telescope Ventilation", "", ISS_OFF);
IUFillSwitch(&RelaisInfoS[3], "Heating Resistor 1", "", ISS_OFF);
IUFillSwitch(&RelaisInfoS[4], "Heating Resistor 2", "", ISS_OFF);
IUFillSwitch(&RelaisInfoS[5], "Roof Control Command", "", ISS_OFF);
IUFillSwitch(&RelaisInfoS[6], "Mount Power Supply", "", ISS_OFF);
IUFillSwitch(&RelaisInfoS[7], "Camera Power Supply ", "", ISS_OFF);
IUFillSwitch(&RelaisInfoS[8], "Other Power Supply 1", "", ISS_OFF);
IUFillSwitch(&RelaisInfoS[9], "Other Power Supply 2", "", ISS_OFF);
IUFillSwitch(&RelaisInfoS[10], "Other Power Supply 3", "", ISS_OFF);
//set default value of each relay
for(int i=0;i<11;i++)
{
Relais1InfoS[i] = RelaisInfoS[i];
Relais2InfoS[i] = RelaisInfoS[i];
Relais3InfoS[i] = RelaisInfoS[i];
Relais4InfoS[i] = RelaisInfoS[i];
Relais5InfoS[i] = RelaisInfoS[i];
Relais6InfoS[i] = RelaisInfoS[i];
Relais7InfoS[i] = RelaisInfoS[i];
Relais8InfoS[i] = RelaisInfoS[i];
}
//creation du selecteur de configuration des relais
IUFillSwitchVector(&RelaisInfoSP[0], Relais1InfoS, 11, getDeviceName(), "RELAY_1_CONFIGURATION", "Relay 1", RELAYS_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaisInfoSP[1], Relais2InfoS, 11, getDeviceName(), "RELAY_2_CONFIGURATION", "Relay 2", RELAYS_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaisInfoSP[2], Relais3InfoS, 11, getDeviceName(), "RELAY_3_CONFIGURATION", "Relay 3", RELAYS_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaisInfoSP[3], Relais4InfoS, 11, getDeviceName(), "RELAIS_4_CONFIGURATION", "Relay 4", RELAYS_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaisInfoSP[4], Relais5InfoS,11, getDeviceName(), "RELAIS_5_CONFIGURATION", "Relay 5", RELAYS_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaisInfoSP[5], Relais6InfoS, 11, getDeviceName(), "RELAIS_6_CONFIGURATION", "Relay 6", RELAYS_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaisInfoSP[6], Relais7InfoS,11, getDeviceName(), "RELAIS_7_CONFIGURATION", "Relay 7", RELAYS_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaisInfoSP[7], Relais8InfoS, 11, getDeviceName(), "RELAIS_8_CONFIGURATION", "Relay 8", RELAYS_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
//creation liste deroulante entrees discretes
IUFillSwitch(&DigitalInputS[0], "Unused", "",ISS_ON);
IUFillSwitch(&DigitalInputS[1], "DEC Axis Parked", "", ISS_OFF);
IUFillSwitch(&DigitalInputS[2], "RA Axis Parked", "", ISS_OFF);
IUFillSwitch(&DigitalInputS[3], "Roof Opened", "", ISS_OFF);
IUFillSwitch(&DigitalInputS[4], "Roof Closed", "", ISS_OFF);
IUFillSwitch(&DigitalInputS[5], "Roof Engine Supplied", "", ISS_OFF);
IUFillSwitch(&DigitalInputS[6], "Raspberry Power Supplied", "", ISS_OFF);
IUFillSwitch(&DigitalInputS[7], "Main PC Supplied", "", ISS_OFF);
IUFillSwitch(&DigitalInputS[8], "Other Digital 1", "", ISS_OFF);
IUFillSwitch(&DigitalInputS[9], "Other Digital 2", "", ISS_OFF);
//set default value of each digital input
for(int i=0;i<10;i++)
{
Digital1InputS[i] = DigitalInputS[i];
Digital2InputS[i] = DigitalInputS[i];
Digital3InputS[i] = DigitalInputS[i];
Digital4InputS[i] = DigitalInputS[i];
Digital5InputS[i] = DigitalInputS[i];
Digital6InputS[i] = DigitalInputS[i];
Digital7InputS[i] = DigitalInputS[i];
Digital8InputS[i] = DigitalInputS[i];
}
//creation du selecteur de configuration des entrées discretes
IUFillSwitchVector(&DigitalInputSP[0], Digital1InputS, 10, getDeviceName(), "DIGITAL_1_CONFIGURATION", "Digital 1", DIGITAL_INPUT_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitalInputSP[1], Digital2InputS, 10, getDeviceName(), "DIGITAL_2_CONFIGURATION", "Digital 2", DIGITAL_INPUT_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitalInputSP[2], Digital3InputS, 10, getDeviceName(), "DIGITAL_3_CONFIGURATION", "Digital 3", DIGITAL_INPUT_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitalInputSP[3], Digital4InputS, 10, getDeviceName(), "DIGITAL_4_CONFIGURATION", "Digital 4", DIGITAL_INPUT_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitalInputSP[4], Digital5InputS, 10, getDeviceName(), "DIGITAL_5_CONFIGURATION", "Digital 5", DIGITAL_INPUT_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitalInputSP[5], Digital6InputS, 10, getDeviceName(), "DIGITAL_6_CONFIGURATION", "Digital 6", DIGITAL_INPUT_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitalInputSP[6], Digital7InputS, 10, getDeviceName(), "DIGITAL_7_CONFIGURATION", "Digital 7", DIGITAL_INPUT_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitalInputSP[7], Digital8InputS, 10, getDeviceName(), "DIGITAL_8_CONFIGURATION", "Digital 8", DIGITAL_INPUT_CONFIGURATION_TAB,
IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
//TO Manage in a next release
//IUFillText(&LoginPwdT[0], "LOGIN_VAL", "Login", "");
//IUFillText(&LoginPwdT[1], "PASSWD_VAL", "Password", "");
//IUFillTextVector(&LoginPwdTP, LoginPwdT, 2, getDeviceName(), "ACCESS_IPX", "IPX Access", OPTIONS_TAB, IP_RW, 0, IPS_IDLE);
//defineProperty(&LoginPwdTP);
//
//enregistrement des onglets de configurations
for(int i=0;i<8;i++)
{
defineProperty(&RelaisInfoSP[i]);
defineProperty(&DigitalInputSP[i]);
}
///////////////////////////////////////////////
//Page de presentation de l'état des relais
///////////////////////////////////////////////
//char name[3] = 'yyy', nameM[3] = 'xxx';
const char *name = "";
const char *nameM = "";
for(int i=0;i<2;i++)
{
if (i ==0) {
name = "On";
nameM = "ON"; }
else if (i ==1) {
name = "Off";
nameM = "OFF";
}
else {
LOG_ERROR ("Initialization Error...");
return false;
}
IUFillSwitch(&Relay1StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Relay2StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Relay3StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Relay4StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Relay5StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Relay6StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Relay7StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Relay8StateS[i], name, nameM, ISS_OFF);
}
IUFillSwitchVector(&RelaysStatesSP[0], Relay1StateS, 2, getDeviceName(), "RELAY_1_STATE", "Relay 1", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaysStatesSP[1], Relay2StateS, 2, getDeviceName(), "RELAY_2_STATE", "Relay 2", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaysStatesSP[2], Relay3StateS, 2, getDeviceName(), "RELAY_3_STATE", "Relay 3", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaysStatesSP[3], Relay4StateS, 2, getDeviceName(), "RELAY_4_STATE", "Relay 4", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaysStatesSP[4], Relay5StateS, 2, getDeviceName(), "RELAY_5_STATE", "Relay 5", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaysStatesSP[5], Relay6StateS, 2, getDeviceName(), "RELAY_6_STATE", "Relay 6", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaysStatesSP[6], Relay7StateS, 2, getDeviceName(), "RELAY_7_STATE", "Relay 7", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&RelaysStatesSP[7], Relay8StateS, 2, getDeviceName(), "RELAY_8_STATE", "Relay 8", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
//////////////////////////////////////////////////////////
//page de presentation de l'état des entrées discretes
//////////////////////////////////////////////////////////
for(int i=0;i<2;i++)
{
if (i ==0) {
name = "On";
nameM = "ON"; }
else if (i ==1) {
name = "Off";
nameM = "OFF";
}
else {
LOG_ERROR ("Initialization Error...");
return false;
}
IUFillSwitch(&Digit1StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Digit2StateS[i], name, nameM,ISS_OFF);
IUFillSwitch(&Digit3StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Digit4StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Digit5StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Digit6StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Digit7StateS[i], name, nameM, ISS_OFF);
IUFillSwitch(&Digit8StateS[i], name, nameM,ISS_OFF);
}
IUFillSwitchVector(&DigitsStatesSP[0], Digit1StateS, 2, getDeviceName(), "DIGIT_1_STATE", "Digital 1", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitsStatesSP[1], Digit2StateS, 2, getDeviceName(), "DIGIT_2_STATE", "Digital 2", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitsStatesSP[2], Digit3StateS, 2, getDeviceName(), "DIGIT_3_STATE", "Digital 3", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitsStatesSP[3], Digit4StateS, 2, getDeviceName(), "DIGIT_4_STATE", "Digital 4", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitsStatesSP[4], Digit5StateS, 2, getDeviceName(), "DIGIT_5_STATE", "Digital 5", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitsStatesSP[5], Digit6StateS, 2, getDeviceName(), "DIGIT_6_STATE", "Digital 6", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitsStatesSP[6], Digit7StateS, 2, getDeviceName(), "DIGIT_7_STATE", "Digital 7", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
IUFillSwitchVector(&DigitsStatesSP[7], Digit8StateS, 2, getDeviceName(), "DIGIT_8_STATE", "Digital 8", RAW_DATA_TAB,
IP_RO,ISR_1OFMANY, 60, IPS_IDLE);
// Initialisation des commutateurs ON/OFF
IUFillSwitch(&roofEnginePowerS[0], "POWER_ON", "On", ISS_OFF); // Par défaut sur OFF
IUFillSwitch(&roofEnginePowerS[1], "POWER_OFF", "Off", ISS_ON); // Par défaut sur ON
// Initialisation du vecteur de commutateurs avec ISRVector (type radio)
IUFillSwitchVector(&roofEnginePowerSP, roofEnginePowerS, 2, getDeviceName(),
"ROOF_POWER_MNGT", // Nom interne du vecteur
"Roof Engine Power Mngt", // Label affiché
"Options", // Groupe (onglet Options)
IP_RW, // Permissions (lecture/écriture)
ISR_1OFMANY, // Comportement exclusif (radio buttons)
0, // Timeout (si nécessaire, mettre 0 pour ignorer)
IPS_IDLE); // État initial (inactif)
// Ajouter la propriété à l'onglet OPTIONS_TAB
defineProperty(&roofEnginePowerSP);
// Initialisation des commutateurs ON/OFF
IUFillSwitch(&IPXVersionS[0], "VERSION_3", "V3", ISS_OFF); // Par défaut sur OFF
IUFillSwitch(&IPXVersionS[1], "VERSION_4", "V4", ISS_ON); // Par défaut sur ON
IUFillSwitch(&IPXVersionS[2], "VERSION_5", "V5", ISS_OFF); // Par défaut sur ON
// Initialisation du vecteur de commutateurs avec ISRVector (type radio)
IUFillSwitchVector(&IPXVersionSP, IPXVersionS, 3, getDeviceName(),
"VERSION_SELECTION", // Nom interne du vecteur
"IPX800 Version", // Label affiché
"Main Control", // Groupe (onglet Options)
IP_RO, // Permissions (lecture/écriture)
ISR_1OFMANY, // Comportement exclusif (radio buttons)
0, // Timeout (si nécessaire, mettre 0 pour ignorer)
IPS_IDLE); // État initial (inactif)
// Ajouter la propriété à l'onglet OPTIONS_TAB
defineProperty(&IPXVersionSP);
setDefaultPollingPeriod(DEFAULT_POLLING_TIMER);
tcpConnection = new Connection::TCP(this);
tcpConnection->setConnectionType(Connection::TCP::TYPE_TCP);
tcpConnection->setDefaultHost("192.168.1.1");
tcpConnection->setDefaultPort(666);
LOG_DEBUG("Updating Connection - Handshake");
tcpConnection->registerHandshake([&]()
{
LOG_DEBUG("Updating Connection - Call Handshake");
return Handshake();
}
);
registerConnection(tcpConnection);
return true;
}
bool Ipx800::Handshake()
{
bool status = false;
bool res = false;
if (isSimulation())
{
LOGF_INFO("Connected successfuly to simulated %s.", getDeviceName());
return true;
}
else {
res = readCommand(GetR);
readAnswer();
if (res==false) {
LOG_ERROR("Handshake with IPX800 failed");
return false;
}
else {
LOG_INFO("Handshake with IPX800 successfull");
return true;
}
readAnswer();
if (!checkAnswer())
{
LOG_ERROR("Handshake with IPX800 failed - Wrong answer");
res = false;
}
else {
recordData(GetR);
}
}
return status;
}
void Ipx800::ISGetProperties(const char *dev)
{
INDI::DefaultDevice::ISGetProperties(dev);
}
void ISSnoopDevice(XMLEle *root)
{
ipx800->ISSnoopDevice(root);
}
bool Ipx800::ISSnoopDevice(XMLEle *root)
{
return INDI::DefaultDevice::ISSnoopDevice(root);
}
/********************************************************************************************
** Establish conditions on a connect.
*********************************************************************************************/
bool Ipx800::setupParams()
{
LOG_DEBUG("Setting Params...");
updateObsStatus();
return true;
}
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
ipx800->ISNewSwitch(dev, name, states, names, n);
}
bool Ipx800::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
ISwitch *myRelaisInfoS;
ISwitchVectorProperty myRelaisInfoSP;
ISwitch *myDigitalInputS;
ISwitchVectorProperty myDigitalInputSP;
int currentRIndex, currentDIndex =0;
bool infoSet = false;
// Make sure the call is for our device, and Fonctions Tab are initialized
if(dev != nullptr && !strcmp(dev,getDeviceName()))
{
if (INDI::OutputInterface::processSwitch(dev, name, states, names, n))
return true;
// Vérifie que l'événement concerne le vecteur de commutateurs Roof Engine Power Management - Options Tab
if (strcmp(name, roofEnginePowerSP.name) == 0)
{
// Parcours des commutateurs pour traiter les changements d'état
for (int i = 0; i < n; i++)
{
if (strcmp(names[i], "POWER_ON") == 0)
{
// Si POWER_ON est activé
if (states[i] == ISS_ON)
{
IDMessage(getDeviceName(), "Roof Engine Power Management: ON");
roofEnginePowerS[0].s = ISS_ON;
roofEnginePowerS[1].s = ISS_OFF; // Désactive l'autre switch
roofPowerManagement = true;
}
}
else if (strcmp(names[i], "POWER_OFF") == 0)
{
// Si POWER_OFF est activé
if (states[i] == ISS_ON)
{
IDMessage(getDeviceName(), "Roof Engine Power Management: OFF");
roofEnginePowerS[0].s = ISS_OFF;
roofEnginePowerS[1].s = ISS_ON; // Désactive l'autre switch
roofPowerManagement = false;
}
}
}
// Marque le vecteur de commutateurs comme mis à jour et notifie l'interface
roofEnginePowerSP.s = IPS_OK;
IDSetSwitch(&roofEnginePowerSP, nullptr);
}
for(int i=0;i<8;i++)
{
myRelaisInfoSP = ipx800->getMyRelayVector(i);
myDigitalInputSP = ipx800->getMyDigitsVector(i);
////////////////////////////////////////////////////
// Relay Configuration
////////////////////////////////////////////////////
if (!strcmp(name, myRelaisInfoSP.name))
{
LOGF_DEBUG("Relay function selected - SP : %s", myRelaisInfoSP.name);
IUUpdateSwitch(&myRelaisInfoSP,states,names,n);
myRelaisInfoS = myRelaisInfoSP.sp;
myRelaisInfoSP.s = IPS_OK;
IDSetSwitch(&myRelaisInfoSP,nullptr);
currentRIndex = IUFindOnSwitchIndex(&myRelaisInfoSP);
if (currentRIndex != -1) {
Relay_Fonction_Tab [currentRIndex] = i;
LOGF_DEBUG("Relay fonction index : %d", currentRIndex);
defineProperty(&RelaysStatesSP[i]);}
else
LOG_DEBUG("No On Switches found");
infoSet = true;
return true;
}
////////////////////////////////////////////////////
// Digits Configuration
////////////////////////////////////////////////////
if (!strcmp(name, myDigitalInputSP.name))
{
LOGF_DEBUG("Digital init : %s", myDigitalInputSP.name);
IUUpdateSwitch(&myDigitalInputSP,states,names,n);
myDigitalInputS = myDigitalInputSP.sp;
// myRelaisInfoS[].s = ISS_ON;
myDigitalInputSP.s = IPS_OK;
IDSetSwitch(&myDigitalInputSP,nullptr);
//sauvegarde de la configuration
currentDIndex = IUFindOnSwitchIndex(&myDigitalInputSP);
if (currentDIndex != -1) {
Digital_Fonction_Tab [currentDIndex] = i;
LOGF_DEBUG("Digital Inp. fonction index : %d", currentDIndex);
defineProperty(&DigitsStatesSP[i]);
}
else
LOG_DEBUG("No On Switches found");
infoSet = true;
return true;
}
}
LOG_DEBUG("ISNewSwitch - First Init + UpDate");
updateIPXData();
if (infoSet)
updateObsStatus();
}
return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n);
}
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
{
ipx800->ISNewText(dev, name, texts, names, n);
}
bool Ipx800::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
{
////////////////////////////////////////////////////
// IPX Access - If password protected
// To manage in a next release
////////////////////////////////////////////////////
/*
IText* myLoginT = ipx800->getMyLogin();
ITextVectorProperty myLoginVector = ipx800->getMyLoginVector();
if (dev && !strcmp(name, myLoginVector.name))
{
IUUpdateText(&myLoginVector, texts, names, n);
myLoginVector.s = IPS_OK;
myPasswd = myLoginT[1].text;
myLogin = myLoginT[0].text;
IDSetText(&myLoginVector, nullptr);
LOG_INFO("Password updated");
}
*/
if (INDI::InputInterface::processText(dev, name, texts, names, n))
return true;
if (INDI::OutputInterface::processText(dev, name, texts, names, n))
return true;
return INDI::DefaultDevice::ISNewText(dev, name, texts, names, n);
}
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
{
ipx800->ISNewNumber(dev, name, values, names, n);
}
bool Ipx800::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
{
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
return true;
return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n);
}
///////////////////////////////////////////
// When IPX800 is connected two more tabs appear : Relays Status
// Digital inputs Status
///////////////////////////////////////////
bool Ipx800::Connect()
{
bool status = INDI::DefaultDevice::Connect();
LOG_DEBUG("Connecting to device...");
return status;
}
bool Ipx800::Disconnect()
{
bool status = INDI::DefaultDevice::Disconnect();
return status;
}
const char *Ipx800::getDefaultName()
{
return (const char *)"Ipx800";
}
/////////////////////////////////////////
// Used after connection / Disconnection
/////////////////////////////////////////
bool Ipx800::updateProperties()
{
INDI::DefaultDevice::updateProperties();
LOG_DEBUG("updateProperties - Starting");
///////////////////////////
if (isConnected())
{ // Connect both states tabs
updateIPXData();
//firstFonctionTabInit();
//updateObsStatus();
INDI::InputInterface::updateProperties();
INDI::OutputInterface::updateProperties();
defineProperty(&roofEnginePowerSP);
defineProperty(&IPXVersionSP);
for(int i=0;i<8;i++)
{
defineProperty(&RelaysStatesSP[i]);
//MàJ DomeState
}
for(int i=0;i<8;i++)
{
defineProperty(&DigitsStatesSP[i]);
}
setupParams();
}
else { // Disconnect both "States TAB"
for(int i=0;i<8;i++)
{
deleteProperty(RelaysStatesSP[i].name);
}
for(int i=0;i<8;i++)
{
deleteProperty(DigitsStatesSP[i].name);
}
deleteProperty(roofEnginePowerSP.name);
deleteProperty(IPXVersionSP.name);
}
return true;
}
//////////////////////////////////////////
// ** complete **
//////////////////////////////////////////
void Ipx800::TimerHit()
{
if (!isConnected()) {
return; // No need to reset timer if we are not connected anymore
}
updateIPXData();
SetTimer(getPollingPeriod());
}
//////////////////////////////////////
/* Save conf */
bool Ipx800::saveConfigItems(FILE *fp)
{
INDI::DefaultDevice::saveConfigItems(fp);
//IUSaveConfigText(fp, &LoginPwdTP);
/** sauvegarde de la configuration des relais et entrées discretes **/
////////////////////////////
for(int i=0;i<8;i++)
{
IUSaveConfigSwitch(fp, &RelaisInfoSP[i]);
IUSaveConfigSwitch(fp, &DigitalInputSP[i]);
}
INDI::InputInterface::saveConfigItems(fp);
INDI::OutputInterface::saveConfigItems(fp);
return true;////////
}
//////////////////////////////////////
/* readCommand */
bool Ipx800::readCommand(IPX800_command rCommand) {
bool rc = false;
std::string ipx_url = "";
//int bytesWritten = 0, totalBytes = 0;
switch (rCommand) {
case GetR :
ipx_url = "Get=R";
break;
case GetD :
ipx_url = "Get=D";
break;
default :
{
LOGF_ERROR("readCommand - Unknown Command %s", rCommand);
return false;
}
}
LOGF_DEBUG ("readCommand - Sending %s",ipx_url.c_str());
rc = writeTCP(ipx_url);
return rc;
};
//////////////////////////////////////
/* writeCommand */
bool Ipx800::writeCommand(IPX800_command wCommand, int toSet) {
std::string ipx_url;
std::string number;
bool rc = false;
//int bytesWritten = 0, totalBytes = 0;
if (toSet <10)
number = "0"+ std::to_string(toSet);
else {
number = std::to_string(toSet);
}
switch (wCommand) {
case SetR :
ipx_url = "SetR=" + number ;
LOGF_DEBUG ("Sending Set R %s",number.c_str());
break;
case ClearR :
ipx_url = "ClearR=" + number;
LOGF_DEBUG ("Sending Clear R %s",number.c_str());
break;
default :
{
LOGF_ERROR("Unknown Command %s", wCommand);
return false;
}
}
rc = writeTCP(ipx_url);
return rc;
};
//////////////////////////////////////
/* readAnswer */
// TCP Answer reading
void Ipx800::readAnswer(){
int received = 0;
int bytes, total = 0;
int portFD = tcpConnection->getPortFD();
char tmp[58] = "";
total = 58;
int i = 0;
do {
bytes = read(portFD,tmp+received,total-received);
if (bytes < 0) {
LOGF_ERROR("readAnswer - ERROR reading response from socket : %s", strerror(errno));
//std::this_thread::sleep_for(std::chrono::milliseconds(500));
i++;
if (i>2)
break;
}
else if (bytes == 0) {
LOG_DEBUG("readAnswer : end of stream");
break; }
received+=bytes;
} while (received < total);
LOGF_DEBUG("readAnswer - Longeur reponse : %i", received);
strncpy(tmpAnswer,tmp,8);
LOGF_DEBUG ("readAnswer - Reponse reçue : %s", tmpAnswer);
};
//////////////////////////////////////
/* recordData */
void Ipx800::recordData(IPX800_command recCommand) {
int i = -1;
int tmpDR = UNUSED_DIGIT;
switch (recCommand) {
case GetD :
for (i=0;i<8;i++){
DigitsStatesSP[i].s = IPS_OK;
DigitalInputsSP[i].reset();
if (tmpAnswer[i] == '0') {
LOGF_DEBUG("recordData - Digital Input N° %d is %s",i+1,"OFF");
DigitalInputsSP[i][0].setState(ISS_ON);
DigitsStatesSP[i].sp[0].s = ISS_OFF;
DigitsStatesSP[i].sp[1].s = ISS_ON;
digitalState[i] = false;}
else if(tmpAnswer[i] == '1'){
LOGF_DEBUG("recordData - Digital Input N° %d is %s",i+1,"ON");
DigitalInputsSP[i][1].setState(ISS_ON);
DigitsStatesSP[i].sp[0].s = ISS_ON ;
DigitsStatesSP[i].sp[1].s = ISS_OFF;
digitalState[i] = true;
}
tmpAnswer[i] = ' ';
DigitalInputsSP[i].setState(IPS_OK);
DigitalInputsSP[i].apply();
defineProperty(&DigitsStatesSP[i]);
DigitsStatesSP[i].s = IPS_OK;
IDSetSwitch(&DigitsStatesSP[i], nullptr);
}
for (i=0;i<10;i++) {
tmpDR = Digital_Fonction_Tab[i];
if (tmpDR >= 0) {
if (tmpDR == ROOF_ENGINE_POWERED ) {
DigitalInputsSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]].reset();
if (DigitsStatesSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]].sp[0].s == ISS_OFF) {
LOG_DEBUG("recordData - reversing ROOF_ENGINE_POWERED TO ON");
DigitsStatesSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]].sp[0].s = ISS_ON;
DigitsStatesSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]].sp[1].s = ISS_OFF;
digitalState[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]] = true;
DigitalInputsSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]][1].setState(ISS_ON);}
else {
LOG_DEBUG("recordData - reversing ROOF_ENGINE_POWERED TO OFF");
DigitsStatesSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]].sp[0].s = ISS_OFF;
DigitsStatesSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]].sp[1].s = ISS_ON;
digitalState[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]] = false;
DigitalInputsSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]][0].setState(ISS_ON);}
DigitalInputsSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]].setState(IPS_OK);
DigitalInputsSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]].apply();
defineProperty(&DigitsStatesSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]]);
DigitsStatesSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]].s = IPS_OK;
IDSetSwitch(&DigitsStatesSP[Digital_Fonction_Tab[ROOF_ENGINE_POWERED]], nullptr);
}
else if(tmpDR == RASPBERRY_SUPPLIED) {
DigitalInputsSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]].reset();
if (DigitsStatesSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]].sp[0].s == ISS_OFF) {
LOG_DEBUG("recordData - reversing RASPBERRY_SUPPLIED TO ON");
DigitsStatesSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]].sp[0].s = ISS_ON;
DigitsStatesSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]].sp[1].s = ISS_OFF;
digitalState[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]] = true;
DigitalInputsSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]][1].setState(ISS_ON);}
else {
LOG_DEBUG("recordData - reversing RASPBERRY_SUPPLIED TO OFF");
DigitsStatesSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]].sp[0].s = ISS_OFF;
DigitsStatesSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]].sp[1].s = ISS_ON;
digitalState[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]] = false;
DigitalInputsSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]][0].setState(ISS_ON);}
DigitalInputsSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]].setState(IPS_OK);
DigitalInputsSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]].apply();
defineProperty(&DigitsStatesSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]]);
DigitsStatesSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]].s = IPS_OK;
IDSetSwitch(&DigitsStatesSP[Digital_Fonction_Tab[RASPBERRY_SUPPLIED]], nullptr);
}
else if (tmpDR == MAIN_PC_SUPPLIED) {
DigitalInputsSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]].reset();
if (DigitsStatesSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]].sp[0].s == ISS_OFF) {
LOG_DEBUG("recordData - reversing MAIN_PC_SUPPLIED TO ON");
DigitsStatesSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]].sp[0].s = ISS_ON;
DigitsStatesSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]].sp[1].s = ISS_OFF;
digitalState[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]] = true;
DigitalInputsSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]][1].setState(ISS_ON);}
else {
LOG_DEBUG("recordData - reversing MAIN_PC_SUPPLIED TO OFF");
DigitsStatesSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]].sp[0].s = ISS_OFF;
DigitsStatesSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]].sp[1].s = ISS_ON;
digitalState[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]] = false;
DigitalInputsSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]][0].setState(ISS_ON);}
DigitalInputsSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]].setState(IPS_OK);
DigitalInputsSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]].apply();
defineProperty(&DigitsStatesSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]]);
DigitsStatesSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]].s = IPS_OK;
IDSetSwitch(&DigitsStatesSP[Digital_Fonction_Tab[MAIN_PC_SUPPLIED]], nullptr);
}
}
else {
LOGF_WARN("Wrong Digital ROOF_ENGINE_POWERED initialisation. Now it's = %d",tmpDR);
}
enginePowered = digitalState[Digital_Fonction_Tab [ROOF_ENGINE_POWERED]];
}
break;
case GetR :
for (int i=0;i<8;i++){
RelaysStatesSP[i].s = IPS_OK;
DigitalOutputsSP[i].reset();
if (tmpAnswer[i] == '0') {
LOGF_DEBUG("recordData - Relay N° %d is %s",i+1,"OFF");
RelaysStatesSP[i].sp[0].s = ISS_OFF;
RelaysStatesSP[i].sp[1].s = ISS_ON;
DigitalOutputsSP[i][0].setState(ISS_ON);
//relayState[i]= false;
}
else {
LOGF_DEBUG("recordData - Relay N° %d is %s",i+1,"ON");
RelaysStatesSP[i].sp[0].s = ISS_ON;
RelaysStatesSP[i].sp[1].s = ISS_OFF;
DigitalOutputsSP[i][1].setState(ISS_ON);
//relayState[i]=true;
}
tmpAnswer[i] = ' ';
DigitalOutputsSP[i].setState(IPS_OK);
DigitalOutputsSP[i].apply();
RelaysStatesSP[i].s = IPS_OK;
IDSetSwitch(&RelaysStatesSP[i], nullptr);
//defineProperty(&RelaysStatesSP[i]);
}
break;
default :
LOGF_ERROR("recordData - Unknown Command %s", recCommand);
break;
}
LOG_DEBUG("recordData - Switches States Recorded");
};
//////////////////////////////////////
/* writeTCP Write Command on TCP socket */
bool Ipx800::writeTCP(std::string toSend) {
int bytesWritten = 0, totalBytes = 0;
totalBytes = toSend.length();
int portFD = tcpConnection->getPortFD();
LOGF_DEBUG("writeTCP - Command to send %s", toSend.c_str());
LOGF_DEBUG ("writeTCP - Numéro de socket %i", portFD);
if (!isSimulation()) {
while (bytesWritten < totalBytes)
{
int bytesSent = write(portFD, toSend.c_str(), totalBytes - bytesWritten);
if (bytesSent >= 0)
bytesWritten += bytesSent;
else
{
LOGF_ERROR("writeTCP - Error request to IPX800. %s", strerror(errno));
return false;
}
}
}
LOGF_DEBUG ("writeTCP - bytes to send : %s", toSend.c_str());
LOGF_DEBUG ("writeTCP - Number of bytes sent : %d", bytesWritten);
return true;
}
//////////////////////////////////////
/* updateIPXData */
/* prepare commands to update Inputs Status */
//////////////////////////////////////
bool Ipx800::updateIPXData()
{
bool res = false;
LOG_DEBUG("Updating IPX Data...");
res = UpdateDigitalOutputs();
if (res==false) {
LOG_ERROR("updateIPXData - Send Command GetR failed");
return false;
}
res = UpdateDigitalInputs();
if (res==false) {
LOG_ERROR("updateIPXData - Send Command GetD failed");
return false;
}
return true;
}
//////////////////////////////////////
/* updateObsStatus */
void Ipx800::updateObsStatus()