-rw-r--r-- | noncore/unsupported/gsmtool/gsmtool.cpp | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/noncore/unsupported/gsmtool/gsmtool.cpp b/noncore/unsupported/gsmtool/gsmtool.cpp index 6fea596..e6122ad 100644 --- a/noncore/unsupported/gsmtool/gsmtool.cpp +++ b/noncore/unsupported/gsmtool/gsmtool.cpp | |||
@@ -1,460 +1,456 @@ | |||
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 | #include <qlistview.h> | 7 | #include <qlistview.h> |
8 | #include <qtextbrowser.h> | 8 | #include <qtextbrowser.h> |
9 | #include <qmultilineedit.h> | 9 | #include <qmultilineedit.h> |
10 | 10 | ||
11 | #include <termios.h> | 11 | #include <termios.h> |
12 | 12 | ||
13 | #include <gsmlib/gsm_me_ta.h> | 13 | #include <gsmlib/gsm_me_ta.h> |
14 | #include <gsmlib/gsm_unix_serial.h> | 14 | #include <gsmlib/gsm_unix_serial.h> |
15 | #include <gsmlib/gsm_sms.h> | 15 | #include <gsmlib/gsm_sms.h> |
16 | #include <gsmlib/gsm_sorted_sms_store.h> | 16 | #include <gsmlib/gsm_sorted_sms_store.h> |
17 | 17 | ||
18 | using namespace gsmlib; | 18 | using namespace gsmlib; |
19 | 19 | ||
20 | 20 | ||
21 | /* | 21 | /* |
22 | * Constructs a GSMTool which is a child of 'parent', with the | 22 | * Constructs a GSMTool which is a child of 'parent', with the |
23 | * name 'name' and widget flags set to 'f' | 23 | * name 'name' and widget flags set to 'f' |
24 | */ | 24 | */ |
25 | GSMTool::GSMTool( QWidget* parent, const char* name, WFlags fl ) | 25 | GSMTool::GSMTool( QWidget* parent, const char* name, WFlags fl ) |
26 | : GSMToolBase( parent, name, fl ) | 26 | : GSMToolBase( parent, name, fl ) |
27 | { | 27 | { |
28 | devicelocked = 0; | 28 | devicelocked = 0; |
29 | me = NULL; | 29 | me = NULL; |
30 | sms_store = NULL; | 30 | sms_store = NULL; |
31 | setConnected(FALSE); | 31 | setConnected(FALSE); |
32 | /* FIXME: Persistent settings for device/baudrate */ | 32 | /* FIXME: Persistent settings for device/baudrate */ |
33 | connect(ConnectButton, SIGNAL(clicked()), this, SLOT(doConnectButton())); | 33 | connect(ConnectButton, SIGNAL(clicked()), this, SLOT(doConnectButton())); |
34 | connect(SMSDeleteButton, SIGNAL(clicked()), this, SLOT(doSMSDeleteButton())); | 34 | connect(SMSDeleteButton, SIGNAL(clicked()), this, SLOT(doSMSDeleteButton())); |
35 | connect(SMSSendButton, SIGNAL(clicked()), this, SLOT(doSMSSendButton())); | 35 | connect(SMSSendButton, SIGNAL(clicked()), this, SLOT(doSMSSendButton())); |
36 | connect(NewSMSClearButton, SIGNAL(clicked()), this, SLOT(doNewSMSClearButton())); | 36 | connect(NewSMSClearButton, SIGNAL(clicked()), this, SLOT(doNewSMSClearButton())); |
37 | connect(NewSMSSaveButton, SIGNAL(clicked()), this, SLOT(doNewSMSSaveButton())); | 37 | connect(NewSMSSaveButton, SIGNAL(clicked()), this, SLOT(doNewSMSSaveButton())); |
38 | connect(NewSMSSendButton, SIGNAL(clicked()), this, SLOT(doNewSMSSendButton())); | 38 | connect(NewSMSSendButton, SIGNAL(clicked()), this, SLOT(doNewSMSSendButton())); |
39 | connect(ScanButton, SIGNAL(clicked()), this, SLOT(doScanButton())); | 39 | connect(ScanButton, SIGNAL(clicked()), this, SLOT(doScanButton())); |
40 | connect(TabWidget2, SIGNAL(currentChanged(QWidget *)), this, SLOT(doTabChanged())); | 40 | connect(TabWidget2, SIGNAL(currentChanged(QWidget *)), this, SLOT(doTabChanged())); |
41 | connect(SMSStoreList, SIGNAL(activated(int)), this, SLOT(doSMSStoreChanged())); | 41 | connect(SMSStoreList, SIGNAL(activated(int)), this, SLOT(doSMSStoreChanged())); |
42 | connect(SMSViewType, SIGNAL(activated(int)), this, SLOT(doSMSTypeChanged())); | 42 | connect(SMSViewType, SIGNAL(activated(int)), this, SLOT(doSMSTypeChanged())); |
43 | connect(SMSList, SIGNAL(selectionChanged(QListViewItem *)), this, SLOT(doSelectedSMSChanged(QListViewItem *))); | 43 | connect(SMSList, SIGNAL(selectionChanged(QListViewItem *)), this, SLOT(doSelectedSMSChanged(QListViewItem *))); |
44 | timerid = -1; // Is this not possible normally? | 44 | timerid = -1; // Is this not possible normally? |
45 | } | 45 | } |
46 | 46 | ||
47 | /* | 47 | /* |
48 | * Destroys the object and frees any allocated resources | 48 | * Destroys the object and frees any allocated resources |
49 | */ | 49 | */ |
50 | GSMTool::~GSMTool() | 50 | GSMTool::~GSMTool() |
51 | { | 51 | { |
52 | // no need to delete child widgets, Qt does it all for us | 52 | // no need to delete child widgets, Qt does it all for us |
53 | if (devicelocked) | 53 | if (devicelocked) |
54 | unlockDevice(); | 54 | unlockDevice(); |
55 | } | 55 | } |
56 | const speed_t GSMTool::baudrates[12] = { | 56 | const speed_t GSMTool::baudrates[12] = { |
57 | B300, B600, B1200, B2400, B4800, B9600, B19200, | 57 | B300, B600, B1200, B2400, B4800, B9600, B19200, |
58 | B38400, B57600, B115200, B230400, B460800 | 58 | B38400, B57600, B115200, B230400, B460800 |
59 | }; | 59 | }; |
60 | 60 | ||
61 | int GSMTool::lockDevice( ) | 61 | int GSMTool::lockDevice( ) |
62 | { | 62 | { |
63 | devicelocked = 1; | 63 | devicelocked = 1; |
64 | /* FIXME */ | 64 | /* FIXME */ |
65 | return 0; | 65 | return 0; |
66 | } | 66 | } |
67 | 67 | ||
68 | void GSMTool::unlockDevice( ) | 68 | void GSMTool::unlockDevice( ) |
69 | { | 69 | { |
70 | devicelocked = 0; | 70 | devicelocked = 0; |
71 | } | 71 | } |
72 | 72 | ||
73 | void GSMTool::setConnected( bool conn ) | 73 | void GSMTool::setConnected( bool conn ) |
74 | { | 74 | { |
75 | TabWidget2->setTabEnabled(tab_2, conn); | 75 | TabWidget2->setTabEnabled(tab_2, conn); |
76 | TabWidget2->setTabEnabled(tab_3, conn); | 76 | TabWidget2->setTabEnabled(tab_3, conn); |
77 | TabWidget2->setTabEnabled(tab_4, conn); | 77 | TabWidget2->setTabEnabled(tab_4, conn); |
78 | MfrLabel->setEnabled(conn); | 78 | MfrLabel->setEnabled(conn); |
79 | MfrText->setEnabled(conn); | 79 | MfrText->setEnabled(conn); |
80 | ModelLabel->setEnabled(conn); | 80 | ModelLabel->setEnabled(conn); |
81 | ModelText->setEnabled(conn); | 81 | ModelText->setEnabled(conn); |
82 | RevisionLabel->setEnabled(conn); | 82 | RevisionLabel->setEnabled(conn); |
83 | RevisionText->setEnabled(conn); | 83 | RevisionText->setEnabled(conn); |
84 | SerialLabel->setEnabled(conn); | 84 | SerialLabel->setEnabled(conn); |
85 | SerialText->setEnabled(conn); | 85 | SerialText->setEnabled(conn); |
86 | 86 | ||
87 | } | 87 | } |
88 | void GSMTool::doTabChanged() | 88 | void GSMTool::doTabChanged() |
89 | { | 89 | { |
90 | int index = TabWidget2->currentPageIndex(); | 90 | int index = TabWidget2->currentPageIndex(); |
91 | qDebug("tab changed to %d", index); | 91 | qDebug("tab changed to %d", index); |
92 | 92 | ||
93 | if (index == 1) { | 93 | if (index == 1) { |
94 | timerid = startTimer(5000); | 94 | timerid = startTimer(5000); |
95 | timerEvent(NULL); | 95 | timerEvent(NULL); |
96 | } else if (timerid != -1) { | 96 | } else if (timerid != -1) { |
97 | killTimer(timerid); | 97 | killTimer(timerid); |
98 | timerid = -1; | 98 | timerid = -1; |
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | void GSMTool::timerEvent( QTimerEvent * ) | 102 | void GSMTool::timerEvent( QTimerEvent * ) |
103 | { | 103 | { |
104 | OPInfo opi; | 104 | OPInfo opi; |
105 | 105 | ||
106 | opi = me->getCurrentOPInfo(); | 106 | opi = me->getCurrentOPInfo(); |
107 | 107 | ||
108 | if (opi._numericName == NOT_SET) { | 108 | if (opi._numericName == NOT_SET) { |
109 | NetStatText->setText("No network"); | 109 | NetStatText->setText("No network"); |
110 | NetworkLabel->setEnabled(FALSE); | 110 | NetworkLabel->setEnabled(FALSE); |
111 | NetworkText->setEnabled(FALSE); | 111 | NetworkText->setEnabled(FALSE); |
112 | NetworkText->setText(""); | 112 | NetworkText->setText(""); |
113 | SigStrText->setEnabled(FALSE); | 113 | SigStrText->setEnabled(FALSE); |
114 | SigStrText->setText(""); | 114 | SigStrText->setText(""); |
115 | dB->setEnabled(FALSE); | 115 | dB->setEnabled(FALSE); |
116 | SigStrLabel->setEnabled(FALSE); | 116 | SigStrLabel->setEnabled(FALSE); |
117 | } else { | 117 | } else { |
118 | // FIXME: Add 'roaming' info from AT+CFUN | 118 | // FIXME: Add 'roaming' info from AT+CFUN |
119 | qDebug("network"); | 119 | qDebug("network"); |
120 | NetStatText->setText("Registered"); | 120 | NetStatText->setText("Registered"); |
121 | NetworkLabel->setEnabled(TRUE); | 121 | NetworkLabel->setEnabled(TRUE); |
122 | NetworkText->setEnabled(TRUE); | 122 | NetworkText->setEnabled(TRUE); |
123 | NetworkText->setText(opi._longName.c_str()); | 123 | NetworkText->setText(opi._longName.c_str()); |
124 | SigStrText->setEnabled(TRUE); | 124 | SigStrText->setEnabled(TRUE); |
125 | 125 | ||
126 | qDebug("get sig str"); | 126 | qDebug("get sig str"); |
127 | int csq = me->getSignalStrength(); | 127 | int csq = me->getSignalStrength(); |
128 | if (csq == 0) { | 128 | if (csq == 0) { |
129 | SigStrText->setText("<= -113"); | 129 | SigStrText->setText("<= -113"); |
130 | dB->setEnabled(TRUE); | 130 | dB->setEnabled(TRUE); |
131 | SigStrLabel->setEnabled(TRUE); | 131 | SigStrLabel->setEnabled(TRUE); |
132 | } else if (csq == 99) { | 132 | } else if (csq == 99) { |
133 | SigStrText->setText("Unknown"); | 133 | SigStrText->setText("Unknown"); |
134 | dB->setEnabled(FALSE); | 134 | dB->setEnabled(FALSE); |
135 | SigStrLabel->setEnabled(FALSE); | 135 | SigStrLabel->setEnabled(FALSE); |
136 | } else { | 136 | } else { |
137 | char buf[6]; | 137 | char buf[6]; |
138 | sprintf(buf, "%d", -113 + (2*csq)); | 138 | sprintf(buf, "%d", -113 + (2*csq)); |
139 | SigStrText->setText(buf); | 139 | SigStrText->setText(buf); |
140 | dB->setEnabled(TRUE); | 140 | dB->setEnabled(TRUE); |
141 | SigStrLabel->setEnabled(TRUE); | 141 | SigStrLabel->setEnabled(TRUE); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | void GSMTool::doSMSStoreChanged() | 146 | void GSMTool::doSMSStoreChanged() |
147 | { | 147 | { |
148 | const char *storename = SMSStoreList->currentText().ascii(); | 148 | const char *storename = SMSStoreList->currentText().ascii(); |
149 | qDebug("Store Changed to '%s'", storename); | 149 | qDebug("Store Changed to '%s'", storename); |
150 | if (!strcmp(storename, "None")) { | 150 | if (!strcmp(storename, "None")) { |
151 | sms_store = NULL; | 151 | sms_store = NULL; |
152 | } else try { | 152 | } else try { |
153 | sms_store = new SortedSMSStore(me->getSMSStore(storename)); | 153 | sms_store = new SortedSMSStore(me->getSMSStore(storename)); |
154 | sms_store->setSortOrder(ByIndex); | 154 | sms_store->setSortOrder(ByIndex); |
155 | 155 | ||
156 | qDebug("got store of size %d", sms_store->size()); | 156 | qDebug("got store of size %d", sms_store->size()); |
157 | } catch (GsmException) { | 157 | } catch (GsmException) { |
158 | sms_store = NULL; | 158 | sms_store = NULL; |
159 | qDebug("get store failed"); | 159 | qDebug("get store failed"); |
160 | } | 160 | } |
161 | 161 | ||
162 | SMSList->setEnabled(!(sms_store == NULL)); | 162 | SMSList->setEnabled(!(sms_store == NULL)); |
163 | NewSMSSaveButton->setEnabled(!(sms_store == NULL)); | 163 | NewSMSSaveButton->setEnabled(!(sms_store == NULL)); |
164 | doSMSTypeChanged(); | 164 | doSMSTypeChanged(); |
165 | } | 165 | } |
166 | 166 | ||
167 | void GSMTool::doSMSTypeChanged() | 167 | void GSMTool::doSMSTypeChanged() |
168 | { | 168 | { |
169 | int direction = SMSViewType->currentItem(); | 169 | int direction = SMSViewType->currentItem(); |
170 | qDebug("direction %s\n", direction?"outgoing":"incoming"); | 170 | qDebug("direction %s\n", direction?"outgoing":"incoming"); |
171 | if (direction) | 171 | if (direction) |
172 | SMSSendButton->setText("Send"); | 172 | SMSSendButton->setText("Send"); |
173 | else | 173 | else |
174 | SMSSendButton->setText("Reply"); | 174 | SMSSendButton->setText("Reply"); |
175 | 175 | ||
176 | SMSList->clear(); | 176 | SMSList->clear(); |
177 | doSelectedSMSChanged(NULL); | 177 | doSelectedSMSChanged(NULL); |
178 | 178 | ||
179 | if (sms_store == NULL) | 179 | if (sms_store == NULL) |
180 | return; | 180 | return; |
181 | for (SortedSMSStore::iterator e = sms_store->begin(); | 181 | for (SortedSMSStore::iterator e = sms_store->begin(); |
182 | e != sms_store->end(); e++) { | 182 | e != sms_store->end(); e++) { |
183 | // qDebug("Message %d", i); | 183 | // qDebug("Message %d", i); |
184 | qDebug("Is%sempty", e->empty()?" ":" not "); | 184 | qDebug("Is%sempty", e->empty()?" ":" not "); |
185 | if (e->empty()) | 185 | if (e->empty()) |
186 | continue; | 186 | continue; |
187 | 187 | ||
188 | qDebug("Status %d", e->status()); | 188 | qDebug("Status %d", e->status()); |
189 | SMSMessageRef message = e->message(); | 189 | SMSMessageRef message = e->message(); |
190 | qDebug("Got message."); | 190 | qDebug("Got message."); |
191 | 191 | ||
192 | // qDebug(message->toString().c_str()); | 192 | // qDebug(message->toString().c_str()); |
193 | if (direction == message->messageType()) { | 193 | if (direction == message->messageType()) { |
194 | qDebug("yes\n"); | 194 | qDebug("yes\n"); |
195 | char buf[3]; | 195 | char buf[3]; |
196 | snprintf(buf, 3, "%d", e->index()); | 196 | snprintf(buf, 3, "%d", e->index()); |
197 | new QListViewItem(SMSList, message->address()._number.c_str(), message->serviceCentreTimestamp().toString().c_str(), buf); | 197 | new QListViewItem(SMSList, message->address()._number.c_str(), message->serviceCentreTimestamp().toString().c_str(), buf); |
198 | } | 198 | } |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | void GSMTool::doSelectedSMSChanged(QListViewItem *item) | 202 | void GSMTool::doSelectedSMSChanged(QListViewItem *item) |
203 | { | 203 | { |
204 | qDebug("message changed\n"); | 204 | qDebug("message changed\n"); |
205 | 205 | ||
206 | if (!item || sms_store == NULL) { | 206 | if (!item || sms_store == NULL) { |
207 | SMSText->setText(""); | 207 | SMSText->setText(""); |
208 | SMSText->setEnabled(FALSE); | 208 | SMSText->setEnabled(FALSE); |
209 | SMSDeleteButton->setEnabled(FALSE); | 209 | SMSDeleteButton->setEnabled(FALSE); |
210 | SMSSendButton->setEnabled(FALSE); | 210 | SMSSendButton->setEnabled(FALSE); |
211 | return; | 211 | return; |
212 | } | 212 | } |
213 | /* ARGH. This sucks. Surely there's an app-private pointer in the | 213 | /* ARGH. This sucks. Surely there's an app-private pointer in the |
214 | QListViewItem that I've failed to notice? | 214 | QListViewItem that I've failed to notice? |
215 | 215 | ||
216 | SMSMessageRef message = *(SMSMessageRef*)item->private; | 216 | SMSMessageRef message = *(SMSMessageRef*)item->private; |
217 | */ | 217 | */ |
218 | qDebug("item %p\n", item); | 218 | qDebug("item %p\n", item); |
219 | 219 | ||
220 | qDebug("text(2) is %s\n", item->text(2).ascii()); | 220 | qDebug("text(2) is %s\n", item->text(2).ascii()); |
221 | int index = atoi(item->text(2).ascii()); | 221 | int index = atoi(item->text(2).ascii()); |
222 | qDebug("index %d\n", index); | 222 | qDebug("index %d\n", index); |
223 | SMSMessageRef message = sms_store->find(index)->message(); | 223 | SMSMessageRef message = sms_store->find(index)->message(); |
224 | 224 | ||
225 | SMSText->setText(message->userData().c_str()); | 225 | SMSText->setText(message->userData().c_str()); |
226 | SMSText->setEnabled(TRUE); | 226 | SMSText->setEnabled(TRUE); |
227 | SMSDeleteButton->setEnabled(TRUE); | 227 | SMSDeleteButton->setEnabled(TRUE); |
228 | SMSSendButton->setEnabled(TRUE); | 228 | SMSSendButton->setEnabled(TRUE); |
229 | 229 | ||
230 | } | 230 | } |
231 | 231 | ||
232 | void GSMTool::doSMSSendButton() | 232 | void GSMTool::doSMSSendButton() |
233 | { | 233 | { |
234 | qDebug("SMSSendButton"); | 234 | qDebug("SMSSendButton"); |
235 | 235 | ||
236 | QListViewItem *item = SMSList->currentItem(); | 236 | QListViewItem *item = SMSList->currentItem(); |
237 | if (!item) | 237 | if (!item) |
238 | return; | 238 | return; |
239 | 239 | ||
240 | int index = atoi(item->text(2).ascii()); | 240 | int index = atoi(item->text(2).ascii()); |
241 | qDebug("index %d\n", index); | 241 | qDebug("index %d\n", index); |
242 | 242 | ||
243 | int direction = SMSViewType->currentItem(); | 243 | int direction = SMSViewType->currentItem(); |
244 | qDebug("direction %s\n", direction?"outgoing":"incoming"); | 244 | qDebug("direction %s\n", direction?"outgoing":"incoming"); |
245 | 245 | ||
246 | SMSMessageRef message = sms_store->find(index)->message(); | 246 | SMSMessageRef message = sms_store->find(index)->message(); |
247 | 247 | ||
248 | if (direction) | 248 | if (direction) |
249 | NewSMSText->setText(message->userData().c_str()); | 249 | NewSMSText->setText(message->userData().c_str()); |
250 | else | 250 | else |
251 | NewSMSText->setText(""); | 251 | NewSMSText->setText(""); |
252 | NewSMSToBox->insertItem(message->address()._number.c_str(), 0); | 252 | NewSMSToBox->insertItem(message->address()._number.c_str(), 0); |
253 | TabWidget2->setCurrentPage(3); | 253 | TabWidget2->setCurrentPage(3); |
254 | 254 | ||
255 | } | 255 | } |
256 | 256 | ||
257 | void GSMTool::doNewSMSClearButton() | 257 | void GSMTool::doNewSMSClearButton() |
258 | { | 258 | { |
259 | NewSMSText->setText(""); | 259 | NewSMSText->setText(""); |
260 | } | 260 | } |
261 | 261 | ||
262 | void GSMTool::doNewSMSSaveButton() | 262 | void GSMTool::doNewSMSSaveButton() |
263 | { | 263 | { |
264 | qDebug("NewSMSSaveButton"); | 264 | qDebug("NewSMSSaveButton"); |
265 | const char *msgtext = strdup(NewSMSText->text().local8Bit()); | 265 | const char *msgtext = strdup(NewSMSText->text().local8Bit()); |
266 | const char *dest = NewSMSToBox->currentText().ascii(); | 266 | const char *dest = NewSMSToBox->currentText().ascii(); |
267 | 267 | ||
268 | NewSMSStatusLabel->setText("Sending..."); | 268 | NewSMSStatusLabel->setText("Sending..."); |
269 | me->setMessageService(1); | 269 | me->setMessageService(1); |
270 | 270 | ||
271 | qDebug("NewSMSSendButton: '%s' to '%s'", msgtext, dest); | 271 | qDebug("NewSMSSendButton: '%s' to '%s'", msgtext, dest); |
272 | 272 | ||
273 | SMSMessageRef m = new SMSSubmitMessage (msgtext, dest); | 273 | SMSMessageRef m = new SMSSubmitMessage (msgtext, dest); |
274 | sms_store->insert(m); | 274 | sms_store->insert(m); |
275 | free((void *)msgtext); | 275 | free((void *)msgtext); |
276 | 276 | ||
277 | } | 277 | } |
278 | void GSMTool::doNewSMSSendButton() | 278 | void GSMTool::doNewSMSSendButton() |
279 | { | 279 | { |
280 | const char *msgtext = strdup(NewSMSText->text().local8Bit()); | 280 | const char *msgtext = strdup(NewSMSText->text().local8Bit()); |
281 | const char *dest = NewSMSToBox->currentText().ascii(); | 281 | const char *dest = NewSMSToBox->currentText().ascii(); |
282 | 282 | ||
283 | NewSMSStatusLabel->setText("Sending..."); | 283 | NewSMSStatusLabel->setText("Sending..."); |
284 | me->setMessageService(1); | 284 | me->setMessageService(1); |
285 | 285 | ||
286 | qDebug("NewSMSSendButton: '%s' to '%s'", msgtext, dest); | 286 | qDebug("NewSMSSendButton: '%s' to '%s'", msgtext, dest); |
287 | 287 | ||
288 | SMSSubmitMessage m(msgtext, dest); | 288 | SMSSubmitMessage m(msgtext, dest); |
289 | try { | 289 | try { |
290 | Ref<SMSMessage> ackPDU; | ||
291 | m.setAt(new GsmAt(*me)); | 290 | m.setAt(new GsmAt(*me)); |
292 | m.send(ackPDU); | 291 | m.send(); |
293 | 292 | ||
294 | // print acknowledgement if available | ||
295 | if (! ackPDU.isnull()) | ||
296 | cout << ackPDU->toString(); | ||
297 | NewSMSStatusLabel->setText("Message sent."); | 293 | NewSMSStatusLabel->setText("Message sent."); |
298 | } catch (GsmException &ge) { | 294 | } catch (GsmException &ge) { |
299 | NewSMSStatusLabel->setText("Failed."); | 295 | NewSMSStatusLabel->setText("Failed."); |
300 | qDebug(ge.what()); | 296 | qDebug(ge.what()); |
301 | } | 297 | } |
302 | free((void *)msgtext); | 298 | free((void *)msgtext); |
303 | 299 | ||
304 | 300 | ||
305 | } | 301 | } |
306 | 302 | ||
307 | 303 | ||
308 | void GSMTool::doSMSDeleteButton() | 304 | void GSMTool::doSMSDeleteButton() |
309 | { | 305 | { |
310 | QListViewItem *item = SMSList->currentItem(); | 306 | QListViewItem *item = SMSList->currentItem(); |
311 | if (!item) | 307 | if (!item) |
312 | return; | 308 | return; |
313 | 309 | ||
314 | int index = atoi(item->text(2).ascii()); | 310 | int index = atoi(item->text(2).ascii()); |
315 | qDebug("delete SMS with index %d\n", index); | 311 | qDebug("delete SMS with index %d\n", index); |
316 | 312 | ||
317 | 313 | ||
318 | 314 | ||
319 | SortedSMSStore::iterator e = sms_store->find(index); | 315 | SortedSMSStore::iterator e = sms_store->find(index); |
320 | 316 | ||
321 | if (e != sms_store->end()) { | 317 | if (e != sms_store->end()) { |
322 | qDebug("message is %s\n", e->message()->userData().c_str()); | 318 | qDebug("message is %s\n", e->message()->userData().c_str()); |
323 | sms_store->erase(e); | 319 | sms_store->erase(e); |
324 | 320 | ||
325 | } | 321 | } |
326 | doSMSTypeChanged(); | 322 | doSMSTypeChanged(); |
327 | } | 323 | } |
328 | 324 | ||
329 | void GSMTool::doScanButton() | 325 | void GSMTool::doScanButton() |
330 | { | 326 | { |
331 | qDebug("ScanButton"); | 327 | qDebug("ScanButton"); |
332 | 328 | ||
333 | NetworkList->setEnabled(FALSE); | 329 | NetworkList->setEnabled(FALSE); |
334 | AvailNetsLabel->setEnabled(FALSE); | 330 | AvailNetsLabel->setEnabled(FALSE); |
335 | NetworkList->clear(); | 331 | NetworkList->clear(); |
336 | new QListViewItem(NetworkList, "Scanning..."); | 332 | new QListViewItem(NetworkList, "Scanning..."); |
337 | 333 | ||
338 | vector<OPInfo> opis; | 334 | vector<OPInfo> opis; |
339 | 335 | ||
340 | try { | 336 | try { |
341 | opis = me->getAvailableOPInfo(); | 337 | opis = me->getAvailableOPInfo(); |
342 | } catch (GsmException) { | 338 | } catch (GsmException) { |
343 | NetworkList->clear(); | 339 | NetworkList->clear(); |
344 | new QListViewItem(NetworkList, "Scan failed..."); | 340 | new QListViewItem(NetworkList, "Scan failed..."); |
345 | return; | 341 | return; |
346 | } | 342 | } |
347 | 343 | ||
348 | NetworkList->clear(); | 344 | NetworkList->clear(); |
349 | for (vector<OPInfo>::iterator i = opis.begin(); i != opis.end(); ++i) { | 345 | for (vector<OPInfo>::iterator i = opis.begin(); i != opis.end(); ++i) { |
350 | char *statustext; | 346 | char *statustext; |
351 | switch (i->_status) { | 347 | switch (i->_status) { |
352 | 348 | ||
353 | case UnknownOPStatus: | 349 | case UnknownOPStatus: |
354 | statustext = "unknown"; | 350 | statustext = "unknown"; |
355 | break; | 351 | break; |
356 | 352 | ||
357 | case CurrentOPStatus: | 353 | case CurrentOPStatus: |
358 | statustext = "current"; | 354 | statustext = "current"; |
359 | break; | 355 | break; |
360 | 356 | ||
361 | case AvailableOPStatus: | 357 | case AvailableOPStatus: |
362 | statustext = "available"; | 358 | statustext = "available"; |
363 | break; | 359 | break; |
364 | 360 | ||
365 | case ForbiddenOPStatus: | 361 | case ForbiddenOPStatus: |
366 | statustext = "forbidden"; | 362 | statustext = "forbidden"; |
367 | break; | 363 | break; |
368 | 364 | ||
369 | default: | 365 | default: |
370 | statustext = "(ERROR)"; | 366 | statustext = "(ERROR)"; |
371 | } | 367 | } |
372 | char num[7]; | 368 | char num[7]; |
373 | snprintf(num, 6, "%d", i->_numericName); | 369 | snprintf(num, 6, "%d", i->_numericName); |
374 | new QListViewItem(NetworkList, i->_longName.c_str(), statustext, num, i->_shortName.c_str()); | 370 | new QListViewItem(NetworkList, i->_longName.c_str(), statustext, num, i->_shortName.c_str()); |
375 | } | 371 | } |
376 | NetworkList->setEnabled(TRUE); | 372 | NetworkList->setEnabled(TRUE); |
377 | AvailNetsLabel->setEnabled(TRUE); | 373 | AvailNetsLabel->setEnabled(TRUE); |
378 | } | 374 | } |
379 | /* | 375 | /* |
380 | * A simple slot... not very interesting. | 376 | * A simple slot... not very interesting. |
381 | */ | 377 | */ |
382 | void GSMTool::doConnectButton() | 378 | void GSMTool::doConnectButton() |
383 | { | 379 | { |
384 | gsmlib::Port *port; | 380 | gsmlib::Port *port; |
385 | 381 | ||
386 | speed_t rate; | 382 | speed_t rate; |
387 | devicename = strdup(DeviceName->currentText().local8Bit().data()); | 383 | devicename = strdup(DeviceName->currentText().local8Bit().data()); |
388 | rate = baudrates[BaudRate->currentItem()]; | 384 | rate = baudrates[BaudRate->currentItem()]; |
389 | 385 | ||
390 | qDebug("Connect Button Pressed"); | 386 | qDebug("Connect Button Pressed"); |
391 | MfrText->setText("Opening..."); | 387 | MfrText->setText("Opening..."); |
392 | ModelText->setText(""); | 388 | ModelText->setText(""); |
393 | RevisionText->setText(""); | 389 | RevisionText->setText(""); |
394 | SerialText->setText(""); | 390 | SerialText->setText(""); |
395 | 391 | ||
396 | setConnected(FALSE); | 392 | setConnected(FALSE); |
397 | if (me) { | 393 | if (me) { |
398 | me = NULL; | 394 | me = NULL; |
399 | } | 395 | } |
400 | 396 | ||
401 | if (lockDevice()) { | 397 | if (lockDevice()) { |
402 | qDebug("lockDevice() failed\n"); | 398 | qDebug("lockDevice() failed\n"); |
403 | MfrText->setText("Lock port failed"); | 399 | MfrText->setText("Lock port failed"); |
404 | }; | 400 | }; |
405 | 401 | ||
406 | qDebug("Device name is %s\n", devicename); | 402 | qDebug("Device name is %s\n", devicename); |
407 | 403 | ||
408 | try { | 404 | try { |
409 | port = new UnixSerialPort(devicename, rate, DEFAULT_INIT_STRING, 0); | 405 | port = new UnixSerialPort(devicename, rate, DEFAULT_INIT_STRING, 0); |
410 | } catch (GsmException) { | 406 | } catch (GsmException) { |
411 | qDebug("port failed"); | 407 | qDebug("port failed"); |
412 | MfrText->setText("Open port failed"); | 408 | MfrText->setText("Open port failed"); |
413 | return; | 409 | return; |
414 | } | 410 | } |
415 | MfrText->setText("Initialising..."); | 411 | MfrText->setText("Initialising..."); |
416 | qDebug("got port"); | 412 | qDebug("got port"); |
417 | try { | 413 | try { |
418 | me = new MeTa(port); | 414 | me = new MeTa(port); |
419 | } catch (GsmException) { | 415 | } catch (GsmException) { |
420 | qDebug("meta failed"); | 416 | qDebug("meta failed"); |
421 | MfrText->setText("Initialise GSM unit failed"); | 417 | MfrText->setText("Initialise GSM unit failed"); |
422 | me = NULL; | 418 | me = NULL; |
423 | unlockDevice(); | 419 | unlockDevice(); |
424 | return; | 420 | return; |
425 | } | 421 | } |
426 | 422 | ||
427 | qDebug("Opened"); | 423 | qDebug("Opened"); |
428 | 424 | ||
429 | MEInfo ifo; | 425 | MEInfo ifo; |
430 | 426 | ||
431 | MfrText->setText("Querying..."); | 427 | MfrText->setText("Querying..."); |
432 | 428 | ||
433 | try { | 429 | try { |
434 | ifo = me->getMEInfo(); | 430 | ifo = me->getMEInfo(); |
435 | } catch (GsmException) { | 431 | } catch (GsmException) { |
436 | qDebug("getMEInfo failed"); | 432 | qDebug("getMEInfo failed"); |
437 | MfrText->setText("Query GSM unit failed"); | 433 | MfrText->setText("Query GSM unit failed"); |
438 | me = NULL; | 434 | me = NULL; |
439 | unlockDevice(); | 435 | unlockDevice(); |
440 | return; | 436 | return; |
441 | } | 437 | } |
442 | 438 | ||
443 | MfrText->setText(ifo._manufacturer.c_str()); | 439 | MfrText->setText(ifo._manufacturer.c_str()); |
444 | ModelText->setText(ifo._model.c_str()); | 440 | ModelText->setText(ifo._model.c_str()); |
445 | RevisionText->setText(ifo._revision.c_str()); | 441 | RevisionText->setText(ifo._revision.c_str()); |
446 | SerialText->setText(ifo._serialNumber.c_str()); | 442 | SerialText->setText(ifo._serialNumber.c_str()); |
447 | setConnected(TRUE); | 443 | setConnected(TRUE); |
448 | 444 | ||
449 | SMSStoreList->clear(); | 445 | SMSStoreList->clear(); |
450 | SMSStoreList->insertItem("None"); | 446 | SMSStoreList->insertItem("None"); |
451 | 447 | ||
452 | vector<string> storenames = me->getSMSStoreNames(); | 448 | vector<string> storenames = me->getSMSStoreNames(); |
453 | 449 | ||
454 | for (vector<string>::iterator i = storenames.begin(); i != storenames.end(); ++i) { | 450 | for (vector<string>::iterator i = storenames.begin(); i != storenames.end(); ++i) { |
455 | SMSStoreList->insertItem(i->c_str()); | 451 | SMSStoreList->insertItem(i->c_str()); |
456 | } | 452 | } |
457 | SMSList->clear(); | 453 | SMSList->clear(); |
458 | SMSText->setText(""); | 454 | SMSText->setText(""); |
459 | sms_store = NULL; | 455 | sms_store = NULL; |
460 | } | 456 | } |