Instrument Neutral Distributed Interface INDI  1.9.2
celestronauxpacket.h
Go to the documentation of this file.
1 /*
2  Celestron Focuser for SCT and EDGEHD
3 
4  Copyright (C) 2019 Chris Rowland
5  Copyright (C) 2019 Jasem Mutlaq (mutlaqja@ikarustech.com)
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 
23 #pragma once
24 
25 #include <vector>
26 #include <stdint.h>
27 #include <cstring>
28 #include <string>
29 
35 namespace Aux
36 {
37 
38 typedef std::vector<uint8_t> buffer;
39 
43 enum Command
44 {
45  MC_GET_POSITION = 0x01,
46  MC_GOTO_FAST = 0x02,
47  MC_SET_POSITION = 0x04,
53  MC_SLEW_DONE = 0x13,
54  MC_GOTO_SLOW = 0x17,
55  MC_SEEK_INDEX = 0x19,
56  MC_MOVE_POS = 0x24,
57  MC_MOVE_NEG = 0x25,
60 
61  // common to all devices (maybe)
62  GET_VER = 0xfe,
63 
64  // GPS device commands
65  //GPS_GET_LAT = 0x01,
66  //GPS_GET_LONG = 0x02,
67  //GPS_GET_DATE = 0x03,
68  //GPS_GET_YEAR = 0x04,
69  //GPS_GET_TIME = 0x33,
70  //GPS_TIME_VALID = 0x36,
71  //GPS_LINKED = 0x37,
72 
74 
78 
79 };
80 
84 enum Target
85 {
86  ANY = 0x00,
87  MB = 0x01,
88  HC = 0x04,
89  HCP = 0x0d,
90  AZM = 0x10,
91  ALT = 0x11,
92  FOCUSER = 0x12,
93  APP = 0x20,
94  NEX_REMOTE = 0x22,
95  GPS = 0xb0,
96  WiFi = 0xb5,
97  BAT = 0xb6,
98  CHG = 0xb7,
99  LIGHT = 0xbf
100 };
101 
105 class Packet
106 {
107  public:
108  Packet() {}
111 
112  // packet contents
113  static const uint8_t AUX_HDR = 0x3b;
114  uint32_t length;
119 
120  void FillBuffer(buffer &buf);
121 
122  bool Parse (buffer buf);
123 
124  private:
125  uint8_t checksum(buffer data);
126 };
127 
132 {
133  public:
134  Communicator();
136  // send command with data and reply
137  bool sendCommand(int port, Target dest, Command cmd, buffer data, buffer &reply);
138  // send command with reply but no data
139  bool sendCommand(int port, Target dest, Command cmd, buffer &reply);
140  // send command with data but no reply
141  bool commandBlind(int port, Target dest, Command cmd, buffer data);
142 
144 
145  static std::string Device;
146  static void setDeviceName(const std::string &device)
147  {
148  Device = device;
149  }
150 
151  private:
152  bool sendPacket(int port, Target dest, Command cmd, buffer data);
153  bool readPacket(int port, Packet &reply);
154 };
155 
156 }
Aux::Communicator::Communicator
Communicator()
Definition: celestronauxpacket.cpp:131
Aux::Communicator
The Communicator class handles high-level communication with the Celestron devices.
Definition: celestronauxpacket.h:131
Aux::AZM
@ AZM
azimuth|hour angle axis motor
Definition: celestronauxpacket.h:90
Aux::LIGHT
@ LIGHT
Definition: celestronauxpacket.h:99
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
Aux::MC_MOVE_NEG
@ MC_MOVE_NEG
send move rate 0-9
Definition: celestronauxpacket.h:57
Aux::MB
@ MB
Definition: celestronauxpacket.h:87
Aux::MC_SET_POS_GUIDERATE
@ MC_SET_POS_GUIDERATE
Definition: celestronauxpacket.h:48
Aux::ANY
@ ANY
Definition: celestronauxpacket.h:86
Aux
Definition: celestronauxpacket.cpp:33
Aux::MC_MOVE_POS
@ MC_MOVE_POS
send move rate 0-9
Definition: celestronauxpacket.h:56
Aux::MC_GET_POSITION
@ MC_GET_POSITION
return 24 bit position
Definition: celestronauxpacket.h:45
Aux::Packet::source
Target source
Definition: celestronauxpacket.h:115
Aux::APP
@ APP
Definition: celestronauxpacket.h:93
Aux::GET_VER
@ GET_VER
return 2 or 4 bytes major.minor.build
Definition: celestronauxpacket.h:62
Aux::Communicator::commandBlind
bool commandBlind(int port, Target dest, Command cmd, buffer data)
Definition: celestronauxpacket.cpp:244
Aux::MC_SET_NEG_BACKLASH
@ MC_SET_NEG_BACKLASH
1 byte, 0-99
Definition: celestronauxpacket.h:52
Aux::HCP
@ HCP
Definition: celestronauxpacket.h:89
GPS
Class to provide general functionality of a GPS device.
Aux::Packet::command
Command command
Definition: celestronauxpacket.h:117
Aux::MC_SEEK_INDEX
@ MC_SEEK_INDEX
Definition: celestronauxpacket.h:55
Aux::Communicator::sendCommand
bool sendCommand(int port, Target dest, Command cmd, buffer data, buffer &reply)
Definition: celestronauxpacket.cpp:209
Aux::Command
Command
The Command enum includes all the command types sent to the various devices (motor,...
Definition: celestronauxpacket.h:43
device
hid_device * device
Definition: activefocuser_utils.cpp:92
Aux::Packet::length
uint32_t length
Definition: celestronauxpacket.h:114
Aux::Packet::data
buffer data
Definition: celestronauxpacket.h:118
Aux::FOC_GET_HS_POSITIONS
@ FOC_GET_HS_POSITIONS
returns 2 ints low and high limits
Definition: celestronauxpacket.h:77
Aux::FOCUSER
@ FOCUSER
focuser motor
Definition: celestronauxpacket.h:92
Aux::FOC_CALIB_ENABLE
@ FOC_CALIB_ENABLE
send 0 to start or 1 to stop
Definition: celestronauxpacket.h:75
Aux::Communicator::setDeviceName
static void setDeviceName(const std::string &device)
Definition: celestronauxpacket.h:146
Aux::FOC_CALIB_DONE
@ FOC_CALIB_DONE
returns 2 bytes [0] done, [1] state 0-12
Definition: celestronauxpacket.h:76
Aux::Packet::Parse
bool Parse(buffer buf)
Definition: celestronauxpacket.cpp:80
Aux::MC_LEVEL_START
@ MC_LEVEL_START
Definition: celestronauxpacket.h:50
Aux::MC_GOTO_SLOW
@ MC_GOTO_SLOW
send 24 bit target
Definition: celestronauxpacket.h:54
Aux::MC_SET_POSITION
@ MC_SET_POSITION
send 24 bit new position
Definition: celestronauxpacket.h:47
Aux::Packet::Packet
Packet()
Definition: celestronauxpacket.h:108
Aux::WiFi
@ WiFi
WiFi Board.
Definition: celestronauxpacket.h:96
Aux::Packet::destination
Target destination
Definition: celestronauxpacket.h:116
Aux::Packet::AUX_HDR
static const uint8_t AUX_HDR
Definition: celestronauxpacket.h:113
Aux::CHG
@ CHG
Definition: celestronauxpacket.h:98
Aux::MC_GET_POS_BACKLASH
@ MC_GET_POS_BACKLASH
1 byte, 0-99
Definition: celestronauxpacket.h:58
Aux::MC_GOTO_FAST
@ MC_GOTO_FAST
send 24 bit target
Definition: celestronauxpacket.h:46
Aux::ALT
@ ALT
altitude|declination axis motor
Definition: celestronauxpacket.h:91
Aux::Communicator::Device
static std::string Device
Definition: celestronauxpacket.h:145
Aux::MC_SLEW_DONE
@ MC_SLEW_DONE
return 0xFF when move finished
Definition: celestronauxpacket.h:53
Aux::HC
@ HC
Hand Controller.
Definition: celestronauxpacket.h:88
Aux::Packet::FillBuffer
void FillBuffer(buffer &buf)
Definition: celestronauxpacket.cpp:62
Aux::NEX_REMOTE
@ NEX_REMOTE
Definition: celestronauxpacket.h:94
Aux::Communicator::source
Target source
Definition: celestronauxpacket.h:143
Aux::Packet
The Packet class handles low-level communication with the Celestron devices.
Definition: celestronauxpacket.h:105
Aux::MC_SET_POS_BACKLASH
@ MC_SET_POS_BACKLASH
1 byte, 0-99
Definition: celestronauxpacket.h:51
Aux::Target
Target
The Target enum Specifies the target device of the command.
Definition: celestronauxpacket.h:84
Aux::MC_GET_NEG_BACKLASH
@ MC_GET_NEG_BACKLASH
1 byte, 0-99
Definition: celestronauxpacket.h:59
Aux::MC_SET_NEG_GUIDERATE
@ MC_SET_NEG_GUIDERATE
Definition: celestronauxpacket.h:49
Aux::BAT
@ BAT
Definition: celestronauxpacket.h:97
Aux::buffer
std::vector< uint8_t > buffer
Definition: celestronauxpacket.h:38