summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-09 14:25:38 (UTC)
committer zecke <zecke>2002-10-09 14:25:38 (UTC)
commitf9f2d227b3cfbc2187b4f7f535fc59f9735798d0 (patch) (unidiff)
tree7645623f7dde640222fab3e5ff0af0af3ae2f882
parentff0caad7ea46d19f7a7916047fd0914f6f100dde (diff)
downloadopie-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
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
@@ -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}
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
@@ -75,15 +75,17 @@ void Profile::setTerminal( int 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 ) {
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