[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [patch] Use +CPMS (SMS preferred memory store) more correctly.
From: |
David Vrabel |
Subject: |
Re: [patch] Use +CPMS (SMS preferred memory store) more correctly. |
Date: |
Wed, 12 Jan 2005 15:56:41 +0000 |
User-agent: |
Mozilla Thunderbird 0.9 (X11/20041124) |
David Vrabel wrote:
Attached is an updated patch...
--
David Vrabel, Design Engineer
Arcom, Clifton Road Tel: +44 (0)1223 411200 ext. 3233
Cambridge CB1 7EA, UK Web: http://www.arcom.com/
diff -ur gnokii-0.6.4.orig/common/phones/atgen.c
gnokii-0.6.4/common/phones/atgen.c
--- gnokii-0.6.4.orig/common/phones/atgen.c Sun Oct 17 20:44:21 2004
+++ gnokii-0.6.4/common/phones/atgen.c Wed Jan 12 15:00:26 2005
@@ -519,19 +519,36 @@
return ret;
}
+/* GSM 07.05 section 3.2.3 specified the +CPMS (Preferred Message Store) AT
+ * command as taking 3 memory parameters <mem1>, <mem2> and <mem3>. Each of
+ * these stores is used for different purposes:
+ * <mem1> - memory from which messages are read and deleted
+ * <mem2> - memory to which writing and sending operations are made
+ * <mem3> - memory to which received SMs are preferred to be stored
+ *
+ * To avoid confusing the user by changing <mem3> we set it to the current
+ * setting.
+ */
gn_error AT_SetSMSMemoryType(gn_memory_type mt, struct gn_statemachine *state)
{
at_driver_instance *drvinst = AT_DRVINST(state);
gn_data data;
+ gn_sms_status sms_status;
char req[32];
gn_error ret = GN_ERR_NONE;
if (mt != drvinst->smsmemorytype) {
- sprintf(req, "AT+CPMS=\"%s\"\r", memorynames[mt]);
- ret = sm_message_send(13, GN_OP_Init, req, state);
+ gn_data_clear(&data);
+ data.sms_status = &sms_status;
+ ret = AT_GetSMSStatus(&data, state);
+ if (ret != GN_ERR_NONE)
+ return ret;
+
+ sprintf(req, "AT+CPMS=\"%s\",\"%s\",\"%s\"\r", memorynames[mt],
memorynames[mt],
+ memorynames[data.sms_status->new_message_store]);
+ ret = sm_message_send(23, GN_OP_Init, req, state);
if (ret != GN_ERR_NONE)
return GN_ERR_NOTREADY;
- gn_data_clear(&data);
ret = sm_block_no_retry(GN_OP_Init, &data, state);
if (ret == GN_ERR_NONE)
drvinst->smsmemorytype = mt;
@@ -830,7 +847,13 @@
if (!data->sms_status) return GN_ERR_INTERNALERROR;
- ret = sm_message_send(13, GN_OP_GetSMSStatus, "AT+CPMS=\"SM\"\r",
state);
+ if (data->memory_status) {
+ ret = AT_SetSMSMemoryType(data->memory_status->memory_type,
state);
+ if (ret != GN_ERR_NONE)
+ return ret;
+ }
+
+ ret = sm_message_send(9, GN_OP_GetSMSStatus, "AT+CPMS?\r", state);
if (ret != GN_ERR_NONE)
return GN_ERR_NOTREADY;
return sm_block_no_retry(GN_OP_GetSMSStatus, data, state);
@@ -1317,6 +1340,8 @@
{
at_line_buffer buf;
gn_error error;
+ char store[3] = "XX";
+ int i;
if ((error = at_error_get(buffer, state)) != GN_ERR_NONE) return error;
@@ -1324,12 +1349,21 @@
buf.length = length;
splitlines(&buf);
- if (sscanf(buf.line2, "+CPMS: %d", &data->sms_status->number) != 1)
+ if (sscanf(buf.line2, "+CPMS:
\"%*c%*c\",%d,%*d,\"%*c%*c\",%*d,%*d,\"%c%c\",%*d,%*d",
+ &data->sms_status->number, &store[0], &store[1]) != 3)
return GN_ERR_FAILED;
data->sms_status->unread = 0;
data->sms_status->changed = 0;
data->sms_status->folders_count = 0;
+
+ data->sms_status->new_message_store = GN_MT_ME;
+ for (i = 0; i < sizeof(memorynames)/sizeof(char *); i++) {
+ if (strcmp(store, memorynames[i]) == 0) {
+ data->sms_status->new_message_store = i;
+ break;
+ }
+ }
return GN_ERR_NONE;
}
diff -ur gnokii-0.6.4.orig/include/gnokii/sms.h
gnokii-0.6.4/include/gnokii/sms.h
--- gnokii-0.6.4.orig/include/gnokii/sms.h Sun Oct 17 20:44:22 2004
+++ gnokii-0.6.4/include/gnokii/sms.h Wed Jan 12 13:47:50 2005
@@ -75,6 +75,9 @@
unsigned int changed;
/* Number of Folders we get from GetFolders */
unsigned int folders_count;
+ /* Message store used for new received messages (this is used
+ * internally by AT_SetSMSMemoryType() in common/phones/atgen.c). */
+ gn_memory_type new_message_store;
} gn_sms_status;
diff -ur gnokii-0.6.4.orig/smsd/lowlevel.c gnokii-0.6.4/smsd/lowlevel.c
--- gnokii-0.6.4.orig/smsd/lowlevel.c Sun Oct 17 20:44:20 2004
+++ gnokii-0.6.4/smsd/lowlevel.c Wed Jan 12 14:37:56 2005
@@ -237,10 +237,7 @@
{
msg = g_malloc (sizeof (gn_sms));
memset (msg, 0, sizeof (gn_sms));
- if (phoneMonitor.supported & PM_FOLDERS)
- msg->memory_type = GN_MT_IN;
- else
- msg->memory_type = GN_MT_SM;
+ msg->memory_type = smsdConfig.memoryType;
msg->number = ++i;
data.sms = msg;
@@ -371,6 +368,13 @@
exit (1);
}
+ if (smsdConfig.memoryType == GN_MT_XX) {
+ if (phoneMonitor.supported & PM_FOLDERS)
+ smsdConfig.memoryType = GN_MT_IN;
+ else
+ smsdConfig.memoryType = GN_MT_SM;
+ }
+
gn_log_xdebug ("Phone connected. Starting monitoring...\n");
while (1)
@@ -380,7 +384,7 @@
if (phoneMonitor.supported & PM_FOLDERS)
{
data->sms_folder = &SMSFolder;
- SMSFolder.folder_id = GN_MT_IN;
+ SMSFolder.folder_id = smsdConfig.memoryType;
if (status && (error = gn_sm_functions (GN_OP_GetSMSFolderStatus, data,
&sm)) == GN_ERR_NONE)
{
if (phoneMonitor.sms.number != SMSFolder.number)
@@ -405,7 +409,11 @@
}
else
{
+ gn_memory_status dummy;
+ dummy.memory_type = smsdConfig.memoryType;
+
data->sms_status = &SMSStatus;
+ data->memory_status = &dummy;
if (status && (error = gn_sm_functions (GN_OP_GetSMSStatus, data, &sm))
== GN_ERR_NONE)
{
if (phoneMonitor.sms.unRead != SMSStatus.unread ||
diff -ur gnokii-0.6.4.orig/smsd/man/smsd.8 gnokii-0.6.4/smsd/man/smsd.8
--- gnokii-0.6.4.orig/smsd/man/smsd.8 Sun Oct 17 20:44:20 2004
+++ gnokii-0.6.4/smsd/man/smsd.8 Wed Jan 12 14:44:52 2005
@@ -253,6 +253,15 @@
sms status this option is ignored.
.TP
+.BR -b,\ --inbox\ memory_type
+Where to look for new messages. For the memory_type you usually use
+SM for the SIM card and ME for the phone memory. The exception are the
+phones supported by nk7110 (Nokia 7110/6210/6250) and nk6510 (Nokia
+6310/6510/8310) drivers. For these you should use IN for the Inbox, OU
+for the Outbox, AR for the Archive, TE for the Templates and F1,
+F2, ... for your own folders.
+
+.TP
.BR -v,\ --version
Shows smsd version.
diff -ur gnokii-0.6.4.orig/smsd/smsd.c gnokii-0.6.4/smsd/smsd.c
--- gnokii-0.6.4.orig/smsd/smsd.c Sun Oct 17 20:44:20 2004
+++ gnokii-0.6.4/smsd/smsd.c Wed Jan 12 14:42:44 2005
@@ -226,6 +226,7 @@
smsdConfig.refreshInt = 1; // Phone querying interval in seconds
smsdConfig.maxSMS = 10; // Smsd uses it if GetSMSStatus isn't
implemented
smsdConfig.smsSets = 0;
+ smsdConfig.memoryType = GN_MT_XX;
while (1)
{
@@ -244,11 +245,12 @@
{"version", 0, 0, 'v'},
{"interval", 1, 0, 'i'},
{"maxsms", 1, 0, 's'},
+ {"inbox", 1, 0, 'b'},
{"help", 0, 0, 'h'},
{0, 0, 0, 0}
};
- c = getopt_long (argc, argv, "u:p:d:c:m:l:f:t:vi:s:h", longOptions,
&optionIndex);
+ c = getopt_long (argc, argv, "u:p:d:c:m:l:f:t:vi:s:b:h", longOptions,
&optionIndex);
if (c == EOF)
break;
switch (c)
@@ -305,6 +307,10 @@
case 's':
smsdConfig.maxSMS = atoi (optarg);
+ break;
+
+ case 'b':
+ smsdConfig.memoryType = gn_str2memory_type (optarg);
break;
case 'v':
diff -ur gnokii-0.6.4.orig/smsd/smsd.h gnokii-0.6.4/smsd/smsd.h
--- gnokii-0.6.4.orig/smsd/smsd.h Sun Oct 17 20:44:20 2004
+++ gnokii-0.6.4/smsd/smsd.h Wed Jan 12 14:14:53 2005
@@ -46,6 +46,7 @@
gint refreshInt;
gint maxSMS;
gint smsSets:4;
+ gn_memory_type memoryType;
} SmsdConfig;
typedef struct {