Instrument Neutral Distributed Interface INDI 2.2.5
oapa.h
Go to the documentation of this file.
1/*******************************************************************************
2 OAPA - Open Automatic Polar Alignment
3
4 Copyright (C) 2026 Michele Bergo
5
6 OAPA wire protocol (GRBL-style text lines, 115200 8N1).
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#pragma once
24
25#include "defaultdevice.h"
26#include "indipacinterface.h"
27
28#include <chrono>
29
30namespace Connection
31{
32class Serial;
33class TCP;
34}
35
63{
64 public:
65 OAPA();
66 virtual ~OAPA() override = default;
67
68 const char *getDefaultName() override;
69
70 bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
71 bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
72
73 protected:
74 bool initProperties() override;
75 bool updateProperties() override;
76 bool saveConfigItems(FILE *fp) override;
77
78 bool Handshake();
79 void TimerHit() override;
80
81 // PACInterface - axis movement
82 IPState MoveAZ(double degrees) override;
83 IPState MoveALT(double degrees) override;
84 IPState MoveBoth(double azDegrees, double altDegrees) override;
85
86 // PACInterface - abort and reverse
87 bool AbortMotion() override;
88 bool ReverseAZ(bool enabled) override;
89 bool ReverseALT(bool enabled) override;
90
91 private:
95 struct Status
96 {
97 bool moving {false};
98 double x {0};
99 double y {0};
100 char version[16] {0};
101 };
102
104 bool sendCommand(const char *cmd, char *res);
105
107 void drainInput();
108
110 bool queryStatus(Status &status);
111
113 static bool parseStatus(const char *line, Status &status);
114
116 bool sendDriverSetting(char type, int axis, double value);
117
119 bool pushDriverConfig();
120
124 IPState startMove(double azDegrees, double altDegrees);
125
127 double degreesToSteps(double degrees, int axis);
128
129 bool isReversed(int axis);
130 void updatePosition(const Status &status);
131 void checkMove(const Status &status);
132 void finishMove(IPState state, const char *message);
133
137 enum
138 {
139 AXIS_AZ,
140 AXIS_ALT
141 };
142
143 // Jog speed per axis in steps/s, sent as the F feed of each jog.
144 INDI::PropertyNumber AxisSpeedNP {2};
145
146 // Motor steps per arcminute of polar-axis correction, per axis. 0 = not calibrated.
147 INDI::PropertyNumber StepsPerArcminNP {2};
148
149 // TMC driver run current (mA) and hold current (% of run), per axis.
150 INDI::PropertyNumber MotorCurrentNP {2};
151 INDI::PropertyNumber MotorHoldNP {2};
152
153 // Read-only firmware version reported in the status frame.
154 INDI::PropertyText FirmwareTP {1};
155
159 using Clock = std::chrono::steady_clock;
160
161 bool m_MoveActive {false};
162 double m_TargetX {0}, m_TargetY {0};
163 double m_LastX {0}, m_LastY {0};
164 Clock::time_point m_LastProgress;
165 Clock::time_point m_Deadline;
166
167 int PortFD {-1};
168 Connection::Serial *serialConnection {nullptr};
169 Connection::TCP *tcpConnection {nullptr};
170
174 static constexpr int DRIVER_TIMEOUT {2};
175 static constexpr int DRIVER_LEN {128};
176 static constexpr char DRIVER_STOP_CHAR {'\n'};
177 static constexpr int HANDSHAKE_ATTEMPTS {6};
178 static constexpr int DEFAULT_TCP_PORT {2323};
179 static constexpr int MIN_SPEED {50};
180 static constexpr int MAX_SPEED {3000};
181 static constexpr int DEFAULT_SPEED {1000};
182 static constexpr int MIN_RUN_CURRENT {100};
183 static constexpr int MAX_RUN_CURRENT {2000};
184 static constexpr int DEFAULT_RUN_CURRENT {600};
185 static constexpr int DEFAULT_HOLD_PERCENT {25};
186 static constexpr double ACCELERATION {1000};
187 static constexpr double POSITION_TOLERANCE {1.0};
188 static constexpr double STALL_SECONDS {3.0};
189};
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
The OAPA class drives an Open Automatic Polar Alignment platform running the OAPA reference firmware ...
Definition oapa.h:63
bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition oapa.cpp:143
virtual ~OAPA() override=default
bool ReverseALT(bool enabled) override
ReverseALT Reverse the direction of altitude axis movement.
Definition oapa.cpp:421
bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition oapa.cpp:58
OAPA()
Definition oapa.cpp:46
IPState MoveAZ(double degrees) override
Motion.
Definition oapa.cpp:219
bool Handshake()
Definition oapa.cpp:154
IPState MoveALT(double degrees) override
MoveALT Move the altitude axis by the given number of degrees.
Definition oapa.cpp:224
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition oapa.cpp:481
bool AbortMotion() override
AbortMotion Abort all axis motion immediately.
Definition oapa.cpp:402
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition oapa.cpp:193
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition oapa.cpp:427
bool ReverseAZ(bool enabled) override
ReverseAZ Reverse the direction of azimuth axis movement.
Definition oapa.cpp:415
IPState MoveBoth(double azDegrees, double altDegrees) override
MoveBoth Move both axes in a single coordinated operation.
Definition oapa.cpp:229
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition oapa.cpp:118
const char * getDefaultName() override
Definition oapa.cpp:53
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34
uint16_t type
Definition pwc-ioctl.h:0
uint8_t cmd[4]
Definition pwc-ioctl.h:2