Lines 178-188
Link Here
|
178 |
|
178 |
|
179 |
// switch off non-blocking mode |
179 |
// switch off non-blocking mode |
180 |
int fdFlags; |
180 |
int fdFlags; |
181 |
if ((fdFlags = fcntl(_fd, F_GETFL)) == -1) |
181 |
if ((fdFlags = fcntl(_fd, F_GETFL)) == -1) { |
|
|
182 |
close(_fd); |
182 |
throwModemException(_("getting file status flags failed")); |
183 |
throwModemException(_("getting file status flags failed")); |
|
|
184 |
} |
183 |
fdFlags &= ~O_NONBLOCK; |
185 |
fdFlags &= ~O_NONBLOCK; |
184 |
if (fcntl(_fd, F_SETFL, fdFlags) == -1) |
186 |
if (fcntl(_fd, F_SETFL, fdFlags) == -1) { |
|
|
187 |
close(_fd); |
185 |
throwModemException(_("switching of non-blocking mode failed")); |
188 |
throwModemException(_("switching of non-blocking mode failed")); |
|
|
189 |
} |
186 |
|
190 |
|
187 |
long int saveTimeoutVal = _timeoutVal; |
191 |
long int saveTimeoutVal = _timeoutVal; |
188 |
_timeoutVal = 3; |
192 |
_timeoutVal = 3; |
Lines 194-210
Link Here
|
194 |
|
198 |
|
195 |
// toggle DTR to reset modem |
199 |
// toggle DTR to reset modem |
196 |
int mctl = TIOCM_DTR; |
200 |
int mctl = TIOCM_DTR; |
197 |
if (ioctl(_fd, TIOCMBIC, &mctl) < 0) |
201 |
if (ioctl(_fd, TIOCMBIC, &mctl) < 0) { |
|
|
202 |
close(_fd); |
198 |
throwModemException(_("clearing DTR failed")); |
203 |
throwModemException(_("clearing DTR failed")); |
|
|
204 |
} |
199 |
// the waiting time for DTR toggling is increased with each loop |
205 |
// the waiting time for DTR toggling is increased with each loop |
200 |
usleep(holdoff[initTries]); |
206 |
usleep(holdoff[initTries]); |
201 |
if (ioctl(_fd, TIOCMBIS, &mctl) < 0) |
207 |
if (ioctl(_fd, TIOCMBIS, &mctl) < 0) { |
|
|
208 |
close(_fd); |
202 |
throwModemException(_("setting DTR failed")); |
209 |
throwModemException(_("setting DTR failed")); |
203 |
|
210 |
} |
204 |
// get line modes |
211 |
// get line modes |
205 |
if (tcgetattr(_fd, &t) < 0) |
212 |
if (tcgetattr(_fd, &t) < 0) { |
|
|
213 |
close(_fd); |
206 |
throwModemException(stringPrintf(_("tcgetattr device '%s'"), |
214 |
throwModemException(stringPrintf(_("tcgetattr device '%s'"), |
207 |
device.c_str())); |
215 |
device.c_str())); |
|
|
216 |
} |
208 |
|
217 |
|
209 |
// set line speed |
218 |
// set line speed |
210 |
cfsetispeed(&t, lineSpeed); |
219 |
cfsetispeed(&t, lineSpeed); |
Lines 229-237
Link Here
|
229 |
t.c_cc[VSUSP] = 0; |
238 |
t.c_cc[VSUSP] = 0; |
230 |
|
239 |
|
231 |
// write back |
240 |
// write back |
232 |
if(tcsetattr (_fd, TCSANOW, &t) < 0) |
241 |
if(tcsetattr (_fd, TCSANOW, &t) < 0) { |
|
|
242 |
close(_fd); |
233 |
throwModemException(stringPrintf(_("tcsetattr device '%s'"), |
243 |
throwModemException(stringPrintf(_("tcsetattr device '%s'"), |
234 |
device.c_str())); |
244 |
device.c_str())); |
|
|
245 |
} |
235 |
// the waiting time for writing to the ME/TA is increased with each loop |
246 |
// the waiting time for writing to the ME/TA is increased with each loop |
236 |
usleep(holdoff[initTries]); |
247 |
usleep(holdoff[initTries]); |
237 |
|
248 |
|
Lines 277-287
Link Here
|
277 |
catch (GsmException &e) |
288 |
catch (GsmException &e) |
278 |
{ |
289 |
{ |
279 |
_timeoutVal = saveTimeoutVal; |
290 |
_timeoutVal = saveTimeoutVal; |
280 |
if (initTries == 0) |
291 |
if (initTries == 0) { |
|
|
292 |
close(_fd); |
281 |
throw e; |
293 |
throw e; |
|
|
294 |
} |
282 |
} |
295 |
} |
283 |
} |
296 |
} |
284 |
// no response after 3 tries |
297 |
// no response after 3 tries |
|
|
298 |
close(_fd); |
285 |
throw GsmException(stringPrintf(_("reset modem failed '%s'"), |
299 |
throw GsmException(stringPrintf(_("reset modem failed '%s'"), |
286 |
device.c_str()), OtherError); |
300 |
device.c_str()), OtherError); |
287 |
} |
301 |
} |