Longer timeout when calling (should fix some modems eg Openmoko Freerunner)

This commit is contained in:
Pierre Pronchery 2010-05-12 11:38:56 +00:00
parent 7a7d96158f
commit 0a6e11eecc
4 changed files with 47 additions and 7 deletions

View File

@ -31,6 +31,7 @@ struct _GSMCommand
{ {
GSMPriority priority; GSMPriority priority;
char * command; char * command;
unsigned int timeout;
GSMError error; GSMError error;
GSMCommandCallback callback; GSMCommandCallback callback;
GSMMode mode; GSMMode mode;
@ -51,6 +52,7 @@ GSMCommand * gsm_command_new(char const * command)
return NULL; /* XXX report error */ return NULL; /* XXX report error */
gsmc->priority = GSM_PRIORITY_NORMAL; gsmc->priority = GSM_PRIORITY_NORMAL;
gsmc->command = strdup(command); gsmc->command = strdup(command);
gsmc->timeout = 2000;
gsmc->error = GSM_ERROR_UNKNOWN; gsmc->error = GSM_ERROR_UNKNOWN;
gsmc->callback = NULL; gsmc->callback = NULL;
gsmc->mode = GSM_MODE_COMMAND; 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 */ /* gsm_command_set_callback */
void gsm_command_set_callback(GSMCommand * gsmc, void gsm_command_set_callback(GSMCommand * gsmc,
GSMCommandCallback callback) GSMCommandCallback callback)
@ -138,3 +147,10 @@ void gsm_command_set_priority(GSMCommand * gsmc, GSMPriority priority)
{ {
gsmc->priority = priority; gsmc->priority = priority;
} }
/* gsm_command_set_timeout */
void gsm_command_set_timeout(GSMCommand * gsmc, unsigned int timeout)
{
gsmc->timeout = timeout;
}

View File

@ -34,10 +34,12 @@ char const * gsm_command_get_command(GSMCommand * gsmc);
GSMError gsm_command_get_error(GSMCommand * gsmc); GSMError gsm_command_get_error(GSMCommand * gsmc);
GSMMode gsm_command_get_mode(GSMCommand * gsmc); GSMMode gsm_command_get_mode(GSMCommand * gsmc);
GSMPriority gsm_command_get_priority(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_callback(GSMCommand * gsmc, GSMCommandCallback callback);
void gsm_command_set_error(GSMCommand * gsmc, GSMError error); void gsm_command_set_error(GSMCommand * gsmc, GSMError error);
void gsm_command_set_mode(GSMCommand * gsmc, GSMMode mode); void gsm_command_set_mode(GSMCommand * gsmc, GSMMode mode);
void gsm_command_set_priority(GSMCommand * gsmc, GSMPriority priority); void gsm_command_set_priority(GSMCommand * gsmc, GSMPriority priority);
void gsm_command_set_timeout(GSMCommand * gsmc, unsigned int timeout);
#endif /* !PHONE_COMMAND_H */ #endif /* !PHONE_COMMAND_H */

View File

@ -1797,6 +1797,7 @@ static gboolean _on_watch_can_write(GIOChannel * source, GIOCondition condition,
GIOStatus status; GIOStatus status;
char * p; char * p;
GSMCommand * gsmc; GSMCommand * gsmc;
unsigned int timeout = 2000;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s() cnt=%lu\n", __func__, gsm->wr_buf_cnt); 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 else
{ {
if(gsm->queue != NULL && (gsmc = gsm->queue->data) != NULL) if(gsm->queue != NULL && (gsmc = gsm->queue->data) != NULL)
{
gsm->mode = gsm_command_get_mode(gsmc); gsm->mode = gsm_command_get_mode(gsmc);
timeout = gsm_command_get_timeout(gsmc);
}
if(gsm->source != 0) if(gsm->source != 0)
g_source_remove(gsm->source); 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; return FALSE;
} }

View File

@ -38,6 +38,8 @@ static int _is_code(char const * code);
static int _is_figure(int c); static int _is_figure(int c);
static int _is_number(char const * number); static int _is_number(char const * number);
static int _modem_call_do(GSM * gsm, char const * command);
/* public */ /* public */
/* functions */ /* functions */
@ -94,8 +96,7 @@ int gsm_modem_call(GSMModem * gsmm, GSMCallType calltype, char const * number)
if((buf = malloc(len)) == NULL) if((buf = malloc(len)) == NULL)
return 1; return 1;
snprintf(buf, len, "%s%s%s", cmd, number, suffix); snprintf(buf, len, "%s%s%s", cmd, number, suffix);
ret = gsm_queue_full(gsmm->gsm, GSM_PRIORITY_HIGH, buf, ret = _modem_call_do(gsmm->gsm, buf);
GSM_ERROR_CALL_FAILED, NULL);
free(buf); free(buf);
return ret; return ret;
} }
@ -137,8 +138,7 @@ int gsm_modem_call_contact(GSMModem * gsmm, GSMCallType calltype,
return 1; return 1;
} }
snprintf(buf, sizeof(buf), "%s%u%s", cmd, index, suffix); snprintf(buf, sizeof(buf), "%s%u%s", cmd, index, suffix);
return gsm_queue_full(gsmm->gsm, GSM_PRIORITY_HIGH, buf, return _modem_call_do(gsmm->gsm, buf);
GSM_ERROR_CALL_FAILED, NULL);
} }
@ -177,8 +177,7 @@ int gsm_modem_call_last(GSMModem * gsmm, GSMCallType calltype)
default: default:
return 1; return 1;
} }
return gsm_queue_full(gsmm->gsm, GSM_PRIORITY_HIGH, cmd, return _modem_call_do(gsmm->gsm, cmd);
GSM_ERROR_CALL_FAILED, NULL);
} }
@ -788,3 +787,21 @@ static int _is_number(char const * number)
return 0; return 0;
return 1; 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;
}