-rw-r--r-- | noncore/unsupported/gsmtool/gsmtool.cpp | 18 | ||||
-rw-r--r-- | noncore/unsupported/gsmtool/gsmtool.h | 1 |
2 files changed, 7 insertions, 12 deletions
diff --git a/noncore/unsupported/gsmtool/gsmtool.cpp b/noncore/unsupported/gsmtool/gsmtool.cpp index 14ef368..38c8c59 100644 --- a/noncore/unsupported/gsmtool/gsmtool.cpp +++ b/noncore/unsupported/gsmtool/gsmtool.cpp | |||
@@ -1,208 +1,204 @@ | |||
1 | #include "gsmtool.h" | 1 | #include "gsmtool.h" |
2 | #include <qpushbutton.h> | 2 | #include <qpushbutton.h> |
3 | #include <qcombobox.h> | 3 | #include <qcombobox.h> |
4 | #include <qlineedit.h> | 4 | #include <qlineedit.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qtabwidget.h> | 6 | #include <qtabwidget.h> |
7 | 7 | ||
8 | #include <termios.h> | 8 | #include <termios.h> |
9 | 9 | ||
10 | #include <gsmlib/gsm_me_ta.h> | 10 | #include <gsmlib/gsm_me_ta.h> |
11 | #include <gsmlib/gsm_unix_serial.h> | 11 | #include <gsmlib/gsm_unix_serial.h> |
12 | 12 | ||
13 | using namespace gsmlib; | 13 | using namespace gsmlib; |
14 | 14 | ||
15 | 15 | ||
16 | /* | 16 | /* |
17 | * Constructs a GSMTool which is a child of 'parent', with the | 17 | * Constructs a GSMTool which is a child of 'parent', with the |
18 | * name 'name' and widget flags set to 'f' | 18 | * name 'name' and widget flags set to 'f' |
19 | */ | 19 | */ |
20 | GSMTool::GSMTool( QWidget* parent, const char* name, WFlags fl ) | 20 | GSMTool::GSMTool( QWidget* parent, const char* name, WFlags fl ) |
21 | : GSMToolBase( parent, name, fl ) | 21 | : GSMToolBase( parent, name, fl ) |
22 | { | 22 | { |
23 | devicelocked = 0; | 23 | devicelocked = 0; |
24 | me = NULL; | 24 | me = NULL; |
25 | port = NULL; | ||
26 | setConnected(FALSE); | 25 | setConnected(FALSE); |
27 | /* FIXME: Persistent settings for device/baudrate */ | 26 | /* FIXME: Persistent settings for device/baudrate */ |
28 | connect(ConnectButton, SIGNAL(clicked()), this, SLOT(doConnectButton())); | 27 | connect(ConnectButton, SIGNAL(clicked()), this, SLOT(doConnectButton())); |
29 | connect(ScanButton, SIGNAL(clicked()), this, SLOT(doScanButton())); | 28 | connect(ScanButton, SIGNAL(clicked()), this, SLOT(doScanButton())); |
30 | connect(TabWidget2, SIGNAL(currentChanged(QWidget *)), this, SLOT(doTabChanged())); | 29 | connect(TabWidget2, SIGNAL(currentChanged(QWidget *)), this, SLOT(doTabChanged())); |
31 | timerid = -1; // Is this not possible normally? | 30 | timerid = -1; // Is this not possible normally? |
32 | } | 31 | } |
33 | 32 | ||
34 | /* | 33 | /* |
35 | * Destroys the object and frees any allocated resources | 34 | * Destroys the object and frees any allocated resources |
36 | */ | 35 | */ |
37 | GSMTool::~GSMTool() | 36 | GSMTool::~GSMTool() |
38 | { | 37 | { |
39 | // no need to delete child widgets, Qt does it all for us | 38 | // no need to delete child widgets, Qt does it all for us |
40 | if (devicelocked) | 39 | if (devicelocked) |
41 | unlockDevice(); | 40 | unlockDevice(); |
42 | } | 41 | } |
43 | const speed_t GSMTool::baudrates[12] = { | 42 | const speed_t GSMTool::baudrates[12] = { |
44 | B300, B600, B1200, B2400, B4800, B9600, B19200, | 43 | B300, B600, B1200, B2400, B4800, B9600, B19200, |
45 | B38400, B57600, B115200, B230400, B460800 | 44 | B38400, B57600, B115200, B230400, B460800 |
46 | }; | 45 | }; |
47 | 46 | ||
48 | int GSMTool::lockDevice( ) | 47 | int GSMTool::lockDevice( ) |
49 | { | 48 | { |
50 | devicelocked = 1; | 49 | devicelocked = 1; |
51 | /* FIXME */ | 50 | /* FIXME */ |
52 | return 0; | 51 | return 0; |
53 | } | 52 | } |
54 | 53 | ||
55 | void GSMTool::unlockDevice( ) | 54 | void GSMTool::unlockDevice( ) |
56 | { | 55 | { |
57 | devicelocked = 0; | 56 | devicelocked = 0; |
58 | } | 57 | } |
59 | 58 | ||
60 | void GSMTool::setConnected( bool conn ) | 59 | void GSMTool::setConnected( bool conn ) |
61 | { | 60 | { |
62 | TabWidget2->setTabEnabled(tab_2, conn); | 61 | TabWidget2->setTabEnabled(tab_2, conn); |
63 | TabWidget2->setTabEnabled(tab_3, conn); | 62 | TabWidget2->setTabEnabled(tab_3, conn); |
64 | MfrLabel->setEnabled(conn); | 63 | MfrLabel->setEnabled(conn); |
65 | MfrText->setEnabled(conn); | 64 | MfrText->setEnabled(conn); |
66 | ModelLabel->setEnabled(conn); | 65 | ModelLabel->setEnabled(conn); |
67 | ModelText->setEnabled(conn); | 66 | ModelText->setEnabled(conn); |
68 | RevisionLabel->setEnabled(conn); | 67 | RevisionLabel->setEnabled(conn); |
69 | RevisionText->setEnabled(conn); | 68 | RevisionText->setEnabled(conn); |
70 | SerialLabel->setEnabled(conn); | 69 | SerialLabel->setEnabled(conn); |
71 | SerialText->setEnabled(conn); | 70 | SerialText->setEnabled(conn); |
72 | 71 | ||
73 | } | 72 | } |
74 | void GSMTool::doTabChanged() | 73 | void GSMTool::doTabChanged() |
75 | { | 74 | { |
76 | int index = TabWidget2->currentPageIndex(); | 75 | int index = TabWidget2->currentPageIndex(); |
77 | qDebug("tab changed to %d", index); | 76 | qDebug("tab changed to %d", index); |
78 | 77 | ||
79 | if (index == 1) { | 78 | if (index == 1) { |
80 | timerid = startTimer(5000); | 79 | timerid = startTimer(5000); |
81 | timerEvent(NULL); | 80 | timerEvent(NULL); |
82 | } else if (timerid != -1) { | 81 | } else if (timerid != -1) { |
83 | killTimer(timerid); | 82 | killTimer(timerid); |
84 | timerid = -1; | 83 | timerid = -1; |
85 | } | 84 | } |
86 | } | 85 | } |
87 | 86 | ||
88 | void GSMTool::timerEvent( QTimerEvent * ) | 87 | void GSMTool::timerEvent( QTimerEvent * ) |
89 | { | 88 | { |
90 | OPInfo opi; | 89 | OPInfo opi; |
91 | 90 | ||
92 | opi = me->getCurrentOPInfo(); | 91 | opi = me->getCurrentOPInfo(); |
93 | 92 | ||
94 | if (opi._numericName == NOT_SET) { | 93 | if (opi._numericName == NOT_SET) { |
95 | NetStatText->setText("No network"); | 94 | NetStatText->setText("No network"); |
96 | NetworkLabel->setEnabled(FALSE); | 95 | NetworkLabel->setEnabled(FALSE); |
97 | NetworkText->setEnabled(FALSE); | 96 | NetworkText->setEnabled(FALSE); |
98 | NetworkText->setText(""); | 97 | NetworkText->setText(""); |
99 | SigStrText->setEnabled(FALSE); | 98 | SigStrText->setEnabled(FALSE); |
100 | SigStrText->setText(""); | 99 | SigStrText->setText(""); |
101 | dB->setEnabled(FALSE); | 100 | dB->setEnabled(FALSE); |
102 | SigStrLabel->setEnabled(FALSE); | 101 | SigStrLabel->setEnabled(FALSE); |
103 | } else { | 102 | } else { |
104 | // FIXME: Add 'roaming' info from AT+CFUN | 103 | // FIXME: Add 'roaming' info from AT+CFUN |
105 | qDebug("network"); | 104 | qDebug("network"); |
106 | NetStatText->setText("Registered"); | 105 | NetStatText->setText("Registered"); |
107 | NetworkLabel->setEnabled(TRUE); | 106 | NetworkLabel->setEnabled(TRUE); |
108 | NetworkText->setEnabled(TRUE); | 107 | NetworkText->setEnabled(TRUE); |
109 | NetworkText->setText(opi._longName.c_str()); | 108 | NetworkText->setText(opi._longName.c_str()); |
110 | SigStrText->setEnabled(TRUE); | 109 | SigStrText->setEnabled(TRUE); |
111 | 110 | ||
112 | qDebug("get sig str"); | 111 | qDebug("get sig str"); |
113 | int csq = me->getSignalStrength(); | 112 | int csq = me->getSignalStrength(); |
114 | if (csq == 0) { | 113 | if (csq == 0) { |
115 | SigStrText->setText("<= -113"); | 114 | SigStrText->setText("<= -113"); |
116 | dB->setEnabled(TRUE); | 115 | dB->setEnabled(TRUE); |
117 | SigStrLabel->setEnabled(TRUE); | 116 | SigStrLabel->setEnabled(TRUE); |
118 | } else if (csq == 99) { | 117 | } else if (csq == 99) { |
119 | SigStrText->setText("Unknown"); | 118 | SigStrText->setText("Unknown"); |
120 | dB->setEnabled(FALSE); | 119 | dB->setEnabled(FALSE); |
121 | SigStrLabel->setEnabled(FALSE); | 120 | SigStrLabel->setEnabled(FALSE); |
122 | } else { | 121 | } else { |
123 | char buf[6]; | 122 | char buf[6]; |
124 | sprintf(buf, "%d", -113 + (2*csq)); | 123 | sprintf(buf, "%d", -113 + (2*csq)); |
125 | SigStrText->setText(buf); | 124 | SigStrText->setText(buf); |
126 | dB->setEnabled(TRUE); | 125 | dB->setEnabled(TRUE); |
127 | SigStrLabel->setEnabled(TRUE); | 126 | SigStrLabel->setEnabled(TRUE); |
128 | } | 127 | } |
129 | } | 128 | } |
130 | } | 129 | } |
131 | 130 | ||
132 | void GSMTool::doScanButton() | 131 | void GSMTool::doScanButton() |
133 | { | 132 | { |
134 | qDebug("ScanButton"); | 133 | qDebug("ScanButton"); |
135 | } | 134 | } |
136 | /* | 135 | /* |
137 | * A simple slot... not very interesting. | 136 | * A simple slot... not very interesting. |
138 | */ | 137 | */ |
139 | void GSMTool::doConnectButton() | 138 | void GSMTool::doConnectButton() |
140 | { | 139 | { |
140 | gsmlib::Port *port; | ||
141 | |||
141 | speed_t rate; | 142 | speed_t rate; |
142 | devicename = strdup(DeviceName->currentText().local8Bit().data()); | 143 | devicename = strdup(DeviceName->currentText().local8Bit().data()); |
143 | rate = baudrates[BaudRate->currentItem()]; | 144 | rate = baudrates[BaudRate->currentItem()]; |
144 | 145 | ||
145 | qDebug("Connect Button Pressed"); | 146 | qDebug("Connect Button Pressed"); |
146 | MfrText->setText("Opening..."); | 147 | MfrText->setText("Opening..."); |
147 | ModelText->setText(""); | 148 | ModelText->setText(""); |
148 | RevisionText->setText(""); | 149 | RevisionText->setText(""); |
149 | SerialText->setText(""); | 150 | SerialText->setText(""); |
150 | 151 | ||
151 | setConnected(FALSE); | 152 | setConnected(FALSE); |
152 | if (me) { | 153 | if (me) { |
153 | // delete me; | ||
154 | me = NULL; | 154 | me = NULL; |
155 | } | 155 | } |
156 | if (port) { | ||
157 | // delete port; | ||
158 | port = NULL; | ||
159 | } | ||
160 | 156 | ||
161 | if (lockDevice()) { | 157 | if (lockDevice()) { |
162 | qDebug("lockDevice() failed\n"); | 158 | qDebug("lockDevice() failed\n"); |
159 | MfrText->setText("Lock port failed"); | ||
163 | }; | 160 | }; |
164 | 161 | ||
165 | qDebug("Device name is %s\n", devicename); | 162 | qDebug("Device name is %s\n", devicename); |
166 | 163 | ||
167 | try { | 164 | try { |
168 | port = new UnixSerialPort(devicename, rate, DEFAULT_INIT_STRING, 0); | 165 | port = new UnixSerialPort(devicename, rate, DEFAULT_INIT_STRING, 0); |
169 | } catch (GsmException) { | 166 | } catch (GsmException) { |
170 | qDebug("port failed"); | 167 | qDebug("port failed"); |
168 | MfrText->setText("Open port failed"); | ||
171 | return; | 169 | return; |
172 | } | 170 | } |
173 | MfrText->setText("Initialising..."); | 171 | MfrText->setText("Initialising..."); |
174 | qDebug("got port"); | 172 | qDebug("got port"); |
175 | try { | 173 | try { |
176 | me = new MeTa(port); | 174 | me = new MeTa(port); |
177 | } catch (GsmException) { | 175 | } catch (GsmException) { |
178 | qDebug("meta failed"); | 176 | qDebug("meta failed"); |
179 | delete port; | 177 | MfrText->setText("Initialise GSM unit failed"); |
180 | port = NULL; | 178 | me = NULL; |
181 | unlockDevice(); | 179 | unlockDevice(); |
182 | return; | 180 | return; |
183 | } | 181 | } |
184 | 182 | ||
185 | qDebug("Opened"); | 183 | qDebug("Opened"); |
186 | 184 | ||
187 | MEInfo ifo; | 185 | MEInfo ifo; |
188 | 186 | ||
189 | MfrText->setText("Querying..."); | 187 | MfrText->setText("Querying..."); |
190 | 188 | ||
191 | try { | 189 | try { |
192 | ifo = me->getMEInfo(); | 190 | ifo = me->getMEInfo(); |
193 | } catch (GsmException) { | 191 | } catch (GsmException) { |
194 | qDebug("getMEInfo failed"); | 192 | qDebug("getMEInfo failed"); |
195 | delete me; | 193 | MfrText->setText("Query GSM unit failed"); |
196 | me = NULL; | 194 | me = NULL; |
197 | delete port; | ||
198 | port = NULL; | ||
199 | unlockDevice(); | 195 | unlockDevice(); |
200 | return; | 196 | return; |
201 | } | 197 | } |
202 | 198 | ||
203 | MfrText->setText(ifo._manufacturer.c_str()); | 199 | MfrText->setText(ifo._manufacturer.c_str()); |
204 | ModelText->setText(ifo._model.c_str()); | 200 | ModelText->setText(ifo._model.c_str()); |
205 | RevisionText->setText(ifo._revision.c_str()); | 201 | RevisionText->setText(ifo._revision.c_str()); |
206 | SerialText->setText(ifo._serialNumber.c_str()); | 202 | SerialText->setText(ifo._serialNumber.c_str()); |
207 | setConnected(TRUE); | 203 | setConnected(TRUE); |
208 | } | 204 | } |
diff --git a/noncore/unsupported/gsmtool/gsmtool.h b/noncore/unsupported/gsmtool/gsmtool.h index cb19f54..1625cb1 100644 --- a/noncore/unsupported/gsmtool/gsmtool.h +++ b/noncore/unsupported/gsmtool/gsmtool.h | |||
@@ -1,41 +1,40 @@ | |||
1 | #ifndef EXAMPLE_H | 1 | #ifndef EXAMPLE_H |
2 | #define EXAMPLE_H | 2 | #define EXAMPLE_H |
3 | #include "gsmtoolbase.h" | 3 | #include "gsmtoolbase.h" |
4 | 4 | ||
5 | #include <termios.h> | 5 | #include <termios.h> |
6 | 6 | ||
7 | #include <gsmlib/gsm_me_ta.h> | 7 | #include <gsmlib/gsm_me_ta.h> |
8 | 8 | ||
9 | class GSMTool : public GSMToolBase | 9 | class GSMTool : public GSMToolBase |
10 | { | 10 | { |
11 | Q_OBJECT | 11 | Q_OBJECT |
12 | 12 | ||
13 | public: | 13 | public: |
14 | GSMTool( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 14 | GSMTool( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
15 | ~GSMTool(); | 15 | ~GSMTool(); |
16 | 16 | ||
17 | protected: | 17 | protected: |
18 | void timerEvent(QTimerEvent *te ); | 18 | void timerEvent(QTimerEvent *te ); |
19 | 19 | ||
20 | private slots: | 20 | private slots: |
21 | void doConnectButton(); | 21 | void doConnectButton(); |
22 | void doScanButton(); | 22 | void doScanButton(); |
23 | void doTabChanged(); | 23 | void doTabChanged(); |
24 | private: | 24 | private: |
25 | static const speed_t baudrates[]; | 25 | static const speed_t baudrates[]; |
26 | int devicelocked; | 26 | int devicelocked; |
27 | int timerid; | 27 | int timerid; |
28 | 28 | ||
29 | gsmlib::MeTa *me; | 29 | gsmlib::MeTa *me; |
30 | gsmlib::Port *port; | ||
31 | 30 | ||
32 | char *devicename; | 31 | char *devicename; |
33 | speed_t baudrate; | 32 | speed_t baudrate; |
34 | 33 | ||
35 | int lockDevice( ); | 34 | int lockDevice( ); |
36 | void unlockDevice( ); | 35 | void unlockDevice( ); |
37 | 36 | ||
38 | void setConnected( bool conn ); | 37 | void setConnected( bool conn ); |
39 | }; | 38 | }; |
40 | 39 | ||
41 | #endif // EXAMPLE_H | 40 | #endif // EXAMPLE_H |