📄 egi_time.c
字号:
/*
*
* Egi_stat.c
*
* Part of the Myson Century CS620X demo program.
*
* Authors: LY Lin, WM Wang, IJ Chen, WH Lee
*
* Egi_stat.c contains HTTP status.cgi callback routine.
*
* This program was developed using the Keil 8051 C uVision 2 system.
* The Keil compiler MUST be used if working with Myson Century supplied
* firmware.
*
*
*
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "ether.h"
#include "netutil.h"
#include "ip.h"
#include "tcp.h"
#include "config.h"
#include "http.h"
#include "time.h"
#include "rtc_api.h"
//extern xdata unsigned char PORTB_EN;
//extern xdata unsigned char PORTB;
int x=0,y=0;
//sfr P1=0x90;
/************************************************************************
/* Function Name : status_resp *
/* *
/* Arguments : *
/* TSOCK xdata *ts: Point to TSOCK. *
/* char xdata *str: Point to egi comment tag string(<!--#) *
/* or NULL if this function is first time be *
/* called. *
/* *
/* Return : *
/* None *
/* Comment : *
/* This function is a callback function for status.cgi. First, *
/* this function be called on the start of status.cgi with *
/* str=NULL. Then when webpage meet egi comment tag(<!--#) , *
/* this function will be called , the 'str' is point to egi *
/* comment tag. *
/* *
/************************************************************************/
void time_resp(TSOCK xdata *ts, char xdata *str)
{
APPDATA *adp;
RAM_WEB_PAGE *ptr_web_page;
unsigned int hour_val,min_val;
unsigned char *temp;
unsigned int year_val,mon_val,date_val;
unsigned int day_val=0;
int webdebug=0;
unsigned char *s,*p,*q;
char *dest;
char dest2[16];
adp = (APPDATA *)ts->app;
if (!str) /*The egi function is called the first time.*/
{/*Init app for time.cgi. */
adp->egi = time_resp;
ptr_web_page = search_get_web_page ("time.cgi");
adp->in = ptr_web_page->RAM_WEB_PAGE_DATA;
adp->file_length = ptr_web_page->RAM_WEB_PAGE_LEN;
s=find_connvar(ts,"L1");
while(*s)
{
s=find_connvar(ts,"U1");
p=find_connvar(ts,"U2");
if(!*s)
break;
s=s+3;
if((isdigit(*s)||isdigit(*(p+3)))==0)
{
x=0;
break;
}
if(isdigit(*s)==0)
{
x=1;
break;
}
hour_val=strtoul(s,&temp,10);
p=p+3;
if(isdigit(*p)==0)
{
x=1;
break;
}
min_val=strtoul(p,&temp,10);
if(!((min_val<60)&&(hour_val<24)))
{
x=2;
break;
}
rtc_time_write(0x06,hour_val);
rtc_time_write(0x05,min_val);
break;
}
s=find_connvar(ts,"L1");
while(*s)
{
s=find_connvar(ts,"V1");
p=find_connvar(ts,"V2");
q=find_connvar(ts,"V3");
if(!*s)
break;
s=s+3;
if((isdigit(*s)||isdigit(*(p+3))||isdigit(*(q+3)))==0)
{
y=0;
break;
}
if(isdigit(*s)==0)
{
y=1;
break;
}
year_val=strtoul(s,&temp,10);
p=p+3;
if(isdigit(*p)==0)
{
y=1;
break;
}
mon_val=strtoul(p,&temp,10);
q=q+3;
if(isdigit(*q)==0)
{
y=1;
break;
}
date_val=strtoul(q,&temp,10);
if(!((mon_val<=12)&&(date_val<=31)&&(year_val>2000)))
{
y=2;
break;
}
day_val=get_days(year_val,mon_val,date_val);
rtc_date_write(0x07,day_val);
break;
}
}
else/*Egi comment tag.*/
{
str += EGI_STARTLEN;/*Skip "<!--#" .*/
while(!strncmp(str, "$label0", 7) )//&& isdigit(*(str+7)))
{
if(y==1)
{
buff_instr(&ts->txb,"please input date entirely");
y=0;
break;
}
if(y==2)
{
buff_instr(&ts->txb,"please input date correctly");
y=0;
break;
}
dest=print_current_date();
sprintf(dest2,"%s\n",dest);
buff_instr(&ts->txb, dest2);
break;
}
while(!strncmp(str, "$label1", 7))// && isdigit(*(str+7)))
{
if(x==1)
{
buff_instr(&ts->txb,"please input time entirely");
x=0;
break;
}
if(x==2)
{
buff_instr(&ts->txb,"please input time correctly");
x=0;
break;
}
//i = *(str+7) - '0';
dest=print_current_time();
sprintf(dest2,"%s\n",dest);
buff_instr(&ts->txb, dest2);
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -