Instrument Neutral Distributed Interface INDI 2.2.5
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
29#ifdef _USE_SYSTEM_JSONLIB
30#include <nlohmann/json.hpp>
31#else
32#include <indijson.hpp>
33#endif
34
36
37namespace PrimalucaLabs
38{
39typedef struct MotorRates
40{
41 // Rate values: 1-10
42 uint32_t accRate = 0, runSpeed = 0, decRate = 0;
43} MotorRates;
44
45typedef struct MotorCurrents
46{
47 // Current values: 1-10
48 uint32_t accCurrent = 0, runCurrent = 0, decCurrent = 0;
49 // Hold current: 1-5
50 uint32_t holdCurrent = 0;
51} MotorCurrents;
52
53typedef enum
54{
59
66
67/*****************************************************************************************
68 * Communication class handle the serial communication with SestoSenso2/Esatto/Arco
69 * models according to the USB Protocol specifications document in JSON.
70******************************************************************************************/
72{
73 public:
74
75 explicit Communication(const std::string &name, int port) : m_DeviceName(name), m_PortFD(port) {}
76 const char *getDeviceName()
77 {
78 return m_DeviceName.c_str();
79 }
80
81 // Communication functions
82 bool sendRequest(const json &command, json *response = nullptr);
83 template <typename T = int32_t> bool genericRequest(const std::string &node, const std::string &type, const json &command,
84 T *response = nullptr);
94 template <typename T = int32_t> bool get(NodeType type, const std::string &parameter, T &value);
95
103 bool getStringAsDouble(NodeType type, const std::string &parameter, double &value);
104
113 bool set(NodeType type, const json &value);
114
121 template <typename T = int32_t> bool command(NodeType type, const json &jsonCommand);
122
123 private:
124 std::string m_DeviceName;
125 int m_PortFD {-1};
126
127 // Maximum buffer for sending/receiving.
128 static constexpr const int DRIVER_LEN {4096};
129 static const char DRIVER_STOP_CHAR { 0xD };
130 static const char DRIVER_TIMEOUT { 5 };
131};
132
133/*****************************************************************************************
134 * Focuser class represent the common functionality between SestoSenso2 and Esatto models.
135******************************************************************************************/
137{
138 public:
139 Focuser(const std::string &name, int port);
140
141 // Position
142 bool getMaxPosition(uint32_t &position);
143 bool isHallSensorDetected(bool &isDetected);
144 bool getAbsolutePosition(uint32_t &position);
145
146 // Motion
147 bool getStatus(json &status);
148 bool goAbsolutePosition(uint32_t position);
149 bool stop();
150 bool fastMoveOut();
151 bool fastMoveIn();
152 bool getCurrentSpeed(uint32_t &speed);
153 bool isBusy();
154
155 // Firmware
156 bool getSerialNumber(std::string &response);
157 bool getFirmwareVersion(std::string &response);
158 bool getModel(std::string &model); // Moved from Communication
159
160 // Backlash
161 bool setBacklash(uint32_t steps);
162 bool getBacklash(uint32_t &steps);
163
164 // Sensors
165 bool getMotorTemp(double &value);
166 bool getExternalTemp(double &value);
167 bool getVoltage12v(double &value);
168
169 protected:
170 std::unique_ptr<Communication> m_Communication;
171};
172
173/*****************************************************************************************
174 * SestoSenso2 class
175 * Adds presets and motor rates/current control in addition to calibration.
176******************************************************************************************/
177class SestoSenso2 : public Focuser
178{
179 public:
180 SestoSenso2(const std::string &name, int port);
181
182 const char *getDeviceName()
183 {
184 return m_Communication->getDeviceName();
185 }
186
187 // Presets
188 bool applyMotorPreset(const std::string &name);
189 bool setMotorUserPreset(uint32_t index, const MotorRates &rates, const MotorCurrents &currents);
190
191 // Motor Settings
192 bool getMotorSettings(struct MotorRates &rates, struct MotorCurrents &currents, bool &motorHoldActive);
193 bool setMotorRates(const MotorRates &rates);
194 bool setMotorCurrents(const MotorCurrents &currents);
195 bool setMotorHold(bool hold);
196
197 // ===== Calibration Methods =====
198 bool initCalibration(); // Sends: "Init"
199 bool goOutToFindMaxPos(); // Sends: "GoOutToFindMaxPos"
200 bool storeAsMaxPosition(); // Sends: "StoreAsMaxPos"
201 bool storeAsMinPosition(); // Sends: "StoreAsMinPos"
202
203 bool getModel(std::string &model);
204};
205
206/*****************************************************************************************
207 * SestoSenso3 class
208 * Separate class for SestoSenso3 with clean method names (no SS3 suffix needed).
209 * Overrides motion methods to use SS3-specific protocol commands.
210******************************************************************************************/
211class SestoSenso3 : public Focuser
212{
213 public:
214 SestoSenso3(const std::string &name, int port);
215
216 const char *getDeviceName()
217 {
218 return m_Communication->getDeviceName();
219 }
220
221 // Motion overrides (SS3-specific protocol)
222 bool goAbsolutePosition(uint32_t position); // Uses GOTO instead of MOVE_ABS
223 bool isBusy(); // Checks BUSY + MST fields
224 bool getAbsolutePosition(uint32_t &position); // Uses ABS_POS_STEPS
225
226 // Model detection
227 bool getModel(std::string &model);
228 bool getSubModel(std::string &submodel);
229
230 // Recovery delay
231 bool setRecoveryDelay(int32_t delay);
232 bool getRecoveryDelay(int32_t &delay);
233
234 // Motor settings
235 bool getMotorSettings(MotorRates &rates, MotorCurrents &currents, bool &motorHoldActive);
236 bool setMotorRates(const MotorRates &rates);
237 bool setMotorCurrents(const MotorCurrents &currents);
238 bool setMotorHold(bool hold);
239 bool applyMotorPreset(const std::string &name);
240
241 // ===== Calibration Methods =====
242 bool initCalibrationSemiAuto(); // Sends: "Init"
243 bool goInToFindMinPos(); // Sends: "GoInToFindMinPos"
244 bool goOutToFindMaxPos(); // Sends: "GoOutToFindMaxPos"
245 bool stopMotor(); // Sends: "StopMotor"
246 bool storeAsMinPosition(); // Sends: "StoreAsMinPos"
247 bool storeAsMaxPosition(); // Sends: "StoreAsMaxPos"
248 bool moveIn(uint32_t steps); // Sends: "MoveIn-<steps>"
249 bool moveOut(uint32_t steps); // Sends: "MoveOut-<steps>"
250 bool startAutoCalibration(); // Sends: "start_auto_cal" (SC only)
251 bool stopCalibration(); // Sends: "stop_calib"
252};
253
254/*****************************************************************************************
255 * Esatto class
256 * Just adds backlash support.
257******************************************************************************************/
258class Esatto : public Focuser
259{
260 public:
261 Esatto(const std::string &name, int port);
262
263 // Backlash
264 bool setBacklash(uint32_t steps);
265 bool getBacklash(uint32_t &steps);
266
267 // Sensors
268 bool getVoltageUSB(double &value);
269 bool getModel(std::string &model); // Added to Esatto
270};
271
272/*****************************************************************************************
273 * Arco class
274 * GOTO/Sync/Stop and reverse support.
275******************************************************************************************/
276class Arco
277{
278
279 public:
280 explicit Arco(const std::string &name, int port);
281
282 // Motor Info
283 bool getMotorInfo(json &info);
284 // Is it detected and enabled?
285 bool setEnabled(bool enabled);
286 bool isEnabled();
287
288 // Motion
289 bool isBusy();
290 bool getStatus(json &status);
291 bool moveAbsolutePoition(Units unit, double value);
292 bool stop();
293
294 // Position
295 bool getAbsolutePosition(Units unit, double &value);
296 bool sync(Units unit, double value);
297
298 // Calibration
299 bool calibrate();
300 bool isCalibrating();
301
302 // Reverse
303 bool reverse(bool enabled);
304 bool isReversed();
305
306 // Firmware
307 bool getSerialNumber(std::string &response);
308 bool getFirmwareVersion(std::string &response);
309 bool getModel(std::string &model); // Added to Arco
310
311 private:
312 std::unique_ptr<Communication> m_Communication;
313};
314
315/*****************************************************************************************
316 * GIOTTO class
317 * Set/Get brightness levels
318******************************************************************************************/
320{
321
322 public:
323 explicit GIOTTO(const std::string &name, int port);
324
325 // Light
326 bool setLightEnabled(bool enabled);
327 bool isLightEnabled();
328
329 // Brightness
330 bool getMaxBrightness(uint16_t &value);
331 bool setBrightness(uint16_t value);
332 bool getBrightness(uint16_t &value);
333 bool getModel(std::string &model); // Added to GIOTTO
334
335 private:
336 std::unique_ptr<Communication> m_Communication;
337};
338
339/*****************************************************************************************
340 * ALTO class
341 * Park/Unpark, change position.
342******************************************************************************************/
343class ALTO
344{
345
346 public:
347 explicit ALTO(const std::string &name, int port);
348
349 // Status
350 bool getStatus(json &status);
351
352 // Parking
353 bool Park();
354 bool UnPark();
355
356 // Set position 0 to 100
357 bool setPosition(uint8_t value);
358 bool getPosition(uint8_t &value);
359 bool stop();
360
361 // Calibration
362 bool initCalibration();
363 bool close(bool fast = false);
364 bool open(bool fast = false);
365 bool storeClosedPosition();
366 bool storeOpenPosition();
367 bool getModel(std::string &model); // Added to ALTO
368
369 private:
370 std::unique_ptr<Communication> m_Communication;
371};
372
373}
bool close(bool fast=false)
bool getPosition(uint8_t &value)
bool getModel(std::string &model)
bool setPosition(uint8_t value)
bool open(bool fast=false)
bool getStatus(json &status)
bool setEnabled(bool enabled)
bool getModel(std::string &model)
bool getStatus(json &status)
bool getMotorInfo(json &info)
bool moveAbsolutePoition(Units unit, double value)
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)
bool getBacklash(uint32_t &steps)
bool getVoltageUSB(double &value)
bool getModel(std::string &model)
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)
bool getFirmwareVersion(std::string &response)
bool setBacklash(uint32_t steps)
bool getCurrentSpeed(uint32_t &speed)
bool getModel(std::string &model)
bool getMotorTemp(double &value)
bool getMaxPosition(uint32_t &position)
bool getBacklash(uint32_t &steps)
bool goAbsolutePosition(uint32_t position)
bool getMaxBrightness(uint16_t &value)
bool getModel(std::string &model)
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)
bool setMotorUserPreset(uint32_t index, const MotorRates &rates, const MotorCurrents &currents)
bool getModel(std::string &model)
bool setMotorRates(const MotorRates &rates)
bool getModel(std::string &model)
bool setMotorRates(const MotorRates &rates)
bool getSubModel(std::string &submodel)
bool applyMotorPreset(const std::string &name)
bool goAbsolutePosition(uint32_t position)
bool getMotorSettings(MotorRates &rates, MotorCurrents &currents, bool &motorHoldActive)
bool getRecoveryDelay(int32_t &delay)
bool getAbsolutePosition(uint32_t &position)
bool setMotorCurrents(const MotorCurrents &currents)
a class to store JSON values
basic_json<> json
default specialization
uint16_t type
Definition pwc-ioctl.h:0