Instrument Neutral Distributed Interface INDI  2.0.2
indi_shelyak_usis.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2022 Etienne Cochard. 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 #pragma once
24 
25 #include "defaultdevice.h"
27 #include "json.h"
28 
30 
31 #define MAX_FRAME_LENGTH 150
32 #define MAX_NAME_LENGTH 25
33 #define MAX_VALUE_LENGTH 125
34 
35 struct UsisResponse {
37  char* parts[5];
38  int pcount;
39 };
40 
41 #define ACTION_STOP 1
42 #define ACTION_CALIB 2
43 
44 #define MAX_ACTION 8
45 #define MAX_ENUMS 8
46 
47 class Action;
48 
49 struct TextValue {
52 };
53 
54 struct EnumValue {
57 };
58 
59 struct NumValue {
63 };
64 
65 struct EnumItem {
67  int index;
68  std::string val;
69 };
70 
71 struct CmdItem {
73  std::string cmd;
74  std::string name;
75 };
76 
77 enum PropType {
78  _text = 0x10,
79  _enum = 0x11,
80  _number = 0x12,
81 
82  _eitm = 0x01,
83  _ecmd = 0x02,
84 };
85 
86 class Action {
87 public:
88  char uid[8];
89  std::string name;
90 
92  union {
98  };
99 
100 public:
101  Action( uint32_t _uid, const std::string& _cmd, PropType _type ) {
102  sprintf( uid, "%04x", _uid );
103  name = _cmd;
104  type = _type;
105  }
106 };
107 
109 {
110 public:
111  ShelyakDriver();
112  ~ShelyakDriver();
113 
114  bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
115  bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
116  bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
117 
118  void update( );
119  static void __update( void* ptr );
120 
121  const char *getDefaultName() override;
122 
123 private:
124  void genCatProps( const char* catName, json& categ );
125 
126  bool initProperties() override;
127  bool updateProperties() override;
128  void clearProperties( );
129 
130  bool Connect() override;
131  bool Disconnect() override;
132 
133 private:
134  int _serialPort; // file descriptor for serial port
135  json _config; // json configuration
136 
137  uint32_t _guid;
138  std::vector<Action*> _actions;
139 
140  bool sendCmd( UsisResponse* rsp, const char* text, ... );
141  bool _send( const char* text, va_list lst );
142  bool _receive( UsisResponse* response );
143  void scanProperties( );
144 
145  bool readConfig( );
146  bool findBoard( const char* boardName, json* board_def );
147 
148  Action* createAction( PropType type, const std::string& command );
149 
150  Connection::Serial *serialConnection = nullptr;
151 };
152 
TextValue text
Action(uint32_t _uid, const std::string &_cmd, PropType _type)
EnumItem itm
CmdItem cmd
char uid[8]
std::string name
NumValue num
EnumValue enm
PropType type
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
const char * getDefaultName() override
static void __update(void *ptr)
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
a class to store JSON values
Definition: json.h:18647
PropType
@ _number
@ _eitm
@ _ecmd
@ _text
@ _enum
#define MAX_FRAME_LENGTH
#define MAX_ENUMS
ISState
Switch state.
Definition: indiapi.h:150
basic_json<> json
default specialization
Definition: json.h:3196
__le16 type
Definition: pwc-ioctl.h:0
Action * parent
std::string cmd
std::string name
Action * parent
std::string val
ISwitchVectorProperty _vec
ISwitch _vals[MAX_ENUMS]
One number descriptor.
One switch descriptor.
One text descriptor.
INumber _val
EnumValue _act
INumberVectorProperty _vec
ITextVectorProperty _vec
char buffer[MAX_FRAME_LENGTH]
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246