Instrument Neutral Distributed Interface INDI 2.2.5
gpusb.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2012-2019 Jasem Mutlaq. All rights reserved.
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18
19 The full GNU General Public License is included in this distribution in the
20 file called LICENSE.
21*******************************************************************************/
22
23#include "gpusb.h"
24
25#include "gpdriver.h"
26
27#include <memory>
28#include <cstring>
29#include <unistd.h>
30
31// We declare an auto pointer to gpGuide.
32static std::unique_ptr<GPUSB> gpGuide(new GPUSB());
33
35{
36 driver = new GPUSBDriver();
37}
38
40{
41 delete (driver);
42}
43
45{
46 return "GPUSB";
47}
48
50{
51 driver->setDebug(isDebug());
52
53 bool rc = driver->Connect();
54
55 if (rc)
56 LOG_INFO("GPUSB is online.");
57 else
58 LOG_ERROR("Error: cannot find GPUSB device.");
59
60 return rc;
61}
62
64{
65 LOG_INFO("GPSUSB is offline.");
66
67 return driver->Disconnect();
68}
69
84
93
94bool GPUSB::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
95{
96 // Check guider interface
97 if (GI::processNumber(dev, name, values, names, n))
98 return true;
99
100 return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n);
101}
102
103void GPUSB::debugTriggered(bool enable)
104{
105 driver->setDebug(enable);
106}
107
108//float GPUSB::CalcWEPulseTimeLeft()
109//{
110// double timesince;
111// double timeleft;
112// struct timeval now
113// {
114// 0, 0
115// };
116// gettimeofday(&now, nullptr);
117
118// timesince = (double)(now.tv_sec * 1000.0 + now.tv_usec / 1000) -
119// (double)(WEPulseStart.tv_sec * 1000.0 + WEPulseStart.tv_usec / 1000);
120// timesince = timesince / 1000;
121
122// timeleft = WEPulseRequest - timesince;
123// return timeleft;
124//}
125
126//float GPUSB::CalcNSPulseTimeLeft()
127//{
128// double timesince;
129// double timeleft;
130// struct timeval now
131// {
132// 0, 0
133// };
134// gettimeofday(&now, nullptr);
135
136// timesince = (double)(now.tv_sec * 1000.0 + now.tv_usec / 1000) -
137// (double)(NSPulseStart.tv_sec * 1000.0 + NSPulseStart.tv_usec / 1000);
138// timesince = timesince / 1000;
139
140// timeleft = NSPulseRequest - timesince;
141// return timeleft;
142//}
143
144
146{
147 RemoveTimer(NSTimerID);
148
149 driver->startPulse(GPUSB_NORTH);
150
151 NSDirection = GPUSB_NORTH;
152
153 LOG_DEBUG("Starting NORTH guide");
154
155 NSPulseRequest = ms;
156
157 NSGuideTS = std::chrono::system_clock::now();
158
159 NSTimerID = IEAddTimer(ms, &GPUSB::NSTimerHelper, this);
160
161 return IPS_BUSY;
162}
163
165{
166 RemoveTimer(NSTimerID);
167
168 driver->startPulse(GPUSB_SOUTH);
169
170 NSDirection = GPUSB_SOUTH;
171
172 LOG_DEBUG("Starting SOUTH guide");
173
174 NSPulseRequest = ms;
175
176 NSGuideTS = std::chrono::system_clock::now();
177
178 NSTimerID = IEAddTimer(ms, &GPUSB::NSTimerHelper, this);
179
180 return IPS_BUSY;
181}
182
184{
185 RemoveTimer(WETimerID);
186
187 driver->startPulse(GPUSB_EAST);
188
189 WEDirection = GPUSB_EAST;
190
191 LOG_DEBUG("Starting EAST guide");
192
193 WEPulseRequest = ms;
194
195 WEGuideTS = std::chrono::system_clock::now();
196
197 WETimerID = IEAddTimer(ms, &GPUSB::WETimerHelper, this);
198
199 return IPS_BUSY;
200}
201
203{
204 RemoveTimer(WETimerID);
205
206 driver->startPulse(GPUSB_WEST);
207
208 WEDirection = GPUSB_WEST;
209
210 LOG_DEBUG("Starting WEST guide");
211
212 WEPulseRequest = ms;
213
214 WEGuideTS = std::chrono::system_clock::now();
215
216 WETimerID = IEAddTimer(ms, &GPUSB::WETimerHelper, this);
217
218 return IPS_BUSY;
219}
220
221void GPUSB::NSTimerHelper(void *context)
222{
223 static_cast<GPUSB*>(context)->NSTimerCallback();
224}
225
226void GPUSB::WETimerHelper(void *context)
227{
228 static_cast<GPUSB*>(context)->WETimerCallback();
229}
230
231void GPUSB::NSTimerCallback()
232{
233 driver->stopPulse(NSDirection);
235}
236
237void GPUSB::WETimerCallback()
238{
239 driver->stopPulse(WEDirection);
241}
242
void setDebug(bool enable)
Definition gpdriver.h:52
bool Connect()
Definition gpdriver.cpp:38
bool Disconnect()
Definition gpdriver.cpp:53
bool stopPulse(int direction)
Definition gpdriver.cpp:99
bool startPulse(int direction)
Definition gpdriver.cpp:59
Definition gpusb.h:33
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition gpusb.cpp:49
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition gpusb.cpp:94
virtual IPState GuideEast(uint32_t ms) override
Guide east for ms milliseconds. East is defined as RA+.
Definition gpusb.cpp:183
virtual IPState GuideWest(uint32_t ms) override
Guide west for ms milliseconds. West is defined as RA-.
Definition gpusb.cpp:202
virtual IPState GuideNorth(uint32_t ms) override
Guide north for ms milliseconds. North is defined as DEC+.
Definition gpusb.cpp:145
const char * getDefaultName() override
Definition gpusb.cpp:44
bool Disconnect() override
Disconnect from device.
Definition gpusb.cpp:63
GPUSB()
Definition gpusb.cpp:34
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition gpusb.cpp:70
static void NSTimerHelper(void *context)
Definition gpusb.cpp:221
virtual ~GPUSB()
Definition gpusb.cpp:39
virtual IPState GuideSouth(uint32_t ms) override
Guide south for ms milliseconds. South is defined as DEC-.
Definition gpusb.cpp:164
static void WETimerHelper(void *context)
Definition gpusb.cpp:226
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition gpusb.cpp:85
void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
Definition gpusb.cpp:103
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
void RemoveTimer(int id)
Remove timer added with SetTimer.
void addDebugControl()
Add Debug control to the driver.
virtual void GuideComplete(INDI_EQ_AXIS axis)
Call GuideComplete once the guiding pulse is complete.
bool updateProperties()
updateProperties Define or Delete Rotator properties based on the connection status of the base devic...
void initProperties(const char *groupName)
Initialize guider properties. It is recommended to call this function within initProperties() of your...
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Call this function whenever client updates GuideNSNP or GuideWSP properties in the primary device....
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
int IEAddTimer(int millisecs, IE_TCF *fp, void *p)
Register a new single-shot timer function, fp, to be called with ud as argument after ms.
Definition eventloop.c:586
@ GPUSB_SOUTH
Definition gpdriver.h:30
@ GPUSB_WEST
Definition gpdriver.h:32
@ GPUSB_NORTH
Definition gpdriver.h:29
@ GPUSB_EAST
Definition gpdriver.h:31
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ AXIS_DE
@ AXIS_RA
#define LOG_DEBUG(txt)
Definition indilogger.h:75
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
Definition indilogger.h:72
#define LOG_INFO(txt)
Definition indilogger.h:74