summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/io_serial.cpp
Unidiff
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.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index 845f4be..4129d64 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -18,24 +18,25 @@ IOSerial::~IOSerial() {
18 } 18 }
19} 19}
20 20
21void IOSerial::send(const QByteArray &data) { 21void IOSerial::send(const QByteArray &data) {
22 if (m_fd) { 22 if (m_fd) {
23 write(m_fd, data.data(), data.size()); 23 write(m_fd, data.data(), data.size());
24 } else { 24 } else {
25 emit error(Refuse, tr("Not connected")); 25 emit error(Refuse, tr("Not connected"));
26 } 26 }
27} 27}
28 28
29void IOSerial::close() { 29void IOSerial::close() {
30 qWarning("closing!");
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;
35 } else { 36 } else {
36 emit error(Refuse, tr("Not connected")); 37 emit error(Refuse, tr("Not connected"));
37 } 38 }
38} 39}
39 40
40bool IOSerial::open() { 41bool IOSerial::open() {
41 qWarning("open"); 42 qWarning("open");
@@ -108,25 +109,25 @@ bool IOSerial::open() {
108 tty.c_cflag |= (PARENB | PARODD); 109 tty.c_cflag |= (PARENB | PARODD);
109 110
110 /* Set the changes */ 111 /* Set the changes */
111 tcsetattr(m_fd, TCSANOW, &tty); 112 tcsetattr(m_fd, TCSANOW, &tty);
112 113
113 /* Notifications on read & errors */ 114 /* Notifications on read & errors */
114 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); 115 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
115 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); 116 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this);
116 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 117 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
117 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 118 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
118 return TRUE; 119 return TRUE;
119 } else { 120 } else {
120 qWarning("opened"); 121 qWarning(" already opened");
121 emit error(Refuse, tr("Device is already connected")); 122 emit error(Refuse, tr("Device is already connected"));
122 m_fd = 0; 123 m_fd = 0;
123 return FALSE; 124 return FALSE;
124 } 125 }
125} 126}
126 127
127void IOSerial::reload(const Profile &config) { 128void IOSerial::reload(const Profile &config) {
128 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); 129 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE);
129 qWarning( "Dev" +m_device ); 130 qWarning( "Dev" +m_device );
130 qWarning( "Conf:" +config.readEntry("Device") ); 131 qWarning( "Conf:" +config.readEntry("Device") );
131 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD); 132 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD);
132 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); 133 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY);
@@ -167,16 +168,29 @@ void IOSerial::dataArrived() {
167 array.resize( len ); 168 array.resize( len );
168 emit received(array); 169 emit received(array);
169} 170}
170 171
171QString IOSerial::identifier() const { 172QString IOSerial::identifier() const {
172 return "serial"; 173 return "serial";
173} 174}
174 175
175QString IOSerial::name() const { 176QString IOSerial::name() const {
176 return "RS232 Serial IO Layer"; 177 return "RS232 Serial IO Layer";
177} 178}
178int IOSerial::rawIO()const { 179int IOSerial::rawIO()const {
180 if (m_read )
181 disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
182 if (m_error )
183 disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
184
179 int fd = ::open(m_device, O_RDWR ); 185 int fd = ::open(m_device, O_RDWR );
180 186
181 return fd; 187 return fd;
182}; 188};
189void IOSerial::closeRawIO(int fd) {
190 if (m_read )
191 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
192 if (m_error )
193 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
194
195 ::close( fd );
196}