Instrument Neutral Distributed Interface INDI  2.0.2
primalucacommandset.h
Go to the documentation of this file.
1 /*
2  Primaluca Labs Essato-Arco-Sesto Command Set
3  For USB Control Specification Document Revision 3.3 published 2020.07.08
4 
5  Copyright (C) 2022 Jasem Mutlaq
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  JM 2022.07.16: Major refactor to using json.h and update to Essato Arco
22  Document protocol revision 3.3 (8th July 2022).
23 */
24 
25 #pragma once
26 
27 #include <cstdint>
28 #include "json.h"
29 
31 
32 namespace PrimalucaLabs
33 {
34 typedef struct MotorRates
35 {
36  // Rate values: 1-10
37  uint32_t accRate = 0, runSpeed = 0, decRate = 0;
39 
40 typedef struct MotorCurrents
41 {
42  // Current values: 1-10
43  uint32_t accCurrent = 0, runCurrent = 0, decCurrent = 0;
44  // Hold current: 1-5
45  uint32_t holdCurrent = 0;
47 
48 typedef enum
49 {
54 
55 typedef enum
56 {
61 
62 /*****************************************************************************************
63  * Communicaton class handle the serial communication with SestoSenso2/Esatto/Arco
64  * models according to the USB Protocol specifications document in JSON.
65 ******************************************************************************************/
67 {
68  public:
69 
70  explicit Communication(const std::string &name, int port) : m_DeviceName(name), m_PortFD(port) {}
71  const char *getDeviceName()
72  {
73  return m_DeviceName.c_str();
74  }
75 
76  // Communication functions
77  bool sendRequest(const json &command, json *response = nullptr);
78  template <typename T = int32_t> bool genericRequest(const std::string &node, const std::string &type, const json &command, T *response = nullptr);
88  template <typename T = int32_t> bool get(NodeType type, const std::string &parameter, T &value);
89 
97  bool getStringAsDouble(NodeType type, const std::string &parameter, double &value);
98 
107  bool set(NodeType type, const json &value);
108 
115  template <typename T = int32_t> bool command(NodeType type, const json &jsonCommand);
116 
117  private:
118  std::string m_DeviceName;
119  int m_PortFD {-1};
120 
121  // Maximum buffer for sending/receving.
122  static constexpr const int DRIVER_LEN {4096};
123  static const char DRIVER_STOP_CHAR { 0xD };
124  static const char DRIVER_TIMEOUT { 5 };
125 };
126 
127 /*****************************************************************************************
128  * Focuser class represent the common functionality between SestoSenso2 and Esatto models.
129 ******************************************************************************************/
130 class Focuser
131 {
132  public:
133  Focuser(const std::string &name, int port);
134 
135  // Position
136  bool getMaxPosition(uint32_t &position);
137  bool isHallSensorDetected(bool &isDetected);
138  bool getAbsolutePosition(uint32_t &position);
139 
140  // Motion
141  bool getStatus(json &status);
142  bool goAbsolutePosition(uint32_t position);
143  bool stop();
144  bool fastMoveOut();
145  bool fastMoveIn();
146  bool getCurrentSpeed(uint32_t &speed);
147  bool isBusy();
148 
149  // Firmware
150  bool getSerialNumber(std::string &response);
151  bool getFirmwareVersion(std::string &response);
152 
153  // Backlash
154  bool setBacklash(uint32_t steps);
155  bool getBacklash(uint32_t &steps);
156 
157  // Sensors
158  bool getMotorTemp(double &value);
159  bool getExternalTemp(double &value);
160  bool getVoltage12v(double &value);
161 
162  protected:
163  std::unique_ptr<Communication> m_Communication;
164 };
165 
166 /*****************************************************************************************
167  * SestoSenso2 class
168  * Adds presets and motor rates/current control in addition to calibration.
169 ******************************************************************************************/
170 class SestoSenso2 : public Focuser
171 {
172  public:
173  SestoSenso2(const std::string &name, int port);
174 
175  // Presets
176  bool applyMotorPreset(const std::string &name);
177  bool setMotorUserPreset(uint32_t index, const MotorRates &rates, const MotorCurrents &currents);
178 
179  // Motor Settings
180  bool getMotorSettings(struct MotorRates &rates, struct MotorCurrents &currents, bool &motorHoldActive);
181  bool setMotorRates(const MotorRates &rates);
182  bool setMotorCurrents(const MotorCurrents &currents);
183  bool setMotorHold(bool hold);
184 
185  // Calibration
186  bool initCalibration();
187  bool storeAsMaxPosition();
188  bool storeAsMinPosition();
189  bool goOutToFindMaxPos();
190 };
191 
192 /*****************************************************************************************
193  * Esatto class
194  * Just adds backlash support.
195 ******************************************************************************************/
196 class Esatto : public Focuser
197 {
198  public:
199  Esatto(const std::string &name, int port);
200 
201  // Backlash
202  bool setBacklash(uint32_t steps);
203  bool getBacklash(uint32_t &steps);
204 
205  // Sensors
206  bool getVoltageUSB(double &value);
207 };
208 
209 /*****************************************************************************************
210  * Arco class
211  * GOTO/Sync/Stop and reverse support.
212 ******************************************************************************************/
213 class Arco
214 {
215 
216  public:
217  explicit Arco(const std::string &name, int port);
218 
219  // Motor Info
220  bool getMotorInfo(json &info);
221  // Is it detected and enabled?
222  bool setEnabled(bool enabled);
223  bool isEnabled();
224 
225  // Motion
226  bool isBusy();
227  bool getStatus(json &status);
228  bool moveAbsolutePoition(Units unit, double value);
229  bool stop();
230 
231  // Position
232  bool getAbsolutePosition(Units unit, double &value);
233  bool sync(Units unit, double value);
234 
235  // Calibration
236  bool calibrate();
237  bool isCalibrating();
238 
239  // Reverse
240  bool reverse(bool enabled);
241  bool isReversed();
242 
243  // Firmware
244  bool getSerialNumber(std::string &response);
245  bool getFirmwareVersion(std::string &response);
246 
247  private:
248  std::unique_ptr<Communication> m_Communication;
249 };
250 
251 /*****************************************************************************************
252  * GIOTTO class
253  * Set/Get brightness levels
254 ******************************************************************************************/
255 class GIOTTO
256 {
257 
258  public:
259  explicit GIOTTO(const std::string &name, int port);
260 
261  // Light
262  bool setLightEnabled(bool enabled);
263  bool isLightEnabled();
264 
265  // Brightness
266  bool getMaxBrightness(uint16_t &value);
267  bool setBrightness(uint16_t value);
268  bool getBrightness(uint16_t &value);
269 
270 private:
271  std::unique_ptr<Communication> m_Communication;
272 };
273 
274 /*****************************************************************************************
275  * ALTO class
276  * Park/Unpark, change position.
277 ******************************************************************************************/
278 class ALTO
279 {
280 
281 public:
282  explicit ALTO(const std::string &name, int port);
283 
284  // Status
285  bool getStatus(json &status);
286  // Model
287  bool getModel(std::string &model);
288 
289  // Parking
290  bool Park();
291  bool UnPark();
292 
293  // Set position 0 to 100
294  bool setPosition(uint8_t value);
295  bool stop();
296 
297  // Calibration
298  bool initCalibration();
299  bool close(bool fast = false);
300  bool open(bool fast = false);
301  bool storeClosedPosition();
302  bool storeOpenPosition();
303 
304 private:
305  std::unique_ptr<Communication> m_Communication;
306 };
307 
308 }
bool close(bool fast=false)
bool getModel(std::string &model)
ALTO(const std::string &name, int port)
bool setPosition(uint8_t value)
bool open(bool fast=false)
bool getStatus(json &status)
bool setEnabled(bool enabled)
bool getStatus(json &status)
bool getMotorInfo(json &info)
bool moveAbsolutePoition(Units unit, double value)
Arco(const std::string &name, int port)
bool sync(Units unit, double value)
bool getSerialNumber(std::string &response)
bool getAbsolutePosition(Units unit, double &value)
bool reverse(bool enabled)
bool getFirmwareVersion(std::string &response)
bool command(NodeType type, const json &jsonCommand)
bool genericRequest(const std::string &node, const std::string &type, const json &command, T *response=nullptr)
bool sendRequest(const json &command, json *response=nullptr)
bool getStringAsDouble(NodeType type, const std::string &parameter, double &value)
getStringAsDouble Same as get, but it receives a string and scan it for double.
bool get(NodeType type, const std::string &parameter, T &value)
Communication(const std::string &name, int port)
bool set(NodeType type, const json &value)
bool setBacklash(uint32_t steps)
Esatto(const std::string &name, int port)
bool getBacklash(uint32_t &steps)
bool getVoltageUSB(double &value)
bool getVoltage12v(double &value)
std::unique_ptr< Communication > m_Communication
bool getAbsolutePosition(uint32_t &position)
bool getExternalTemp(double &value)
bool isHallSensorDetected(bool &isDetected)
bool getSerialNumber(std::string &response)
Focuser(const std::string &name, int port)
bool getFirmwareVersion(std::string &response)
bool setBacklash(uint32_t steps)
bool getCurrentSpeed(uint32_t &speed)
bool getMotorTemp(double &value)
bool getMaxPosition(uint32_t &position)
bool getStatus(json &status)
bool getBacklash(uint32_t &steps)
bool goAbsolutePosition(uint32_t position)
GIOTTO(const std::string &name, int port)
bool getMaxBrightness(uint16_t &value)
bool setLightEnabled(bool enabled)
bool getBrightness(uint16_t &value)
bool setBrightness(uint16_t value)
bool getMotorSettings(struct MotorRates &rates, struct MotorCurrents &currents, bool &motorHoldActive)
bool setMotorCurrents(const MotorCurrents &currents)
bool applyMotorPreset(const std::string &name)
SestoSenso2(const std::string &name, int port)
bool setMotorUserPreset(uint32_t index, const MotorRates &rates, const MotorCurrents &currents)
bool setMotorRates(const MotorRates &rates)
a class to store JSON values
Definition: json.h:18647
struct PrimalucaLabs::MotorCurrents MotorCurrents
struct PrimalucaLabs::MotorRates MotorRates
basic_json<> json
default specialization
Definition: json.h:3196
__le16 type
Definition: pwc-ioctl.h:0