📄 funcsys.c
字号:
#include "funcsys.h"
#include "symtab.h"
#include "uip.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//http://192.168.0.3/password.cgi?password=&send=Submit
char hdr[]="http/1.0 200 ok\r\nContent-type: text/html\r\n\r\n";
char pw[10];
void password(void){
char* buf = (char*)uip_appdata;
char* passkey="123456";
int len=0;
len += sizeof(hdr); //注意sizeof与strlen的区别
strcpy(buf,hdr);
buf += (len-1);
if(!strcmp(pw,passkey))
len += sprintf(buf,"<html><body>ok! Welcome to ARM world!</body></html>");
else
len += sprintf(buf,"<html><body>Error! Please input again!</body></html>");
uip_send(uip_appdata, len);
}
void dynDisp(void){
char* buf = (char*)uip_appdata;
int curr;
int len=0;
len += sizeof(hdr); //注意sizeof与strlen的区别
strcpy(buf,hdr);
buf += (len-1);
srand((int)time(NULL));
curr = rand()%200;
len += sprintf(buf,"<html><body>The current is %d A.</body></html>",curr);
}
char* password_s = "password";
funcsys password_t;
pFUNC ppassword = &password_t;
void func_init(void){
ppassword->funcname = (func)password;
Enter(password_s, ppassword);
}
//首先创建一个字符串变量,它的值为函数的名字,变量名前面加上后缀_s,表示这是一个字符串变量;
//然后创建一个funcsys结构变量,后缀为_t表示这是一个用typedef定义的类型;
//并把funcsys变量的地址赋给一个pFUNC变量,并加前缀p,表示这是一个指针变量。
//最后,在函数系统初始化函数中,为创建的funcsys结构变量赋值,并加入符合表中。
//注意要调用函数系统或者文件系统的初始化函数。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -