Instrument Neutral Distributed Interface INDI 2.2.5
indi_astrolink4mini2.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2022 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_DEVICE_CODE 0
40#define Q_FOC1_POS 1
41#define Q_FOC1_TO_GO 2
42#define Q_FOC2_POS 3
43#define Q_FOC2_TO_GO 4
44#define Q_ITOT 5
45#define Q_SENS1_PRESENT 6
46#define Q_SENS1_TEMP 7
47#define Q_SENS1_HUM 8
48#define Q_SENS1_DEW 9
49#define Q_SENS2_PRESENT 10
50#define Q_SENS2_TEMP 11
51#define Q_PWM1 12
52#define Q_PWM2 13
53#define Q_OUT1 14
54#define Q_OUT2 15
55#define Q_OUT3 16
56#define Q_VIN 17
57#define Q_VREG 18
58#define Q_AH 19
59#define Q_WH 20
60#define Q_FOC1_COMP 21
61#define Q_FOC2_COMP 22
62#define Q_OVERTYPE 23
63#define Q_OVERVALUE 24
64#define Q_MLX_TEMP 25
65#define Q_MLX_AUX 26
66#define Q_SENS2_HUM 30
67#define Q_SENS2_DEW 31
68#define Q_SBM_PRESENT 32
69#define Q_SBM 33
70
71#define U_BUZZER 1
72#define U_MANUAL 2
73#define U_FOC1_CUR 3
74#define U_FOC2_CUR 4
75#define U_FOC1_HOLD 5
76#define U_FOC2_HOLD 6
77#define U_FOC1_SPEED 7
78#define U_FOC2_SPEED 8
79#define U_FOC1_ACC 9
80#define U_FOC2_ACC 10
81#define U_FOC1_MODE 11
82#define U_FOC2_MODE 12
83#define U_FOC1_MAX 13
84#define U_FOC2_MAX 14
85#define U_FOC1_REV 15
86#define U_FOC2_REV 16
87#define U_FOC1_STEP 17
88#define U_FOC2_STEP 18
89#define U_FOC1_COMPSTEPS 19
90#define U_FOC2_COMPSTEPS 20
91#define U_FOC_COMP_CYCLE 21
92#define U_FOC1_COMPTRIGGER 22
93#define U_FOC2_COMPTRIGGER 23
94#define U_FOC1_COMPAUTO 24
95#define U_FOC2_COMPAUTO 25
96#define U_PWM_PRESC 26
97#define U_OUT1_DEF 27
98#define U_OUT2_DEF 28
99#define U_OUT3_DEF 29
100#define U_PWM1_DEF 30
101#define U_PWM2_DEF 31
102#define U_HUM_SENSOR 32
103#define U_HUM_START 33
104#define U_HUM_FULL 34
105#define U_TEMP_PRESET 35
106#define U_VREF 36
107#define U_OVERVOLTAGE 37
108#define U_OVERCURRENT 38
109#define U_OVERTIME 39
110#define U_COMPSENSOR 40
111
112namespace Connection
113{
114 class Serial;
115}
116
118{
119
120public:
122 virtual bool initProperties() override;
123 virtual bool updateProperties() override;
124
125 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
126 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
127 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
128
129protected:
130 virtual const char *getDefaultName() override;
131 virtual void TimerHit() override;
132 virtual bool saveConfigItems(FILE *fp) override;
133
134 virtual bool sendCommand(const char *cmd, char *res);
135
136 // Focuser Overrides
137 virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
138 virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
139 virtual bool AbortFocuser() override;
140 virtual bool ReverseFocuser(bool enabled) override;
141 virtual bool SyncFocuser(uint32_t ticks) override;
142
143 virtual bool SetFocuserBacklash(int32_t steps) override;
144 virtual bool SetFocuserBacklashEnabled(bool enabled) override;
145 virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
146
147 // Weather Overrides
148 virtual IPState updateWeather() override
149 {
150 return IPS_OK;
151 }
152
153private:
154 virtual bool Handshake();
155 int PortFD = -1;
156 Connection::Serial *serialConnection{nullptr};
157 char stopChar{0xA}; // new line
158 int focuserIndex {0};
159 int getFindex();
160 void setFindex(int index);
161 bool readDevice();
162 bool updateSettings(const char *getCom, const char *setCom, int index, const char *value);
163 bool updateSettings(const char *getCom, const char *setCom, std::map<int, std::string> values);
164 std::vector<std::string> split(const std::string &input, const std::string &regex);
165 std::string doubleToStr(double val);
166 std::string intToStr(double val);
167
168 INDI::PropertySwitch FocuserSelectSP {2};
169 enum
170 {
171 FOC_SEL_1,
172 FOC_SEL_2
173 };
174
175 INDI::PropertyNumber Focuser1SettingsNP {6};
176 enum
177 {
178 FS1_SPEED,
179 FS1_CURRENT,
180 FS1_HOLD,
181 FS1_STEP_SIZE,
182 FS1_COMPENSATION,
183 FS1_COMP_THRESHOLD
184 };
185 INDI::PropertyNumber Focuser2SettingsNP {6};
186 enum
187 {
188 FS2_SPEED,
189 FS2_CURRENT,
190 FS2_HOLD,
191 FS2_STEP_SIZE,
192 FS2_COMPENSATION,
193 FS2_COMP_THRESHOLD
194 };
195
196 INDI::PropertySwitch Focuser1ModeSP {3};
197 enum
198 {
199 FS1_MODE_UNI,
200 FS1_MODE_MICRO_L,
201 FS1_MODE_MICRO_H
202 };
203
204 INDI::PropertySwitch Focuser2ModeSP {3};
205 enum
206 {
207 FS2_MODE_UNI,
208 FS2_MODE_MICRO_L,
209 FS2_MODE_MICRO_H
210 };
211
212 INDI::PropertyNumber PowerDataNP {5};
213 enum
214 {
215 POW_VIN,
216 POW_REG,
217 POW_ITOT,
218 POW_AH,
219 POW_WH
220 };
221
222 INDI::PropertySwitch Power1SP {2};
223 enum
224 {
225 PWR1BTN_ON,
226 PWR1BTN_OFF
227 };
228 INDI::PropertySwitch Power2SP {2};
229 enum
230 {
231 PWR2BTN_ON,
232 PWR2BTN_OFF
233 };
234 INDI::PropertySwitch Power3SP {2};
235 enum
236 {
237 PWR3BTN_ON,
238 PWR3BTN_OFF
239 };
240 INDI::PropertyNumber PWMNP {2};
241 enum
242 {
243 PWM1_VAL,
244 PWM2_VAL
245 };
246 INDI::PropertySwitch PowerDefaultOnSP {3};
247 enum
248 {
249 POW_DEF_ON1,
250 POW_DEF_ON2,
251 POW_DEF_ON3
252 };
253
254 static constexpr const char *POWER_TAB{"Power"};
255 static constexpr const char *ENVIRONMENT_TAB{"Environment"};
256 static constexpr const char *SETTINGS_TAB{"Settings"};
257 static constexpr const char *FOC2_SETTINGS_TAB{"Focuser 2 Settings"};
258 static constexpr const char *FOC1_SETTINGS_TAB{"Focuser 1 Settings"};
259};
260
261#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 ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool sendCommand(const char *cmd, char *res)
Serial commands.
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Set Focuser Maximum position limit in the hardware.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual bool initProperties() override
Overrides.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
Focuser interface.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual IPState updateWeather() override
updateWeather Update weather conditions from device or service. The function should not change the st...
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual const char * getDefaultName() override
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