Author Topic: Telnet Connection  (Read 7395 times)

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
Telnet Connection
« on: August 29, 2011, 06:41:41 PM »
Hi Mark,

I'm running a long loop, which actually prints the the loop variable. Using Telnet connection as my Output Screen the telnet stops displaying anything after a while when loop reaches somewhere at 548 (Starting at 0), but I'm able to interact with telnet GUI Commands.


Thanks,
Ab
« Last Edit: August 29, 2011, 07:19:46 PM by abhimanyum »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Telnet Connection
« Reply #1 on: August 29, 2011, 07:28:27 PM »
Hi

This is presumably because the loop is putting so much data into the output buffer that the buffer overflow (then the data is simply dropped).
To avoid this it is possible to first check the space in the TELNET output buffer (actually the buffered TCP's output buffer) and quit the loop when the buffer becomes full. Then, using the TX_FREE event the loop can continue once the output buffer has space again.

See the way that debug.c does this - it allows large command line menus to be sent to TELNET (or serial interfaces) which only have quite small buffer sizes.

    while (iEntries--) {
        if (!fnWrite(DebugHandle, 0, MAX_MENU_LINE)) {                   // the transmit buffer cannot accept more data so we will pause until it can
            fnDriver(DebugHandle, MODIFY_WAKEUP, (MODIFY_TX | OWN_TASK));// we want to be woken when the queue is free again
            iMenuLocation = (iEntries + 1);                              // save the position we stopped at
            return 1;
        }
        iDisplayLen = fnDebugMsg(ptrCom->strCommand);
        if (iDisplayLen >= ucTab) {
            fnWrite(DebugHandle, ucTabs, 1);
        }
        else {
            fnWrite(DebugHandle, ucTabs, (QUEUE_TRANSFER)(ucTab - iDisplayLen));
        }
        iDisplayLen = fnDebugMsg(ptrCom->strText);
        fnDebugMsg("\n\r");
        ptrCom++;
    }


Here, each time a new command line item is to be sent there is first a check of the remaining buffer size (the write with zero buffer pointer). Once the space is no longer adequate the loop is quit (the loop variable is remembered so that the lpp can later continue from where it was) and the TX_FREE event is used (not shown in thsi code) to kick-off the next block.

Regards

Mark

Offline abhimanyum

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • Ae Applications
Re: Telnet Connection
« Reply #2 on: August 29, 2011, 08:06:30 PM »
Hi Mark,

I'm not quite sure how can I use TX_FREE and above code snipnet to free the Buffer. If you can please help me understand how to use it.


Thanks,
Ab

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: Telnet Connection
« Reply #3 on: August 29, 2011, 11:02:13 PM »
Ab

The use of TX_FREE and control of output buffers is described in chapter 6 of http://www.utasker.com/docs/uTasker/uTaskerUART.PDF (UART document, whereby the principel is the same for any buffered output, including TELNET).

Regards

Mark