I have an issue with the TCP client - sending data as Telnet.
My code appears to work if I use client.write( data), but is slow.
If I move to using client.write (bufferptr, buffersize), then I appear to be getting duplicate messages sent.
I’ll explain…
The Telnet code receives a ‘command’ packet from the network and automatically replies with a simple ‘T3’ string confirmation response, This received packet is parsed and sent to an SPI peripheral which causes another ‘answer’ response packet sent back over Telnet.
So we should have… ‘command’ … ‘T3’ … ‘answer’
What appears to be happening is the following… ‘command’ …‘previous answer’ … ‘T3’… ‘answer’
Each time the call is made to the functional calling client.write (bufferptr, buffersize), the bufferpointer is reset and size set to zero, so there seems to be a record of the data sent being held elsewhere and not cleared - perhaps in the tcp functions
There will be two possibly fast sequential calls to the client.write (bufferptr, buffersize) function, and I don’t know if this is permitted without some validity check.
The debug variables will only be showing the results from the second transmission because of the timings involved.
The duplicate message does not arise on the first attempt of sending a command.
b returns as -7009, which seems odd. ( no of bytes written )
R2 increments twice per command as expected ( ‘T3’ & ‘answer’ )
I also have a UDP transmission every 5 seconds which continues fine.
// Sends a globally defined array to TCP Client
void sendarray()
{
unsigned char *buffarrytemp; /* ascii buffer pointer */
unsigned int n;
unsigned int b;
R2++; // Cloud variable - count entry to this function debug
R3 = arraysize; // cloud variable for debug
#if true
buffarrytemp = &array[0];
for (n = 0; n <37 ;n++)
{ cmdbuf4[n] = *buffarrytemp++ ;} // create cloud string for debug
#endif
b = client.write( &array[0], arraysize); // This is the actual write
R4 = b; // Inspect Cloud variable for debug
}
This is how the buffer is created and initialised
unsigned char serial_write0 (unsigned char byte)
{
unsigned char tmp = 1;
*arrayptr = byte;
arrayptr++;
arraysize++;
return tmp; /* tmp is return code from fifo_enqueue()*/
}
void resetarray()
{
arraysize = 0;
arrayptr = &array[0];
}
Thanks