Instrument Neutral Distributed Interface INDI  1.9.2
connectionserial.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3 
4  Connection Plugin Interface
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 #pragma once
22 
23 #include "connectioninterface.h"
24 
25 #include <string>
26 #include <vector>
27 
28 namespace Connection
29 {
38 class Serial : public Interface
39 {
40  public:
46  typedef enum { B_9600, B_19200, B_38400, B_57600, B_115200, B_230400 } BaudRate;
47 
49  virtual ~Serial();
50 
51  virtual bool Connect() override;
52 
53  virtual bool Disconnect() override;
54 
55  virtual void Activated() override;
56 
57  virtual void Deactivated() override;
58 
59  virtual std::string name() override
60  {
61  return "CONNECTION_SERIAL";
62  }
63 
64  virtual std::string label() override
65  {
66  return "Serial";
67  }
68 
72  virtual const char *port()
73  {
74  return PortT[0].text;
75  }
76 
80  virtual uint32_t baud();
81 
87  void setDefaultPort(const char *port);
88 
94  void setDefaultBaudRate(BaudRate newRate);
95 
100  int getPortFD() const
101  {
102  return PortFD;
103  }
104 
105  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
106  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
107  virtual bool saveConfigItems(FILE *fp) override;
108 
112  bool Refresh(bool silent = false);
113 
114  uint8_t getWordSize() const
115  {
116  return wordSize;
117  }
121  void setWordSize(const uint8_t &value)
122  {
123  wordSize = value;
124  }
125 
126  uint8_t getParity() const
127  {
128  return parity ;
129  }
134  void setParity(const uint8_t &value)
135  {
136  parity = value;
137  }
138 
139  uint8_t getStopBits() const
140  {
141  return stopBits;
142  }
146  void setStopBits(const uint8_t &value)
147  {
148  stopBits = value ;
149  }
150 
151  protected:
160  virtual bool Connect(const char *port, uint32_t baud);
161 
162  virtual bool processHandshake();
163 
164  enum
165  {
166  SERIAL_DEV,
167  USB_ID_DEV,
169  };
170 
171  // Device physical port
173  IText PortT[1] {};
174 
177 
178  ISwitch AutoSearchS[2];
180 
181  ISwitch *SystemPortS = nullptr;
183 
184  ISwitch RefreshS[1];
186 
187  int PortFD = -1;
188 
189  // Default 8N1 parameters
190  uint8_t wordSize = 8;
191  uint8_t parity = 0;
192  uint8_t stopBits = 1;
193 
194  std::string m_ConfigPort;
195  int m_ConfigBaudRate {-1};
196  std::vector<std::string> m_SystemPorts;
197 };
198 }
connectioninterface.h
Connection::Serial::port
virtual const char * port()
Definition: connectionserial.h:108
Connection::Serial::parity
uint8_t parity
Definition: connectionserial.h:227
Connection::Serial::m_ConfigBaudRate
int m_ConfigBaudRate
Definition: connectionserial.h:231
Connection::Serial::setWordSize
void setWordSize(const uint8_t &value)
setWordSize Set word size to be used in the serial connection. Default 8
Definition: connectionserial.h:157
Connection::Serial::wordSize
uint8_t wordSize
Definition: connectionserial.h:226
Connection::Serial::B_38400
@ B_38400
Definition: connectionserial.h:82
Connection::Serial::Connect
virtual bool Connect() override
Connect Connect to device via the implemented communication medium. Do not perform any handshakes.
Definition: connectionserial.cpp:199
ISwitch
One switch descriptor.
Connection::Serial::setStopBits
void setStopBits(const uint8_t &value)
setStopBits Set stop bits to be used in the serial connection. Default 0
Definition: connectionserial.h:182
Connection::Serial::stopBits
uint8_t stopBits
Definition: connectionserial.h:228
Connection::Serial::Refresh
bool Refresh(bool silent=false)
Definition: connectionserial.cpp:435
Connection::Serial::B_230400
@ B_230400
Definition: connectionserial.h:82
Connection::Serial::Serial
Serial(INDI::DefaultDevice *dev)
Definition: connectionserial.cpp:52
Connection::Serial::B_115200
@ B_115200
Definition: connectionserial.h:82
Connection::Serial::AutoSearchSP
ISwitchVectorProperty AutoSearchSP
Definition: connectionserial.h:215
Connection::Serial::BLUETOOTH_DEV
@ BLUETOOTH_DEV
Definition: connectionserial.h:204
Connection::Serial::PortTP
ITextVectorProperty PortTP
Definition: connectionserial.h:208
Connection::Serial::~Serial
virtual ~Serial()
Definition: connectionserial.cpp:103
Connection::Serial::B_19200
@ B_19200
Definition: connectionserial.h:82
Connection::Serial::B_9600
@ B_9600
Definition: connectionserial.h:82
Connection::Serial::Disconnect
virtual bool Disconnect() override
Disconnect Disconnect from device.
Definition: connectionserial.cpp:331
Connection::Serial::m_ConfigPort
std::string m_ConfigPort
Definition: connectionserial.h:230
Connection::Serial::name
virtual std::string name() override
Definition: connectionserial.h:95
Connection::Serial::setDefaultPort
void setDefaultPort(const char *port)
setDefaultPort Set default port. Call this function in initProperties() of your driver if you want to...
Definition: connectionserial.cpp:370
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
Connection::Serial::setParity
void setParity(const uint8_t &value)
setParity Set parity to be used in the serial connection. Default 0 (NONE)
Definition: connectionserial.h:170
Connection::Serial::setDefaultBaudRate
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
Definition: connectionserial.cpp:375
Connection::Serial::SystemPortSP
ISwitchVectorProperty SystemPortSP
Definition: connectionserial.h:218
Connection::Serial::B_57600
@ B_57600
Definition: connectionserial.h:82
Connection::Serial::label
virtual std::string label() override
Definition: connectionserial.h:100
Connection::Serial::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
Definition: connectionserial.cpp:361
IText
One text descriptor.
Connection::Serial::BaudRate
BaudRate
Supported baud rates.
Definition: connectionserial.h:82
Connection::Serial::RefreshSP
ISwitchVectorProperty RefreshSP
Definition: connectionserial.h:221
Connection::Serial::m_SystemPorts
std::vector< std::string > m_SystemPorts
Definition: connectionserial.h:232
Connection::Serial::PortFD
int PortFD
Definition: connectionserial.h:223
Connection::Serial::getStopBits
uint8_t getStopBits() const
Definition: connectionserial.h:175
Connection::Serial::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Definition: connectionserial.cpp:108
Connection::Serial::BaudRateSP
ISwitchVectorProperty BaudRateSP
Definition: connectionserial.h:212
Connection
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:33
Connection::Serial::AutoSearchS
ISwitch AutoSearchS[2]
Definition: connectionserial.h:214
Connection::Serial::baud
virtual uint32_t baud()
Definition: connectionserial.cpp:381
Connection::Serial::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Definition: connectionserial.cpp:137
Connection::Serial::processHandshake
virtual bool processHandshake()
Definition: connectionserial.cpp:284
Connection::Serial::RefreshS
ISwitch RefreshS[1]
Definition: connectionserial.h:220
Connection::Serial::getParity
uint8_t getParity() const
Definition: connectionserial.h:162
Connection::Serial::SystemPortS
ISwitch * SystemPortS
Definition: connectionserial.h:217
Connection::Serial::Deactivated
virtual void Deactivated() override
Deactivated Function called by the framework when the plugin is deactivated. It is usually used to de...
Definition: connectionserial.cpp:350
ISState
ISState
Switch state.
Definition: indiapi.h:148
Connection::Serial::getPortFD
int getPortFD() const
Definition: connectionserial.h:136
Connection::Serial::PortT
IText PortT[1]
Definition: connectionserial.h:209
Connection::Serial::USB_ID_DEV
@ USB_ID_DEV
Definition: connectionserial.h:203
Connection::Serial::SERIAL_DEV
@ SERIAL_DEV
Definition: connectionserial.h:202
INDI::DefaultDevice
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:118
Connection::Serial::Activated
virtual void Activated() override
Activated Function called by the framework when the plugin is activated (i.e. selected by the user)....
Definition: connectionserial.cpp:341
Connection::Serial::BaudRateS
ISwitch BaudRateS[6]
Definition: connectionserial.h:211
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
Connection::Serial::getWordSize
uint8_t getWordSize() const
Definition: connectionserial.h:150