summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-08-21 22:32:50 (UTC)
committer mickeyl <mickeyl>2005-08-21 22:32:50 (UTC)
commit140e4dc44a29678de1ae8b2cef5b1d081993223e (patch) (unidiff)
tree70b0875f779f6a4a327e583207664f4396ecc141
parent4def5629dc68465b1dc8bb23c115e2f5f7513804 (diff)
downloadopie-140e4dc44a29678de1ae8b2cef5b1d081993223e.zip
opie-140e4dc44a29678de1ae8b2cef5b1d081993223e.tar.gz
opie-140e4dc44a29678de1ae8b2cef5b1d081993223e.tar.bz2
Add support for some unusual requirements of the iPAQ hx4700 BT interface.
Patch courtesy Michael Haynie - thanks!
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/device.cc55
1 files changed, 42 insertions, 13 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc
index eea1178..40acbd2 100644
--- a/noncore/net/opietooth/lib/device.cc
+++ b/noncore/net/opietooth/lib/device.cc
@@ -1,151 +1,180 @@
1 1
2#include "device.h" 2#include "device.h"
3 3
4/* OPIE */ 4/* OPIE */
5#include <opie2/oprocess.h> 5#include <opie2/oprocess.h>
6#include <opie2/odebug.h> 6#include <opie2/odebug.h>
7#include <opie2/odevice.h>
8
7using namespace Opie::Core; 9using namespace Opie::Core;
8 10
9/* STD */ 11/* STD */
10#include <signal.h> 12#include <signal.h>
11 13
12 14
13using namespace OpieTooth; 15using namespace OpieTooth;
14 16
15using Opie::Core::OProcess; 17using Opie::Core::OProcess;
16namespace { 18namespace {
17 int parsePid( const QCString& par ){ 19 int parsePid( const QCString& par )
18 int id=0; 20 {
19 QString string( par ); 21 int id=0;
20 QStringList list = QStringList::split( '\n', string ); 22 QString string( par );
21 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ 23 QStringList list = QStringList::split( '\n', string );
22 owarn << "parsePID: " << (*it).latin1() << oendl; 24
23 if( !(*it).startsWith("CSR") ){ 25 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
24 id = (*it).toInt(); 26 {
25 break; 27 owarn << "parsePID: " << (*it).latin1() << oendl;
26 } 28
29 // FIXME mbhaynie: Surely there is a better way to skip
30 // verbosity (E.g. the TI device configuration
31 // script). Apparently the PID is always on a line by
32 // itself, or is at least the first word of a line. Does
33 // QString have somethine like startsWithRegex("[0-9]+")?
34 if( (*it).startsWith("#") ) continue;
35 if( (*it).startsWith("TI") ) continue;
36 if( (*it).startsWith("Loading") ) continue;
37 if( (*it).startsWith("BTS") ) continue;
38 if( !(*it).startsWith("CSR") )
39 {
40 id = (*it).toInt();
41 break;
42 }
43 }
44 return id;
27 } 45 }
28 return id;
29 }
30} 46}
31 47
32Device::Device(const QString &device, const QString &mode, const QString &speed ) 48Device::Device(const QString &device, const QString &mode, const QString &speed )
33 : QObject(0, "device") { 49 : QObject(0, "device") {
34 50
35 owarn << "OpieTooth::Device create" << oendl; 51 owarn << "OpieTooth::Device create" << oendl;
36 m_hci = 0; 52 m_hci = 0;
37 m_process = 0; 53 m_process = 0;
38 m_attached = false; 54 m_attached = false;
39 m_device = device; 55 m_device = device;
40 m_mode = mode; 56 m_mode = mode;
41 m_speed = speed; 57 m_speed = speed;
42 attach(); 58 attach();
43} 59}
44Device::~Device(){ 60Device::~Device(){
45 detach(); 61 detach();
46} 62}
63
64// FIXME mbhaynie -- If BT is active, and opie is restarted, this
65// applet thinks bt is down, and will fail to start it again. Not
66// sure why.
47void Device::attach(){ 67void Device::attach(){
48 owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; 68 owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl;
49 if(m_process == 0 ){ 69 if(m_process == 0 ){
50 m_output.resize(0); 70 m_output.resize(0);
51 owarn << "new process to create" << oendl; 71 owarn << "new process to create" << oendl;
52 m_process = new OProcess(); 72 m_process = new OProcess();
53 *m_process << "hciattach"; 73 *m_process << "hciattach";
54 *m_process << "-p"; 74 *m_process << "-p";
55 *m_process << m_device << m_mode << m_speed; 75
76 // FIXME -- this is a hack for an odd hciattach interface.
77 if ( ODevice::inst()->modelString() == "HX4700" )
78 {
79 *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas";
80 }
81 else
82 {
83 *m_process << m_device << m_mode << m_speed;
84 }
56 connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), 85 connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ),
57 this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); 86 this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
58 connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), 87 connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ),
59 this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); 88 this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) );
60 connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), 89 connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ),
61 this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); 90 this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) );
62 if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ 91 if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){
63 owarn << "Could not start" << oendl; 92 owarn << "Could not start" << oendl;
64 delete m_process; 93 delete m_process;
65 m_process = 0; 94 m_process = 0;
66 } 95 }
67 }; 96 };
68} 97}
69void Device::detach(){ 98void Device::detach(){
70 delete m_hci; 99 delete m_hci;
71 delete m_process; 100 delete m_process;
72 // kill the pid we got 101 // kill the pid we got
73 if(m_attached ){ 102 if(m_attached ){
74 //kill the pid 103 //kill the pid
75 owarn << "killing" << oendl; 104 owarn << "killing" << oendl;
76 kill(pid, 9); 105 kill(pid, 9);
77 } 106 }
78 owarn << "detached" << oendl; 107 owarn << "detached" << oendl;
79} 108}
80bool Device::isLoaded()const{ 109bool Device::isLoaded()const{
81 return m_attached; 110 return m_attached;
82} 111}
83QString Device::devName()const { 112QString Device::devName()const {
84 return QString::fromLatin1("hci0"); 113 return QString::fromLatin1("hci0");
85}; 114};
86void Device::slotExited( OProcess* proc) 115void Device::slotExited( OProcess* proc)
87{ 116{
88 owarn << "prcess exited" << oendl; 117 owarn << "prcess exited" << oendl;
89 if(proc== m_process ){ 118 if(proc== m_process ){
90 owarn << "proc == m_process" << oendl; 119 owarn << "proc == m_process" << oendl;
91 if( m_process->normalExit() ){ // normal exit 120 if( m_process->normalExit() ){ // normal exit
92 owarn << "normalExit" << oendl; 121 owarn << "normalExit" << oendl;
93 int ret = m_process->exitStatus(); 122 int ret = m_process->exitStatus();
94 if( ret == 0 ){ // attached 123 if( ret == 0 ){ // attached
95 owarn << "attached" << oendl; 124 owarn << "attached" << oendl;
96 owarn << "Output: " << m_output.data() << oendl; 125 owarn << "Output: " << m_output.data() << oendl;
97 pid = parsePid( m_output ); 126 pid = parsePid( m_output );
98 owarn << "Pid = " << pid << oendl; 127 owarn << "Pid = " << pid << oendl;
99 // now hciconfig hci0 up ( determine hciX FIXME) 128 // now hciconfig hci0 up ( determine hciX FIXME)
100 // and call hciconfig hci0 up 129 // and call hciconfig hci0 up
101 // FIXME hardcoded to hci0 now :( 130 // FIXME hardcoded to hci0 now :(
102 m_hci = new OProcess( ); 131 m_hci = new OProcess( );
103 *m_hci << "hciconfig"; 132 *m_hci << "hciconfig";
104 *m_hci << "hci0 up"; 133 *m_hci << "hci0 up";
105 connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), 134 connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ),
106 this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); 135 this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
107 if(!m_hci->start() ){ 136 if(!m_hci->start() ){
108 owarn << "could not start" << oendl; 137 owarn << "could not start" << oendl;
109 m_attached = false; 138 m_attached = false;
110 emit device("hci0", false ); 139 emit device("hci0", false );
111 } 140 }
112 }else{ 141 }else{
113 owarn << "crass" << oendl; 142 owarn << "crass" << oendl;
114 m_attached = false; 143 m_attached = false;
115 emit device("hci0", false ); 144 emit device("hci0", false );
116 145
117 } 146 }
118 } 147 }
119 delete m_process; 148 delete m_process;
120 m_process = 0; 149 m_process = 0;
121 }else if(proc== m_hci ){ 150 }else if(proc== m_hci ){
122 owarn << "M HCI exited" << oendl; 151 owarn << "M HCI exited" << oendl;
123 if( m_hci->normalExit() ){ 152 if( m_hci->normalExit() ){
124 owarn << "normal exit" << oendl; 153 owarn << "normal exit" << oendl;
125 int ret = m_hci->exitStatus(); 154 int ret = m_hci->exitStatus();
126 if( ret == 0 ){ 155 if( ret == 0 ){
127 owarn << "attached really really attached" << oendl; 156 owarn << "attached really really attached" << oendl;
128 m_attached = true; 157 m_attached = true;
129 emit device("hci0", true ); 158 emit device("hci0", true );
130 }else{ 159 }else{
131 owarn << "failed" << oendl; 160 owarn << "failed" << oendl;
132 emit device("hci0", false ); 161 emit device("hci0", false );
133 m_attached = false; 162 m_attached = false;
134 } 163 }
135 }// normal exit 164 }// normal exit
136 delete m_hci; 165 delete m_hci;
137 m_hci = 0; 166 m_hci = 0;
138 } 167 }
139} 168}
140void Device::slotStdOut(OProcess* proc, char* chars, int len) 169void Device::slotStdOut(OProcess* proc, char* chars, int len)
141{ 170{
142 owarn << "std out" << oendl; 171 owarn << "std out" << oendl;
143 if( len <1 ){ 172 if( len <1 ){
144 owarn << "len < 1 " << oendl; 173 owarn << "len < 1 " << oendl;
145 return; 174 return;
146 } 175 }
147 if(proc == m_process ){ 176 if(proc == m_process ){
148 QCString string( chars, len+1 ); // \0 == +1 177 QCString string( chars, len+1 ); // \0 == +1
149 owarn << "output: " << string.data() << oendl; 178 owarn << "output: " << string.data() << oendl;
150 m_output.append( string.data() ); 179 m_output.append( string.data() );
151 } 180 }