My main problem is create custom
recv() function , which will use source for
buffer.
In PAHO library example, there
is a transport_getdata() function. It handle
transportation layer. This is
tranport_getdata() function.This example
uses socket library from which I don't have
:(
int transport_getdata(unsigned char<
span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.7142858505249px; vertical-align: baseline; background: transparent;">* buf, int count
)
{
int rc = recv(mysock, buf, count, 0);
//printf("received %d bytes count %d\n", rc, (int)count);
return rc;
}
To port library to my project, I
need to write my own recv() function like
my_recv().
Standartd socket Recv() function
description said,
Recv() will return length of
message written to buffer from source.
So I try to write my_recv() for
replace recv() , ( I don't need socket ID
and FLAG)
int my_recv(char *buf,
int len){
int i=0;
if (len <= 0 <
/span>)
return -1;
if (len > BUF_MAX)
len=BUF_MAX - 2;
for(i=0;i<len;i++){
*buf=serial_buffer[0];
*buf++;
//shift one byte buffer to left
memmove(serial_buffer, serial_buffer+1
,(BUF_MAX-1)*sizeof(*serial_buffer));
interrupt_pointer--; // After one byte shift, reduce serial interrupt pointer.
}
return i;
}
Handling TCP incoming data, I
have a serial/TCP transparent connection
over GPRS module.
I used interrupt to read every bytes . All
incoming bytes written on serial_buffer.
void USART1_IRQHandler(void){
int byte;
if (USART_GetITStatus(USART1,&
lt;
span class="ecxpln" style="padding:0px;border:0px;font-size:13.7142858505249px;vertical-align:baseline;background:transparent;"> USART_IT_RXNE) != RESET) // Re
ceived characters modify string
{
byte= USART_ReceiveData(USART1);
}
serial_buffer[interrupt_pointer]=byte;
interrupt_pointer++;
if(interrupt_pointer==BUF_MAX){
interrupt_pointer=0;
memset(serial_buffer,0,BUF_MAX<
span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 13.7142858505249px; vertical-align: baseline; background: transparent;">);
}
}
For simple test, I send
"1234567890" from over TCP socket,
simple test code is
while(strlen(serial_buffer)>0)
{
delay_ms(1000);
printf("%s\r\n",serial_buffer);
my_recv(buf,3);
printf("%s\r\n",buf);
printf("%s\r\n",serial_buffer);
}
My system out is,
1234567890 // All TCP data received
123 // getting 3 bytes from buffer
4567890 // remaining bytes
I'm not sure I understand recv()
function well. Is this output is alright.
Couse still I cant handle MQTT
package with PAHO library