summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib/device.cc
Unidiff
Diffstat (limited to 'noncore/net/opietooth/lib/device.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/device.cc108
1 files changed, 52 insertions, 56 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc
index 40acbd2..2f04d46 100644
--- a/noncore/net/opietooth/lib/device.cc
+++ b/noncore/net/opietooth/lib/device.cc
@@ -16,33 +16,31 @@ using namespace OpieTooth;
16 16
17using Opie::Core::OProcess; 17using Opie::Core::OProcess;
18namespace { 18namespace {
19 int parsePid( const QCString& par ) 19 int parsePid( const QCString& par )
20 { 20 {
21 int id=0; 21 int id = 0;
22 QString string( par ); 22 QString string( par );
23 QStringList list = QStringList::split( '\n', string ); 23 QStringList list = QStringList::split( '\n', string );
24 24
25 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 25 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
26 { 26 owarn << "parsePID: " << (*it).latin1() << oendl;
27 owarn << "parsePID: " << (*it).latin1() << oendl;
28 27
29 // FIXME mbhaynie: Surely there is a better way to skip 28 // FIXME mbhaynie: Surely there is a better way to skip
30 // verbosity (E.g. the TI device configuration 29 // verbosity (E.g. the TI device configuration
31 // script). Apparently the PID is always on a line by 30 // script). Apparently the PID is always on a line by
32 // itself, or is at least the first word of a line. Does 31 // itself, or is at least the first word of a line. Does
33 // QString have somethine like startsWithRegex("[0-9]+")? 32 // QString have somethine like startsWithRegex("[0-9]+")?
34 if( (*it).startsWith("#") ) continue; 33 if( (*it).startsWith("#") ) continue;
35 if( (*it).startsWith("TI") ) continue; 34 if( (*it).startsWith("TI") ) continue;
36 if( (*it).startsWith("Loading") ) continue; 35 if( (*it).startsWith("Loading") ) continue;
37 if( (*it).startsWith("BTS") ) continue; 36 if( (*it).startsWith("BTS") ) continue;
38 if( !(*it).startsWith("CSR") ) 37 if( !(*it).startsWith("CSR") ) {
39 { 38 id = (*it).toInt();
40 id = (*it).toInt(); 39 break;
41 break; 40 }
42 }
43 }
44 return id;
45 } 41 }
42 return id;
43 }
46} 44}
47 45
48Device::Device(const QString &device, const QString &mode, const QString &speed ) 46Device::Device(const QString &device, const QString &mode, const QString &speed )
@@ -75,13 +73,9 @@ void Device::attach(){
75 73
76 // FIXME -- this is a hack for an odd hciattach interface. 74 // FIXME -- this is a hack for an odd hciattach interface.
77 if ( ODevice::inst()->modelString() == "HX4700" ) 75 if ( ODevice::inst()->modelString() == "HX4700" )
78 { 76 *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas";
79 *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas";
80 }
81 else 77 else
82 { 78 *m_process << m_device << m_mode << m_speed;
83 *m_process << m_device << m_mode << m_speed;
84 }
85 connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), 79 connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ),
86 this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); 80 this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
87 connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), 81 connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ),
@@ -93,16 +87,18 @@ void Device::attach(){
93 delete m_process; 87 delete m_process;
94 m_process = 0; 88 m_process = 0;
95 } 89 }
96 }; 90 }
97} 91}
98void Device::detach(){ 92void Device::detach(){
99 delete m_hci; 93 delete m_hci;
94 m_hci = 0;
100 delete m_process; 95 delete m_process;
96 m_process = 0;
101 // kill the pid we got 97 // kill the pid we got
102 if(m_attached ){ 98 if(m_attached ){
103 //kill the pid 99 //kill the pid
104 owarn << "killing" << oendl; 100 owarn << "killing" << oendl;
105 kill(pid, 9); 101 ::kill(pid, 9);
106 } 102 }
107 owarn << "detached" << oendl; 103 owarn << "detached" << oendl;
108} 104}
@@ -121,27 +117,27 @@ void Device::slotExited( OProcess* proc)
121 owarn << "normalExit" << oendl; 117 owarn << "normalExit" << oendl;
122 int ret = m_process->exitStatus(); 118 int ret = m_process->exitStatus();
123 if( ret == 0 ){ // attached 119 if( ret == 0 ){ // attached
124 owarn << "attached" << oendl; 120 owarn << "attached" << oendl;
125 owarn << "Output: " << m_output.data() << oendl; 121 owarn << "Output: " << m_output.data() << oendl;
126 pid = parsePid( m_output ); 122 pid = parsePid( m_output );
127 owarn << "Pid = " << pid << oendl; 123 owarn << "Pid = " << pid << oendl;
128 // now hciconfig hci0 up ( determine hciX FIXME) 124 // now hciconfig hci0 up ( determine hciX FIXME)
129 // and call hciconfig hci0 up 125 // and call hciconfig hci0 up
130 // FIXME hardcoded to hci0 now :( 126 // FIXME hardcoded to hci0 now :(
131 m_hci = new OProcess( ); 127 m_hci = new OProcess( );
132 *m_hci << "hciconfig"; 128 *m_hci << "hciconfig";
133 *m_hci << "hci0 up"; 129 *m_hci << "hci0 up";
134 connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), 130 connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ),
135 this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); 131 this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
136 if(!m_hci->start() ){ 132 if(!m_hci->start() ){
137 owarn << "could not start" << oendl; 133 owarn << "could not start" << oendl;
138 m_attached = false; 134 m_attached = false;
139 emit device("hci0", false ); 135 emit device("hci0", false );
140 } 136 }
141 }else{ 137 }else{
142 owarn << "crass" << oendl; 138 owarn << "crass" << oendl;
143 m_attached = false; 139 m_attached = false;
144 emit device("hci0", false ); 140 emit device("hci0", false );
145 141
146 } 142 }
147 } 143 }
@@ -153,13 +149,13 @@ void Device::slotExited( OProcess* proc)
153 owarn << "normal exit" << oendl; 149 owarn << "normal exit" << oendl;
154 int ret = m_hci->exitStatus(); 150 int ret = m_hci->exitStatus();
155 if( ret == 0 ){ 151 if( ret == 0 ){
156 owarn << "attached really really attached" << oendl; 152 owarn << "attached really really attached" << oendl;
157 m_attached = true; 153 m_attached = true;
158 emit device("hci0", true ); 154 emit device("hci0", true );
159 }else{ 155 }else{
160 owarn << "failed" << oendl; 156 owarn << "failed" << oendl;
161 emit device("hci0", false ); 157 emit device("hci0", false );
162 m_attached = false; 158 m_attached = false;
163 } 159 }
164 }// normal exit 160 }// normal exit
165 delete m_hci; 161 delete m_hci;