Instrument Neutral Distributed Interface INDI 2.2.5
indi_astrolink4.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2019 astrojolo.com
3 .
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7 .
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12 .
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#ifndef ASTROLINK4_H
20#define ASTROLINK4_H
21
22#include <string>
23#include <iostream>
24#include <stdio.h>
25#include <unistd.h>
26#include <fcntl.h>
27#include <termios.h>
28#include <memory>
29#include <regex>
30#include <cstring>
31#include <map>
32#include <sstream>
33
34#include <defaultdevice.h>
38
39#define Q_STEPPER_POS 1
40#define Q_STEPS_TO_GO 2
41#define Q_CURRENT 3
42#define Q_SENS1_TYPE 4
43#define Q_SENS1_TEMP 5
44#define Q_SENS1_HUM 6
45#define Q_SENS1_DEW 7
46#define Q_SENS2_TYPE 8
47#define Q_SENS2_TEMP 9
48#define Q_PWM1 10
49#define Q_PWM2 11
50#define Q_OUT1 12
51#define Q_OUT2 13
52#define Q_OUT3 14
53#define Q_VIN 15
54#define Q_VREG 16
55#define Q_AH 17
56#define Q_WH 18
57#define Q_DC_MOVE 19
58#define Q_COMP_DIFF 20
59#define Q_OP_FLAG 21
60#define Q_OP_VALUE 22
61
62#define U_MAX_POS 1
63#define U_SPEED 2
64#define U_PWMSTOP 3
65#define U_PWMRUN 4
66#define U_ACC 5
67#define U_REVERSED 6
68#define U_STEPPER_MODE 7
69#define U_COMPSENS 8
70#define U_STEPSIZE 9
71#define U_PWMPRESC 10
72#define U_STEPPRESC 11
73#define U_BUZ_ENABLED 12
74#define U_HUM_SENS 13
75#define U_DC_REVERSED 14
76#define U_OUT1_DEF 15
77#define U_OUT2_DEF 16
78#define U_OUT3_DEF 17
79
80#define E_COMP_CYCLE 1
81#define E_COMP_STEPS 2
82#define E_COMP_SENSR 3
83#define E_COMP_AUTO 4
84#define E_COMP_TRGR 5
85
86#define N_AREF_COEFF 1
87#define N_OVER_VOLT 2
88#define N_OVER_AMP 3
89#define N_OVER_TIME 4
90
91namespace Connection
92{
93class Serial;
94}
95
97{
98
99public:
101 virtual bool initProperties() override;
102 virtual bool updateProperties() override;
103
104 virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n) override;
105 virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n) override;
106 virtual bool ISNewText(const char * dev, const char * name, char * texts[], char * names[], int n) override;
107
108protected:
109 virtual const char *getDefaultName() override;
110 virtual void TimerHit() override;
111 virtual bool saveConfigItems(FILE *fp) override;
112 virtual bool sendCommand(const char * cmd, char * res);
113
114 // Focuser Overrides
115 virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
116 virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
117 virtual bool AbortFocuser() override;
118 virtual bool ReverseFocuser(bool enabled) override;
119 virtual bool SyncFocuser(uint32_t ticks) override;
120
121 virtual bool SetFocuserBacklash(int32_t steps) override;
122 virtual bool SetFocuserBacklashEnabled(bool enabled) override;
123 virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
124
125 // Weather Overrides
126 virtual IPState updateWeather() override
127 {
128 return IPS_OK;
129 }
130
131
132private:
133 virtual bool Handshake();
134 int PortFD = -1;
135 Connection::Serial *serialConnection { nullptr };
136 bool updateSettings(const char * getCom, const char * setCom, int index, const char * value);
137 bool updateSettings(const char * getCom, const char * setCom, std::map<int, std::string> values);
138 std::vector<std::string> split(const std::string &input, const std::string &regex);
139 std::string doubleToStr(double val);
140 bool sensorRead();
141 bool setAutoPWM();
142 int32_t calculateBacklash(uint32_t targetTicks);
143 char stopChar { 0xA }; // new line
144 bool backlashEnabled = false;
145 int32_t backlashSteps = 0;
146 bool requireBacklashReturn = false;
147
148 IText PowerControlsLabelsT[3];
149 ITextVectorProperty PowerControlsLabelsTP;
150
151 ISwitch Power1S[2];
152 ISwitchVectorProperty Power1SP;
153 ISwitch Power2S[2];
154 ISwitchVectorProperty Power2SP;
155 ISwitch Power3S[2];
156 ISwitchVectorProperty Power3SP;
157
158 INumber Sensor2N[1];
159 INumberVectorProperty Sensor2NP;
160
161 INumber PWMN[2];
163
164 ISwitch AutoPWMS[2];
165 ISwitchVectorProperty AutoPWMSP;
166
167 INumber PowerDataN[5];
168 INumberVectorProperty PowerDataNP;
169 enum
170 {
171 POW_VIN, POW_VREG, POW_ITOT, POW_AH, POW_WH
172 };
173
174 INumber FocusPosMMN[1];
175 INumberVectorProperty FocusPosMMNP;
176
177 INumber CompensationValueN[1];
178 INumberVectorProperty CompensationValueNP;
179 ISwitch CompensateNowS[1];
180 ISwitchVectorProperty CompensateNowSP;
181
182 INumber FocuserSettingsN[4];
183 INumberVectorProperty FocuserSettingsNP;
184 enum
185 {
186 FS_SPEED, FS_STEP_SIZE, FS_COMPENSATION, FS_COMP_THRESHOLD
187 };
188 ISwitch FocuserModeS[3];
189 ISwitchVectorProperty FocuserModeSP;
190 enum
191 {
192 FS_MODE_UNI, FS_MODE_BI, FS_MODE_MICRO
193 };
194
195 ISwitch FocuserCompModeS[2];
196 ISwitchVectorProperty FocuserCompModeSP;
197 enum
198 {
199 FS_COMP_AUTO, FS_COMP_MANUAL
200 };
201
202 ISwitch FocuserManualS[2];
203 ISwitchVectorProperty FocuserManualSP;
204 enum
205 {
206 FS_MANUAL_ON, FS_MANUAL_OFF
207 };
208
209 ISwitch PowerDefaultOnS[3];
210 ISwitchVectorProperty PowerDefaultOnSP;
211
212 ISwitch AutoPWMDefaultOnS[2];
213 ISwitchVectorProperty AutoPWMDefaultOnSP;
214
215 INumber OtherSettingsN[4];
216 INumberVectorProperty OtherSettingsNP;
217 enum
218 {
219 SET_AREF_COEFF, SET_OVER_TIME, SET_OVER_VOLT, SET_OVER_AMP
220 };
221
222 INumber DCFocTimeN[2];
223 INumberVectorProperty DCFocTimeNP;
224 enum
225 {
226 DC_PERIOD, DC_PWM
227 };
228
229 ISwitch DCFocDirS[2];
230 ISwitchVectorProperty DCFocDirSP;
231
232 ISwitch DCFocAbortS[1];
233 ISwitchVectorProperty DCFocAbortSP;
234
235 ISwitch BuzzerS[1];
236 ISwitchVectorProperty BuzzerSP;
237
238 static constexpr const char *POWER_TAB {"Power"};
239 static constexpr const char *ENVIRONMENT_TAB {"Environment"};
240 static constexpr const char *SETTINGS_TAB {"Settings"};
241 static constexpr const char *DCFOCUSER_TAB {"DC Focuser"};
242};
243
244#endif
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Provides interface to implement focuser functionality.
Provides interface to implement weather reporting and safety monitoring functionality.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Set Focuser Maximum position limit in the hardware.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
Focuser interface.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool sendCommand(const char *cmd, char *res)
Serial commands.
virtual bool initProperties() override
Overrides.
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
IndiAstrolink4()
Constructor.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual const char * getDefaultName() override
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
@ IPS_OK
Definition indiapi.h:160
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34
uint8_t cmd[4]
Definition pwc-ioctl.h:2
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244