使用举例:
/*--------------------------- tnet_process_cmd ------------------------------*/
U16 tnet_process_cmd (U8 *cmd, U8 *buf, U16 buflen, U32 *pvar)
{
/* This is a Telnet Client callback function to make a formatted output */
/* for 'stdout'. It returns the number of bytes written to the out buffer.*/
/* Hi-bit of return value (len is or-ed with 0x8000) is a disconnect flag.*/
/* Bit 14 (len is or-ed with 0x4000) is a repeat flag for the Tnet client.*/
/* If this bit is set to 1, the system will call the 'tnet_process_cmd()' */
/* again with parameter 'pvar' pointing to a 4-byte buffer. This buffer */
/* can be used for storing different status variables for this function. */
/* It is set to 0 by Telnet server on first call and is not altered by */
/* Telnet server for repeated calls. This function should NEVER write */
/* more than 'buflen' bytes to the buffer. */
/* Parameters: */
/* cmd - telnet received command string */
/* buf - Telnet transmit buffer */
/* buflen - length of this buffer (500-1400 bytes - depends on MSS) */
/* pvar - pointer to local storage buffer used for repeated loops */
/* This is a U32 variable - size is 4 bytes. Value is: */
/* - on 1st call = 0 */
/* - 2nd call = as set by this function on first call */
REMOTEM rm;
U16 len = 0;
switch (MYBUF(pvar)->id)
{
case 0:
/* First call to this function, the value of '*pvar' is 0 */
break;
case 1:
/* Request a repeated call, bit 14 is a repeat flag. */
return (len | 0x4000);
case 2:
/* Request a repeated call, bit 14 is a repeat flag. */
return (len |= 0x4000);
}
/* Simple Command line parser */
len = strlen ((const char *)cmd);
if (tnet_ccmp (cmd, "LEDON") == __TRUE)
{
/* 'LED4' command received */
len = str_copy (buf,"rn=====>LED4 Lights ON");
bsp_LedOn(4);
return (len);
}
if (tnet_ccmp (cmd, "LEDOFF") == __TRUE)
{
/* 'LED4' command received */
len = str_copy (buf,"rn=====>LED4 Lights OFF");
bsp_LedOff(4);
return (len);
}
if (tnet_ccmp (cmd, "BYE") == __TRUE)
{
/* 'BYE' command, send message and disconnect */
len = str_copy (buf, "rnDisconnect...rn");
/* Hi bit of return value is a disconnect flag */
return (len | 0x8000);
}
if (tnet_ccmp (cmd, "RINFO") == __TRUE)
{
/* Display Remote Machine IP and MAC address. */
tnet_get_info (&rm);
len = sprintf ((char *)buf,"rn Remote IP : %d.%d.%d.%d",
rm.IpAdr[0],rm.IpAdr[1],rm.IpAdr[2],rm.IpAdr[3]);
len += sprintf ((char *)(buf+len),
"rn Remote MAC: %02X-%02X-%02X-%02X-%02X-%02X",
rm.HwAdr[0],rm.HwAdr[1],rm.HwAdr[2],
rm.HwAdr[3],rm.HwAdr[4],rm.HwAdr[5]);
return (len);
}
if (tnet_ccmp (cmd, "HELP") == __TRUE || tnet_ccmp (cmd, "?") == __TRUE)
{
/* 'HELP' command, display help text */
len = str_copy (buf,(U8 *)tnet_help1);
len += str_copy (buf+len,(U8 *)tnet_help2);
return (len);
}
/* Unknown command, display message */
len = str_copy (buf, "rn==> Unknown Command: ");
len += str_copy (buf+len, cmd);
return (len);
} |
评分
-
查看全部评分
|