/* Demo7 for DHCP. show the IP on 5 digit LED with XS_09300.LIB */ #include #include //#include"..\lib\7188e.h" #include"..\lib\8000a.h" #include"..\lib\tcpip32.h" #include"..\lib\MFW.H" void ShowIp(void); void XS_UserInit(int argc,char *argv[]) { void UserLoop(void); char version[20]; extern struct NETDATA netdata[]; //for use of DHCP InitLib(); bUseDhcp=1; /* use dhcp function, and the ip got is stored in netconf[nets[0].confix].Iaddr.c[0] ~netconf[nets[0].confix].Iaddr.c[3] which is defined in tcpip.h*/ XS_GetVersion(version); Print("[X-Server library]: version=%s ",version); XS_GetLibDate(version); Print("date=%s\r\n",version); GetTcpipLibDate(version); Print("Tcpip library version:%X, Library Date is %s\r\n",GetTcpipLibVer(),version); /* for xs_09001.lib ~ xs_09003.lib NEED NOT the next 4 lines. */ XS_AddSystemLoopFun(UserLoop); // for using DHCP, Set the IP address/MASK to 0 before call Ninit(). *(long *)netdata[0].Iaddr.c= *(long *)netdata[0].Imask.c= *(long *)netdata[1].Iaddr.c= *(long *)netdata[1].Imask.c=0L; // DhcpLeaseTime=xxxx; // by default DhcpLeaseTime=0, // DhcpLeaseTime=20; // that is the time is assigned by the DHCP server. // the time unit is second. Install_DHCP(); // must call Install_DHCP() for DHCP function to work. XS_AddSystemLoopFun(XS_SocketLoopFun); XS_StartSocket(); } /************************************************************************/ void XS_UserEnd(void) { } /************************************************************************/ void UserLoop(void) { int data; if(Kbhit()){ data=Getch(); if(data=='q' || data=='Q'){ QuitMain=1; } } ShowIp(); } /************************************************************************/ /* XS 0.9.200 or later must add the function main() */ void main(int argc,char *argv[]) { XS_main(argc,argv); /* call the XS library main function. */ } /************************************************************************/ int once=0; static int idx=0; void ShowIp(void) { int data; data=netconf[nets[0].confix].Iaddr.c[idx]; if(once ==0){ Print("IP = %d.",data); once++; } else if(once<3){ Print("%d.",data); once++; } else if(once==3){ Print("%d\r\n",data); once++; } idx++; Show5DigitLedWithDot(1,idx); Show5DigitLed(5,data%10); data/=10; if(data){ Show5DigitLed(4,data%10); data/=10; if(data) Show5DigitLed(3,data); else Show5DigitLed(3,16); } else { Show5DigitLed(4,16); Show5DigitLed(3,16); } Show5DigitLed(2,16); if(idx>=4) idx=0; Delay(500); }