gnokii-users
[Top][All Lists]
Advanced

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

Motorola C350 patch 1


From: Ron Yorston
Subject: Motorola C350 patch 1
Date: Sun, 15 Feb 2004 11:34:33 GMT

I've reworked my patch to support the way the Motorola C350 handles
indices into phonebook memory.  The treatment of the range of indices
is now internal to the atgen driver.  Programs which call the driver
can continue to use 1 as the first index into phonebook memory.  This
means that no changes are required to xgnokii.

Ron

---
*** gnokii/include/phones/atgen.h       2003-01-21 11:07:58.000000000 +0000
--- gnokii.latest/include/phones/atgen.h        2004-02-15 10:40:53.000000000 
+0000
***************
*** 39,44 ****
--- 39,45 ----
        GN_OP_AT_SetCharset,
        GN_OP_AT_SetPDUMode,
        GN_OP_AT_Prompt,
+       GN_OP_AT_GetMemoryRange,
        GN_OP_AT_Max    /* don't append anything after this entry */
  } at_operation;
  
***************
*** 63,68 ****
--- 64,71 ----
        int if_pos;
  
        gn_memory_type memorytype;
+       int memoryoffset;
+       int memorysize;
        gn_memory_type smsmemorytype;
        at_charset availcharsets;
        at_charset defaultcharset;
*** gnokii/common/phones/atgen.c        2004-02-03 21:26:28.000000000 +0000
--- gnokii.latest/common/phones/atgen.c 2004-02-15 10:40:52.000000000 +0000
***************
*** 53,58 ****
--- 53,59 ----
  static gn_error ReplyGetBattery(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state);
  static gn_error ReplyReadPhonebook(int messagetype, unsigned char *buffer, 
int length, gn_data *data, struct gn_statemachine *state);
  static gn_error ReplyMemoryStatus(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state);
+ static gn_error ReplyMemoryRange(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state);
  static gn_error ReplyCallDivert(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state);
  static gn_error ReplyGetPrompt(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state);
  static gn_error ReplyGetSMSStatus(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state);
***************
*** 72,77 ****
--- 73,79 ----
  static gn_error AT_GetBattery(gn_data *data,  struct gn_statemachine *state);
  static gn_error AT_GetRFLevel(gn_data *data,  struct gn_statemachine *state);
  static gn_error AT_GetMemoryStatus(gn_data *data,  struct gn_statemachine 
*state);
+ static gn_error AT_GetMemoryRange(gn_data *data,  struct gn_statemachine 
*state);
  static gn_error AT_ReadPhonebook(gn_data *data,  struct gn_statemachine 
*state);
  static gn_error AT_WritePhonebook(gn_data *data,  struct gn_statemachine 
*state);
  static gn_error AT_DeletePhonebook(gn_data *data,  struct gn_statemachine 
*state);
***************
*** 112,117 ****
--- 114,120 ----
        { GN_OP_GetPowersource,        AT_GetBattery,            
ReplyGetBattery },
        { GN_OP_GetRFLevel,            AT_GetRFLevel,            
ReplyGetRFLevel },
        { GN_OP_GetMemoryStatus,       AT_GetMemoryStatus,       
ReplyMemoryStatus },
+       { GN_OP_AT_GetMemoryRange,     AT_GetMemoryRange,        
ReplyMemoryRange },
        { GN_OP_ReadPhonebook,         AT_ReadPhonebook,         
ReplyReadPhonebook },
        { GN_OP_WritePhonebook,        AT_WritePhonebook,        Reply },
        { GN_OP_DeletePhonebook,       AT_DeletePhonebook,       Reply },
***************
*** 147,152 ****
--- 150,168 ----
        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)) {
***************
*** 320,325 ****
--- 336,344 ----
                ret = sm_block_no_retry(GN_OP_Init, &data, state);
                if (ret == GN_ERR_NONE)
                        drvinst->memorytype = mt;
+ 
+               gn_data_clear(&data);
+               ret = state->driver.functions(GN_OP_AT_GetMemoryRange, &data, 
state);
        }
        return ret;
  }
***************
*** 505,512 ****
--- 524,542 ----
        return sm_block_no_retry(GN_OP_GetMemoryStatus, data, state);
  }
  
+ static gn_error AT_GetMemoryRange(gn_data *data, struct gn_statemachine 
*state)
+ {
+       gn_error ret;
+ 
+       ret = sm_message_send(10, GN_OP_AT_GetMemoryRange, "AT+CPBR=?\r", 
state);
+       if (ret)
+               return GN_ERR_NOTREADY;
+       return sm_block_no_retry(GN_OP_AT_GetMemoryRange, data, state);
+ }
+ 
  static gn_error AT_ReadPhonebook(gn_data *data, struct gn_statemachine *state)
  {
+       at_driver_instance *drvinst = AT_DRVINST(state);
        char req[32];
        gn_error ret;
  
***************
*** 516,522 ****
        ret = at_memory_type_set(data->phonebook_entry->memory_type, state);
        if (ret)
                return ret;
!       sprintf(req, "AT+CPBR=%d\r", data->phonebook_entry->location);
        if (sm_message_send(strlen(req), GN_OP_ReadPhonebook, req, state))
                return GN_ERR_NOTREADY;
        return sm_block_no_retry(GN_OP_ReadPhonebook, data, state);
--- 546,552 ----
        ret = at_memory_type_set(data->phonebook_entry->memory_type, state);
        if (ret)
                return ret;
!       sprintf(req, "AT+CPBR=%d\r", 
data->phonebook_entry->location+drvinst->memoryoffset);
        if (sm_message_send(strlen(req), GN_OP_ReadPhonebook, req, state))
                return GN_ERR_NOTREADY;
        return sm_block_no_retry(GN_OP_ReadPhonebook, data, state);
***************
*** 539,545 ****
                if (ret)
                        return ret;
                ofs = sprintf(req, "AT+CPBW=%d,\"%s\",%s,\"",
!                             data->phonebook_entry->location,
                              data->phonebook_entry->number,
                              data->phonebook_entry->number[0] == '+' ? "145" : 
"129");
                len = strlen(data->phonebook_entry->name);
--- 569,575 ----
                if (ret)
                        return ret;
                ofs = sprintf(req, "AT+CPBW=%d,\"%s\",%s,\"",
!                             
data->phonebook_entry->location+drvinst->memoryoffset,
                              data->phonebook_entry->number,
                              data->phonebook_entry->number[0] == '+' ? "145" : 
"129");
                len = strlen(data->phonebook_entry->name);
***************
*** 570,575 ****
--- 600,606 ----
  
  static gn_error AT_DeletePhonebook(gn_data *data, struct gn_statemachine 
*state)
  {
+       at_driver_instance *drvinst = AT_DRVINST(state);
        int len;
        char req[64];
        gn_error ret;
***************
*** 581,587 ****
        if (ret)
                return ret;
  
!       len = sprintf(req, "AT+CPBW=%d\r", data->phonebook_entry->location);
  
        if (sm_message_send(len, GN_OP_DeletePhonebook, req, state))
                return GN_ERR_NOTREADY;
--- 612,618 ----
        if (ret)
                return ret;
  
!       len = sprintf(req, "AT+CPBW=%d\r", 
data->phonebook_entry->location+drvinst->memoryoffset);
  
        if (sm_message_send(len, GN_OP_DeletePhonebook, req, state))
                return GN_ERR_NOTREADY;
***************
*** 956,961 ****
--- 987,993 ----
  
  static gn_error ReplyMemoryStatus(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state)
  {
+       at_driver_instance *drvinst = AT_DRVINST(state);
        at_line_buffer buf;
        char *pos;
  
***************
*** 972,978 ****
                if (pos) {
                        data->memory_status->used = atoi(++pos);
                } else {
!                       data->memory_status->used = 100;
                        data->memory_status->free = 0;
                        return GN_ERR_UNKNOWN;
                }
--- 1004,1010 ----
                if (pos) {
                        data->memory_status->used = atoi(++pos);
                } else {
!                       data->memory_status->used = drvinst->memorysize;
                        data->memory_status->free = 0;
                        return GN_ERR_UNKNOWN;
                }
***************
*** 986,991 ****
--- 1018,1060 ----
        return GN_ERR_NONE;
  }
  
+ static gn_error ReplyMemoryRange(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state)
+ {
+       at_driver_instance *drvinst = AT_DRVINST(state);
+       at_line_buffer buf;
+       char *pos, *s, *t;
+ 
+       drvinst->memoryoffset = 0;
+       drvinst->memorysize = 100;
+ 
+       if (buffer[0] != GN_AT_OK)
+               return GN_ERR_UNKNOWN;
+ 
+       buf.line1 = buffer + 1;
+       buf.length= length;
+ 
+       splitlines(&buf);
+ 
+       if (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);
+                               drvinst->memoryoffset = first-1;
+                               drvinst->memorysize = last-first+1;
+                       }
+               }
+       }
+ 
+       return GN_ERR_NONE;
+ }
+ 
  static gn_error ReplyGetBattery(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state)
  {
        at_line_buffer buf;
***************
*** 1409,1414 ****
--- 1478,1485 ----
        state->driver.incoming_functions = drvinst->incoming_functions;
        AT_DRVINST(state) = drvinst;
        drvinst->memorytype = GN_MT_XX;
+       drvinst->memoryoffset = 0;
+       drvinst->memorysize = 100;
        drvinst->smsmemorytype = GN_MT_XX;
        drvinst->defaultcharset = AT_CHAR_UNKNOWN;
        drvinst->charset = AT_CHAR_UNKNOWN;




reply via email to

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