-
Notifications
You must be signed in to change notification settings - Fork 0
/
indi_astrolink4usb.h
256 lines (219 loc) · 6.81 KB
/
indi_astrolink4usb.h
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
/*******************************************************************************
Copyright(c) 2019 astrojolo.com
.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
.
This library 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
Library General Public License for more details.
.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*******************************************************************************/
#ifndef ASTROLINK4USB_H
#define ASTROLINK4USB_H
#include <string>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <memory>
#include <regex>
#include <cstring>
#include <map>
#include <sstream>
#include <defaultdevice.h>
#include <indifocuserinterface.h>
#include <indiweatherinterface.h>
#include <connectionplugins/connectionserial.h>
#define Q_STEPPER_POS 1
#define Q_STEPS_TO_GO 2
#define Q_CURRENT 3
#define Q_SENS1_TYPE 4
#define Q_SENS1_TEMP 5
#define Q_SENS1_HUM 6
#define Q_SENS1_DEW 7
#define Q_SENS2_TYPE 8
#define Q_SENS2_TEMP 27
#define Q_SENS2_HUM 28
#define Q_SENS2_DEW 29
#define Q_PWM1 10
#define Q_PWM2 11
#define Q_OUT1 12
#define Q_OUT2 13
#define Q_OUT3 14
#define Q_VIN 15
#define Q_VREG 16
#define Q_AH 17
#define Q_WH 18
#define Q_DC_MOVE 19
#define Q_COMP_DIFF 20
#define Q_OP_FLAG 21
#define Q_OP_VALUE 22
#define Q_SKYSENS_TYPE 23
#define Q_SKYSENS_TEMP 24
#define Q_SKYSENS_AMB 25
#define U_MAX_POS 1
#define U_SPEED 2
#define U_PWMSTOP 3
#define U_PWMRUN 4
#define U_ACC 5
#define U_REVERSED 6
#define U_STEPPER_MODE 7
#define U_COMPSENS 8
#define U_STEPSIZE 9
#define U_PWMPRESC 10
#define U_STEPPRESC 11
#define U_BUZ_ENABLED 12
#define U_HUM_SENS 13
#define U_DC_REVERSED 14
#define U_OUT1_DEF 15
#define U_OUT2_DEF 16
#define U_OUT3_DEF 17
#define E_COMP_CYCLE 1
#define E_COMP_STEPS 2
#define E_COMP_SENSR 3
#define E_COMP_AUTO 4
#define E_COMP_TRGR 5
#define N_AREF_COEFF 1
#define N_OVER_VOLT 2
#define N_OVER_AMP 3
#define N_OVER_TIME 4
#define Z_CURRENT 1
#define Z_STOP_CURRENT 2
namespace Connection
{
class Serial;
}
class IndiAstrolink4USB : public INDI::DefaultDevice, public INDI::FocuserInterface, public INDI::WeatherInterface
{
public:
IndiAstrolink4USB();
virtual bool initProperties();
virtual bool updateProperties();
virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
virtual bool ISNewText(const char * dev, const char * name, char * texts[], char * names[], int n);
protected:
virtual const char *getDefaultName();
virtual void TimerHit();
virtual bool saveConfigItems(FILE *fp);
virtual bool sendCommand(const char * cmd, char * res);
// Focuser Overrides
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
virtual bool AbortFocuser() override;
virtual bool ReverseFocuser(bool enabled) override;
virtual bool SyncFocuser(uint32_t ticks) override;
virtual bool SetFocuserBacklash(int32_t steps) override;
virtual bool SetFocuserBacklashEnabled(bool enabled) override;
virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
// Weather Overrides
virtual IPState updateWeather() override
{
return IPS_OK;
}
private:
virtual bool Handshake();
int PortFD = -1;
Connection::Serial *serialConnection { nullptr };
bool updateSettings(const char * getCom, const char * setCom, int index, const char * value);
bool updateSettings(const char * getCom, const char * setCom, std::map<int, std::string> values);
std::vector<std::string> split(const std::string &input, const std::string ®ex);
std::string doubleToStr(double val);
bool sensorRead();
bool setAutoPWM();
int32_t calculateBacklash(uint32_t targetTicks);
char stopChar { 0xA }; // new line
bool backlashEnabled = false;
int32_t backlashSteps = 0;
bool requireBacklashReturn = false;
IText PowerControlsLabelsT[3];
ITextVectorProperty PowerControlsLabelsTP;
ISwitch Power1S[2];
ISwitchVectorProperty Power1SP;
ISwitch Power2S[2];
ISwitchVectorProperty Power2SP;
ISwitch Power3S[2];
ISwitchVectorProperty Power3SP;
INumber Sensor2N[3];
INumberVectorProperty Sensor2NP;
enum
{
SENS_T, SENS_H, SENS_D
};
INumber SensorSkyN[2];
INumberVectorProperty SensorSkyNP;
enum
{
SENSSKY_T, SENSSKY_A
};
INumber PWMN[2];
INumberVectorProperty PWMNP;
ISwitch AutoPWMS[2];
ISwitchVectorProperty AutoPWMSP;
INumber PowerDataN[4];
INumberVectorProperty PowerDataNP;
enum
{
POW_VIN, POW_ITOT, POW_AH, POW_WH
};
INumber FocusPosMMN[1];
INumberVectorProperty FocusPosMMNP;
INumber CompensationValueN[1];
INumberVectorProperty CompensationValueNP;
ISwitch CompensateNowS[1];
ISwitchVectorProperty CompensateNowSP;
INumber FocuserSettingsN[5];
INumberVectorProperty FocuserSettingsNP;
enum
{
FS_SPEED, FS_STEP_SIZE, FS_CURRENT, FS_COMPENSATION, FS_COMP_THRESHOLD
};
ISwitch FocuserModeS[4];
ISwitchVectorProperty FocuserModeSP;
enum
{
FS_MODE_UNI, FS_MODE_BI, FS_MODE_MICRO_L, FS_MODE_MICRO_H
};
ISwitch FocuserHoldS[2];
ISwitchVectorProperty FocuserHoldSP;
enum
{
FS_HOLD_ON, FS_HOLD_OFF
};
ISwitch FocuserCompModeS[2];
ISwitchVectorProperty FocuserCompModeSP;
enum
{
FS_COMP_AUTO, FS_COMP_MANUAL
};
ISwitch FocuserManualS[2];
ISwitchVectorProperty FocuserManualSP;
enum
{
FS_MANUAL_ON, FS_MANUAL_OFF
};
ISwitch PowerDefaultOnS[3];
ISwitchVectorProperty PowerDefaultOnSP;
ISwitch AutoPWMDefaultOnS[2];
ISwitchVectorProperty AutoPWMDefaultOnSP;
INumber OtherSettingsN[4];
INumberVectorProperty OtherSettingsNP;
enum
{
SET_AREF_COEFF, SET_OVER_TIME, SET_OVER_VOLT, SET_OVER_AMP
};
ISwitch BuzzerS[1];
ISwitchVectorProperty BuzzerSP;
static constexpr const char *POWER_TAB {"Power"};
static constexpr const char *ENVIRONMENT_TAB {"Environment"};
static constexpr const char *SETTINGS_TAB {"Settings"};
};
#endif