cancel
Showing results for 
Search instead for 
Did you mean: 

how send NULL string with lwip?

h_kabiri
Associate II
Posted on January 28, 2015 at 23:28

i can send string with lwip.

how send NULL string with lwip

 sprintf(BUF,''(%c%c%c%c'',len/256,len%256,Cmd/256,Cmd%256);

 

 strncat(&BUF[5],buf,len);

 

 strncat(&BUF[5+len],'')'',1);

 

 tcp_write(TcpPCB,BUF,BufLen+6,1);

if value at location 1 or 3 is 0 tcp_write send 1 or 3 byte 

#stm32 #lwip #null #pascalstring
8 REPLIES 8
Posted on January 29, 2015 at 01:58

If you're sending binary data, don't use string functions to do it. Are you sure the problem isn't at the receiving end?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
h_kabiri
Associate II
Posted on January 29, 2015 at 09:59

Yes

I send binary data.

when data have 0 , receiving and sending  have problem

which function send and receive binary data in lwip?

Thanks 

Posted on January 29, 2015 at 10:08

lpiw is innocent in this case.

You must not use str(n)cpy()/str(n)cat() for copying binary data; use memcpy().

JW

h_kabiri
Associate II
Posted on January 29, 2015 at 10:27

i use strncat(

&BUF[5]

,buf,len); 

 

problem in sending and receiving

i change code to this :

BUF[0]='(';

BUF[1]=(len/256);

BUF[2]=(len%256);

BUF[3]=(Cmd/256);

BUF[4]=(Cmd%256);

for(i=0;i<len;i++)

 BUF[5+i]=dbuf[i];

BUF[5+i]=')';

 tcp_write(TcpPCB,BUF,BufLen+6,1);

when len<10 send and receive 1 byte 

when len=10 or 20 or 30 , ... send and receive 2 byte

when 0 in dbuf send and receive until 0 index

Posted on January 29, 2015 at 12:51

>  tcp_write(TcpPCB,BUF,BufLen+6,1);

What is BufLen? Where do you have it from? What is its value at that moment?

(You should also use the symbols defined for the apiFlag parameter instead of numbers, namely TCP_WRITE_FLAG_COPY instead of 1, but that is not what causes your problem at the moment.)

JW

h_kabiri
Associate II
Posted on January 29, 2015 at 15:57

static err_t SendPacket(uint16_t Cmd,unsigned char *dbuf,int len,int

BufLen

){

 char BUF[600];

 int i;

 

if(TcpPCB->state==CLOSED){

return ERR_CLSD;

}

BUF[0]='(';

BUF[1]=(len/256);

BUF[2]=(len%256);

BUF[3]=(Cmd/256);

BUF[4]=(Cmd%256);

for(i=0;i<len;i++)

  BUF[5+i]=dbuf[i];

BUF[5+i]=')';

  tcp_write(TcpPCB,BUF,BufLen+6,1);

}

Posted on January 29, 2015 at 16:02

Nice, but this still did not answer, what is the value of it and where does it come from (i.e. show how do you invoke this function).

JW

h_kabiri
Associate II
Posted on January 29, 2015 at 16:38

Oh my good , I was wrong , i define 2 variable for buffer len 

static err_t SendPacket(uint16_t Cmd,unsigned char *dbuf,int len){

 char BUF[600];

 int i;

 

if(TcpPCB->state==CLOSED){

return ERR_CLSD;

}

 BUF[0]='(';

 BUF[1]=(len/256);

 BUF[2]=(len%256);

 BUF[3]=(Cmd/256);

 BUF[4]=(Cmd%256);

 for(i=0;i<len;i++)

  BUF[5+i]=dbuf[i];

 BUF[5+i]=')'; 

 tcp_write(TcpPCB,BUF,len+6,1);

 return (tcp_output(TcpPCB));

}

Now work

Thanks waclawek.jan