Instrument Neutral Distributed Interface INDI  2.0.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 #include <cstdint>
28 
29 namespace Connection
30 {
39 class Serial : public Interface
40 {
41  public:
48 
50  virtual ~Serial();
51 
52  virtual bool Connect() override;
53 
54  virtual bool Disconnect() override;
55 
56  virtual void Activated() override;
57 
58  virtual void Deactivated() override;
59 
60  virtual std::string name() override
61  {
62  return "CONNECTION_SERIAL";
63  }
64 
65  virtual std::string label() override
66  {
67  return "Serial";
68  }
69 
73  virtual const char *port()
74  {
75  return PortT[0].text;
76  }
77 
81  virtual uint32_t baud();
82 
88  void setDefaultPort(const char *port);
89 
95  void setDefaultBaudRate(BaudRate newRate);
96 
101  int getPortFD() const
102  {
103  return PortFD;
104  }
105 
106  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
107  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
108  virtual bool saveConfigItems(FILE *fp) override;
109 
113  bool Refresh(bool silent = false);
114 
115  uint8_t getWordSize() const
116  {
117  return wordSize;
118  }
122  void setWordSize(const uint8_t &value)
123  {
124  wordSize = value;
125  }
126 
127  uint8_t getParity() const
128  {
129  return parity ;
130  }
135  void setParity(const uint8_t &value)
136  {
137  parity = value;
138  }
139 
140  uint8_t getStopBits() const
141  {
142  return stopBits;
143  }
147  void setStopBits(const uint8_t &value)
148  {
149  stopBits = value ;
150  }
151 
152  protected:
161  virtual bool Connect(const char *port, uint32_t baud);
162 
163  virtual bool processHandshake();
164 
165  enum
166  {
170  };
171 
172  // Device physical port
174  IText PortT[1] {};
175 
178 
181 
182  ISwitch *SystemPortS = nullptr;
184 
187 
188  int PortFD = -1;
189 
190  // Default 8N1 parameters
191  uint8_t wordSize = 8;
192  uint8_t parity = 0;
193  uint8_t stopBits = 1;
194 
195  std::string m_ConfigPort;
197  std::vector<std::string> m_SystemPorts;
198 };
199 }
The Interface class is the base class for all INDI connection plugins.
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
ISwitchVectorProperty RefreshSP
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
virtual std::string name() override
BaudRate
Supported baud rates.
std::string m_ConfigPort
ITextVectorProperty PortTP
std::vector< std::string > m_SystemPorts
virtual void Activated() override
Activated Function called by the framework when the plugin is activated (i.e. selected by the user)....
bool Refresh(bool silent=false)
ISwitchVectorProperty BaudRateSP
void setWordSize(const uint8_t &value)
setWordSize Set word size to be used in the serial connection. Default 8
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
virtual void Deactivated() override
Deactivated Function called by the framework when the plugin is deactivated. It is usually used to de...
uint8_t getWordSize() const
ISwitchVectorProperty SystemPortSP
ISwitchVectorProperty AutoSearchSP
Serial(INDI::DefaultDevice *dev)
virtual bool Disconnect() override
Disconnect Disconnect from device.
void setParity(const uint8_t &value)
setParity Set parity to be used in the serial connection. Default 0 (NONE)
virtual bool saveConfigItems(FILE *fp) override
void setDefaultPort(const char *port)
setDefaultPort Set default port. Call this function in initProperties() of your driver if you want to...
virtual bool Connect() override
Connect Connect to device via the implemented communication medium. Do not perform any handshakes.
virtual uint32_t baud()
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
uint8_t getParity() const
uint8_t getStopBits() const
void setStopBits(const uint8_t &value)
setStopBits Set stop bits to be used in the serial connection. Default 0
virtual bool processHandshake()
virtual std::string label() override
virtual const char * port()
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
ISState
Switch state.
Definition: indiapi.h:150
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:34
One switch descriptor.
One text descriptor.
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246