nimaltd / gsm_v5

gsm module library for STM32 LL
GNU General Public License v3.0
232 stars 86 forks source link

Bug in function `bool Gsm_Ussd(char *send, char *receive)` #6

Closed d-serj closed 5 years ago

d-serj commented 5 years ago

Hello! Could you descrive (write comments) of the API functions in your code?

In my case, I dont understand the meaning of the parameter receive in function bool Gsm_Ussd(char *send, char *receive) . I think, there is no effect of code in this function if(receive != NULL) receive = Sim80x.Gsm.Msg; because receive is local variable. Or I need to pass pointer to pointer as the parameter?

P.S. Sorry for my English.

nimaltd commented 5 years ago

Hello. Call init in your task. Reseive can a global variable. Like Char myussdanswer[128]; Or null. If it's null. You can read answer in sim80x structure ( in sim80x.gsm.msg)

d-serj commented 5 years ago

Thanks for your fast replying. Here is minimal model of your problem:

char a[10], *ptr = a;
void foo(char *p)
{
    p = NULL;
}
...
foo(ptr);   // after calling this function ptr won't be changed

If we need to change ptr we have to pass pointer to pointer

void foo(char **p)
{
    *p = NULL;
}
...
foo(&ptr );  // in that case the value of ptr will be changed

Your code if(receive != NULL) receive = Sim80x.Gsm.Msg; has absolutely no effect and function bool Gsm_Ussd(char *send, char *receive) doesn't work! The value of variable that receive pointed to, will never be changed.

d-serj commented 5 years ago

My solution is to use memcpy(receive, Sim80x.Gsm.Msg, receiveSize); instead of receive = Sim80x.Gsm.Msg or pass pointer to pointer as function argument.

nimaltd commented 5 years ago

I dont have a board for test now. . I try it soon. Thank you for report bugs