summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/btconfigwidget.cpp45
-rw-r--r--noncore/apps/opie-console/btconfigwidget.h6
-rw-r--r--noncore/apps/opie-console/io_bt.cpp38
-rw-r--r--noncore/apps/opie-console/io_serial.cpp1
4 files changed, 71 insertions, 19 deletions
diff --git a/noncore/apps/opie-console/btconfigwidget.cpp b/noncore/apps/opie-console/btconfigwidget.cpp
index 7673d0b..6246f92 100644
--- a/noncore/apps/opie-console/btconfigwidget.cpp
+++ b/noncore/apps/opie-console/btconfigwidget.cpp
@@ -1,157 +1,188 @@
1#include <qlabel.h> 1#include <qlabel.h>
2#include <qlayout.h> 2#include <qlayout.h>
3#include <qlineedit.h> 3#include <qlineedit.h>
4#include <qcombobox.h> 4#include <qcombobox.h>
5#include <qhbox.h>
6#include <qradiobutton.h>
5 7
6#include "iolayerbase.h" 8#include "iolayerbase.h"
7#include "btconfigwidget.h" 9#include "btconfigwidget.h"
8 10
9namespace { 11namespace {
10 void setCurrent( const QString& str, QComboBox* bo ) { 12 void setCurrent( const QString& str, QComboBox* bo ) {
11 uint b = bo->count(); 13 uint b = bo->count();
12 for (uint i = 0; i < bo->count(); i++ ) { 14 for (uint i = 0; i < bo->count(); i++ ) {
13 if ( bo->text(i) == str ) { 15 if ( bo->text(i) == str ) {
14 bo->setCurrentItem( i ); 16 bo->setCurrentItem( i );
15 return; 17 return;
16 } 18 }
17 } 19 }
18 bo->insertItem( str ); 20 bo->insertItem( str );
19 bo->setCurrentItem( b ); 21 bo->setCurrentItem( b );
20 } 22 }
21} 23}
22 24
23BTConfigWidget::BTConfigWidget( const QString& name, 25BTConfigWidget::BTConfigWidget( const QString& name,
24 QWidget* parent, 26 QWidget* parent,
25 const char* na ) 27 const char* na )
26 : ProfileDialogConnectionWidget( name, parent, na ) { 28 : ProfileDialogConnectionWidget( name, parent, na ) {
27 29
28 m_lay = new QVBoxLayout(this ); 30 m_lay = new QVBoxLayout( this );
29 m_device = new QLabel(tr("Device"), this ); 31
30 m_deviceCmb = new QComboBox(this ); 32 m_device = new QLabel( tr( "Device" ), this );
33 QHBox *deviceBox = new QHBox( this );
34 m_devRadio = new QRadioButton( deviceBox );
35 connect( m_devRadio, SIGNAL( toggled( bool ) ), this, SLOT( slotDevRadio( bool ) ) );
36 m_deviceCmb = new QComboBox( deviceBox );
31 m_deviceCmb->setEditable( TRUE ); 37 m_deviceCmb->setEditable( TRUE );
32 38
33 QLabel *macLabel = new QLabel( this ); 39 QLabel *macLabel = new QLabel( this );
34 macLabel->setText( tr("Enter peer mac address here:") ); 40 macLabel->setText( tr( "Or peer mac address" ) );
35 m_mac = new QLineEdit( this ); 41 QHBox *macBox = new QHBox( this );
42 m_macRadio = new QRadioButton( macBox );
43 connect( m_macRadio, SIGNAL( toggled( bool ) ), this, SLOT( slotMacRadio( bool ) ) );
44 m_mac = new QLineEdit( macBox );
36 45
37 m_base = new IOLayerBase(this, "base"); 46 m_base = new IOLayerBase(this, "base");
38 47
39 m_lay->addWidget( m_device ); 48 m_lay->addWidget( m_device );
40 m_lay->addWidget( m_deviceCmb ); 49 m_lay->addWidget( deviceBox );
41 m_lay->addWidget( macLabel ); 50 m_lay->addWidget( macLabel );
42 m_lay->addWidget( m_mac ); 51 m_lay->addWidget( macBox );
43 m_lay->addWidget( m_base ); 52 m_lay->addWidget( m_base );
44 53
45 m_deviceCmb->insertItem( "/dev/ttyU0" ); 54 m_deviceCmb->insertItem( "/dev/ttyU0" );
46 m_deviceCmb->insertItem( "/dev/ttyU1" ); 55 m_deviceCmb->insertItem( "/dev/ttyU1" );
47} 56}
48 57
49BTConfigWidget::~BTConfigWidget() { 58BTConfigWidget::~BTConfigWidget() {
50 59
51} 60}
52void BTConfigWidget::load( const Profile& prof ) { 61void BTConfigWidget::load( const Profile& prof ) {
53 int rad_flow = prof.readNumEntry("Flow"); 62 int rad_flow = prof.readNumEntry("Flow");
54 int rad_parity = prof.readNumEntry("Parity"); 63 int rad_parity = prof.readNumEntry("Parity");
55 int speed = prof.readNumEntry("Speed"); 64 int speed = prof.readNumEntry("Speed");
56 QString mac = prof.readEntry("Mac"); 65 QString mac = prof.readEntry("Mac");
57 66
58 if (!mac.isEmpty() ) { 67 if (!mac.isEmpty() ) {
59 m_mac->setText( mac ); 68 m_mac->setText( mac );
69 } else {
70 m_devRadio->setChecked( true );
60 } 71 }
61 72
62 if (rad_flow == 1) { 73 if (rad_flow == 1) {
63 m_base->setFlow( IOLayerBase::Hardware ); 74 m_base->setFlow( IOLayerBase::Hardware );
64 } else if (rad_flow == 2) { 75 } else if (rad_flow == 2) {
65 m_base->setFlow( IOLayerBase::Software ); 76 m_base->setFlow( IOLayerBase::Software );
66 } else if (rad_flow == 0) { 77 } else if (rad_flow == 0) {
67 m_base->setFlow( IOLayerBase::None ); 78 m_base->setFlow( IOLayerBase::None );
68 } 79 }
69 80
70 if (rad_parity == 1) { 81 if (rad_parity == 1) {
71 m_base->setParity( IOLayerBase::Even ); 82 m_base->setParity( IOLayerBase::Even );
72 } else if ( rad_parity == 2 ) { 83 } else if ( rad_parity == 2 ) {
73 m_base->setParity( IOLayerBase::Odd ); 84 m_base->setParity( IOLayerBase::Odd );
74 } else { 85 } else {
75 m_base->setParity( IOLayerBase::NonePar ); 86 m_base->setParity( IOLayerBase::NonePar );
76 } 87 }
77 88
78 switch( speed ) { 89 switch( speed ) {
79 case 115200: 90 case 115200:
80 m_base->setSpeed(IOLayerBase::Baud_115200 ); 91 m_base->setSpeed(IOLayerBase::Baud_115200 );
81 break; 92 break;
82 case 57600: 93 case 57600:
83 m_base->setSpeed( IOLayerBase::Baud_57600 ); 94 m_base->setSpeed( IOLayerBase::Baud_57600 );
84 break; 95 break;
85 case 38400: 96 case 38400:
86 m_base->setSpeed(IOLayerBase::Baud_38400 ); 97 m_base->setSpeed(IOLayerBase::Baud_38400 );
87 break; 98 break;
88 case 19200: 99 case 19200:
89 m_base->setSpeed( IOLayerBase::Baud_19200 ); 100 m_base->setSpeed( IOLayerBase::Baud_19200 );
90 break; 101 break;
91 case 9600: 102 case 9600:
92 default: 103 default:
93 m_base->setSpeed(IOLayerBase::Baud_9600 ); 104 m_base->setSpeed(IOLayerBase::Baud_9600 );
94 break; 105 break;
95 } 106 }
96 107
97 if ( prof.readEntry("Device").isEmpty() ) return; 108 if ( prof.readEntry("Device").isEmpty() ) return;
98 setCurrent( prof.readEntry("Device"), m_deviceCmb ); 109 setCurrent( prof.readEntry("Device"), m_deviceCmb );
99 110
100} 111}
101/* 112/*
102 * save speed, 113 * save speed,
103 * flow, 114 * flow,
104 * parity 115 * parity
105 */ 116 */
106void BTConfigWidget::save( Profile& prof ) { 117void BTConfigWidget::save( Profile& prof ) {
107 int flow, parity, speed; 118 int flow, parity, speed;
108 prof.writeEntry("Device", m_deviceCmb->currentText() ); 119 prof.writeEntry("Device", m_deviceCmb->currentText() );
109 120
110 121
111 switch( m_base->flow() ) { 122 switch( m_base->flow() ) {
112 case IOLayerBase::None: 123 case IOLayerBase::None:
113 flow = 0; 124 flow = 0;
114 break; 125 break;
115 case IOLayerBase::Software: 126 case IOLayerBase::Software:
116 flow = 2; 127 flow = 2;
117 break; 128 break;
118 case IOLayerBase::Hardware: 129 case IOLayerBase::Hardware:
119 flow = 1; 130 flow = 1;
120 break; 131 break;
121 } 132 }
122 133
123 switch( m_base->parity() ) { 134 switch( m_base->parity() ) {
124 case IOLayerBase::Odd: 135 case IOLayerBase::Odd:
125 parity = 2; 136 parity = 2;
126 break; 137 break;
127 case IOLayerBase::Even: 138 case IOLayerBase::Even:
128 parity = 1; 139 parity = 1;
129 break; 140 break;
130 case IOLayerBase::NonePar: 141 case IOLayerBase::NonePar:
131 parity = 0; 142 parity = 0;
132 break; 143 break;
133 } 144 }
134 145
135 switch( m_base->speed() ) { 146 switch( m_base->speed() ) {
136 case IOLayerBase::Baud_115200: 147 case IOLayerBase::Baud_115200:
137 speed = 115200; 148 speed = 115200;
138 break; 149 break;
139 case IOLayerBase::Baud_57600: 150 case IOLayerBase::Baud_57600:
140 speed = 57600; 151 speed = 57600;
141 break; 152 break;
142 case IOLayerBase::Baud_38400: 153 case IOLayerBase::Baud_38400:
143 speed = 38400; 154 speed = 38400;
144 break; 155 break;
145 case IOLayerBase::Baud_19200: 156 case IOLayerBase::Baud_19200:
146 speed = 19200; 157 speed = 19200;
147 break; 158 break;
148 case IOLayerBase::Baud_9600: 159 case IOLayerBase::Baud_9600:
149 speed = 9600; 160 speed = 9600;
150 break; 161 break;
151 } 162 }
152 163
153 prof.writeEntry("Flow", flow); 164 prof.writeEntry("Flow", flow);
154 prof.writeEntry("Parity", parity); 165 prof.writeEntry("Parity", parity);
155 prof.writeEntry("Speed", speed); 166 prof.writeEntry("Speed", speed);
156 prof.writeEntry("Mac", m_mac->text() ); 167 prof.writeEntry("Mac", m_mac->text() );
157} 168}
169
170void BTConfigWidget::slotMacRadio( bool on ) {
171 if ( on ) {
172 m_devRadio->setChecked( false );
173 m_deviceCmb->setEnabled( false );
174 m_mac->setEnabled( true );
175 } else {
176 m_devRadio->setChecked( true );
177 }
178}
179
180void BTConfigWidget::slotDevRadio( bool on ) {
181 if ( on ) {
182 m_macRadio->setChecked( false );
183 m_deviceCmb->setEnabled( true );
184 m_mac->setEnabled( false );
185 } else {
186 m_macRadio->setChecked( true );
187 }
188}
diff --git a/noncore/apps/opie-console/btconfigwidget.h b/noncore/apps/opie-console/btconfigwidget.h
index ceb13ee..d60d8a2 100644
--- a/noncore/apps/opie-console/btconfigwidget.h
+++ b/noncore/apps/opie-console/btconfigwidget.h
@@ -1,31 +1,37 @@
1#ifndef OPIE_BT_CONFIG_WIDGET_H 1#ifndef OPIE_BT_CONFIG_WIDGET_H
2#define OPIE_BT_CONFIG_WIDGET_H 2#define OPIE_BT_CONFIG_WIDGET_H
3 3
4#include "profiledialogwidget.h" 4#include "profiledialogwidget.h"
5 5
6class QVBoxLayout; 6class QVBoxLayout;
7class QLabel; 7class QLabel;
8class QComboBox; 8class QComboBox;
9class QLineEdit; 9class QLineEdit;
10class QRadioButton;
10class IOLayerBase; 11class IOLayerBase;
11class BTConfigWidget : public ProfileDialogConnectionWidget { 12class BTConfigWidget : public ProfileDialogConnectionWidget {
12 13
13 Q_OBJECT 14 Q_OBJECT
14 15
15public: 16public:
16 BTConfigWidget( const QString& name, QWidget* parent, const char* name = 0l ); 17 BTConfigWidget( const QString& name, QWidget* parent, const char* name = 0l );
17 ~BTConfigWidget(); 18 ~BTConfigWidget();
18 19
19 void load( const Profile& ); 20 void load( const Profile& );
20 void save( Profile& ); 21 void save( Profile& );
21private: 22private:
22 QVBoxLayout* m_lay; 23 QVBoxLayout* m_lay;
23 QLabel* m_device; 24 QLabel* m_device;
24 QComboBox* m_deviceCmb; 25 QComboBox* m_deviceCmb;
25 IOLayerBase* m_base; 26 IOLayerBase* m_base;
26 QLineEdit* m_mac; 27 QLineEdit* m_mac;
28 QRadioButton *m_macRadio;
29 QRadioButton *m_devRadio;
27 30
31private slots:
32 void slotMacRadio( bool on );
33 void slotDevRadio( bool on );
28}; 34};
29 35
30 36
31#endif 37#endif
diff --git a/noncore/apps/opie-console/io_bt.cpp b/noncore/apps/opie-console/io_bt.cpp
index 0831faf..d71aacc 100644
--- a/noncore/apps/opie-console/io_bt.cpp
+++ b/noncore/apps/opie-console/io_bt.cpp
@@ -1,64 +1,78 @@
1 1
2#include "io_bt.h" 2#include "io_bt.h"
3 3
4IOBt::IOBt( const Profile &config ) : IOSerial( config ) { 4IOBt::IOBt( const Profile &config ) : IOSerial( config ) {
5 m_attach = 0; 5 m_attach = 0;
6} 6}
7 7
8 8
9IOBt::~IOBt() { 9IOBt::~IOBt() {
10 if ( m_attach ) { 10 if ( m_attach ) {
11 delete m_attach; 11 delete m_attach;
12 } 12 }
13} 13}
14 14
15 15
16void IOBt::close() { 16void IOBt::close() {
17 17
18 IOSerial::close(); 18 IOSerial::close();
19 // still need error handling 19 // still need error handling
20 delete m_attach; 20 if ( m_attach ) {
21 delete m_attach;
22 m_attach = 0;
23 }
21} 24}
22 25
23bool IOBt::open() { 26bool IOBt::open() {
24 27
25 // hciattach here 28 // only set up bt stuff if mac address was set, otherwise use the device set
26 m_attach = new OProcess(); 29 if ( !m_mac.isEmpty() ) {
27 *m_attach << "hciattach /dev/ttyS2 any 57600";
28 30
29 // then start hcid, then rcfomm handling (m_mac) 31 // now it should also be checked, if there is a connection to the device with that mac allready
30 32
31 connect( m_attach, SIGNAL( processExited( OProcess* ) ), 33 // hciattach here
32 this, SLOT( slotExited( OProcess* ) ) ); 34 m_attach = new OProcess();
35 *m_attach << "hciattach /dev/ttyS2 any 57600";
33 36
34 if ( m_attach->start() ) { 37 // then start hcid, then rcfomm handling (m_mac)
35 IOSerial::open(); 38
39 connect( m_attach, SIGNAL( processExited( OProcess* ) ),
40 this, SLOT( slotExited( OProcess* ) ) );
41
42 if ( m_attach->start() ) {
43 IOSerial::open();
44 } else {
45 qWarning("could not attach to device");
46 delete m_attach;
47 m_attach = 0;
48 }
36 } else { 49 } else {
37 qWarning("could not attach to device"); 50 // directly to the normal serial
38 delete m_attach; 51 // TODO: look first if the connection really exists. ( is set up )
39 m_attach = 0; 52
53 IOSerial::open();
40 } 54 }
41} 55}
42 56
43void IOBt::reload( const Profile &config ) { 57void IOBt::reload( const Profile &config ) {
44 m_device = config.readEntry("Device", BT_DEFAULT_DEVICE); 58 m_device = config.readEntry("Device", BT_DEFAULT_DEVICE);
45 m_mac = config.readEntry("Mac", BT_DEFAULT_MAC); 59 m_mac = config.readEntry("Mac", BT_DEFAULT_MAC);
46 m_baud = config.readNumEntry("Baud", BT_DEFAULT_BAUD); 60 m_baud = config.readNumEntry("Baud", BT_DEFAULT_BAUD);
47 m_parity = config.readNumEntry("Parity", BT_DEFAULT_PARITY); 61 m_parity = config.readNumEntry("Parity", BT_DEFAULT_PARITY);
48 m_dbits = config.readNumEntry("DataBits", BT_DEFAULT_DBITS); 62 m_dbits = config.readNumEntry("DataBits", BT_DEFAULT_DBITS);
49 m_sbits = config.readNumEntry("StopBits", BT_DEFAULT_SBITS); 63 m_sbits = config.readNumEntry("StopBits", BT_DEFAULT_SBITS);
50 m_flow = config.readNumEntry("Flow", BT_DEFAULT_FLOW); 64 m_flow = config.readNumEntry("Flow", BT_DEFAULT_FLOW);
51} 65}
52 66
53 67
54QString IOBt::identifier() const { 68QString IOBt::identifier() const {
55 return "bluetooth"; 69 return "bluetooth";
56} 70}
57 71
58QString IOBt::name() const { 72QString IOBt::name() const {
59 return "BLuetooth IO Layer"; 73 return "BLuetooth IO Layer";
60} 74}
61 75
62void IOBt::slotExited( OProcess* proc ){ 76void IOBt::slotExited( OProcess* proc ){
63 close(); 77 close();
64} 78}
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index cc63c58..e6d1688 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -1,205 +1,206 @@
1
1#include <fcntl.h> 2#include <fcntl.h>
2#include <termios.h> 3#include <termios.h>
3#include <errno.h> 4#include <errno.h>
4#include <unistd.h> 5#include <unistd.h>
5#include "io_serial.h" 6#include "io_serial.h"
6 7
7IOSerial::IOSerial(const Profile &config) : IOLayer(config) { 8IOSerial::IOSerial(const Profile &config) : IOLayer(config) {
8 m_read = 0l; 9 m_read = 0l;
9 m_error = 0l; 10 m_error = 0l;
10 m_fd = 0; 11 m_fd = 0;
11 m_connected = false; 12 m_connected = false;
12 reload(config); 13 reload(config);
13} 14}
14 15
15 16
16IOSerial::~IOSerial() { 17IOSerial::~IOSerial() {
17 if (m_fd) { 18 if (m_fd) {
18 close(); 19 close();
19 } 20 }
20} 21}
21 22
22void IOSerial::send(const QByteArray &data) { 23void IOSerial::send(const QByteArray &data) {
23 if (m_fd) { 24 if (m_fd) {
24 write(m_fd, data.data(), data.size()); 25 write(m_fd, data.data(), data.size());
25 } else { 26 } else {
26 emit error(Refuse, tr("Not connected")); 27 emit error(Refuse, tr("Not connected"));
27 } 28 }
28} 29}
29 30
30void IOSerial::close() { 31void IOSerial::close() {
31 if (m_fd) { 32 if (m_fd) {
32 delete m_read; 33 delete m_read;
33 delete m_error; 34 delete m_error;
34 ::close(m_fd); 35 ::close(m_fd);
35 m_fd = 0; 36 m_fd = 0;
36 m_connected = false; 37 m_connected = false;
37 } else { 38 } else {
38 m_connected = false; 39 m_connected = false;
39 emit error(Refuse, tr("Not connected")); 40 emit error(Refuse, tr("Not connected"));
40 } 41 }
41} 42}
42 43
43bool IOSerial::open() { 44bool IOSerial::open() {
44 if (!m_fd) { 45 if (!m_fd) {
45 struct termios tty; 46 struct termios tty;
46 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); 47 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
47 if (m_fd < 0) { 48 if (m_fd < 0) {
48 emit error(CouldNotOpen, strerror(errno)); 49 emit error(CouldNotOpen, strerror(errno));
49 m_fd = 0; 50 m_fd = 0;
50 return FALSE; 51 return FALSE;
51 } 52 }
52 tcgetattr(m_fd, &tty); 53 tcgetattr(m_fd, &tty);
53 54
54 /* Baud rate */ 55 /* Baud rate */
55 int speed = baud(m_baud); 56 int speed = baud(m_baud);
56 if (speed == -1) { 57 if (speed == -1) {
57 emit error(Refuse, tr("Invalid baud rate")); 58 emit error(Refuse, tr("Invalid baud rate"));
58 } 59 }
59 cfsetospeed(&tty, speed); 60 cfsetospeed(&tty, speed);
60 cfsetispeed(&tty, speed); 61 cfsetispeed(&tty, speed);
61 62
62 /* Take care of Space / Mark parity */ 63 /* Take care of Space / Mark parity */
63 if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) { 64 if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) {
64 m_dbits = 8; 65 m_dbits = 8;
65 } 66 }
66 67
67 /* Data bits */ 68 /* Data bits */
68 switch (m_dbits) { 69 switch (m_dbits) {
69 case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break; 70 case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break;
70 case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break; 71 case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break;
71 case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break; 72 case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break;
72 case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break; 73 case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break;
73 default: break; 74 default: break;
74 } 75 }
75 76
76 /* Raw, no echo mode */ 77 /* Raw, no echo mode */
77 tty.c_iflag = IGNBRK; 78 tty.c_iflag = IGNBRK;
78 tty.c_lflag = 0; 79 tty.c_lflag = 0;
79 tty.c_oflag = 0; 80 tty.c_oflag = 0;
80 tty.c_cflag |= CLOCAL | CREAD; 81 tty.c_cflag |= CLOCAL | CREAD;
81 82
82 /* Stop bits */ 83 /* Stop bits */
83 if (m_sbits == 2) { 84 if (m_sbits == 2) {
84 tty.c_cflag |= CSTOPB; 85 tty.c_cflag |= CSTOPB;
85 } else { 86 } else {
86 tty.c_cflag &= ~CSTOPB; 87 tty.c_cflag &= ~CSTOPB;
87 } 88 }
88 89
89 tty.c_cc[VMIN] = 1; 90 tty.c_cc[VMIN] = 1;
90 tty.c_cc[VTIME] = 5; 91 tty.c_cc[VTIME] = 5;
91 92
92 /* Flow control */ 93 /* Flow control */
93 if (m_flow & FlowSW) 94 if (m_flow & FlowSW)
94 tty.c_iflag |= IXON | IXOFF; 95 tty.c_iflag |= IXON | IXOFF;
95 else 96 else
96 tty.c_iflag &= ~(IXON|IXOFF|IXANY); 97 tty.c_iflag &= ~(IXON|IXOFF|IXANY);
97 98
98 if (m_flow & FlowHW) 99 if (m_flow & FlowHW)
99 tty.c_cflag |= CRTSCTS; 100 tty.c_cflag |= CRTSCTS;
100 else 101 else
101 tty.c_cflag &= ~CRTSCTS; 102 tty.c_cflag &= ~CRTSCTS;
102 103
103 /* Parity */ 104 /* Parity */
104 tty.c_cflag &= ~(PARENB | PARODD); 105 tty.c_cflag &= ~(PARENB | PARODD);
105 if (m_parity & ParityEven) 106 if (m_parity & ParityEven)
106 tty.c_cflag |= PARENB; 107 tty.c_cflag |= PARENB;
107 else if (m_parity & ParityOdd) 108 else if (m_parity & ParityOdd)
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 m_connected = false; 119 m_connected = false;
119 return TRUE; 120 return TRUE;
120 } else { 121 } else {
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 m_baud = config.readNumEntry("Speed", SERIAL_DEFAULT_BAUD); 130 m_baud = config.readNumEntry("Speed", SERIAL_DEFAULT_BAUD);
130 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); 131 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY);
131 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); 132 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS);
132 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); 133 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS);
133 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); 134 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW);
134 135
135} 136}
136 137
137int IOSerial::baud(int baud) const { 138int IOSerial::baud(int baud) const {
138 switch (baud) { 139 switch (baud) {
139 case 300: return B300; break; 140 case 300: return B300; break;
140 case 600: return B600; break; 141 case 600: return B600; break;
141 case 1200: return B1200; break; 142 case 1200: return B1200; break;
142 case 2400: return B2400; break; 143 case 2400: return B2400; break;
143 case 4800: return B4800; break; 144 case 4800: return B4800; break;
144 case 9600: return B9600; break; 145 case 9600: return B9600; break;
145 case 19200: return B19200; break; 146 case 19200: return B19200; break;
146 case 38400: return B38400; break; 147 case 38400: return B38400; break;
147 case 57600: return B57600; break; 148 case 57600: return B57600; break;
148 case 115200: return B115200; break; 149 case 115200: return B115200; break;
149 } 150 }
150 return -1; 151 return -1;
151} 152}
152 153
153void IOSerial::errorOccured() { 154void IOSerial::errorOccured() {
154 emit error(ClosedUnexpected, strerror(errno)); 155 emit error(ClosedUnexpected, strerror(errno));
155 close(); 156 close();
156} 157}
157 158
158void IOSerial::dataArrived() { 159void IOSerial::dataArrived() {
159 QByteArray array(4097); 160 QByteArray array(4097);
160 161
161 int len = read(m_fd, array.data(), 4096); 162 int len = read(m_fd, array.data(), 4096);
162 if (len == 0) 163 if (len == 0)
163 close(); 164 close();
164 if (len < 0) 165 if (len < 0)
165 return; 166 return;
166 array.resize( len ); 167 array.resize( len );
167 emit received(array); 168 emit received(array);
168} 169}
169 170
170QString IOSerial::identifier() const { 171QString IOSerial::identifier() const {
171 return "serial"; 172 return "serial";
172} 173}
173 174
174QString IOSerial::name() const { 175QString IOSerial::name() const {
175 return "RS232 Serial IO Layer"; 176 return "RS232 Serial IO Layer";
176} 177}
177int IOSerial::rawIO()const { 178int IOSerial::rawIO()const {
178 if (m_read ) 179 if (m_read )
179 disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 180 disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
180 if (m_error ) 181 if (m_error )
181 disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 182 disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
182 183
183 int fd = ::open(m_device, O_RDWR ); 184 int fd = ::open(m_device, O_RDWR );
184 185
185 return fd; 186 return fd;
186}; 187};
187void IOSerial::closeRawIO(int fd) { 188void IOSerial::closeRawIO(int fd) {
188 if (m_read ) 189 if (m_read )
189 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 190 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
190 if (m_error ) 191 if (m_error )
191 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 192 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
192 193
193 ::close( fd ); 194 ::close( fd );
194} 195}
195QBitArray IOSerial::supports()const { 196QBitArray IOSerial::supports()const {
196 QBitArray ar(3); 197 QBitArray ar(3);
197 ar[0] = ar[2] = 0; 198 ar[0] = ar[2] = 0;
198 ar[1] = 1; 199 ar[1] = 1;
199 200
200 return ar; 201 return ar;
201} 202}
202 203
203bool IOSerial::isConnected() { 204bool IOSerial::isConnected() {
204 return m_connected; 205 return m_connected;
205} 206}