Instrument Neutral Distributed Interface INDI 2.2.5
skycommander.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3
4 Simple SkyCommander DSC Driver
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9 .
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14 .
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*******************************************************************************/
20
21#include "skycommander.h"
22
23#include "indicom.h"
24
25#include <memory>
26#include <termios.h>
27
28#define SKYCOMMANDER_TIMEOUT 3
29
30// We declare an auto pointer to SkyCommander.
31std::unique_ptr<SkyCommander> skycommander(new SkyCommander());
32
37
39{
40 return (const char *)"SkyCommander";
41}
42
44{
45 return true;
46}
47
49{
50 char CR[1] = { 0x0D };
51 int rc = 0, nbytes_read = 0, nbytes_written = 0;
52
53 LOGF_DEBUG("CMD: %#02X", CR[0]);
54
55 tcflush(PortFD, TCIFLUSH);
56
57 if ((rc = tty_write(PortFD, CR, 1, &nbytes_written)) != TTY_OK)
58 {
59 char errmsg[256];
60 tty_error_msg(rc, errmsg, 256);
61 LOGF_ERROR("Error writing to SkyCommander %s (%d)", errmsg, rc);
62 return false;
63 }
64
65 char coords[16];
66 if ((rc = tty_read(PortFD, coords, 16, SKYCOMMANDER_TIMEOUT, &nbytes_read)) != TTY_OK)
67 {
68 char errmsg[256];
69 tty_error_msg(rc, errmsg, 256);
70 LOGF_ERROR("Error reading from SkyCommander %s (%d)", errmsg, rc);
71 return false;
72 }
73
74 LOGF_DEBUG("RES: %s", coords);
75
76 float RA = 0.0, DEC = 0.0;
77 nbytes_read = sscanf(coords, " %g %g", &RA, &DEC);
78
79 if (nbytes_read < 2)
80 {
81 LOGF_ERROR("Error in Sky commander number format (%s).", coords);
82 return false;
83 }
84
85 char RAStr[64], DecStr[64];
86 fs_sexa(RAStr, RA, 2, 3600);
87 fs_sexa(DecStr, DEC, 2, 3600);
88 LOGF_DEBUG("Current RA: %s Current DEC: %s", RAStr, DecStr);
89
90 NewRaDec(RA, DEC);
91 return true;
92}
void SetTelescopeCapability(uint32_t cap, uint8_t slewRateCount)
SetTelescopeCapability sets the Telescope capabilities. All capabilities must be initialized.
void NewRaDec(double ra, double dec)
The child class calls this function when it has updates.
virtual const char * getDefaultName()
virtual bool Handshake()
perform handshake with device to check communication
virtual bool ReadScopeStatus()
Read telescope status.
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
Definition indicom.c:418
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition indicom.c:548
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Definition indicom.c:1243
int fs_sexa(char *out, double a, int w, int fracbase)
Converts a sexagesimal number to a string. sprint the variable a in sexagesimal format into out[].
Definition indicom.c:130
Implementations for common driver routines.
@ TTY_OK
Definition indicom.h:54
#define LOGF_DEBUG(fmt,...)
Definition indilogger.h:83
#define LOGF_ERROR(fmt,...)
Definition indilogger.h:80
std::unique_ptr< SkyCommander > skycommander(new SkyCommander())
#define SKYCOMMANDER_TIMEOUT