Instrument Neutral Distributed Interface INDI 2.2.5
pegasus_focuscube3.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2023 Chrysikos Efstathios. All rights reserved.
3
4 Pegasus FocusCube
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20
21 The full GNU General Public License is included in this distribution in the
22 file called LICENSE.
23*******************************************************************************/
24#pragma once
25
26#include "indifocuser.h"
27#include "pegasus_wifi.h"
28
29#include <chrono>
30
32{
33 public:
35 virtual ~PegasusFocusCube3() override = default;
36
37 virtual bool Handshake() override;
38 const char *getDefaultName() override;
39 virtual bool initProperties() override;
40 virtual bool updateProperties() override;
41 virtual void ISGetProperties(const char *dev) override;
42 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
43 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
44 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
45
46 protected:
47 virtual bool saveConfigItems(FILE *fp) override;
48 virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
49 virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
50 virtual bool AbortFocuser() override;
51 virtual void TimerHit() override;
52
53 virtual bool SyncFocuser(uint32_t ticks) override;
54 virtual bool ReverseFocuser(bool enabled) override;
55 virtual bool SetFocuserBacklash(int32_t steps) override;
56
57
58 char stopChar { 0xD };
59 static constexpr const uint8_t PEGASUS_TIMEOUT {3};
60 static constexpr const uint8_t PEGASUS_LEN {128};
61 int PortFD { -1 };
62 bool setupComplete { false };
63 bool sendCommand(const char *cmd, char *res);
64 std::vector<std::string> split(const std::string &input, const std::string &regex);
65
66 private:
67 bool updateFocusParams();
68 bool setSpeed(uint16_t speed);
69 bool getSpeed(int &speed);
71 static bool parseReply(const char *res, const char *prefix, int &value);
72 bool move(uint32_t newPosition);
73 std::string getFirmwareVersion();
74
75 uint32_t currentPosition { 0 };
76 uint32_t targetPosition { 0 };
77 bool isMoving = false;
78 // The firmware reports -127 when no temperature sensor is connected.
79 bool hasTemperatureSensor = false;
80 // Start of the last move, to tell a finished move from one that has not started yet.
81 std::chrono::steady_clock::time_point moveStarted;
82 static constexpr std::chrono::seconds MOVE_START_TIMEOUT {5};
83
84
85 // WiFi settings and login on the TCP command socket
86 PegasusAstro::WiFi wifi {this};
87
88 INDI::PropertyNumber TemperatureNP {1};
89 INDI::PropertyText FirmwareVersionTP {1};
90 INDI::PropertyNumber SpeedNP {1};
91
92
93};
virtual ~PegasusFocusCube3() override=default
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual bool saveConfigItems(FILE *fp) override
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
static constexpr const uint8_t PEGASUS_LEN
virtual void ISGetProperties(const char *dev) override
Handles client requests for property definitions for this device or all devices. Delegates to the bas...
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
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 SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
static constexpr const uint8_t PEGASUS_TIMEOUT
bool sendCommand(const char *cmd, char *res)
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
const char * getDefaultName() override
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Processes incoming new text values from the client for this device. Delegates processing to the contr...
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
std::vector< std::string > split(const std::string &input, const std::string &regex)
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 bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
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
uint8_t cmd[4]
Definition pwc-ioctl.h:2