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.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index 77ced85..929aeff 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -35,24 +35,28 @@ void IOSerial::close() {
35 } else { 35 } else {
36 emit error(Refuse, tr("Not connected")); 36 emit error(Refuse, tr("Not connected"));
37 } 37 }
38} 38}
39 39
40bool IOSerial::open() { 40bool IOSerial::open() {
41 qWarning("open");
41 if (!m_fd) { 42 if (!m_fd) {
43 qWarning("going to open %s", m_device.latin1());
42 struct termios tty; 44 struct termios tty;
43 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); 45 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
44 if (m_fd < 0) { 46 if (m_fd < 0) {
47 qWarning(" fd < 0 ");
45 emit error(CouldNotOpen, strerror(errno)); 48 emit error(CouldNotOpen, strerror(errno));
46 return FALSE; 49 return FALSE;
47 } 50 }
48 tcgetattr(m_fd, &tty); 51 tcgetattr(m_fd, &tty);
49 52
50 /* Baud rate */ 53 /* Baud rate */
51 int speed = baud(m_baud); 54 int speed = baud(m_baud);
52 if (speed == -1) { 55 if (speed == -1) {
56 qWarning("speed -1");
53 emit error(Refuse, tr("Invalid baud rate")); 57 emit error(Refuse, tr("Invalid baud rate"));
54 } 58 }
55 cfsetospeed(&tty, speed); 59 cfsetospeed(&tty, speed);
56 cfsetispeed(&tty, speed); 60 cfsetispeed(&tty, speed);
57 61
58 /* Take care of Space / Mark parity */ 62 /* Take care of Space / Mark parity */
@@ -110,20 +114,23 @@ bool IOSerial::open() {
110 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); 114 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
111 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); 115 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this);
112 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 116 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
113 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 117 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
114 return TRUE; 118 return TRUE;
115 } else { 119 } else {
120 qWarning("opened");
116 emit error(Refuse, tr("Device is already connected")); 121 emit error(Refuse, tr("Device is already connected"));
117 m_fd = 0; 122 m_fd = 0;
118 return FALSE; 123 return FALSE;
119 } 124 }
120} 125}
121 126
122void IOSerial::reload(const Profile &config) { 127void IOSerial::reload(const Profile &config) {
123 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); 128 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE);
129 qWarning( "Dev" +m_device );
130 qWarning( "Conf:" +config.readEntry("Device") );
124 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD); 131 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD);
125 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); 132 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY);
126 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); 133 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS);
127 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); 134 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS);
128 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); 135 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW);
129} 136}
@@ -147,21 +154,20 @@ int IOSerial::baud(int baud) const {
147void IOSerial::errorOccured() { 154void IOSerial::errorOccured() {
148 emit error(ClosedUnexpected, strerror(errno)); 155 emit error(ClosedUnexpected, strerror(errno));
149 close(); 156 close();
150} 157}
151 158
152void IOSerial::dataArrived() { 159void IOSerial::dataArrived() {
153 QByteArray array; 160 QByteArray array(4096);
154 char buf[4096];
155 161
156 int len = read(m_fd, buf, 4096); 162 int len = read(m_fd, array.data(), 4096);
157 if (len == 0) 163 if (len == 0)
158 close(); 164 close();
159 if (len < 0) 165 if (len < 0)
160 return; 166 return;
161 array.setRawData(buf, len); 167 array.resize( len );
162 emit received(array); 168 emit received(array);
163} 169}
164 170
165QString IOSerial::identifier() const { 171QString IOSerial::identifier() const {
166 return "serial"; 172 return "serial";
167} 173}