|

楼主 |
发表于 2017-12-8 16:23:02
|
显示全部楼层
32.7 实验例程说明(RTX)
32.7.1 STM32F407开发板实验
配套例子:
V5-1045_RL-TCPnet实验_Telnet应用(RTX)
实验目的:
1. 学习RL-TCPnet的Telnet应用。
实验内容:
1. 强烈推荐将网线接到路由器或者交换机上面测试,因为已经使能了DHCP,可以自动获取IP地址。
2. 程序中实现了一个Telnet服务器,用户名是admin,密码123456。
实验操作:
详见本章节32.5小节。
配置向导文件设置(Net_Config.c):
详见本章节32.3小节。
调试文件设置(Net_Debug.c):
详见本章节32.4小节。
RTX配置:
RTX配置向导详情如下:
Task Configuration
(1)Number of concurrent running tasks
允许创建6个任务,实际创建了如下5个任务:
AppTaskUserIF任务 :按键消息处理。
AppTaskLED任务 :LED闪烁。
AppTaskMsgPro任务 :按键检测。
AppTaskTCPMain任务:RL-TCPnet测试任务。
AppTaskStart任务 :启动任务,也是最高优先级任务,这里实现RL-TCPnet的时间基准更新。
(2)Number of tasks with user-provided stack
创建的5个任务都是采用自定义堆栈方式。
(3)Run in privileged mode
设置任务运行在非特权级模式。
RTX任务调试信息:
程序设计:
任务栈大小分配:
staticuint64_t AppTaskUserIFStk[1024/8]; /* 任务栈 */
staticuint64_t AppTaskLEDStk[1024/8]; /* 任务栈 */
staticuint64_t AppTaskMsgProStk[1024/8]; /* 任务栈 */
staticuint64_t AppTaskTCPMainStk[2048/8]; /* 任务栈 */
staticuint64_t AppTaskStartStk[1024/8]; /* 任务栈 */
将任务栈定义成uint64_t类型可以保证任务栈是8字节对齐的,8字节对齐的含义就是数组的首地址对8求余等于0。如果不做8字节对齐的话,部分C语言库函数、浮点运算和uint64_t类型数据运算会出问题。
系统栈大小分配:
RTX初始化:
- /*
- *********************************************************************************************************
- * 函 数 名: main
- * 功能说明: 标准c程序入口。
- * 形 参: 无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- int main (void)
- {
- /* 初始化外设 */
- bsp_Init();
-
- /* 创建启动任务 */
- os_sys_init_user (AppTaskStart, /* 任务函数 */
- 5, /* 任务优先级 */
- &AppTaskStartStk, /* 任务栈 */
- sizeof(AppTaskStartStk)); /* 任务栈大小,单位字节数 */
- while(1);
- }
复制代码 硬件外设初始化
硬件外设的初始化是在 bsp.c 文件实现:
- /*
- *********************************************************************************************************
- * 函 数 名: bsp_Init
- * 功能说明: 初始化所有的硬件设备。该函数配置CPU寄存器和外设的寄存器并初始化一些全局变量。只需要调用一次
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void bsp_Init(void)
- {
- /*
- 由于ST固件库的启动文件已经执行了CPU系统时钟的初始化,所以不必再次重复配置系统时钟。
- 启动文件配置了CPU主时钟频率、内部Flash访问速度和可选的外部SRAM FSMC初始化。
-
- 系统时钟缺省配置为168MHz,如果需要更改,可以修改 system_stm32f4xx.c 文件
- */
- /* 优先级分组设置为4,可配置0-15级抢占式优先级,0级子优先级,即不存在子优先级。*/
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
-
- bsp_InitDWT(); /* 初始化DWT */
- bsp_InitUart(); /* 初始化串口 */
- bsp_InitKey(); /* 初始化按键变量(必须在 bsp_InitTimer() 之前调用) */
- bsp_InitLed(); /* 初始LED指示灯端口 */
- }
复制代码 RTX任务创建:
- /*
- *********************************************************************************************************
- * 函 数 名: AppTaskCreate
- * 功能说明: 创建应用任务
- * 形 参: 无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- static void AppTaskCreate (void)
- {
- HandleTaskUserIF = os_tsk_create_user(AppTaskUserIF, /* 任务函数 */
- 1, /* 任务优先级 */
- &AppTaskUserIFStk, /* 任务栈 */
- sizeof(AppTaskUserIFStk)); /* 任务栈大小,单位字节数 */
-
- HandleTaskLED = os_tsk_create_user(AppTaskLED, /* 任务函数 */
- 2, /* 任务优先级 */
- &AppTaskLEDStk, /* 任务栈 */
- sizeof(AppTaskLEDStk)); /* 任务栈大小,单位字节数 */
-
- HandleTaskMsgPro = os_tsk_create_user(AppTaskMsgPro, /* 任务函数 */
- 3, /* 任务优先级 */
- &AppTaskMsgProStk, /* 任务栈 */
- sizeof(AppTaskMsgProStk)); /* 任务栈大小,单位字节数 */
-
- HandleTaskTCPMain = os_tsk_create_user(AppTaskTCPMain, /* 任务函数 */
- 4, /* 任务优先级 */
- &AppTaskTCPMainStk, /* 任务栈 */
- sizeof(AppTaskTCPMainStk)); /* 任务栈大小,单位字节数 */
- }
复制代码 五个RTX任务的实现:
RL-TCPnet功能测试
这里专门创建了一个app_tcpnet_lib.c文件用于RL-TCPnet功能的测试,此文件主要实现网络主函数main_TcpNet的调用。
- #include "includes.h"
-
-
-
- /*
- *********************************************************************************************************
- * 函 数 名: TCPnetTest
- * 功能说明: TCPent测试函数。
- * 形 参: 无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void TCPnetTest(void)
- {
-
- while (1)
- {
- os_evt_wait_and(0x0001, 0xFFFF);
- while (main_TcpNet() == __TRUE);
- }
- }
复制代码 Telnet用户接口文件的实现
KEIL官网有提供Telnet的接口文件,名为Telnet_uif.c文件。我们就是在这个文件上修改。具体修改后的代码如下:
- /* Net_Config.c */
- extern struct tcp_cfg tcp_config;
- extern struct tnet_cfg tnet_config;
- #define tcp_NumSocks tcp_config.NumSocks
- #define tcp_socket tcp_config.Scb
- #define tnet_EnAuth tnet_config.EnAuth
- #define tnet_auth_passw tnet_config.Passw
-
- /* ANSI ESC Sequences for terminal control. */
- #define CLS "\\033[2J"
- #define TBLUE "\\033[37;44m"
- #define TNORM "\\033[0m"
-
-
- /* My structure of a Telnet U32 storage variable. This variable is private */
- /* for each Telnet Session and is not altered by Telnet Server. It is only */
- /* set to zero when tnet_process_cmd() is called for the first time. */
- typedef struct
- {
- U8 id;
- U8 nmax;
- U8 idx;
- } MY_BUF;
-
- #define MYBUF(p) ((MY_BUF *)p)
-
- /* Local variables */
- static U8 const tnet_header[] =
- {
- CLS "\\r\\n"
- " " TBLUE
- "*=============================================================*\\r\\n" TNORM
- " " TBLUE
- "* RL-TCPnet之Telnet服务器实验 *\\r\\n" TNORM
- " " TBLUE
- "*=============================================================*\\r\\n" TNORM
- };
-
- static U8 const tnet_help1[] =
- {
- "\\r\\n\\r\\n"
- " 当前支持的命令:\\r\\n"
- " ----------------------------\\r\\n"
- " ledon - 打开LED4\\r\\n"
- " ledoff - 关闭LED4\\r\\n"
- " rinfo - 显示远程设备的IP地址和MAC\\r\\n"
- };
-
- static U8 const tnet_help2[] =
- {
- " help, ? - 显示帮助\\r\\n"
- " bye - 断开连接\\r\\n\\r\\n"
- " <ESC>,<^C> - ESC按键,断开连接\\r\\n"
- " <BS> - 回车函数,删除左侧字符\\r\\n"
- " <UP><DOWN> - 按键UP和DOWM,浏览历史命令\\r\\n"
- };
-
-
- /*----------------------------------------------------------------------------
- * Telnet CallBack Functions
- *---------------------------------------------------------------------------*/
- /*--------------------------- tnet_cbfunc -----------------------------------*/
-
- U16 tnet_cbfunc (U8 code, U8 *buf, U16 buflen)
- {
- /* This function is called by the Telnet Client to get formated system */
- /* messages for different code values. */
- /* Values for 'code': */
- /* 0 - initial header */
- /* 1 - prompt string */
- /* 2 - header for login only if authorization is enabled */
- /* 3 - string 'Username' for login */
- /* 4 - string 'Password' for login */
- /* 5 - message 'Login incorrect' */
- /* 6 - message 'Login timeout' */
- /* 7 - Unsolicited messages from Server (ie. Basic Interpreter) */
- U16 len = 0;
-
- /* Make a reference to disable compiler warning. */
- buflen = buflen;
-
- switch (code)
- {
- case 0:
- /* Write initial header after login. */
- len = str_copy (buf, (U8 *)&tnet_header);
- break;
-
- case 1:
- /* Write a prompt string. */
- len = str_copy (buf, "\\r\\narmfly> ");
- break;
- case 2:
- /* Write Login header. */
- len = str_copy (buf, CLS "\\r\\nRL-TCPnet之Telnet服务器,"
- " 请登录...\\r\\n");
- break;
-
- case 3:
- /* Write 'username' prompt. */
- len = str_copy (buf, "\\r\\n用户名: ");
- break;
-
- case 4:
- /* Write 'Password' prompt. */
- len = str_copy (buf, "\\r\\n密 码: ");
- break;
-
- case 5:
- /* Write 'Login incorrect'.message. */
- len = str_copy (buf, "\\r\\n登录失败");
- break;
-
- case 6:
- /* Write 'Login Timeout' message. */
- len = str_copy (buf, "\\r\\n120秒无操作,退出登录\\r\\n");
- break;
- }
-
- return (len);
- }
-
- /*--------------------------- 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,"\\r\\n=====>LED4 Lights ON");
- bsp_LedOn(4);
- return (len);
- }
-
- if (tnet_ccmp (cmd, "LEDOFF") == __TRUE)
- {
- /* 'LED4' command received */
- len = str_copy (buf,"\\r\\n=====>LED4 Lights OFF");
- bsp_LedOff(4);
- return (len);
- }
-
- if (tnet_ccmp (cmd, "BYE") == __TRUE)
- {
- /* 'BYE' command, send message and disconnect */
- len = str_copy (buf, "\\r\\nDisconnect...\\r\\n");
- /* 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,"\\r\\n Remote IP : %d.%d.%d.%d",
- rm.IpAdr[0],rm.IpAdr[1],rm.IpAdr[2],rm.IpAdr[3]);
- len += sprintf ((char *)(buf+len),
- "\\r\\n 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, "\\r\\n==> Unknown Command: ");
- len += str_copy (buf+len, cmd);
- return (len);
- }
复制代码
32.7.2 STM32F429开发板实验
配套例子:
V6-1045_RL-TCPnet实验_Telnet应用(RTX)
实验目的:
1. 学习RL-TCPnet的Telnet应用。
实验内容:
1. 强烈推荐将网线接到路由器或者交换机上面测试,因为已经使能了DHCP,可以自动获取IP地址。
2. 程序中实现了一个Telnet服务器,用户名是admin,密码123456。
实验操作:
详见本章节32.5小节。
配置向导文件设置(Net_Config.c):
详见本章节32.3小节。
调试文件设置(Net_Debug.c):
详见本章节32.4小节。
RTX配置:
RTX配置向导详情如下:
Task Configuration
(1)Number of concurrent running tasks
允许创建6个任务,实际创建了如下5个任务:
AppTaskUserIF任务 :按键消息处理。
AppTaskLED任务 :LED闪烁。
AppTaskMsgPro任务 :按键检测。
AppTaskTCPMain任务:RL-TCPnet测试任务。
AppTaskStart任务 :启动任务,也是最高优先级任务,这里实现RL-TCPnet的时间基准更新。
(2)Number of tasks with user-provided stack
创建的5个任务都是采用自定义堆栈方式。
(3)Run in privileged mode
设置任务运行在非特权级模式。
RTX任务调试信息:
程序设计:
任务栈大小分配:
staticuint64_t AppTaskUserIFStk[1024/8]; /* 任务栈 */
staticuint64_t AppTaskLEDStk[1024/8]; /* 任务栈 */
staticuint64_t AppTaskMsgProStk[1024/8]; /* 任务栈 */
staticuint64_t AppTaskTCPMainStk[2048/8]; /* 任务栈 */
staticuint64_t AppTaskStartStk[1024/8]; /* 任务栈 */
将任务栈定义成uint64_t类型可以保证任务栈是8字节对齐的,8字节对齐的含义就是数组的首地址对8求余等于0。如果不做8字节对齐的话,部分C语言库函数、浮点运算和uint64_t类型数据运算会出问题。
系统栈大小分配:
RTX初始化:
- /*
- *********************************************************************************************************
- * 函 数 名: main
- * 功能说明: 标准c程序入口。
- * 形 参: 无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- int main (void)
- {
- /* 初始化外设 */
- bsp_Init();
-
- /* 创建启动任务 */
- os_sys_init_user (AppTaskStart, /* 任务函数 */
- 5, /* 任务优先级 */
- &AppTaskStartStk, /* 任务栈 */
- sizeof(AppTaskStartStk)); /* 任务栈大小,单位字节数 */
- while(1);
- }
复制代码 硬件外设初始化
硬件外设的初始化是在 bsp.c 文件实现:
- /*
- *********************************************************************************************************
- * 函 数 名: bsp_Init
- * 功能说明: 初始化所有的硬件设备。该函数配置CPU寄存器和外设的寄存器并初始化一些全局变量。只需要调用一次
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void bsp_Init(void)
- {
- /*
- 由于ST固件库的启动文件已经执行了CPU系统时钟的初始化,所以不必再次重复配置系统时钟。
- 启动文件配置了CPU主时钟频率、内部Flash访问速度和可选的外部SRAM FSMC初始化。
-
- 系统时钟缺省配置为168MHz,如果需要更改,可以修改 system_stm32f4xx.c 文件
- */
- /* 优先级分组设置为4,可配置0-15级抢占式优先级,0级子优先级,即不存在子优先级。*/
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
-
- SystemCoreClockUpdate(); /* 根据PLL配置更新系统时钟频率变量 SystemCoreClock */
-
- bsp_InitDWT(); /* 初始化DWT */
- bsp_InitUart(); /* 初始化串口 */
- bsp_InitKey(); /* 初始化按键变量(必须在 bsp_InitTimer() 之前调用) */
-
- bsp_InitExtIO(); /* FMC总线上扩展了32位输出IO, 操作LED等外设必须初始化 */
- bsp_InitLed(); /* 初始LED指示灯端口 */
- }
复制代码 RTX任务创建:
- /*
- *********************************************************************************************************
- * 函 数 名: AppTaskCreate
- * 功能说明: 创建应用任务
- * 形 参: 无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- static void AppTaskCreate (void)
- {
- HandleTaskUserIF = os_tsk_create_user(AppTaskUserIF, /* 任务函数 */
- 1, /* 任务优先级 */
- &AppTaskUserIFStk, /* 任务栈 */
- sizeof(AppTaskUserIFStk)); /* 任务栈大小,单位字节数 */
-
- HandleTaskLED = os_tsk_create_user(AppTaskLED, /* 任务函数 */
- 2, /* 任务优先级 */
- &AppTaskLEDStk, /* 任务栈 */
- sizeof(AppTaskLEDStk)); /* 任务栈大小,单位字节数 */
-
- HandleTaskMsgPro = os_tsk_create_user(AppTaskMsgPro, /* 任务函数 */
- 3, /* 任务优先级 */
- &AppTaskMsgProStk, /* 任务栈 */
- sizeof(AppTaskMsgProStk)); /* 任务栈大小,单位字节数 */
-
- HandleTaskTCPMain = os_tsk_create_user(AppTaskTCPMain, /* 任务函数 */
- 4, /* 任务优先级 */
- &AppTaskTCPMainStk, /* 任务栈 */
- sizeof(AppTaskTCPMainStk)); /* 任务栈大小,单位字节数 */
- }
复制代码 五个RTX任务的实现:
RL-TCPnet功能测试
这里专门创建了一个app_tcpnet_lib.c文件用于RL-TCPnet功能的测试,此文件主要实现网络主函数main_TcpNet的调用。
- #include "includes.h"
-
-
-
- /*
- *********************************************************************************************************
- * 函 数 名: TCPnetTest
- * 功能说明: TCPent测试函数。
- * 形 参: 无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void TCPnetTest(void)
- {
-
- while (1)
- {
- os_evt_wait_and(0x0001, 0xFFFF);
- while (main_TcpNet() == __TRUE);
- }
- }
复制代码 Telnet用户接口文件的实现
KEIL官网有提供Telnet的接口文件,名为Telnet_uif.c文件。我们就是在这个文件上修改。具体修改后的代码如下:
- /* Net_Config.c */
- extern struct tcp_cfg tcp_config;
- extern struct tnet_cfg tnet_config;
- #define tcp_NumSocks tcp_config.NumSocks
- #define tcp_socket tcp_config.Scb
- #define tnet_EnAuth tnet_config.EnAuth
- #define tnet_auth_passw tnet_config.Passw
-
- /* ANSI ESC Sequences for terminal control. */
- #define CLS "\\033[2J"
- #define TBLUE "\\033[37;44m"
- #define TNORM "\\033[0m"
-
-
- /* My structure of a Telnet U32 storage variable. This variable is private */
- /* for each Telnet Session and is not altered by Telnet Server. It is only */
- /* set to zero when tnet_process_cmd() is called for the first time. */
- typedef struct
- {
- U8 id;
- U8 nmax;
- U8 idx;
- } MY_BUF;
-
- #define MYBUF(p) ((MY_BUF *)p)
-
- /* Local variables */
- static U8 const tnet_header[] =
- {
- CLS "\\r\\n"
- " " TBLUE
- "*=============================================================*\\r\\n" TNORM
- " " TBLUE
- "* RL-TCPnet之Telnet服务器实验 *\\r\\n" TNORM
- " " TBLUE
- "*=============================================================*\\r\\n" TNORM
- };
-
- static U8 const tnet_help1[] =
- {
- "\\r\\n\\r\\n"
- " 当前支持的命令:\\r\\n"
- " ----------------------------\\r\\n"
- " ledon - 打开LED4\\r\\n"
- " ledoff - 关闭LED4\\r\\n"
- " rinfo - 显示远程设备的IP地址和MAC\\r\\n"
- };
-
- static U8 const tnet_help2[] =
- {
- " help, ? - 显示帮助\\r\\n"
- " bye - 断开连接\\r\\n\\r\\n"
- " <ESC>,<^C> - ESC按键,断开连接\\r\\n"
- " <BS> - 回车函数,删除左侧字符\\r\\n"
- " <UP><DOWN> - 按键UP和DOWM,浏览历史命令\\r\\n"
- };
-
-
- /*----------------------------------------------------------------------------
- * Telnet CallBack Functions
- *---------------------------------------------------------------------------*/
- /*--------------------------- tnet_cbfunc -----------------------------------*/
-
- U16 tnet_cbfunc (U8 code, U8 *buf, U16 buflen)
- {
- /* This function is called by the Telnet Client to get formated system */
- /* messages for different code values. */
- /* Values for 'code': */
- /* 0 - initial header */
- /* 1 - prompt string */
- /* 2 - header for login only if authorization is enabled */
- /* 3 - string 'Username' for login */
- /* 4 - string 'Password' for login */
- /* 5 - message 'Login incorrect' */
- /* 6 - message 'Login timeout' */
- /* 7 - Unsolicited messages from Server (ie. Basic Interpreter) */
- U16 len = 0;
-
- /* Make a reference to disable compiler warning. */
- buflen = buflen;
-
- switch (code)
- {
- case 0:
- /* Write initial header after login. */
- len = str_copy (buf, (U8 *)&tnet_header);
- break;
-
- case 1:
- /* Write a prompt string. */
- len = str_copy (buf, "\\r\\narmfly> ");
- break;
- case 2:
- /* Write Login header. */
- len = str_copy (buf, CLS "\\r\\nRL-TCPnet之Telnet服务器,"
- " 请登录...\\r\\n");
- break;
-
- case 3:
- /* Write 'username' prompt. */
- len = str_copy (buf, "\\r\\n用户名: ");
- break;
-
- case 4:
- /* Write 'Password' prompt. */
- len = str_copy (buf, "\\r\\n密 码: ");
- break;
-
- case 5:
- /* Write 'Login incorrect'.message. */
- len = str_copy (buf, "\\r\\n登录失败");
- break;
-
- case 6:
- /* Write 'Login Timeout' message. */
- len = str_copy (buf, "\\r\\n120秒无操作,退出登录\\r\\n");
- break;
- }
-
- return (len);
- }
-
- /*--------------------------- 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,"\\r\\n=====>LED4 Lights ON");
- bsp_LedOn(4);
- return (len);
- }
-
- if (tnet_ccmp (cmd, "LEDOFF") == __TRUE)
- {
- /* 'LED4' command received */
- len = str_copy (buf,"\\r\\n=====>LED4 Lights OFF");
- bsp_LedOff(4);
- return (len);
- }
-
- if (tnet_ccmp (cmd, "BYE") == __TRUE)
- {
- /* 'BYE' command, send message and disconnect */
- len = str_copy (buf, "\\r\\nDisconnect...\\r\\n");
- /* 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,"\\r\\n Remote IP : %d.%d.%d.%d",
- rm.IpAdr[0],rm.IpAdr[1],rm.IpAdr[2],rm.IpAdr[3]);
- len += sprintf ((char *)(buf+len),
- "\\r\\n 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, "\\r\\n==> Unknown Command: ");
- len += str_copy (buf+len, cmd);
- return (len);
- }
复制代码 |
|