Instrument Neutral Distributed Interface INDI 2.2.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 ([email protected])
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
30class 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 {
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 bool SetFocuserSpeed(int speed) override;
82 virtual void TimerHit() override;
83 virtual bool Disconnect() override;
84
85 virtual bool saveConfigItems(FILE *fp) override;
86
87 private:
91 bool isGOTOComplete();
92 bool readPosition();
93 bool readTemperature();
94 bool readFanState();
95 bool readCalibrationState();
96 bool readMaxSlewLimit();
97 bool readSlewRate();
98 bool readApproachDirection();
99 bool readStopDetect();
100
104 bool setFanEnabled(bool enabled);
105 bool setCalibrationEnabled(bool enabled);
106 bool setMotorSlewRate(uint8_t rate);
107 bool setApproachDirection(uint8_t direction);
108 bool setStopDetect(bool enabled);
109
113 int readByte(int fd, uint8_t *buf, int timeout, int *nbytes_read);
114 int readBytes(int fd, uint8_t *buf, int nbytes, int timeout, int *nbytes_read);
115 int writeBytes(int fd, const uint8_t *buf, int nbytes, int *nbytes_written);
116 int readPacket(int fd, uint8_t *buf, int nbytes, int timeout, int *nbytes_read);
117 bool sendCommand(const uint8_t * cmd, uint8_t * res, uint32_t cmd_len, uint32_t res_len);
118 char * efaDump(char * buf, int buflen, const uint8_t * data, uint32_t size);
119 std::vector<std::string> split(const std::string &input, const std::string &regex);
120
124 void getStartupValues();
125 double calculateTemperature(uint8_t byte2, uint8_t byte3);
126 bool validateLengths(const uint8_t *cmd, uint32_t len);
127 uint8_t calculateCheckSum(const uint8_t *cmd, uint32_t len);
128 template <typename T> std::string to_string(const T a_value, const int n = 2);
129
133
134 // Focuser Information
135 INDI::PropertyText InfoTP {1};
136 enum
137 {
138 INFO_VERSION
139 };
140
141 // FAN State
142 INDI::PropertySwitch FanStateSP {2};
143 enum
144 {
145 FAN_ON,
146 FAN_OFF
147 };
148
149 // Fan Control Mode
150 INDI::PropertySwitch FanControlSP {3};
151 enum
152 {
153 FAN_MANUAL,
154 FAN_AUTOMATIC_ABSOLUTE,
155 FAN_AUTOMATIC_RELATIVE,
156 };
157
158 // Fan Control Parameters
159 INDI::PropertyNumber FanControlNP {3};
160 enum
161 {
162 FAN_MAX_ABSOLUTE,
163 FAN_MAX_RELATIVE,
164 FAN_DEADZONE,
165 };
166
167 // Fan Off on Disconnect
168 INDI::PropertySwitch FanDisconnectSP {1};
169 enum
170 {
171 FAN_OFF_ON_DISCONNECT
172 };
173
174 // Calibration State
175 INDI::PropertySwitch CalibrationStateSP {2};
176 enum
177 {
178 CALIBRATION_ON,
179 CALIBRATION_OFF
180 };
181
182 // Approach Direction for consistent backlash compensation
183 INDI::PropertySwitch ApproachDirectionSP {2};
184 enum
185 {
186 APPROACH_POSITIVE,
187 APPROACH_NEGATIVE
188 };
189
190 // Stop Detection (end-of-travel limit switch detection)
191 INDI::PropertySwitch StopDetectSP {2};
192 enum
193 {
194 STOP_DETECT_ON,
195 STOP_DETECT_OFF
196 };
197
198 // Read Only Temperature Reporting
199 INDI::PropertyNumber TemperatureNP {2};
200 enum
201 {
202 TEMPERATURE_PRIMARY,
203 TEMPERATURE_AMBIENT
204 };
205
209 double m_LastTemperature[2] {0, 0};
210 double m_LastPosition {0};
211
212 bool IN_TIMER = false;
213
217 // Start of Message
218 static const uint8_t DRIVER_SOM { 0x3B };
219 // Temperature Reporting threshold
220 static constexpr double TEMPERATURE_THRESHOLD { 0.05 };
221 // Invalid temperature sentinel value returned by hardware (0x7F, 0x7F)
222 static constexpr double TEMPERATURE_INVALID { -100.0 };
223
224 static constexpr const uint8_t DRIVER_LEN {9};
225 // Wait up to a maximum of 3 seconds for serial input
226 static constexpr const uint8_t DRIVER_TIMEOUT {3};
227 // Fan Control
228 static constexpr const char *FAN_TAB = "Fan";
229};
virtual bool SyncFocuser(uint32_t ticks) override
Sync focuser.
virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override
Move Focuser relatively.
virtual bool ReverseFocuser(bool enabled) override
Reverse Focuser Motion.
@ DEVICE_HC
@ DEVICE_PC
@ DEVICE_FOC
@ DEVICE_TEMP
@ DEVICE_FAN
virtual bool saveConfigItems(FILE *fp) override
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
Set Maximum Position.
@ MTR_SLEWLIMITMAX
@ MTR_SLEWLIMITGETMAX
@ MTR_GET_APPROACH_DIRECTION
@ GET_VERSION
@ TEMP_GET
@ MTR_GET_STOP_DETECT
@ FANS_GET
@ MTR_GOTO_OVER
@ MTR_GOTO_POS2
@ MTR_PMSLEW_RATE
@ MTR_OFFSET_CNT
@ FANS_SET
@ MTR_STOP_DETECT
@ MTR_NMSLEW_RATE
@ MTR_SET_CALIBRATION_STATE
@ MTR_APPROACH_DIRECTION
@ MTR_GET_CALIBRATION_STATE
@ MTR_GET_POS
const char * getDefaultName() override
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
Move Absolute Focuser.
virtual bool AbortFocuser() override
virtual bool SetFocuserSpeed(int speed) override
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
virtual bool Disconnect() override
Disconnect from device.
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
int fd
uint8_t cmd[4]
Definition pwc-ioctl.h:2