bladox.com Forum Index bladox.com
Turbo SIM Toolkit Adapter Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

add_data() retrieval behaving inappropriate

 
Post new topic   Reply to topic    bladox.com Forum Index -> Development
View previous topic :: View next topic  
Author Message
tkm



Joined: 18 Jan 2011
Posts: 72

PostPosted: Wed Oct 12, 2011 1:57 pm    Post subject: add_data() retrieval behaving inappropriate Reply with quote

Hello, I am trying to use app_data(). I am trying to save some data and later retrieve them. Before saving I check if the data already exist or not. My prob is it works first time as expected--finds no data as the array is empty;saves the new data and on retrieval says a match is found.

The problem is: when I try to insert another data it says match found;whereas the data shouldn't be there as data being new. I am pretty much sure my algorithm/code is right. But can't sort out this wrong behaviour. I am using call control as well in the program. Does it anyhow affects the data stored in EEPROM? My code:
Code:

typedef struct _Pers_mem
{
  u8 active;
  u8 service_nr[MAX_NR_LEN]; 
  u8 *array_dialing_nr[MAX_NR_AMOUNT];
}
Pers_mem;

////////////////////// The following two lines happens in register function
for (i = 0; i < MAX_NR_AMOUNT; i++)
    ww (&p->array_dialing_nr[i], NULL);
////////////////////////

Pers_mem *p2=app_data ();
for(i=0; i<MAX_NR_AMOUNT;i++)
   {
      val=rw(&p2->array_dialing_nr[i]);             
      if(val==NULL)
      {
         dbsp ("\nBreaking out\n");
         break;      
      }      
      
      if((val[0]==s[0]) && (val[1]==s[1]) && (val[2]==s[2]) && (val[3]==s[3]) && (val[4]==s[4]) && (val[5]==s[5]) && (val[6]==s[6]))
      {
         found=1;
         dbsp ("\nFound\n");      
         
         break;
      
      }
      
   }
   
   if(found==0)
   {
      u8 *saving_number_loc;          
      saving_number_loc = emalloc (sizeof(u8)*20);
      memcpy(&saving_number_loc, &s , strlen(s) );
      
      
      if(i>0)
      {
         memcpy(&p2->array_dialing_nr[i],&saving_number_loc,sizeof(u8 *));         
      }
      else
      {         
         memcpy(&p2->array_dialing_nr[0],&saving_number_loc,sizeof(u8 *));      
      }
   
   }//end


Any help would be much appreciated. Many thanks.
Back to top
View user's profile Send private message
Tim



Joined: 30 Sep 2011
Posts: 12

PostPosted: Wed Oct 12, 2011 4:19 pm    Post subject: Reply with quote

Hi tkm, I'm quite new to this (...so I could be wrong) - but I'm using EEPROM storage in my app and I'm using the wb() call to write each byte. I think I tried memcpy() and it didn't work.
Back to top
View user's profile Send private message
pz



Joined: 12 Mar 2004
Posts: 1161

PostPosted: Thu Oct 13, 2011 7:27 am    Post subject: Re: add_data() retrieval behaving inappropriate Reply with quote

tkm wrote:
Hello, I am trying to use app_data(). I am trying to save some data and later retrieve them. Before saving I check if the data already exist or not. My prob is it works first time as expected--finds no data as the array is empty;saves the new data and on retrieval says a match is found.

The problem is: when I try to insert another data it says match found;whereas the data shouldn't be there as data being new. I am pretty much sure my algorithm/code is right. But can't sort out this wrong behaviour. I am using call control as well in the program. Does it anyhow affects the data stored in EEPROM? My code:
Code:

typedef struct _Pers_mem
{
  u8 active;
  u8 service_nr[MAX_NR_LEN]; 
  u8 *array_dialing_nr[MAX_NR_AMOUNT];
}
Pers_mem;

////////////////////// The following two lines happens in register function
for (i = 0; i < MAX_NR_AMOUNT; i++)
    ww (&p->array_dialing_nr[i], NULL);
////////////////////////

Pers_mem *p2=app_data ();
for(i=0; i<MAX_NR_AMOUNT;i++)
   {
      val=rw(&p2->array_dialing_nr[i]);             
      if(val==NULL)
      {
         dbsp ("\nBreaking out\n");
         break;      
      }      
      
      if((val[0]==s[0]) && (val[1]==s[1]) && (val[2]==s[2]) && (val[3]==s[3]) && (val[4]==s[4]) && (val[5]==s[5]) && (val[6]==s[6]))



This val[]==... seems wrong. Use rb(val[])==...

Quote:

Code:

      {
         found=1;
         dbsp ("\nFound\n");      
         
         break;
      
      }
      
   }
   
   if(found==0)
   {
      u8 *saving_number_loc;          
      saving_number_loc = emalloc (sizeof(u8)*20);
      memcpy(&saving_number_loc, &s , strlen(s) );
      
      
      if(i>0)
      {
         memcpy(&p2->array_dialing_nr[i],&saving_number_loc,sizeof(u8 *));         
      }
      else
      {         
         memcpy(&p2->array_dialing_nr[0],&saving_number_loc,sizeof(u8 *));      
      }
   
   }//end


Any help would be much appreciated. Many thanks.


Also no need to use memcpy() just to write a pointer, ww() is enough.
Back to top
View user's profile Send private message
tkm



Joined: 18 Jan 2011
Posts: 72

PostPosted: Fri Oct 14, 2011 9:10 am    Post subject: Reply with quote

Thanks a lot, Tim and PZ. Using WB instead of memcpy did the trick. Much appreciated.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bladox.com Forum Index -> Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group