Instrument Neutral Distributed Interface INDI  1.9.5
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 };
EFA::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: planewave_efa.cpp:126
EFA::DEVICE_FOC
@ DEVICE_FOC
Definition: planewave_efa.h:69
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
fd
int fd
Definition: indiserver.c:117
IPState
IPState
Property state.
Definition: indiapi.h:158
EFA::MTR_SLEWLIMITMAX
@ MTR_SLEWLIMITMAX
Definition: planewave_efa.h:49
EFA::DEVICE_PC
@ DEVICE_PC
Definition: planewave_efa.h:67
EFA::MTR_SLEWLIMITGETMAX
@ MTR_SLEWLIMITGETMAX
Definition: planewave_efa.h:50
EFA::getDefaultName
const char * getDefaultName() override
Definition: planewave_efa.cpp:205
ISwitch
One switch descriptor.
EFA::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
Sync focuser.
Definition: planewave_efa.cpp:320
INumber
One number descriptor.
EFA::MTR_OFFSET_CNT
@ MTR_OFFSET_CNT
Definition: planewave_efa.h:47
EFA::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: planewave_efa.cpp:532
EFA::DEVICE_TEMP
@ DEVICE_TEMP
Definition: planewave_efa.h:71
EFA::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override
Move Focuser relatively.
Definition: planewave_efa.cpp:372
EFA::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: planewave_efa.cpp:388
EFA::MTR_GET_POS
@ MTR_GET_POS
Definition: planewave_efa.h:45
EFA::FANS_GET
@ FANS_GET
Definition: planewave_efa.h:55
EFA::GET_VERSION
@ GET_VERSION
Definition: planewave_efa.h:62
indifocuser.h
EFA::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
Move Absolute Focuser.
Definition: planewave_efa.cpp:346
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
EFA::MTR_GET_CALIBRATION_STATE
@ MTR_GET_CALIBRATION_STATE
Definition: planewave_efa.h:56
EFA::FANS_SET
@ FANS_SET
Definition: planewave_efa.h:54
EFA
Definition: planewave_efa.h:30
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
IText
One text descriptor.
EFA::EFA
EFA()
Definition: planewave_efa.cpp:41
EFA::MTR_APPROACH_DIRECTION
@ MTR_APPROACH_DIRECTION
Definition: planewave_efa.h:61
EFA::MTR_GET_STOP_DETECT
@ MTR_GET_STOP_DETECT
Definition: planewave_efa.h:58
EFA::MTR_GOTO_OVER
@ MTR_GOTO_OVER
Definition: planewave_efa.h:48
EFA::MTR_PMSLEW_RATE
@ MTR_PMSLEW_RATE
Definition: planewave_efa.h:51
EFA::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: planewave_efa.cpp:489
EFA::SetFocuserMaxPosition
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
Set Maximum Position.
Definition: planewave_efa.cpp:497
EFA::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: planewave_efa.cpp:53
EFA::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
Reverse Focuser Motion.
Definition: planewave_efa.cpp:523
EFA::DEVICE_FAN
@ DEVICE_FAN
Definition: planewave_efa.h:70
name
const char * name
Definition: indiserver.c:116
EFA::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: planewave_efa.cpp:300
EFA::DEVICE_HC
@ DEVICE_HC
Definition: planewave_efa.h:68
EFA::MTR_GOTO_POS2
@ MTR_GOTO_POS2
Definition: planewave_efa.h:46
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
EFA::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: planewave_efa.cpp:213
EFA::MTR_GET_APPROACH_DIRECTION
@ MTR_GET_APPROACH_DIRECTION
Definition: planewave_efa.h:60
EFA::MTR_NMSLEW_RATE
@ MTR_NMSLEW_RATE
Definition: planewave_efa.h:52
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::Focuser
Definition: indifocuser.h:43
EFA::MTR_SET_CALIBRATION_STATE
@ MTR_SET_CALIBRATION_STATE
Definition: planewave_efa.h:57
EFA::TEMP_GET
@ TEMP_GET
Definition: planewave_efa.h:53
EFA::Disconnect
virtual bool Disconnect() override
Disconnect from device.
Definition: planewave_efa.cpp:164
EFA::MTR_STOP_DETECT
@ MTR_STOP_DETECT
Definition: planewave_efa.h:59
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
EFA::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: planewave_efa.cpp:175