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 {
51 // Not a speed setting: these MOVE the motor positive/negative at speed 0x00 (stop) to 0x09
52 // until the slew limit is reached (PlaneWave EFA protocol). Never send them to query anything.
55 TEMP_GET = 0x26,
56 FANS_SET = 0x27,
57 FANS_GET = 0x28,
65 };
66
67 enum
68 {
69 DEVICE_PC = 0x20,
70 DEVICE_HC = 0x0D,
71 DEVICE_FOC = 0x12,
72 DEVICE_FAN = 0x13,
74 };
75
76 protected:
77 virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
78 virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override;
79 virtual bool SyncFocuser(uint32_t ticks) override;
80 virtual bool ReverseFocuser(bool enabled) override;
81 virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
82 virtual bool AbortFocuser() override;
83 virtual void TimerHit() override;
84 virtual bool Disconnect() override;
85
86 virtual bool saveConfigItems(FILE *fp) override;
87
88 private:
92 bool isGOTOComplete();
93 bool readPosition();
94 bool readTemperature();
95 bool readFanState();
96 bool readCalibrationState();
97 bool readMaxSlewLimit();
98 bool readApproachDirection();
99 bool readStopDetect();
100
104 bool setFanEnabled(bool enabled);
105 bool setCalibrationEnabled(bool enabled);
106 bool setApproachDirection(uint8_t direction);
107 bool setStopDetect(bool enabled);
108
112 int readByte(int fd, uint8_t *buf, int timeout, int *nbytes_read);
113 int readBytes(int fd, uint8_t *buf, int nbytes, int timeout, int *nbytes_read);
114 int writeBytes(int fd, const uint8_t *buf, int nbytes, int *nbytes_written);
115 int readPacket(int fd, uint8_t *buf, int nbytes, int timeout, int *nbytes_read);
116 bool sendCommand(const uint8_t * cmd, uint8_t * res, uint32_t cmd_len, uint32_t res_len);
117 char * efaDump(char * buf, int buflen, const uint8_t * data, uint32_t size);
118 std::vector<std::string> split(const std::string &input, const std::string &regex);
119
123 void getStartupValues();
124 double calculateTemperature(uint8_t byte2, uint8_t byte3);
125 bool validateLengths(const uint8_t *cmd, uint32_t len);
126 uint8_t calculateCheckSum(const uint8_t *cmd, uint32_t len);
127 template <typename T> std::string to_string(const T a_value, const int n = 2);
128
132
133 // Focuser Information
134 INDI::PropertyText InfoTP {1};
135 enum
136 {
137 INFO_VERSION
138 };
139
140 // FAN State
141 INDI::PropertySwitch FanStateSP {2};
142 enum
143 {
144 FAN_ON,
145 FAN_OFF
146 };
147
148 // Fan Control Mode
149 INDI::PropertySwitch FanControlSP {3};
150 enum
151 {
152 FAN_MANUAL,
153 FAN_AUTOMATIC_ABSOLUTE,
154 FAN_AUTOMATIC_RELATIVE,
155 };
156
157 // Fan Control Parameters
158 INDI::PropertyNumber FanControlNP {3};
159 enum
160 {
161 FAN_MAX_ABSOLUTE,
162 FAN_MAX_RELATIVE,
163 FAN_DEADZONE,
164 };
165
166 // Fan Off on Disconnect
167 INDI::PropertySwitch FanDisconnectSP {1};
168 enum
169 {
170 FAN_OFF_ON_DISCONNECT
171 };
172
173 // Calibration State
174 INDI::PropertySwitch CalibrationStateSP {2};
175 enum
176 {
177 CALIBRATION_ON,
178 CALIBRATION_OFF
179 };
180
181 // Approach Direction for consistent backlash compensation
182 INDI::PropertySwitch ApproachDirectionSP {2};
183 enum
184 {
185 APPROACH_POSITIVE,
186 APPROACH_NEGATIVE
187 };
188
189 // Stop Detection (end-of-travel limit switch detection)
190 INDI::PropertySwitch StopDetectSP {2};
191 enum
192 {
193 STOP_DETECT_ON,
194 STOP_DETECT_OFF
195 };
196
197 // Read Only Temperature Reporting
198 INDI::PropertyNumber TemperatureNP {2};
199 enum
200 {
201 TEMPERATURE_PRIMARY,
202 TEMPERATURE_AMBIENT
203 };
204
208 double m_LastTemperature[2] {0, 0};
209 double m_LastPosition {0};
210
211 bool IN_TIMER = false;
212
216 // Start of Message
217 static const uint8_t DRIVER_SOM { 0x3B };
218 // Temperature Reporting threshold
219 static constexpr double TEMPERATURE_THRESHOLD { 0.05 };
220 // Invalid temperature sentinel value returned by hardware (0x7F, 0x7F)
221 static constexpr double TEMPERATURE_INVALID { -100.0 };
222
223 static constexpr const uint8_t DRIVER_LEN {9};
224 // Wait up to a maximum of 3 seconds for serial input
225 static constexpr const uint8_t DRIVER_TIMEOUT {3};
226 // Fan Control
227 static constexpr const char *FAN_TAB = "Fan";
228};
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.
virtual bool saveConfigItems(FILE *fp) override
@ DEVICE_HC
@ DEVICE_PC
@ DEVICE_FOC
@ DEVICE_TEMP
@ DEVICE_FAN
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.
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 initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
@ 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
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
*brief user defined string literal for JSON values *sa std::size_t n
int fd
uint8_t cmd[4]
Definition pwc-ioctl.h:2