Instrument Neutral Distributed Interface INDI 2.2.5
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#include "indipropertytext.h"
25#include "indipropertyswitch.h"
26
27#include <string>
28#include <vector>
29#include <cstdint>
30
31namespace Connection
32{
41class Serial : public Interface
42{
43 public:
50
51 Serial(INDI::DefaultDevice *dev, IPerm permission = IP_RW);
52 virtual ~Serial();
53
54 virtual bool Connect() override;
55
56 virtual bool Disconnect() override;
57
58 virtual void Activated() override;
59
60 virtual void Deactivated() override;
61
62 virtual std::string name() override
63 {
64 return "CONNECTION_SERIAL";
65 }
66
67 virtual std::string label() override
68 {
69 return "Serial";
70 }
71
75 virtual const char *port()
76 {
77 return PortTP[0].getText();
78 }
79
83 virtual uint32_t baud();
84
90 void setDefaultPort(const char *port);
91
97 void setDefaultBaudRate(BaudRate newRate);
98
115 void setPortMatchPattern(const std::string &pattern);
116
121 int getPortFD() const
122 {
123 return PortFD;
124 }
125
126 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
127 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
128 virtual bool saveConfigItems(FILE *fp) override;
129
133 bool Refresh(bool silent = false);
134
135 uint8_t getWordSize() const
136 {
137 return wordSize;
138 }
142 void setWordSize(const uint8_t &value)
143 {
144 wordSize = value;
145 }
146
147 uint8_t getParity() const
148 {
149 return parity ;
150 }
155 void setParity(const uint8_t &value)
156 {
157 parity = value;
158 }
159
160 uint8_t getStopBits() const
161 {
162 return stopBits;
163 }
167 void setStopBits(const uint8_t &value)
168 {
169 stopBits = value ;
170 }
171
172 protected:
181 virtual bool Connect(const char *port, uint32_t baud);
182
183 virtual bool processHandshake();
184
185 enum
186 {
190 };
191
192 // Device physical port
194
196
198
199 // Dynamically populated from the ports detected on the system
201
203
204 int PortFD = -1;
205
206 // Default 8N1 parameters
207 uint8_t wordSize = 8;
208 uint8_t parity = 0;
209 uint8_t stopBits = 1;
210
212
213 std::string m_ConfigPort;
215 std::vector<std::string> m_SystemPorts;
216 // Optional regex pattern for auto-selecting a port by device name (e.g. Pegasus devices)
218};
219}
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 ...
INDI::PropertySwitch RefreshSP
std::string m_PortMatchPattern
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
virtual const char * port()
INDI::PropertySwitch AutoSearchSP
virtual std::string name() override
BaudRate
Supported baud rates.
INDI::PropertySwitch SystemPortSP
std::vector< std::string > m_SystemPorts
INDI::PropertySwitch BaudRateSP
virtual void Activated() override
Activated Function called by the framework when the plugin is activated (i.e. selected by the user)....
void setPortMatchPattern(const std::string &pattern)
setPortMatchPattern Set a regex pattern used to automatically select a serial port from the discovere...
bool Refresh(bool silent=false)
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
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
INDI::PropertyText PortTP
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
INDI::PropertyViewText * getText() const
ISState
Switch state.
Definition indiapi.h:148
IPerm
Permission hint, with respect to client.
Definition indiapi.h:181
@ IP_RW
Definition indiapi.h:184
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34