summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/io_serial.cpp
authorharlekin <harlekin>2002-10-15 22:03:01 (UTC)
committer harlekin <harlekin>2002-10-15 22:03:01 (UTC)
commitce953c24f809385088905ffd02f6d6187d0a4f12 (patch) (unidiff)
tree19f10579ebd5870cf38940d624c97111ea8137b3 /noncore/apps/opie-console/io_serial.cpp
parent676be5604cbdb3213c00775e0ff66f4e766f8dcb (diff)
downloadopie-ce953c24f809385088905ffd02f6d6187d0a4f12.zip
opie-ce953c24f809385088905ffd02f6d6187d0a4f12.tar.gz
opie-ce953c24f809385088905ffd02f6d6187d0a4f12.tar.bz2
next isConnected try
Diffstat (limited to 'noncore/apps/opie-console/io_serial.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/io_serial.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index c10d5a8..b89a53b 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -1,47 +1,50 @@
1#include <fcntl.h> 1#include <fcntl.h>
2#include <termios.h> 2#include <termios.h>
3#include <errno.h> 3#include <errno.h>
4#include <unistd.h> 4#include <unistd.h>
5#include "io_serial.h" 5#include "io_serial.h"
6 6
7IOSerial::IOSerial(const Profile &config) : IOLayer(config) { 7IOSerial::IOSerial(const Profile &config) : IOLayer(config) {
8 m_read = 0l; 8 m_read = 0l;
9 m_error = 0l; 9 m_error = 0l;
10 m_fd = 0; 10 m_fd = 0;
11 m_connected = false;
11 reload(config); 12 reload(config);
12} 13}
13 14
14 15
15IOSerial::~IOSerial() { 16IOSerial::~IOSerial() {
16 if (m_fd) { 17 if (m_fd) {
17 close(); 18 close();
18 } 19 }
19} 20}
20 21
21void IOSerial::send(const QByteArray &data) { 22void IOSerial::send(const QByteArray &data) {
22 if (m_fd) { 23 if (m_fd) {
23 write(m_fd, data.data(), data.size()); 24 write(m_fd, data.data(), data.size());
24 } else { 25 } else {
25 emit error(Refuse, tr("Not connected")); 26 emit error(Refuse, tr("Not connected"));
26 } 27 }
27} 28}
28 29
29void IOSerial::close() { 30void IOSerial::close() {
30 if (m_fd) { 31 if (m_fd) {
31 delete m_read; 32 delete m_read;
32 delete m_error; 33 delete m_error;
33 ::close(m_fd); 34 ::close(m_fd);
34 m_fd = 0; 35 m_fd = 0;
36 m_connected = false;
35 } else { 37 } else {
38 m_connected = false;
36 emit error(Refuse, tr("Not connected")); 39 emit error(Refuse, tr("Not connected"));
37 } 40 }
38} 41}
39 42
40bool IOSerial::open() { 43bool IOSerial::open() {
41 if (!m_fd) { 44 if (!m_fd) {
42 struct termios tty; 45 struct termios tty;
43 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); 46 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
44 if (m_fd < 0) { 47 if (m_fd < 0) {
45 emit error(CouldNotOpen, strerror(errno)); 48 emit error(CouldNotOpen, strerror(errno));
46 return FALSE; 49 return FALSE;
47 } 50 }
@@ -102,24 +105,25 @@ bool IOSerial::open() {
102 tty.c_cflag |= PARENB; 105 tty.c_cflag |= PARENB;
103 else if (m_parity & ParityOdd) 106 else if (m_parity & ParityOdd)
104 tty.c_cflag |= (PARENB | PARODD); 107 tty.c_cflag |= (PARENB | PARODD);
105 108
106 /* Set the changes */ 109 /* Set the changes */
107 tcsetattr(m_fd, TCSANOW, &tty); 110 tcsetattr(m_fd, TCSANOW, &tty);
108 111
109 /* Notifications on read & errors */ 112 /* Notifications on read & errors */
110 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); 113 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
111 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); 114 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this);
112 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 115 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
113 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 116 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
117 m_connected = false;
114 return TRUE; 118 return TRUE;
115 } else { 119 } else {
116 emit error(Refuse, tr("Device is already connected")); 120 emit error(Refuse, tr("Device is already connected"));
117 m_fd = 0; 121 m_fd = 0;
118 return FALSE; 122 return FALSE;
119 } 123 }
120} 124}
121 125
122void IOSerial::reload(const Profile &config) { 126void IOSerial::reload(const Profile &config) {
123 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); 127 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE);
124 m_baud = config.readNumEntry("Speed", SERIAL_DEFAULT_BAUD); 128 m_baud = config.readNumEntry("Speed", SERIAL_DEFAULT_BAUD);
125 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); 129 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY);
@@ -185,12 +189,16 @@ void IOSerial::closeRawIO(int fd) {
185 if (m_error ) 189 if (m_error )
186 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 190 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
187 191
188 ::close( fd ); 192 ::close( fd );
189} 193}
190QBitArray IOSerial::supports()const { 194QBitArray IOSerial::supports()const {
191 QBitArray ar(3); 195 QBitArray ar(3);
192 ar[0] = ar[2] = 0; 196 ar[0] = ar[2] = 0;
193 ar[1] = 1; 197 ar[1] = 1;
194 198
195 return ar; 199 return ar;
196} 200}
201
202bool IOSerial::isConnected() {
203 return m_connected;
204}