Instrument Neutral Distributed Interface INDI  1.9.2
connectiontcp.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 <stdint.h>
26 #include <cstdlib>
27 #include <string>
28 
29 namespace Connection
30 {
37 class TCP : public Interface
38 {
39  public:
40  enum ConnectionType
41  {
42  TYPE_TCP = 0,
43  TYPE_UDP
44  };
45 
47  virtual ~TCP() = default;
48 
49  virtual bool Connect() override;
50 
51  virtual bool Disconnect() override;
52 
53  virtual void Activated() override;
54 
55  virtual void Deactivated() override;
56 
57  virtual std::string name() override { return "CONNECTION_TCP"; }
58 
59  virtual std::string label() override { return "Ethernet"; }
60 
61  virtual const char *host() const { return AddressT[0].text; }
62  virtual uint32_t port() const { return atoi(AddressT[1].text); }
63  ConnectionType connectionType() const { return static_cast<ConnectionType>(IUFindOnSwitchIndex(&TcpUdpSP)); }
64 
65  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
66  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
67  virtual bool saveConfigItems(FILE *fp) override;
68 
69  int getPortFD() const { return PortFD; }
70  void setDefaultHost(const char *addressHost);
71  void setDefaultPort(uint32_t addressPort);
72  void setConnectionType(int type);
73 
74  protected:
75  // IP Address/Port
77  IText AddressT[2] {};
78 
79  ISwitch TcpUdpS[2];
81 
82  int sockfd = -1;
83  const uint8_t SOCKET_TIMEOUT = 5;
84 
85  int PortFD = -1;
86 };
87 }
connectioninterface.h
Connection::TCP::getPortFD
int getPortFD() const
Definition: connectiontcp.h:105
Connection::TCP::AddressTP
ITextVectorProperty AddressTP
Definition: connectiontcp.h:112
Connection::TCP::Disconnect
virtual bool Disconnect() override
Disconnect Disconnect from device.
Definition: connectiontcp.cpp:198
ISwitch
One switch descriptor.
Connection::TCP::TcpUdpS
ISwitch TcpUdpS[2]
Definition: connectiontcp.h:115
Connection::TCP::TYPE_TCP
@ TYPE_TCP
Definition: connectiontcp.h:96
Connection::TCP::PortFD
int PortFD
Definition: connectiontcp.h:121
Connection::TCP::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
Definition: connectiontcp.cpp:223
Connection::TCP::sockfd
int sockfd
Definition: connectiontcp.h:118
Connection::TCP::label
virtual std::string label() override
Definition: connectiontcp.h:95
Connection::TCP::Connect
virtual bool Connect() override
Connect Connect to device via the implemented communication medium. Do not perform any handshakes.
Definition: connectiontcp.cpp:112
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
Connection::TCP::SOCKET_TIMEOUT
const uint8_t SOCKET_TIMEOUT
Definition: connectiontcp.h:119
Connection::TCP::~TCP
virtual ~TCP()=default
IText
One text descriptor.
Connection::TCP::setConnectionType
void setConnectionType(int type)
Definition: connectiontcp.cpp:243
Connection::Interface::type
virtual Type type()
type Return connection type
Definition: connectioninterface.h:105
Connection::TCP::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Definition: connectiontcp.cpp:77
Connection::TCP::TCP
TCP(INDI::DefaultDevice *dev)
Definition: connectiontcp.cpp:55
Connection::TCP::ConnectionType
ConnectionType
Definition: connectiontcp.h:76
Connection::TCP::Activated
virtual void Activated() override
Activated Function called by the framework when the plugin is activated (i.e. selected by the user)....
Definition: connectiontcp.cpp:209
Connection::TCP::connectionType
ConnectionType connectionType() const
Definition: connectiontcp.h:99
Connection::TCP::TcpUdpSP
ISwitchVectorProperty TcpUdpSP
Definition: connectiontcp.h:116
Connection
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:33
Connection::TCP::port
virtual uint32_t port() const
Definition: connectiontcp.h:98
Connection::TCP::TYPE_UDP
@ TYPE_UDP
Definition: connectiontcp.h:97
Connection::TCP::setDefaultHost
void setDefaultHost(const char *addressHost)
Definition: connectiontcp.cpp:231
Connection::TCP::setDefaultPort
void setDefaultPort(uint32_t addressPort)
Definition: connectiontcp.cpp:236
Connection::TCP::name
virtual std::string name() override
Definition: connectiontcp.h:93
Connection::TCP::host
virtual const char * host() const
Definition: connectiontcp.h:97
Connection::TCP::Deactivated
virtual void Deactivated() override
Deactivated Function called by the framework when the plugin is deactivated. It is usually used to de...
Definition: connectiontcp.cpp:217
ISState
ISState
Switch state.
Definition: indiapi.h:148
IUFindOnSwitchIndex
int IUFindOnSwitchIndex(const ISwitchVectorProperty *sp)
Returns the index of first ON switch it finds in the vector switch property.
Definition: indicom.c:1403
INDI::DefaultDevice
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:118
Connection::TCP::AddressT
IText AddressT[2]
Definition: connectiontcp.h:113
Connection::TCP::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Definition: connectiontcp.cpp:94
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365