Instrument Neutral Distributed Interface INDI  2.0.2
planewave_efa.h
Go to the documentation of this file.
1 /*
2  PlaneWave EFA Protocol
3 
4  Hendrick Focuser
5 
6  Copyright (C) 2020 Jasem Mutlaq (mutlaqja@ikarustech.com)
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 */
23 
24 #pragma once
25 
26 #include "indifocuser.h"
27 
28 #include <map>
29 
30 class EFA : public INDI::Focuser
31 {
32  public:
33  EFA();
34 
35  virtual bool Handshake() override;
36  const char *getDefaultName() override;
37  virtual bool initProperties() override;
38  virtual bool updateProperties() override;
39 
40  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
41  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
42 
43  enum
44  {
45  MTR_GET_POS = 0x01,
46  MTR_GOTO_POS2 = 0x17,
48  MTR_GOTO_OVER = 0x13,
53  TEMP_GET = 0x26,
54  FANS_SET = 0x27,
55  FANS_GET = 0x28,
62  GET_VERSION = 0xFE
63  };
64 
65  enum
66  {
67  DEVICE_PC = 0x20,
68  DEVICE_HC = 0x0D,
69  DEVICE_FOC = 0x12,
70  DEVICE_FAN = 0x13,
71  DEVICE_TEMP = 0x12
72  };
73 
74  protected:
75  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
76  virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override;
77  virtual bool SyncFocuser(uint32_t ticks) override;
78  virtual bool ReverseFocuser(bool enabled) override;
79  virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
80  virtual bool AbortFocuser() override;
81  virtual void TimerHit() override;
82  virtual bool Disconnect() override;
83 
84  virtual bool saveConfigItems(FILE *fp) override;
85 
86  private:
90  bool isGOTOComplete();
91  bool readPosition();
92  bool readTemperature();
93  bool readFanState();
94  bool readCalibrationState();
95  bool readMaxSlewLimit();
96 
100  bool setFanEnabled(bool enabled);
101  bool setCalibrationEnabled(bool enabled);
102 
106  //bool readResponse(uint8_t * res, uint32_t res_len, int *nbytes_read);
107  int readByte(int fd, uint8_t *buf, int timeout, int *nbytes_read);
108  int readBytes(int fd, uint8_t *buf, int nbytes, int timeout, int *nbytes_read);
109  int writeBytes(int fd, const uint8_t *buf, int nbytes, int *nbytes_written);
110  int readPacket(int fd, uint8_t *buf, int nbytes, int timeout, int *nbytes_read);
111  bool sendCommand(const uint8_t * cmd, uint8_t * res, uint32_t cmd_len, uint32_t res_len);
112  char * efaDump(char * buf, int buflen, const uint8_t * data, uint32_t size);
113  std::vector<std::string> split(const std::string &input, const std::string &regex);
114 
118  void getStartupValues();
119  double calculateTemperature(uint8_t byte2, uint8_t byte3);
120  bool validateLengths(const uint8_t *cmd, uint32_t len);
121  uint8_t calculateCheckSum(const uint8_t *cmd, uint32_t len);
122  template <typename T> std::string to_string(const T a_value, const int n = 2);
123 
127 
128  // Focuser Informatin
129  ITextVectorProperty InfoTP;
130  IText InfoT[1] {};
131  enum
132  {
133  INFO_VERSION
134  };
135 
136 
137  // FAN State
138  ISwitchVectorProperty FanStateSP;
139  ISwitch FanStateS[2];
140  enum
141  {
142  FAN_ON,
143  FAN_OFF
144  };
145 
146  // Fan Control Mode
147  ISwitchVectorProperty FanControlSP;
148  ISwitch FanControlS[3];
149  enum
150  {
151  FAN_MANUAL,
152  FAN_AUTOMATIC_ABSOLUTE,
153  FAN_AUTOMATIC_RELATIVE,
154  };
155 
156  // Fan Control Parameters
157  INumberVectorProperty FanControlNP;
158  INumber FanControlN[3];
159  enum
160  {
161  FAN_MAX_ABSOLUTE,
162  FAN_MAX_RELATIVE,
163  FAN_DEADZONE,
164  };
165 
166  // Fan Off on Disconnect
167  ISwitchVectorProperty FanDisconnectSP;
168  ISwitch FanDisconnectS[1];
169  enum
170  {
171  FAN_OFF_ON_DISCONNECT
172  };
173 
174  // Calibration State
175  ISwitchVectorProperty CalibrationStateSP;
176  ISwitch CalibrationStateS[2];
177  enum
178  {
179  CALIBRATION_ON,
180  CALIBRATION_OFF
181  };
182 
183  // Read Only Temperature Reporting
184  INumberVectorProperty TemperatureNP;
185  INumber TemperatureN[2];
186  enum
187  {
188  TEMPERATURE_PRIMARY,
189  TEMPERATURE_AMBIENT
190  };
191 
195  double m_LastTemperature[2];
196  double m_LastPosition {0};
197 
198  bool IN_TIMER = false;
199 
203  // Start of Message
204  static const uint8_t DRIVER_SOM { 0x3B };
205  // Temperature Reporting threshold
206  static constexpr double TEMPERATURE_THRESHOLD { 0.05 };
207 
208  static constexpr const uint8_t DRIVER_LEN {9};
209  // Wait up to a maximum of 3 seconds for serial input
210  static constexpr const uint8_t DRIVER_TIMEOUT {3};
211  // Fan Control
212  static constexpr const char *FAN_TAB = "Fan";
213 };
virtual bool SyncFocuser(uint32_t ticks) override
Sync focuser.
virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override
Move Focuser relatively.
@ MTR_SLEWLIMITMAX
Definition: planewave_efa.h:49
@ MTR_SLEWLIMITGETMAX
Definition: planewave_efa.h:50
@ MTR_GET_APPROACH_DIRECTION
Definition: planewave_efa.h:60
@ GET_VERSION
Definition: planewave_efa.h:62
@ TEMP_GET
Definition: planewave_efa.h:53
@ MTR_GET_STOP_DETECT
Definition: planewave_efa.h:58
@ FANS_GET
Definition: planewave_efa.h:55
@ MTR_GOTO_OVER
Definition: planewave_efa.h:48
@ MTR_GOTO_POS2
Definition: planewave_efa.h:46
@ MTR_PMSLEW_RATE
Definition: planewave_efa.h:51
@ MTR_OFFSET_CNT
Definition: planewave_efa.h:47
@ FANS_SET
Definition: planewave_efa.h:54
@ MTR_STOP_DETECT
Definition: planewave_efa.h:59
@ MTR_NMSLEW_RATE
Definition: planewave_efa.h:52
@ MTR_SET_CALIBRATION_STATE
Definition: planewave_efa.h:57
@ MTR_APPROACH_DIRECTION
Definition: planewave_efa.h:61
@ MTR_GET_CALIBRATION_STATE
Definition: planewave_efa.h:56
@ MTR_GET_POS
Definition: planewave_efa.h:45
virtual bool ReverseFocuser(bool enabled) override
Reverse Focuser Motion.
@ DEVICE_HC
Definition: planewave_efa.h:68
@ DEVICE_PC
Definition: planewave_efa.h:67
@ DEVICE_FOC
Definition: planewave_efa.h:69
@ DEVICE_TEMP
Definition: planewave_efa.h:71
@ DEVICE_FAN
Definition: planewave_efa.h:70
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
Set Maximum Position.
const char * getDefaultName() override
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
Move Absolute Focuser.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool Disconnect() override
Disconnect from device.
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
int fd
Definition: intelliscope.c:43
__u8 cmd[4]
Definition: pwc-ioctl.h:2
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246