📄 iocbk.c
字号:
/****************************************************************************** Name: ioCbk.c** Description: GPIO Call Back Function** Copyright: (c) 2001-2002 Taifatech Inc.* All rights reserved.*****************************************************************************/#include <math.h>#include <ctype.h>#include <stdlib.h>#include <string.h>#include <stdio.h>#include "tfTypes.h"#include "fs.h"#include "httpd.h"#include "html.h"//#include "ioControl.h"//#include "ioRead.h"#include "system.h"#include "errormsg.h"#include "smtp.h"#include "alert.h"#include "password.h"#include "firmwareUpdate.h"#include "reg51.h"#include "tf320drv.h"#include "io.h"#include "uip.h"#ifdef EEPROM_ENABLE#include "eeprom.h"#include "i2c.h"#endif#define ERRORMSG_LOGIN 0#define ERRORMSG_HISTORY_BACK 1#define ERRORMSG_SETUP 2#define ERRORMSG_NOTE 3unsigned char errmsgflag = ERRORMSG_LOGIN ;extern u8_t EE_FLAG;extern struct httpd_state *hs;extern variable_t var_list[];extern u8_t code DefaultMyMACAddr[6];extern u8_t code DefaultMyIPAddr[4];extern u8_t xdata MY_MAC[6];extern u8_t xdata MY_IP[4];extern IPADDR_T xdata MY_IP;extern IPADDR_T xdata MY_NETMASK;extern IPADDR_T xdata MY_GATEWAY;#if SMTP_MODE == SMTP_TEXTextern u8_t xdata MyEmailBodyText[MaxEmailBodyTextLen] ;#endifstatic char ipbuf[8];static char macbuf[8];//struct PIN_STRUCT xdata pin[8];extern u32_t sys_tick_get();extern void set_my_uip();extern void dns_init() ;extern void arp_init() ;/* * non-reentrant * Convert an IP address string of dotted format to a long integer. * Original format: xxx.xxx.xxx.xxx */u32_t ip_str2long(const char *ipstr){ IPADDR_T ipa;#ifdef _MSC_VER u16_t ip1, ip2, ip3, ip4; if (sscanf(ipstr, "%hu.%hu.%hu.%hu", &ip1, &ip2, &ip3, &ip4) == 4) { ipa[0] = (u8_t)ip1; ipa[1] = (u8_t)ip2; ipa[2] = (u8_t)ip3; ipa[3] = (u8_t)ip4; return ntohl(*(u32_t *)&ipa); }#else if (sscanf(ipstr, "%bu.%bu.%bu.%bu", &ipa[0], &ipa[1], &ipa[2], &ipa[3]) ==4) return ntohl(*(u32_t *)&ipa);#endif return 0;} u8_t ssi_errormsg(u8_t varid, value_t *vp){ switch (varid) { case TGI_TITLE : if( errmsgflag == ERRORMSG_LOGIN ) vp->value.string = "Error"; if( errmsgflag == ERRORMSG_HISTORY_BACK ) vp->value.string = "Error"; if( errmsgflag == ERRORMSG_SETUP ) vp->value.string = "Error"; if( errmsgflag == ERRORMSG_NOTE ) vp->value.string = "Note"; break ; case TGI_ERROR_MESSAGE : vp->value.string = hs->errormsg; vp->type = string; break; case TGI_PATH : if( errmsgflag == ERRORMSG_LOGIN ) vp->value.string = "window.location='/'"; if( errmsgflag == ERRORMSG_HISTORY_BACK ) vp->value.string = "history.back()"; if( errmsgflag == ERRORMSG_SETUP ) vp->value.string = "window.location='/system.htm'"; if( errmsgflag == ERRORMSG_NOTE ) vp->value.string = "window.location='/pwd.htm'"; vp->type = string; break ; } return OK;}u8_t ssiSystem(u8_t varid, value_t *vp){ switch (varid) { case TGI_FW_VERSION: vp->value.string = "Version 2.0 "; vp->type = string; break; case TGI_IPADDRC: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_IP[0], MY_IP[1], MY_IP[2], MY_IP[3]); sprintf(ipbuf, "%bu", config_g.ipaddr[0]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_IPADDRC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_IPADDRC2: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_IP[0], MY_IP[1], MY_IP[2], MY_IP[3]); sprintf(ipbuf, "%bu", config_g.ipaddr[1]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_IPADDRC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_IPADDRC3: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_IP[0], MY_IP[1], MY_IP[2], MY_IP[3]); sprintf(ipbuf, "%bu", config_g.ipaddr[2]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_IPADDRC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_IPADDRC4: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_IP[0], MY_IP[1], MY_IP[2], MY_IP[3]); sprintf(ipbuf, "%bu", config_g.ipaddr[3]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_IPADDRC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_NETMASKC: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_NETMASK[0], MY_NETMASK[1], MY_NETMASK[2], MY_NETMASK[3]); sprintf(ipbuf, "%bu", config_g.netmask[0]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_NETMASKC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_NETMASKC2: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_NETMASK[0], MY_NETMASK[1], MY_NETMASK[2], MY_NETMASK[3]); sprintf(ipbuf, "%bu", config_g.netmask[1]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_NETMASKC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_NETMASKC3: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_NETMASK[0], MY_NETMASK[1], MY_NETMASK[2], MY_NETMASK[3]); sprintf(ipbuf, "%bu", config_g.netmask[2]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_NETMASKC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_NETMASKC4: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_NETMASK[0], MY_NETMASK[1], MY_NETMASK[2], MY_NETMASK[3]); sprintf(ipbuf, "%bu", config_g.netmask[3]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_NETMASKC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_GATEWAYC: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_GATEWAY[0], MY_GATEWAY[1], MY_GATEWAY[2], MY_GATEWAY[3]); sprintf(ipbuf, "%bu", config_g.gateway[0]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_GATEWAYC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_GATEWAYC2: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_GATEWAY[0], MY_GATEWAY[1], MY_GATEWAY[2], MY_GATEWAY[3]); sprintf(ipbuf, "%bu", config_g.gateway[1]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_GATEWAYC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_GATEWAYC3: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_GATEWAY[0], MY_GATEWAY[1], MY_GATEWAY[2], MY_GATEWAY[3]); sprintf(ipbuf, "%bu", config_g.gateway[2]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_GATEWAYC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_GATEWAYC4: //sprintf(ipbuf, "%bu.%bu.%bu.%bu", MY_GATEWAY[0], MY_GATEWAY[1], MY_GATEWAY[2], MY_GATEWAY[3]); sprintf(ipbuf, "%bu", config_g.gateway[3]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_GATEWAYC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_MAC0: sprintf(ipbuf, "%bx", config_g.hardmac[0]); vp->value.string =ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_MAC]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_MAC1: sprintf(ipbuf, "%bx", config_g.hardmac[1]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_MAC1]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_MAC2: sprintf(ipbuf, "%bx", config_g.hardmac[2]); vp->value.string =ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_MAC2]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)",ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_MAC3: sprintf(ipbuf, "%bx", config_g.hardmac[3]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_MAC3]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_MAC4: sprintf(ipbuf, "%bx", config_g.hardmac[4]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_MAC4]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)", ipbuf)); DEBUGF(DEBUG_SYS, ("\r\n =>vp->value.string: (%s)", vp->value.string)); break; case TGI_MAC5: sprintf(ipbuf, "%bx", config_g.hardmac[5]); vp->value.string = ipbuf; vp->type = string; DEBUGF(DEBUG_SYS, ("\r\n [TGI_MAC5]")); DEBUGF(DEBUG_SYS, ("\r\n =>ipbuf : (%s)",ipbuf)); DEBUGF(DEBUG_SYS, (" =>vp->value.string: (%s)", vp->value.string)); break; /*case TGI_DHCPC_DIS: if (config_g.dhcp_en) vp->value.string = ""; else vp->value.string = "CHECKED"; vp->type = string; break; case TGI_DHCPC_EN: if (config_g.dhcp_en) vp->value.string = "CHECKED"; else vp->value.string = ""; vp->type = string; break; */ default: vp->value.string = ""; vp->type = string; break; } return OK;}u8_t tgiSystem(u8_t varid, variable_t *vp){ s32_t i4; u16_t u16EEData; u8_t u8EEData1, u8EEData2, i; bool_t en; u16_t hex; u8_t u8buf[8]; u8_t ConfigChangeFlag = 0 ; DEBUGF(DEBUG_SYS, ("\r\n\r\n @ tgiSystem()")); if (varid == 0) ; if ((!strcmp(vp[19].value, "Submit"))||(!strcmp(vp[18].value, "Submit"))){ DEBUGF(DEBUG_SYS, ("\r\n Submit Button!!!")); /* IP config vp[0] ~ vp[3] */ /* IP[0] config */ i4 = (atol(vp[0].value)); if( (config_g.ipaddr[0] != (u8_t)i4) && (i4>0) && (i4<255) ) { //tempconfig_g.ipaddr[0] = (u8_t)i4; config_g.ipaddr[0] = (u8_t)i4; ConfigChangeFlag = 1 ; } if( i4 <= 0 || i4 >= 255 ) { errmsgflag = ERRORMSG_SETUP ; hs->errormsg = "Invalid IP"; httpd_send_file(fs_open("errormsg.htm")); return OK; } /* IP[1] config */ i4 = (atol(vp[1].value)); if( (config_g.ipaddr[1] != (u8_t)i4) && (i4>=0) && (i4<=255) ) { //tempconfig_g.ipaddr[1] = (u8_t)i4 ; config_g.ipaddr[1] = (u8_t)i4; ConfigChangeFlag = 1 ; } if( i4 < 0 || i4 > 255 ) { errmsgflag = ERRORMSG_SETUP ; hs->errormsg = "Invalid IP"; httpd_send_file(fs_open("errormsg.htm")); return OK; } /* IP[2] config */ i4 = (atol(vp[2].value)); if( (config_g.ipaddr[2] != (u8_t)i4) && (i4>=0) && (i4<=255) ) { //tempconfig_g.ipaddr[2] = (u8_t)i4; config_g.ipaddr[2] = (u8_t)i4; ConfigChangeFlag = 1 ; } if( i4 < 0|| i4 > 255 ) { errmsgflag = ERRORMSG_SETUP ; hs->errormsg = "Invalid IP"; httpd_send_file(fs_open("errormsg.htm")); return OK; } /* IP[3] config */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -