Keil Logo

Technical Support

On-Line Manuals

RL-ARM User's Guide (MDK v4)

RL-RTX RL-FlashFS RL-TCPnet TCP Socket Opening TCP Connection TCP Active Open TCP Passive Open Sending TCP Data Example for Sending Data Multiple TCP Connections UDP Socket Opening UDP Connection Sending UDP Data When DHCP Enabled When ARP Cache Empty Example for Sending Data IP Multicasting Multiple UDP Connections Configuring RL-TCPnet Static Configuration System Definitions Ethernet Network Interface PPP Network Interface SLIP Network Interface UDP Socket TCP Socket BSD Socket HTTP Server Telnet Server TFTP Server TFTP Client FTP Server FTP Client DNS Client SMTP Client SNMP Agent SNTP Client Error Function Runtime Configuration Library Files Using RL-TCPnet Stand Alone With RTX Kernel Event Driven Operation IP Address Assignment Ethernet Interface PPP Interface SLIP Interface Localhost Applications HTTP Server Script Language CGI Functions Ajax Support Using XML XML Example How it works SOAP Support SOAP Interface Large POST Messages Web Pages Default Page Error Pages Web on SD Card Web Update File System Interface Http Caching How it works Internal Web External Web Multi-user Authentication Using RAM File System FCARM File Converter PRINT Directive NOPRINT Directive PAGEWIDTH Directive PAGELENGTH Directive ROOT Directive Telnet Server Command Line Interface Multi-user Authentication Sending Reply Message Short Reply Long Reply Continuous Screen Update TFTP Server File System Interface TFTP Client File System Interface FTP Server File System Interface Multi-user Authentication Supported Commands FTP Client File System Interface SMTP Client SNMP Agent MIB Database MIB Interface MIB Entry MIB Table DNS Resolver Starting DNS Device Drivers Ethernet Driver Interrupt Mode Modem Driver Serial Driver Using Serial Link Cable Connection Modem Connection Windows Dial-up Add Direct Serial Link New Dial-up Connection Configure PPP Dial-up Configure SLIP Dial-up Debugging Enabling Debug Debug Level Redirecting Output Function Overview BSD Routines CGI Routines Ethernet Routines FTP Routines HTTP Routines IGMP Routines Miscellaneous Routines Modem Routines PPP Routines Serial Routines SLIP Routines SMTP Routines SNMP Routines System Functions TCP Routines Telnet Routines TFTP Routines UDP Routines RL-CAN RL-USB Example Programs Library Reference Appendix

Long Reply

A long reply message requires multiple calls to the function tnet_process_cmd. Each call to this function generates part of the reply message until the entire message is generated and sent. To distinguish between different calls to the function, the argument pvar is used. This argument is a pointer to a variable that is set to 0 on the first call and not altered on each subsequent call to this function. The function's return value, which specifies the number of bytes in the reply message, cannot exceed 1500. Hence the high bits of the function's return value is used to store the flags:

  • Repeat flag - bit 14
    This flag tells the Telnet Server whether the function tnet_process_cmd must be called again or not (because the command processing is complete). The return value must be OR-ed with 0x4000 to call the function again.
  • Disconnect flag - bit 15
    This flag tells the Telnet Server to disconnect the telnet connection. If this flag is set, the Telnet Server disconnects the current Telnet session. The return value must be OR-ed with 0x8000 to disconnect.

In the following example, the MEAS command is given by the user using the Telnet client.

MCB2100> MEAS 100

When a new telnet command is received, the function tnet_process_cmd is called with the argument *pvar set to 0. The command buffer cmd is checked to identify the command.

U16 tnet_process_cmd (U8 *cmd, U8 *buf, U16 buflen, U32 *pvar) {

  switch (MYBUF(pvar)->id) {
    case 0:
      /* First call to this function, the value of '*pvar' is 0 */
      break;

    case 1:
      /* Repeated call, command 'MEAS' measurements display. */
        ..
      /* Request a repeated call, bit 14 is a repeat flag. */
      return (len | 0x4000);
        ..
  }

  /* Check if the command 'MEAS' is entered. */
  if (tnet_ccmp (cmd, "MEAS") == __TRUE) {
    MYBUF(pvar)->id = 1;
    if (len > 5) {
      /* We must be careful here, because data is overlaid. */
      sscanf ((const S8 *)&cmd[5], "%d", &temp);
      MYBUF(pvar)->nmax = temp;
    }
    len = str_copy (buf,(U8 *)meas_header);
    if (MYBUF(pvar)->nmax) {
      /* Bit 14 is a repeat flag. */
      len |= 0x4000;
    }
    return (len);
  }

When a command is recognized, you can reuse the same command buffer to store local variables, which might be needed in repeated calls. During the repeated call to this function, the cmd buffer is locked and is not altered by the system. You can use it as temporary storage of variables for the repeated calls. Each Telnet session has its own buffer of size 96 bytes. You can use only 95 bytes since the last byte is not available.

The above example uses 3 bytes of a storage variable pointed by pvar pointer for the following structure:

typedef struct {
  U8 id;
  U8 nmax;
  U8 idx;
} MY_BUF;
#define MYBUF(p)        ((MY_BUF *)p)

When the call to tnet_process_cmd() is repeated for the same command, the value of a storage variable pointed to by argument pvar is not altered anymore. You can use the value of *pvar to process the command differently. The *pvar buffer now holds the private structure MY_BUF, which is valid for the lifetime of processing the command. When the command processing is finished, this buffer is not used anymore until the next command.

U16 tnet_process_cmd (U8 *cmd, U8 *buf, U16 buflen, U32 *pvar) {

  switch (MYBUF(pvar)->id) {
    case 0:
      /* First call to this function, the value of '*pvar' is 0 */
      break;

    case 1:
      /* Repeated call, command 'MEAS' measurements display. */
      while (len < buflen-80) {
        /* Let's use as much of the buffer as possible. */
        /* This will produce less packets and speedup the transfer. */
        len += sprintf ((S8 *)(buf+len), "\r\n%4d", MYBUF(pvar)->idx);
        for (val = 0; val < 8; val++) {
          len += sprintf ((S8 *)(buf+len), "%7d", AD_in(val));
        }
        if (++MYBUF(pvar)->idx >= MYBUF(pvar)->nmax) {
          /* OK, we are done. */
          return (len);
        }
      }
      /* Request a repeated call, bit 14 is a repeat flag. */
      return (len | 0x4000);

    case 2:
      /* Repeated call, TCP status display. */
     ..
}

After giving a MEAS command, the Telnet Client screen looks like this:

Measure Command

Note

  • You can check the Telnet_demo example to see how the Telnet Server works. This example is located in the \Keil\ARM\Boards\Phytec\LPC229x\RL\TCPnet folder.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.