Instrument Neutral Distributed Interface INDI  1.9.5
activefocuser_utils.h
Go to the documentation of this file.
1 /*
2  ActiveFocuser driver for Takahashi CCA-250 and Mewlon-250/300CRS
3 
4  Driver written by Alvin FREY <https://afrey.fr> for Optique Unterlinden and Takahashi Europe
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 */
21 
22 #pragma once
23 
24 #include <map>
25 #include <string>
26 #include <hidapi.h>
27 #include <mutex>
28 #include <future>
29 #include <cstring>
30 #include <chrono>
31 #include <cmath>
32 #include <memory>
33 #include <indifocuser.h>
34 #include "activefocuser.h"
35 
37 
38 public :
39 
40  typedef enum {
51  } Commands;
52 
53  static const std::map<Commands, unsigned char> CommandsMap;
54 
55  class Parser {
56  public :
57  static int Get32(const unsigned char *buffer, int position);
58  static int Get16(const unsigned char *buffer, int position);
59  static double TicksToMillimeters(int ticks);
60  static int MillimetersToTicks(double millimeters);
61  static void PrintFrame(const unsigned char *buffer);
62  static void PrintBasicDeviceData(const unsigned char *buffer);
63  private:
64  Parser() = delete;
65  ~Parser() = delete;
66  void operator=(const Parser &) = delete;
67 
68  };
69 
70  class Poller {
71  public:
72  static Poller *GetInstance(hid_device &hid_handle);
73  bool IsRunning;
74  bool Start();
75  bool Stop();
76  protected:
77  Poller(hid_device &hid_handle) : hid_handle_(hid_handle) {}
78  ~Poller() {}
80  private:
81  Poller(Poller &other) = delete;
82  void operator=(const Poller &) = delete;
83  static Poller *pinstance_;
84  static std::mutex mutex_;
85  };
86 
87  class SystemState {
88 
89  public:
90  static int GetCurrentPositionStep();
91  static void SetCurrentPositionStep(int currentPositionStep);
92  static double GetCurrentPosition();
93  static void SetCurrentPosition(double currentPosition);
94  static void SetIsOrigin(bool isOrigin);
95  static bool GetIsMoving();
96  static void SetIsMoving(bool isMoving);
97  static bool GetIsFanOn();
98  static void SetIsFanOn(bool isFanOn);
99  static bool GetIsHold();
100  static void SetIsHold(bool isHold);
101  static char * GetHardwareRevision();
102  static void SetHardwareRevision(char * hardwareRevision);
103  static int GetImmpp();
104  static void SetImmpp(int immpp);
105  static int GetSpan();
106  static void SetSpan(int span);
107  static double GetMmpp();
108  static void SetMmpp(double mmpp);
109  static double GetAirTemperature();
110  static void SetAirTemperature(double airTemperature);
111  static double GetTubeTemperature();
112  static void SetTubeTemperature(double tubeTemperature);
113  static double GetMirrorTemperature();
114  static void SetMirrorTemperature(double mirrorTemperature);
115  private:
116  SystemState() = delete;
117  ~SystemState() = delete;
118  void operator=(const SystemState &) = delete;
119 
120  bool GetIsOrigin();
121  };
122 
123 private:
124  ActiveFocuserUtils() = delete;
125  ~ActiveFocuserUtils() = delete;
126  void operator=(const ActiveFocuserUtils &) = delete;
127 
128 };
ActiveFocuserUtils::SystemState::GetIsMoving
static bool GetIsMoving()
Definition: activefocuser_utils.cpp:229
ActiveFocuserUtils::RESET
@ RESET
Definition: activefocuser_utils.h:49
ActiveFocuserUtils::SystemState::SetIsMoving
static void SetIsMoving(bool isMoving)
Definition: activefocuser_utils.cpp:233
ActiveFocuserUtils::SystemState::SetIsFanOn
static void SetIsFanOn(bool isFanOn)
Definition: activefocuser_utils.cpp:241
ActiveFocuserUtils::Parser::PrintBasicDeviceData
static void PrintBasicDeviceData(const unsigned char *buffer)
Definition: activefocuser_utils.cpp:66
ActiveFocuserUtils::FAN_ON
@ FAN_ON
Definition: activefocuser_utils.h:47
ActiveFocuserUtils::SystemState::GetCurrentPosition
static double GetCurrentPosition()
Definition: activefocuser_utils.cpp:213
ActiveFocuserUtils::Poller
Definition: activefocuser_utils.h:70
ActiveFocuserUtils::Commands
Commands
Definition: activefocuser_utils.h:40
hidapi.h
ActiveFocuserUtils::SystemState::GetMirrorTemperature
static double GetMirrorTemperature()
Definition: activefocuser_utils.cpp:301
ActiveFocuserUtils::SystemState::GetIsFanOn
static bool GetIsFanOn()
Definition: activefocuser_utils.cpp:237
ActiveFocuserUtils::Poller::GetInstance
static Poller * GetInstance(hid_device &hid_handle)
Definition: activefocuser_utils.cpp:94
ActiveFocuserUtils::Poller::IsRunning
bool IsRunning
Definition: activefocuser_utils.h:73
ActiveFocuserUtils::ZERO
@ ZERO
Definition: activefocuser_utils.h:41
ActiveFocuserUtils::Parser::TicksToMillimeters
static double TicksToMillimeters(int ticks)
Definition: activefocuser_utils.cpp:42
ActiveFocuserUtils::Poller::~Poller
~Poller()
Definition: activefocuser_utils.h:78
indifocuser.h
ActiveFocuserUtils::Parser::Get32
static int Get32(const unsigned char *buffer, int position)
Definition: activefocuser_utils.cpp:26
currentPosition
#define currentPosition
Definition: robofocus.cpp:37
ActiveFocuserUtils::SystemState::SetIsHold
static void SetIsHold(bool isHold)
Definition: activefocuser_utils.cpp:249
ActiveFocuserUtils::SystemState::GetSpan
static int GetSpan()
Definition: activefocuser_utils.cpp:269
hid_device_
Definition: hid_libusb.c:93
ActiveFocuserUtils::Poller::hid_handle_
hid_device & hid_handle_
Definition: activefocuser_utils.h:79
activefocuser.h
ActiveFocuserUtils::SystemState::GetTubeTemperature
static double GetTubeTemperature()
Definition: activefocuser_utils.cpp:293
ActiveFocuserUtils::Parser
Definition: activefocuser_utils.h:55
ActiveFocuserUtils::CommandsMap
static const std::map< Commands, unsigned char > CommandsMap
Definition: activefocuser_utils.h:53
ActiveFocuserUtils::Parser::Get16
static int Get16(const unsigned char *buffer, int position)
Definition: activefocuser_utils.cpp:36
ActiveFocuserUtils::Poller::Stop
bool Stop()
Definition: activefocuser_utils.cpp:171
ActiveFocuserUtils::AUTO
@ AUTO
Definition: activefocuser_utils.h:44
ActiveFocuserUtils::SystemState::SetCurrentPositionStep
static void SetCurrentPositionStep(int currentPositionStep)
Definition: activefocuser_utils.cpp:209
ActiveFocuserUtils::SystemState::GetCurrentPositionStep
static int GetCurrentPositionStep()
Definition: activefocuser_utils.cpp:205
ActiveFocuserUtils::SystemState::GetAirTemperature
static double GetAirTemperature()
Definition: activefocuser_utils.cpp:285
ActiveFocuserUtils::SystemState::SetSpan
static void SetSpan(int span)
Definition: activefocuser_utils.cpp:273
ActiveFocuserUtils
Definition: activefocuser_utils.h:36
ActiveFocuserUtils::SystemState::SetAirTemperature
static void SetAirTemperature(double airTemperature)
Definition: activefocuser_utils.cpp:289
ActiveFocuserUtils::SystemState::SetCurrentPosition
static void SetCurrentPosition(double currentPosition)
Definition: activefocuser_utils.cpp:217
ActiveFocuserUtils::SystemState::SetImmpp
static void SetImmpp(int immpp)
Definition: activefocuser_utils.cpp:265
ActiveFocuserUtils::SystemState::SetIsOrigin
static void SetIsOrigin(bool isOrigin)
Definition: activefocuser_utils.cpp:225
ActiveFocuserUtils::DUMMY
@ DUMMY
Definition: activefocuser_utils.h:50
ActiveFocuserUtils::SystemState::SetMmpp
static void SetMmpp(double mmpp)
Definition: activefocuser_utils.cpp:281
ActiveFocuserUtils::SystemState::GetIsHold
static bool GetIsHold()
Definition: activefocuser_utils.cpp:245
ActiveFocuserUtils::Parser::MillimetersToTicks
static int MillimetersToTicks(double millimeters)
Definition: activefocuser_utils.cpp:48
ActiveFocuserUtils::SystemState::GetMmpp
static double GetMmpp()
Definition: activefocuser_utils.cpp:277
ActiveFocuserUtils::SystemState
Definition: activefocuser_utils.h:87
ActiveFocuserUtils::FAN_OFF
@ FAN_OFF
Definition: activefocuser_utils.h:48
ActiveFocuserUtils::RELEASE
@ RELEASE
Definition: activefocuser_utils.h:42
ActiveFocuserUtils::Poller::Start
bool Start()
Definition: activefocuser_utils.cpp:158
ActiveFocuserUtils::Poller::Poller
Poller(hid_device &hid_handle)
Definition: activefocuser_utils.h:77
ActiveFocuserUtils::SystemState::GetHardwareRevision
static char * GetHardwareRevision()
Definition: activefocuser_utils.cpp:253
ActiveFocuserUtils::SystemState::SetMirrorTemperature
static void SetMirrorTemperature(double mirrorTemperature)
Definition: activefocuser_utils.cpp:305
ActiveFocuserUtils::SystemState::SetHardwareRevision
static void SetHardwareRevision(char *hardwareRevision)
Definition: activefocuser_utils.cpp:257
ActiveFocuserUtils::STOP
@ STOP
Definition: activefocuser_utils.h:46
ActiveFocuserUtils::FREE
@ FREE
Definition: activefocuser_utils.h:43
ActiveFocuserUtils::SystemState::SetTubeTemperature
static void SetTubeTemperature(double tubeTemperature)
Definition: activefocuser_utils.cpp:297
ActiveFocuserUtils::SystemState::GetImmpp
static int GetImmpp()
Definition: activefocuser_utils.cpp:261
ActiveFocuserUtils::Parser::PrintFrame
static void PrintFrame(const unsigned char *buffer)
Definition: activefocuser_utils.cpp:54
ActiveFocuserUtils::MOVE
@ MOVE
Definition: activefocuser_utils.h:45
Aux::buffer
std::vector< uint8_t > buffer
Definition: celestronauxpacket.h:38