From 0a6e11eecc8d9cb785c5187219cea910daa3d8f7 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 12 May 2010 11:38:56 +0000 Subject: [PATCH] Longer timeout when calling (should fix some modems eg Openmoko Freerunner) --- src/command.c | 16 ++++++++++++++++ src/command.h | 2 ++ src/gsm.c | 7 ++++++- src/modem.c | 29 +++++++++++++++++++++++------ 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/command.c b/src/command.c index 927e8da..5c35971 100644 --- a/src/command.c +++ b/src/command.c @@ -31,6 +31,7 @@ struct _GSMCommand { GSMPriority priority; char * command; + unsigned int timeout; GSMError error; GSMCommandCallback callback; GSMMode mode; @@ -51,6 +52,7 @@ GSMCommand * gsm_command_new(char const * command) return NULL; /* XXX report error */ gsmc->priority = GSM_PRIORITY_NORMAL; gsmc->command = strdup(command); + gsmc->timeout = 2000; gsmc->error = GSM_ERROR_UNKNOWN; gsmc->callback = NULL; gsmc->mode = GSM_MODE_COMMAND; @@ -111,6 +113,13 @@ GSMPriority gsm_command_get_priority(GSMCommand * gsmc) } +/* gsm_command_get_timeout */ +unsigned int gsm_command_get_timeout(GSMCommand * gsmc) +{ + return gsmc->timeout; +} + + /* gsm_command_set_callback */ void gsm_command_set_callback(GSMCommand * gsmc, GSMCommandCallback callback) @@ -138,3 +147,10 @@ void gsm_command_set_priority(GSMCommand * gsmc, GSMPriority priority) { gsmc->priority = priority; } + + +/* gsm_command_set_timeout */ +void gsm_command_set_timeout(GSMCommand * gsmc, unsigned int timeout) +{ + gsmc->timeout = timeout; +} diff --git a/src/command.h b/src/command.h index a18a82e..87cb557 100644 --- a/src/command.h +++ b/src/command.h @@ -34,10 +34,12 @@ char const * gsm_command_get_command(GSMCommand * gsmc); GSMError gsm_command_get_error(GSMCommand * gsmc); GSMMode gsm_command_get_mode(GSMCommand * gsmc); GSMPriority gsm_command_get_priority(GSMCommand * gsmc); +unsigned int gsm_command_get_timeout(GSMCommand * gsmc); void gsm_command_set_callback(GSMCommand * gsmc, GSMCommandCallback callback); void gsm_command_set_error(GSMCommand * gsmc, GSMError error); void gsm_command_set_mode(GSMCommand * gsmc, GSMMode mode); void gsm_command_set_priority(GSMCommand * gsmc, GSMPriority priority); +void gsm_command_set_timeout(GSMCommand * gsmc, unsigned int timeout); #endif /* !PHONE_COMMAND_H */ diff --git a/src/gsm.c b/src/gsm.c index 094799c..7ca8710 100644 --- a/src/gsm.c +++ b/src/gsm.c @@ -1797,6 +1797,7 @@ static gboolean _on_watch_can_write(GIOChannel * source, GIOCondition condition, GIOStatus status; char * p; GSMCommand * gsmc; + unsigned int timeout = 2000; #ifdef DEBUG fprintf(stderr, "DEBUG: %s() cnt=%lu\n", __func__, gsm->wr_buf_cnt); @@ -1839,10 +1840,14 @@ static gboolean _on_watch_can_write(GIOChannel * source, GIOCondition condition, else { if(gsm->queue != NULL && (gsmc = gsm->queue->data) != NULL) + { gsm->mode = gsm_command_get_mode(gsmc); + timeout = gsm_command_get_timeout(gsmc); + } if(gsm->source != 0) g_source_remove(gsm->source); - gsm->source = g_timeout_add(2000, _on_timeout, gsm); + if(timeout != 0) + gsm->source = g_timeout_add(timeout, _on_timeout, gsm); } return FALSE; } diff --git a/src/modem.c b/src/modem.c index 62aee9f..32ba54a 100644 --- a/src/modem.c +++ b/src/modem.c @@ -38,6 +38,8 @@ static int _is_code(char const * code); static int _is_figure(int c); static int _is_number(char const * number); +static int _modem_call_do(GSM * gsm, char const * command); + /* public */ /* functions */ @@ -94,8 +96,7 @@ int gsm_modem_call(GSMModem * gsmm, GSMCallType calltype, char const * number) if((buf = malloc(len)) == NULL) return 1; snprintf(buf, len, "%s%s%s", cmd, number, suffix); - ret = gsm_queue_full(gsmm->gsm, GSM_PRIORITY_HIGH, buf, - GSM_ERROR_CALL_FAILED, NULL); + ret = _modem_call_do(gsmm->gsm, buf); free(buf); return ret; } @@ -137,8 +138,7 @@ int gsm_modem_call_contact(GSMModem * gsmm, GSMCallType calltype, return 1; } snprintf(buf, sizeof(buf), "%s%u%s", cmd, index, suffix); - return gsm_queue_full(gsmm->gsm, GSM_PRIORITY_HIGH, buf, - GSM_ERROR_CALL_FAILED, NULL); + return _modem_call_do(gsmm->gsm, buf); } @@ -177,8 +177,7 @@ int gsm_modem_call_last(GSMModem * gsmm, GSMCallType calltype) default: return 1; } - return gsm_queue_full(gsmm->gsm, GSM_PRIORITY_HIGH, cmd, - GSM_ERROR_CALL_FAILED, NULL); + return _modem_call_do(gsmm->gsm, cmd); } @@ -788,3 +787,21 @@ static int _is_number(char const * number) return 0; return 1; } + + +/* modem_call_queue */ +static int _modem_call_do(GSM * gsm, char const * command) +{ + GSMCommand * gsmc; + + if((gsmc = gsm_command_new(command)) == NULL) + return 1; + gsm_command_set_priority(gsmc, GSM_PRIORITY_HIGH); + gsm_command_set_error(gsmc, GSM_ERROR_CALL_FAILED); + gsm_command_set_callback(gsmc, NULL); + gsm_command_set_timeout(gsmc, 30000); + if(gsm_queue_command(gsm, gsmc) == 0) + return 0; + gsm_command_delete(gsmc); + return 1; +}