Instrument Neutral Distributed Interface INDI 2.2.5
ttybase.h
Go to the documentation of this file.
1/*
2 TTY Base
3
4 Base class for TTY Serial Connections.
5
6 Copyright (C) 2018 Jasem Mutlaq
7 Copyright (C) 2011 Wildi Markus
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
23*/
24
25#pragma once
26
27#include <string>
28#include <indilogger.h>
29
43{
44 public:
57
58 TTYBase(const char *driverName);
59 virtual ~TTYBase();
60
69 TTY_RESPONSE read(uint8_t *buffer, uint32_t nbytes, uint8_t timeout, uint32_t *nbytes_read);
70
80 TTY_RESPONSE readSection(uint8_t *buffer, uint32_t nsize, uint8_t stop_byte, uint8_t timeout, uint32_t *nbytes_read);
81
89 TTY_RESPONSE write(const uint8_t *buffer, uint32_t nbytes, uint32_t *nbytes_written);
90
97 TTY_RESPONSE writeString(const char *string, uint32_t *nbytes_written);
98
108 TTY_RESPONSE connect(const char *device, uint32_t bit_rate, uint8_t word_size, uint8_t parity, uint8_t stop_bits);
109
114
123
128 const std::string error(TTY_RESPONSE code) const;
129
130 int getPortFD() const
131 {
132 return m_PortFD;
133 }
134
135 private:
136
137 TTY_RESPONSE checkTimeout(uint8_t timeout);
138
139 int m_PortFD { -1 };
140 bool m_Debug { false };
142 const char *m_DriverName;
143};
hid_device * device
Base class for serial communications.
Definition ttybase.h:43
TTY_RESPONSE read(uint8_t *buffer, uint32_t nbytes, uint8_t timeout, uint32_t *nbytes_read)
read buffer from terminal
Definition ttybase.cpp:158
const std::string error(TTY_RESPONSE code) const
Retrieve the tty error message.
Definition ttybase.cpp:740
void setDebug(INDI::Logger::VerbosityLevel channel)
setDebug Enable or Disable debug logging
TTY_RESPONSE writeString(const char *string, uint32_t *nbytes_written)
Writes a null terminated string to fd.
Definition ttybase.cpp:152
virtual ~TTYBase()
Definition ttybase.cpp:78
TTY_RESPONSE readSection(uint8_t *buffer, uint32_t nsize, uint8_t stop_byte, uint8_t timeout, uint32_t *nbytes_read)
read buffer from terminal with a delimiter
Definition ttybase.cpp:219
TTY_RESPONSE disconnect()
Closes a tty connection and flushes the bus.
Definition ttybase.cpp:722
TTY_RESPONSE
Definition ttybase.h:46
@ TTY_PORT_FAILURE
Definition ttybase.h:52
@ TTY_OK
Definition ttybase.h:47
@ TTY_READ_ERROR
Definition ttybase.h:48
@ TTY_WRITE_ERROR
Definition ttybase.h:49
@ TTY_TIME_OUT
Definition ttybase.h:51
@ TTY_PARAM_ERROR
Definition ttybase.h:53
@ TTY_SELECT_ERROR
Definition ttybase.h:50
@ TTY_ERRNO
Definition ttybase.h:54
@ TTY_OVERFLOW
Definition ttybase.h:55
TTY_RESPONSE write(const uint8_t *buffer, uint32_t nbytes, uint32_t *nbytes_written)
Writes a buffer to fd.
Definition ttybase.cpp:121
TTY_RESPONSE connect(const char *device, uint32_t bit_rate, uint8_t word_size, uint8_t parity, uint8_t stop_bits)
Establishes a tty connection to a terminal device.
Definition ttybase.cpp:534
int getPortFD() const
Definition ttybase.h:130