Instrument Neutral Distributed Interface INDI 2.2.5
lx200_OnStep.cpp
Go to the documentation of this file.
1/*
2 LX200 LX200_OnStep
3 Based on LX200 classic, ([email protected])
4 Contributors:
5 James Lan https://github.com/james-lan
6 Ray Wells https://github.com/blueshawk
7
8 Copyright (C) 2003-2026 Jasem Mutlaq ([email protected])
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
24*/
25
26//#define DEBUG_TRACKSTATE
27
28
29#include "lx200_OnStep.h"
30
31
32#include <cmath>
33#include <mutex>
34
35#define LIBRARY_TAB "Library"
36#define FIRMWARE_TAB "Firmware data"
37#define STATUS_TAB "ONStep Status"
38#define PEC_TAB "PEC"
39#define ALIGN_TAB "Align"
40#define OUTPUT_TAB "Outputs"
41#define ENVIRONMENT_TAB "Weather"
42#define ROTATOR_TAB "Rotator"
43
44#define RA_AXIS 0
45#define DEC_AXIS 1
46
47extern std::mutex lx200CommsLock;
48
49
51{
52 currentCatalog = LX200_STAR_C;
53 currentSubCatalog = 0;
54
55 setVersion(1, 32); // don't forget to update libindi/drivers.xml
56
59
65
66 //CAN_ABORT, CAN_GOTO ,CAN_PARK ,CAN_SYNC ,HAS_LOCATION ,HAS_TIME ,HAS_TRACK_MODE Already inherited from lx200generic,
67 // 4 stands for the number of Slewrate Buttons as defined in Inditelescope.cpp
68 //setLX200Capability(LX200_HAS_FOCUS | LX200_HAS_TRACKING_FREQ | LX200_HAS_ALIGNMENT_TYPE | LX200_HAS_SITES | LX200_HAS_PULSE_GUIDING);
69 //
70 // Get generic capabilities but discard the following:
71 // LX200_HAS_FOCUS
72
73
75 // Unused option: FOCUSER_HAS_VARIABLE_SPEED
76
78 // /*{
79 // ROTATOR_CAN_ABORT = 1 << 0, /*!< Can the Rotator abort motion once started? */
80 // ROTATOR_CAN_HOME = 1 << 1, /*!< Can the Rotator go to home position? */
81 // ROTATOR_CAN_SYNC = 1 << 2, /*!< Can the Rotator sync to specific tick? */ /*Not supported */
82 // ROTATOR_CAN_REVERSE = 1 << 3, /*!< Can the Rotator reverse direction? */ //It CAN reverse, but there's no way to query the direction
83 // ROTATOR_HAS_BACKLASH = 1 << 4 /*!< Can the Rotatorer compensate for backlash? */
84 // //}*/
85
86}
87
89{
90 return "LX200 OnStep";
91}
92
94{
95
101
103
104 //FocuserInterface
105 //Initial, these will be updated later.
106 FocusRelPosNP[0].setMin(0.);
107 FocusRelPosNP[0].setMax(30000.);
108 FocusRelPosNP[0].setValue(0);
109 FocusRelPosNP[0].setStep(10);
110 FocusAbsPosNP[0].setMin(0.);
111 FocusAbsPosNP[0].setMax(60000.);
112 FocusAbsPosNP[0].setValue(0);
113 FocusAbsPosNP[0].setStep(10);
114
115
116 // ============== MAIN_CONTROL_TAB
117 ReticSP[0].fill("PLUS", "Light", ISS_OFF);
118 ReticSP[1].fill("MOINS", "Dark", ISS_OFF);
119 ReticSP.fill(getDeviceName(), "RETICULE_BRIGHTNESS", "Reticule +/-", MAIN_CONTROL_TAB, IP_RW,
120 ISR_ATMOST1, 60, IPS_IDLE);
121
122 ElevationLimitNP[0].fill("minAlt", "Elev Min", "%g", -30, 30, 1, -30);
123 ElevationLimitNP[1].fill("maxAlt", "Elev Max", "%g", 60, 90, 1, 89);
124 ElevationLimitNP.fill(getDeviceName(), "Slew elevation Limit", "", MAIN_CONTROL_TAB, IP_RW, 0, IPS_IDLE);
125
126 ObjectInfoTP[0].fill("Info", "", "");
127 ObjectInfoTP.fill(getDeviceName(), "Object Info", "", MAIN_CONTROL_TAB, IP_RO, 0, IPS_IDLE);
128
129 // ============== COMMUNICATION_TAB
130
131 // ============== CONNECTION_TAB
132
133 // ============== OPTIONS_TAB
134
135 // ============== FILTER_TAB
136
137 // ============== MOTION_TAB
138 //Override the standard slew rate command. Also add appropriate description. This also makes it work in Ekos Mount Control correctly
139 //Note that SlewRateSP and MaxSlewRateNP BOTH track the rate. I have left them in there because MaxRateNP reports OnStep Values
140
141 MaxSlewRateNP[0].fill("maxSlew", "Rate", "%f", 0.0, 9.0, 1.0, 5.0);
142 MaxSlewRateNP.fill(getDeviceName(), "Max slew Rate", "", MOTION_TAB, IP_RW, 0, IPS_IDLE);
143
144 TrackCompSP[0].fill("1", "Full Compensation", ISS_OFF);
145 TrackCompSP[1].fill("2", "Refraction", ISS_OFF);
146 TrackCompSP[2].fill("3", "Off", ISS_ON);
147 TrackCompSP.fill(getDeviceName(), "Compensation", "Compensation Tracking", MOTION_TAB, IP_RW,
149
150 TrackAxisSP[0].fill("1", "Single Axis", ISS_OFF);
151 TrackAxisSP[1].fill("2", "Dual Axis", ISS_OFF);
152 TrackAxisSP.fill(getDeviceName(), "Multi-Axis", "Multi-Axis Tracking", MOTION_TAB, IP_RW,
154
155 BacklashNP[0].fill("Backlash DEC", "DE", "%g", 0, 3600, 1, 15);
156 BacklashNP[1].fill("Backlash RA", "RA", "%g", 0, 3600, 1, 15);
157 BacklashNP.fill(getDeviceName(), "Backlash", "", MOTION_TAB, IP_RW, 0, IPS_IDLE);
158
159 GuideRateNP[RA_AXIS].fill("GUIDE_RATE_WE", "W/E Rate", "%g", 0, 1, 0.25, 0.5);
160 GuideRateNP[DEC_AXIS].fill("GUIDE_RATE_NS", "N/S Rate", "%g", 0, 1, 0.25, 0.5);
161 GuideRateNP.fill(getDeviceName(), "GUIDE_RATE", "Guiding Rate", MOTION_TAB, IP_RO, 0, IPS_IDLE);
162
163 AutoFlipSP[0].fill("1", "AutoFlip: OFF", ISS_OFF);
164 AutoFlipSP[1].fill("2", "AutoFlip: ON", ISS_OFF);
165 AutoFlipSP.fill(getDeviceName(), "AutoFlip", "Meridian Auto Flip", MOTION_TAB, IP_RW,
167
168 HomePauseSP[0].fill("1", "HomePause: OFF", ISS_OFF);
169 HomePauseSP[1].fill("2", "HomePause: ON", ISS_OFF);
170 HomePauseSP[2].fill("3", "HomePause: Continue", ISS_OFF);
171 HomePauseSP.fill(getDeviceName(), "HomePause", "Pause at Home", MOTION_TAB, IP_RW,
173
174 FrequencyAdjustSP[0].fill("1", "Frequency -", ISS_OFF);
175 FrequencyAdjustSP[1].fill("2", "Frequency +", ISS_OFF);
176 FrequencyAdjustSP[2].fill("3", "Reset Sidereal Frequency", ISS_OFF);
177 FrequencyAdjustSP.fill(getDeviceName(), "FrequencyAdjust", "Frequency Adjust",
179
180 PreferredPierSideSP[0].fill("1", "West", ISS_OFF);
181 PreferredPierSideSP[1].fill("2", "East", ISS_OFF);
182 PreferredPierSideSP[2].fill("3", "Best", ISS_OFF);
183 PreferredPierSideSP.fill(getDeviceName(), "Preferred Pier Side",
184 "Preferred Pier Side", MOTION_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
185
186 minutesPastMeridianNP[0].fill("East", "East ± 180", "%g", -180, 180, 1, 20);
187 minutesPastMeridianNP[1].fill("West", "West ± 180", "%g", -180, 180, 1, -20);
188 minutesPastMeridianNP.fill(getDeviceName(), "Minutes Past Meridian",
189 "Minutes Past Meridian", MOTION_TAB, IP_RW, 0, IPS_IDLE);
190
191
192 // ============== DATETIME_TAB
193
194 // ============== SITE_TAB
195 // IUFillSwitch(&SetHomeS[0], "RETURN_HOME", "Return Home", ISS_OFF);
196 // IUFillSwitch(&SetHomeS[1], "AT_HOME", "At Home (Reset)", ISS_OFF);
197 // IUFillSwitchVector(&SetHomeSP, SetHomeS, 2, getDeviceName(), "HOME_INIT", "Homing", SITE_TAB, IP_RW, ISR_ATMOST1, 60,
198 // IPS_IDLE);
199
200 // ============== GUIDE_TAB
201
202 // ============== FOCUS_TAB
203 // Focuser 1
204
205 OSFocus1InitializeSP[0].fill("Focus1_0", "Zero", ISS_OFF);
206 OSFocus1InitializeSP[1].fill("Focus1_2", "Mid", ISS_OFF);
207 // OSFocus1InitializeSP[2].fill("Focus1_3", "max", ISS_OFF);
208 OSFocus1InitializeSP.fill(getDeviceName(), "Foc1Rate", "Initialize", FOCUS_TAB,
210 // Focus T° Compensation
211 // Property must be FOCUS_TEMPERATURE to be recognized by Ekos
212 FocusTemperatureNP[0].fill("FOCUS_TEMPERATURE", "TFC T°", "%+2.2f", 0, 1, 0.25,
213 25); //default value is meaningless
214 FocusTemperatureNP[1].fill("TFC Δ T°", "TFC Δ T°", "%+2.2f", 0, 1, 0.25, 25); //default value is meaningless
215 FocusTemperatureNP.fill(getDeviceName(), "FOCUS_TEMPERATURE", "Focuser T°",
216 FOCUS_TAB, IP_RO, 0,
217 IPS_IDLE);
218 TFCCompensationSP[0].fill("Off", "Compensation: OFF", ISS_OFF);
219 TFCCompensationSP[1].fill("On", "Compensation: ON", ISS_OFF);
220 TFCCompensationSP.fill(getDeviceName(), "Compensation T°", "Temperature Compensation",
223
224 TFCCoefficientNP[0].fill("TFC Coefficient", "TFC Coefficient µm/°C", "%+03.5f", -999.99999, 999.99999, 1, 100);
225 TFCCoefficientNP.fill(getDeviceName(), "TFC Coefficient", "", FOCUS_TAB, IP_RW, 0,
226 IPS_IDLE);
227 TFCDeadbandNP[0].fill("TFC Deadband", "TFC Deadband µm", "%g", 1, 32767, 1, 5);
228 TFCDeadbandNP.fill(getDeviceName(), "TFC Deadband", "", FOCUS_TAB, IP_RW, 0, IPS_IDLE);
229 // End Focus T° Compensation
230
231 OSFocusSelectSP[0].fill("Focuser_Primary_1", "Focuser 1", ISS_ON);
232 OSFocusSelectSP[1].fill("Focuser_Primary_2", "Focuser 2/Swap", ISS_OFF);
233 // For when OnStepX comes out
234 OSFocusSelectSP[2].fill("Focuser_Primary_3", "3", ISS_OFF);
235 OSFocusSelectSP[3].fill("Focuser_Primary_4", "4", ISS_OFF);
236 OSFocusSelectSP[4].fill("Focuser_Primary_5", "5", ISS_OFF);
237 OSFocusSelectSP[5].fill("Focuser_Primary_6", "6", ISS_OFF);
238 OSFocusSelectSP[6].fill("Focuser_Primary_7", "7", ISS_OFF);
239 OSFocusSelectSP[7].fill("Focuser_Primary_8", "8", ISS_OFF);
240 OSFocusSelectSP[8].fill("Focuser_Primary_9", "9", ISS_OFF);
241 OSFocusSelectSP[9].fill("Focuser_Primary_10", "10", ISS_OFF);
242
243 OSFocusSelectSP.fill(getDeviceName(), "OSFocusSWAP", "Primary Focuser", FOCUS_TAB,
245
246
247 // Focuser 2
248 //OSFocus2SelSP[0].fill("Focus2_Sel1", "Foc 1", ISS_OFF);
249 //OSFocus2SelSP[1].fill("Focus2_Sel2", "Foc 2", ISS_OFF);
250 //OSFocus2SelSP.fill(getDeviceName(), "Foc2Sel", "Foc 2", FOCUS_TAB, IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
251
252 OSFocus2MotionSP[0].fill("Focus2_In", "In", ISS_OFF);
253 OSFocus2MotionSP[1].fill("Focus2_Out", "Out", ISS_OFF);
254 OSFocus2MotionSP[2].fill("Focus2_Stop", "Stop", ISS_OFF);
255 OSFocus2MotionSP.fill(getDeviceName(), "Foc2Mot", "Foc 2 Motion", FOCUS_TAB, IP_RW,
257
258 OSFocus2RateSP[0].fill("Focus2_1", "min", ISS_OFF);
259 OSFocus2RateSP[1].fill("Focus2_2", "0.01", ISS_OFF);
260 OSFocus2RateSP[2].fill("Focus2_3", "0.1", ISS_OFF);
261 OSFocus2RateSP[3].fill("Focus2_4", "1", ISS_OFF);
262 OSFocus2RateSP.fill(getDeviceName(), "Foc2Rate", "Foc 2 Rates", FOCUS_TAB, IP_RW,
264
265 OSFocus2TargNP[0].fill("FocusTarget2", "Abs Pos", "%g", -25000, 25000, 1, 0);
266 OSFocus2TargNP.fill(getDeviceName(), "Foc2Targ", "Foc 2 Target", FOCUS_TAB, IP_RW, 0,
267 IPS_IDLE);
268
269 // =========== ROTATOR TAB
270
271 OSRotatorDerotateSP[0].fill("Derotate_OFF", "OFF", ISS_OFF);
272 OSRotatorDerotateSP[1].fill("Derotate_ON", "ON", ISS_OFF);
273 OSRotatorDerotateSP.fill(getDeviceName(), "Derotate_Status", "DEROTATE", ROTATOR_TAB,
274 IP_RW,
276
277 // ============== FIRMWARE_TAB
278 VersionTP[0].fill("Date", "", "");
279 VersionTP[1].fill("Time", "", "");
280 VersionTP[2].fill("Number", "", "");
281 VersionTP[3].fill("Name", "", "");
282 VersionTP.fill(getDeviceName(), "Firmware Info", "", FIRMWARE_TAB, IP_RO, 0, IPS_IDLE);
283
284 //PEC Tab
285 OSPECStatusSP[0].fill("OFF", "OFF", ISS_OFF);
286 OSPECStatusSP[1].fill("Playing", "Playing", ISS_OFF);
287 OSPECStatusSP[2].fill("Recording", "Recording", ISS_OFF);
288 OSPECStatusSP[3].fill("Will Play", "Will Play", ISS_OFF);
289 OSPECStatusSP[4].fill("Will Record", "Will Record", ISS_OFF);
290 OSPECStatusSP.fill(getDeviceName(), "PEC Status", "PEC Status", PEC_TAB, IP_RO,
292
293 OSPECIndexSP[0].fill("Not Detected", "Not Detected", ISS_ON);
294 OSPECIndexSP[1].fill("Detected", "Detected", ISS_OFF);
295 OSPECIndexSP.fill(getDeviceName(), "PEC Index Detect", "PEC Index", PEC_TAB, IP_RO,
297
298 OSPECRecordSP[0].fill("Clear", "Clear", ISS_OFF);
299 OSPECRecordSP[1].fill("Record", "Record", ISS_OFF);
300 OSPECRecordSP[2].fill("Write to EEPROM", "Write to EEPROM", ISS_OFF);
301 OSPECRecordSP.fill(getDeviceName(), "PEC Operations", "PEC Recording", PEC_TAB, IP_RW,
303
304 OSPECReadSP[0].fill("Read", "Read PEC to FILE****", ISS_OFF);
305 OSPECReadSP[1].fill("Write", "Write PEC from FILE***", ISS_OFF);
306 // OSPECReadSP[2].fill("Write to EEPROM", "Write to EEPROM", ISS_OFF);
307 OSPECReadSP.fill(getDeviceName(), "PEC File", "PEC File", PEC_TAB, IP_RW, ISR_ATMOST1, 0,
308 IPS_IDLE);
309 // ============== ALIGNMENT_TAB
310 // Only supports Alpha versions currently (July 2018) Now Beta (Dec 2018)
311 OSNAlignStarsSP[0].fill("1", "1 Star", ISS_OFF);
312 OSNAlignStarsSP[1].fill("2", "2 Stars", ISS_OFF);
313 OSNAlignStarsSP[2].fill("3", "3 Stars", ISS_ON);
314 OSNAlignStarsSP[3].fill("4", "4 Stars", ISS_OFF);
315 OSNAlignStarsSP[4].fill("5", "5 Stars", ISS_OFF);
316 OSNAlignStarsSP[5].fill("6", "6 Stars", ISS_OFF);
317 OSNAlignStarsSP[6].fill("7", "7 Stars", ISS_OFF);
318 OSNAlignStarsSP[7].fill("8", "8 Stars", ISS_OFF);
319 OSNAlignStarsSP[8].fill("9", "9 Stars", ISS_OFF);
320 OSNAlignStarsSP.fill(getDeviceName(), "AlignStars", "Select # of stars",
322
323 OSNAlignSP[0].fill("0", "Start Align", ISS_OFF);
324 OSNAlignSP[1].fill("1", "Issue Align", ISS_OFF);
325 OSNAlignSP.fill(getDeviceName(), "NewAlignStar", "Align using up to 9 stars",
327
328 OSNAlignWriteSP[0].fill("0", "Write Align to NVRAM/Flash", ISS_OFF);
329 OSNAlignWriteSP.fill(getDeviceName(), "NewAlignStar2", "NVRAM", ALIGN_TAB, IP_RW,
331 OSNAlignPolarRealignSP[0].fill("0", "Instructions", ISS_OFF);
332 OSNAlignPolarRealignSP[1].fill("1", "Refine Polar Align (manually)", ISS_OFF);
333 OSNAlignPolarRealignSP.fill(getDeviceName(), "AlignMP",
334 "Polar Correction, See info box", ALIGN_TAB, IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
335
336 OSNAlignTP[0].fill("0", "Align Process Status", "Align not started");
337 OSNAlignTP[1].fill("1", "1. Manual Process", "Point towards the NCP");
338 OSNAlignTP[2].fill("2", "2. Plate Solver Process", "Point towards the NCP");
339 OSNAlignTP[3].fill("3", "Manual Action after 1", "Press 'Start Align'");
340 OSNAlignTP[4].fill("4", "Current Status", "Not Updated");
341 OSNAlignTP[5].fill("5", "Max Stars", "Not Updated");
342 OSNAlignTP[6].fill("6", "Current Star", "Not Updated");
343 OSNAlignTP[7].fill("7", "# of Align Stars", "Not Updated");
344 OSNAlignTP.fill(getDeviceName(), "Align Process", "", ALIGN_TAB, IP_RO, 0, IPS_IDLE);
345
346 OSNAlignErrTP[0].fill("0", "EQ Polar Error Alt", "Available once Aligned");
347 OSNAlignErrTP[1].fill("1", "EQ Polar Error Az", "Available once Aligned");
348 // OSNAlignErrTP[2].fill("2", "2. Plate Solver Process", "Point towards the NCP");
349 // OSNAlignErrTP[3].fill("3", "After 1 or 2", "Press 'Start Align'");
350 // OSNAlignErrTP[4].fill("4", "Current Status", "Not Updated");
351 // OSNAlignErrTP[5].fill("5", "Max Stars", "Not Updated");
352 // OSNAlignErrTP[6].fill("6", "Current Star", "Not Updated");
353 // OSNAlignErrTP[7].fill("7", "# of Align Stars", "Not Updated");
354 OSNAlignErrTP.fill(getDeviceName(), "Align OnStep results", "", ALIGN_TAB, IP_RO, 0,
355 IPS_IDLE);
356
357 // =============== INFO_TAB
358
359#ifdef ONSTEP_NOTDONE
360 // =============== OUTPUT_TAB
361 // ===============
362 IUFillSwitch(&OSOutput1S[0], "0", "OFF", ISS_ON);
363 IUFillSwitch(&OSOutput1S[1], "1", "ON", ISS_OFF);
364 IUFillSwitchVector(&OSOutput1SP, OSOutput1S, 2, getDeviceName(), "Output 1", "Output 1", OUTPUT_TAB, IP_RW, ISR_ATMOST1, 60,
365 IPS_ALERT);
366
367 IUFillSwitch(&OSOutput2S[0], "0", "OFF", ISS_ON);
368 IUFillSwitch(&OSOutput2S[1], "1", "ON", ISS_OFF);
369 IUFillSwitchVector(&OSOutput2SP, OSOutput2S, 2, getDeviceName(), "Output 2", "Output 2", OUTPUT_TAB, IP_RW, ISR_ATMOST1, 60,
370 IPS_ALERT);
371#endif
372
373 for(int i = 0; i < PORTS_COUNT; i++)
374 {
375 char port_name[30];
376 snprintf(port_name, sizeof(port_name), "Output %d", i);
377 OutputPorts_NP[i].fill(port_name, port_name, "%g", 0, 255, 1, 0);
378 }
379
380 OutputPorts_NP.fill(getDeviceName(), "Outputs", "Outputs", OUTPUT_TAB, IP_WO, 60,
381 IPS_OK);
382
383
384 // ============== STATUS_TAB
385 OnstepStatTP[0].fill(":GU# return", "", "");
386 OnstepStatTP[1].fill("Tracking", "", "");
387 OnstepStatTP[2].fill("Refractoring", "", "");
388 OnstepStatTP[3].fill("Park", "", "");
389 OnstepStatTP[4].fill("Pec", "", "");
390 OnstepStatTP[5].fill("TimeSync", "", "");
391 OnstepStatTP[6].fill("Mount Type", "", "");
392 OnstepStatTP[7].fill("Error", "", "");
393 OnstepStatTP[8].fill("Multi-Axis Tracking", "", "");
394 OnstepStatTP[9].fill("TMC Axis1", "", "");
395 OnstepStatTP[10].fill("TMC Axis2", "", "");
396 OnstepStatTP.fill(getDeviceName(), "OnStep Status", "", STATUS_TAB, IP_RO, 0, IPS_OK);
397
398 // ============== WEATHER TAB
399 // Uses OnStep's defaults for this
400 OSSetTemperatureNP[0].fill("Set Temperature (C)", "C", "%4.2f", -100, 100, 1, 10);
401 OSSetTemperatureNP.fill(getDeviceName(), "Set Temperature (C)", "", ENVIRONMENT_TAB,
402 IP_RW, 0, IPS_IDLE);
403 OSSetHumidityNP[0].fill("Set Relative Humidity (%)", "%", "%5.2f", 0, 100, 1, 70);
404 OSSetHumidityNP.fill(getDeviceName(), "Set Relative Humidity (%)", "", ENVIRONMENT_TAB,
405 IP_RW, 0, IPS_IDLE);
406 OSSetPressureNP[0].fill("Set Pressure (hPa)", "hPa", "%4f", 500, 1500, 1, 1010);
407 OSSetPressureNP.fill(getDeviceName(), "Set Pressure (hPa)", "", ENVIRONMENT_TAB, IP_RW,
408 0, IPS_IDLE);
409
410 //Will eventually pull from the elevation in site settings
411 //TODO: Pull from elevation in site settings
412 OSSetAltitudeNP[0].fill("Set Altitude (m)", "m", "%4f", 0, 20000, 1, 110);
413 OSSetAltitudeNP.fill(getDeviceName(), "Set Altitude (m)", "", ENVIRONMENT_TAB, IP_RW, 0,
414 IPS_IDLE);
415
416
417 addParameter("WEATHER_TEMPERATURE", "Temperature (C)", -40, 85, 15);
418 addParameter("WEATHER_HUMIDITY", "Humidity %", 0, 100, 15);
419 addParameter("WEATHER_BAROMETER", "Pressure (hPa)", 0, 1500, 15);
420 addParameter("WEATHER_DEWPOINT", "Dew Point (C)", 0, 100, 15); // From OnStep
421 addParameter("WEATHER_CPU_TEMPERATURE", "OnStep CPU Temperature", -274, 200, -274); // From OnStep, -274 = unread
422 setCriticalParameter("WEATHER_TEMPERATURE");
423
425
426
428
429 return true;
430}
431
432void LX200_OnStep::ISGetProperties(const char *dev)
433{
434 if (dev != nullptr && strcmp(dev, getDeviceName()) != 0) return;
436}
437
439{
441 //TODO: Properly setup Weather
443
444 if (isConnected())
445 {
446 Connection::Interface *activeConnection = getActiveConnection();
447 if (!activeConnection->name().compare("CONNECTION_TCP"))
448 {
449 LOG_INFO("Network based connection, detection timeouts set to 2 seconds");
452 }
453 else
454 {
455 LOG_INFO("Non-Network based connection, detection timeouts set to 0.1 seconds");
456 OSTimeoutMicroSeconds = 100000;
458 }
459
460 // Firstinitialize some variables
461 // keep sorted by TABs is easier
462 // Main Control
466 // Connection
467
468 // Options
469
470 // OnStep Status
472
473 // Motion Control
474 defineProperty(SlewRateSP); // was missing
485
486 // Site Management
488 //defineProperty(SetHomeSP);
489
490 // Guide
491
492 // Focuser
493
494 // Focuser 1
495 OSNumFocusers = 0; //Reset before detection
496 //if (!sendOnStepCommand(":FA#")) // do we have a Focuser 1
497 char response[RB_MAX_LEN] = {0};
498 int error_or_fail = getCommandSingleCharResponse(PortFD, response, ":FA#"); //0 = failure, 1 = success, no # on reply
499 if (error_or_fail > 0 && response[0] == '1')
500 {
501 LOG_INFO("Focuser 1 found");
502 OSFocuser1 = true;
504 // Focus T° Compensation
509 // End Focus T° Compensation
510 OSNumFocusers = 1;
511 }
512 else
513 {
514 OSFocuser1 = false;
515 LOG_INFO("Focuser 1 NOT found");
516 LOGF_DEBUG("error_or_fail = %u, response = %c", error_or_fail, response[0]);
517 }
518 // Focuser 2
519 if (!sendOnStepCommand(":fA#")) // Do we have a Focuser 2 (:fA# will only work for OnStep, not OnStepX)
520 {
521 LOG_INFO("Focuser 2 found");
522 OSFocuser2 = true;
523 OSNumFocusers = 2;
524 //defineProperty(OSFocus2SelSP);
528 OSFocusSelectSP.fill(getDeviceName(), "OSFocusSWAP", "Primary Focuser",
529 FOCUS_TAB,
531 defineProperty(OSFocusSelectSP); //Swap focusers (only matters if two focusers)
532 }
533 else //For OnStepX, up to 6 focusers
534 {
535 LOG_INFO("Focuser 2 NOT found");
536 OSFocuser2 = false;
538 {
539 LOG_INFO("Version unknown or OnStepX (Checking for OnStepX Focusers)");
540 for (int i = 0; i < 9; i++)
541 {
542 char cmd[CMD_MAX_LEN] = {0};
543 char read_buffer[RB_MAX_LEN] = {0};
544 snprintf(cmd, sizeof(cmd), ":F%dA#", i + 1);
545 int fail_or_error = getCommandSingleCharResponse(PortFD, read_buffer,
546 cmd); //0 = failure, 1 = success, 0 on all prior to OnStepX no # on reply
547 if (!fail_or_error && read_buffer[0] == '1') // Do we have a Focuser X
548 {
549 LOGF_INFO("Focuser %i Found", i);
550 OSNumFocusers = i + 1;
551 }
552 else
553 {
554 if(fail_or_error < 0)
555 {
556 //Non detection = 0, Read errors < 0, stop
557 LOGF_INFO("Function call failed in a way that says OnStep doesn't have this setup, stopping Focuser probing, return: %i",
558 fail_or_error);
559 break;
560 }
561 }
562 }
563 }
564 if (OSNumFocusers > 1)
565 {
566 OSFocusSelectSP.fill(getDeviceName(), "OSFocusSWAP", "Primary Focuser",
567 FOCUS_TAB,
570 }
571 }
572 if (OSNumFocusers == 0)
573 {
574 LOG_INFO("No Focusers found");
575 }
576 else
577 {
578 LOG_INFO("At least one focuser found, showing interface");
580 }
581
582 LOG_DEBUG("Focusers checked Variables:");
583 LOGF_DEBUG("OSFocuser1: %d, OSFocuser2: %d, OSNumFocusers: %i", OSFocuser1, OSFocuser2, OSNumFocusers);
584
585 //Rotation Information
586 char rotator_response[RB_MAX_LEN] = {0};
587 error_or_fail = getCommandSingleCharResponse(PortFD, rotator_response, ":GX98#");
588 if (error_or_fail > 0)
589 {
590 if (rotator_response[0] == 'D' || rotator_response[0] == 'R')
591 {
592 LOG_INFO("Rotator found.");
593 OSRotator1 = true;
597 }
598 if (rotator_response[0] == 'D')
599 {
601 }
602 if (rotator_response[0] == '0')
603 {
604 OSRotator1 = false;
605 }
606 }
607 else
608 {
609 LOGF_WARN("Error: %i", error_or_fail);
610 LOG_WARN("Error on response to rotator check (:GX98#) CHECK CONNECTION");
611 }
612 //=================
613
614 if (OSRotator1 == false)
615 {
616 LOG_INFO("No Rotator found.");
617 OSRotator1 = false;
618 }
619
620 // Firmware Data
622
623 //PEC
624 //TODO: Define later when it might be supported
629 //defineProperty(OSPECCurrentIndexNP);
630 //defineProperty(OSPECRWValuesNP);
631
632 //New Align
639
640#ifdef ONSTEP_NOTDONE
641 //Outputs
642 defineProperty(OSOutput1SP);
643 defineProperty(OSOutput2SP);
644#endif
645 // OSHasOutputs = true; //Set to true on new connection, Init_Outputs will set to false if appropriate
646 Init_Outputs();
647
648 //Weather
653
654
655
656 if (InitPark())
657 {
658 // If loading parking data is successful, we just set the default parking values.
659 SetAxis1ParkDefault(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
661 }
662 else
663 {
664 // Otherwise, we set all parking data to default in case no parking data is found.
665 SetAxis1Park(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
667
668 SetAxis1ParkDefault(LocationNP[LOCATION_LATITUDE].getValue() >= 0 ? 0 : 180);
670 }
671
672 double longitude = -1000, latitude = -1000;
673 // Get value from config file if it exists.
674 IUGetConfigNumber(getDeviceName(), "GEOGRAPHIC_COORD", "LONG", &longitude);
675 IUGetConfigNumber(getDeviceName(), "GEOGRAPHIC_COORD", "LAT", &latitude);
676 // if (longitude != -1000 && latitude != -1000)
677 // {
678 // updateLocation(latitude, longitude, 0);
679 // }
680 //NOTE: if updateProperties is called it clobbers this, so added here
681
682
683 }
684 else
685 {
686 // keep sorted by TABs is easier
687 // Main Control
690 // Connection
691
692 // Options
693
694 // Motion Control
695 deleteProperty(SlewRateSP); // was missing
706
707 // Site Management
709 //deleteProperty(SetHomeSP.name);
710 // Guide
711
712 // Focuser
713 // Focuser 1
718 // Focus T° Compensation
720 // End Focus T° Compensation
721
722 // Focuser 2
723 //deleteProperty(OSFocus2SelSP.name);
728
729 // Rotator
731
732 // Firmware Data
734
735
736 //PEC
741 //deleteProperty(OSPECCurrentIndexNP.name);
742 //deleteProperty(OSPECRWValuesNP.name);
743
744 //New Align
751
752#ifdef ONSTEP_NOTDONE
753 //Outputs
754 deleteProperty(OSOutput1SP);
755 deleteProperty(OSOutput2SP);
756#endif
757
759
760 // OnStep Status
762 //Weather
769 OSHasOutputs = true; //Set once per connection, either at startup or on disconnection for next connection;
770 }
771 LOG_INFO("Initialization Complete");
772 return true;
773}
774
775bool LX200_OnStep::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
776{
777 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
778 {
779 if (strstr(name, "FOCUS_"))
780 return FI::processNumber(dev, name, values, names, n);
781 if (strstr(name, "ROTATOR_"))
782 return RI::processNumber(dev, name, values, names, n);
783
784 if (EqNP.isNameMatch(name))
785 //Replace this from inditelescope so it doesn't change state
786 //Most of this needs to be handled by our updates, or it breaks things
787 {
788 // this is for us, and it is a goto
789 bool rc = false;
790 double ra = -1;
791 double dec = -100;
792
793 for (int x = 0; x < n; x++)
794 {
795 if (EqNP[AXIS_RA].isNameMatch(names[x]))
796 ra = values[x];
797 else if (EqNP[AXIS_DE].isNameMatch(names[x]))
798 dec = values[x];
799 }
800
801 if ((ra >= 0) && (ra <= 24) && (dec >= -90) && (dec <= 90))
802 {
803 // Check if it is already parked.
804 if (CanPark())
805 {
806 if (isParked())
807 {
808 LOG_DEBUG("Please unpark the mount before issuing any motion/sync commands.");
809 // EqNP.setState(lastEqState = IPS_IDLE);
810 // EqNP.apply();
811 return false;
812 }
813 }
814
815 // Check if it can sync
816 if (Telescope::CanSync())
817 {
818 auto oneSwitch = CoordSP.findWidgetByName("SYNC");
819 if (oneSwitch && oneSwitch->getState() == ISS_ON)
820 {
821 return Sync(ra, dec);
822 }
823 }
824
825 // Issue GOTO
826 rc = Goto(ra, dec);
827 if (rc)
828 {
829 // Now fill in target co-ords, so domes can start turning
830 TargetNP[AXIS_RA].setValue(ra);
831 TargetNP[AXIS_DE].setValue(dec);
832 TargetNP.apply();
833 }
834 }
835 return rc;
836 }
837
838 if (ObjectNoNP.isNameMatch(name))
839 {
840 char object_name[256];
841
842 if (selectCatalogObject(PortFD, currentCatalog, (int)values[0]) < 0)
843 {
844 ObjectNoNP.setState(IPS_ALERT);
845 ObjectNoNP.apply();
846 LOG_ERROR("Failed to select catalog object.");
847 return false;
848 }
849
852
853 ObjectNoNP.setState(IPS_OK);
854 ObjectNoNP.apply();
855
856 if (getObjectInfo(PortFD, object_name) < 0)
857 IDMessage(getDeviceName(), "Getting object info failed.");
858 else
859 {
860 ObjectInfoTP[0].setText(object_name);
861 ObjectInfoTP.apply();
862 }
864 return true;
865 }
866
867 if (MaxSlewRateNP.isNameMatch(name))
868 {
869 int ret;
870 char cmd[CMD_MAX_LEN] = {0};
871 snprintf(cmd, 5, ":R%d#", (int)values[0]);
873
874 //if (setMaxSlewRate(PortFD, (int)values[0]) < 0) //(int) MaxSlewRateN[0].value
875 if (ret == -1)
876 {
877 LOGF_DEBUG("Pas OK Return value =%d", ret);
878 LOGF_DEBUG("Setting Max Slew Rate to %f\n", values[0]);
879 MaxSlewRateNP.setState(IPS_ALERT);
880 MaxSlewRateNP.apply();
881 LOG_ERROR("Setting Max Slew Rate Failed");
882 return false;
883 }
884 LOGF_DEBUG("OK Return value =%d", ret);
885 MaxSlewRateNP.setState(IPS_OK);
886 MaxSlewRateNP[0].setValue(values[0]);
887 MaxSlewRateNP.apply();
888 LOGF_INFO("Slewrate set to %04.1f", values[0]);
889 SlewRateSP.reset();
890 SlewRateSP[int(values[0])].setState(ISS_ON);
891 SlewRateSP.setState(IPS_OK);
892 SlewRateSP.apply();
893 return true;
894 }
895
896 if (BacklashNP.isNameMatch(name))
897 {
898 //char cmd[CMD_MAX_LEN] = {0};
899 int i, nset;
900 double bklshdec = 0, bklshra = 0;
901
902 for (nset = i = 0; i < n; i++)
903 {
904 if (BacklashNP[0].isNameMatch(names[i]))
905 {
906 bklshdec = values[i];
907 LOGF_DEBUG("===CMD==> Backlash DEC= %f", bklshdec);
908 nset += bklshdec >= 0 && bklshdec <= 999; //range 0 to 999
909 }
910 else if (BacklashNP[1].isNameMatch(names[i]))
911 {
912 bklshra = values[i];
913 LOGF_DEBUG("===CMD==> Backlash RA= %f", bklshra);
914 nset += bklshra >= 0 && bklshra <= 999; //range 0 to 999
915 }
916 }
917 if (nset == 2)
918 {
919 char cmd[CMD_MAX_LEN] = {0};
920 snprintf(cmd, 9, ":$BD%d#", (int)bklshdec);
922 {
923 BacklashNP.setState(IPS_ALERT);
924 BacklashNP.apply();
925 LOG_ERROR("Error Backlash DEC limit.");
926 }
927 const struct timespec timeout = {0, 100000000L};
928 nanosleep(&timeout, nullptr); // time for OnStep to respond to previous cmd
929 snprintf(cmd, 9, ":$BR%d#", (int)bklshra);
931 {
932 BacklashNP.setState(IPS_ALERT);
933 BacklashNP.apply();
934 LOG_ERROR("Error Backlash RA limit.");
935 }
936
937 BacklashNP[0].setValue(bklshdec);
938 BacklashNP[1].setValue(bklshra);
939 BacklashNP.setState(IPS_OK);
940 BacklashNP.apply();
941 return true;
942 }
943 else
944 {
945 BacklashNP.setState(IPS_ALERT);
946 BacklashNP.apply();
947 LOG_ERROR("Backlash invalid.");
948 return false;
949 }
950 }
951
952 if (ElevationLimitNP.isNameMatch(name))
953 {
954 // new elevation limits
955 double minAlt = 0, maxAlt = 0;
956 int i, nset;
957
958 for (nset = i = 0; i < n; i++)
959 {
960 if (ElevationLimitNP[0].isNameMatch(names[i]))
961 {
962 minAlt = values[i];
963 nset += minAlt >= -30.0 && minAlt <= 30.0; //range -30 to 30
964 }
965 else if (ElevationLimitNP[1].isNameMatch(names[i]))
966 {
967 maxAlt = values[i];
968 nset += maxAlt >= 60.0 && maxAlt <= 90.0; //range 60 to 90
969 }
970 }
971 if (nset == 2)
972 {
973 if (setMinElevationLimit(PortFD, (int)maxAlt) < 0)
974 {
975 ElevationLimitNP.setState(IPS_ALERT);
976 LOG_ERROR("Error setting min elevation limit.");
977 }
978
979 if (setMaxElevationLimit(PortFD, (int)minAlt) < 0)
980 {
981 ElevationLimitNP.setState(IPS_ALERT);
982 ElevationLimitNP.apply();
983 LOG_ERROR("Error setting max elevation limit.");
984 return false;
985 }
986 ElevationLimitNP[0].setValue(minAlt);
987 ElevationLimitNP[1].setValue(maxAlt);
988 ElevationLimitNP.setState(IPS_OK);
989 ElevationLimitNP.apply();
990 return true;
991 }
992 else
993 {
994 ElevationLimitNP.setState(IPS_IDLE);
995 ElevationLimitNP.apply();
996 LOG_ERROR("elevation limit missing or invalid.");
997 return false;
998 }
999 }
1000 }
1001
1002 if (minutesPastMeridianNP.isNameMatch(name))
1003 {
1004 //char cmd[CMD_MAX_LEN] ={0};
1005 int i, nset;
1006 double minPMEast = 0, minPMWest = 0;
1007
1008 for (nset = i = 0; i < n; i++)
1009 {
1010 if (minutesPastMeridianNP[0].isNameMatch(names[i]))
1011 {
1012 minPMEast = values[i];
1013 LOGF_DEBUG("===CMD==> minutesPastMeridianN[0]/East = %f", minPMEast);
1014 nset += minPMEast >= -180 && minPMEast <= 180; //range -180 to 180
1015 }
1016 else if (minutesPastMeridianNP[1].isNameMatch(names[i]))
1017 {
1018 minPMWest = values[i];
1019 LOGF_DEBUG("===CMD==> minutesPastMeridianN[1]/West= %f", minPMWest);
1020 nset += minPMWest >= -180 && minPMWest <= 180; //range -180 to 180
1021 }
1022 }
1023 if (nset == 2)
1024 {
1025 char cmd[CMD_MAX_LEN] = {0};
1026 snprintf(cmd, 20, ":SXE9,%d#", (int) minPMEast);
1028 {
1030 minutesPastMeridianNP.apply();
1031 LOG_ERROR("Error minutesPastMeridian East.");
1032 }
1033 const struct timespec timeout = {0, 100000000L};
1034 nanosleep(&timeout, nullptr); // time for OnStep to respond to previous cmd
1035 snprintf(cmd, 20, ":SXEA,%d#", (int) minPMWest);
1037 {
1039 minutesPastMeridianNP.apply();
1040 LOG_ERROR("Error minutesPastMeridian West.");
1041 }
1042
1043 minutesPastMeridianNP[0].setValue(minPMEast);
1044 minutesPastMeridianNP[1].setValue(minPMWest);
1045 minutesPastMeridianNP.setState(IPS_OK);
1046 minutesPastMeridianNP.apply();
1047 return true;
1048 }
1049 else
1050 {
1052 minutesPastMeridianNP.apply();
1053 LOG_ERROR("minutesPastMeridian invalid.");
1054 return false;
1055 }
1056 }
1057 // Focuser
1058 // Focuser 1 Now handled by Focusr Interface
1059
1060 // Focuser 2 Target
1061 if (OSFocus2TargNP.isNameMatch(name))
1062 {
1063 char cmd[CMD_MAX_LEN] = {0};
1064
1065 if ((values[0] >= -25000) && (values[0] <= 25000))
1066 {
1067 snprintf(cmd, 15, ":fR%d#", (int)values[0]);
1069 OSFocus2TargNP.setState(IPS_OK);
1070 OSFocus2TargNP.apply("Focuser 2 position (relative) moved by %d", (int)values[0]);
1072 }
1073 else
1074 {
1075 OSFocus2TargNP.setState(IPS_ALERT);
1076 OSFocus2TargNP.apply("Setting Max Slew Rate Failed");
1077 }
1078 return true;
1079 }
1080
1081 if (OutputPorts_NP.isNameMatch(name))
1082 {
1083 //go through all output values and see if any value needs to be changed
1084 for(int i = 0; i < n; i++)
1085 {
1086 int value = (int)values[i];
1087 if(OutputPorts_NP[i].getValue() != value)
1088 {
1089 int ret;
1090 char cmd[CMD_MAX_LEN] = {0};
1091 int port = STARTING_PORT + i;
1092
1093 //This is for newer version of OnStep:
1094 snprintf(cmd, sizeof(cmd), ":SXX%d,V%d#", port, value);
1095 //This is for older version of OnStep:
1096 //snprintf(cmd, sizeof(cmd), ":SXG%d,%d#", port, value);
1098
1099 if (ret == -1)
1100 {
1101 LOGF_ERROR("Set port %d to value =%d failed", port, value);
1102 OutputPorts_NP.setState(IPS_ALERT);
1103 return false;
1104 }
1105
1106 OutputPorts_NP.setState(IPS_OK);
1107 OutputPorts_NP[i].setValue(value);
1108 OutputPorts_NP.apply("Set port %d to value =%d", port, value);
1109 }
1110 }
1111 return true;
1112 }
1113 //Weather not handled by Weather Interface
1114
1115 if (OSSetTemperatureNP.isNameMatch(name))
1116 {
1117 // char cmd[CMD_MAX_LEN] = {0};
1118
1119 if ((values[0] >= -100) && (values[0] <= 100))
1120 {
1121 char cmd[CMD_MAX_LEN] = {0};
1122 snprintf(cmd, 15, ":SX9A,%d#", (int)values[0]);
1124 OSSetTemperatureNP.setState(IPS_OK);
1125 OSSetTemperatureNP[0].setValue(values[0]);
1126 OSSetTemperatureNP.apply("Temperature set to %d", (int)values[0]);
1127 }
1128 else
1129 {
1130 OSSetTemperatureNP.setState(IPS_ALERT);
1131 OSSetTemperatureNP.apply("Setting Temperature Failed");
1132 }
1133 return true;
1134 }
1135
1136 if (OSSetHumidityNP.isNameMatch(name))
1137 {
1138 char cmd[CMD_MAX_LEN] = {0};
1139
1140 if ((values[0] >= 0) && (values[0] <= 100))
1141 {
1142 snprintf(cmd, 15, ":SX9C,%d#", (int)values[0]);
1144 OSSetHumidityNP.setState(IPS_OK);
1145 OSSetHumidityNP[0].setValue(values[0]);
1146 OSSetHumidityNP.apply("Humidity set to %d", (int)values[0]);
1147 }
1148 else
1149 {
1150 OSSetHumidityNP.setState(IPS_ALERT);
1151 OSSetHumidityNP.apply("Setting Humidity Failed");
1152 }
1153 return true;
1154 }
1155
1156 if (OSSetPressureNP.isNameMatch(name))
1157 {
1158 char cmd[CMD_MAX_LEN] = {0};
1159
1160 if ((values[0] >= 500) && (values[0] <= 1100)) // typo
1161 {
1162 snprintf(cmd, 15, ":SX9B,%d#", (int)values[0]);
1164 OSSetPressureNP.setState(IPS_OK);
1165 OSSetPressureNP[0].setValue(values[0]);
1166 OSSetPressureNP.apply("Pressure set to %d", (int)values[0]);
1167 }
1168 else
1169 {
1170 OSSetPressureNP.setState(IPS_ALERT);
1171 OSSetPressureNP.apply("Setting Pressure Failed");
1172 }
1173 return true;
1174 }
1175
1176 // Focus T° Compensation
1177 if (TFCCoefficientNP.isNameMatch(name))
1178 {
1179 // :FC[sn.n]# Set focuser temperature compensation coefficient in µ/°C
1180 char cmd[CMD_MAX_LEN] = {0};
1181
1182 if (abs(values[0]) < 1000) //Range is -999.999 .. + 999.999
1183 {
1184 snprintf(cmd, 15, ":FC%+3.5f#", values[0]);
1186 TFCCoefficientNP.setState(IPS_OK);
1187 TFCCoefficientNP.apply("TFC Coefficient set to %+3.5f", values[0]);
1188 }
1189 else
1190 {
1191 TFCCoefficientNP.setState(IPS_ALERT);
1192 TFCCoefficientNP.apply("Setting TFC Coefficient Failed");
1193 }
1194 return true;
1195 }
1196
1197 if (TFCDeadbandNP.isNameMatch(name))
1198 {
1199 // :FD[n]# Set focuser temperature compensation deadband amount (in steps or microns)
1200 char cmd[CMD_MAX_LEN] = {0};
1201
1202 if ((values[0] >= 1) && (values[0] <= 32768)) //Range is 1 .. 32767
1203 {
1204 snprintf(cmd, 15, ":FD%d#", (int)values[0]);
1206 TFCDeadbandNP.setState(IPS_OK);
1207 TFCDeadbandNP.apply("TFC Deadbandset to %d", (int)values[0]);
1208 }
1209 else
1210 {
1211 TFCDeadbandNP.setState(IPS_ALERT);
1212 TFCDeadbandNP.apply("Setting TFC Deadband Failed");
1213 }
1214 return true;
1215 }
1216
1217
1218
1219 // end Focus T° Compensation
1220
1221 if (strstr(name, "WEATHER_"))
1222 {
1223 return WI::processNumber(dev, name, values, names, n);
1224 }
1225
1226 return LX200Generic::ISNewNumber(dev, name, values, names, n);
1227}
1228
1229bool LX200_OnStep::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
1230{
1231 int index = 0;
1232
1233 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
1234 {
1235 //Intercept Before inditelescope base can set TrackState
1236 //Next one modification of inditelescope.cpp function
1237 if (TrackStateSP.isNameMatch(name))
1238 {
1239 // int previousState = IUFindOnSwitchIndex(&TrackStateSP);
1240 TrackStateSP.update(states, names, n);
1241 int targetState = TrackStateSP.findOnSwitchIndex();
1242 // LOG_DEBUG("OnStep driver TrackStateSP override called");
1243 // if (previousState == targetState)
1244 // {
1245 // TrackStateSP.apply();
1246 // return true;
1247 // }
1248
1249 if (TrackState == SCOPE_PARKED)
1250 {
1251 LOG_WARN("Telescope is Parked, Unpark before tracking.");
1252 return false;
1253 }
1254
1255 bool rc = SetTrackEnabled((targetState == TRACK_ON) ? true : false);
1256
1257 if (rc)
1258 {
1259 return true;
1260 //TrackStateSP moved to Update
1261 }
1262 else
1263 {
1264 //This is the case for an error on sending the command, so change TrackStateSP
1265 TrackStateSP.setState(IPS_ALERT);
1266 TrackStateSP.reset();
1267 return false;
1268 }
1269
1270 LOG_DEBUG("TrackStateSP intercept, OnStep driver, should never get here");
1271 return false;
1272 }
1273
1274
1275
1276 // Reticlue +/- Buttons
1277 if (ReticSP.isNameMatch(name))
1278 {
1279 int ret = 0;
1280 ReticSP.update(states, names, n);
1281 ReticSP.setState(IPS_OK);
1282
1283 if (ReticSP[0].getState() == ISS_ON)
1284 {
1285 ret = increaseReticleBrightness(PortFD); //in lx200driver
1286 ReticSP[0].setState(ISS_OFF);
1287 ReticSP.apply("Bright");
1288 }
1289 else
1290 {
1291 ret = decreaseReticleBrightness(PortFD); //in lx200driver
1292 ReticSP[1].setState(ISS_OFF);
1293 ReticSP.apply("Dark");
1294 }
1295
1296 INDI_UNUSED(ret);
1297 ReticSP.reset();
1298 ReticSP.apply();
1299 return true;
1300 }
1301 //Move to more standard controls
1302 if (SlewRateSP.isNameMatch(name))
1303 {
1304 SlewRateSP.update(states, names, n);
1305 int ret;
1306 char cmd[CMD_MAX_LEN] = {0};
1307 int index = SlewRateSP.findOnSwitchIndex() ;//-1; //-1 because index is 1-10, OS Values are 0-9
1308 snprintf(cmd, sizeof(cmd), ":R%d#", index);
1310
1311 //if (setMaxSlewRate(PortFD, (int)values[0]) < 0) //(int) MaxSlewRateN[0].value
1312 if (ret == -1)
1313 {
1314 LOGF_DEBUG("Pas OK Return value =%d", ret);
1315 LOGF_DEBUG("Setting Max Slew Rate to %u\n", index);
1316 SlewRateSP.setState(IPS_ALERT);
1317 LOG_ERROR("Setting Max Slew Rate Failed");
1318 SlewRateSP.apply();
1319 return false;
1320 }
1321 LOGF_INFO("Setting Max Slew Rate to %u (%s) \n", index, SlewRateSP[index].getLabel());
1322 LOGF_DEBUG("OK Return value =%d", ret);
1323 MaxSlewRateNP.setState(IPS_OK);
1324 MaxSlewRateNP[0].setValue(index);
1325 MaxSlewRateNP.apply("Slewrate set to %d", index);
1326 SlewRateSP.reset();
1327 SlewRateSP[index].setState(ISS_ON);
1328 SlewRateSP.setState(IPS_OK);
1329 SlewRateSP.apply();
1330 return true;
1331 }
1332
1333 // Tracking Compensation selection
1334 if (TrackCompSP.isNameMatch(name))
1335 {
1336 TrackCompSP.update(states, names, n);
1337 TrackCompSP.setState(IPS_BUSY);
1338
1339 if (TrackCompSP[0].getState() == ISS_ON)
1340 {
1341 if (!sendOnStepCommand(":To#"))
1342 {
1343 TrackCompSP.setState(IPS_OK);
1344 TrackCompSP.apply("Full Compensated Tracking On");
1345 return true;
1346 }
1347 }
1348 if (TrackCompSP[1].getState() == ISS_ON)
1349 {
1350 if (!sendOnStepCommand(":Tr#"))
1351 {
1352 TrackCompSP.setState(IPS_OK);
1353 TrackCompSP.apply("Refraction Tracking On");
1354 return true;
1355 }
1356 }
1357 if (TrackCompSP[2].getState() == ISS_ON)
1358 {
1359 if (!sendOnStepCommand(":Tn#"))
1360 {
1361 TrackCompSP.setState(IPS_OK);
1362 TrackCompSP.apply("Refraction Tracking Disabled");
1363 return true;
1364 }
1365 }
1366 TrackCompSP.reset();
1367 TrackCompSP.setState(IPS_IDLE);
1368 TrackCompSP.apply();
1369 return true;
1370 }
1371
1372 if (TrackAxisSP.isNameMatch(name))
1373 {
1374 TrackAxisSP.update(states, names, n);
1375 TrackAxisSP.setState(IPS_BUSY);
1376
1377 if (TrackAxisSP[0].getState() == ISS_ON)
1378 {
1379 if (!sendOnStepCommand(":T1#"))
1380 {
1381 TrackAxisSP.setState(IPS_OK);
1382 TrackAxisSP.apply("Single Tracking On");
1383 return true;
1384 }
1385 }
1386 if (TrackAxisSP[1].getState() == ISS_ON)
1387 {
1388 if (!sendOnStepCommand(":T2#"))
1389 {
1390 TrackAxisSP.setState(IPS_OK);
1391 TrackAxisSP.apply("Dual Axis Tracking On");
1392 return true;
1393 }
1394 }
1395 TrackAxisSP.reset();
1396 TrackAxisSP.setState(IPS_IDLE);
1397 TrackAxisSP.apply();
1398 return true;
1399 }
1400
1401 if (AutoFlipSP.isNameMatch(name))
1402 {
1403 AutoFlipSP.update(states, names, n);
1404 AutoFlipSP.setState(IPS_BUSY);
1405
1406 if (AutoFlipSP[0].getState() == ISS_ON)
1407 {
1408 if (sendOnStepCommand(":SX95,0#"))
1409 {
1410 AutoFlipSP.setState(IPS_OK);
1411 AutoFlipSP.apply("Auto Meridian Flip OFF");
1412 return true;
1413 }
1414 }
1415 if (AutoFlipSP[1].getState() == ISS_ON)
1416 {
1417 if (sendOnStepCommand(":SX95,1#"))
1418 {
1419 AutoFlipSP.setState(IPS_OK);
1420 AutoFlipSP.apply("Auto Meridian Flip ON");
1421 return true;
1422 }
1423 }
1424 AutoFlipSP.reset();
1425 //AutoFlipSP.setState(IPS_IDLE);
1426 AutoFlipSP.apply();
1427 return true;
1428 }
1429
1430 if (HomePauseSP.isNameMatch(name))
1431 {
1432 HomePauseSP.update(states, names, n);
1433 HomePauseSP.setState(IPS_BUSY);
1434
1435 if (HomePauseSP[0].getState() == ISS_ON)
1436 {
1437 if (sendOnStepCommand(":SX98,0#"))
1438 {
1439 HomePauseSP.setState(IPS_OK);
1440 HomePauseSP.apply("Home Pause OFF");
1441 return true;
1442 }
1443 }
1444 if (HomePauseSP[1].getState() == ISS_ON)
1445 {
1446 if (sendOnStepCommand(":SX98,1#"))
1447 {
1448 HomePauseSP.setState(IPS_OK);
1449 HomePauseSP.apply("Home Pause ON");
1450 return true;
1451 }
1452 }
1453 if (HomePauseSP[2].getState() == ISS_ON)
1454 {
1455 if (sendOnStepCommand(":SX99,1#"))
1456 {
1457 HomePauseSP.reset();
1458 HomePauseSP.setState(IPS_OK);
1459 HomePauseSP.apply("Home Pause: Continue");
1460 return true;
1461 }
1462 }
1463 HomePauseSP.reset();
1464 HomePauseSP.setState(IPS_IDLE);
1465 HomePauseSP.apply();
1466 return true;
1467 }
1468
1469 if (FrequencyAdjustSP.isNameMatch(name)) //
1470
1471 //
1472 {
1473 FrequencyAdjustSP.update(states, names, n);
1474 FrequencyAdjustSP.setState(IPS_OK);
1475
1476 if (FrequencyAdjustSP[0].getState() == ISS_ON)
1477 {
1478 if (!sendOnStepCommandBlind(":T-#"))
1479 {
1480 FrequencyAdjustSP.apply("Frequency decreased");
1481 return true;
1482 }
1483 }
1484 if (FrequencyAdjustSP[1].getState() == ISS_ON)
1485 {
1486 if (!sendOnStepCommandBlind(":T+#"))
1487 {
1488 FrequencyAdjustSP.apply("Frequency increased");
1489 return true;
1490 }
1491 }
1492 if (FrequencyAdjustSP[2].getState() == ISS_ON)
1493 {
1494 if (!sendOnStepCommandBlind(":TR#"))
1495 {
1496 FrequencyAdjustSP.apply("Frequency Reset (TO saved EEPROM)");
1497 return true;
1498 }
1499 }
1500 FrequencyAdjustSP.reset();
1501 FrequencyAdjustSP.setState(IPS_IDLE);
1502 FrequencyAdjustSP.apply();
1503 return true;
1504 }
1505
1506 //Pier Side
1507 if (PreferredPierSideSP.isNameMatch(name))
1508 {
1509 PreferredPierSideSP.update(states, names, n);
1510 PreferredPierSideSP.setState(IPS_BUSY);
1511
1512 if (PreferredPierSideSP[0].getState() == ISS_ON) //West
1513 {
1514 if (sendOnStepCommand(":SX96,W#"))
1515 {
1516 PreferredPierSideSP.setState(IPS_OK);
1517 PreferredPierSideSP.apply("Preferred Pier Side: West");
1518 return true;
1519 }
1520 }
1521 if (PreferredPierSideSP[1].getState() == ISS_ON) //East
1522 {
1523 if (sendOnStepCommand(":SX96,E#"))
1524 {
1525 PreferredPierSideSP.setState(IPS_OK);
1526 PreferredPierSideSP.apply("Preferred Pier Side: East");
1527 return true;
1528 }
1529 }
1530 if (PreferredPierSideSP[2].getState() == ISS_ON) //Best
1531 {
1532 if (sendOnStepCommand(":SX96,B#"))
1533 {
1534 PreferredPierSideSP.setState(IPS_OK);
1535 PreferredPierSideSP.apply("Preferred Pier Side: Best");
1536 return true;
1537 }
1538 }
1539 PreferredPierSideSP.reset();
1540 PreferredPierSideSP.apply();
1541 return true;
1542 }
1543
1544
1545 // Focuser
1546 // Focuser 1 Rates
1547 if (OSFocus1InitializeSP.isNameMatch(name))
1548 {
1549 char cmd[CMD_MAX_LEN] = {0};
1550 OSFocus1InitializeSP.update(states, names, n);
1551 index = OSFocus1InitializeSP.findOnSwitchIndex();
1552 if (index == 0)
1553 {
1554 snprintf(cmd, 5, ":FZ#");
1556 OSFocus1InitializeSP[index].setState(ISS_OFF);
1557 OSFocus1InitializeSP.setState(IPS_OK);
1558 OSFocus1InitializeSP.apply();
1559 }
1560 if (index == 1)
1561 {
1562 snprintf(cmd, 5, ":FH#");
1564 OSFocus1InitializeSP[index].setState(ISS_OFF);
1565 OSFocus1InitializeSP.setState(IPS_OK);
1566 OSFocus1InitializeSP.apply();
1567 }
1568 return true;
1569 }
1570
1571
1572 //Focuser Swap/Select
1573 if (OSFocusSelectSP.isNameMatch(name))
1574 {
1575 char cmd[CMD_MAX_LEN] = {0};
1576 OSFocusSelectSP.update(states, names, n);
1577 index = OSFocusSelectSP.findOnSwitchIndex();
1578 LOGF_INFO("Primary focuser set: Focuser 1 in INDI/Controllable Focuser = OnStep Focuser %d", index + 1);
1579 if (index == 0 && OSNumFocusers <= 2)
1580 {
1581 LOG_INFO("If using OnStep: Focuser 2 in INDI = OnStep Focuser 2");
1582 }
1583 if (index == 1 && OSNumFocusers <= 2)
1584 {
1585 LOG_INFO("If using OnStep: Focuser 2 in INDI = OnStep Focuser 1");
1586 }
1587 if (OSNumFocusers > 2)
1588 {
1589 LOGF_INFO("If using OnStepX, There is no swap, and current max number: %d", OSNumFocusers);
1590 }
1591 snprintf(cmd, 7, ":FA%d#", index + 1 );
1592 OSFocusSelectSP.reset();
1593 OSFocusSelectSP[index].setState(ISS_ON);
1594 if (!sendOnStepCommand(cmd))
1595 {
1596 OSFocusSelectSP.setState(IPS_BUSY);
1597 }
1598 else
1599 {
1600 OSFocusSelectSP.setState(IPS_ALERT);
1601 }
1602 OSFocusSelectSP.apply();
1603 return true;
1604 }
1605
1606
1607 // Focuser 2 Rates
1608 if (OSFocus2RateSP.isNameMatch(name))
1609 {
1610 char cmd[CMD_MAX_LEN] = {0};
1611 OSFocus2RateSP.update(states, names, n);
1612 index = OSFocus2RateSP.findOnSwitchIndex();
1613 snprintf(cmd, 5, ":F%d#", index + 1);
1615 OSFocus2RateSP[index].setState(ISS_OFF);
1616 OSFocus2RateSP.setState(IPS_OK);
1617 OSFocus2RateSP.apply();
1618 return true;
1619 }
1620 // Focuser 2 Motion
1621 if (OSFocus2MotionSP.isNameMatch(name))
1622 {
1623 char cmd[CMD_MAX_LEN] = {0};
1624 OSFocus2MotionSP.update(states, names, n);
1625 index = OSFocus2MotionSP.findOnSwitchIndex();
1626 if (index == 0)
1627 {
1628 strncpy(cmd, ":f+#", sizeof(cmd));
1629 }
1630 if (index == 1)
1631 {
1632 strncpy(cmd, ":f-#", sizeof(cmd));
1633 }
1634 if (index == 2)
1635 {
1636 strncpy(cmd, ":fQ#", sizeof(cmd));
1637 }
1639 const struct timespec timeout = {0, 100000000L};
1640 nanosleep(&timeout, nullptr); // Pulse 0,1 s
1641 if(index != 2)
1642 {
1643 sendOnStepCommandBlind(":fQ#");
1644 }
1645 OSFocus2MotionSP[index].setState(ISS_OFF);
1646 OSFocus2MotionSP.setState(IPS_OK);
1647 OSFocus2MotionSP.apply();
1648 return true;
1649 }
1650
1651 //Rotator De-rotation
1652 if (OSRotatorDerotateSP.isNameMatch(name))
1653 {
1654 char cmd[CMD_MAX_LEN] = {0};
1655 OSRotatorDerotateSP.update(states, names, n);
1656 index = OSRotatorDerotateSP.findOnSwitchIndex();
1657 if (index == 0) //Derotate_OFF
1658 {
1659 strncpy(cmd, ":r-#", sizeof(cmd));
1660 }
1661 if (index == 1) //Derotate_ON
1662 {
1663 strncpy(cmd, ":r+#", sizeof(cmd));
1664 }
1666 OSRotatorDerotateSP[index].setState(ISS_OFF);
1667 OSRotatorDerotateSP.setState(IPS_IDLE);
1668 OSRotatorDerotateSP.apply();
1669 return true;
1670 }
1671
1672 // PEC
1673 if (OSPECRecordSP.isNameMatch(name))
1674 {
1675 OSPECRecordSP.update(states, names, n);
1676 OSPECRecordSP.setState(IPS_OK);
1677
1678 if (OSPECRecordSP[0].getState() == ISS_ON)
1679 {
1680 OSPECEnabled = true;
1681 ClearPECBuffer(0);
1682 OSPECRecordSP[0].setState(ISS_OFF);
1683 }
1684 if (OSPECRecordSP[1].getState() == ISS_ON)
1685 {
1686 OSPECEnabled = true;
1687 StartPECRecord(0);
1688 OSPECRecordSP[1].setState(ISS_OFF);
1689 }
1690 if (OSPECRecordSP[2].getState() == ISS_ON)
1691 {
1692 OSPECEnabled = true;
1693 SavePECBuffer(0);
1694 OSPECRecordSP[2].setState(ISS_OFF);
1695 }
1696 OSPECRecordSP.apply();
1697 return true;
1698 }
1699 if (OSPECReadSP.isNameMatch(name))
1700 {
1701 OSPECReadSP.update(states, names, n);
1702 if (OSPECReadSP[0].getState() == ISS_ON)
1703 {
1704 OSPECEnabled = true;
1705 ReadPECBuffer(0);
1706 OSPECReadSP[0].setState(ISS_OFF);
1707 }
1708 if (OSPECReadSP[1].getState() == ISS_ON)
1709 {
1710 OSPECEnabled = true;
1711 WritePECBuffer(0);
1712 OSPECReadSP[1].setState(ISS_OFF);
1713 }
1714 OSPECReadSP.apply();
1715 return true;
1716 }
1717 if (PECStateSP.isNameMatch(name))
1718 {
1719 PECStateSP.update(states, names, n);
1720 index = PECStateSP.findOnSwitchIndex();
1721 if (index == 0)
1722 {
1723 OSPECEnabled = true;
1724 StopPECPlayback(0); //Status will set OSPECEnabled to false if that's set by the controller
1725 PECStateSP[PEC_OFF].setState(ISS_ON);
1726 PECStateSP[PEC_ON].setState(ISS_OFF);
1727 PECStateSP.apply();
1728 }
1729 else if (index == 1)
1730 {
1731 OSPECEnabled = true;
1733 PECStateSP[PEC_OFF].setState(ISS_OFF);
1734 PECStateSP[PEC_ON].setState(ISS_ON);
1735 PECStateSP.apply();
1736 }
1737 return true;
1738 }
1739
1740 // Align Buttons
1741 if (OSNAlignStarsSP.isNameMatch(name))
1742 {
1743 OSNAlignStarsSP.reset();
1744 OSNAlignStarsSP.update(states, names, n);
1745 return true;
1746 }
1747
1748 // Alignment
1749 if (OSNAlignSP.isNameMatch(name))
1750 {
1751 OSNAlignSP.update(states, names, n);
1752 index = OSNAlignSP.findOnSwitchIndex();
1753 //NewGeometricAlignment
1754 //End NewGeometricAlignment
1755 OSNAlignSP.setState(IPS_BUSY);
1756 if (index == 0)
1757 {
1758 /* Index is 0-8 and represents index+1*/
1759 int index_stars = OSNAlignStarsSP.findOnSwitchIndex();
1760 if ((index_stars <= 8) && (index_stars >= 0))
1761 {
1762 int stars = index_stars + 1;
1763 OSNAlignSP[0].setState(ISS_OFF);
1764 LOGF_INFO("Align index: %d, stars: %d", index_stars, stars);
1765 AlignStartGeometric(stars);
1766 }
1767 }
1768 if (index == 1)
1769 {
1770 OSNAlignSP[1].setState(ISS_OFF);
1771 OSNAlignSP.setState(AlignAddStar());
1772 }
1773 //Write to EEPROM moved to new line/variable
1774 OSNAlignSP.apply();
1776 return true;
1777 }
1778
1779 if (OSNAlignWriteSP.isNameMatch(name))
1780 {
1781 OSNAlignWriteSP.update(states, names, n);
1782 index = OSNAlignWriteSP.findOnSwitchIndex();
1783 OSNAlignWriteSP.setState(IPS_BUSY);
1784 if (index == 0)
1785 {
1786 OSNAlignWriteSP[0].setState(ISS_OFF);
1787 OSNAlignWriteSP.setState(AlignWrite());
1788 }
1789 OSNAlignWriteSP.apply();
1791 return true;
1792 }
1793
1794 if (OSNAlignPolarRealignSP.isNameMatch(name))
1795 {
1796 char cmd[CMD_MAX_LEN] = {0};
1797 char response[RB_MAX_LEN];
1798 OSNAlignPolarRealignSP.update(states, names, n);
1800 if (OSNAlignPolarRealignSP[0].getState() == ISS_ON) //INFO
1801 {
1802 OSNAlignPolarRealignSP[0].setState(ISS_OFF);
1803 LOG_INFO("Step 1: Goto a bright star between 50 and 80 degrees N/S from the pole. Preferably on the Meridian.");
1804 LOG_INFO("Step 2: Make sure it is centered.");
1805 LOG_INFO("Step 3: Press Refine Polar Alignment.");
1806 LOG_INFO("Step 4: Using the mount's Alt and Az screws manually recenter the star. (Video mode if your camera supports it will be helpful.)");
1807 LOG_INFO("Optional: Start a new alignment.");
1808 OSNAlignPolarRealignSP.apply();
1810 return true;
1811 }
1812 if (OSNAlignPolarRealignSP[1].getState() == ISS_ON)
1813 {
1814 OSNAlignPolarRealignSP[1].setState(ISS_OFF);
1815 // int returncode=sendOnStepCommand("
1816 snprintf(cmd, 5, ":MP#");
1817 // Returns:
1818 // 0=goto is possible
1819 // 1=below the horizon limit
1820 // 2=above overhead limit
1821 // 3=controller in standby
1822 // 4=mount is parked
1823 // 5=goto in progress
1824 // 6=outside limits
1825 // 7=hardware fault
1826 // 8=already in motion
1827 // 9=unspecified error
1828
1829 int res = getCommandSingleCharResponse(PortFD, response, cmd); //0 = 0 Success 1..9 failure, no # on reply
1830 if(res > 0 && response[0] == '0')
1831 {
1832 LOG_INFO("Command for Refine Polar Alignment Successful");
1835 OSNAlignPolarRealignSP.apply();
1836 return true;
1837 }
1838 else
1839 {
1840 LOGF_ERROR("Command for Refine Polar Alignment Failed, error=%s", response[0]);
1843 OSNAlignPolarRealignSP.apply();
1844 return false;
1845 }
1846 }
1847 return true;
1848 }
1849
1850 // Focus T° Compensation
1851 if (TFCCompensationSP.isNameMatch(name))
1852 {
1853 // :Fc[n]# Enable/disable focuser temperature compensation where [n] = 0 or 1
1854 // Return: 0 on failure
1855 // 1 on success
1856 char cmd[CMD_MAX_LEN] = {0};
1857 int ret = 0;
1858 TFCCompensationSP.update(states, names, n);
1859 TFCCompensationSP.setState(IPS_OK);
1860
1861 if (TFCCompensationSP[0].getState() == ISS_ON)
1862 {
1863 snprintf(cmd, sizeof(cmd), ":Fc0#");
1865 //TFCCompensationSP[0].setState(ISS_OFF);
1866 TFCCompensationSP.apply("Idle");
1867 }
1868 else
1869 {
1870 snprintf(cmd, sizeof(cmd), ":Fc1#");
1872 //TFCCompensationSP[1].setState(ISS_OFF);
1873 TFCCompensationSP.apply("Idle");
1874 }
1875
1876 INDI_UNUSED(ret);
1877 TFCCompensationSP.reset();
1878 TFCCompensationSP.apply();
1879 return true;
1880 }
1881 //End Focus T° Compensation
1882
1883#ifdef ONSTEP_NOTDONE
1884 if (OSOutput1SP.isNameMatch(name)) //
1885 {
1886 OSOutput1SP.update(states, names, n);
1887 if (OSOutput1SP[0].getState() == ISS_ON)
1888 {
1889 OSDisableOutput(1);
1890 //OSOutput1SP[0].setState(ISS_OFF);
1891 }
1892 else if (OSOutput1SP[1].getState() == ISS_ON)
1893 {
1894 OSEnableOutput(1);
1895 //OSOutput1SP[1].setState(ISS_OFF);
1896 }
1897 OSOutput1SP.apply();
1898 return true;
1899 }
1900 if (OSOutput2SP.isNameMatch(name)) //
1901 {
1902 OSOutput2SP.update(states, names, n);
1903 if (OSOutput2SP[0].getState() == ISS_ON)
1904 {
1905 OSDisableOutput(2);
1906 //OSOutput2SP[0].setState(ISS_OFF);
1907 }
1908 else if (OSOutput2SP[1].getState() == ISS_ON)
1909 {
1910 OSEnableOutput(2);
1911 //OSOutput2SP[1].setState(ISS_OFF);
1912 }
1913 OSOutput2SP.apply();
1914 return true;
1915 }
1916#endif
1917
1918 // Focuser
1919 if (strstr(name, "FOCUS"))
1920 {
1921 return FI::processSwitch(dev, name, states, names, n);
1922 }
1923 // Focuser
1924 if (strstr(name, "ROTATOR"))
1925 {
1926 return RI::processSwitch(dev, name, states, names, n);
1927 }
1928 }
1929
1930 return LX200Generic::ISNewSwitch(dev, name, states, names, n);
1931}
1932
1934{
1935 // process parent
1937
1938 if (!isSimulation())
1939 {
1940 char buffer[128] = {0};
1941 getVersionDate(PortFD, buffer);
1942 VersionTP[0].setText(buffer);
1943 getVersionTime(PortFD, buffer);
1944 VersionTP[1].setText(buffer);
1945 getVersionNumber(PortFD, buffer);
1946 VersionTP[2].setText(buffer);
1947 getProductName(PortFD, buffer);
1948 VersionTP[3].setText(buffer);
1949
1950 VersionTP.apply();
1951 if ((VersionTP[2].getText()[0] == '1' || VersionTP[2].getText()[0] == '2') && (VersionTP[2].getText()[1] == '.' )
1952 && (strcmp(VersionTP[3].getText(), "OnStep") || strcmp(VersionTP[3].getText(), "On-Step")))
1953 {
1954 LOG_INFO("Old OnStep (V1/V2 depreciated) detected, setting some defaults");
1955 LOG_INFO("Note: Everything should work, but it may have timeouts in places, as it's not tested against.");
1956 OSHighPrecision = false;
1958 }
1959 else if (VersionTP[2].getText()[0] == '3' && (strcmp(VersionTP[3].getText(), "OnStep")
1960 || strcmp(VersionTP[3].getText(), "On-Step")))
1961 {
1962 LOG_INFO("V3 OnStep detected, setting some defaults");
1963 OSHighPrecision = false;
1965 }
1966 else if (VersionTP[2].getText()[0] == '4' && (strcmp(VersionTP[3].getText(), "OnStep")
1967 || strcmp(VersionTP[3].getText(), "On-Step")))
1968 {
1969 LOG_INFO("V4 OnStep detected, setting some defaults");
1970 OSHighPrecision = true;
1972 }
1973 else if (VersionTP[2].getText()[0] == '5' && (strcmp(VersionTP[3].getText(), "OnStep")
1974 || strcmp(VersionTP[3].getText(), "On-Step")))
1975 {
1976 LOG_INFO("V5 OnStep detected, setting some defaults");
1977 OSHighPrecision = true;
1979 }
1980 else if (VersionTP[2].getText()[0] == '1' && VersionTP[2].getText()[1] == '0' && VersionTP[2].getText()[2] == '.'
1981 && (strcmp(VersionTP[3].getText(), "OnStepX") || strcmp(VersionTP[3].getText(), "On-Step")))
1982 {
1983 LOG_INFO("OnStepX detected, setting some defaults");
1984 OSHighPrecision = true;
1986 }
1987 else
1988 {
1989 LOG_INFO("OnStep/OnStepX version could not be detected");
1990 OSHighPrecision = false;
1992 }
1993
1994 // Query the current mount type with the LX200 alignment status :GW#, whose first character is
1995 // A = AltAz, P = Polar (Fork), G = German (GEM). Do not use :GXEM#: it returns the mount mode
1996 // OnStepX will use after the next reboot (as set by :SXEM#), not the one it is running now.
1997 // If :GW# gives no usable answer, the mount type is taken from the :GU# status string during
1998 // the first ReadScopeStatus(), which also keeps it in sync afterwards.
1999 bool mountTypeDetected = false;
2000 char mountTypeResponse[RB_MAX_LEN] = {0};
2001 int gw_error = getCommandSingleCharErrorOrLongResponse(PortFD, mountTypeResponse, ":GW#");
2002 if (gw_error > 0)
2003 {
2004 mountTypeDetected = true;
2005 switch (mountTypeResponse[0])
2006 {
2007 case 'A':
2010 LOG_INFO("Mount type detected: AltAz");
2011 break;
2012 case 'P':
2015 LOG_INFO("Mount type detected: Fork (Equatorial)");
2016 break;
2017 case 'G':
2020 LOG_INFO("Mount type detected: GEM");
2021 break;
2022 default:
2023 mountTypeDetected = false;
2024 break;
2025 }
2026 }
2027
2028 if (!mountTypeDetected)
2029 LOGF_WARN("Could not determine mount type via :GW# (error %d, reply '%s'), "
2030 "it will be determined from :GU# status", gw_error, mountTypeResponse);
2031
2032 if (InitPark())
2033 {
2034 // If loading parking data is successful, we just set the default parking values.
2035 LOG_INFO("=============== Parkdata loaded");
2036 }
2037 else
2038 {
2039 // Otherwise, we set all parking data to default in case no parking data is found.
2040 LOG_INFO("=============== Parkdata Load Failed");
2041 }
2042 }
2043}
2044
2045//======================== Parking =======================
2047{
2048 char response[RB_MAX_LEN];
2049 // 0 = failure, 1 = success
2050 int error_or_fail = getCommandSingleCharResponse(PortFD, response, ":hQ#");
2051 if(error_or_fail != 1 || response[0] != '1')
2052 {
2053 LOGF_WARN("===CMD==> Set Park Pos %s", response);
2054 return false;
2055 }
2058 LOG_WARN("Park Value set to current position");
2059 return true;
2060}
2061
2063{
2064 IDMessage(getDeviceName(), "Setting Park Data to Default.");
2065 SetAxis1Park(20);
2066 SetAxis2Park(80);
2067 LOG_WARN("Park Position set to Default value, 20/80");
2068 return true;
2069}
2070
2072{
2073 char response[RB_MAX_LEN];
2074
2075
2076 if (!isSimulation())
2077 {
2078 int failure_or_error = getCommandSingleCharResponse(PortFD, response, ":hR#"); //0 = failure, 1 = success, no # on reply
2079 if ((response[0] != '1') || (failure_or_error < 0))
2080 {
2081 return false;
2082 }
2083 }
2084 return true;
2085}
2086
2088{
2089 if (!isSimulation())
2090 {
2091 // If scope is moving, let's stop it first.
2092 if (EqNP.getState() == IPS_BUSY)
2093 {
2094 if (!isSimulation() && abortSlew(PortFD) < 0)
2095 {
2096 Telescope::AbortSP.setState(IPS_ALERT);
2097 LOG_ERROR("Abort slew failed.");
2098 Telescope::AbortSP.apply();
2099 return false;
2100 }
2101 Telescope::AbortSP.setState(IPS_OK);
2102 EqNP.setState(IPS_IDLE);
2103 LOG_ERROR("Slew aborted.");
2104 Telescope::AbortSP.apply();
2105 EqNP.apply();
2106
2107 if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)
2108 {
2109 MovementNSSP.setState(IPS_IDLE);
2110 MovementWESP.setState(IPS_IDLE);
2111 EqNP.setState(IPS_IDLE);
2112 MovementNSSP.reset();
2113 MovementWESP.reset();
2114
2115 MovementNSSP.apply();
2116 MovementWESP.apply();
2117 }
2118 }
2119 if (!isSimulation() && slewToPark(PortFD) < 0)
2120 {
2121 ParkSP.setState(IPS_ALERT);
2122 LOG_ERROR("Parking Failed.");
2123 ParkSP.apply();
2124 return false;
2125 }
2126 }
2127 ParkSP.setState(IPS_BUSY);
2128 // Report the park as running until OnStep reports it parked (see ReadScopeStatus()). Without this the base class
2129 // marks the park done as soon as the command is sent, and clients disconnect while the mount still moves.
2131 m_ParkStartTime = std::chrono::steady_clock::now();
2132 LOG_INFO("Parking telescope in progress...");
2133 return true;
2134}
2135
2136// Periodically Polls OnStep Parameter from controller
2137// The reason for the :GU# error codes that make OnStep stop the mount (limits, faults), nullptr for the others
2138static const char *gotoStopReason(Errors error)
2139{
2140 switch (error)
2141 {
2142 case ERR_MOTOR_FAULT:
2143 return "Motor/Driver Fault";
2144 case ERR_ALT_MIN:
2145 return "Below Horizon Limit";
2146 case ERR_LIMIT_SENSE:
2147 return "Limit Sense";
2148 case ERR_DEC:
2149 return "Dec Limit Exceeded";
2150 case ERR_AZM:
2151 return "Azm Limit Exceeded";
2152 case ERR_UNDER_POLE:
2153 return "Under Pole Limit Exceeded";
2154 case ERR_MERIDIAN:
2155 // OnStepX reports both sides with this code
2156 return "Meridian Limit Exceeded";
2157 case ERR_ALT_MAX:
2158 return "Above Overhead Limit";
2159 default:
2160 return nullptr;
2161 }
2162}
2163
2165{
2166 char OSbacklashDEC[RB_MAX_LEN] = {0};
2167 char OSbacklashRA[RB_MAX_LEN] = {0};
2168 char GuideValue[RB_MAX_LEN] = {0};
2169 // int i;
2170 bool pier_not_set = true; // Avoid a call to :Gm if :GU it
2171 Errors Lasterror = ERR_NONE;
2172
2173
2174 if (isSimulation()) //if Simulation is selected
2175 {
2176 mountSim();
2177 return true;
2178 }
2179
2180 tcflush(PortFD, TCIOFLUSH);
2181 flushIO(PortFD);
2182
2183
2184#ifdef OnStep_Alpha
2185 OSSupports_bitfield_Gu = try_bitfield_Gu();
2186
2188 {
2189 //Fall back to :GU parsing
2190#endif
2191
2193 ":GU#"); // :GU# returns a string containing controller status
2194 if (error_or_fail > 1) // check if successful read (strcmp(OSStat, OldOSStat) != 0) //if status changed
2195 {
2196 //If this fails, simply return;
2197 char check_GU_valid1[RB_MAX_LEN] = {0};
2198 char check_GU_valid2[RB_MAX_LEN] = {0};
2199 char check_GU_valid3[RB_MAX_LEN] = {0};
2200 //:GU should always have one of pIPF and 3 numbers
2201 if (sscanf(OSStat, "%s%[pIPF]%s%[0-9]%[0-9]%[0-9]", check_GU_valid1, &check_GU_valid2[0], check_GU_valid3,
2202 &check_GU_valid2[1], &check_GU_valid2[2], &check_GU_valid2[3]) != 1)
2203 {
2204 LOG_WARN(":GU# returned something that can not be right, this update aborted, will try again...");
2205 LOGF_DEBUG("Parameters matched: %u from %s", sscanf(OSStat, "%s%[pIPF]%s%[0-9]%[0-9]%[0-9]", check_GU_valid1,
2206 &check_GU_valid2[0], check_GU_valid3, &check_GU_valid2[1], &check_GU_valid2[2], &check_GU_valid2[3]), OSStat);
2207 flushIO(PortFD);
2208 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
2209 }
2210 if (getLX200RA(PortFD, &currentRA) < 0 || getLX200DEC(PortFD, &currentDEC) < 0) // Update actual position
2211 {
2212 EqNP.setState(IPS_ALERT);
2213 LOG_ERROR("Error reading RA/DEC.");
2214 EqNP.apply();
2215 LOG_INFO("RA/DEC could not be read, possible solution if using (wireless) ethernet: Use port 9998");
2216 LOG_WARN("This update aborted, will try again...");
2217 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
2218 }
2219 snprintf(OldOSStat, sizeof(OldOSStat), "%s", OSStat);
2220
2221 OnstepStatTP[0].setText(OSStat);
2222
2223 // ============= Parkstatus
2224
2225#ifdef DEBUG_TRACKSTATE
2226 LOG_DEBUG("Prior TrackState:");
2228 LOG_DEBUG("^ Prior");
2229#endif
2230 //TelescopeStatus PriorTrackState = TrackState;
2231 // not [p]arked, parking [I]n-progress, [P]arked, Park [F]ailed
2232 // "P" (Parked moved to Telescope Status, since it would override any other TrackState
2233 // Other than parked, none of these affect TrackState
2234 if (strstr(OSStat, "F"))
2235 {
2236 OnstepStatTP[3].setText("Parking Failed");
2237 }
2238 if (strstr(OSStat, "I"))
2239 {
2240 OnstepStatTP[3].setText("Park in Progress");
2241 }
2242 if (strstr(OSStat, "p"))
2243 {
2244 OnstepStatTP[3].setText("UnParked");
2245 }
2246 // ============= End Parkstatus
2247
2248
2249
2250
2251 // ============= Error Code
2252 //From OnStep: ERR_NONE, ERR_MOTOR_FAULT, ERR_ALT_MIN, ERR_LIMIT_SENSE, ERR_DEC, ERR_AZM, ERR_UNDER_POLE, ERR_MERIDIAN, ERR_SYNC, ERR_PARK, ERR_GOTO_SYNC, ERR_UNSPECIFIED, ERR_ALT_MAX, ERR_GOTO_ERR_NONE, ERR_GOTO_ERR_BELOW_HORIZON, ERR_GOTO_ERR_ABOVE_OVERHEAD, ERR_GOTO_ERR_STANDBY, ERR_GOTO_ERR_PARK, ERR_GOTO_ERR_GOTO, ERR_GOTO_ERR_OUTSIDE_LIMITS, ERR_GOTO_ERR_HARDWARE_FAULT, ERR_GOTO_ERR_IN_MOTION, ERR_GOTO_ERR_UNSPECIFIED
2253
2254 //For redoing this, quick python, if needed (will only give the error name):
2255 //all_errors=' (Insert)
2256 //split_errors=all_errors.split(', ')
2257 //for specific in split_errors:
2258 // print('case ' +specific+':')
2259 // print('\tIUSaveText(&OnstepStat[7],"'+specific+'");')
2260 // print('\tbreak;')
2261
2262 // Read before EqNP is updated below: a goto that ends with a limit error is reported as failed
2263 Lasterror = (Errors)(OSStat[strlen(OSStat) - 1] - '0');
2264
2265 // ============= Telescope Status
2266
2267 if (strstr(OSStat, "P"))
2268 {
2270 OnstepStatTP[3].setText("Parked");
2271 OnstepStatTP[1].setText("Parked");
2272 if (!isParked()) //Don't call this every time OSStat changes
2273 {
2274 SetParked(true);
2275 }
2277 }
2278 else
2279 {
2280 if (strstr(OSStat, "n") && strstr(OSStat, "N"))
2281 {
2282 OnstepStatTP[1].setText("Idle");
2284 }
2285 if (strstr(OSStat, "n") && !strstr(OSStat, "N"))
2286 {
2287 if (strstr(OSStat, "I"))
2288 {
2289 OnstepStatTP[1].setText("Parking/Slewing");
2291 }
2292 else
2293 {
2294 OnstepStatTP[1].setText("Slewing");
2296 }
2297 }
2298 if (strstr(OSStat, "N") && !strstr(OSStat, "n"))
2299 {
2300 OnstepStatTP[1].setText("Tracking");
2302 }
2303 if (!strstr(OSStat, "N") && !strstr(OSStat, "n"))
2304 {
2305 OnstepStatTP[1].setText("Slewing");
2307 }
2308 // A park we started is still running until OnStep reports 'P'. The first polls after :hP# may not
2309 // show 'I' yet, so don't let them end the park. A failed park ends it with an error.
2310 if (ParkSP.getState() == IPS_BUSY && ParkSP[PARK].getState() == ISS_ON)
2311 {
2312 const auto parkSeconds = std::chrono::duration_cast<std::chrono::seconds>(
2313 std::chrono::steady_clock::now() - m_ParkStartTime).count();
2314 if (strstr(OSStat, "F"))
2315 {
2316 LOG_ERROR("OnStep reports that parking failed.");
2317 ParkSP.setState(IPS_ALERT);
2318 ParkSP.apply();
2319 }
2320 else if (parkSeconds >= m_ParkTimeoutSeconds)
2321 {
2322 // Don't report a park forever as running if the controller never reports it parked
2323 LOGF_ERROR("OnStep did not report the mount parked within %d seconds, park failed.",
2325 ParkSP.setState(IPS_ALERT);
2326 ParkSP.apply();
2327 }
2328 else
2329 {
2331 }
2332 }
2334 if (isParked()) //IMPORTANT: SET AFTER setting TrackState!
2335 {
2336 SetParked(false);
2337 }
2339 }
2340 // Set TrackStateSP based on above, but only change if needed.
2341 // NOTE: Technically during a slew it can have tracking on, but elsewhere there is the assumption:
2342 // Slewing = Not tracking
2343#ifdef DEBUG_TRACKSTATE
2344 LOG_DEBUG("BEFORE UPDATE");
2345 if (EqNP.s == IPS_BUSY)
2346 {
2347 LOG_DEBUG("EqNP is IPS_BUSY (Goto/slew or Parking)");
2348 }
2349 if (EqNP.s == IPS_OK)
2350 {
2351 LOG_DEBUG("EqNP is IPS_OK (Tracking)");
2352 }
2353 if (EqNP.s == IPS_IDLE)
2354 {
2355 LOG_DEBUG("EqNP is IPS_IDLE (Not Tracking or Parked)");
2356 }
2357 if (EqNP.s == IPS_ALERT)
2358 {
2359 LOG_DEBUG("EqNP is IPS_ALERT (Something wrong)");
2360 }
2361 LOG_DEBUG("/BEFORE UPDATE");
2362#endif
2363 // Fewer updates might help with KStars handling.
2364 bool trackStateUpdateNeded = false;
2366 {
2367 if (TrackStateSP.getState() != IPS_BUSY)
2368 {
2369 TrackStateSP.setState(IPS_BUSY);
2370 trackStateUpdateNeded = true;
2371 }
2372 if (TrackStateSP[TRACK_ON].getState() != ISS_ON || TrackStateSP[TRACK_OFF].getState() != ISS_OFF)
2373 {
2374 TrackStateSP[TRACK_ON].setState(ISS_ON);
2375 TrackStateSP[TRACK_OFF].setState(ISS_OFF);
2376 trackStateUpdateNeded = true;
2377 }
2378 }
2379 else
2380 {
2381 if (TrackStateSP.getState() != IPS_IDLE)
2382 {
2383 TrackStateSP.setState(IPS_IDLE);
2384 trackStateUpdateNeded = true;
2385 }
2386 if (TrackStateSP[TRACK_ON].getState() != ISS_OFF || TrackStateSP[TRACK_OFF].getState() != ISS_ON)
2387 {
2388 TrackStateSP[TRACK_ON].setState(ISS_OFF);
2389 TrackStateSP[TRACK_OFF].setState(ISS_ON);
2390 trackStateUpdateNeded = true;
2391 }
2392 }
2393 if (trackStateUpdateNeded)
2394 {
2395#ifdef DEBUG_TRACKSTATE
2396 LOG_DEBUG("TRACKSTATE CHANGED");
2397#endif
2398 TrackStateSP.apply();
2399 }
2400 else
2401 {
2402#ifdef DEBUG_TRACKSTATE
2403 LOG_DEBUG("TRACKSTATE UNCHANGED");
2404#endif
2405 }
2406 //TrackState should be set correctly, only update EqNP if actually needed.
2407 bool update_needed = false;
2408 switch (TrackState)
2409 {
2410 case SCOPE_PARKED:
2411 case SCOPE_IDLE:
2412 {
2413 // OnStep stops a goto at a limit (or doesn't start it while a limit error is set) and leaves
2414 // the mount idle, with the reason only in the error code. Report that goto as failed: clients
2415 // would otherwise take the idle mount for a goto that ended without tracking and wait.
2416 const char *stopReason = (TrackState == SCOPE_IDLE && EqNP.getState() == IPS_BUSY) ?
2417 gotoStopReason(Lasterror) : nullptr;
2418 if (stopReason != nullptr)
2419 {
2420 LOGF_ERROR("OnStep stopped the slew: %s.", stopReason);
2421 EqNP.setState(IPS_ALERT);
2422 update_needed = true;
2423 }
2424 else if (EqNP.getState() != IPS_IDLE)
2425 {
2426 EqNP.setState(IPS_IDLE);
2427 update_needed = true;
2428#ifdef DEBUG_TRACKSTATE
2429 LOG_DEBUG("EqNP set to IPS_IDLE");
2430#endif
2431 }
2432 }
2433 break;
2434
2435 case SCOPE_SLEWING:
2436 case SCOPE_PARKING:
2437 if (EqNP.getState() != IPS_BUSY)
2438 {
2439 EqNP.setState(IPS_BUSY);
2440 update_needed = true;
2441#ifdef DEBUG_TRACKSTATE
2442 LOG_DEBUG("EqNP set to IPS_BUSY");
2443#endif
2444 }
2445 break;
2446
2447 case SCOPE_TRACKING:
2448 if (EqNP.getState() != IPS_OK)
2449 {
2450 EqNP.setState(IPS_OK);
2451 update_needed = true;
2452#ifdef DEBUG_TRACKSTATE
2453 LOG_DEBUG("EqNP set to IPS_OK");
2454#endif
2455 }
2456 break;
2457 }
2458 if (EqNP[AXIS_RA].getValue() != currentRA || EqNP[AXIS_DE].getValue() != currentDEC)
2459 {
2460#ifdef DEBUG_TRACKSTATE
2461 LOG_DEBUG("EqNP coordinates updated");
2462#endif
2463 update_needed = true;
2464 }
2465 if (update_needed)
2466 {
2467#ifdef DEBUG_TRACKSTATE
2468 LOG_DEBUG("EqNP changed state");
2469#endif
2470 EqNP[AXIS_RA].setValue(currentRA);
2471 EqNP[AXIS_DE].setValue(currentDEC);
2472 EqNP.apply();
2473#ifdef DEBUG_TRACKSTATE
2474 if (EqNP.s == IPS_BUSY)
2475 {
2476 LOG_DEBUG("EqNP is IPS_BUSY (Goto/slew or Parking)");
2477 }
2478 if (EqNP.s == IPS_OK)
2479 {
2480 LOG_DEBUG("EqNP is IPS_OK (Tracking)");
2481 }
2482 if (EqNP.s == IPS_IDLE)
2483 {
2484 LOG_DEBUG("EqNP is IPS_IDLE (Not Tracking or Parked)");
2485 }
2486 if (EqNP.s == IPS_ALERT)
2487 {
2488 LOG_DEBUG("EqNP is IPS_ALERT (Something wrong)");
2489 }
2490#endif
2491 }
2492 else
2493 {
2494#ifdef DEBUG_TRACKSTATE
2495 LOG_DEBUG("EqNP UNCHANGED");
2496#endif
2497 }
2499
2500 // ============= End Telescope Status
2501
2502 // ============= Refractoring
2503 if ((strstr(OSStat, "r") || strstr(OSStat, "t"))) //On, either refractory only (r) or full (t)
2504 {
2505 if (strstr(OSStat, "t"))
2506 {
2507 OnstepStatTP[2].setText("Full Comp");
2508 }
2509 if (strstr(OSStat, "r"))
2510 {
2511 OnstepStatTP[2].setText("Refractory Comp");
2512 }
2513 if (strstr(OSStat, "s"))
2514 {
2515 OnstepStatTP[8].setText("Single Axis");
2516 }
2517 else
2518 {
2519 OnstepStatTP[8].setText("2-Axis");
2520 }
2521 }
2522 else
2523 {
2524 OnstepStatTP[2].setText("Refractoring Off");
2525 OnstepStatTP[8].setText("N/A");
2526 }
2527
2528 //if (strstr(OSStat,"H")) { OnstepStatTP[3].setText("At Home"); }
2529 if (strstr(OSStat, "H") && strstr(OSStat, "P"))
2530 {
2531 OnstepStatTP[3].setText("At Home and Parked");
2532 }
2533 if (strstr(OSStat, "H") && strstr(OSStat, "p"))
2534 {
2535 OnstepStatTP[3].setText("At Home and UnParked");
2536 }
2537 //AutoPauseAtHome
2538 if (strstr(OSStat, "u")) // pa[u]se at home enabled?
2539 {
2540 HomePauseSP[1].setState(ISS_ON);
2541 HomePauseSP.setState(IPS_OK);
2542 HomePauseSP.apply("Pause at Home Enabled");
2543 }
2544 else
2545 {
2546 HomePauseSP[0].setState(ISS_ON);
2547 HomePauseSP.setState(IPS_OK);
2548 HomePauseSP.apply();
2549 }
2550
2551 if (strstr(OSStat, "w"))
2552 {
2553 OnstepStatTP[3].setText("Waiting at Home");
2554 }
2555
2556 // ============= Pec Status
2557 if ((!strstr(OSStat, "R") && !strstr(OSStat, "W")))
2558 {
2559 OnstepStatTP[4].setText("N/A");
2560 }
2561 if (strstr(OSStat, "R"))
2562 {
2563 OnstepStatTP[4].setText("Recorded");
2564 }
2565 if (strstr(OSStat, "W"))
2566 {
2567 OnstepStatTP[4].setText("Autorecord");
2568 }
2569
2570 //Handles pec with :GU, also disables the (old) :$QZ?# command
2571 if (strstr(OSStat, "/"))
2572 {
2573 OnstepStatTP[4].setText("Ignored");
2574 OSPECviaGU = true;
2575 OSPECStatusSP.setState(IPS_OK);
2576 OSPECStatusSP[0].setState(ISS_ON);
2577 OSPECRecordSP.setState(IPS_IDLE);
2578 }
2579 if (strstr(OSStat, ";"))
2580 {
2581
2582 OnstepStatTP[4].setText("AutoRecord (waiting on index)");
2583 OSPECviaGU = true;
2584 OSPECStatusSP.setState(IPS_OK);
2585 OSPECStatusSP[4].setState(ISS_ON);
2586 OSPECRecordSP.setState(IPS_BUSY);
2587 }
2588 if (strstr(OSStat, ","))
2589 {
2590 OnstepStatTP[4].setText("AutoPlaying (waiting on index)");
2591 OSPECviaGU = true;
2592 OSPECStatusSP.setState(IPS_BUSY);
2593 OSPECStatusSP[3].setState(ISS_ON);
2594 OSPECRecordSP.setState(IPS_IDLE);
2595 }
2596 if (strstr(OSStat, "~"))
2597 {
2598 OnstepStatTP[4].setText("Playing");
2599 OSPECviaGU = true;
2600 OSPECStatusSP.setState(IPS_BUSY);
2601 OSPECStatusSP[1].setState(ISS_ON);
2602 OSPECRecordSP.setState(IPS_IDLE);
2603 }
2604 if (strstr(OSStat, "^"))
2605 {
2606 OnstepStatTP[4].setText("Recording");
2607 OSPECviaGU = true;
2608 OSPECStatusSP.setState(IPS_OK);
2609 OSPECStatusSP[2].setState(ISS_ON);
2610 OSPECRecordSP.setState(IPS_BUSY);
2611 }
2612 if (OSPECviaGU)
2613 {
2615 {
2616 //We have PEC reported via :GU already, enable if any are detected, as they are not reported with ALTAZ/FORK_ALT)
2617 //NOTE: Might want to drop the && !strstr(OSStat, "/") as it will startup that way.
2618 uint32_t capabilities = GetTelescopeCapability();
2619 if ((capabilities | TELESCOPE_HAS_PEC) != capabilities)
2620 {
2621 LOG_INFO("Telescope detected having PEC, setting that capability");
2622 LOGF_DEBUG("capabilities = %x", capabilities);
2623 capabilities |= TELESCOPE_HAS_PEC;
2624 SetTelescopeCapability(capabilities, 10 );
2625 initSlewRates();
2627 }
2628 }
2629 OSPECStatusSP.apply();
2630 OSPECRecordSP.apply();
2631 OSPECIndexSP.apply();
2632 }
2633
2634
2635
2636 // ============= Time Sync Status
2637 if (!strstr(OSStat, "S"))
2638 {
2639 OnstepStatTP[5].setText("N/A");
2640 }
2641 if (strstr(OSStat, "S"))
2642 {
2643 OnstepStatTP[5].setText("PPS / GPS Sync Ok");
2644 }
2645
2646 // ============= Mount Types
2647 if (strstr(OSStat, "E"))
2648 {
2649 OnstepStatTP[6].setText("German Equatorial Mount");
2651 }
2652 if (strstr(OSStat, "K"))
2653 {
2654 OnstepStatTP[6].setText("Fork Mount");
2656 }
2657 if (strstr(OSStat, "k"))
2658 {
2659 //NOTE: This seems to have been removed from OnStep, so the chances of encountering it are small, I can't even find, but I think it was Alt-Az mounting of a FORK, now folded into ALTAZ
2660 OnstepStatTP[6].setText("Fork Alt Mount");
2662 }
2663 if (strstr(OSStat, "A"))
2664 {
2665 OnstepStatTP[6].setText("AltAZ Mount");
2667 }
2668
2669 // Keep TELESCOPE_MOUNT_TYPE in sync with the :GU# status, which is the authoritative source.
2670 // setMountType() is a no-op if the type has not changed.
2671 switch (OSMountType)
2672 {
2673 case MOUNTTYPE_ALTAZ:
2674 case MOUNTTYPE_FORK_ALT:
2676 break;
2677 case MOUNTTYPE_FORK:
2679 break;
2680 case MOUNTTYPE_GEM:
2681 default:
2683 break;
2684 }
2685
2686
2687 //Pier side:
2688 // o - nOne
2689 // T - easT
2690 // W - West
2692 {
2693 uint32_t capabilities = GetTelescopeCapability();
2694 if ((capabilities | TELESCOPE_HAS_PIER_SIDE) != capabilities)
2695 {
2696 LOG_INFO("Telescope detected having Pier Side, adding that capability (many messages duplicated)");
2697 LOGF_DEBUG("capabilities = %x", capabilities);
2698 capabilities |= TELESCOPE_HAS_PIER_SIDE;
2699 SetTelescopeCapability(capabilities, 10 );
2700 initSlewRates();
2702 }
2703 if (strstr(OSStat, "o"))
2704 {
2706 PIER_UNKNOWN); //Closest match to None, For forks may trigger an extra goto, during imaging if it would do a meridian flip
2707 pier_not_set = false;
2708 }
2709 if (strstr(OSStat, "T"))
2710 {
2712 pier_not_set = false;
2713 }
2714 if (strstr(OSStat, "W"))
2715 {
2717 pier_not_set = false;
2718 }
2719 }
2720
2721 // ============= Error Code: read with the telescope status above
2722
2723 // Refresh current Slew Rate
2724 // OnStepX reports the custom rate of :RA#/:RE# as 10 (':'), which is not one of the slew rates
2725 int idx = OSStat[strlen(OSStat) - 2] - '0';
2726 if (idx >= 0 && idx < static_cast<int>(SlewRateSP.count()) && SlewRateSP.findOnSwitchIndex() != idx)
2727 {
2728 SlewRateSP.reset();
2729 SlewRateSP[idx].setState(ISS_ON);
2730 SlewRateSP.setState(IPS_OK);
2731 SlewRateSP.apply();
2732 LOGF_DEBUG("Slew Rate Index: %d", idx);
2733 }
2734 // End Refresh current Slew Rate
2735 }
2736 else
2737 {
2738 // No (complete) :GU# answer, e.g. right after :MS# while the controller starts the slew. Skip this update
2739 // and try again, don't put the mount in an error state (clients would abort and resend the goto, which
2740 // OnStep refuses with "Goto in progress"). Several missed answers in a row mean a lost connection: fail
2741 // the poll as before, so that it is reported.
2742 flushIO(PortFD);
2744 {
2745 LOG_DEBUG(":GU# got no answer, this update aborted, will try again...");
2746 return true;
2747 }
2749 LOGF_WARN(":GU# got no answer %d times in a row, check the connection.", m_MissedStatusReplies);
2750 return false;
2751 }
2753
2754#ifdef OnStep_Alpha // For the moment, for :Gu
2755 }
2756 else
2757 {
2758 //TODO: Check and recode :Gu# paths
2760 ":Gu#"); // :Gu# returns a string containing controller status that's bitpacked
2761 if (strcmp(OSStat, OldOSStat) != 0) //if status changed
2762 {
2763 //Ignored for now.
2764 }
2765 //Byte 0: Current Status
2766 if (OSStat[0] & 0b10000001 == 0b10000001)
2767 {
2768 //Not tracking
2769 }
2770 if (OSStat[0] & 0b10000010 == 0b10000010)
2771 {
2772 //No goto
2773 }
2774 if (OSStat[0] & 0b10000100 == 0b10000100)
2775 {
2776 // PPS sync
2777 OnstepStatTP[5].setText("PPS / GPS Sync Ok");
2778 }
2779 else
2780 {
2781 OnstepStatTP[5].setText("N/A");
2782 }
2783 if (OSStat[0] & 0b10001000 == 0b10001000)
2784 {
2785 // Guide active
2786 }
2787 //Refraction and Number of axis handled differently for now, might combine to one variable.
2788 // reply[0]|=0b11010000; // Refr enabled Single axis
2789 // reply[0]|=0b10010000; // Refr enabled
2790 // reply[0]|=0b11100000; // OnTrack enabled Single axis
2791 // reply[0]|=0b10100000; // OnTrack enabled
2792 if ((OSStat[0] & 0b10010000 == 0b10010000
2793 || OSStat[0] & 0b10100000 == 0b10100000)) //On, either refractory only (r) or full (t)
2794 {
2795 if (OSStat[0] & 0b10100000 == 0b10100000)
2796 {
2797 OnstepStatTP[2].setText("Full Comp");
2798 }
2799 if (OSStat[0] & 0b10010000 == 0b10010000)
2800 {
2801 OnstepStatTP[2].setText("Refractory Comp");
2802 }
2803 if (OSStat[0] & 0b11000000 == 0b11000000)
2804 {
2805 OnstepStatTP[8].setText("Single Axis");
2806 }
2807 else
2808 {
2809 OnstepStatTP[8].setText("2-Axis");
2810 }
2811 }
2812 else
2813 {
2814 OnstepStatTP[2].setText("Refractoring Off");
2815 OnstepStatTP[8].setText("N/A");
2816 }
2817 //Byte 1: Standard tracking rates
2818 if (OSStat[1] & 0b10000001 == 0b10000001)
2819 {
2820 // Lunar rate selected
2821 }
2822 if (OSStat[1] & 0b10000010 == 0b10000010)
2823 {
2824 // Solar rate selected
2825 }
2826 if (OSStat[1] & 0b10000011 == 0b10000011)
2827 {
2828 // King rate selected
2829 }
2830 //Byte 2: Flags
2831 if (OSStat[2] & 0b10000001 == 0b10000001)
2832 {
2833 // At home
2834 }
2835 if (OSStat[2] & 0b10000010 == 0b10000010)
2836 {
2837 // Waiting at home
2838 OnstepStatTP[3].setText("Waiting at Home");
2839 }
2840 if (OSStat[2] & 0b10000100 == 0b10000100)
2841 {
2842 // Pause at home enabled?
2843 //AutoPauseAtHome
2844 HomePauseSP[1].setState(ISS_ON);
2845 HomePauseSP.setState(IPS_OK);
2846 HomePauseSP.apply("Pause at Home Enabled");
2847 }
2848 else
2849 {
2850 HomePauseSP[0].setState(ISS_ON);
2851 HomePauseSP.setState(IPS_OK);
2852 HomePauseSP.apply();
2853 }
2854 if (OSStat[2] & 0b10001000 == 0b10001000)
2855 {
2856 // Buzzer enabled?
2857 }
2858 if (OSStat[2] & 0b10010000 == 0b10010000)
2859 {
2860 // Auto meridian flip
2861 AutoFlipSP[0].setState(ISS_OFF);
2862 AutoFlipSP[1].setState(ISS_ON);
2863 AutoFlipSP.setState(IPS_OK);
2864 AutoFlipSP.apply();
2865 }
2866 else
2867 {
2868 AutoFlipSP[1].setState(ISS_OFF);
2869 AutoFlipSP[0].setState(ISS_ON);
2870 AutoFlipSP.setState(IPS_OK);
2871 AutoFlipSP.apply();
2872 }
2873 if (OSStat[2] & 0b10100000 == 0b10100000)
2874 {
2875 // PEC data has been recorded
2876 }
2877
2878
2879
2880
2881 //Byte 3: Mount type and info
2882 if (OSStat[3] & 0b10000001 == 0b10000001)
2883 {
2884 // GEM
2885 OnstepStatTP[6].setText("German Mount");
2887 }
2888 if (OSStat[3] & 0b10000010 == 0b10000010)
2889 {
2890 // FORK
2891 OnstepStatTP[6].setText("Fork Mount");
2893 }
2894 if (OSStat[3] & 0b10000100 == 0b10000100) //Seems depreciated/subsumed into FORK
2895 {
2896 // Fork Alt
2897 OnstepStatTP[6].setText("Fork Alt Mount");
2899 }
2900 if (OSStat[3] & 0b10001000 == 0b10001000)
2901 {
2902 // ALTAZM
2903 OnstepStatTP[6].setText("AltAZ Mount");
2905 }
2906
2907
2909 if (OSStat[3] & 0b10010000 == 0b10010000)
2910 {
2911 // Pier side none
2913 // INDI doesn't account for 'None'
2914 }
2915 if (OSStat[3] & 0b10100000 == 0b10100000)
2916 {
2917 // Pier side east
2919 }
2920 if (OSStat[3] & 0b11000000 == 0b11000000)
2921 {
2922 // Pier side west
2924 }
2925 // Byte 4: PEC
2926 PECStatusGU = OSStat[4] & 0b01111111;
2927 if (OSStat[4] == 0)
2928 {
2929 // AltAZM, no PEC possible
2930 PECStatusGU = 0;
2931 }
2932 else
2933 {
2934 // PEC status: 0 ignore, 1 get ready to play, 2 playing, 3 get ready to record, 4 recording
2935
2936
2937 }
2938 ParkStatusGU = OSStat[5] & 0b01111111;
2939 PulseGuideGU = OSStat[6] & 0b01111111;
2940 GuideRateGU = OSStat[7] & 0b01111111;
2941 LastError = OSStat[8] & 0b01111111;
2942 }
2943#endif
2944
2945
2946 switch (Lasterror)
2947 {
2948 case ERR_NONE:
2949 OnstepStatTP[7].setText("None");
2950 break;
2951 case ERR_MOTOR_FAULT:
2952 OnstepStatTP[7].setText("Motor/Driver Fault");
2953 break;
2954 case ERR_ALT_MIN:
2955 OnstepStatTP[7].setText("Below Horizon Limit");
2956 break;
2957 case ERR_LIMIT_SENSE:
2958 OnstepStatTP[7].setText("Limit Sense");
2959 break;
2960 case ERR_DEC:
2961 OnstepStatTP[7].setText("Dec Limit Exceeded");
2962 break;
2963 case ERR_AZM:
2964 OnstepStatTP[7].setText("Azm Limit Exceeded");
2965 break;
2966 case ERR_UNDER_POLE:
2967 OnstepStatTP[7].setText("Under Pole Limit Exceeded");
2968 break;
2969 case ERR_MERIDIAN:
2970 OnstepStatTP[7].setText("Meridian Limit (W) Exceeded");
2971 break;
2972 case ERR_SYNC:
2973 OnstepStatTP[7].setText("Sync Safety Limit Exceeded");
2974 break;
2975 case ERR_PARK:
2976 OnstepStatTP[7].setText("Park Failed");
2977 break;
2978 case ERR_GOTO_SYNC:
2979 OnstepStatTP[7].setText("Goto Sync Failed");
2980 break;
2981 case ERR_UNSPECIFIED:
2982 OnstepStatTP[7].setText("Unspecified Error");
2983 break;
2984 case ERR_ALT_MAX:
2985 OnstepStatTP[7].setText("Above Overhead Limit");
2986 break;
2987 case ERR_GOTO_ERR_NONE:
2988 OnstepStatTP[7].setText("Goto No Error");
2989 break;
2991 OnstepStatTP[7].setText("Goto Below Horizon");
2992 break;
2994 OnstepStatTP[7].setText("Goto Abv Overhead");
2995 break;
2997 OnstepStatTP[7].setText("Goto Err Standby");
2998 break;
2999 case ERR_GOTO_ERR_PARK:
3000 OnstepStatTP[7].setText("Goto Err Park");
3001 break;
3002 case ERR_GOTO_ERR_GOTO:
3003 OnstepStatTP[7].setText("Goto Err Goto");
3004 break;
3006 OnstepStatTP[7].setText("Goto Outside Limits");
3007 break;
3009 OnstepStatTP[7].setText("Goto H/W Fault");
3010 break;
3012 OnstepStatTP[7].setText("Goto Err Motion");
3013 break;
3015 OnstepStatTP[7].setText("Goto Unspecified Error");
3016 break;
3017 default:
3018 OnstepStatTP[7].setText("Unknown Error");
3019 break;
3020 }
3021
3022#ifndef OnStep_Alpha
3023 // Get actual Pier Side
3024 if (pier_not_set)
3025 {
3027 {
3029 }
3030 else
3031 {
3032 int error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, OSPier, ":Gm#");
3033 if (error_or_fail > 1)
3034 {
3035 if (strcmp(OSPier, OldOSPier) != 0) // any change ?
3036 {
3037 snprintf(OldOSPier, sizeof(OldOSPier), "%s", OSPier);
3038 switch(OSPier[0])
3039 {
3040 case 'E':
3042 break;
3043 case 'W':
3045 break;
3046 case 'N':
3048 break;
3049 case '?':
3051 break;
3052 }
3053 }
3054 }
3055 else
3056 {
3057 LOG_WARN("Communication error on Pier Side (:Gm#), this update aborted, will try again...");
3058 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3059 }
3060 }
3061 }
3062#endif
3063
3064
3065 //========== Jasem Mutlaq 2025.01.10: If we are in manual motion, immediately return as rapid updates for RA/DE are far more critical
3066 // then the rest of the measurements below.
3067 if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)
3068 return true;
3069
3070 //========== Get actual Backlash values
3071 double backlash_DEC, backlash_RA;
3072 int BD_error = getCommandDoubleResponse(PortFD, &backlash_DEC, OSbacklashDEC, ":%BD#");
3073 int BR_error = getCommandDoubleResponse(PortFD, &backlash_RA, OSbacklashRA, ":%BR#");
3074 if (BD_error > 1 && BR_error > 1)
3075 {
3076 BacklashNP[0].setValue(backlash_DEC);
3077 BacklashNP[1].setValue(backlash_RA);
3078 BacklashNP.apply();
3079 }
3080 else
3081 {
3082 LOG_WARN("Communication error on backlash (:%BD#/:%BR#), this update aborted, will try again...");
3083 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3084 }
3085
3086 double pulseguiderate = 0.0;
3087 if (getCommandDoubleResponse(PortFD, &pulseguiderate, GuideValue, ":GX90#") > 1)
3088 {
3089 LOGF_DEBUG("Guide Rate String: %s", GuideValue);
3090 pulseguiderate = atof(GuideValue);
3091 LOGF_DEBUG("Guide Rate: %f", pulseguiderate);
3092 GuideRateNP[0].setValue(pulseguiderate);
3093 GuideRateNP[1].setValue(pulseguiderate);
3094 GuideRateNP.apply();
3095 }
3096 else
3097 {
3098 LOGF_DEBUG("Guide Rate String: %s", GuideValue);
3099 LOG_DEBUG("Guide rate error response, Not setting guide rate from :GX90# response, falling back to :GU#, which may not be accurate, if custom settings are used");
3100 int pulseguiderateint = (Errors)(OSStat[strlen(OSStat) - 3] - '0');
3101 switch(pulseguiderateint)
3102 {
3103 case 0:
3104 pulseguiderate = (double)0.25;
3105 break;
3106 case 1:
3107 pulseguiderate = (double)0.5;
3108 break;
3109 case 2:
3110 pulseguiderate = (double)1.0;
3111 break;
3112 default:
3113 pulseguiderate = 0.0;
3114 LOG_DEBUG("Could not get guide rate from :GU# response, not setting");
3115 LOG_WARN("Communication error on Guide Rate (:GX90#/:GU#), this update aborted, will try again...");
3116 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3117 }
3118 if (pulseguiderate != 0.0)
3119 {
3120 LOGF_DEBUG("Guide Rate: %f", pulseguiderate);
3121 GuideRateNP[0].setValue(pulseguiderate);
3122 GuideRateNP[1].setValue(pulseguiderate);
3123 GuideRateNP.apply();
3124 }
3125 }
3126
3127#ifndef OnStep_Alpha
3129 {
3130 //AutoFlip
3131 char merdidianflipauto_response[RB_MAX_LEN] = {0};
3132 int gx95_error = getCommandSingleCharErrorOrLongResponse(PortFD, merdidianflipauto_response, ":GX95#");
3133 if (gx95_error > 1)
3134 {
3135 if (merdidianflipauto_response[0] == '1') // && merdidianflipauto_response[1] == 0) //Only set on 1#
3136 {
3137 AutoFlipSP[0].setState(ISS_OFF);
3138 AutoFlipSP[1].setState(ISS_ON);
3139 AutoFlipSP.setState(IPS_OK);
3140 AutoFlipSP.apply();
3141 }
3142 else if (merdidianflipauto_response[0] == '0') // && merdidianflipauto_response[1] == 0) //Only set on 1#
3143 {
3144 AutoFlipSP[1].setState(ISS_OFF);
3145 AutoFlipSP[0].setState(ISS_ON);
3146 AutoFlipSP.setState(IPS_OK);
3147 AutoFlipSP.apply();
3148 }
3149 }
3150 else
3151 {
3152 LOG_WARN("Communication error on meridianAutoFlip (:GX95#), this update aborted, will try again...");
3153 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3154 }
3155 }
3156#endif
3157
3158 if (OSMountType == MOUNTTYPE_GEM) //Doesn't apply to non-GEMs
3159 {
3160 //PreferredPierSide
3161 char preferredpierside_response[RB_MAX_LEN] = {0};
3162 int gx96_error = getCommandSingleCharErrorOrLongResponse(PortFD, preferredpierside_response, ":GX96#");
3163 if (gx96_error > 1)
3164 {
3165 if (strstr(preferredpierside_response, "W"))
3166 {
3167 PreferredPierSideSP[0].setState(ISS_ON);
3168 PreferredPierSideSP.setState(IPS_OK);
3169 PreferredPierSideSP.apply();
3170 }
3171 else if (strstr(preferredpierside_response, "E"))
3172 {
3173 PreferredPierSideSP[1].setState(ISS_ON);
3174 PreferredPierSideSP.setState(IPS_OK);
3175 PreferredPierSideSP.apply();
3176 }
3177 else if (strstr(preferredpierside_response, "B"))
3178 {
3179 PreferredPierSideSP[2].setState(ISS_ON);
3180 PreferredPierSideSP.setState(IPS_OK);
3181 PreferredPierSideSP.apply();
3182 }
3183 /* remove this dead code
3184 else if (strstr(preferredpierside_response, "%"))
3185 {
3186 //NOTE: This bug is only present in very early OnStepX, and should be fixed shortly after 10.03k
3187 LOG_DEBUG(":GX96 returned \% indicating early OnStepX bug");
3188 PreferredPierSideSP.reset();
3189 PreferredPierSideSP.setState(IPS_ALERT);
3190 PreferredPierSideSP.apply();
3191 }
3192 */
3193 else
3194 {
3195 PreferredPierSideSP.reset();
3196 PreferredPierSideSP.setState(IPS_BUSY);
3197 PreferredPierSideSP.apply();
3198 }
3199 }
3200 else
3201 {
3202 LOG_WARN("Communication error on Preferred Pier Side (:GX96#), this update aborted, will try again...");
3203 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3204 }
3205
3207 {
3208 // Minutes past Meridian, Onstep uses angulat values in degree we use minutes: 1° = 4 minutes
3209 char limit1_response[RB_MAX_LEN] = {0};
3210 int gxea_error, gxe9_error;
3211 double minutes_past_Meridian_East, minutes_past_Meridian_West;
3212 gxe9_error = getCommandDoubleResponse(PortFD, &minutes_past_Meridian_East, limit1_response, ":GXE9#");
3213 if (gxe9_error > 1) //NOTE: Possible failure not checked.
3214 {
3215 char limit2_response[RB_MAX_LEN] = {0};
3216 gxea_error = getCommandDoubleResponse(PortFD, &minutes_past_Meridian_West, limit2_response, ":GXEA#");
3217 if (gxea_error > 1) //NOTE: Possible failure not checked.
3218 {
3219 minutesPastMeridianNP[0].setValue(minutes_past_Meridian_East); // E
3220 minutesPastMeridianNP[1].setValue(minutes_past_Meridian_West); //W
3221 minutesPastMeridianNP.apply();
3222 }
3223 else
3224 {
3225 LOG_WARN("Communication error on Degrees past Meridian West (:GXEA#), this update aborted, will try again...");
3226 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3227 }
3228 }
3229 else
3230 {
3231 LOG_WARN("Communication error on Degrees past Meridian East (:GXE9#), this update aborted, will try again...");
3232 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3233 }
3234 }
3235 }
3236 // Get Overhead Limits
3237 // :Go# Get Overhead Limit
3238 // Returns: DD*#
3239 // The highest elevation above the horizon that the telescope will goto
3240 char Go[RB_MAX_LEN] = {0};
3241 int Go_int ;
3242 int Go_error = getCommandIntResponse(PortFD, &Go_int, Go, ":Go#");
3243 if (Go_error > 0)
3244 {
3245 ElevationLimitNP[1].setValue(atoi(Go));
3246 ElevationLimitNP.apply();
3247 LOGF_DEBUG("Elevation Limit Min: %s, %i Go_nbcar: %i", Go, Go_int, Go_error); //typo
3248 }
3249 else
3250 {
3251 LOG_WARN("Communication :Go# error, check connection.");
3252 flushIO(PortFD); //Unlikely to do anything, but just in case.
3253 }
3254
3255 // :Gh# Get Horizon Limit, the minimum elevation of the mount relative to the horizon
3256 // Returns: sDD*#
3257 char Gh[RB_MAX_LEN] = {0};
3258 int Gh_int ;
3259 int Gh_error = getCommandIntResponse(PortFD, &Gh_int, Gh, ":Gh#");
3260 if (Gh_error > 0)
3261 {
3262 ElevationLimitNP[0].setValue(atoi(Gh));
3263 ElevationLimitNP.apply();
3264 LOGF_DEBUG("Elevation Limit Min: %s, %i Gh_nbcar: %i", Gh, Gh_int, Gh_error); //typo
3265 }
3266 else
3267 {
3268 LOG_WARN("Communication :Gh# error, check connection.");
3269 flushIO(PortFD); //Unlikely to do anything, but just in case.
3270 }
3271 // End Get Overhead Limits
3272
3273 //TODO: Improve Rotator support
3274 if (OSUpdateRotator() != 0)
3275 {
3276 LOG_WARN("Communication error on Rotator Update, this update aborted, will try again...");
3277 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3278 }
3279
3280 //Weather update
3281 char temperature_response[RB_MAX_LEN] = {0};
3282 double temperature_value;
3283 int gx9a_error = getCommandDoubleResponse(PortFD, &temperature_value, temperature_response, ":GX9A#");
3284 if (gx9a_error > 1) //> 1 as an OnStep error would be 1 char in response
3285 {
3286 setParameterValue("WEATHER_TEMPERATURE", temperature_value);
3287 }
3288 else
3289 {
3290 LOG_WARN("Communication error on Temperature (:GX9A#), this update aborted, will try again...");
3291 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3292 }
3293
3294 char humidity_response[RB_MAX_LEN] = {0};
3295 double humidity_value;
3296 int gx9c_error = getCommandDoubleResponse(PortFD, &humidity_value, humidity_response, ":GX9C#");
3297 if (gx9c_error > 1) //> 1 as an OnStep error would be 1 char in response
3298 {
3299 setParameterValue("WEATHER_HUMIDITY", humidity_value);
3300 }
3301 else
3302 {
3303 LOG_WARN("Communication error on Humidity (:GX9C#), this update aborted, will try again...");
3304 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3305 }
3306
3307
3308 char barometer_response[RB_MAX_LEN] = {0};
3309 double barometer_value;
3310 int gx9b_error = getCommandDoubleResponse(PortFD, &barometer_value, barometer_response, ":GX9B#");
3311 if (gx9b_error > 1)
3312 {
3313 setParameterValue("WEATHER_BAROMETER", barometer_value);
3314 }
3315 else
3316 {
3317 LOG_WARN("Communication error on Barometer (:GX9B#), this update aborted, will try again...");
3318 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3319 }
3320
3321 char dewpoint_reponse[RB_MAX_LEN] = {0};
3322 double dewpoint_value;
3323 int gx9e_error = getCommandDoubleResponse(PortFD, &dewpoint_value, dewpoint_reponse, ":GX9E#");
3324 if (gx9e_error > 1)
3325 {
3326 setParameterValue("WEATHER_DEWPOINT", dewpoint_value);
3327 }
3328 else
3329 {
3330 LOG_WARN("Communication error on Dewpoint (:GX9E#), this update aborted, will try again...");
3331 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3332 }
3333
3334 if (OSCpuTemp_good)
3335 {
3336 char cputemp_reponse[RB_MAX_LEN] = {0};
3337 double cputemp_value;
3338 int error_return = getCommandDoubleResponse(PortFD, &cputemp_value, cputemp_reponse, ":GX9F#");
3339 if ( error_return >= 0) // && !strcmp(cputemp_reponse, "0") )
3340 {
3341 setParameterValue("WEATHER_CPU_TEMPERATURE", cputemp_value);
3342 }
3343 else
3344 {
3345 LOGF_DEBUG("CPU Temp not responded to, disabling further checks, return values: error_return: %i, cputemp_reponse: %s",
3346 error_return, cputemp_reponse);
3347 OSCpuTemp_good = false;
3348 }
3349 }
3350 //
3351 //Disabled, because this is supplied via Kstars or other location, no sensor to read this
3352 //double altitude_value;
3353 //int error_or_fail = getCommandDoubleResponse(PortFD, &altitude_value, TempValue, ":GX9D#");
3354 //setParameterValue("WEATHER_ALTITUDE", altitude_value);
3356
3358 critialParametersLP.apply();
3359 ParametersNP.setState(IPS_OK);
3360 ParametersNP.apply();
3361
3362 if (TMCDrivers)
3363 {
3364 for (int driver_number = 1; driver_number < 3; driver_number++)
3365 {
3366 char TMCDriverTempValue[RB_MAX_LEN] = {0};
3367 char TMCDriverCMD[CMD_MAX_LEN] = {0};
3368 snprintf(TMCDriverCMD, sizeof(TMCDriverCMD), ":GXU%i#", driver_number);
3369 if (TMCDrivers) //Prevent check on :GXU2# if :GXU1# failed
3370 {
3371 int i = getCommandSingleCharErrorOrLongResponse(PortFD, TMCDriverTempValue, TMCDriverCMD);
3372 if (i == -4 && TMCDriverTempValue[0] == '0' )
3373 {
3374 char ResponseText[RB_MAX_LEN] = {0};
3375 snprintf(ResponseText, sizeof(ResponseText), "TMC Reporting not detected, Axis %i", driver_number);
3376 OnstepStatTP[8 + driver_number].setText(ResponseText);
3377 LOG_DEBUG("TMC Drivers responding as if not there, disabling further checks");
3378 TMCDrivers = false;
3379 }
3380 else
3381 {
3382 if (i > 0 )
3383 {
3384 if (TMCDriverTempValue[0] == 0)
3385 {
3386 OnstepStatTP[8 + driver_number].setText("No Condition");
3387 TMCDrivers = false;
3388 }
3389 else
3390 {
3391 char StepperState[1024] = {0};
3392 bool unknown_value = false;
3393 int current_position = 0;
3394 while (TMCDriverTempValue[current_position] != 0 && unknown_value == false)
3395 {
3396 if (TMCDriverTempValue[current_position] == ',')
3397 {
3398 current_position++;
3399 }
3400 else
3401 {
3402 if (TMCDriverTempValue[current_position] == 'S' && TMCDriverTempValue[current_position + 1] == 'T')
3403 {
3404 strcat(StepperState, "Standstill,");
3405 }
3406 else if (TMCDriverTempValue[current_position] == 'O' && TMCDriverTempValue[current_position + 1] == 'A')
3407 {
3408 strcat(StepperState, "Open Load A Pair,");
3409 }
3410 else if (TMCDriverTempValue[current_position] == 'O' && TMCDriverTempValue[current_position + 1] == 'B')
3411 {
3412 strcat(StepperState, "Open Load B Pair,");
3413 }
3414 else if (TMCDriverTempValue[current_position] == 'G' && TMCDriverTempValue[current_position + 1] == 'A')
3415 {
3416 strcat(StepperState, "Short to Ground A Pair,");
3417 }
3418 else if (TMCDriverTempValue[current_position] == 'G' && TMCDriverTempValue[current_position + 1] == 'B')
3419 {
3420 strcat(StepperState, "Short to Ground B Pair,");
3421 }
3422 else if (TMCDriverTempValue[current_position] == 'O' && TMCDriverTempValue[current_position + 1] == 'T')
3423 {
3424 strcat(StepperState, "Over Temp (>150C),");
3425 }
3426 else if (TMCDriverTempValue[current_position] == 'P' && TMCDriverTempValue[current_position + 1] == 'W')
3427 {
3428 strcat(StepperState, "Pre-Warning: Over Temp (>120C),");
3429 }
3430 else if (TMCDriverTempValue[current_position] == 'G' && TMCDriverTempValue[current_position + 1] == 'F')
3431 {
3432 strcat(StepperState, "General Fault,");
3433 }
3434 else
3435 {
3436 unknown_value = true;
3437 break;
3438 }
3439 current_position = current_position + 3;
3440 }
3441 }
3442 if (unknown_value)
3443 {
3444 OnstepStatTP[8 + driver_number].setText(TMCDriverTempValue);
3445 }
3446 else
3447 {
3448 OnstepStatTP[8 + driver_number].setText(StepperState);
3449 }
3450 }
3451 }
3452 else
3453 {
3454 OnstepStatTP[8 + driver_number].setText("Unknown read error");
3455 }
3456 }
3457 }
3458 }
3459 }
3460
3461 // Update OnStep Status TAB
3462 OnstepStatTP.apply();
3463 //Align tab, so it doesn't conflict
3464 //May want to reduce frequency of updates
3465 if (!UpdateAlignStatus())
3466 {
3467 LOG_WARN("Fail Align Command");
3468 LOG_WARN("Communication error on Align Status Update, this update aborted, will try again...");
3469 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3470 }
3472
3473
3474 if (OSUpdateFocuser() != 0) // Update Focuser Position
3475 {
3476 LOG_WARN("Communication error on Focuser Update, this update aborted, will try again...");
3477 return true; //COMMUNICATION ERROR, BUT DON'T PUT TELESCOPE IN ERROR STATE
3478 }
3479
3480#ifndef OnStep_Alpha
3481 if (!OSPECviaGU)
3482 {
3483 PECStatus(0);
3484 }
3485 //#Gu# has this built in
3486#endif
3487
3488
3489 return true;
3490}
3491
3492
3493bool LX200_OnStep::SetTrackEnabled(bool enabled) //track On/Off events handled by inditelescope Tested
3494{
3495 char response[RB_MAX_LEN];
3496
3497 if (enabled)
3498 {
3499 int res = getCommandSingleCharResponse(PortFD, response, ":Te#"); //0 = failure, 1 = success, no # on reply
3500 if(res < 0 || response[0] == '0')
3501 {
3502 LOGF_ERROR("===CMD==> Track On %s", response);
3503 return false;
3504 }
3505
3506 // The base class does not send a track mode selected while tracking was off. Apply Custom now; for the other
3507 // modes only clear the rate offsets Custom may have left, so a rate set outside INDI (King, :ST#) is kept.
3509 {
3510 if (TrackModeSP.findOnSwitchIndex() == TRACK_CUSTOM)
3511 return SetTrackMode(TRACK_CUSTOM);
3512 return setTrackRateOffsets(0, 0);
3513 }
3514 }
3515 else
3516 {
3517 int res = getCommandSingleCharResponse(PortFD, response, ":Td#"); //0 = failure, 1 = success, no # on reply
3518 if(res < 0 || response[0] == '0')
3519 {
3520 LOGF_ERROR("===CMD==> Track Off %s", response);
3521 return false;
3522 }
3523 }
3524 return true;
3525}
3526
3527bool LX200_OnStep::setLocalDate(uint8_t days, uint8_t months, uint16_t years)
3528{
3529 years = years % 100;
3530 char cmd[CMD_MAX_LEN] = {0};
3531
3532 snprintf(cmd, CMD_MAX_LEN, ":SC%02d/%02d/%02d#", months, days, years);
3533
3534 if (!sendOnStepCommand(cmd)) return true;
3535 return false;
3536}
3537
3539{
3540 int error_type;
3541 int nbytes_write = 0;
3542
3543 DEBUGF(DBG_SCOPE, "CMD <%s>", cmd);
3544
3545 flushIO(PortFD);
3546 /* Add mutex */
3547 std::unique_lock<std::mutex> guard(lx200CommsLock);
3548 tcflush(PortFD, TCIFLUSH);
3549
3550
3551 if ((error_type = tty_write_string(PortFD, cmd, &nbytes_write)) != TTY_OK)
3552 {
3553 LOGF_ERROR("CHECK CONNECTION: Error sending command %s", cmd);
3554 return 0; //Fail if we can't write
3555 //return error_type;
3556 }
3557
3558 return 1;
3559}
3560
3562{
3563 char response[1] = {0};
3564 int error_type;
3565 int nbytes_write = 0, nbytes_read = 0;
3566
3567 DEBUGF(DBG_SCOPE, "CMD <%s>", cmd);
3568
3569 flushIO(PortFD);
3570 /* Add mutex */
3571 std::unique_lock<std::mutex> guard(lx200CommsLock);
3572 tcflush(PortFD, TCIFLUSH);
3573
3574 if ((error_type = tty_write_string(PortFD, cmd, &nbytes_write)) != TTY_OK)
3575 return error_type;
3576
3577 error_type = tty_read_expanded(PortFD, response, 1, OSTimeoutSeconds, OSTimeoutMicroSeconds, &nbytes_read);
3578
3579 tcflush(PortFD, TCIFLUSH);
3580 DEBUGF(DBG_SCOPE, "RES <%c>", response[0]);
3581
3582 if (nbytes_read < 1)
3583 {
3584 LOG_WARN("Timeout/Error on response. Check connection.");
3585 return false;
3586 }
3587
3588 return (response[0] == '0'); //OnStep uses 0 for success and non zero for failure, in *most* cases;
3589}
3590
3591int LX200_OnStep::getCommandSingleCharResponse(int fd, char *data, const char *cmd)
3592{
3593 char *term;
3594 int error_type;
3595 int nbytes_write = 0, nbytes_read = 0;
3596
3597 DEBUGF(DBG_SCOPE, "CMD <%s>", cmd);
3598
3599 flushIO(fd);
3600 /* Add mutex */
3601 std::unique_lock<std::mutex> guard(lx200CommsLock);
3602
3603 if ((error_type = tty_write_string(fd, cmd, &nbytes_write)) != TTY_OK)
3604 return error_type;
3605
3606 error_type = tty_read_expanded(fd, data, 1, OSTimeoutSeconds, OSTimeoutMicroSeconds, &nbytes_read);
3607 tcflush(fd, TCIFLUSH);
3608
3609 if (error_type != TTY_OK)
3610 return error_type;
3611
3612 term = strchr(data, '#');
3613 if (term)
3614 *term = '\0';
3615 if (nbytes_read < RB_MAX_LEN) //given this function that should always be true, as should nbytes_read always be 1
3616 {
3617 data[nbytes_read] = '\0';
3618 }
3619 else
3620 {
3621 LOG_DEBUG("got RB_MAX_LEN bytes back (which should never happen), last byte set to null and possible overflow");
3622 data[RB_MAX_LEN - 1] = '\0';
3623 }
3624
3625 DEBUGF(DBG_SCOPE, "RES <%s>", data);
3626
3627 return nbytes_read;
3628}
3629
3630
3632{
3633 tcflush(fd, TCIOFLUSH);
3634 int error_type = 0;
3635 int nbytes_read;
3636 std::unique_lock<std::mutex> guard(lx200CommsLock);
3637 tcflush(fd, TCIOFLUSH);
3638 do
3639 {
3640 char discard_data[RB_MAX_LEN] = {0};
3641 error_type = tty_nread_section_expanded(fd, discard_data, sizeof(discard_data), '#', 0, 1000, &nbytes_read);
3642 if (error_type >= 0)
3643 {
3644 LOGF_DEBUG("flushIO: Information in buffer: Bytes: %u, string: %s", nbytes_read, discard_data);
3645 }
3646 //LOGF_DEBUG("flushIO: error_type = %i", error_type);
3647 }
3648 while (error_type > 0);
3649 return 0;
3650}
3651
3652int LX200_OnStep::getCommandDoubleResponse(int fd, double *value, char *data, const char *cmd)
3653{
3654 char *term;
3655 int error_type;
3656 int nbytes_write = 0, nbytes_read = 0;
3657
3658 DEBUGF(DBG_SCOPE, "CMD <%s>", cmd);
3659
3660 flushIO(fd);
3661 /* Add mutex */
3662 std::unique_lock<std::mutex> guard(lx200CommsLock);
3663 tcflush(fd, TCIFLUSH);
3664
3665 if ((error_type = tty_write_string(fd, cmd, &nbytes_write)) != TTY_OK)
3666 return error_type;
3667
3668 error_type = tty_nread_section_expanded(fd, data, RB_MAX_LEN, '#', OSTimeoutSeconds, OSTimeoutMicroSeconds, &nbytes_read);
3669 tcflush(fd, TCIFLUSH);
3670
3671 term = strchr(data, '#');
3672 if (term)
3673 *term = '\0';
3674 if (nbytes_read < RB_MAX_LEN) //If within buffer, terminate string with \0 (in case it didn't find the #)
3675 {
3676 data[nbytes_read] = '\0'; //Indexed at 0, so this is the byte passed it
3677 }
3678 else
3679 {
3680 LOG_DEBUG("got RB_MAX_LEN bytes back, last byte set to null and possible overflow");
3681 data[RB_MAX_LEN - 1] = '\0';
3682 }
3683
3684 DEBUGF(DBG_SCOPE, "RES <%s>", data);
3685
3686 if (error_type != TTY_OK)
3687 {
3688 LOGF_DEBUG("Error %d", error_type);
3689 LOG_DEBUG("Flushing connection");
3690 tcflush(fd, TCIOFLUSH);
3691 return error_type;
3692 }
3693
3694 if (sscanf(data, "%lf", value) != 1)
3695 {
3696 LOG_WARN("Invalid response, check connection");
3697 LOG_DEBUG("Flushing connection");
3698 tcflush(fd, TCIOFLUSH);
3699 return RES_ERR_FORMAT; //-1001, so as not to conflict with TTY_RESPONSE;
3700 }
3701
3702 return nbytes_read;
3703
3704}
3705
3706
3707int LX200_OnStep::getCommandIntResponse(int fd, int *value, char *data, const char *cmd)
3708{
3709 char *term;
3710 int error_type;
3711 int nbytes_write = 0, nbytes_read = 0;
3712
3713 DEBUGF(DBG_SCOPE, "CMD <%s>", cmd);
3714
3715 flushIO(fd);
3716 /* Add mutex */
3717 std::unique_lock<std::mutex> guard(lx200CommsLock);
3718 tcflush(fd, TCIFLUSH);
3719
3720 if ((error_type = tty_write_string(fd, cmd, &nbytes_write)) != TTY_OK)
3721 return error_type;
3722
3723 error_type = tty_nread_section_expanded(fd, data, RB_MAX_LEN, '#', OSTimeoutSeconds, OSTimeoutMicroSeconds, &nbytes_read);
3724 tcflush(fd, TCIFLUSH);
3725
3726 term = strchr(data, '#');
3727 if (term)
3728 *term = '\0';
3729 if (nbytes_read < RB_MAX_LEN) //If within buffer, terminate string with \0 (in case it didn't find the #)
3730 {
3731 data[nbytes_read] = '\0'; //Indexed at 0, so this is the byte passed it
3732 }
3733 else
3734 {
3735 LOG_DEBUG("got RB_MAX_LEN bytes back, last byte set to null and possible overflow");
3736 data[RB_MAX_LEN - 1] = '\0';
3737 }
3738 DEBUGF(DBG_SCOPE, "RES <%s>", data);
3739 if (error_type != TTY_OK)
3740 {
3741 LOGF_DEBUG("Error %d", error_type);
3742 LOG_DEBUG("Flushing connection");
3743 tcflush(fd, TCIOFLUSH);
3744 return error_type;
3745 }
3746 if (sscanf(data, "%i", value) != 1)
3747 {
3748 LOG_WARN("Invalid response, check connection");
3749 LOG_DEBUG("Flushing connection");
3750 tcflush(fd, TCIOFLUSH);
3751 return RES_ERR_FORMAT; //-1001, so as not to conflict with TTY_RESPONSE;
3752 }
3753 return nbytes_read;
3754}
3755
3757{
3758 char *term;
3759 int error_type;
3760 int nbytes_write = 0, nbytes_read = 0;
3761
3762 DEBUGF(DBG_SCOPE, "CMD <%s>", cmd);
3763
3764 flushIO(fd);
3765 /* Add mutex */
3766 std::unique_lock<std::mutex> guard(lx200CommsLock);
3767 tcflush(fd, TCIFLUSH);
3768
3769 if ((error_type = tty_write_string(fd, cmd, &nbytes_write)) != TTY_OK)
3770 return error_type;
3771
3772 error_type = tty_nread_section_expanded(fd, data, RB_MAX_LEN, '#', OSTimeoutSeconds, OSTimeoutMicroSeconds, &nbytes_read);
3773 tcflush(fd, TCIFLUSH);
3774
3775 term = strchr(data, '#');
3776 if (term)
3777 *term = '\0';
3778 if (nbytes_read < RB_MAX_LEN) //If within buffer, terminate string with \0 (in case it didn't find the #)
3779 {
3780 data[nbytes_read] = '\0'; //Indexed at 0, so this is the byte passed it
3781 }
3782 else
3783 {
3784 LOG_DEBUG("got RB_MAX_LEN bytes back, last byte set to null and possible overflow");
3785 data[RB_MAX_LEN - 1] = '\0';
3786 }
3787
3788 DEBUGF(DBG_SCOPE, "RES <%s>", data);
3789
3790 if (error_type != TTY_OK)
3791 {
3792 LOGF_DEBUG("Error %d", error_type);
3793 return error_type;
3794 }
3795 return nbytes_read;
3796
3797}
3798
3799
3800
3801bool LX200_OnStep::updateLocation(double latitude, double longitude, double elevation)
3802{
3803 INDI_UNUSED(elevation);
3804
3805 if (isSimulation())
3806 return true;
3807
3808 double onstep_long = 360 - longitude ;
3809 while (onstep_long < 0)
3810 onstep_long += 360;
3811 while (onstep_long > 360)
3812 onstep_long -= 360;
3813
3814 if (!isSimulation() && setSiteLongitude(PortFD, onstep_long) < 0)
3815 {
3816 LOG_ERROR("Error setting site longitude coordinates");
3817 return false;
3818 }
3819
3820 if (!isSimulation() && setSiteLatitude(PortFD, latitude) < 0)
3821 {
3822 LOG_ERROR("Error setting site latitude coordinates");
3823 return false;
3824 }
3825
3826 char l[32] = {0}, L[32] = {0};
3827 fs_sexa(l, latitude, 3, 360000);
3828 fs_sexa(L, longitude, 4, 360000);
3829
3830 LOGF_INFO("Site location updated to Lat %.32s - Long %.32s", l, L);
3831
3832 return true;
3833}
3834
3835int LX200_OnStep::setMinElevationLimit(int fd, int max) // According to standard command is :SoDD*# Tested
3836{
3837 LOGF_INFO("<%s>", __FUNCTION__);
3838
3839 char read_buffer[RB_MAX_LEN] = {0};
3840
3841 snprintf(read_buffer, sizeof(read_buffer), ":So%02d#", max);
3842
3843 return (setStandardProcedure(fd, read_buffer));
3844}
3845
3847{
3848 int d, m;
3849 double s;
3850 char read_buffer[32];
3851
3852 getSexComponentsIID(Long, &d, &m, &s);
3853 if (OSHighPrecision)
3854 {
3855 snprintf(read_buffer, sizeof(read_buffer), ":Sg%.03d:%02d:%.02f#", d, m, s);
3856 int result1 = setStandardProcedure(fd, read_buffer);
3857 if (result1 == 0)
3858 {
3859 return 0;
3860 }
3861 else
3862 {
3863 snprintf(read_buffer, sizeof(read_buffer), ":Sg%03d:%02d#", d, m);
3864 return (setStandardProcedure(fd, read_buffer));
3865 }
3866 }
3867 snprintf(read_buffer, sizeof(read_buffer), ":Sg%03d:%02d#", d, m);
3868 return (setStandardProcedure(fd, read_buffer));
3869}
3870
3872{
3873 int d, m;
3874 double s;
3875 char read_buffer[32];
3876
3877 getSexComponentsIID(Long, &d, &m, &s);
3878
3879 if(OSHighPrecision)
3880 {
3881 snprintf(read_buffer, sizeof(read_buffer), ":St%+.02d:%02d:%.02f#", d, m, s);
3882 int result1 = setStandardProcedure(fd, read_buffer);
3883 if (result1 == 0)
3884 {
3885 return 0;
3886 }
3887 else
3888 {
3889 snprintf(read_buffer, sizeof(read_buffer), ":St%+03d:%02d#", d, m);
3890 return (setStandardProcedure(fd, read_buffer));
3891 }
3892 }
3893 snprintf(read_buffer, sizeof(read_buffer), ":St%+03d:%02d#", d, m);
3894 return (setStandardProcedure(fd, read_buffer));
3895}
3896
3897
3898
3899
3900/***** FOCUSER INTERFACE ******
3901
3902NOT USED:
3903virtual bool SetFocuserSpeed (int speed)
3904SetFocuserSpeed Set Focuser speed. More...
3905
3906USED:
3907virtual IPState MoveFocuser (FocusDirection dir, int speed, uint16_t duration)
3908MoveFocuser the focuser in a particular direction with a specific speed for a finite duration. More...
3909
3910USED:
3911virtual IPState MoveAbsFocuser (uint32_t targetTicks)
3912MoveFocuser the focuser to an absolute position. More...
3913
3914USED:
3915virtual IPState MoveRelFocuser (FocusDirection dir, uint32_t ticks)
3916MoveFocuser the focuser to an relative position. More...
3917
3918USED:
3919virtual bool AbortFocuser ()
3920AbortFocuser all focus motion. More...
3921
3922*/
3923
3924
3925IPState LX200_OnStep::MoveFocuser(FocusDirection dir, int speed, uint16_t duration)
3926{
3927 INDI_UNUSED(speed);
3928 // :FRsnnn# Set focuser target position relative (in microns)
3929 // Returns: Nothing
3930 double output;
3931 char read_buffer[32];
3932 output = duration;
3933 if (dir == FOCUS_INWARD) output = 0 - output;
3934 snprintf(read_buffer, sizeof(read_buffer), ":FR%5f#", output);
3935 sendOnStepCommandBlind(read_buffer);
3936 return IPS_BUSY; // Normal case, should be set to normal by update.
3937}
3938
3940{
3941 // :FSsnnn# Set focuser target position (in microns)
3942 // Returns: Nothing
3943 if (FocusAbsPosNP[0].getMax() >= int(targetTicks) && FocusAbsPosNP[0].getMin() <= int(targetTicks))
3944 {
3945 char read_buffer[32];
3946 snprintf(read_buffer, sizeof(read_buffer), ":FS%06d#", int(targetTicks));
3947 sendOnStepCommandBlind(read_buffer);
3948 return IPS_BUSY; // Normal case, should be set to normal by update.
3949 }
3950 else
3951 {
3952 LOG_INFO("Unable to move focuser, out of range");
3953 return IPS_ALERT;
3954 }
3955}
3956
3958{
3959 // :FRsnnn# Set focuser target position relative (in microns)
3960 // Returns: Nothing
3961 int output;
3962 char read_buffer[32];
3963 output = ticks;
3964 if (dir == FOCUS_INWARD) output = 0 - ticks;
3965 snprintf(read_buffer, sizeof(read_buffer), ":FR%04d#", output);
3966 sendOnStepCommandBlind(read_buffer);
3967 return IPS_BUSY; // Normal case, should be set to normal by update.
3968}
3969
3971{
3972 // :FQ# Stop the focuser
3973 // Returns: Nothing
3974 char cmd[CMD_MAX_LEN] = {0};
3975 strncpy(cmd, ":FQ#", sizeof(cmd));
3977}
3978
3980{
3981
3982 // double current = 0;
3983 // int temp_value;
3984 // int i;
3985 if (OSFocuser1)
3986 {
3987 // Alternate option:
3988 //if (!sendOnStepCommand(":FA#")) {
3989 char value[RB_MAX_LEN] = {0};
3990 int value_int;
3991 int error_or_fail = getCommandIntResponse(PortFD, &value_int, value, ":FG#");
3992 if (error_or_fail > 1)
3993 {
3994 FocusAbsPosNP[0].setValue( value_int);
3995 // double current = FocusAbsPosNP[0].getValue();
3996 FocusAbsPosNP.apply();
3997 LOGF_DEBUG("Current focuser: %d, %f", value_int, FocusAbsPosNP[0].getValue());
3998 }
3999
4000 // :FT# get status
4001 // Returns: M# (for moving) or S# (for stopped)
4002 char valueStatus[RB_MAX_LEN] = {0};
4003 error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, valueStatus, ":FT#");
4004 if (error_or_fail > 0 )
4005 {
4006 if (valueStatus[0] == 'S')
4007 {
4008 FocusRelPosNP.setState(IPS_OK);
4009 FocusRelPosNP.apply();
4010 FocusAbsPosNP.setState(IPS_OK);
4011 FocusAbsPosNP.apply();
4012 }
4013 else if (valueStatus[0] == 'M')
4014 {
4015 FocusRelPosNP.setState(IPS_BUSY);
4016 FocusRelPosNP.apply();
4017 FocusAbsPosNP.setState(IPS_BUSY);
4018 FocusAbsPosNP.apply();
4019 }
4020 else
4021 {
4022 LOG_WARN("Communication :FT# error, check connection.");
4023 //INVALID REPLY
4024 FocusRelPosNP.setState(IPS_ALERT);
4025 FocusRelPosNP.apply();
4026 FocusAbsPosNP.setState(IPS_ALERT);
4027 FocusAbsPosNP.apply();
4028 }
4029 }
4030 else
4031 {
4032 //INVALID REPLY
4033 LOG_WARN("Communication :FT# error, check connection.");
4034 FocusRelPosNP.setState(IPS_ALERT);
4035 FocusRelPosNP.apply();
4036 FocusAbsPosNP.setState(IPS_ALERT);
4037 FocusAbsPosNP.apply();
4038 }
4039
4040 // :FM# Get max position (in microns)
4041 // Returns: n#
4042 char focus_max[RB_MAX_LEN] = {0};
4043 int focus_max_int;
4044 int fm_error = getCommandIntResponse(PortFD, &focus_max_int, focus_max, ":FM#");
4045 if (fm_error > 0)
4046 {
4047 FocusAbsPosNP[0].setMax(focus_max_int);
4048 FocusAbsPosNP.updateMinMax();
4049 FocusAbsPosNP.apply();
4050 LOGF_DEBUG("focus_max: %s, %i, fm_nbchar: %i", focus_max, focus_max_int, fm_error);
4051 }
4052 else
4053 {
4054 LOG_WARN("Communication :FM# error, check connection.");
4055 LOGF_WARN("focus_max: %s, %u, fm_error: %i", focus_max, focus_max[0], fm_error);
4056 flushIO(PortFD); //Unlikely to do anything, but just in case.
4057 }
4058
4059 // :FI# Get full in position (in microns)
4060 // Returns: n#
4061 char focus_min[RB_MAX_LEN] = {0};
4062 int focus_min_int ;
4063 int fi_error = getCommandIntResponse(PortFD, &focus_min_int, focus_min, ":FI#");
4064 if (fi_error > 0)
4065 {
4066 FocusAbsPosNP[0].setMin( focus_min_int);
4067 FocusAbsPosNP.updateMinMax();
4068 FocusAbsPosNP.apply();
4069 LOGF_DEBUG("focus_min: %s, %i fi_nbchar: %i", focus_min, focus_min_int, fi_error);
4070 }
4071 else
4072 {
4073 LOG_WARN("Communication :FI# error, check connection.");
4074 flushIO(PortFD); //Unlikely to do anything, but just in case.
4075 }
4076
4077 // :Ft# Get Focuser Temperature
4078 // Returns: n#
4079 char focus_T[RB_MAX_LEN] = {0};
4080 double focus_T_double ;
4081 int ft_error = getCommandDoubleResponse(PortFD, &focus_T_double, focus_T, ":Ft#");
4082 if (ft_error > 0)
4083 {
4084 FocusTemperatureNP[0].setValue(atof(focus_T));
4085 FocusTemperatureNP.apply();
4086 LOGF_DEBUG("focus T°: %s, focus_T_double %i ft_nbcar: %i", focus_T, focus_T_double, ft_error);
4087 }
4088 else
4089 {
4090 LOG_WARN("Communication :Ft# error, check connection.");
4091 LOGF_DEBUG("focus T°: %s, focus_T_double %i ft_nbcar: %i", focus_T, focus_T_double, ft_error);
4092 flushIO(PortFD); //Unlikely to do anything, but just in case.
4093 }
4094
4095 // :Fe# Get Focus Differential T°
4096 // Returns: n#
4097 char focus_TD[RB_MAX_LEN] = {0};
4098 int focus_TD_int ;
4099 int fe_error = getCommandIntResponse(PortFD, &focus_TD_int, focus_TD, ":Fe#");
4100 if (fe_error > 0)
4101 {
4102 FocusTemperatureNP[1].setValue(atof(focus_TD));
4103 FocusTemperatureNP.apply();
4104 LOGF_DEBUG("focus Differential T°: %s, %i fi_nbchar: %i", focus_TD, focus_TD_int, fe_error);
4105 }
4106 else
4107 {
4108 LOG_WARN("Communication :Fe# error, check connection.");
4109 flushIO(PortFD); //Unlikely to do anything, but just in case.
4110 }
4111
4112 // :FC# Get focuser temperature compensation coefficient in microns per °C)
4113 // Return: n.n#
4114 char focus_Coeficient[RB_MAX_LEN] = {0};
4115 int focus_Coefficient_int ;
4116 int fC_error = getCommandIntResponse(PortFD, &focus_Coefficient_int, focus_Coeficient, ":FC#");
4117 if (fC_error > 0)
4118 {
4119 TFCCoefficientNP[0].setValue(atof(focus_Coeficient));
4120 TFCCoefficientNP.apply();
4121 LOGF_DEBUG("TFC Coefficient: %s, %i fC_nbchar: %i", focus_Coeficient, focus_Coefficient_int, fC_error);
4122 }
4123 else
4124 {
4125 LOG_WARN("Communication :FC# error, check connection.");
4126 flushIO(PortFD); //Unlikely to do anything, but just in case.
4127 }
4128
4129 // :FD# Get focuser temperature compensation deadband amount (in steps or microns)
4130 // Return: n#
4131 char focus_Deadband[RB_MAX_LEN] = {0};
4132 int focus_Deadband_int ;
4133 int fD_error = getCommandIntResponse(PortFD, &focus_Deadband_int, focus_Deadband, ":FD#");
4134 if (fD_error > 0)
4135 {
4136 TFCDeadbandNP[0].setValue(focus_Deadband_int);
4137 TFCDeadbandNP.apply();
4138 LOGF_DEBUG("TFC Deadband: %s, %i fD_nbchar: %i", focus_Deadband, focus_Deadband_int, fD_error);
4139 }
4140 else
4141 {
4142 LOG_WARN("Communication :FD# error, check connection.");
4143 flushIO(PortFD); //Unlikely to do anything, but just in case.
4144 }
4145
4146 // :Fc# Get focuser temperature compensation status
4147 // Return: n.n#
4148 char response[RB_MAX_LEN];
4149 int res = getCommandSingleCharResponse(PortFD, response, ":Fc#");
4150 if (res > 0)
4151 {
4152 if (strcmp(response, "0"))
4153 {
4154 TFCCompensationSP.setState(IPS_OK);
4155 TFCCompensationSP[0].setState(ISS_OFF);
4156 TFCCompensationSP[1].setState(ISS_ON);
4157 }
4158 else if (strcmp(response, "1"))
4159 {
4160 TFCCompensationSP.setState(IPS_OK);
4161 TFCCompensationSP[0].setState(ISS_ON);
4162 TFCCompensationSP[1].setState(ISS_OFF);
4163 }
4164 TFCCompensationSP.apply();
4165 LOGF_DEBUG("TFC Enable: fc_nbchar:%d Fc_response: %s", res, response);
4166 }
4167 else
4168 {
4169 //LOGF_DEBUG("TFC Enable1: fc_error:%i Fc_response: %s", res, response);
4170 LOG_WARN("Communication :Fc# error, check connection.");
4171 flushIO(PortFD); //Unlikely to do anything, but just in case.
4172 }
4173
4175 LOGF_DEBUG("After update properties: FocusAbsPosN min: %f max: %f", FocusAbsPosNP[0].getMin(), FocusAbsPosNP[0].getMax());
4176 }
4177
4178 if(OSFocuser2)
4179 {
4180 char value[RB_MAX_LEN] = {0};
4181 int error_return;
4182 //TODO: Check to see if getCommandIntResponse would be better
4183 error_return = getCommandSingleCharErrorOrLongResponse(PortFD, value, ":fG#");
4184 if (error_return >= 0)
4185 {
4186 if ( strcmp(value, "0") )
4187 {
4188 LOG_INFO("Focuser 2 called, but not present, disabling polling");
4189 LOGF_DEBUG("OSFocuser2: %d, OSNumFocusers: %i", OSFocuser2, OSNumFocusers);
4190 OSFocuser2 = false;
4191 }
4192 else
4193 {
4194 OSFocus2TargNP[0].setValue(atoi(value));
4195 OSFocus2TargNP.apply();
4196 }
4197 }
4198 else
4199 {
4200 LOGF_INFO("Focuser 2 called, but returned error %i on read, disabling further polling", error_return);
4201 LOGF_DEBUG("OSFocuser2: %d, OSNumFocusers: %i", OSFocuser2, OSNumFocusers);
4202 OSFocuser2 = false;
4203 }
4204 }
4205
4206 if(OSNumFocusers > 1)
4207 {
4208 char value[RB_MAX_LEN] = {0};
4209 int error_or_fail = getCommandSingleCharResponse(PortFD, value, ":Fa#"); //0 = failure, 1 = success, no # on reply
4210 if (error_or_fail > 0 && value[0] > '0' && value[0] < '9')
4211 {
4212 int temp_value = (unsigned int)(value[0]) - '0';
4213 LOGF_DEBUG(":Fa# return: %d", temp_value);
4214 OSFocusSelectSP.reset();
4215 if (temp_value == 0)
4216 {
4217 OSFocusSelectSP[1].setState(ISS_ON);
4218 }
4219 else if (temp_value > 9 || temp_value < 0) //TODO: Check if completely redundant
4220 {
4221 //To solve issue mentioned https://www.indilib.org/forum/development/1406-driver-onstep-lx200-like-for-indi.html?start=624#71572
4222 OSFocusSelectSP.setState(IPS_ALERT);
4223 LOGF_WARN("Active focuser returned out of range: %d, should be 0-9", temp_value);
4224 OSFocusSelectSP.apply();
4225 return 1;
4226 }
4227 else
4228 {
4229 OSFocusSelectSP[temp_value - 1].setState(ISS_ON);
4230 }
4231 OSFocusSelectSP.setState(IPS_OK);
4232 OSFocusSelectSP.apply();
4233 }
4234 else
4235 {
4236 LOGF_DEBUG(":Fa# returned outside values: %c, %u", value[0], value[0]);
4237 }
4238 }
4239 return 0;
4240}
4241
4242
4243//Rotator stuff
4244// IPState MoveRotator(double angle) override;
4245// bool SyncRotator(double angle) override;
4246// IPState HomeRotator() override;
4247// bool ReverseRotator(bool enabled) override;
4248// bool AbortRotator() override;
4249// bool SetRotatorBacklash (int32_t steps) override;
4250// bool SetRotatorBacklashEnabled(bool enabled) override;
4251
4252//OnStep Rotator Commands (For reference, and from 5 1 v 4)
4253// :r+# Enable derotator
4254// Returns: Nothing
4255// :r-# Disable derotator
4256// Returns: Nothing
4257// :rP# Move rotator to the parallactic angle
4258// Returns: Nothing
4259// :rR# Reverse derotator direction
4260// Returns: Nothing
4261// :rT# Get status
4262// Returns: M# (for moving) or S# (for stopped)
4263// :rI# Get mIn position (in degrees)
4264// Returns: n#
4265// :rM# Get Max position (in degrees)
4266// Returns: n#
4267// :rD# Get rotator degrees per step
4268// Returns: n.n#
4269// :rb# Get rotator backlash amount in steps
4270// Return: n#
4271// :rb[n]#
4272// Set rotator backlash amount in steps
4273// Returns: 0 on failure
4274// 1 on success
4275// :rF# Reset rotator at the home position
4276// Returns: Nothing
4277// :rC# Moves rotator to the home position
4278// Returns: Nothing
4279// :rG# Get rotator current position in degrees
4280// Returns: sDDD*MM#
4281// :rc# Set continuous move mode (for next move command)
4282// Returns: Nothing
4283// :r># Move clockwise as set by :rn# command, default = 1 deg (or 0.1 deg/s in continuous mode)
4284// Returns: Nothing
4285// :r<# Move counter clockwise as set by :rn# command
4286// Returns: Nothing
4287// :rQ# Stops movement (except derotator)
4288// Returns: Nothing
4289// :r[n]# Move increment where n = 1 for 1 degrees, 2 for 2 degrees, 3 for 5 degrees, 4 for 10 degrees
4290// Move rate where n = 1 for .01 deg/s, 2 for 0.1 deg/s, 3 for 1.0 deg/s, 4 for 5.0 deg/s
4291// Returns: Nothing
4292// :rS[sDDD*MM'SS]#
4293// Set position in degrees
4294// Returns: 0 on failure
4295// 1 on success
4296
4298{
4299 char value[RB_MAX_LEN];
4300 double double_value;
4301 if(OSRotator1)
4302 {
4303 int error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, value, ":rG#");
4304 if (error_or_fail == 1 && value[0] == '0') //1 char return, response 0 = no Rotator
4305 {
4306 LOG_INFO("Detected Response that Rotator is not present, disabling further checks");
4307 OSRotator1 = false;
4308 return 0; //Return 0, as this is not a communication error
4309 }
4310 if (error_or_fail < 1) //This does not necessarily mean
4311 {
4312 LOG_WARN("Error talking to rotator, might be timeout (especially on network)");
4313 return -1;
4314 }
4315 if (f_scansexa(value, &double_value))
4316 {
4317 // 0 = good, thus this is the bad
4318 GotoRotatorNP.setState(IPS_ALERT);
4319 GotoRotatorNP.apply();
4320 return -1;
4321 }
4322 GotoRotatorNP[0].setValue(double_value);
4323 double min_rotator, max_rotator;
4324 //NOTE: The following commands are only on V4, V5 & OnStepX, not V3
4325 //TODO: Psudo-state for V3 Rotator?
4326 bool changed_minmax = false;
4328 {
4329 memset(value, 0, RB_MAX_LEN);
4330 error_or_fail = getCommandDoubleResponse(PortFD, &min_rotator, value, ":rI#");
4331 if (error_or_fail > 1)
4332 {
4333 changed_minmax = true;
4334 GotoRotatorNP[0].setMin(min_rotator);
4335 }
4336 memset(value, 0, RB_MAX_LEN);
4337 error_or_fail = getCommandDoubleResponse(PortFD, &max_rotator, value, ":rM#");
4338 if (error_or_fail > 1)
4339 {
4340 changed_minmax = true;
4341 GotoRotatorNP[0].setMax(max_rotator);
4342 }
4343 if (changed_minmax)
4344 {
4345 GotoRotatorNP.updateMinMax();
4346 GotoRotatorNP.apply();
4347 }
4348 //GotoRotatorN
4349 memset(value, 0, RB_MAX_LEN);
4350 error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, value, ":rT#");
4351 if (error_or_fail > 1)
4352 {
4353 if (value[0] == 'S') /*Stopped normal on EQ mounts */
4354 {
4355 GotoRotatorNP.setState(IPS_OK);
4356 GotoRotatorNP.apply();
4357
4358 }
4359 else if (value[0] == 'M') /* Moving, including de-rotation */
4360 {
4361 GotoRotatorNP.setState(IPS_BUSY);
4362 GotoRotatorNP.apply();
4363 }
4364 else
4365 {
4366 //INVALID REPLY
4367 GotoRotatorNP.setState(IPS_ALERT);
4368 GotoRotatorNP.apply();
4369 }
4370 }
4371 memset(value, 0, RB_MAX_LEN);
4372 int backlash_value;
4373 error_or_fail = getCommandIntResponse(PortFD, &backlash_value, value, ":rb#");
4374 if (error_or_fail > 1)
4375 {
4376 RotatorBacklashNP[0].setValue(backlash_value);
4377 RotatorBacklashNP.setState(IPS_OK);
4378 RotatorBacklashNP.apply();
4379 }
4380 }
4381 }
4382 return 0;
4383}
4384
4386{
4387 char cmd[CMD_MAX_LEN] = {0};
4388 int d, m, s;
4389 getSexComponents(angle, &d, &m, &s);
4390
4391 snprintf(cmd, sizeof(cmd), ":rS%.03d:%02d:%02d#", d, m, s);
4392 LOGF_INFO("Move Rotator: %s", cmd);
4393
4394
4396 {
4397 return IPS_BUSY;
4398 }
4399 else
4400 {
4401 return IPS_ALERT;
4402 }
4403
4404
4405 return IPS_BUSY;
4406}
4407/*
4408bool LX200_OnStep::SyncRotator(double angle) {
4409
4410}*/
4412{
4413 //Not entirely sure if this means attempt to use limit switches and home, or goto home
4414 //Assuming MOVE to Home
4415 LOG_INFO("Moving Rotator to Home");
4416 sendOnStepCommandBlind(":rC#");
4417 return IPS_BUSY;
4418}
4419// bool LX200_OnStep::ReverseRotator(bool enabled) {
4420// sendOnStepCommandBlind(":rR#");
4421// return true;
4422// } //No way to check which way it's going as Indi expects
4423
4425{
4426 LOG_INFO("Aborting Rotation, de-rotation in same state");
4427 sendOnStepCommandBlind(":rQ#"); //Does NOT abort de-rotator
4428 return true;
4429}
4430
4432{
4433 char cmd[CMD_MAX_LEN] = {0};
4434 // char response[RB_MAX_LEN];
4435 snprintf(cmd, sizeof(cmd), ":rb%d#", steps);
4437 {
4438 return true;
4439 }
4440 return false;
4441}
4442
4444{
4445 //Nothing required here.
4446 INDI_UNUSED(enabled);
4447 return true;
4448 // As it's always enabled, which would mean setting it like SetRotatorBacklash to 0, and losing any saved values. So for now, leave it as is (always enabled)
4449}
4450
4451// bool SyncRotator(double angle) override;
4452// IPState HomeRotator(double angle) override;
4453// bool ReverseRotator(bool enabled) override;
4454// bool AbortRotator() override;
4455// bool SetRotatorBacklash (int32_t steps) override;
4456// bool SetRotatorBacklashEnabled(bool enabled) override;
4457
4458// Now, derotation is NOT explicitly handled.
4459
4460
4461
4462//End Rotator stuff
4463
4464
4465
4466
4467//PEC Support
4468//Should probably be added to inditelescope or another interface, because the PEC that's there... is very limited.
4469
4471{
4472 // :$QZ+ Enable RA PEC compensation
4473 // Returns: nothing
4474 INDI_UNUSED(axis); //We only have RA on OnStep
4476 {
4477 if (OSPECEnabled == true)
4478 {
4479 char cmd[CMD_MAX_LEN] = {0};
4480 LOG_INFO("Sending Command to Start PEC Playback");
4481 strncpy(cmd, ":$QZ+#", sizeof(cmd));
4483 return IPS_BUSY;
4484 }
4485 else
4486 {
4487 LOG_DEBUG("Command to Playback PEC called when Controller does not support PEC");
4488 }
4489 return IPS_ALERT;
4490 }
4491 else
4492 {
4493 OSPECEnabled = false;
4494 LOG_INFO("Command to Start Playback PEC called when Controller does not support PEC due to being Alt-Az, PEC Ignored going forward");
4495 return IPS_ALERT;
4496 }
4497
4498}
4499
4501{
4502 // :$QZ- Disable RA PEC Compensation
4503 // Returns: nothing
4504 INDI_UNUSED(axis); //We only have RA on OnStep
4505 if (OSPECEnabled == true)
4506 {
4507 char cmd[CMD_MAX_LEN] = {0};
4508 LOG_INFO("Sending Command to Stop PEC Playback");
4509 strncpy(cmd, ":$QZ-#", sizeof(cmd));
4511 return IPS_BUSY;
4512 }
4513 else
4514 {
4515 LOG_DEBUG("Command to Stop Playing PEC called when Controller does not support PEC");
4516 }
4517 return IPS_ALERT;
4518}
4519
4521{
4522 // :$QZ/ Ready Record PEC
4523 // Returns: nothing
4524 INDI_UNUSED(axis); //We only have RA on OnStep
4525 if (OSPECEnabled == true)
4526 {
4527 char cmd[CMD_MAX_LEN] = {0};
4528 LOG_INFO("Sending Command to Start PEC record");
4529 strncpy(cmd, ":$QZ/#", CMD_MAX_LEN);
4531 return IPS_BUSY;
4532 }
4533 else
4534 {
4535 LOG_DEBUG("Command to Record PEC called when Controller does not support PEC");
4536 }
4537 return IPS_ALERT;
4538}
4539
4541{
4542 // :$QZZ Clear the PEC data buffer
4543 // Return: Nothing
4544 INDI_UNUSED(axis); //We only have RA on OnStep
4545 if (OSPECEnabled == true)
4546 {
4547 char cmd[CMD_MAX_LEN] = {0};
4548 LOG_INFO("Sending Command to Clear PEC record");
4549 strncpy(cmd, ":$QZZ#", CMD_MAX_LEN);
4551 return IPS_BUSY;
4552 }
4553 else
4554 {
4555 LOG_DEBUG("Command to clear PEC called when Controller does not support PEC");
4556 }
4557 return IPS_ALERT;
4558
4559}
4560
4562{
4563 // :$QZ! Write PEC data to EEPROM
4564 // Returns: nothing
4565 INDI_UNUSED(axis); //We only have RA on OnStep
4566 if (OSPECEnabled == true)
4567 {
4568 char cmd[CMD_MAX_LEN] = {0};
4569 LOG_INFO("Sending Command to Save PEC to EEPROM");
4570 strncpy(cmd, ":$QZ!#", CMD_MAX_LEN);
4572 return IPS_BUSY;
4573 }
4574 else
4575 {
4576 LOG_DEBUG("Command to save PEC called when Controller does not support PEC");
4577 }
4578 return IPS_ALERT;
4579}
4580
4581
4583{
4584 // if (!OSPECviaGU) {
4585 INDI_UNUSED(axis); //We only have RA on OnStep
4586 if (OSPECEnabled == true && OSPECviaGU == false) //All current versions report via #GU
4587 {
4589 {
4590 OSPECEnabled = false;
4591 LOG_INFO("Command to give PEC called when Controller does not support PEC due to being Alt-Az Disabled");
4592 return IPS_ALERT;
4593 }
4594 //LOG_INFO("Getting PEC Status");
4595 // :$QZ? Get PEC status
4596 // Returns: S#
4597 // Returns status (pecSense) In the form: Status is one of "IpPrR" (I)gnore, get ready to (p)lay, (P)laying, get ready to (r)ecord, (R)ecording. Or an optional (.) to indicate an index detect.
4598 // IUFillSwitch(&OSPECStatusS[0], "OFF", "OFF", ISS_ON);
4599 // IUFillSwitch(&OSPECStatusS[1], "Playing", "Playing", ISS_OFF);
4600 // IUFillSwitch(&OSPECStatusS[2], "Recording", "Recording", ISS_OFF);
4601 // IUFillSwitch(&OSPECStatusS[3], "Will Play", "Will Play", ISS_OFF);
4602 // IUFillSwitch(&OSPECStatusS[4], "Will Record", "Will Record", ISS_OFF);
4603 char value[RB_MAX_LEN] = {0};
4604 OSPECStatusSP.setState(IPS_BUSY);
4605 int error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, value, ":$QZ?#");
4606 if (error_or_fail > 1)
4607 {
4608 OSPECStatusSP.reset();
4609 if (value[0] == 'I') //Ignore
4610 {
4611 OSPECStatusSP.setState(IPS_OK);
4612 OSPECStatusSP[0].setState(ISS_ON);
4613 OSPECRecordSP.setState(IPS_IDLE);
4614 // OSPECEnabled = false;
4615 LOG_INFO("Controller reports PEC Ignored and not supported");
4616 LOG_INFO("No Further PEC Commands will be processed, unless status changed");
4617 }
4618 else if (value[0] == 'R') //Active Recording
4619 {
4620 OSPECStatusSP.setState(IPS_OK);
4621 OSPECStatusSP[2].setState(ISS_ON);
4622 OSPECRecordSP.setState(IPS_BUSY);
4623 }
4624 else if (value[0] == 'r') //Waiting for index before recording
4625 {
4626 OSPECStatusSP.setState(IPS_OK);
4627 OSPECStatusSP[4].setState(ISS_ON);
4628 OSPECRecordSP.setState(IPS_BUSY);
4629 }
4630 else if (value[0] == 'P') //Active Playing
4631 {
4632 OSPECStatusSP.setState(IPS_BUSY);
4633 OSPECStatusSP[1].setState(ISS_ON);
4634 OSPECRecordSP.setState(IPS_IDLE);
4635 }
4636 else if (value[0] == 'p') //Waiting for index before playing
4637 {
4638 OSPECStatusSP.setState(IPS_BUSY);
4639 OSPECStatusSP[3].setState(ISS_ON);
4640 OSPECRecordSP.setState(IPS_IDLE);
4641 }
4642 else //INVALID REPLY
4643 {
4644 OSPECStatusSP.setState(IPS_ALERT);
4645 OSPECRecordSP.setState(IPS_ALERT);
4646 }
4647 if (value[1] == '.')
4648 {
4649 OSPECIndexSP.setState(IPS_OK);
4650 OSPECIndexSP[0].setState(ISS_OFF);
4651 OSPECIndexSP[1].setState(ISS_ON);
4652 }
4653 else
4654 {
4655 OSPECIndexSP[1].setState(ISS_OFF);
4656 OSPECIndexSP[0].setState(ISS_ON);
4657 }
4658 OSPECStatusSP.apply();
4659 OSPECRecordSP.apply();
4660 OSPECIndexSP.apply();
4661 return IPS_OK;
4662 }
4663 else
4664 {
4665 LOG_DEBUG("Timeout or other error on :$QZ?#");
4666 }
4667 }
4668 else
4669 {
4670 // LOG_DEBUG("PEC status called when Controller does not support PEC");
4671 }
4672 return IPS_ALERT;
4673}
4674
4675
4677{
4678 INDI_UNUSED(axis); //We only have RA on OnStep
4679 if (OSPECEnabled == true)
4680 {
4681 LOG_WARN("PEC Reading NOT Implemented");
4682 return IPS_OK;
4683 }
4684 else
4685 {
4686 LOG_DEBUG("Command to Read PEC called when Controller does not support PEC");
4687 }
4688 return IPS_ALERT;
4689}
4690
4691
4693{
4694 INDI_UNUSED(axis); //We only have RA on OnStep
4695 if (OSPECEnabled == true)
4696 {
4697 LOG_WARN("PEC Writing NOT Implemented");
4698 return IPS_OK;
4699 }
4700 else
4701 {
4702 LOG_DEBUG("Command to Read PEC called when Controller does not support PEC");
4703 }
4704 return IPS_ALERT;
4705}
4706
4707// New, Multistar alignment goes here:
4708
4710{
4711 //See here https://groups.io/g/onstep/message/3624
4712 char cmd[CMD_MAX_LEN] = {0};
4713
4714 LOG_INFO("Sending Command to Start Alignment");
4715 OSNAlignTP[0].setText("Align STARTED");
4716 OSNAlignTP[1].setText("GOTO a star, center it");
4717 OSNAlignTP[2].setText("GOTO a star, Solve and Sync");
4718 OSNAlignTP[3].setText("Press 'Issue Align' if not solving");
4719 OSNAlignTP.apply("==>Align Started");
4720 // Check for max number of stars and gracefully fall back to max, if more are requested.
4721 char read_buffer[RB_MAX_LEN] = {0};
4722 int error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, read_buffer, ":A?#");
4723 if(error_or_fail != 4 || read_buffer[0] < '0' || read_buffer[0] > '9' || read_buffer[1] < '0' || read_buffer[1] > ':'
4724 || read_buffer[2] < '0' || read_buffer[2] > '9')
4725 {
4726 LOGF_INFO("Getting Alignment Status: response Error, response = %s>", read_buffer);
4727 return IPS_ALERT;
4728 }
4729 //Check max_stars
4730
4731 int max_stars = read_buffer[0] - '0';
4732 if (stars > max_stars)
4733 {
4734 LOG_INFO("Tried to start Align with too many stars.");
4735 LOGF_INFO("Starting Align with %d stars", max_stars);
4736 stars = max_stars;
4737 }
4738 snprintf(cmd, sizeof(cmd), ":A%.1d#", stars);
4739 LOGF_INFO("Started Align with %s, max possible stars: %d", cmd, max_stars);
4741 {
4742 LOG_INFO("Starting Align failed");
4743 return IPS_BUSY;
4744 }
4745 return IPS_ALERT;
4746}
4747
4748
4750{
4751 //Used if centering a star manually, most will use plate-solving
4752 //See here https://groups.io/g/onstep/message/3624
4753 char cmd[CMD_MAX_LEN] = {0};
4754 LOG_INFO("Sending Command to Record Star");
4755 strncpy(cmd, ":A+#", sizeof(cmd));
4757 {
4758 LOG_INFO("Adding Align failed");
4759 return IPS_BUSY;
4760 }
4761 return IPS_ALERT;
4762}
4763
4765{
4766 // :A?# Align status
4767 // Returns: mno#
4768 // where m is the maximum number of alignment stars
4769 // n is the current alignment star (0 otherwise) or ':' in case 9 stars selected
4770 // o is the last required alignment star when an alignment is in progress (0 otherwise)
4771
4772 char msg[40] = {0};
4773 char stars[5] = {0};
4774 int max_stars, current_star, align_stars;
4775
4776 char read_buffer[RB_MAX_LEN] = {0};
4777 int error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, read_buffer, ":A?#");
4778 if(error_or_fail != 4 || read_buffer[0] < '0' || read_buffer[0] > '9' || read_buffer[1] < '0' || read_buffer[1] > ':'
4779 || read_buffer[2] < '0' || read_buffer[2] > '9')
4780 {
4781 LOGF_INFO("Getting Alignment Status: response Error, response = %s>", read_buffer);
4782 return false;
4783 }
4784 max_stars = read_buffer[0] - '0';
4785 current_star = read_buffer[1] - '0';
4786 align_stars = read_buffer[2] - '0';
4787 snprintf(stars, sizeof(stars), "%d", max_stars);
4788 OSNAlignTP[5].setText(stars);
4789 snprintf(stars, sizeof(stars), "%d", current_star);
4790 if (read_buffer[1] > '9')
4791 {
4792 OSNAlignTP[6].setText(":");
4793 }
4794 else
4795 {
4796 OSNAlignTP[6].setText(stars);
4797 }
4798 snprintf(stars, sizeof(stars), "%d", align_stars);
4799 OSNAlignTP[7].setText(stars);
4800 LOGF_DEBUG("Align: max_stars: %i current star: %u, align_stars %u", max_stars, current_star, align_stars);
4801
4802 if (current_star <= align_stars)
4803 {
4804 snprintf(msg, sizeof(msg), "%s Alignment: Star %d/%d", read_buffer, current_star, align_stars );
4805 OSNAlignTP[4].setText(msg);
4806 }
4807 if (current_star > align_stars && max_stars > 1)
4808 {
4809 LOGF_DEBUG("Align: current star: %u, align_stars %u", int(current_star), int(align_stars));
4810 snprintf(msg, sizeof(msg), "Align: Completed");
4811 AlignDone();
4812 OSNAlignTP[4].setText(msg);
4814 }
4815 OSNAlignTP.apply();
4816 return true;
4817}
4818
4820{
4821 // :GX0n# Get OnStep value
4822 // Returns: value
4823
4824 // 00 ax1Cor
4825 // 01 ax2Cor
4826 // 02 altCor
4827 // 03 azmCor
4828 // 04 doCor
4829 // 05 pdCor
4830 // 06 ffCor
4831 // 07 dfCor
4832 // 08 tfCor
4833 // 09 Number of stars, reset to first star
4834 // 0A Star #n HA
4835 // 0B Star #n Dec
4836 // 0C Mount #n HA
4837 // 0D Mount #n Dec
4838 // 0E Mount PierSide (and increment n)
4839
4840
4841
4842 char read_buffer[RB_MAX_LEN] = {0};
4843 char polar_error[RB_MAX_LEN] = {0};
4844 char sexabuf[RB_MAX_LEN] = {0};
4845
4846 // LOG_INFO("Getting Align Error Status");
4847 int error_or_fail;
4848 double altCor, azmCor;
4849 error_or_fail = getCommandDoubleResponse(PortFD, &altCor, read_buffer, ":GX02#");
4850 if (error_or_fail < 2)
4851 {
4852 LOGF_INFO("Polar Align Error Status response Error, response = %s>", read_buffer);
4853 return false;
4854 }
4855 error_or_fail = getCommandDoubleResponse(PortFD, &azmCor, read_buffer, ":GX03#");
4856 if (error_or_fail < 2)
4857 {
4858 LOGF_INFO("Polar Align Error Status response Error, response = %s>", read_buffer);
4859 return false;
4860 }
4861 fs_sexa(sexabuf, (double)azmCor / 3600, 4, 3600);
4862 snprintf(polar_error, sizeof(polar_error), "%f'' /%s", azmCor, sexabuf);
4863 OSNAlignErrTP[1].setText(polar_error);
4864 fs_sexa(sexabuf, (double)altCor / 3600, 4, 3600);
4865 snprintf(polar_error, sizeof(polar_error), "%f'' /%s", altCor, sexabuf);
4866 OSNAlignErrTP[0].setText(polar_error);
4867 OSNAlignErrTP.apply();
4868
4869
4870 return true;
4871}
4872
4874{
4875 //See here https://groups.io/g/onstep/message/3624
4876 if (OSAlignCompleted == false)
4877 {
4878 OSAlignCompleted = true;
4879 LOG_INFO("Alignment Done - May still be calculating");
4880 OSNAlignTP[0].setText("Align FINISHED");
4881 OSNAlignTP[1].setText("------");
4882 OSNAlignTP[2].setText("Optionally press:");
4883 OSNAlignTP[3].setText("Write Align to NVRAM/Flash ");
4884 OSNAlignTP.apply();
4885 return IPS_OK;
4886 }
4887 return IPS_BUSY;
4888}
4889
4891{
4892 //See here https://groups.io/g/onstep/message/3624
4893 char cmd[CMD_MAX_LEN] = {0};
4894 char response[RB_MAX_LEN];
4895
4896 LOG_INFO("Sending Command to Finish Alignment and write");
4897 strncpy(cmd, ":AW#", sizeof(cmd));
4898 int res = getCommandSingleCharResponse(PortFD, response, cmd); //1 success , no # on reply
4899 if(res > 0 && response[0] == '1')
4900 {
4901 LOG_INFO("Align Write Successful");
4903 OSNAlignTP[0].setText("Align FINISHED");
4904 OSNAlignTP[1].setText("------");
4905 OSNAlignTP[2].setText("And Written to EEPROM");
4906 OSNAlignTP[3].setText("------");
4907 OSNAlignTP.apply();
4908 return IPS_OK;
4909 }
4910 else
4911 {
4912 LOGF_ERROR("Align Write Failed: error=%s", response);
4914 OSNAlignTP[0].setText("Align WRITE FAILED");
4915 OSNAlignTP.apply();
4916 return IPS_ALERT;
4917 }
4918}
4919
4920#ifdef ONSTEP_NOTDONE
4922{
4923 // :SXnn,VVVVVV...# Set OnStep value
4924 // Return: 0 on failure
4925 // 1 on success
4926 // if (parameter[0]=='G') { // Gn: General purpose output
4927 // :SXGn,value
4928 // value, 0 = low, other = high
4929 LOG_INFO("Not implemented yet");
4930 return IPS_OK;
4931}
4932#endif
4933
4935{
4936 LOG_INFO("Not implemented yet");
4937 OSGetOutputState(output);
4938 return IPS_OK;
4939}
4940
4941/*
4942Reference:
4943 // :GXnn# Get OnStep value
4944 // Returns: value
4945 // Error = 123456789
4946 //
4947 // Double unless noted: integer:i, special:* and values in {}
4948 //
4949 // 00 ax1Cor
4950 // 01 ax2Cor
4951 // 02 altCor //EQ Altitude Correction
4952 // 03 azmCor //EQ Azimuth Correction
4953 // 04 doCor
4954 // 05 pdCor
4955 // 06 ffCor
4956 // 07 dfCor
4957 // 08 tfCor
4958 // 09 Number of stars, reset to first star
4959 // 0A Star #n HA
4960 // 0B Star #n Dec
4961 // 0C Mount #n HA
4962 // 0D Mount #n Dec
4963 // 0E Mount PierSide (and increment n)
4964 // 80 UTC time
4965 // 81 UTC date
4966 // 90 pulse-guide rate
4967 // i 91 pec analog value
4968 // 92 MaxRate
4969 // 93 MaxRate (default) number
4970 // * 94 pierSide (N if never) {Same as :Gm# (E, W, None)}
4971 // i 95 autoMeridianFlip AutoFlip setting {0/1+}
4972 // * 96 preferred pier side {E, W, B}
4973 // 97 slew speed
4974 // * 98 rotator {D, R, N}
4975 // 9A temperature in deg. C
4976 // 9B pressure in mb
4977 // 9C relative humidity in %
4978 // 9D altitude in meters
4979 // 9E dew point in deg. C
4980 // 9F internal MCU temperature in deg. C
4981 // * Un: Get stepper driver statUs
4982 // En: Get settings
4983 // Fn: Debug
4984 // G0-GF (HEX!) = Onstep output status
4985
4986*/
4987
4989{
4990 // :GXnn# Get OnStep value
4991 // Returns: value
4992 // nn= G0-GF (HEX!) - Output status
4993 //
4994 char value[RB_MAX_LEN] = {0};
4995 char command[CMD_MAX_LEN] = {0};
4996 strncpy(command, ":$GXGm#", CMD_MAX_LEN);
4997 LOGF_INFO("Output: %s", char(output));
4998 LOGF_INFO("Command: %s", command);
4999 command[5] = char(output);
5000 LOGF_INFO("Command: %s", command);
5001
5002 int error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, value, command);
5003 if (error_or_fail > 0)
5004 {
5005 /*
5006 if (value[0] == 0)
5007 {
5008 OSOutput1S[0].s = ISS_ON;
5009 OSOutput1S[1].s = ISS_OFF;
5010 }
5011 else
5012 {
5013 OSOutput1S[0].s = ISS_OFF;
5014 OSOutput1S[1].s = ISS_ON;
5015 }
5016 IDSetSwitch(&OSOutput1SP, nullptr);
5017 */
5018 return true;
5019 }
5020 return false;
5021}
5022
5024{
5025 if (isSimulation())
5026 return true;
5027
5029 {
5030 if (mode == TRACK_CUSTOM)
5031 {
5032 LOG_ERROR("Custom tracking rates need OnStepX.");
5033 return false;
5034 }
5035 return LX200Generic::SetTrackMode(mode);
5036 }
5037
5038 // Custom tracking is sidereal tracking plus the RA and Dec rate offsets
5039 if (mode == TRACK_CUSTOM)
5041 SetTrackRate(TrackRateNP[AXIS_RA].getValue(), TrackRateNP[AXIS_DE].getValue());
5042
5043 return setTrackRateOffsets(0, 0) && LX200Generic::SetTrackMode(mode);
5044}
5045
5046bool LX200_OnStep::SetTrackRate(double raRate, double deRate)
5047{
5048 if (isSimulation())
5049 return true;
5050
5052 {
5053 LOG_ERROR("Custom tracking rates need OnStepX.");
5054 return false;
5055 }
5056
5057 // INDI rates are in arcsec per SI second, with TRACKRATE_SIDEREAL on RA tracking the stars. OnStepX offsets are
5058 // in arcsec per sidereal second (15 is the sidereal rate); a positive RA offset makes RA increase.
5059 const double toSiderealSecond = 15.0 / TRACKRATE_SIDEREAL;
5060 return setTrackRateOffsets((TRACKRATE_SIDEREAL - raRate) * toSiderealSecond, deRate * toSiderealSecond);
5061}
5062
5063bool LX200_OnStep::setTrackRateOffsets(double raOffset, double decOffset)
5064{
5065 // OnStepX limits the offsets to +/-1800 arcsec per sidereal second
5066 if (std::fabs(raOffset) > 1800 || std::fabs(decOffset) > 1800)
5067 {
5068 LOG_ERROR("Custom tracking rates must be within 1800 arcsec/s of sidereal tracking.");
5069 return false;
5070 }
5071
5072 char cmd[CMD_MAX_LEN] = {0};
5073 char response[RB_MAX_LEN] = {0};
5074
5075 snprintf(cmd, sizeof(cmd), ":SXTR,%.6f#", raOffset);
5076 if (getCommandSingleCharResponse(PortFD, response, cmd) < 0 || response[0] != '1')
5077 {
5078 LOGF_ERROR("Failed to set the RA tracking rate offset (%s).", response);
5079 return false;
5080 }
5081
5082 snprintf(cmd, sizeof(cmd), ":SXTD,%.6f#", decOffset);
5083 if (getCommandSingleCharResponse(PortFD, response, cmd) < 0 || response[0] != '1')
5084 {
5085 LOGF_ERROR("Failed to set the Dec tracking rate offset (%s).", response);
5086 return false;
5087 }
5088
5089 LOGF_DEBUG("Tracking rate offsets RA %.6f, Dec %.6f arcsec per sidereal second.", raOffset, decOffset);
5090 return true;
5091}
5092
5093void LX200_OnStep::slewError(int slewCode)
5094{
5095 // 0=Goto is possible
5096 // 1=below the horizon limit
5097 // 2=above overhead limit
5098 // 3=controller in standby
5099 // 4=mount is parked
5100 // 5=Goto in progress
5101 // 6=outside limits (MaxDec, MinDec, UnderPoleLimit, MeridianLimit)
5102 // 7=hardware fault
5103 // 8=already in motion
5104 // 9=unspecified error
5105 switch(slewCode)
5106 {
5107 case 0:
5108 LOG_ERROR("OnStep slew/syncError called with value 0-goto possible, this is normal operation");
5109 return;
5110 case 1:
5111 LOG_ERROR("OnStep slew/syncError: Below the horizon limit");
5112 break;
5113 case 2:
5114 LOG_ERROR("OnStep slew/syncError: Above Overhead limit");
5115 break;
5116 case 3:
5117 LOG_ERROR("OnStep slew/syncError: Controller in standby, Usual issue fix: Turn tracking on");
5118 break;
5119 case 4:
5120 LOG_ERROR("OnStep slew/syncError: Mount is Parked");
5121 break;
5122 case 5:
5123 LOG_ERROR("OnStep slew/syncError: Goto in progress");
5124 break;
5125 case 6:
5126 LOG_ERROR("OnStep slew/syncError: Outside limits: Max/Min Dec, Under Pole Limit, Meridian Limit, Sync attempted to wrong pier side");
5127 break;
5128 case 7:
5129 LOG_ERROR("OnStep slew/syncError: Hardware Fault");
5130 break;
5131 case 8:
5132 LOG_ERROR("OnStep slew/syncError: Already in motion");
5133 break;
5134 case 9:
5135 LOG_ERROR("OnStep slew/syncError: Unspecified Error");
5136 break;
5137 default:
5138 LOG_ERROR("OnStep slew/syncError: Not in range of values that should be returned! INVALID, Something went wrong!");
5139 }
5140 EqNP.setState(IPS_ALERT);
5141 EqNP.apply();
5142}
5143
5144
5145//Override LX200 sync function, to allow for error returns
5146bool LX200_OnStep::Sync(double ra, double dec)
5147{
5148
5149 char read_buffer[RB_MAX_LEN] = {0};
5150 // int error_code;
5151
5152 if (!isSimulation())
5153 {
5154 if (setObjectRA(PortFD, ra) < 0 || (setObjectDEC(PortFD, dec)) < 0)
5155 {
5156 EqNP.setState(IPS_ALERT);
5157 LOG_ERROR("Error setting RA/DEC. Unable to Sync.");
5158 EqNP.apply();
5159 return false;
5160 }
5161 LOG_DEBUG("CMD <:CM#>");
5162 int error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, read_buffer, ":CM#");
5163 LOGF_DEBUG("RES <%s>", read_buffer);
5164 if (error_or_fail > 1)
5165 {
5166 if (strcmp(read_buffer, "N/A"))
5167 {
5168 if (read_buffer[0] == 'E' && read_buffer[1] >= '0'
5169 && read_buffer[1] <= '9') //strcmp will be 0 if they match, so this is the case for failure.
5170 {
5171 int error_code = read_buffer[1] - '0';
5172 LOGF_DEBUG("Sync failed with response: %s, Error code: %i", read_buffer, error_code);
5173 slewError(error_code);
5174 EqNP.setState(IPS_ALERT);
5175 LOG_ERROR("Synchronization failed.");
5176 EqNP.apply();
5177 return false;
5178 }
5179 else
5180 {
5181 LOG_ERROR("Unexpected return on sync call!");
5182 LOG_ERROR("Check system & Align if doing align to see if it went through!");
5183 return false;
5184 }
5185 }
5186 }
5187 else
5188 {
5189 LOG_ERROR("Communication error on sync! Re-issue sync!");
5190 return false;
5191 }
5192 }
5193
5194 currentRA = ra;
5195 currentDEC = dec;
5196
5197 EqNP.setState(IPS_OK);
5199
5200 LOG_INFO("OnStep: Synchronization successful.");
5201 return true;
5202}
5203
5205{
5208 return true;
5209}
5210
5212{
5213 if (OSHasOutputs)
5214 {
5215 // Features names and type are accessed via :GXYn (where n 1 to 8)
5216 // we take these names to display in Output tab
5217 // return value is ssssss,n where ssssss is the name and n is the type
5218 char port_name[MAXINDINAME] = {0}, getoutp[MAXINDINAME] = {0}, configured[MAXINDINAME] = {0}, p_name[MAXINDINAME] = {0};
5219 size_t k {0};
5220 int error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, configured,
5221 ":GXY0#"); // returns a string with 1 where Feature is configured
5222 // ex: 10010010 means Feature 1,4 and 7 are configured
5223
5224 if (error_or_fail == -4 && configured[0] == '0')
5225 {
5226 OSHasOutputs = false;
5227 LOG_INFO("Outputs not detected, disabling further checks");
5228 }
5229
5230 OutputPorts_NP[0].fill("Unconfigured", "Unconfigured", "%g", 0, 255, 1, 0);
5231 for(int i = 1; i < PORTS_COUNT; i++)
5232 {
5233 if(configured[i - 1] == '1') // is Feature is configured
5234 {
5235 snprintf(getoutp, sizeof(getoutp), ":GXY%d#", i);
5236 int error_or_fail = getCommandSingleCharErrorOrLongResponse(PortFD, port_name, getoutp);
5237 if (error_or_fail > 0)
5238 {
5239 for(k = 0; k < strlen(port_name); k++) // remove feature type
5240 {
5241 if(port_name[k] == ',') port_name[k] = '_';
5242 p_name[k] = port_name[k];
5243 p_name[k + 1] = 0;
5244 }
5245 OutputPorts_NP[i].fill(p_name, p_name, "%g", 0, 255, 1, 0);
5246 }
5247 else
5248 {
5249 LOGF_ERROR("Communication error on %s, ignoring, disconnect and reconnect to clear", getoutp);
5250 OutputPorts_NP[i].fill("Unconfigured", "Unconfigured", "%g", 0, 255, 1, 0);
5251 }
5252 }
5253 else
5254 {
5255 OutputPorts_NP[i].fill("Unconfigured", "Unconfigured", "%g", 0, 255, 1, 0);
5256 }
5257 }
5259 }
5260}
5261
5262
5264{
5265 char cdate[MAXINDINAME] = {0};
5266 char ctime[MAXINDINAME] = {0};
5267 struct tm ltm;
5268 struct tm utm;
5269 time_t time_epoch;
5270 memset(&ltm, 0, sizeof(ltm));
5271 memset(&utm, 0, sizeof(utm));
5272
5273 double offset = 0;
5274 if (getUTFOffset(&offset))
5275 {
5276 char utcStr[8] = {0};
5277 snprintf(utcStr, 8, "%.2f", offset);
5278 TimeTP[OFFSET].setText(utcStr);
5279 }
5280 else
5281 {
5282 LOG_WARN("Could not obtain UTC offset from mount!");
5283 return false;
5284 }
5285
5286 if (getLocalTime(ctime) == false)
5287 {
5288 LOG_WARN("Could not obtain local time from mount!");
5289 return false;
5290 }
5291
5292 if (getLocalDate(cdate) == false)
5293 {
5294 LOG_WARN("Could not obtain local date from mount!");
5295 return false;
5296 }
5297
5298 // To ISO 8601 format in LOCAL TIME!
5299 char datetime[MAXINDINAME] = {0};
5300 snprintf(datetime, MAXINDINAME, "%sT%s", cdate, ctime);
5301
5302 // Now that date+time are combined, let's get tm representation of it.
5303 if (strptime(datetime, "%FT%T", &ltm) == nullptr)
5304 {
5305 LOGF_WARN("Could not process mount date and time: %s", datetime);
5306 return false;
5307 }
5308
5309 ltm.tm_isdst = 0;
5310 // Get local time epoch in UNIX seconds
5311 time_epoch = mktime(&ltm);
5312
5313 // LOCAL to UTC by subtracting offset.
5314 time_epoch -= static_cast<int>(offset * 3600.0);
5315
5316 // Get UTC (we're using localtime_r, but since we shifted time_epoch above by UTCOffset, we should be getting the real UTC time)
5317 localtime_r(&time_epoch, &utm);
5318
5319 // Format it into the final UTC ISO 8601
5320 strftime(cdate, MAXINDINAME, "%Y-%m-%dT%H:%M:%S", &utm);
5321 TimeTP[UTC].setText(cdate);
5322
5323 LOGF_DEBUG("Mount controller UTC Time: %s", TimeTP[UTC].getText());
5324 LOGF_DEBUG("Mount controller UTC Offset: %s", TimeTP[OFFSET].getText());
5325
5326 // Let's send everything to the client
5327 TimeTP.setState(IPS_OK);
5328 TimeTP.apply();
5329
5330 return true;
5331}
5332
5334{
5335 int lat_dd = 0, lat_mm = 0, long_dd = 0, long_mm = 0;
5336 double lat_ssf = 0.0, long_ssf = 0.0;
5337 char lat_sexagesimal[MAXINDIFORMAT];
5338 char lng_sexagesimal[MAXINDIFORMAT];
5339
5340 if (isSimulation())
5341 {
5342 LocationNP[LOCATION_LATITUDE].setValue(29.5);
5343 LocationNP[LOCATION_LONGITUDE].setValue(48.0);
5344 LocationNP[LOCATION_ELEVATION].setValue(10);
5345 LocationNP.setState(IPS_OK);
5346 LocationNP.apply();
5347 return true;
5348 }
5349 if (OSHighPrecision)
5350 {
5351 if (getSiteLatitudeAlt(PortFD, &lat_dd, &lat_mm, &lat_ssf, ":GtH#") < 0)
5352 {
5353 //NOTE: All OnStep pre-31 Aug 2020 will fail the above:
5354 // So Try the normal command, if it fails
5355 if (getSiteLatitude(PortFD, &lat_dd, &lat_mm, &lat_ssf) < 0)
5356 {
5357 LOG_WARN("Failed to get site latitude from device.");
5358 return false;
5359 }
5360 else
5361 {
5362 double value = 0;
5363 OSHighPrecision = false; //Don't check using :GtH again
5364 snprintf(lat_sexagesimal, MAXINDIFORMAT, "%02d:%02d:%02.1lf", lat_dd, lat_mm, lat_ssf);
5365 f_scansexa(lat_sexagesimal, &value);
5366 LocationNP[LOCATION_LATITUDE].setValue(value);
5367 }
5368 }
5369 else
5370 {
5371 double value = 0;
5372 //Got High precision coordinates
5373 snprintf(lat_sexagesimal, MAXINDIFORMAT, "%02d:%02d:%02.1lf", lat_dd, lat_mm, lat_ssf);
5374 f_scansexa(lat_sexagesimal, &value);
5375 LocationNP[LOCATION_LATITUDE].setValue(value);
5376 }
5377 }
5378 if (!OSHighPrecision) //Bypass check
5379 {
5380 if (getSiteLatitude(PortFD, &lat_dd, &lat_mm, &lat_ssf) < 0)
5381 {
5382 LOG_WARN("Failed to get site latitude from device.");
5383 return false;
5384 }
5385 else
5386 {
5387 double value = 0;
5388 snprintf(lat_sexagesimal, MAXINDIFORMAT, "%02d:%02d:%02.1lf", lat_dd, lat_mm, lat_ssf);
5389 f_scansexa(lat_sexagesimal, &value);
5390 LocationNP[LOCATION_LATITUDE].setValue(value);
5391 }
5392 }
5393
5394 if (OSHighPrecision)
5395 {
5396 if (getSiteLongitudeAlt(PortFD, &long_dd, &long_mm, &long_ssf, ":GgH#") < 0)
5397 {
5398 //NOTE: All OnStep pre-31 Aug 2020 will fail the above:
5399 // So Try the normal command, if it fails
5400 if (getSiteLongitude(PortFD, &long_dd, &long_mm, &long_ssf) < 0)
5401 {
5402 LOG_WARN("Failed to get site longitude from device.");
5403 return false;
5404 }
5405 else
5406 {
5407 double value = 0;
5408 OSHighPrecision = false;
5409 snprintf(lng_sexagesimal, MAXINDIFORMAT, "%02d:%02d:%02.1lf", long_dd, long_mm, long_ssf);
5410 f_scansexa(lng_sexagesimal, &value);
5411 LocationNP[LOCATION_LONGITUDE].setValue(value);
5412 }
5413 }
5414 else
5415 {
5416 double value = 0;
5417 //Got High precision coordinates
5418 snprintf(lng_sexagesimal, MAXINDIFORMAT, "%02d:%02d:%02.1lf", long_dd, long_mm, long_ssf);
5419 f_scansexa(lng_sexagesimal, &value);
5420 LocationNP[LOCATION_LONGITUDE].setValue(value);
5421 }
5422 }
5423 if(!OSHighPrecision) //Not using high precision
5424 {
5425 if (getSiteLongitude(PortFD, &long_dd, &long_mm, &long_ssf) < 0)
5426 {
5427 LOG_WARN("Failed to get site longitude from device.");
5428 return false;
5429 }
5430 else
5431 {
5432 double value = 0;
5433 snprintf(lng_sexagesimal, MAXINDIFORMAT, "%02d:%02d:%02.1lf", long_dd, long_mm, long_ssf);
5434
5435 f_scansexa(lng_sexagesimal, &value);
5436 LocationNP[LOCATION_LONGITUDE].setValue(value);
5437 }
5438 }
5439
5440 LOGF_INFO("Mount has Latitude %s (%g) Longitude %s (%g) (Longitude sign in carthography format)",
5441 lat_sexagesimal,
5442 LocationNP[LOCATION_LATITUDE].getValue(),
5443 lng_sexagesimal,
5444 LocationNP[LOCATION_LONGITUDE].getValue());
5445
5446 LocationNP.apply();
5447
5448 saveConfig(true, "GEOGRAPHIC_COORD");
5449
5450 return true;
5451}
5452
5453
5454bool LX200_OnStep::Goto(double ra, double dec)
5455{
5456 const struct timespec timeout = {0, 100000000L};
5457
5458 targetRA = ra;
5459 targetDEC = dec;
5460 char RAStr[64] = {0}, DecStr[64] = {0};
5461 int fracbase = 0;
5462
5463 switch (getLX200EquatorialFormat())
5464 {
5466 fracbase = 360000;
5467 break;
5470 default:
5471 fracbase = 3600;
5472 break;
5473 }
5474
5475 fs_sexa(RAStr, targetRA, 2, fracbase);
5476 fs_sexa(DecStr, targetDEC, 2, fracbase);
5477
5478 // If moving, let's stop it first.
5479 if (EqNP.getState() == IPS_BUSY)
5480 {
5481 if (!isSimulation() && abortSlew(PortFD) < 0)
5482 {
5483 AbortSP.setState(IPS_ALERT);
5484 LOG_ERROR("Abort slew failed.");
5485 Telescope::AbortSP.apply();
5486 return false;
5487 }
5488
5489 AbortSP.setState(IPS_OK);
5490 EqNP.setState(IPS_IDLE);
5491 LOG_ERROR("Slew aborted.");
5492 AbortSP.apply();
5493 EqNP.apply();
5494
5495 if (MovementNSSP.getState() == IPS_BUSY || MovementWESP.getState() == IPS_BUSY)
5496 {
5497 MovementNSSP.setState(IPS_IDLE);
5498 MovementWESP.setState(IPS_IDLE);
5499 EqNP.setState(IPS_IDLE);
5500 MovementNSSP.reset();
5501 MovementWESP.reset();
5502 MovementNSSP.apply();
5503 MovementWESP.apply();
5504 }
5505
5506 // sleep for 100 mseconds
5507 nanosleep(&timeout, nullptr);
5508 }
5509
5510 if (!isSimulation())
5511 {
5513 {
5514 EqNP.setState(IPS_ALERT);
5515 LOG_ERROR("Error setting RA/DEC.");
5516 EqNP.apply();
5517 return false;
5518 }
5519
5520 int err = 0;
5521
5522 /* Slew reads the '0', that is not the end of the slew */
5523 if ((err = Slew(PortFD)))
5524 {
5525 LOGF_ERROR("Error Slewing to JNow RA %s - DEC %s", RAStr, DecStr);
5526 slewError(err);
5527 return false;
5528 }
5529 }
5530
5531 //OnStep: DON'T set TrackState, this may resolve issues with the autoalign, this is updated by the status updates.
5532 // TrackState = SCOPE_SLEWING;
5533
5534 // Do report the goto as busy, though. Clients mark EQUATORIAL_EOD_COORD busy when they send it, and
5535 // ReadScopeStatus() only publishes EqNP when its state or the position changes. A goto that OnStep
5536 // finishes before the next status poll without changing the reported position (e.g. a goto to where
5537 // the mount already is) would otherwise never be answered, and the client would wait forever. With
5538 // EqNP busy here, the next poll finds the state changed and publishes the real one.
5539 EqNP.setState(IPS_BUSY);
5540 EqNP.apply();
5541
5542 LOGF_INFO("Slewing to RA: %s - DEC: %s", RAStr, DecStr);
5543
5544 return true;
5545}
5546
5548{
5549 //NOTE: THIS SHOULD ONLY BE CALLED _AFTER_ TrackState is set by the update function.
5550 //Otherwise it will not be consistent.
5551 LOG_DEBUG("OnStep SyncParkStatus called");
5553 IsParked = isparked;
5554 ParkSP.reset();
5555 ParkSP.setState(IPS_OK);
5556
5557 if (TrackState == SCOPE_PARKED)
5558 {
5559 ParkSP[PARK].setState(ISS_ON);
5560 LOG_INFO("Mount is parked.");
5561 }
5562 else
5563 {
5564 ParkSP[UNPARK].setState(ISS_ON);
5565 LOG_INFO("Mount is unparked.");
5566 }
5567
5568 ParkSP.apply();
5569}
5570
5571
5572void LX200_OnStep::SetParked(bool isparked)
5573{
5575 SyncParkStatus(isparked);
5577 if (parkDataType != PARK_NONE)
5578 WriteParkData();
5580}
5581
5583{
5584#ifdef DEBUG_TRACKSTATE
5585 switch(TrackState)
5586 {
5587 case(SCOPE_IDLE):
5588 LOG_DEBUG("TrackState: SCOPE_IDLE");
5589 return;
5590 case(SCOPE_SLEWING):
5591 LOG_DEBUG("TrackState: SCOPE_SLEWING");
5592 return;
5593 case(SCOPE_TRACKING):
5594 LOG_DEBUG("TrackState: SCOPE_TRACKING");
5595 return;
5596 case(SCOPE_PARKING):
5597 LOG_DEBUG("TrackState: SCOPE_PARKING");
5598 return;
5599 case(SCOPE_PARKED):
5600 LOG_DEBUG("TrackState: SCOPE_PARKED");
5601 return;
5602 }
5603#endif
5604 return;
5605}
5606
5608{
5609 bool result = true;
5610 char temp_string[RB_MAX_LEN];
5611 int utc_hour, utc_min;
5612 // strange thing offset is rounded up to first decimal so that .75 is .8
5613 utc_hour = int(offset) * -1;
5614 utc_min = abs((offset - int(offset)) * 60); // negative offsets require this abs()
5615 if (utc_min > 30) utc_min = 45;
5616 snprintf(temp_string, sizeof(temp_string), ":SG%03d:%02d#", utc_hour, utc_min);
5617 result = (setStandardProcedure(PortFD, temp_string) == 0);
5618 return result;
5619}
5620
5622{
5623 // Homing, Cold and Warm Init
5624 switch (action)
5625 {
5626 case HOME_GO:
5627 if(!sendOnStepCommandBlind(":hC#"))
5628 return IPS_ALERT;
5629 return IPS_BUSY;
5630
5631 case HOME_SET:
5632 if(!sendOnStepCommandBlind(":hF#"))
5633 return IPS_ALERT;
5634 return IPS_OK;
5635
5636 default:
5637 return IPS_ALERT;
5638 }
5639
5640 return IPS_ALERT;
5641}
5642
5644{
5645 if (checkConnection())
5646 {
5647 return true;
5648 }
5649
5650 /* OnStepX has a tendency to start up in an unresponsive state
5651 * due to grabage in the serial buffer. Try to reset it by sending
5652 * the :GVP# command repeatedly.
5653 *
5654 * First sending should result in a '0' response, the second in
5655 * 'OnStep' so the 2nd sending should return with a failure.
5656 */
5657 if(sendOnStepCommand(":GVP#"))
5658 {
5659 if(!sendOnStepCommand(":GVP#"))
5660 {
5661 return checkConnection();
5662 }
5663 }
5664
5665 return false;
5666}
5667
5669{
5670 SlewRateSP[0].fill("0", "0.25x", ISS_OFF);
5671 SlewRateSP[1].fill("1", "0.5x", ISS_OFF);
5672 SlewRateSP[2].fill("2", "1x", ISS_OFF);
5673 SlewRateSP[3].fill("3", "2x", ISS_OFF);
5674 SlewRateSP[4].fill("4", "4x", ISS_OFF);
5675 SlewRateSP[5].fill("5", "8x", ISS_ON);
5676 SlewRateSP[6].fill("6", "20x", ISS_OFF); //last OnStep - OnStepX
5677 SlewRateSP[7].fill("7", "48x", ISS_OFF);
5678 SlewRateSP[8].fill("8", "Half-Max", ISS_OFF);
5679 SlewRateSP[9].fill("9", "Max", ISS_OFF);
5680
5681 SlewRateSP.fill(getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate", MOTION_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
5682}
5683
5685{
5686 if (command == MOTION_START)
5687 {
5688 if (MovementWESP.getState() != IPS_BUSY && m_RememberPollingPeriod == 0)
5691 }
5692 else
5693 {
5694 // Only restore if WE isn't moving
5695 if (MovementWESP.getState() != IPS_BUSY)
5696 {
5699 }
5700 }
5701
5702 return LX200Telescope::MoveNS(dir, command);
5703}
5704
5706{
5707 if (command == MOTION_START)
5708 {
5709 if (MovementNSSP.getState() != IPS_BUSY && m_RememberPollingPeriod == 0)
5712 }
5713 else
5714 {
5715 // Only restore if NS isn't moving
5716 if (MovementNSSP.getState() != IPS_BUSY)
5717 {
5720 }
5721 }
5722
5723 return LX200Telescope::MoveWE(dir, command);
5724}
5725
The Interface class is the base class for all INDI connection plugins.
virtual std::string name()=0
bool isConnected() const
INDI::PropertyText getText(const char *name) const
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
void setCurrentPollingPeriod(uint32_t msec)
setCurrentPollingPeriod Change the current polling period to call TimerHit() function in the driver.
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
bool isSimulation() const
void syncDriverInfo()
syncDriverInfo sends the current driver information to the client.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
uint32_t getDriverInterface() const
Connection::Interface * getActiveConnection()
INDI::PropertyNumber FocusRelPosNP
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
void initProperties(const char *groupName)
Initialize focuser properties. It is recommended to call this function within initProperties() of you...
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process focus number properties.
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process focus switch properties.
INDI::PropertyNumber FocusAbsPosNP
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process Rotator switch properties.
RotatorInterface(DefaultDevice *defaultDevice)
void initProperties(const char *groupName)
Initialize Rotator properties. It is recommended to call this function within initProperties() of you...
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
void SetCapability(uint32_t cap)
SetRotatorCapability sets the Rotator capabilities. All capabilities must be initialized.
INDI::PropertyNumber RotatorBacklashNP
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process Rotator number properties.
INDI::PropertyNumber GotoRotatorNP
TelescopeStatus TrackState
void SetAxis1Park(double value)
SetRAPark Set current RA/AZ parking position. The data park file (stored in ~/.indi/ParkData....
void SetAxis1ParkDefault(double steps)
SetRAPark Set default RA/AZ parking position.
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
TelescopeParkData parkDataType
bool isParked()
isParked is mount currently parked?
uint32_t GetTelescopeCapability() const
GetTelescopeCapability returns the capability of the Telescope.
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
void setPierSide(TelescopePierSide side)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
void SetAxis2Park(double steps)
SetDEPark Set current DEC/ALT parking position. The data park file (stored in ~/.indi/ParkData....
void setMountType(TelescopeMountType type)
setMountType Report the mount type in TELESCOPE_MOUNT_TYPE. Drivers call it when the type is fixed by...
void SetParkDataType(TelescopeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
void SetAxis2ParkDefault(double steps)
SetDEParkDefault Set default DEC/ALT parking position.
void addParameter(std::string name, std::string label, double numMinOk, double numMaxOk, double percWarning, bool flipWarning=false)
Add a physical weather measurable parameter to the weather driver.
bool setCriticalParameter(std::string name)
setCriticalParameter Set parameter that is considered critical to the operation of the observatory....
bool syncCriticalParameters()
Synchronize and update the state of all critical parameters.
void setParameterValue(std::string name, double value)
setParameterValue Update weather parameter value
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process weather number properties.
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save parameters ranges in the config file.
INDI::PropertyNumber ParametersNP
void initProperties(const char *statusGroup, const char *paramsGroup)
Initialize focuser properties. It is recommended to call this function within initProperties() of you...
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
INDI::PropertyLight critialParametersLP
virtual bool initProperties() override
Called to initialize basic properties required all the time.
virtual bool getLocalDate(char *dateString)
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual bool getUTFOffset(double *offset)
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool getLocalTime(char *timeString)
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool checkConnection()
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual void getBasicData()
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
void setLX200Capability(uint32_t cap)
@ LX200_HAS_PRECISE_TRACKING_FREQ
bool AbortRotator() override
AbortRotator Abort all motion.
char OldOSStat[RB_MAX_LEN]
IPState ClearPECBuffer(int axis)
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
INDI::PropertyNumber OSSetTemperatureNP
IPState PECStatus(int axis)
virtual void Init_Outputs()
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
int getCommandSingleCharResponse(int fd, char *data, const char *cmd)
IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser the focuser in a particular direction with a specific speed for a finite duration.
int getCommandDoubleResponse(int fd, double *value, char *data, const char *cmd)
INDI::PropertySwitch TFCCompensationSP
uint8_t PECStatusGU
virtual IPState ExecuteHomeAction(TelescopeHomeAction action) override
Execute a homing action.
INDI::PropertyNumber OutputPorts_NP
int getCommandIntResponse(int fd, int *value, char *data, const char *cmd)
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
OnStepVersion OnStepMountVersion
virtual bool setLocalDate(uint8_t days, uint8_t months, uint16_t years) override
IPState AlignDone()
INDI::PropertyNumber MaxSlewRateNP
IPState OSDisableOutput(int output)
int m_MissedStatusReplies
INDI::PropertySwitch HomePauseSP
INDI::PropertyNumber GuideRateNP
virtual bool setUTCOffset(double offset) override
INDI::PropertyNumber TFCDeadbandNP
INDI::PropertyNumber ElevationLimitNP
INDI::PropertyText VersionTP
INDI::PropertySwitch OSRotatorDerotateSP
IPState OSEnableOutput(int output)
INDI::PropertyNumber ObjectNoNP
INDI::PropertySwitch OSPECStatusSP
IPState AlignStartGeometric(int stars)
IPState StartPECPlayback(int axis)
bool SetRotatorBacklash(int32_t steps) override
SetRotatorBacklash Set the Rotatorer backlash compensation value.
uint32_t m_RememberPollingPeriod
virtual bool UnPark() override
Unpark the telescope if already parked.
IPState StopPECPlayback(int axis)
IPState SavePECBuffer(int axis)
INDI::PropertySwitch OSNAlignWriteSP
bool OSAlignCompleted
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
INDI::PropertyNumber minutesPastMeridianNP
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
INDI::PropertyText OnstepStatTP
virtual void getBasicData() override
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
bool sendOnStepCommand(const char *cmd)
INDI::PropertySwitch OSFocus2RateSP
int flushIO(int fd)
INDI::PropertySwitch OSNAlignSP
virtual int setSiteLongitude(int fd, double Long)
long int OSTimeoutMicroSeconds
uint8_t ParkStatusGU
IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
IPState AlignAddStar()
AlignStartGeometric starts the OnStep Multistar align process.
INDI::PropertyNumber TFCCoefficientNP
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
int m_ParkTimeoutSeconds
IPState AlignWrite()
INDI::PropertySwitch OSFocus1InitializeSP
MountType OSMountType
virtual bool initProperties() override
Called to initialize basic properties required all the time.
char OSPier[RB_MAX_LEN]
INDI::PropertySwitch TrackAxisSP
bool sendOnStepCommandBlind(const char *cmd)
IPState StartPECRecord(int axis)
bool OSSupports_bitfield_Gu
virtual int setSiteLatitude(int fd, double Long)
long int OSTimeoutSeconds
virtual void SyncParkStatus(bool isparked) override
SyncParkStatus Update the state and switches for parking.
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual bool sendScopeLocation() override
INDI::PropertyNumber BacklashNP
int setMinElevationLimit(int fd, int min)
IPState ReadPECBuffer(int axis)
IPState WritePECBuffer(int axis)
INDI::PropertyText OSNAlignErrTP
char OldOSPier[RB_MAX_LEN]
IPState HomeRotator() override
HomeRotator Go to home position.
INDI::PropertyNumber OSSetHumidityNP
virtual bool Park() override
Park the telescope to its home position.
static constexpr int MAX_MISSED_STATUS_REPLIES
virtual void slewError(int slewCode) override
INDI::PropertyNumber OSSetAltitudeNP
bool SetRotatorBacklashEnabled(bool enabled) override
SetRotatorBacklashEnabled Enables or disables the Rotator backlash compensation.
INDI::PropertyText ObjectInfoTP
INDI::PropertySwitch ReticSP
char OSStat[RB_MAX_LEN]
int getCommandSingleCharErrorOrLongResponse(int fd, char *data, const char *cmd)
virtual bool UpdateAlignErr()
INDI::PropertySwitch OSPECRecordSP
virtual bool SetTrackRate(double raRate, double deRate) override
SetTrackRate Set custom tracking rates.
INDI::PropertyNumber FocusTemperatureNP
INDI::PropertyNumber OSFocus2TargNP
std::chrono::steady_clock::time_point m_ParkStartTime
INDI::PropertySwitch OSPECReadSP
INDI::PropertySwitch OSFocus2MotionSP
virtual bool sendScopeTime() override
bool OSGetOutputState(int output)
virtual bool UpdateAlignStatus()
INDI::PropertySwitch OSFocusSelectSP
IPState MoveRotator(double angle) override
MoveRotator Go to specific angle.
void PrintTrackState()
PrintTrackState will print to the debug log the status of TrackState if DEBUG_TRACKSTATE is defined o...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
INDI::PropertyText OSNAlignTP
virtual const char * getDefaultName() override
INDI::PropertySwitch OSPECIndexSP
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
INDI::PropertySwitch FrequencyAdjustSP
virtual void SetParked(bool isparked) override
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
INDI::PropertySwitch OSNAlignPolarRealignSP
INDI::PropertySwitch OSNAlignStarsSP
INDI::PropertySwitch PreferredPierSideSP
virtual bool Handshake() override
perform handshake with device to check communication
INDI::PropertyNumber OSSetPressureNP
INDI::PropertySwitch TrackCompSP
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
virtual bool ReadScopeStatus() override
Read telescope status.
bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
INDI::PropertySwitch AutoFlipSP
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
const char * FOCUS_TAB
FOCUS_TAB Where all the properties for focuser are located.
double max(void)
#define ROTATOR_TAB
Definition gemini.cpp:39
#define STATUS_TAB
Definition gemini.cpp:38
INDI::PropertySwitch ParkSP
INDI::PropertySwitch AbortSP
INDI::PropertyNumber TrackRateNP
INDI::PropertySwitch MovementNSSP
INDI::PropertyNumber EqNP
INDI::PropertySwitch TrackStateSP
INDI::PropertySwitch PECStateSP
INDI::PropertySwitch SlewRateSP
INDI::PropertySwitch TrackModeSP
INDI::PropertyText TimeTP
INDI::PropertySwitch MovementWESP
INDI::PropertySwitch ParkOptionSP
INDI::PropertySwitch CoordSP
INDI::PropertyNumber LocationNP
INDI::PropertyNumber TargetNP
double ra
double dec
#define RA_AXIS
#define DEC_AXIS
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
#define MAXINDIFORMAT
Definition indiapi.h:193
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
@ IP_WO
Definition indiapi.h:183
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
@ ISR_ATMOST1
Definition indiapi.h:172
#define MAXINDINAME
Definition indiapi.h:189
@ AXIS_DE
@ AXIS_RA
INDI_DIR_WE
INDI_DIR_NS
void getSexComponentsIID(double value, int *d, int *m, double *s)
Definition indicom.c:266
int f_scansexa(const char *str0, double *dp)
convert sexagesimal string str AxBxC to double. x can be anything non-numeric. Any missing A,...
Definition indicom.c:194
void getSexComponents(double value, int *d, int *m, int *s)
Definition indicom.c:243
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
Definition indicom.c:473
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Definition indicom.c:130
int tty_read_expanded(int fd, char *buf, int nbytes, long timeout_seconds, long timeout_microseconds, int *nbytes_read)
read buffer from terminal with a delimiter
Definition indicom.c:553
int tty_nread_section_expanded(int fd, char *buf, int nsize, char stop_char, long timeout_seconds, long timeout_microseconds, int *nbytes_read)
read buffer from terminal with a delimiter
Definition indicom.c:764
@ TTY_OK
Definition indicom.h:54
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition indidevapi.c:376
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:453
#define INDI_UNUSED(x)
Definition indidevapi.h:132
int IUGetConfigNumber(const char *dev, const char *property, const char *member, double *value)
IUGetConfigNumber Opens configuration file and reads single number property.
Definition indidriver.c:846
void IDMessage(const char *dev, const char *fmt,...)
Definition indidriver.c:983
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_DEBUG(txt)
Definition indilogger.h:75
#define LOGF_WARN(fmt,...)
Definition indilogger.h:81
#define LOG_WARN(txt)
Definition indilogger.h:73
#define LOGF_DEBUG(fmt,...)
Definition indilogger.h:83
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Definition indilogger.h:72
#define LOGF_ERROR(fmt,...)
Definition indilogger.h:80
#define LOG_INFO(txt)
Definition indilogger.h:74
#define DEBUGF(priority, msg,...)
Definition indilogger.h:57
#define TRACKRATE_SIDEREAL
Definition indimacros.h:39
#define getDeviceName
INDI::WeatherInterface WI
int fd
#define PEC_TAB
#define OUTPUT_TAB
#define ENVIRONMENT_TAB
#define ALIGN_TAB
@ MOUNTTYPE_GEM
@ MOUNTTYPE_ALTAZ
@ MOUNTTYPE_FORK
@ MOUNTTYPE_FORK_ALT
#define RB_MAX_LEN
#define STARTING_PORT
@ OSV_OnStepV4
@ OSV_OnStepV3
@ OSV_OnStepV5
@ OSV_UNKNOWN
@ OSV_OnStepV1or2
@ OSV_OnStepX
@ RES_ERR_FORMAT
Errors
@ ERR_GOTO_ERR_ABOVE_OVERHEAD
@ ERR_GOTO_ERR_PARK
@ ERR_MERIDIAN
@ ERR_GOTO_ERR_OUTSIDE_LIMITS
@ ERR_GOTO_ERR_BELOW_HORIZON
@ ERR_LIMIT_SENSE
@ ERR_DEC
@ ERR_NONE
@ ERR_GOTO_ERR_GOTO
@ ERR_UNDER_POLE
@ ERR_ALT_MAX
@ ERR_GOTO_ERR_IN_MOTION
@ ERR_GOTO_ERR_UNSPECIFIED
@ ERR_SYNC
@ ERR_ALT_MIN
@ ERR_GOTO_ERR_STANDBY
@ ERR_AZM
@ ERR_UNSPECIFIED
@ ERR_PARK
@ ERR_GOTO_ERR_NONE
@ ERR_GOTO_ERR_HARDWARE_FAULT
@ ERR_MOTOR_FAULT
@ ERR_GOTO_SYNC
#define CMD_MAX_LEN
#define PORTS_COUNT
std::mutex lx200CommsLock
#define FIRMWARE_TAB
int getSiteLongitude(int fd, int *ddd, int *mm, double *ssf)
int getSiteLatitudeAlt(int fd, int *dd, int *mm, double *ssf, const char *cmd)
int setMaxElevationLimit(int fd, int max)
int setObjectRA(int fd, double ra, bool addSpace)
int getLX200EquatorialFormat()
int setStandardProcedure(int fd, const char *data)
int setObjectDEC(int fd, double dec, bool addSpace)
int abortSlew(int fd)
int Slew(int fd)
int getSiteLongitudeAlt(int fd, int *ddd, int *mm, double *ssf, const char *cmd)
int getSiteLatitude(int fd, int *dd, int *mm, double *ssf)
int selectCatalogObject(int fd, int catalog, int NNNN)
#define getVersionDate(fd, x)
#define increaseReticleBrightness(fd)
#define getObjectInfo(fd, x)
#define getVersionTime(fd, x)
#define getLX200DEC(fd, x)
@ LX200_STAR_C
Definition lx200driver.h:83
#define getVersionNumber(fd, x)
#define getLX200RA(fd, x)
#define decreaseReticleBrightness(fd)
#define getProductName(fd, x)
@ LX200_EQ_LONGER_FORMAT
Definition lx200driver.h:52
@ LX200_EQ_SHORT_FORMAT
Definition lx200driver.h:50
@ LX200_EQ_LONG_FORMAT
Definition lx200driver.h:51
#define slewToPark(fd)
uint8_t cmd[4]
Definition pwc-ioctl.h:2