Instrument Neutral Distributed Interface INDI 2.2.5
alluna_tcs2.h
Go to the documentation of this file.
1/*
2 Alluna TCS2 Focus, Dust Cover, Climate, Rotator, and Settings
3 (Dust Cover and Rotator are not implemented)
4
5 Copyright(c) 2022 Peter Englmaier. All rights reserved.
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
22#pragma once
23#include "indifocuser.h"
25#include <mutex>
26#include <chrono>
27#include <ctime>
28
30{
31 public:
32 AllunaTCS2();
33
34 virtual bool Handshake() override;
35 const char *getDefaultName() override;
36
37 bool initProperties() override;
38 bool updateProperties() override;
39
40 bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
41 bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
42
43 protected:
44 // From INDI::DefaultDevice
45 void TimerHit() override;
46 bool saveConfigItems(FILE *fp) override;
47
48 // From Dust Cap
49 virtual IPState ParkCap() override;
50 virtual IPState UnParkCap() override;
51
52 // From INDI::Focuser
53 IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
54 IPState MoveAbsFocuser(uint32_t targetTicks) override;
55 bool AbortFocuser() override;
56
57 private:
58 // while a multi response action is running (such as GetTemperatures), we cannot process additional commands
59 std::mutex tcs;
60
61 // focuser internal state
62 bool isFocuserMoving = false;
63
64 // is getTemperature command in progress
65 bool isGetTemperature = false;
66
67 // is setDustCover command in progress
68 bool isCoverMoving = false;
69
70 // Climate
71 INDI::PropertyNumber TemperatureNP{4}; // note: last value is humidity, not temperature.
72 INDI::PropertySwitch ClimateControlSP{2};
73 typedef enum { AUTO, MANUAL } ClimateControlMode;
74 INDI::PropertySwitch PrimaryDewHeaterSP{2}, SecondaryDewHeaterSP{2};
75 typedef enum { ON, OFF } DewHeaterMode;
76 INDI::PropertyNumber FanPowerNP{1};
77
78 // Focuser
79 INDI::PropertySwitch SteppingModeSP{2};
80
81 typedef enum { MICRO = 1, SPEED = 0 } SteppingMode;
82 SteppingMode steppingMode = MICRO;
83
87 bool getTemperature();
88 bool getPosition();
89 bool getStepping();
90 bool getDustCover();
91 bool getClimateControl();
92 bool getPrimaryDewHeater();
93 bool getSecondaryDewHeater();
94 bool getFanPower();
95
99 bool setStepping(SteppingMode mode);
100 bool setDustCover(void); // open/close dust cover
101 bool setClimateControl(ClimateControlMode mode); // turn on/off climate control
102 bool setPrimaryDewHeater(DewHeaterMode mode); // turn on/off climate control
103 bool setSecondaryDewHeater(DewHeaterMode mode); // turn on/off climate control
104 bool setFanPower(int); // read fan power (between 121=47% and 255=100%, or 0=off)
105
109
120 bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
121 bool sendCommandNoLock(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
122 bool sendCommandOnly(const char * cmd, int cmd_len = -1);
123 bool receiveNext(char * res, int res_len = -1);
124 void receiveDone();
125
133 void hexDump(char * buf, const char * data, int size);
134
138 bool isMoving();
139
143 int32_t m_TargetDiff { 0 };
144
148 static constexpr const char * FOCUSER_TAB = "Focus";
149 static constexpr const char * ROTATOR_TAB = "Rotate";
150 static constexpr const char * CLIMATE_TAB = "Climate";
151 static constexpr const char * DUSTCOVER_TAB = "Dust Cover";
152 // 'LF' is the stop char
153 static const char DRIVER_STOP_CHAR { 0x0A };
154 // Update temperature every 10x POLLMS. For 500ms, we would
155 // update the temperature one every 5 seconds.
156 static constexpr const uint8_t DRIVER_TEMPERATURE_FREQ {10};
157 // Wait up to a maximum of 3 seconds for serial input
158 static constexpr const uint8_t DRIVER_TIMEOUT {5};
159 // Maximum buffer for sending/receving.
160 static constexpr const uint8_t DRIVER_LEN {64};
161};
virtual IPState UnParkCap() override
unPark dust cap (open cover). Must be implemented by child.
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...
const char * getDefaultName() override
bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
virtual IPState ParkCap() override
Park dust cap (close cover). Must be implemented by child.
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...
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
bool AbortFocuser() override
AbortFocuser all focus motion.
bool saveConfigItems(FILE *fp) override
bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
uint8_t cmd[4]
Definition pwc-ioctl.h:2