author | zecke <zecke> | 2002-10-09 14:25:38 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-09 14:25:38 (UTC) |
commit | f9f2d227b3cfbc2187b4f7f535fc59f9735798d0 (patch) (unidiff) | |
tree | 7645623f7dde640222fab3e5ff0af0af3ae2f882 /noncore/apps/opie-console | |
parent | ff0caad7ea46d19f7a7916047fd0914f6f100dde (diff) | |
download | opie-f9f2d227b3cfbc2187b4f7f535fc59f9735798d0.zip opie-f9f2d227b3cfbc2187b4f7f535fc59f9735798d0.tar.gz opie-f9f2d227b3cfbc2187b4f7f535fc59f9735798d0.tar.bz2 |
A small testsuite
the stuff from the remote goes to the stdout
There is a send button and a multilineedit
be sure to hit \n before sending...
Some debug code... in some files
debugged IOSerial it should be fine now
-rw-r--r-- | noncore/apps/opie-console/io_serial.cpp | 14 | ||||
-rw-r--r-- | noncore/apps/opie-console/profile.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/test/console.pro | 15 | ||||
-rw-r--r-- | noncore/apps/opie-console/test/main.cpp | 13 | ||||
-rw-r--r-- | noncore/apps/opie-console/test/sender.ui | 60 | ||||
-rw-r--r-- | noncore/apps/opie-console/test/senderui.cpp | 47 | ||||
-rw-r--r-- | noncore/apps/opie-console/test/senderui.h | 23 |
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) { | |||
29 | void IOSerial::close() { | 29 | void 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 | ||
40 | bool IOSerial::open() { | 40 | bool 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 | ||
122 | void IOSerial::reload(const Profile &config) { | 127 | void 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 | ||
131 | int IOSerial::baud(int baud) const { | 138 | int 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 | ||
147 | void IOSerial::errorOccured() { | 154 | void IOSerial::errorOccured() { |
148 | emit error(ClosedUnexpected, strerror(errno)); | 155 | emit error(ClosedUnexpected, strerror(errno)); |
149 | close(); | 156 | close(); |
150 | } | 157 | } |
151 | 158 | ||
152 | void IOSerial::dataArrived() { | 159 | void 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 | ||
165 | QString IOSerial::identifier() const { | 171 | QString IOSerial::identifier() const { |
166 | return "serial"; | 172 | return "serial"; |
167 | } | 173 | } |
168 | 174 | ||
169 | QString IOSerial::name() const { | 175 | QString 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 | } |
70 | void Profile::setForeground( int fore ) { | 70 | void Profile::setForeground( int fore ) { |
71 | m_fore = fore; | 71 | m_fore = fore; |
72 | } | 72 | } |
73 | void Profile::setTerminal( int term ) { | 73 | void Profile::setTerminal( int term ) { |
74 | m_terminal = term; | 74 | m_terminal = term; |
75 | } | 75 | } |
76 | /* config stuff */ | 76 | /* config stuff */ |
77 | void Profile::clearConf() { | 77 | void Profile::clearConf() { |
78 | m_conf.clear(); | 78 | m_conf.clear(); |
79 | } | 79 | } |
80 | void Profile::writeEntry( const QString& key, const QString& value ) { | 80 | void 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 | } |
83 | void Profile::writeEntry( const QString& key, int num ) { | 84 | void Profile::writeEntry( const QString& key, int num ) { |
85 | qWarning("num"); | ||
84 | writeEntry( key, QString::number( num ) ); | 86 | writeEntry( key, QString::number( num ) ); |
85 | } | 87 | } |
86 | void Profile::writeEntry( const QString& key, bool b ) { | 88 | void Profile::writeEntry( const QString& key, bool b ) { |
87 | writeEntry( key, QString::number(b) ); | 89 | writeEntry( key, QString::number(b) ); |
88 | } | 90 | } |
89 | void Profile::writeEntry( const QString& key, const QStringList& lis, const QChar& sep ) { | 91 | void 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 | } |
92 | QString Profile::readEntry( const QString& key, const QString& deflt )const { | 94 | QString 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 @@ | |||
1 | TEMPLATE = app | ||
2 | #CONFIG = qt warn_on release | ||
3 | CONFIG = qt debug | ||
4 | #DESTDIR = $(OPIEDIR)/bin | ||
5 | HEADERS = ../io_layer.h ../io_serial.h \ | ||
6 | senderui.h ../profile.h | ||
7 | SOURCES = ../io_layer.cpp ../io_serial.cpp \ | ||
8 | ../profile.cpp \ | ||
9 | main.cpp senderui.cpp | ||
10 | INTERFACES = sender.ui | ||
11 | INCLUDEPATH += $(OPIEDIR)/include | ||
12 | DEPENDPATH += $(OPIEDIR)/include | ||
13 | LIBS += -lqpe -lopie | ||
14 | TARGET = 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 | |||
6 | int main( int argc, char* argv[] ){ | ||
7 | QPEApplication app(argc,argv ); | ||
8 | |||
9 | SenderUI ui; | ||
10 | app.showMainWidget(&ui); | ||
11 | |||
12 | return 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>&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 | |||
12 | SenderUI::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 | } | ||
34 | SenderUI::~SenderUI() { | ||
35 | |||
36 | } | ||
37 | void SenderUI::slotSend() { | ||
38 | QCString str = MultiLineEdit1->text().utf8(); | ||
39 | qWarning("sending: %s", str.data() ); | ||
40 | ser->send( str ); | ||
41 | } | ||
42 | void 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 | |||
8 | class IOSerial; | ||
9 | class SenderUI : public Sender { | ||
10 | Q_OBJECT | ||
11 | public: | ||
12 | SenderUI(); | ||
13 | ~SenderUI(); | ||
14 | |||
15 | public slots: | ||
16 | void slotSend(); | ||
17 | void got(const QByteArray& ); | ||
18 | private: | ||
19 | IOSerial* ser; | ||
20 | }; | ||
21 | |||
22 | |||
23 | #endif | ||