Instrument Neutral Distributed Interface INDI  2.0.2
crux_mount.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Driver type: TitanTCS for HOBYM CRUX Mount INDI Driver
3 
4  Copyright(c) 2020 Park Suyoung <hparksy@gmail.com>. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9  .
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14  .
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 
21 #pragma once
22 
23 #include "inditelescope.h"
24 #include "indiguiderinterface.h"
25 
26 #define RESPONSE_TIMEOUT 3
27 #define USE_PEC 1
28 
29 typedef struct
30 {
31  double ra;
32  double dec;
33  //
34  int Parking;
35 #if USE_PEC
36  int PECStatus;
37 #endif
38  int Landscape;
41 } stTitanTCS;
42 
44 {
45  public:
46  TitanTCS();
47 
48  private:
49  int m_Connect;
50 
51  public:
52  virtual const char *getDefaultName() override;
53  virtual bool Connect() override;
54  virtual bool Disconnect() override;
55  virtual bool Handshake() override;
56  virtual bool ReadScopeStatus() override;
57 
58  //virtual void ISGetProperties(const char *dev) override;
59  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
60  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
61  virtual bool initProperties() override;
62  virtual bool updateProperties() override;
63 
64  virtual bool ISNewText(const char *dev, const char *name, char **texts, char **names, int n) override;
65 
66  private:
67  // Mount Info.
68  ITextVectorProperty MountInfoTP;
69  IText MountInfoT[2] {};
70  int GuideNSTID { -1 };
71  int GuideWETID { -1 };
72 
73  stTitanTCS info;
74 #if USE_PEC
75  // PECStatus
76  int _PECStatus {0};
77 
78  // PEC Training
79  ISwitch PECTrainingS[2];
80  ISwitchVectorProperty PECTrainingSP;
81  // PEC Info.
82  ITextVectorProperty PECInfoTP;
83  IText PECInfoT[2] {};
84 #endif
85 
86  protected:
87  // Goto, Sync, and Motion
88  virtual bool Goto(double ra, double dec) override;
89  //bool GotoAzAlt(double az, double alt);
90  virtual bool Sync(double ra, double dec) override;
91  virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override;
92  virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override;
93  virtual bool Abort() override;
94  virtual bool SetSlewRate(int index) override;
95 
96  // Time and Location
97  virtual bool updateLocation(double latitude, double longitude, double elevation) override;
98  virtual bool updateTime(ln_date *utc, double utc_offset) override;
99 
100  //GUIDE: guiding functions
101  virtual IPState GuideNorth(uint32_t ms) override;
102  virtual IPState GuideSouth(uint32_t ms) override;
103  virtual IPState GuideEast(uint32_t ms) override;
104  virtual IPState GuideWest(uint32_t ms) override;
105  // Tracking
106  virtual bool SetTrackMode(uint8_t mode) override;
107  virtual bool SetTrackEnabled(bool enabled) override;
108 
109  // Parking
110  virtual bool Park() override;
111  virtual bool UnPark() override;
112  virtual bool SetCurrentPark() override;
113  virtual bool SetDefaultPark() override;
114  virtual bool SetParkPosition(double Axis1Value, double Axis2Value) override;
115 
116  private:
117  bool SendCommand(const char *cmd_org);
118  bool SendCommand(const char *cmd, int val);
119  bool SendCommand(const char *cmd, double val);
120 
121  bool CommandResponse(const char* pCommand, const char* pResponse, char delimeter, double *pDouble, int *pInteger = nullptr);
122  bool CommandResponseHour(const char* pCommand, const char* pResponse, char delimeter, double* Hour);
123  bool CommandResponseStr(const char* pCommand, const char* pResponse, char delimeter, char* pReturn, int len = 0);
124  bool CommandResponseChar(const char* pCommand, const char* pResponse, char* pReturn);
125 
126  bool GetMountParams(bool bAll = false);
127 
128  bool GetParamStr(const char* pInStr, char* pOutStr, int len, const char* pResponse, char delimeter);
129  bool GetParamNumber(const char* pInStr, char* pOutStr, int len, const char* pResponse, char delimeter, double *pDouble,
130  int *pInteger = NULL);
131  bool GetParamHour(const char* pInStr, char* pOutStr, int len, const char* pResponse, char delimeter, double *pHour);
132 
133  bool GetEqPosition(INDI_EQ_AXIS axis, double *value);
134  bool GetEqPosition(double *ra, double *dec);
135 
136  void ReadFlush();
137  int ReadResponse(char *buf, int len, char delimeter, int timeout = RESPONSE_TIMEOUT);
138 
139  bool SetTarget(double ra, double dec);
140 
141  void guideTimeoutNS();
142  void guideTimeoutWE();
143 
144  static void guideTimeoutHelperNS(void * p);
145  static void guideTimeoutHelperWE(void * p);
146 #if USE_PEC
147  void _setPECState(int pec_status);
148 #endif
149 };
150 
151 
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
Definition: crux_mount.cpp:534
virtual bool ReadScopeStatus() override
Read telescope status.
Definition: crux_mount.cpp:637
virtual bool Disconnect() override
Disconnect from device.
Definition: crux_mount.cpp:79
virtual bool Park() override
Park the telescope to its home position.
virtual bool Abort() override
Abort any telescope motion including tracking if possible.
Definition: crux_mount.cpp:625
virtual bool MoveWE(INDI_DIR_WE dir, TelescopeMotionCommand command) override
Move the telescope in the direction dir.
virtual bool Handshake() override
perform handshake with device to check communication
Definition: crux_mount.cpp:317
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: crux_mount.cpp:200
virtual bool UnPark() override
Unpark the telescope if already parked.
virtual bool ISNewText(const char *dev, const char *name, char **texts, char **names, int n) override
Definition: crux_mount.cpp:309
virtual bool MoveNS(INDI_DIR_NS dir, TelescopeMotionCommand command) override
Start or Stop the telescope motion in the direction dir.
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
Definition: crux_mount.cpp:568
virtual bool Sync(double ra, double dec) override
Set the telescope current RA and DEC coordinates to the supplied RA and DEC coordinates.
virtual bool SetParkPosition(double Axis1Value, double Axis2Value) override
SetParkPosition Set desired parking position to the supplied value. This ONLY sets the desired park p...
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual bool updateProperties() override
Called when connected state changes, to add/remove properties.
Definition: crux_mount.cpp:135
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
Definition: crux_mount.cpp:551
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: crux_mount.cpp:171
virtual bool updateLocation(double latitude, double longitude, double elevation) override
Update telescope location settings.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: crux_mount.cpp:64
virtual bool SetSlewRate(int index) override
SetSlewRate Set desired slew rate index.
virtual bool SetTrackEnabled(bool enabled) override
SetTrackEnabled Engages or disengages mount tracking. If there are no tracking modes available,...
virtual bool updateTime(ln_date *utc, double utc_offset) override
Update telescope time, date, and UTC offset.
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
Definition: crux_mount.cpp:517
virtual bool initProperties() override
Called to initialize basic properties required all the time.
Definition: crux_mount.cpp:92
virtual const char * getDefaultName() override
Definition: crux_mount.cpp:588
virtual bool SetTrackMode(uint8_t mode) override
SetTrackMode Set active tracking mode. Do not change track state.
virtual bool Goto(double ra, double dec) override
Move the scope to the supplied RA and DEC coordinates.
Definition: crux_mount.cpp:596
#define RESPONSE_TIMEOUT
Definition: crux_mount.h:26
double ra
double dec
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
INDI_EQ_AXIS
Definition: indibasetypes.h:34
INDI_DIR_WE
Definition: indibasetypes.h:55
INDI_DIR_NS
Definition: indibasetypes.h:48
__u8 cmd[4]
Definition: pwc-ioctl.h:2
One switch descriptor.
One text descriptor.
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246
int Landscape
Definition: crux_mount.h:38
int TrackingRate
Definition: crux_mount.h:39
int TrackingStatus
Definition: crux_mount.h:40
double dec
Definition: crux_mount.h:32
double ra
Definition: crux_mount.h:31
int Parking
Definition: crux_mount.h:34
int PECStatus
Definition: crux_mount.h:36