Fetching messages in text mode for the moment

This commit is contained in:
Pierre Pronchery 2010-05-11 10:31:10 +00:00
parent 0bb228fe93
commit 9ba6e09f06
3 changed files with 32 additions and 11 deletions

View File

@ -539,6 +539,8 @@ int gsm_event(GSM * gsm, GSMEventType type, ...)
case GSM_EVENT_TYPE_MESSAGE: case GSM_EVENT_TYPE_MESSAGE:
/* FIXME implement correctly */ /* FIXME implement correctly */
event->message.index = va_arg(ap, unsigned int); event->message.index = va_arg(ap, unsigned int);
event->message.date = va_arg(ap, time_t);
event->message.length = va_arg(ap, unsigned int);
event->message.content = va_arg(ap, char const *); event->message.content = va_arg(ap, char const *);
break; break;
case GSM_EVENT_TYPE_MESSAGE_LIST: case GSM_EVENT_TYPE_MESSAGE_LIST:
@ -602,6 +604,7 @@ int gsm_fetch_message_list(GSM * gsm, GSMMessageList list)
/* gsm_fetch_message */ /* gsm_fetch_message */
int gsm_fetch_message(GSM * gsm, unsigned int index) int gsm_fetch_message(GSM * gsm, unsigned int index)
{ {
gsm->event.message.index = index; /* FIXME may be over-written */
return gsm_modem_get_message(gsm->modem, index); return gsm_modem_get_message(gsm->modem, index);
} }
@ -1210,21 +1213,36 @@ static int _gsm_trigger_cmgl(GSM * gsm, char const * result)
/* gsm_trigger_cmgr */ /* gsm_trigger_cmgr */
static int _gsm_trigger_cmgr(GSM * gsm, char const * result) static int _gsm_trigger_cmgr(GSM * gsm, char const * result)
{ {
unsigned int stat; char buf[32];
char date[32];
unsigned int mbox;
unsigned int alpha = 0; unsigned int alpha = 0;
unsigned int length; unsigned int * length = &gsm->event.message.length;
struct tm t;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, result); fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, result);
#endif #endif
/* FIXME implement: /* FIXME report which mailbox contains the message? */
* - store the index (and length?) somewhere /* text mode support */
* - then we (blindly) parse the PDU and report the message */ if(sscanf(result, "\"%31[^\"]\",\"%31[^\"]\",,\"%31[^\"]\"", buf,
if(sscanf(result, "%u,%u,%u", &stat, &alpha, &length) == 3 buf, date) == 3) /* FIXME really implement */
|| sscanf(result, "%u,,%u", &stat, &length) == 2) {
date[sizeof(date) - 1] = '\0';
if(strptime(date, "%y/%m/%d,%T", &t) == NULL) /* XXX timezone */
localtime_r(NULL, &t);
gsm->event.message.date = mktime(&t);
*length = 0;
return 0; /* we need to wait for the next line */
}
/* PDU mode support */
if(sscanf(result, "%u,%u,%u", &mbox, &alpha, length) == 3
|| sscanf(result, "%u,,%u", &mbox, length) == 2)
return 0; return 0;
/* FIXME actually parse the PDU */ /* message content */
gsm->event.message.index = 0; /* FIXME implement */ if(*length == 0) /* XXX assumes this is text mode */
gsm->event.message.content = result;
else /* FIXME actually parse the PDU */
gsm->event.message.content = result; gsm->event.message.content = result;
return _gsm_event_send(gsm, GSM_EVENT_TYPE_MESSAGE); return _gsm_event_send(gsm, GSM_EVENT_TYPE_MESSAGE);
} }

View File

@ -222,6 +222,8 @@ typedef union _GSMEvent
{ {
GSMEventType type; GSMEventType type;
unsigned int index; unsigned int index;
time_t date;
unsigned int length; /* XXX may be removed */
char const * content; char const * content;
} message; } message;

View File

@ -286,7 +286,8 @@ int gsm_modem_get_message(GSMModem * gsmm, unsigned int index)
{ {
char cmd[32]; char cmd[32];
if(gsm_modem_set_message_format(gsmm, GSM_MESSAGE_FORMAT_PDU) != 0) /* FIXME should default to PDU mode */
if(gsm_modem_set_message_format(gsmm, GSM_MESSAGE_FORMAT_TEXT) != 0)
return 1; return 1;
snprintf(cmd, sizeof(cmd), "%s%u", "AT+CMGR=", index); snprintf(cmd, sizeof(cmd), "%s%u", "AT+CMGR=", index);
/* XXX race condition here if the user forces out of PDU mode */ /* XXX race condition here if the user forces out of PDU mode */