summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/io_serial.cpp14
-rw-r--r--noncore/apps/opie-console/profile.cpp2
-rw-r--r--noncore/apps/opie-console/test/console.pro15
-rw-r--r--noncore/apps/opie-console/test/main.cpp13
-rw-r--r--noncore/apps/opie-console/test/sender.ui60
-rw-r--r--noncore/apps/opie-console/test/senderui.cpp47
-rw-r--r--noncore/apps/opie-console/test/senderui.h23
7 files changed, 170 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
@@ -29,36 +29,40 @@ void IOSerial::send(const QByteArray &data) {
29void IOSerial::close() { 29void IOSerial::close() {
30 if (m_fd) { 30 if (m_fd) {
31 delete m_read; 31 delete m_read;
32 delete m_error; 32 delete m_error;
33 ::close(m_fd); 33 ::close(m_fd);
34 m_fd = 0; 34 m_fd = 0;
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 */
59 if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) { 63 if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) {
60 m_dbits = 8; 64 m_dbits = 8;
61 } 65 }
62 66
63 /* Data bits */ 67 /* Data bits */
64 switch (m_dbits) { 68 switch (m_dbits) {
@@ -104,32 +108,35 @@ bool IOSerial::open() {
104 tty.c_cflag |= (PARENB | PARODD); 108 tty.c_cflag |= (PARENB | PARODD);
105 109
106 /* Set the changes */ 110 /* Set the changes */
107 tcsetattr(m_fd, TCSANOW, &tty); 111 tcsetattr(m_fd, TCSANOW, &tty);
108 112
109 /* Notifications on read & errors */ 113 /* Notifications on read & errors */
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}
130 137
131int IOSerial::baud(int baud) const { 138int IOSerial::baud(int baud) const {
132 switch (baud) { 139 switch (baud) {
133 case 300: return B300; break; 140 case 300: return B300; break;
134 case 600: return B600; break; 141 case 600: return B600; break;
135 case 1200: return B1200; break; 142 case 1200: return B1200; break;
@@ -141,31 +148,30 @@ int IOSerial::baud(int baud) const {
141 case 57600: return B57600; break; 148 case 57600: return B57600; break;
142 case 115200: return B115200; break; 149 case 115200: return B115200; break;
143 } 150 }
144 return -1; 151 return -1;
145} 152}
146 153
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}
168 174
169QString IOSerial::name() const { 175QString IOSerial::name() const {
170 return "RS232 Serial IO Layer"; 176 return "RS232 Serial IO Layer";
171} 177}
diff --git a/noncore/apps/opie-console/profile.cpp b/noncore/apps/opie-console/profile.cpp
index 1a94619..ffd672e 100644
--- a/noncore/apps/opie-console/profile.cpp
+++ b/noncore/apps/opie-console/profile.cpp
@@ -69,27 +69,29 @@ void Profile::setBackground( int back ) {
69} 69}
70void Profile::setForeground( int fore ) { 70void Profile::setForeground( int fore ) {
71 m_fore = fore; 71 m_fore = fore;
72} 72}
73void Profile::setTerminal( int term ) { 73void Profile::setTerminal( int term ) {
74 m_terminal = term; 74 m_terminal = term;
75} 75}
76/* config stuff */ 76/* config stuff */
77void Profile::clearConf() { 77void Profile::clearConf() {
78 m_conf.clear(); 78 m_conf.clear();
79} 79}
80void Profile::writeEntry( const QString& key, const QString& value ) { 80void Profile::writeEntry( const QString& key, const QString& value ) {
81 qWarning("key %s value %s", key.latin1(), value.latin1() );
81 m_conf.replace( key, value ); 82 m_conf.replace( key, value );
82} 83}
83void Profile::writeEntry( const QString& key, int num ) { 84void Profile::writeEntry( const QString& key, int num ) {
85 qWarning("num");
84 writeEntry( key, QString::number( num ) ); 86 writeEntry( key, QString::number( num ) );
85} 87}
86void Profile::writeEntry( const QString& key, bool b ) { 88void Profile::writeEntry( const QString& key, bool b ) {
87 writeEntry( key, QString::number(b) ); 89 writeEntry( key, QString::number(b) );
88} 90}
89void Profile::writeEntry( const QString& key, const QStringList& lis, const QChar& sep ) { 91void Profile::writeEntry( const QString& key, const QStringList& lis, const QChar& sep ) {
90 writeEntry( key, lis.join(sep) ); 92 writeEntry( key, lis.join(sep) );
91} 93}
92QString Profile::readEntry( const QString& key, const QString& deflt )const { 94QString Profile::readEntry( const QString& key, const QString& deflt )const {
93 QMap<QString, QString>::ConstIterator it; 95 QMap<QString, QString>::ConstIterator it;
94 it = m_conf.find( key ); 96 it = m_conf.find( key );
95 97
diff --git a/noncore/apps/opie-console/test/console.pro b/noncore/apps/opie-console/test/console.pro
new file mode 100644
index 0000000..721b820
--- a/dev/null
+++ b/noncore/apps/opie-console/test/console.pro
@@ -0,0 +1,15 @@
1TEMPLATE = app
2#CONFIG = qt warn_on release
3 CONFIG = qt debug
4#DESTDIR = $(OPIEDIR)/bin
5HEADERS = ../io_layer.h ../io_serial.h \
6 senderui.h ../profile.h
7SOURCES = ../io_layer.cpp ../io_serial.cpp \
8 ../profile.cpp \
9 main.cpp senderui.cpp
10INTERFACES = sender.ui
11INCLUDEPATH += $(OPIEDIR)/include
12DEPENDPATH += $(OPIEDIR)/include
13LIBS += -lqpe -lopie
14TARGET = test
15
diff --git a/noncore/apps/opie-console/test/main.cpp b/noncore/apps/opie-console/test/main.cpp
new file mode 100644
index 0000000..f5e8722
--- a/dev/null
+++ b/noncore/apps/opie-console/test/main.cpp
@@ -0,0 +1,13 @@
1#include <qpe/qpeapplication.h>
2
3#include "senderui.h"
4
5
6int main( int argc, char* argv[] ){
7QPEApplication app(argc,argv );
8
9SenderUI ui;
10app.showMainWidget(&ui);
11
12return app.exec();
13} \ No newline at end of file
diff --git a/noncore/apps/opie-console/test/sender.ui b/noncore/apps/opie-console/test/sender.ui
new file mode 100644
index 0000000..092f6e3
--- a/dev/null
+++ b/noncore/apps/opie-console/test/sender.ui
@@ -0,0 +1,60 @@
1<!DOCTYPE UI><UI>
2<class>Sender</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>Form1</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>596</width>
15 <height>480</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Form1</string>
21 </property>
22 <vbox>
23 <property stdset="1">
24 <name>margin</name>
25 <number>11</number>
26 </property>
27 <property stdset="1">
28 <name>spacing</name>
29 <number>6</number>
30 </property>
31 <widget>
32 <class>QMultiLineEdit</class>
33 <property stdset="1">
34 <name>name</name>
35 <cstring>MultiLineEdit1</cstring>
36 </property>
37 </widget>
38 <widget>
39 <class>QPushButton</class>
40 <property stdset="1">
41 <name>name</name>
42 <cstring>PushButton1</cstring>
43 </property>
44 <property stdset="1">
45 <name>text</name>
46 <string>&amp;Send</string>
47 </property>
48 </widget>
49 </vbox>
50</widget>
51<connections>
52 <connection>
53 <sender>PushButton1</sender>
54 <signal>clicked()</signal>
55 <receiver>Form1</receiver>
56 <slot>slotSend()</slot>
57 </connection>
58 <slot access="public">slotSend()</slot>
59</connections>
60</UI>
diff --git a/noncore/apps/opie-console/test/senderui.cpp b/noncore/apps/opie-console/test/senderui.cpp
new file mode 100644
index 0000000..fc93c04
--- a/dev/null
+++ b/noncore/apps/opie-console/test/senderui.cpp
@@ -0,0 +1,47 @@
1#include <stdlib.h>
2#include <stdio.h>
3
4#include <qmultilineedit.h>
5
6#include "../profile.h"
7#include "../io_serial.h"
8
9
10#include "senderui.h"
11
12SenderUI::SenderUI()
13 : Sender() {
14
15 /* we do that manually */
16 Profile prof;
17 QString str = "/dev/ttyS0";
18 prof.writeEntry("Device",str );
19 prof.writeEntry("Baud", 115200 );
20
21 qWarning("prof " + prof.readEntry("Device") + " " + str);
22 ser = new IOSerial(prof);
23 connect(ser, SIGNAL(received(const QByteArray& ) ),
24 this, SLOT(got(const QByteArray&) ) );
25
26 if ( ser->open() )
27 qWarning("opened!!!");
28 else
29 qWarning("could not open");
30
31
32
33}
34SenderUI::~SenderUI() {
35
36}
37void SenderUI::slotSend() {
38 QCString str = MultiLineEdit1->text().utf8();
39 qWarning("sending: %s", str.data() );
40 ser->send( str );
41}
42void SenderUI::got(const QByteArray& ar) {
43 for ( uint i = 0; i < ar.count(); i++ ) {
44 printf("%c", ar[i] );
45 }
46 //printf("\n");
47}
diff --git a/noncore/apps/opie-console/test/senderui.h b/noncore/apps/opie-console/test/senderui.h
new file mode 100644
index 0000000..bc69f5d
--- a/dev/null
+++ b/noncore/apps/opie-console/test/senderui.h
@@ -0,0 +1,23 @@
1#ifndef SENDER_UI_H
2#define SENDER_UI_H
3
4#include <qcstring.h>
5
6#include "sender.h"
7
8class IOSerial;
9class SenderUI : public Sender {
10 Q_OBJECT
11public:
12 SenderUI();
13 ~SenderUI();
14
15public slots:
16 void slotSend();
17 void got(const QByteArray& );
18private:
19 IOSerial* ser;
20};
21
22
23#endif