本文主要是介绍W800开发板和网页的交互(存取网页上的字段),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言
前天,将W800工程中加入了一个测试网页(W800开发板修改网页配置), 怎么让W800开发板和这个网页交互。昨天研究了1天,搞定。
网上W800应用层编程资料特别少,就找到一处,那个同学就讲了一下思路。对于实际的工程维护,用处不大。
winnermicro官方SDKwm_sdk_w800_20210513中带的转过的数组文件(wm_sdk_w800_20210513\src\app\web\fsdata_lwip.c)和工程中自带的html(wm_sdk_w800_20210513\src\app\web\fs_basic*.html)并不匹配,将工程自带的html转成fsdata_lwip.c后,编译出的工程无法实现网页字段的交互. 这个应该是WM官方研发的失误,算是个bug. 不过咱也是研发,理解这种情况。工程这么大,如果没有专职的测试组,很难测试出工程的所有bug. 特别是这个问题,需要研发自己去测试才知道。专业的测试工程师因为不是研发,只测试成品,很难发现这种代码上的问题。
如果使用工程中原始自带的fsdata_lwip.c, 是可以实现网页字段交互的。但是demo是demo, fsdata_lwip.c已经是数组了,不知道原始内容是啥。如果想加几个字段,或搞前端同事帮做了一个新网页,再将html转成fsdata_lwip.c, 即使字段和原始的字段一致,编译后,也无法实现网页的交互。
具体为啥不能交互,就需要理解W800官方工程的实现,将不能交互的点找出来加以修复。
因为我没买CK-LINK调试器, 只能靠W800串口0打印出的调试信息结合代码一起分析。昨天从早上一直搞到夜里2:30. 也是够折腾的。
W800上实现网页交互的细节挺多的。每个html字段的存取,都要自己控制。维护点蛮多的,做一个小网页还行,做的html字段多了,还真挺难受的。
实验
我用本地git进行了版本控制。我现在导出了归档的原始W800SDK版本和现在做好的W800SDK版本, 用BC4进行比较,将修改点记录下来。修改点不分先后,就按照BC4的文件列表顺序,比较到哪里,就写到哪里。
实验的html, 就使用上一篇博客做的html (W800开发板修改网页配置)
修改点 - 打开需要的编译开关
wm_sdk_w800_20210513\demo\wm_demo.h
//demo console
#define DEMO_CONSOLE DEMO_ON//connect demo
#define DEMO_CONNECT_NET (DEMO_ON && DEMO_CONSOLE)//http demo
#define DEMO_HTTP (DEMO_ON && DEMO_CONSOLE)
修改点 - 确认热点和连接其他wifi是否成功
调试中发现,W800建立wifi热点和连接外部wifi热点,不是每次都成功。
需要在建立wifi热点和连接外部wifi热点代码中打印调试信息,这样不成功的话,就再连接一次。
我实验中,3次之内肯定能连接成功。大部分是一次就能连接成功。
wm_sdk_w800_20210513\demo\wm_softap_demo.c
MEMCPY(ipinfo->dnsname, "local.wm", sizeof("local.wm"));ret = tls_wifi_softap_create(apinfo, ipinfo);wm_printf("\n2 ap create %s ! \n", (ret == WM_SUCCESS) ? "Successfully" : "Error");
wm_sdk_w800_20210513\demo\wm_apsta_demo.c
ret = tls_wifi_softap_create((struct tls_softap_info_t * )&apinfo, (struct tls_ip_info_t * )&ipinfo);wm_printf("\n1 ap create %s ! \n", (ret == WM_SUCCESS) ? "Successfully" : "Error");return ret;
}static int connect_wifi_demo(char *ssid, char *pwd)
{
修改点 - 加入网页字段在片内FLASH中的存取位置索引
wm_sdk_w800_20210513\include\platform\wm_params.h
/** BT&BLE param */
#define TLS_PARAM_ID_BT_ADAPTER (55)
#define TLS_PARAM_ID_BT_REMOTE_DEVICE_1 (56)
// #define TLS_PARAM_ID_BT_REMOTE_DEVICE_2 (57)
// #define TLS_PARAM_ID_BT_REMOTE_DEVICE_3 (58)// #define TLS_PARAM_ID_BT_REMOTE_DEVICE_4 (59)
// #define TLS_PARAM_ID_BT_REMOTE_DEVICE_5 (60)
// #define TLS_PARAM_ID_BT_REMOTE_DEVICE_6 (61)
// #define TLS_PARAM_ID_BT_REMOTE_DEVICE_7 (62)
// #define TLS_PARAM_ID_BT_REMOTE_DEVICE_8 (63)
// #define TLS_PARAM_ID_BT_REMOTE_DEVICE_9 (64)
// #define TLS_PARAM_ID_BT_REMOTE_DEVICE_10 (65)#define TLS_PARAM_ID_MY_PARAM1 (57)
#define TLS_PARAM_ID_MY_PARAM2 (58)
#define TLS_PARAM_ID_MY_PARAM3 (59)
#define TLS_PARAM_ID_MY_PARAM4 (60)
#define TLS_PARAM_ID_MY_PARAM5 (61)
#define TLS_PARAM_ID_MY_PARAM6 (62)
#define TLS_PARAM_ID_MY_PARAM7 (63)
#define TLS_PARAM_ID_MY_PARAM8 (64)
#define TLS_PARAM_ID_MY_PARAM9 (65)
#define TLS_PARAM_ID_MY_PARAM10 (66)#define TLS_PARAM_ID_MAX (67)
这里要注释掉 TLS_PARAM_ID_BT_REMOTE_DEVICE_2 ~ TLS_PARAM_ID_BT_REMOTE_DEVICE_10的定义,如果再添加变量,稍多一点,W800下载完固件后,就会出现CPU异常,然后挂掉。
我第一感觉就是内存用多了,试了一下果然是。调试的时候,感觉还是挺重要的,能定下一个正确的实验方向,少走弯路。
void UserMain(void)
{printf("\n>> UserMain() \n");printf("\n test_w800 V2021_0624_2220\n");printf("\nsizeof(bt_remote_device_t) = %d\n", sizeof(bt_remote_device_t));#if DEMO_CONSOLECreateDemoTask();
#endif
//用户自己的task
}
在UserMain()打印TLS_PARAM_ID_BT_REMOTE_DEVICE_X对应的变量结构体大小,一个有220个字节。
W800原来的实现是加了5个TLS_PARAM_ID_BT_REMOTE_DEVICE_X, 但是还有5个用宏给注释掉了。我这在加自己的字段挂了之后,就明白了,原来W800研发自己也发现了这个内存不够用的问题:)
去掉了3个TLS_PARAM_ID_BT_REMOTE_DEVICE_X, 加入了自己的字段变量,一个变量32个字节的数组,加了10个。这回好使了,能正常跑。
增加自己的html字段变量
wm_sdk_w800_20210513\platform\common\params\wm_param.h
bt_adapter_t adapter_t; // sizeof(bt_remote_device_t) = 220bt_remote_device_t remote_device1;// 只保留1~2个蓝牙的变量,要不内存不够用
#if 0 bt_remote_device_t remote_device2;bt_remote_device_t remote_device3;bt_remote_device_t remote_device4;bt_remote_device_t remote_device5;bt_remote_device_t remote_device6;bt_remote_device_t remote_device7;bt_remote_device_t remote_device8;bt_remote_device_t remote_device9;bt_remote_device_t remote_device10;
#endif// 这里的内存空间很紧张,如果上面的bt_remote_device_t 有5个,内存空间就满了// 再运行就会崩掉,即使其他处并没有加代码char my_param1[32];char my_param2[32];char my_param3[32];char my_param4[32];char my_param5[32];char my_param6[32];char my_param7[32];char my_param8[32];char my_param9[32];char my_param10[32];
};struct tls_param_flash {
修改点 - 增加html字段变量的flash存取
wm_sdk_w800_20210513\platform\common\params\wm_param.c
这个文件中有多处修改点
case TLS_PARAM_ID_BT_REMOTE_DEVICE_1:MEMCPY(&dest->remote_device1, &src->remote_device1, sizeof(bt_remote_device_t));break;
#if 0
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_2:
// MEMCPY(&dest->remote_device2, &src->remote_device2, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_3:
// MEMCPY(&dest->remote_device3, &src->remote_device3, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_4:
// MEMCPY(&dest->remote_device4, &src->remote_device4, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_5:
// MEMCPY(&dest->remote_device5, &src->remote_device5, sizeof(bt_remote_device_t));
// break;
//
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_6:
// MEMCPY(&dest->remote_device6, &src->remote_device6, sizeof(bt_remote_device_t));
// break;
//
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_7:
// MEMCPY(&dest->remote_device7, &src->remote_device7, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_8:
// MEMCPY(&dest->remote_device8, &src->remote_device8, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_9:
// MEMCPY(&dest->remote_device9, &src->remote_device9, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_10:
// MEMCPY(&dest->remote_device10, &src->remote_device10, sizeof(bt_remote_device_t));
// break;
#endifcase TLS_PARAM_ID_MY_PARAM1:{MEMCPY(&dest->my_param1, &src->my_param1, sizeof(src->my_param1));}break;case TLS_PARAM_ID_MY_PARAM2:{MEMCPY(&dest->my_param2, &src->my_param2, sizeof(src->my_param2));}break;case TLS_PARAM_ID_MY_PARAM3:{MEMCPY(&dest->my_param3, &src->my_param3, sizeof(src->my_param3));}break;case TLS_PARAM_ID_MY_PARAM4:{MEMCPY(&dest->my_param4, &src->my_param4, sizeof(src->my_param4));}break;case TLS_PARAM_ID_MY_PARAM5:{MEMCPY(&dest->my_param5, &src->my_param5, sizeof(src->my_param5));}break;case TLS_PARAM_ID_MY_PARAM6:{MEMCPY(&dest->my_param6, &src->my_param6, sizeof(src->my_param6));}break;case TLS_PARAM_ID_MY_PARAM7:{MEMCPY(&dest->my_param7, &src->my_param7, sizeof(src->my_param7));}break;case TLS_PARAM_ID_MY_PARAM8:{MEMCPY(&dest->my_param8, &src->my_param8, sizeof(src->my_param8));}break;case TLS_PARAM_ID_MY_PARAM9:{MEMCPY(&dest->my_param9, &src->my_param9, sizeof(src->my_param9));}break;case TLS_PARAM_ID_MY_PARAM10:{MEMCPY(&dest->my_param10, &src->my_param10, sizeof(src->my_param10));}break;default:err = TLS_PARAM_STATUS_EINVALIDID;goto exit;}
#endifflash_param.magic = TLS_PARAM_MAGIC;flash_param.length = sizeof(flash_param);if (modify_count < 0){
case TLS_PARAM_ID_BT_REMOTE_DEVICE_1:MEMCPY(¶m->remote_device1, argv, sizeof(bt_remote_device_t));break;
#if 0
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_2:
// MEMCPY(¶m->remote_device2, argv, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_3:
// MEMCPY(¶m->remote_device3, argv, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_4:
// MEMCPY(¶m->remote_device4, argv, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_5:
// MEMCPY(¶m->remote_device5, argv, sizeof(bt_remote_device_t));
// break;
//
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_6:
// MEMCPY(¶m->remote_device6, argv, sizeof(bt_remote_device_t));
// break;
//
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_7:
// MEMCPY(¶m->remote_device7, argv, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_8:
// MEMCPY(¶m->remote_device8, argv, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_9:
// MEMCPY(¶m->remote_device9, argv, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_10:
// MEMCPY(¶m->remote_device10, argv, sizeof(bt_remote_device_t));
// break;
#endifcase TLS_PARAM_ID_MY_PARAM1:{MEMCPY(param->my_param1, argv, sizeof(param->my_param1));}break;case TLS_PARAM_ID_MY_PARAM2:{MEMCPY(param->my_param2, argv, sizeof(param->my_param2));}break;case TLS_PARAM_ID_MY_PARAM3:{MEMCPY(param->my_param3, argv, sizeof(param->my_param3));}break;case TLS_PARAM_ID_MY_PARAM4:{MEMCPY(param->my_param4, argv, sizeof(param->my_param4));}break;case TLS_PARAM_ID_MY_PARAM5:{MEMCPY(param->my_param5, argv, sizeof(param->my_param5));}break;case TLS_PARAM_ID_MY_PARAM6:{MEMCPY(param->my_param6, argv, sizeof(param->my_param6));}break;case TLS_PARAM_ID_MY_PARAM7:{MEMCPY(param->my_param7, argv, sizeof(param->my_param7));}break;case TLS_PARAM_ID_MY_PARAM8:{MEMCPY(param->my_param8, argv, sizeof(param->my_param8));}break;case TLS_PARAM_ID_MY_PARAM9:{MEMCPY(param->my_param9, argv, sizeof(param->my_param9));}break;case TLS_PARAM_ID_MY_PARAM10:{MEMCPY(param->my_param10, argv, sizeof(param->my_param10));}break;default:TLS_DBGPRT_WARNING("invalid parameter id - %d!\n", id);err = TLS_PARAM_STATUS_EINVALIDID;goto exit;}if (to_flash && !updp_mode) {err = param_to_flash(id, -1, -1);TLS_DBGPRT_INFO("write the parameter to spi flash - %d.\n", err);}
exit:tls_os_sem_release(sys_param_lock);return err;
}/**********************************************************************************************************
* Description: This function is used to get system parameter.
*
* Arguments : id param id,from TLS_PARAM_ID_SSID to (TLS_PARAM_ID_MAX - 1)
* argc store parameters
* from_flash whether the parameter is readed from flash,1 read from flash* Returns : TLS_PARAM_STATUS_OK success
* TLS_PARAM_STATUS_EINVALID invalid param
**********************************************************************************************************/
int tls_param_get(int id, void *argv, bool from_flash)
{
case TLS_PARAM_ID_BT_REMOTE_DEVICE_1:MEMCPY(argv,&src->remote_device1, sizeof(bt_remote_device_t));break;#if 0
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_2:
// MEMCPY(argv,&src->remote_device2, sizeof(bt_remote_device_t));
// break;
//
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_3:
// MEMCPY(argv,&src->remote_device3, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_4:
// MEMCPY(argv,&src->remote_device4, sizeof(bt_remote_device_t));
// break;
//
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_5:
// MEMCPY(argv,&src->remote_device5, sizeof(bt_remote_device_t));
// break;
//
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_6:
// MEMCPY(argv,&src->remote_device6, sizeof(bt_remote_device_t));
// break;
//
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_7:
// MEMCPY(argv,&src->remote_device7, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_8:
// MEMCPY(argv,&src->remote_device8, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_9:
// MEMCPY(argv,&src->remote_device9, sizeof(bt_remote_device_t));
// break;
// case TLS_PARAM_ID_BT_REMOTE_DEVICE_10:
// MEMCPY(argv,&src->remote_device10, sizeof(bt_remote_device_t));
// break;
#endifcase TLS_PARAM_ID_MY_PARAM1:{MEMCPY(argv, src->my_param1, sizeof(src->my_param1));}break;case TLS_PARAM_ID_MY_PARAM2:{MEMCPY(argv, src->my_param2, sizeof(src->my_param2));}break;case TLS_PARAM_ID_MY_PARAM3:{MEMCPY(argv, src->my_param3, sizeof(src->my_param3));}break;case TLS_PARAM_ID_MY_PARAM4:{MEMCPY(argv, src->my_param4, sizeof(src->my_param4));}break;case TLS_PARAM_ID_MY_PARAM5:{MEMCPY(argv, src->my_param5, sizeof(src->my_param5));}break;case TLS_PARAM_ID_MY_PARAM6:{MEMCPY(argv, src->my_param6, sizeof(src->my_param6));}break;case TLS_PARAM_ID_MY_PARAM7:{MEMCPY(argv, src->my_param7, sizeof(src->my_param7));}break;case TLS_PARAM_ID_MY_PARAM8:{MEMCPY(argv, src->my_param8, sizeof(src->my_param8));}break;case TLS_PARAM_ID_MY_PARAM9:{MEMCPY(argv, src->my_param9, sizeof(src->my_param9));}break;case TLS_PARAM_ID_MY_PARAM10:{MEMCPY(argv, src->my_param10, sizeof(src->my_param10));}break;default:TLS_DBGPRT_WARNING("invalid parameter id - %d!\n", id);err = TLS_PARAM_STATUS_EINVALIDID;break;}
#if USE_TWO_RAM_FOR_PARAMETER
#elseif (curflashparm){tls_mem_free(curflashparm);}
#endiftls_os_sem_release(sys_param_lock);return err;
}/**********************************************************************************************************
* Description: This function is used to write parameter to flash.
*
* Arguments : id param id,from TLS_PARAM_ID_ALL to (TLS_PARAM_ID_MAX - 1)
*
* Returns : * Returns : TLS_PARAM_STATUS_OK success
* TLS_PARAM_STATUS_EINVALID invalid param
* TLS_PARAM_STATUS_EIO error
**********************************************************************************************************/
int tls_param_to_flash(int id)
{
修改点 - 增加wifi热点连接结果的调试信息
wm_sdk_w800_20210513\platform\sys\tls_sys.c
#if TLS_CONFIG_APcase NETIF_WIFI_SOFTAP_SUCCESS:TLS_DBGPRT_INFO("3 softap create success.\n");tls_sys_net2_up();break;case NETIF_WIFI_SOFTAP_FAILED:TLS_DBGPRT_INFO("4 softap create failed.\n");tls_sys_net2_fail(); break;case NETIF_WIFI_SOFTAP_CLOSED:TLS_DBGPRT_INFO("softap closed.\n");tls_sys_net2_down();break;case NETIF_IP_NET2_UP:
#if TLS_CONFIG_TLS_DEBUGethif = tls_netif_get_ethif2();TLS_DBGPRT_INFO("net up ==> ip = %d.%d.%d.%d\n" ip4_addr1(ip_2_ip4(ðif->ip_addr)), ip4_addr2(ip_2_ip4(ðif->ip_addr)),ip4_addr3(ip_2_ip4(ðif->ip_addr)), ip4_addr4(ip_2_ip4(ðif->ip_addr)));
#endifbreak;
#endifdefault:break;}
}//-------------------------------------------------------------------------int tls_sys_init()
{
修改点 - 修改自己建立的wifi热点名称
wm_sdk_w800_20210513\src\app\oneshotconfig\wm_wifi_oneshot.c
#define APSKT_MAX_ONESHOT_NUM (8)
#define APSKT_SSID_MAX_LEN (32)
#define ONESHOT_AP_NAME "my_ap"
打印AP建立结果的调试信息
/*END CONFIG_UDP_ONE_SHOT*/
#endif
#if TLS_CONFIG_AP_MODE_ONESHOT
int soft_ap_create(void)
{struct tls_softap_info_t apinfo;struct tls_ip_info_t ipinfo;u8 ret=0;u8 ssid_set = 0;char ssid[33];u8 mac_addr[6];tls_get_mac_addr(mac_addr);ssid[0]='\0';u8 ssid_len = sprintf(ssid, "%s_%s_%s_%s_%s_%02x%02x", ONESHOT_AP_NAME, "192", "168", "8", "1", mac_addr[4], mac_addr[5]);printf("\nssid_len = %d\n", ssid_len);tls_param_get(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, (bool)0);if (0 == ssid_set){ssid_set = 1;tls_param_set(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, (bool)1); /*Set BSSID broadcast flag*/}memset(&apinfo, 0, sizeof(struct tls_softap_info_t));MEMCPY(apinfo.ssid, ssid, ssid_len);apinfo.ssid[ssid_len]='\0';apinfo.encrypt = 0; /*0:open, 1:wep64, 2:wep128*/apinfo.channel = 5; /*channel random*//*ip information: ip address?ê?netmask?ê?dns*/// soft ap 建立后, IP不能是192.168.1.1. 因为一般网络都是192.168.1.xipinfo.ip_addr[0] = 192;ipinfo.ip_addr[1] = 168;ipinfo.ip_addr[2] = 8;ipinfo.ip_addr[3] = 1;ipinfo.netmask[0] = 255;ipinfo.netmask[1] = 255;ipinfo.netmask[2] = 255;ipinfo.netmask[3] = 0;MEMCPY(ipinfo.dnsname, "local.wm", sizeof("local.wm"));ret = tls_wifi_softap_create((struct tls_softap_info_t* )&apinfo, (struct tls_ip_info_t* )&ipinfo);printf("\n5 ap create %s ! \n", (ret == WM_SUCCESS)? "Successfully" : "Error");return ret;
}
#if TLS_CONFIG_SOCKET_MODE
修改点 - 打开http调试信息
因为没买硬件调试器,就需要打印调试信息,这样在http回包时,就知道自己回的啥。
wm_sdk_w800_20210513\src\app\web\httpd.h
#define INCLUDE_HTTPD_DEBUG#ifdef INCLUDE_HTTPD_DEBUG
#define DEBUG_PRINT printf
#else
#define DEBUG_PRINT(s, ...)
#endif
修改点 - html文件需要回活数据的处理
http请求到了W800工程中,需要判断哪个html需要回活数据,做了一个标志。
如果不需要回活数据,直接回fsdata_lwip.c定义的固定数据。
wm_sdk_w800_20210513\src\app\web\httpd.c
需要回活数据的标志为 FILEFLAG_FILTER
#endif
// 如果有过滤标志,这些值要从保存的参数中来
if (hs->file_flag & FILEFLAG_FILTER)
{int memlen=len+10;Temp=mem_malloc(memlen);if(Temp==NULL){err = ERR_MEM;return;}do {
#if 1 int templen=0,j=0;filelen=0;memset(Temp,0,memlen); do
/** We found a CGI that handles this URI so extract the* parameters and call the handler.*/count = extract_uri_parameters(hs, params);strcpy(Url, g_pCGIs[i].pfnCGIHandler(i, count, hs->params, hs->param_vals,&NeedRestart));if(NeedRestart==1){send_jump_html(hs,pcb);DEBUG_PRINT("Sending jump html\n\r"); resethandler();return 0;}break;}}}
#endifDEBUG_PRINT("ls debug : Opening %s\n\r", Url);file = fs_open(Url);// 如果是要从参数区取最新数据的文件,要带上 FILEFLAG_FILTER 标记// "hed" 这里原先判断是否html名字中包含"hed", 这就能解释为啥工程中自带的index.html中frame指定的src是 hedbasic.html, 但是SDK的html目录中为啥不提供hedbasic.html? 这让用户咋玩?if (strstr(Url, "basic.html")){ hs->file_flag |= FILEFLAG_FILTER;} if(file == NULL) {file = fs_open("/404.html");}
#ifdef INCLUDE_HTTPD_SSIelse {
修改点 - 确定固定回包是哪个数组.c 文件
wm_sdk_w800_20210513\src\app\web\fs.c
#ifdef FSDATA_IN_EXT_FLASH
#define FS_ROOT (FSDATA_BASE_ADDR+4)#else#if WEB_SERVER_RUSSIAN // #include "fsdata_lwip_russian.c"
#elif WEB_SERVER_BASIC// #include "fsdata_lwip_basic.c"
#elif WEB_SERVER_RUIGONG// #include "fsdata_lwip_ruigong.c"
#else#include "fsdata_lwip.c" // 通过屏蔽法,可知工程中默认用的是这个.c, 如果自己重新生成(html 转.c), 也要生成这个同名文件
#endif#endif// Web_parse_line我改了,加了一个参数tableid
// 如果明白了网页交互的流程,这个函数不用改,只是为了调试才改的。
extern u16 Web_parse_line(char * id_char,u16 * after_id_len,char * idvalue,u16 * Value_Offset,u8 * Id_type, u8* tableid);
理解回包为活数据时的拼接原理,需要加一些调试语句才知道
回包都在fs_read_line()中实现,我加过调试信息的版本如下
只有理解了这个函数,才明白Web_parse_line中使用的web_id_tbl[]中新增的字段读写定义该怎么填?
我看这个回包拼接过程花了好长时间,这时就凸显关键时候,有个硬件调试器该有多爽,花钱买时间有的时候值的一试。
以前也有个工程,因为运行环境做了反调试限制,就靠打文件日志来排查逻辑错误,一个插件模块500行代码写了3天,才写对收工。
/*-----------------------------------------------------------------------------------
// Description: Read one line text into buffer s, and return its length
// Parameters: file:char buffer :buffer to store the text read from file
// max_length: max length of one line
*/
int fs_read_line(const void *ori_data, char *buffer, int max_length, int *tembuflen)
{#define MAX_ID_VALUE_BUFFER_LEN 2048int len=0; char * temp, *data = NULL;char * idvaluebuffer=NULL;///[MAX_ID_BUFFER_LEN];u16 beforeidlen=0;u16 Idlen=0;u16 startatfteid=0;u16 Lenchange=0;u8 IdType=0;u8 u8_tableid = 0;#ifdef FSDATA_IN_EXT_FLASHdata = ext_flash_read_line((unsigned int)ori_data);#elsedata = (char *)ori_data;#endif if(*tembuflen >= 1024){return -1;}idvaluebuffer = mem_malloc(MAX_ID_VALUE_BUFFER_LEN);if(idvaluebuffer == NULL){return -1;}memset(idvaluebuffer, 0, MAX_ID_VALUE_BUFFER_LEN);temp = (char *)data;while(*temp++ != '\n'){if(*temp == 'i' && *(temp+1) == 'd' && *(temp+2) == '='){if(*(temp+3) == '"'){printf("\n >> (temp+4) = %c%c%c%c%c%c%c%c%c%c\n", temp[4 + 0],temp[4 + 1],temp[4 + 2],temp[4 + 3],temp[4 + 4],temp[4 + 5],temp[4 + 6],temp[4 + 7],temp[4 + 8],temp[4 + 9]);u8_tableid = 0;Idlen=Web_parse_line(temp+4,&beforeidlen,idvaluebuffer,&startatfteid,&IdType, &u8_tableid);if ((u8_tableid >= 67 /*Web_Id_my_param1*/) && (u8_tableid <= 76 /*Web_Id_my_param10*/)) {printf("\nWeb_parse_line from Web_Id_my_param1 to Web_Id_my_param10, u8_tableid = %d\n", u8_tableid);printf("\nidvaluebuffer = %s\n", idvaluebuffer);}if(Idlen!=0){if(Idlen>startatfteid){Lenchange=Idlen-startatfteid;}beforeidlen+=(len+1);} }}len++;}len++;printf("\nIdType = %d\n", IdType);if(IdType==0x00){printf("\nlen = %d, Lenchange = %d, beforeidlen = %d, startatfteid = %d\n", len, Lenchange, beforeidlen, startatfteid);if (len+Lenchange<= max_length){ if(Idlen==0){printf("\nIdlen == 0, copy old html\n");memcpy(buffer, data, len);* tembuflen+=len;}else{printf("\nIdlen = %d, copy new html\n", Idlen);printf("\nbeforeidlen = %d\n", beforeidlen);printf("\n1. buffer = %s\n", buffer);memcpy(buffer,data,beforeidlen);printf("\n2. buffer = %s\n", buffer);* tembuflen+=beforeidlen;strcpy(buffer+beforeidlen,idvaluebuffer);printf("\n3. buffer = %s\n", buffer);* tembuflen+=Idlen;memcpy(buffer+beforeidlen+Idlen,((char *)data+beforeidlen+startatfteid),(len-beforeidlen-startatfteid));printf("\n4. buffer = %s\n", buffer);* tembuflen+=(len-beforeidlen-startatfteid); }}else{printf("\nlen = -1\n");len = -1;}} else if(IdType==0x01){if(beforeidlen+Lenchange<= max_length) {if(Idlen==0){memcpy(buffer, data, len);* tembuflen+=len;}else{memcpy(buffer,data,beforeidlen); * tembuflen+=beforeidlen;strcpy(buffer+beforeidlen,idvaluebuffer);* tembuflen+=Idlen;} }else{len = -1; }}else{len = -1;}if(idvaluebuffer)mem_free(idvaluebuffer);return len;
}
修改点 - 网页字段交互逻辑的主实现
wm_sdk_w800_20210513\src\app\web\web.c
ID_VALUE是新增一个html字段处理时,要填的字段处理信息。
理解了fs_read_line()的回包拼接处理,就理解了ID_VALUE该怎么填。我加了注释,给了例子。
typedef struct _ID_VALUE{// key-value的数据格式// id="Ssid" value="my_wifi"char *IdName; // id的名称 "Ssid"u8 tableid; // id的索引 e.g. Web_Id_my_param1 u8 Idlen; // id="Ssid" value=" 的长度, 加上Idlen长度后,就到了copy value实际值的地方u8 Value_Offset; // value初始化值的长度, 跳过这段长度, 就可以拼接原始html value后面的值// 对于下面的key-value来说// id="Ssid" value="value_at_init"// IdName = "Ssid"// tableid是自己定义的, 只要和web_id_tbl中位置索引相同就好// Idlen = len(id="Ssid" value=") = 17// Value_Offset = len(value_at_init) = 13} ID_VALUE;
加入字段索引
#define Web_Id_my_param1 67
#define Web_Id_my_param2 68
#define Web_Id_my_param3 69
#define Web_Id_my_param4 70
#define Web_Id_my_param5 71
#define Web_Id_my_param6 72
#define Web_Id_my_param7 73
#define Web_Id_my_param8 74
#define Web_Id_my_param9 75
#define Web_Id_my_param10 76#define ENCRYPT_TYPE_OPEN_SYS 0///open
#define ENCRYPT_TYPE_WEP_64_BITS 1
#define ENCRYPT_TYPE_WEP_128_BITS 2
加入要处理的字段定义
{"AutoHiden",Web_AutoHidden_Id,22,1,},// my 10 param{"my_param1",Web_Id_my_param1,22,6,},{"my_param2",Web_Id_my_param2,22,6,},{"my_param3",Web_Id_my_param3,22,6,},{"my_param4",Web_Id_my_param4,22,6,},{"my_param5",Web_Id_my_param5,22,6,},{"my_param6",Web_Id_my_param6,22,6,},{"my_param7",Web_Id_my_param7,22,6,},{"my_param8",Web_Id_my_param8,22,6,},{"my_param9",Web_Id_my_param9,22,6,},{"my_param10",Web_Id_my_param10,23,7,}#if 0,NULL,
#endif
};#if 0
char * Encry_Open[]={
将回包数据改成活数据的处理
Web_parse_line()函数中加了回包字段的处理
调试语句和增加的tableid传出参数是调试的,不是必须。
Web_parse_line()函数比较大,因为是switch-case处理,变量越多,这个函数越长。
可以将demo中提供,我们不用的html字段处理去掉,节省点代码空间。
将Web_parse_line()全部贴在这。
u16 Web_parse_line(char * id_char,u16 * after_id_len,char * idvalue,u16 * Value_Offset,u8 * Id_type, u8* tableid)
{/*char idbuffer[MAX_ID_BUFFER_LEN];u8 j=0, mode, encrypt;ID_VALUE *idtble;u8 tableid=0;struct tls_param_ip ip_param;short channellist;struct tls_param_key param_key;u8 auto_mode;struct tls_param_socket remote_socket_cfg;struct tls_param_bssid bssid;struct tls_param_uart uart_cfg;*/char idbuffer[MAX_ID_BUFFER_LEN];u8 j=0, mode;//, encrypt;ID_VALUE *idtble;// u8 tableid=0;struct tls_param_ip ip_param;struct tls_param_key param_key;int k;// printf("\n>> Web_parse_line(after_id_len = %d, id_char = %s)\n", after_id_len, (NULL != id_char) ? id_char : "NULL");// printf("\n>> Web_parse_line(after_id_len = %d, id_char)\n", after_id_len);memset(idbuffer,0,MAX_ID_BUFFER_LEN);* Id_type=0;while(*(id_char+j)!='"'){j++;}memcpy(idbuffer,id_char,j);for (k = 0; k < sizeof(web_id_tbl) / sizeof(ID_VALUE); k++){idtble = (ID_VALUE *)&web_id_tbl[k];if (strcmp(idbuffer,idtble->IdName) == 0){*tableid=idtble->tableid;break;}}//#if 0
// for (idtble = (ID_VALUE *)&web_id_tbl[0]; idtble->IdName; idtble++)
// {
// if (strcmp(idbuffer,idtble->IdName) == 0)
// {
// tableid=idtble->tableid;
// break;
// }
// }
//#endifprintf("###kevin debug Web_parse_line = %s\n\r",idbuffer);tls_param_get(TLS_PARAM_ID_IP, &ip_param, FALSE);switch((int)(*tableid)){case Dhcp_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);if(ip_param.dhcp_enable){sprintf(idvalue, "οnclick=\"dhcp1()\" value=\"1\" checked=\"CHECKED\" %s/>Auto IP Enable</label></td>\n", mode==IEEE80211_MODE_AP ? "disabled=\"disabled\" " : "");}else{sprintf(idvalue, "οnclick=\"dhcp1()\" value=\"1\" %s/>Auto IP Enable</label></td>\n", mode==IEEE80211_MODE_AP ? "disabled=\"disabled\" " : "");}*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; */break;case Web_Ip_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);if(!ip_param.dhcp_enable || mode==IEEE80211_MODE_AP){sprintf(idvalue, "%d.%d.%d.%d", \ip_param.ip[0], ip_param.ip[1],\ip_param.ip[2], ip_param.ip[3]);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{sprintf(idvalue, "%d.%d.%d.%d\" disabled=\"disabled\" ", \0, 0,\0, 0);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1; }*/break;case Web_Sub_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);if(!ip_param.dhcp_enable || mode==IEEE80211_MODE_AP){sprintf(idvalue, "%d.%d.%d.%d", \ip_param.netmask[0], ip_param.netmask[1],\ip_param.netmask[2], ip_param.netmask[3]);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{sprintf(idvalue, "%d.%d.%d.%d\" disabled=\"disabled\" ", \0,0,\0, 0);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1;}*/break;case DNS_Gate_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);if((!ip_param.dhcp_enable)&&(mode != IEEE80211_MODE_AP)){ sprintf(idvalue, "%d.%d.%d.%d", \ip_param.gateway[0], ip_param.gateway[1],\ip_param.gateway[2], ip_param.gateway[3]);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{sprintf(idvalue, "%d.%d.%d.%d\" disabled=\"disabled\" ",\0, 0,\0, 0);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1; }*/break;case DNS_Dns_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);if((!ip_param.dhcp_enable)&&(mode != IEEE80211_MODE_AP)){ sprintf(idvalue, "%d.%d.%d.%d", \ip_param.dns1[0], ip_param.dns1[1],\ip_param.dns1[2], ip_param.dns1[3]);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{sprintf(idvalue, "%d.%d.%d.%d\" disabled=\"disabled\" ",\0, 0,\0, 0);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1; }*/break;case Web_DnsName_Id:/*{u8 dnsname[32];tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_DNSNAME, dnsname, FALSE);if(mode == IEEE80211_MODE_AP){ {sprintf(idvalue, "%s", (char *)dnsname);}*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{sprintf(idvalue, "%s\" disabled=\"disabled\" ", (char *)dnsname);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1; }}*/break;case Web_Encry_Id:{char str[100];struct tls_scan_bss_t *scan_res = NULL;struct tls_bss_info_t *bss_info;u8 *bssBuff = NULL;bssBuff = tls_mem_alloc(BSS_INFO_SIZE);memset(bssBuff, 0, sizeof(BSS_INFO_SIZE));tls_wifi_scan_result_cb_register(scan_result_cb);while (WM_SUCCESS !=tls_wifi_scan()) {tls_os_time_delay(HZ/5);}while( scan_done == 0 ) {tls_os_time_delay(HZ/5);}scan_done = 0;tls_wifi_get_scan_rslt(bssBuff, BSS_INFO_SIZE);scan_res = (struct tls_scan_bss_t *)bssBuff;bss_info = scan_res->bss;DEBUG_PRINT("scan: %d\r\n", scan_res->count);strcpy(idvalue, "arentNode.previousSibling.value=this.value\">\n");sprintf(str, "<option value=\"\"></option>\n");strcat(idvalue, str);for(u8 i=0; i<scan_res->count && i<40; i++){if( bss_info->ssid != NULL && bss_info->ssid_len != 0 ){*(bss_info->ssid + bss_info->ssid_len) = '\0';sprintf(str, "<option value=\"%s\">%s</option>\n", bss_info->ssid, bss_info->ssid);strcat(idvalue, str);bss_info->ssid[bss_info->ssid_len] = '\0';DEBUG_PRINT("legal: %s\r\n", bss_info->ssid);}else{bss_info->ssid[bss_info->ssid_len] = '\0';DEBUG_PRINT("illegal: %d, %s\r\n", bss_info->ssid_len, bss_info->ssid);}bss_info ++; }if( bssBuff != NULL ) {tls_mem_free(bssBuff);bssBuff = NULL;}*after_id_len = idtble->Idlen-4;*Value_Offset = idtble->Value_Offset; *Id_type = 0x01; }break;case Web_Ssid_Id:{ struct tls_param_ssid ssid;tls_param_get(TLS_PARAM_ID_SSID, (void *)&ssid, FALSE);memcpy(idvalue, ssid.ssid, ssid.ssid_len);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; /*case Web_Encry_Id:{int i = 0;char str[100];tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_ENCRY, (void *)&encrypt, FALSE);if(mode == IEEE80211_MODE_INFRA){//strcpy(idvalue, " disabled=\"disabled\">");strcpy(idvalue, " >");for(i=0;i<6;i++){sprintf(str, "<option value=\"%d\" %s>%s</option>", i, \(i == 0)? "selected=\"selected\"" : "", Encry_Open[i]);strcat(idvalue, str);}*after_id_len = idtble->Idlen-4;*Value_Offset = idtble->Value_Offset; *Id_type = 0x01;}else if(mode == IEEE80211_MODE_AP){ for(i=0;i<7;i++){sprintf(str, "<option value=\"%d\" %s>%s</option>", i, \(i == encrypt)? "selected=\"selected\"" : "", Encry_Open[i]);strcat(idvalue, str);}*after_id_len=idtble->Idlen;*Value_Offset = idtble->Value_Offset; *Id_type = 0x01;}else { for(i=0;i<3;i++){sprintf(str, "<option value=\"%d\" %s>%s</option>", i, \(i == encrypt)? "selected=\"selected\"" : "", Encry_Open[i]);strcat(idvalue, str);}*after_id_len=idtble->Idlen;*Value_Offset = idtble->Value_Offset; *Id_type = 0x01;}}break;*/case Web_Key_Id:tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_KEY, (void *)¶m_key, FALSE);
// tls_param_get(TLS_PARAM_ID_ENCRY, (void *)&encrypt, FALSE);if((mode & IEEE80211_MODE_INFRA) ||(IEEE80211_MODE_AP & mode))// (encrypt != ENCRYPT_TYPE_OPEN_SYS)){DEBUG_PRINT("key:%s, keyLen:%d\n", param_key.psk, param_key.key_length);sprintf(idvalue, "%s", param_key.psk); idvalue[param_key.key_length] = '\0';*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{//sprintf(idvalue, "%d\" disabled=\"disabled\" ", 0);sprintf(idvalue, "\" disabled=\"disabled\" ");*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1;}printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);break;case KeyType_Id:/*tls_param_get(TLS_PARAM_ID_KEY, (void *)¶m_key, FALSE);tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_ENCRY, (void *)&encrypt, FALSE);if((mode == IEEE80211_MODE_INFRA) || (encrypt == ENCRYPT_TYPE_OPEN_SYS)){if(param_key.key_format ==1)///Sever{sprintf(idvalue," disabled=\"disabled\"> <option value=\"0\">HEX</option> <option value=\"1\" selected=\"selected\">ASCII</option>\n"); }else //Client{sprintf(idvalue," disabled=\"disabled\"> <option value=\"0\" selected=\"selected\">HEX</option> <option value=\"1\">ASCII</option>\n"); }*after_id_len=idtble->Idlen-2;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }else{if(param_key.key_format ==1){strcpy(idvalue,"<option value=\"0\">HEX</option> <option value=\"1\" selected=\"selected\">ASCII</option>\n");}else{strcpy(idvalue,"<option value=\"0\" selected=\"selected\">HEX</option> <option value=\"1\">ASCII</option>\n");}*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;}*/break;case Web_Auto_Id:/*tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, FALSE);
#if 1if(auto_mode){strcpy(idvalue,Auto_type[1]); }else{strcpy(idvalue,Auto_type[0]); }
#else{sprintf(idvalue, "οnclick=\"auto()\" value=\"%d\" %s /> 远模式</label></td>\n",\(!auto_mode), \(!auto_mode) ? Web_null : Web_checked); }
#endif*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; */break;case Web_AutoHidden_Id:/*tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, FALSE);if(auto_mode){strcpy(idvalue, "1"); }else{strcpy(idvalue, "0"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;*///* Id_type=0x01; break;case Web_Protocol_Id:/*tls_param_get(TLS_PARAM_ID_DEFSOCKET, &remote_socket_cfg, FALSE);tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, FALSE);if(auto_mode==1){if(remote_socket_cfg.protocol){sprintf(idvalue,"%s",Protocol_type[1]); }else TCP{sprintf(idvalue,"%s",Protocol_type[0]);}*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }else{if(remote_socket_cfg.protocol){sprintf(idvalue,"disabled=\"disabled\" %s",Protocol_type[1]); }else TCP{sprintf(idvalue,"disabled=\"disabled\" %s",Protocol_type[0]);}*after_id_len=idtble->Idlen-2;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }*/break;case Web_Cs_Id:/*tls_param_get(TLS_PARAM_ID_DEFSOCKET, &remote_socket_cfg, FALSE);tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, FALSE);if(auto_mode==1){ if(remote_socket_cfg.client_or_server)///Sever{strcpy(idvalue,Cs_type[1]); }else //Client{strcpy(idvalue,Cs_type[0]); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }else{if(remote_socket_cfg.client_or_server)///Sever{sprintf(idvalue,"disabled=\"disabled\" %s",Cs_type[1]); }else //Client{sprintf(idvalue,"disabled=\"disabled\" %s",Cs_type[0]); }*after_id_len=idtble->Idlen-2;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }*/break;case Web_Domain_Id:/*tls_param_get(TLS_PARAM_ID_DEFSOCKET, &remote_socket_cfg, FALSE);tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, FALSE);if(auto_mode==1){ if(remote_socket_cfg.client_or_server && remote_socket_cfg.protocol == 0){sprintf(idvalue, "%s \" disabled=\"disabled\"", "0.0.0.0");*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1; break;}else{sprintf(idvalue, "%s", (char *)remote_socket_cfg.host);}*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{sprintf(idvalue, "%s\" disabled=\"disabled\" ", "0.0.0.0");*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1; }*/break; case Web_Port_Id:/*tls_param_get(TLS_PARAM_ID_DEFSOCKET, &remote_socket_cfg, FALSE);tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, FALSE);if(auto_mode==1){sprintf(idvalue, "%d", remote_socket_cfg.port_num);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{sprintf(idvalue, "%d\" disabled=\"disabled\" ", 0);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1;}*/break; case Wep_KeyIndex_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_KEY, (void *)¶m_key, FALSE);tls_param_get(TLS_PARAM_ID_ENCRY, (void *)&encrypt, FALSE);if((mode != IEEE80211_MODE_INFRA) && (encrypt==ENCRYPT_TYPE_WEP_64_BITS||encrypt==ENCRYPT_TYPE_WEP_128_BITS)){if(param_key.key_index==1)///Sever{sprintf(idvalue, "%s","checked=\"CHECKED\" />\n");}else{sprintf(idvalue, "%s","/>\n"); }}else{sprintf(idvalue, "%s","disabled=\"disabled\" />\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; */break;case Wep_KeyIndex2_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_KEY, (void *)¶m_key, FALSE);tls_param_get(TLS_PARAM_ID_ENCRY, (void *)&encrypt, FALSE);if((mode != IEEE80211_MODE_INFRA) && (encrypt==ENCRYPT_TYPE_WEP_64_BITS||encrypt==ENCRYPT_TYPE_WEP_128_BITS)){if(param_key.key_index==2)//{sprintf(idvalue, "%s","checked=\"CHECKED\" />\n"); }else{sprintf(idvalue, "%s","/>\n"); }}else{sprintf(idvalue, "%s","disabled=\"disabled\" />\n"); } *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; */break; case Wep_KeyIndex3_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_KEY, (void *)¶m_key, FALSE);tls_param_get(TLS_PARAM_ID_ENCRY, (void *)&encrypt, FALSE);if((mode != IEEE80211_MODE_INFRA) && (encrypt==ENCRYPT_TYPE_WEP_64_BITS||encrypt==ENCRYPT_TYPE_WEP_128_BITS)){ if(param_key.key_index==3)///{sprintf(idvalue, "%s","checked=\"CHECKED\" />\n"); }else{sprintf(idvalue, "%s","/>\n"); }}else{sprintf(idvalue, "%s","disabled=\"disabled\" />\n"); } *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; */break; case Wep_KeyIndex4_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_KEY, (void *)¶m_key, FALSE);tls_param_get(TLS_PARAM_ID_ENCRY, (void *)&encrypt, FALSE);if((mode != IEEE80211_MODE_INFRA) && (encrypt==ENCRYPT_TYPE_WEP_64_BITS||encrypt==ENCRYPT_TYPE_WEP_128_BITS)){ if(param_key.key_index==4)///{sprintf(idvalue, "%s","checked=\"CHECKED\" />\n"); }else{sprintf(idvalue, "%s","/>\n"); }}else{sprintf(idvalue, "%s","disabled=\"disabled\" />\n"); } *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; */break; case Web_Mode_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);
#if WEB_SERVER_RUSSIANif(gCurHtmlFile){strcpy(idvalue,Web_Mode[mode + 3]); // get russian str}else{strcpy(idvalue,Web_Mode[mode]);}
#elsestrcpy(idvalue,Web_Mode[mode]);
#endif*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; */break;case Web_Bg_Id:/*{struct tls_param_bgr wbgr;tls_param_get(TLS_PARAM_ID_WBGR, (void *)&wbgr, FALSE);if(wbgr.bg==0)/bg{strcpy(idvalue,"<option value=\"0\" selected=\"selected\">B/G</option> <option value=\"1\">B</option><option value=\"2\">B/G/N</option>\n");}else if(wbgr.bg==2) //bgn{strcpy(idvalue,"<option value=\"0\" >B/G</option> <option value=\"1\">B</option><option value=\"2\" selected=\"selected\">B/G/N</option> \n"); }else b{strcpy(idvalue,"<option value=\"0\" >B/G</option> <option value=\"1\" selected=\"selected\">B</option><option value=\"2\">B/G/N</option>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }*/break;case Web_Rate_Id:/*
#if 0strcpy(idvalue,Web_Rate[wbgr.max_rate]);
#else{int i;char str[] = "<option value=\"11\" selected=\"selected\">54M</option> ";struct tls_param_bgr wbgr;tls_param_get(TLS_PARAM_ID_WBGR, (void *)&wbgr, FALSE);if(wbgr.bg ==0)/bg{for(i=0;i<12;i++){sprintf(str, "<option value=\"%d\" %s>%s</option>", i, \(i == wbgr.max_rate)? "selected=\"selected\"" : "", Web_Rate[i]);strcat(idvalue, str);}}else if(wbgr.bg ==2) //bgn{for(i=0;i<29;i++){sprintf(str, "<option value=\"%d\" %s>%s</option>", i, \(i == wbgr.max_rate)? "selected=\"selected\"" : "", Web_Rate[i]);strcat(idvalue, str);} }else{for(i=0;i<4;i++){sprintf(str, "<option value=\"%d\" %s>%s</option>", i, \(i == wbgr.max_rate)? "selected=\"selected\"" : "", Web_Rate[i]);strcat(idvalue, str);} }strcat(idvalue, "\n");}
#endif *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break;case Web_Bssid_Id:/*{tls_param_get(TLS_PARAM_ID_BSSID, (void *)&bssid, FALSE);tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);u8 Bssid[6]; if(mode==0){if(bssid.bssid_enable==1){memcpy(Bssid, bssid.bssid, 6);sprintf(idvalue, "%02X%02X%02X%02X%02X%02X", Bssid[0],Bssid[1],Bssid[2], Bssid[3],Bssid[4], Bssid[5]); *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{memset(Bssid, 0, 6); sprintf(idvalue, "%02X%02X%02X%02X%02X%02X \" disabled=\"disabled\" ", Bssid[0],Bssid[1],Bssid[2], Bssid[3],Bssid[4], Bssid[5]); *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1; }}else{memset(Bssid, 0, 6); sprintf(idvalue, "%02X%02X%02X%02X%02X%02X\" disabled=\"disabled\" ", Bssid[0],Bssid[1],Bssid[2], Bssid[3],Bssid[4], Bssid[5]); *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1; }}*/break; case Web_Channel_Id:/*{u8 channel;u8 channel_en;tls_param_get(TLS_PARAM_ID_CHANNEL, (void *)&channel, FALSE);tls_param_get(TLS_PARAM_ID_CHANNEL_EN, (void *)&channel_en, FALSE);
#if 0strcpy(idvalue,Web_Channel[channel]);
#else{int i;char str[] = "<option value=\"0\" selected=\"selected\">Auto </option>";if (!channel_en){strcpy(idvalue, str);}else{strcpy(idvalue, "<option value=\"0\" >Auto </option>");}for(i=1;i<=14;i++){sprintf(str, "<option value=\"%d\" %s>%d</option>", i, \((channel_en)&&(i == channel))? "selected=\"selected\"" : "", i);strcat(idvalue, str);}strcat(idvalue, "\n");}
#endif*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }*/break;case Web_ChannlListCh1_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<0)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; */break;case Web_ChannlListCh2_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<1)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break;case Web_ChannlListCh3_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<2)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh4_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<3)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh5_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<4)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh6_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<5)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh7_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<6)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh8_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<7)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh9_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<8)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh10_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<9)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh11_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<10)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh12_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<11)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh13_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<12)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_ChannlListCh14_Id:/*tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, FALSE);if(channellist&(0x01<<13)){strcpy(idvalue,"checked=\"CHECKED\" />\n"); }else{strcpy(idvalue,"/>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_WebPort_Id:/*{struct tls_webs_cfg webcfg;tls_param_get(TLS_PARAM_ID_WEBS_CONFIG, (void *)&webcfg, FALSE);if(1<webcfg.PortNum<10000)sprintf(idvalue, "%d", webcfg.PortNum);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}*/break;case Web_Baud_Id: /BAUDRATE_115200/*tls_param_get(TLS_PARAM_ID_UART, (void *)&uart_cfg, FALSE);
#if 0 strcpy(idvalue,Web_Baud[pSysVal->CfgPara.UartCfg.BaudRate]);
#else{int i;char str[] = "<option value=\"0\" selected=\"selected\">115200</option> ";for(i=0;i<BAUDRATE_BELOW;i++){sprintf(str, "<option value=\"%d\" %s>%d</option>", i, \(Web_Baud[i] == uart_cfg.baudrate)? "selected=\"selected\"" : "", \Web_Baud[i]);strcat(idvalue, str);}strcat(idvalue, "\n");}
#endif*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break;case Web_Check_Id:/*tls_param_get(TLS_PARAM_ID_UART, (void *)&uart_cfg, FALSE);if(uart_cfg.parity==0){strcpy(idvalue,"<option value=\"0\" selected=\"selected\">None </option> <option value=\"1\">Odd </option> <option value=\"2\">Even </option>\n");}else if(uart_cfg.parity==1){strcpy(idvalue,"<option value=\"0\" >None </option> <option value=\"1\" selected=\"selected\">Odd </option> <option value=\"2\">Even </option>\n");}else{strcpy(idvalue,"<option value=\"0\" >None </option> <option value=\"1\">Odd </option> <option value=\"2\" selected=\"selected\">Even </option>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break;case Web_StopSize_Id:/*tls_param_get(TLS_PARAM_ID_UART, (void *)&uart_cfg, FALSE);if(uart_cfg.stop_bits==0){strcpy(idvalue,"<option value=\"0\" selected=\"selected\">1</option> <option value=\"1\">2</option>\n"); }else if(uart_cfg.stop_bits==1){strcpy(idvalue,"<option value=\"0\" >1</option> <option value=\"1\" selected=\"selected\">2</option>\n"); }else{}*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break;case Web_DataSize_Id:/*//strcpy(idvalue,Web_DataSize[pSysVal->CfgPara.UserIntfCfg.Uart.DataBits]);// kevin modify 20131227 only 8 bit strcpy(idvalue,Web_DataSize[0]);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break;case Web_EscChar_Id:/*{u8 escapechar;tls_param_get(TLS_PARAM_ID_ESCAPE_CHAR, (void *)&escapechar, FALSE);sprintf(idvalue, "%X", escapechar);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset; }*/break;case Web_EscP_Id:/*{u16 EscapePeriod;tls_param_get(TLS_PARAM_ID_ESCAPE_PERIOD, (void *)&EscapePeriod, FALSE);sprintf(idvalue, "%d", EscapePeriod);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset; }*/break;case Web_EscDataP_Id:/*{u16 PeriodT;tls_param_get(TLS_PARAM_ID_AUTO_TRIGGER_PERIOD, (void *)&PeriodT, FALSE);sprintf(idvalue, "%d", PeriodT);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset; }*/break;case Web_EscDataL_Id:/*{u16 LengthT;tls_param_get(TLS_PARAM_ID_AUTO_TRIGGER_LENGTH, (void *)&LengthT, FALSE);sprintf(idvalue, "%d", LengthT);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset; }*/break;
#if 0 case Web_GPIO1_Id:if(pSysVal->CfgPara.IOMode==0){strcpy(idvalue,"<option value=\"0\" selected=\"selected\">系统功能</option> <option value=\"1\">输入</option> <option value=\"2\">输出</option>\n"); }else if(pSysVal->CfgPara.IOMode==1){strcpy(idvalue,"<option value=\"0\" >系统功能</option> <option value=\"1\" selected=\"selected\">输入</option> <option value=\"2\">输出</option>\n"); }else{strcpy(idvalue,"<option value=\"0\" >系统功能</option> <option value=\"1\" >输入</option> <option value=\"2\" selected=\"selected\">输出</option>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; break;case Web_CmdMode_Id:if(pSysVal->CfgPara.CmdMode==0){strcpy(idvalue,"<option value=\"0\" selected=\"selected\">AT+指令集模式</option> <option value=\"1\">兼容协议模式</option>\n"); }else {strcpy(idvalue,"<option value=\"0\" >AT+指令集模式</option> <option value=\"1\" selected=\"selected\">兼容协议模式</option>\n"); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; break;
#endifcase Web_BssidEable_Id:/*tls_param_get(TLS_PARAM_ID_BSSID, (void *)&bssid, TRUE);tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);if(mode==0)//sta{if(bssid.bssid_enable==0){strcpy(idvalue,able_type[0]); }else {strcpy(idvalue,able_type[1]); }}else{strcpy(idvalue,able_type[2]); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break;case Web_PassWord_Id:/*{u8 password[6];tls_param_get(TLS_PARAM_ID_PASSWORD, password, FALSE);sprintf(idvalue, "%c%c%c%c%c%c", \password[0],\password[1],\password[2],\password[3],\password[4],\password[5]); *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset; }*/break;case Web_TCP_TimeOut_id:/*tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, FALSE);tls_param_get(TLS_PARAM_ID_DEFSOCKET, &remote_socket_cfg, FALSE);if(remote_socket_cfg.client_or_server && remote_socket_cfg.protocol == 0&&auto_mode) /// TCP Sever{strcpy(idvalue, (char *)remote_socket_cfg.host); }else {sprintf(idvalue, "0\" disabled=\"disabled\"");*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset+1; break;}*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;*/break; case Web_SysInfo_Macaddr:/*{u8 *mac = wpa_supplicant_get_mac();sprintf(idvalue, "%02x-%02x-%02x-%02x-%02x-%02x", \mac[0], \mac[1], \mac[2], \mac[3], \mac[4], \mac[5]); *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset; }*/break; case Web_SysInfo_HardVer:/*{struct tls_cmd_ver_t ver;tls_cmd_get_ver(&ver);sprintf(idvalue, "%c.%x.%02x.%02x.%02x%02x", \ver.hw_ver[0],ver.hw_ver[1],ver.hw_ver[2],ver.hw_ver[3],ver.hw_ver[4],ver.hw_ver[5]);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}*/break; case Web_SysInfo_FirmVer:/*{struct tls_cmd_ver_t ver;tls_cmd_get_ver(&ver);sprintf(idvalue, "%c.%x.%02x.%02x", \ver.fw_ver[0], ver.fw_ver[1], ver.fw_ver[2], ver.fw_ver[3]);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset; }*/break; case Web_SysInfo_RelTime:/*sprintf(idvalue, "%s %s", \SysCreatedTime, SysCreatedDate);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;*/break; case Web_SiteInfo_Copyright:/*//if (!(pSysVal->CfgPara.DebugMode & DBGMODE_COPYRIGHT)){strcpy(idvalue, PRODUCT_MANUFACTOR);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset; }*/break; case Web_Try_times_id:/*{u8 auto_retry_cnt;tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_AUTO_RETRY_CNT, (void* )&auto_retry_cnt, FALSE);if(mode!=2){sprintf(idvalue, "%d", auto_retry_cnt); *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;}else{strcpy(idvalue,"255\" size=\"3\" maxlength=\"3\" disabled=\"disabled\" />\n"); *after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }}*/break;case Web_roam_id:/*{u8 roam;tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);tls_param_get(TLS_PARAM_ID_ROAMING, (void* )&roam, FALSE);if(mode==0){if(roam){strcpy(idvalue,able_type[1]); }else //disable{strcpy(idvalue,able_type[0]); }}else{strcpy(idvalue,able_type[2]); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }*/break;case Web_powersave_id:/*{u8 autoPowerSave;tls_param_get(TLS_PARAM_ID_PSM, (void *)&autoPowerSave, FALSE);tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);if(mode==0){if(autoPowerSave){strcpy(idvalue,able_type[1]); }else //disable{strcpy(idvalue,able_type[0]); }}else{strcpy(idvalue,able_type[2]); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01; }*/break;case Web_SsidBroadcast_Id: /* ap mode *//*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);if(mode==2){u8 ssid_set;tls_param_get(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, FALSE);if(ssid_set){strcpy(idvalue,able_type[1]); }else //disable{strcpy(idvalue,able_type[0]); }}else{strcpy(idvalue,able_type[2]); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break;case Web_Autocreateadhoc_Id:/*tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);if(mode==1) {u8 auto_create_adhoc;tls_param_get(TLS_PARAM_ID_ADHOC_AUTOCREATE, (void *)&auto_create_adhoc, FALSE);if(auto_create_adhoc){strcpy(idvalue,able_type[1]); }else //disable{strcpy(idvalue,able_type[0]); }}else{strcpy(idvalue,able_type[2]); }*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break;case Web_scan_id:
#if 0{char *tempbuf=NULL;char *tempbuf2=NULL;int i, j, k, n;u8 nettab[32];u8 channel;tls_param_get(TLS_PARAM_ID_CHANNEL, (void *)&channel, FALSE);tempbuf = OSMMalloc(1536);if (tempbuf == NULL){break;}tempbuf2 = OSMMalloc(128);if (tempbuf2 == NULL){ OSMFree(tempbuf);break;}memset(tempbuf,0,1536);memset(tempbuf2,0,128);memset(nettab,0,sizeof(nettab));/* total number */for(i=0;i<32;i++){if (channel <= 0){break;}nettab[i] = i;};n = i;for(i=0;i<n-1;i++){for(j=0;j<n-i-1;j++){if (pSysVal->Wifi.Aplist[nettab[j]].rSignalAgility < pSysVal->Wifi.Aplist[nettab[j+1]].rSignalAgility){k = nettab[j];nettab[j] = nettab[j+1];nettab[j+1] = k;} }}/* Limit the max display number */if (n > 16){n=16;}sprintf(tempbuf, "<option value=\"%s\" selected=\"selected\">%s </option> ", \pSysVal->Wifi.Aplist[nettab[0]].SSID,pSysVal->Wifi.Aplist[nettab[0]].SSID);for(i=1;i<n;i++){sprintf(tempbuf2, "<option value=\"%s\">%s </option> ", \pSysVal->Wifi.Aplist[nettab[i]].SSID,pSysVal->Wifi.Aplist[nettab[i]].SSID);strcat(tempbuf,tempbuf2);}strcpy(idvalue,tempbuf);OSMFree(tempbuf);OSMFree(tempbuf2);}*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;
#endifbreak;case Web_WebEncry_id:/*
#if 0strcpy(idvalue,Encry_Open[6]);
#endifstrcpy(idvalue,Encry_Open[2]);*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;* Id_type=0x01;*/break; case Web_Id_my_param1:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM1, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; case Web_Id_my_param2:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM2, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; case Web_Id_my_param3:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM3, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; case Web_Id_my_param4:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM4, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; case Web_Id_my_param5:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM5, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; case Web_Id_my_param6:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM6, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; case Web_Id_my_param7:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM7, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; case Web_Id_my_param8:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM8, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; case Web_Id_my_param9:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM9, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; case Web_Id_my_param10:{ char my_param[32];tls_param_get(TLS_PARAM_ID_MY_PARAM10, (void *)my_param, FALSE);memcpy(idvalue, my_param, sizeof(my_param));*after_id_len=idtble->Idlen;*Value_Offset=idtble->Value_Offset;printf("\nget idvalue = %s, *after_id_len = %d, *Value_Offset = %d\n", idvalue, *after_id_len, *Value_Offset);}break; default:break;}return(strlen(idvalue));
}
页面执行顺序的选择
我们没有hedbasic.html,这里需要改成实际的basic.html和index.html, 具体执行顺序,在使用Res的地方打印调试信息就能看到。
因为访问W800片上http服务器时,只指定了IP . e.g. http://192.168.8.1 这样第一个页面是谁? index.html中还包括哪些html, 在这里指定。
char *Res[] = {// 必须是index.html排在第一位"/index.html", "/basic.html",// 以下是官方的html, 用不到。上面写自己的html
// "/hedbasic.html",
// "/hedadvance.html",
// "/hedfirmware.html",
// "/hedindex.html",
//#if WEB_SERVER_RUSSIAN
// "/hed_basic_en.html",
// "/hed_basic_ru.html",
// "/hed_firmware_en.html",
// "/hed_firmware_ru.html",
//#endif
};
static int HtmlConvertURLStr(char *drc, char *src, int len)
加入自己的页面处理函数定义
//#define CGI_CONFIG MK_CGI_ENTRY( \
// "/hedbasic.html", \ // W800官方没提供hedbasic.html
// do_cgi_config \
// )#define CGI_CONFIG_MY MK_CGI_ENTRY( \"/basic.html", \do_cgi_config \)/*
static void set_default_socket(struct tls_param_socket *remote_socket_cfg)
明确http请求发到http服务器的查询包
可以加串口调试语句看。
extern u8 gucssidData[33];
extern u8 gucpwdData[65];
u8 gwebcfgmode = 0;
char * do_cgi_config(int iIndex, int iNumParams, char *pcParam[], char *pcValue[],u8 * NeedRestart)
{/*int i;int Value;
/// int EnableAutoMode = 0;u32 Ip;int KeyType = 0;int KeyLen = 0;u8 encrypt;struct tls_param_ip ip_param;struct tls_param_key param_key;struct tls_param_original_key* orig_key;struct tls_param_sha1* sha1_key;u8 auto_mode;u8 mode;struct tls_param_socket remote_socket_cfg;*/int i;int KeyLen = 0;struct tls_param_ssid ssid;struct tls_param_key param_key;struct tls_param_original_key* orig_key;struct tls_param_sha1* sha1_key;char my_param[32];printf("\n>> do_cgi_config(%d, %d)\n", iIndex, iNumParams);for (i = 0; i < iNumParams; i++){if (pcParam[i] == NULL || pcValue[i] == NULL){continue;}printf("\npcParam[%d] = %s, pcValue[%d] = %s\n", i, pcParam[i], i, pcValue[i]);}if (iNumParams == 0)
向FLASH中保存新回包字段参数的活内容
用户从界面上改了变量值,点击保存,确定后submit,就到这里。
sha1_key = (struct tls_param_sha1*)¶m_key;memset((u8* )sha1_key, 0, sizeof(struct tls_param_sha1));tls_param_set(TLS_PARAM_ID_SHA1, (void *)sha1_key, FALSE); } else if (strcmp(pcParam[i], "my_param1") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM1, (void *)my_param, FALSE);} else if (strcmp(pcParam[i], "my_param2") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM2, (void *)my_param, FALSE);} else if (strcmp(pcParam[i], "my_param3") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM3, (void *)my_param, FALSE);} else if (strcmp(pcParam[i], "my_param4") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM4, (void *)my_param, FALSE);} else if (strcmp(pcParam[i], "my_param5") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM5, (void *)my_param, FALSE);} else if (strcmp(pcParam[i], "my_param6") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM6, (void *)my_param, FALSE);} else if (strcmp(pcParam[i], "my_param7") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM7, (void *)my_param, FALSE);} else if (strcmp(pcParam[i], "my_param8") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM8, (void *)my_param, FALSE);} else if (strcmp(pcParam[i], "my_param9") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM9, (void *)my_param, FALSE);} else if (strcmp(pcParam[i], "my_param10") == 0){memset(&my_param, 0, sizeof(my_param));HtmlConvertURLStr((char *)my_param, pcValue[i], strlen(pcValue[i]));tls_param_set(TLS_PARAM_ID_MY_PARAM10, (void *)my_param, FALSE);}}//set sta mode and reset the system.tls_param_to_flash(TLS_PARAM_ID_ALL);
#if TLS_CONFIG_WEB_SERVER_MODEgwebcfgmode = 1;
#endif/*httpd_deinit();tls_wifi_oneshot_connect(ssid.ssid, param_key.psk);*/return Res[iIndex];
}//#define CGI_ADVANCE MK_CGI_ENTRY( \
// "/hedadvance.html", \
// do_cgi_advance \
// )//char * do_cgi_advance(int iIndex, int iNumParams, char *pcParam[], char *pcValue[], u8 * NeedRestart)
//{
注释掉不需要html的回包实现
//#define CGI_ADVANCE MK_CGI_ENTRY( \
// "/hedadvance.html", \
// do_cgi_advance \
// )//char * do_cgi_advance(int iIndex, int iNumParams, char *pcParam[], char *pcValue[], u8 * NeedRestart)
//{
// /*
// int i;
// int Value;
// u32 HexValue;
增加存变量的处理
存变量是do_cgi_webindex()实现的。
#define CGI_WEBINDEX MK_CGI_ENTRY( \"/index.html", \do_cgi_webindex \)char * do_cgi_webindex(int iIndex, int iNumParams, char *pcParam[], char *pcValue[], u8 * NeedRestart)
{int i;int Value;//int KeyLen = 0; u8 encrypt;//struct tls_param_key param_key;printf("\n\n");printf("\n>> do_cgi_webindex(%d, %d)\n", iIndex, iNumParams);for (i = 0; i < iNumParams; i++){if (pcParam[i] == NULL || pcValue[i] == NULL){continue;}printf("\npcParam[%d] = %s, pcValue[%d] = %s\n", i, pcParam[i], i, pcValue[i]);}for (i = 0; i < iNumParams - 1; i++) //not care about "Save"{if (pcParam[i] == NULL || pcValue[i] == NULL || *pcValue[i] == '\0'){continue;}printf("\npcParam[i] = %s, pcValue[%d] = %s\n", i, pcParam[i], i, pcValue[i]);if (strcmp(pcParam[i], "SsidSL") == 0){struct tls_param_ssid ssid;memset(&ssid, 0, sizeof(struct tls_param_ssid));HtmlConvertURLStr((char *)ssid.ssid, pcValue[i], strlen(pcValue[i]));ssid.ssid_len = strlen(pcValue[i]);tls_param_set(TLS_PARAM_ID_SSID, (void *)&ssid, FALSE);} else if (strcmp(pcParam[i], "Encryweb") == 0){tls_param_get(TLS_PARAM_ID_ENCRY, (void *)&encrypt, FALSE);strtodec(&Value, pcValue[i]);if(Value==0) ///open{encrypt=ENCRYPT_TYPE_OPEN_SYS;//pSysVal->CfgPara.AuthMode=0;}else if(Value==1)///{encrypt=ENCRYPT_TYPE_WEP_64_BITS;//pSysVal->CfgPara.AuthMode=0; }else if(Value==2)///{encrypt=ENCRYPT_TYPE_WEP_128_BITS;//pSysVal->CfgPara.AuthMode=0; }
#if 0else if(Value==3)///{encrypt=ENCRYPT_TYPE_TKIP;pSysVal->CfgPara.AuthMode=AUTHMODE_WPA; } else if(Value==4)///{encrypt=ENCRYPT_TYPE_CCMP;pSysVal->CfgPara.AuthMode=AUTHMODE_WPA; } else if(Value==5)///{encrypt=ENCRYPT_TYPE_TKIP;pSysVal->CfgPara.AuthMode=AUTHMODE_WPA2; } else if(Value==6)///{encrypt=ENCRYPT_TYPE_CCMP;pSysVal->CfgPara.AuthMode=AUTHMODE_WPA2; }
#endifelse{}tls_param_set(TLS_PARAM_ID_ENCRY, (void *)&encrypt, FALSE);}else if(strcmp(pcParam[i], "ApEnableweb") == 0){//strtodec(&Value, pcValue[i]);u8 mode= 0; // 1tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE);} } tls_param_to_flash(TLS_PARAM_ID_ALL);* NeedRestart=1; return Res[iIndex];}
字段变量的读写用到了tls_param_set(), tls_param_get(), 看看调用点,就能知道哪个参数保存和读取的具体流程,因为程序已经正常跑了,就没太关注。
在http初始化时,要注册的句柄数组
这个句柄数组制定了哪个html由哪个函数处理
//#if WEB_SERVER_RUSSIAN
//
#define CGI_CONFIG_EN MK_CGI_ENTRY( \
"/hed_basic_en.html", \
do_cgi_config \
)
//
#define CGI_CONFIG_RU MK_CGI_ENTRY( \
"/hed_basic_ru.html", \
do_cgi_config \
)
//
#define CGI_FIRMWARE_EN MK_CGI_ENTRY( \
"/hed_firmware_en.html", \
do_cgi_firmware \
)
//
/*#define CGI_FIRMWARE_RU MK_CGI_ENTRY( \
"/hed_firmware_ru.html", \
do_cgi_firmware \
) */
//
//#endif tCGI Cgi[8]=
{CGI_WEBINDEX, CGI_CONFIG_MY,// CGI_CONFIG,// CGI_ADVANCE,// CGI_CONTROL,
//#if WEB_SERVER_RUSSIAN
// CGI_CONFIG_EN,
// CGI_CONFIG_RU,
// CGI_FIRMWARE_EN,
// CGI_FIRMWARE_RU,
//#endif
};
修改后工程的运行效果图
总结
等我下次,在其他计算机上,只要有官方W800SDK,装好了平头哥社区的CDK, 就能按照这个笔记,做一个新的能运行有交互的网页来。
这篇关于W800开发板和网页的交互(存取网页上的字段)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!