gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnokii and Motorola C350


From: Ron Yorston
Subject: gnokii and Motorola C350
Date: Sun, 1 Feb 2004 20:43:25 GMT

I've made some further changes to get gnokii to work better with the
Motorola C350.  With my patches from last week (which are now in CVS)
xgnokii can read the contents of the phone's phonebook memory.  However,
it can't see phonebook entries in the SIM card.

Here's what happens when xgnokii tries to determine the number of
phonebook entries:

write: [AT+CPBS="ME"<cr>]
read : [AT+CPBS="ME"<cr><cr><lf>OK<cr><lf>]
write: [AT+CPBS?<cr>]
read : [AT+CPBS?<cr><cr><lf>+CPBS: "ME"<cr><lf><cr><lf>OK<cr><lf>]
write: [AT+CPBR=?<cr>]
read : [AT+CPBR=?<cr><cr><lf>+CPBR: 1-100,40,24<cr><lf><cr><lf>OK<cr><lf>]
write: [AT+CPBS="SM"<cr>]
read : [AT+CPBS="SM"<cr><cr><lf>OK<cr><lf>]
write: [AT+CPBS?<cr>]
read : [AT+CPBS?<cr><cr><lf>+CPBS: "SM"<cr><lf><cr><lf>OK<cr><lf>]
write: [AT+CPBR=?<cr>]
read : [AT+CPBR=?<cr><cr><lf>+CPBR: 101-300,40,14<cr><lf><cr><lf>OK<cr><lf>]

There are a number of things to note here:

   The '+CPBS?' query doesn't return the number of used/total entries in
   the phonebook.  This is permitted by the standard, as the return of
   these values is optional.  Since no values are provided the code in
   ReplyMemoryStatus (atgen.c) defaults to 100 used entries and 0 free.

   The number of entries in the phonebooks can be derived from the
   response to the '+CPBR=?' query.  The first item here is the range
   of supported index values.  The code in AT_GetMemoryStatus issues the
   '+CPBR=?' query, but ReplyMemoryStatus doesn't make any use of it.

   By my reading of the standard the range of supported index values
   should be placed in brackets, but the Motorola doesn't do that.

   The supported range of index values for the SIM phonebook memory in
   the Motorola C350 is 101-300, whereas the code in xgnokii_contacts.c
   assumes that the first index value for each type of memory is 1.

The patch below addresses some of these issues.  I've added an element to
the gn_memory_status structure to hold the first index value for each type
of memory.  In gnokii.c this is initialised to 1 when the structures are
created.  At present this structure element isn't being used.

I've added code to ReplyMemoryStatus to parse the response to the '+CPBR=?'
query (allowing for the fact that the range may be enclosed in brackets).
The number of indices determined from this takes precedence over the
number from '+CPBS?'.

I've also fixed a problem that was introduced when my last patch was
applied:  the literal string arguments to reply_simpletext in ReplyIdentify
were intended to have a trailing space.

Without this patch xgnokii couldn't see entries in the SIM phonebook
because it was looking at indices 1-100.  With this patch xgnokii
searches the SIM for indices 1-200, so it finds entries in the first
half of the SIM (101-200), but not the second half (201-300).  A proper
fix requires more work in xgnokii_contacts.c to remove the assumption
that the first index of all memories is 1.  I've started to look into
this, but the necessary changes are quite extensive and will affect all
models, not just AT models.  In the meantime the patch below (against
CVS) improves the situation for the Motorola C350 and shouldn't break
anything else.

Ron

---
--- gnokii/include/gnokii/common.h      2004-01-18 16:58:54.000000000 +0000
+++ gnokii.rmy/include/gnokii/common.h  2004-02-01 19:05:51.000000000 +0000
@@ -145,6 +145,7 @@
        gn_memory_type memory_type; /* Type of the memory */
        int used;                   /* Number of used positions */
        int free;                   /* Number of free positions */
+       int first;                  /* Index of first position */
 } gn_memory_status;
 
 /* General date and time structure. It is used for the SMS, calendar, alarm
--- gnokii/common/phones/atgen.c        2004-02-01 20:28:52.000000000 +0000
+++ gnokii.rmy/common/phones/atgen.c    2004-02-01 20:37:25.000000000 +0000
@@ -147,6 +147,19 @@
        return s;
 }
 
+static char *strip_brackets(char *s)
+{
+       char *t ;
+
+       if (*s == '(') {
+               if ((t = strrchr(++s, ')'))) {
+                       *t = '\0';
+               }
+       }
+
+       return s;
+}
+
 static void reply_simpletext(char *l1, char *l2, char *c, char *t)
 {
        if ((strncmp(l1, c, 5) == 0) && (t != NULL)) {
@@ -956,7 +969,7 @@
 static gn_error ReplyMemoryStatus(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state)
 {
        at_line_buffer buf;
-       char *pos;
+       char *pos, *s, *t;
 
        if (buffer[0] != GN_AT_OK)
                return GN_ERR_INVALIDMEMORYTYPE;
@@ -967,6 +980,7 @@
        splitlines(&buf);
 
        if (data->memory_status && strstr(buf.line2,"+CPBS")) {
+               data->memory_status->first = 1;
                pos = strchr(buf.line2, ',');
                if (pos) {
                        data->memory_status->used = atoi(++pos);
@@ -981,6 +995,25 @@
                } else {
                        return GN_ERR_UNKNOWN;
                }
+       } else if (data->memory_status && strncmp(buf.line2,"+CPBR: ",7) == 0) {
+               s = buf.line2+7;
+               pos = strchr(s, ',');
+               if (pos) {
+                       *pos = '\0';
+                       s = strip_brackets(s);
+                       t = strchr(s, '-');
+                       if (t) {
+                               int first, last;
+                               first = atoi(s);
+                               last = atoi(t+1);
+                               data->memory_status->first = first;
+                               if ( 
data->memory_status->free+data->memory_status->used !=
+                                               last-first+1 ) {
+                                       data->memory_status->used = 
last-first+1;
+                                       data->memory_status->free = 0;
+                               }
+                       }
+               }
        }
        return GN_ERR_NONE;
 }
@@ -1054,10 +1087,10 @@
        buf.length = length;
        splitlines(&buf);
        if (!strncmp(buf.line1, "AT+CG", 5)) {
-               reply_simpletext(buf.line1+2, buf.line2, "+CGSN:", data->imei);
-               reply_simpletext(buf.line1+2, buf.line2, "+CGMM:", data->model);
-               reply_simpletext(buf.line1+2, buf.line2, "+CGMI:", 
data->manufacturer);
-               reply_simpletext(buf.line1+2, buf.line2, "+CGMR:", 
data->revision);
+               reply_simpletext(buf.line1+2, buf.line2, "+CGSN: ", data->imei);
+               reply_simpletext(buf.line1+2, buf.line2, "+CGMM: ", 
data->model);
+               reply_simpletext(buf.line1+2, buf.line2, "+CGMI: ", 
data->manufacturer);
+               reply_simpletext(buf.line1+2, buf.line2, "+CGMR: ", 
data->revision);
        }
        return GN_ERR_NONE;
 }
--- gnokii/gnokii/gnokii.c      2004-02-01 15:06:18.000000000 +0000
+++ gnokii.rmy/gnokii/gnokii.c  2004-02-01 19:32:32.000000000 +0000
@@ -2616,15 +2616,15 @@
 
        gn_network_info networkinfo;
        gn_cb_message cbmessage;
-       gn_memory_status simmemorystatus   = {GN_MT_SM, 0, 0};
-       gn_memory_status phonememorystatus = {GN_MT_ME, 0, 0};
-       gn_memory_status dc_memorystatus   = {GN_MT_DC, 0, 0};
-       gn_memory_status en_memorystatus   = {GN_MT_EN, 0, 0};
-       gn_memory_status fd_memorystatus   = {GN_MT_FD, 0, 0};
-       gn_memory_status ld_memorystatus   = {GN_MT_LD, 0, 0};
-       gn_memory_status mc_memorystatus   = {GN_MT_MC, 0, 0};
-       gn_memory_status on_memorystatus   = {GN_MT_ON, 0, 0};
-       gn_memory_status rc_memorystatus   = {GN_MT_RC, 0, 0};
+       gn_memory_status simmemorystatus   = {GN_MT_SM, 0, 0, 1};
+       gn_memory_status phonememorystatus = {GN_MT_ME, 0, 0, 1};
+       gn_memory_status dc_memorystatus   = {GN_MT_DC, 0, 0, 1};
+       gn_memory_status en_memorystatus   = {GN_MT_EN, 0, 0, 1};
+       gn_memory_status fd_memorystatus   = {GN_MT_FD, 0, 0, 1};
+       gn_memory_status ld_memorystatus   = {GN_MT_LD, 0, 0, 1};
+       gn_memory_status mc_memorystatus   = {GN_MT_MC, 0, 0, 1};
+       gn_memory_status on_memorystatus   = {GN_MT_ON, 0, 0, 1};
+       gn_memory_status rc_memorystatus   = {GN_MT_RC, 0, 0, 1};
 
        gn_sms_status smsstatus = {0, 0, 0, 0};
        /*




reply via email to

[Prev in Thread] Current Thread [Next in Thread]