Home
PDF document - eetasia.com
Contents
1. 16 Demonstration 00 00 cece eee 22 Requirements x22 ose ba desis EX GG hs Leena eee ly eee ees Ede 22 zr stare Soha aca ates Seah ee a eee ery ne eee ees 22 DGWINOS 254 240 055 005 so hud R bad RE Ims den kd ei 3 sehen arde ee 23 Procedure 2 2 eee ne 23 SUMMA atid ee ee odie SE eae ee Geek ee eee Ree ee eee been ces 24 Appendix A Reference sees nnn 26 Appendix B Flowcharls x se sse nee ERR EROR RERO XE E xS 27 Appendix C Source Code e eee ee 29 G File 3 se 3 bee eee ee eres pee PME PER EERE ES arca RES E eee 29 Header File 2 0 ccc eee eee ees 32 Q1 MI P eee topea Coe ceased eeke seme E E E 33 Java Source Code File 0 cece eee 34 AN017801 0304 Table of Contents List of Figures Figure 1 Figure 2 Figure 3 Figure 4 Figure 5 Figure 6 List of Tables Table 1 AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java FIL General Setup with the eZ80F91 MCU as a Webserver 2 Communication between Client Browser and the eZ80F91 Webserver 00 cee eee 4 LED and Switch Control Demo Webpage 5 Java Applet Component on HTML Webpage 5 Flowchart to Toggle the LEDs on Development Board USING BUMONS ue xa Saw Ex o oa Bo eR bere u 27 Flowchart to Change the Color of LED Icons on Webpage using Switches z scc hd euin R4 4 RERES RING es ganas teens 28 List of
2. Switch htm SwitchCtrl class switch h logo gif Adding and Integrating Application Specific Files to ZTP 17 AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java VMP rik ga Open the website c file from within ZDSII and enter the following into it include lt Switch h gt HTML extern struct staticpage switch htm CGI int switchinput cgi struct http request request Java applets extern struct staticpage SwitchCtrl class for the image extern const struct staticpage logo gif for LED status static unsigned char ledDCDstatus 1 static unsigned char ledRXstatus 1 The website c file contains the array webpage website with information on the HTML pages Replace the last line of the array 0 NULL NULL NULL With the following lines HTTP PAGE STATIC switch htm text html amp switch htm staticpage switchinput cgi HTTP PAGE DYNAMIC switch cgi text html struct HTTP PAGE STATIC logo gif image gif amp logo gif HTTP PAGE STATIC SwitchCtrl class application octect Stream amp SwitchCtrl class 0 NULL NULL NULL Add the following definition for the switchinput cgi function at the end of the website c file Adding and Integrating Application Specific Files to ZTP Application Note A Webpage Interface for the eZ8
3. Application Note A Webpage Interface for the eZ80F91 MCU using Java AN017801 0304 ZiLOG Worldwide Headquarters 532 Race Street San Jose CA 95126 Telephone 408 558 8500 Fax 408 558 8300 www ZiLOG com Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL This publication is subject to replacement by a later edition To determine whether a later edition exists or to request copies of publications contact ZiLOG Worldwide Headquarters 532 Race Street San Jose CA 95126 Telephone 408 558 8500 Fax 408 558 8300 www zilog com ZiLOG is a registered trademark of ZiLOG Inc in the United States and in other countries All other products and or service names mentioned herein may be trademarks of the companies with which they are associated Information Integrity The information contained within this document has been verified according to the general principles of electrical and mechanical engineering Any applicable source code illustrated in the document was either written by an authorized ZILOG employee or licensed consultant Permission to use these codes in any form besides the intended application must be approved through a license agreement between both parties ZiLOG will not be responsible for any code s used beyond the intended application Contact the local ZiLOG Sales Office to obtain necessary license agreements Document Disclaimer 2004 by ZiLOG Inc All rights reserved
4. tant of which is the ability to respond to browser requests When a Java capable browser loads a page containing an applet the browser sends a request to the applet telling the applet to initialize itself and start executing Declaring the Variables After creating the Applet class the variables that can be used by any function or sub class are declared within the switchctr1 class as follows Socket rwSocket Socket inSocket Thread readThread String ipaddr null String ip null int portNumber int port Button xButton Button yButton DataOutputStream os DataInputStream is AN017801 0304 Creating the Webpage AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL Image imagel Color firstBulbColor Color green Color secondBulbColor Color green Initializing the Applet The applet is initialized using the public void init method The init method is called when the applet is first created and loaded by the underlying soft ware the web browser This method performs all the one time operations that the applet requires for its operation such as creating the user interface or setting the font or displaying the logo public void init The file formats gif and 3pg are used to load and display images on the browser screen Images are stored as an instance of the Image class The applet method get Image returns an instance of these files imagel getI
5. f OxffffFF00UL Default Subnet Mask l The Boot record variable contains the network parameters and settings in the four octet dotted decimal format that are specific to the local area network at ZiLOG as default Modify the above structure definition with appropriate IP addresses within your local area network Add the following lines of code at the end of the main c file before the line return OK to call the switch Input function at intervals of one second PortBInit Initialize pin PBO as Input Create a start task resume create procptr task1 1024 20 task1 0 0 while 1 Loop forever Switch_Input Check status of SW1 and SW2 sleep 1 Adding and Integrating Application Specific Files to ZTP Application Note A Webpage Interface for the eZ80F91 MCU using Java VMP EiL 20 Open the ez80 Hw Config c file and change the default MAC address provided by ZTP such that each eZ80 Development Board on the LAN contains a unique MAC address For example const BYTE f91 mac addr EP ALEN 0x00 0x90 0x23 0x00 OxDF 0x91 In the 6 byte MAC address shown above the first three bytes must not be modified the last three bytes can be used to assign a unique MAC address to the eZ80 Development Board 21 Openthe ipw ez80 c file For this application DHCP Dynamic Host Configuration Protocol is disabled therefore ensure the following b use dhcp FALSE 22
6. g fillOval 185 70 40 40 g setColor Color yellow g setFont new Font Arial 1 10 g drawString To switch ON OFF the LEDs on the board click the buttons 25 145 System out println Exit Graphics Creating the Webpage AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL The setFont method is used to set the font The drawString method prints the specified text on the browser The filloval method paints the LED icons labelled as LED1 and LED2 on the webpage on the screen according to the position X and Y axis and size width and height as specified The setColor method is used to specify the color for the LED icon Synchronizing Independent Threads To run the main thread and obtain the IP address of the client at Port 5000 user specified the following code is used The synchronized keyword tells the applet to synchronize all the threads synchronized public void run System out println Enter RUN ip getCodeBase getHost System out println IP Addr ip tostring port 5000 Reading and Parsing the Data from the Port When the applet runs the browser displays the indicators LED icons LED1 and LED2 and buttons D1 and D2 on the screen The Socket Class is used to set up Port 5000 for input The data on the port is then read and parsed to obtain the proper string value after eliminating and n c
7. Information in this publication concerning the devices applications or technology described is intended to suggest possible uses and may be superseded ZiLOG INC DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY OF THE INFORMATION DEVICES OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT ZiLOG ALSO DOES NOT ASSUME LIABILITY FOR INTELLECTUAL PROPERTY INFRINGEMENT RELATED IN ANY MANNER TO USE OF INFORMATION DEVICES OR TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE Except with the express written approval ZiLOG use of information devices or technology as critical components of life support systems is not authorized No licenses or other rights are conveyed implicitly or otherwise by this document under any intellectual property rights AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java LiLkug Table of Contents N mndzos I M CPI a a e a e iv List of Tables 0 0 0 0 ccc nh iv Abstract 3 4 diced aun adel aa eos G8 Mew WG PsN Ae ae a ke al 1 ZIP OVV OM s acu WERE ek RI PEDE IC HERI EIU TR ROAR EE CR ed Pec 1 ATIP Sever n ZIP grene TP TT 2 Java Applets and HTML usan Kid bd R ae 3 Developing the Java based Webpage Interface Application 3 Creating the Webpage 3x ddr dE ERE eee REED Ke eed 6 Controlling the LEDs on the Development Board 15 Controlling the LED Icons on the Webpage isses 16 Adding and Integrating Application Specific Files to ZTP
8. int port 5000 read switchSW1 PB DR read switchSW2 PB DR if read switchSW1 if switchonl switchonl 1 else switchonl 0 if read switchSW2 if switchon2 switchon2 1 else switchon2 0 return OK Switch Input Create amp start a new task amp SW1 Get status of SW1 amp SW2 Get status of SW2 If switch SW1 is pressed and earlier it was off Then put on flag Otherwise reset flag If switch SW2 is pressed and it was off Then put on flag Otherwise reset flag KR KKK KK Ck Kk oko k kok k oko k k k k k k k k k k k k k k k k k k k kCk ck kCk ck kck ck kck k kck k kck OK ck kk k KEKKKKKKKKKKKKKKKKKKKKKKKKE NG of file F N Xkkkkckckck KK KKK KK ck k KKK kc k KK KOKCKCKCKCKCKCKCk kCk ck kCKCk kCk Ck kCk Ck Ck kCKCk kCk Ck kCkCk KCk Ck Ck kCk Ck kk Ck kok kok kck ck K kk kck ck I ck kk AN017801 0304 C File Header File Application Note A Webpage Interface for the eZ80F91 MCU using Java This section contains the following header file e switch h Z EiL KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK KK File switch h Description Copyright 2004 ZiLOG Inc extent possible Function declarations for Switch input ALL RIGHTS RESERVED The source code in this file was written by an authorized ZiLOG employee or a licensed consultant Permission to use this code is granted
9. 0F91 Develop ment Board using the D1 and D2 buttons on the webpage Initialize webserver using http_init command Establish HTTP connection on Port 80 Received a terminate request Request received from a client Command string 1 Create a thread in ZTP OS based on Client IP address and Port number HN Send HTTP 200 OK status to client Toggle status of LED D1 Figure 5 Flowchart to Toggle the LEDs on Development Board using Buttons AN017801 0304 Appendix B Flowcharts Application Note A Webpage Interface for the eZ80F91 MCU using Java rik ga Figure 6 illustrates the flowchart for changing the color of the LED icons LED1 and LED2 on the webpage using the SW1 and SW2 switches on the eZ80F91 Development Board Initialize Port B pin PBO and PB1 as Input Is Switch SW1 No pressed Yes Yes Is the Flag for SW1 set No Set the Flag for SW1 Reset the Flag for SW1 Send string LED10n to Send string LED1off to the client browser the client browser End Figure 6 Flowchart to Change the Color of LED Icons on Webpage using Switches AN017801 0304 Appendix B Flowcharts Application Note A Webpage Interface for the eZ80F91 MCU using Java VAF rik ga Appendix C Source Code This appendix provides a listing of the source code associated with this Applica tion Note The source code file ano178 Sc01 zip is avail
10. 0F91 MCU using Java ZI EiL a Defintion for CGI Function int switchinput_cgi struct http_request request char switchstr int switchval http output reply request HTTP 200 OK Get a pointer to string from Web page Switchstr http find argument request unsigned char command switchval atoi switchstr Get the Switch number if switchval 1 If SW1 icon clicked if ledDCDstatus Check status of LED PB_DR 0x08 PB3 set to High DCD LED glows ledDCDstatus 1 Set Flag else PB DR amp OxF7 PB3 reset Low DCD LED put off ledDCDstatus 0 Reset Flag else if switchval 2 if ledRXstatus PB_DR 0x10 PB4 set to High RX LED glows ledRXstatus 1 Set Flag else AN017801 0304 Adding and Integrating Application Specific Files to ZTP AN017801 0304 10 11 12 13 Application Note A Webpage Interface for the eZ80F91 MCU using Java MP EiL PB_DR amp OXEF PB4 reset Low RX LED put off ledRXstatus 0 Reset Flag return OK From within ZDSII open the left htm file located in the Web Files folder Search for CGI Calculator and locate the following line nbsp amp nbsp lt a href switch htm target _top gt CGI Calculator lt a gt lt br gt Add the following piece of HTML code below the CGI Calculator line to create a link from the default eZ80A
11. 17801 0304 The procedure to build and run the Java based Webpage Interface Demo is described in this section 1 Ensure that the required Java based Webpage Interface files are added and integrated to ZTP before proceeding See section Adding and Integrating Application Specific Files to ZTP on page 16 for details 2 Make the connections as per Figure 1 Follow the jumper settings provided in the section on Jumper Settings above Connect the 9 volt power supply to the eZ80F91 Development Kit 4 Connect the 5 volt power supply to ZPAKII and the 7 5 volt power supply to the Ethernet Hub 5 Launch the HyperTerminal and follow the settings provided in the HyperTerminal Settings section above Settings 10 11 Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL From within the HyperTerminal press z repeatedly and then press the reset button on ZPAKII to view the menu to set the ZPAKII IP address Enter H to display help menu and follow the menu instructions to obtain the IP address for ZPAKII in order to download the Demo file This ZPAKII IP address must be entered in the ZDSII Launch ZDSIl for eZ80Acclaim and open the Java based Webpage Interface project file AcclaimDemo pro located in the path ZTP Demo Open the main c file Ensure that the Boot Info structure contains information that is relevant to your network configuration Use the IP address in the structure to browse the Interne
12. Butto yButto Lton Di s 120 160 50 30 n addActionListener this ton D2 180 160 50 30 n addActionListener this n setEnabled true n setEnabled true System out println Exit init Start the public void Applet start System out printlin Il ipaddr getCodeBas Enter Start System out println IP Addr ipaddr toString portNumbe System out println PortNumber portNumber int SWBuf try rws Jcatch UnknownHost AN017801 0304 r 80 fSize 250 ocket new Socket ipaddr toString portNumber Exception _ex getHost tIn Invalid format for bgcolor s3 Java Source Code File Application Note A Webpage Interface for the eZ80F91 MCU using Java System out println An error occurred while establishing the catch IOExcepti if readThread readThread readThread System out print catch System out print Exception communication with the server on _ex e reloading the page st null new Thread this art System out println Exit Start Write the text and draw the LED image public void paint Graphics g System out println Enter Graphics g QQ iQ iQ O O O O0 0 0 00 System out printl g g g g g g g g g Z LiLvg Ln Couldn t get I O for the connecti
13. ON These strings are sent as arguments in the switchinput cgi function See Control ling the LEDs on the Development Board section on page 15 for details of this CGI function The ZTP HTTP API nttp ind argument is called within the switchinput cgi function to search for the string LEp1on LED10off This string is sent to the browser where the color of the indicators LED icons LED1 LED2 on the webpage turns green or red See the flowchart illustrating the sequence of events in Figure 6 on page 28 Adding and Integrating Application Specific Files to ZTP AN017801 0304 The Java based Webpage Interface application described in this Application Note requires the eZ809 Development Board with the eZ80F91 MCU and the ZiLOG TGP IP stack ZTP To execute this application the files specific to the applica tion must be added and integrated to the ZTP stack before the stack is down loaded onto the eZ80F91 MCU This section contains the details of adding the application specific files to the ZTP stack The Java based Webpage Interface files are in the AN0178 Sc01 zip file avail able on the ZiLOG website The application files are of the following types e C c files e Header h files HTML htm html files Java class files Controlling the LED Icons on the Webpage AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL Image gif files The ZTP st
14. References 0 00 eee eee 26 List of Figures Abstract Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL An Internet enabled product built around eZ80Acclaim family of microcontrol lers using the ZiLOG TCP IP stack ZTP involves developing webpages to control its functionality This Application Note focuses on developing an application to remotely control the pins of the eZ80F91 MCU from a webpage and display the status of a pin on the webpage The details on how to write a Java applet add the applet into a HTML code use ZTP s HTTP related APIs and integrate the com plete system are discussed in this Application Note With this Java based application a two way control mechanism is demonstrated wherein the user controls the LEDs on the eZ80F91 Development Board via the buttons on the webpage and toggles the color of indicators LED icons on the webpage using switches on the Development Board This Java based Webpage Interface is thus another Java enabled process control application that uses the Internet Intranet See related ZiLOG Application Note on a Thermostat Demo using the eZ80F91 MCU The source code file saved in the WinZip format associated with this Application Note is AN0178 SC01 zip andis available on the ZiLOG website ZIP Overview AN017801 0304 Figure 1 depicts the general data communication path using the eZ80F91 Devel opment Kit the ZPAKII and an Ethernet Hub W
15. Save the files and close the AcclaimDemo project Demonstration This section contains the requirements and instructions to set up the Java based Webpage Interface Demo and run it Requirements The requirements are classified as hardware and software Hardware e eZ80F91 Development Kit eZ80F910200ZCO e PC with an Internet browser with the Java Virtual Machine Software e ZiLOG Developer Studio II IDE for eZ80Acclaim ZDSII e ZiLOG s TCP IP stack ZTP Setup The basic setup to assemble the Java based Webpage Interface demo is illus trated in Figure 1 on page 2 This setup illustrates the connections between the PC ZPAKII LAN WAN Internet and the eZ80F91 Development Kit ANO017801 0304 Demonstration Application Note A Webpage Interface for the eZ80F91 MCU using Java Zi EiL Settings HyperTerminal Settings e Set HyperTerminal to 57 6 Kbps Baud and 8 N 1 with no flow control Jumper Settings For the eZ80F91 Development Board e J11 J7 J2 are ON e J3 J20 J21 J22 are OFF e For J14 connect 2 and 3 e ForJ19 MEM_CEN1 is ON and CS EX IN MEM CEN2 and MEM_CEN3 are OFF For the eZ80F91 Module on eZ80F91 Development Board e JP3 is ON Additional Settings for the eZ80F91 Development Board e Connect PB3 of J6 Header to Pin6 of the J9 Connector Count Pin6 starting from the J9 marking e Connect PB4 of J6 Header to Pin7 of the J9 connector Count Pin7 starting from the J9 marking Procedure AN0
16. The following code illustrates the methods explained to create buttons xButton new Button D1 xButton setBounds 120 160 50 30 xButton addActionListener this add xButton yButton new Button D2 yButton setBounds 180 160 50 30 yButton addActionListener this add yButton xButton setEnabled true yButton setEnabled true Creating the Webpage AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java 10 rik ga Obtaining the Host IP Address The applet is started using the public void start method The IP address of the host where the applet is run must be obtained so that a socket can be opened for a communication channel to be set up between the client and the webserver The following code is used to set the port number and obtain the host IP address which is then sent to the webserver see the section on Adding and Integrating Application Specific Files to ZTP on page 16 public void start System out println Enter Start ipaddr getCodeBase getHost System out println IP Addr ipaddr toString portNumber 80 System out println PortNumber portNumber The following code handles the error due to a connection failure try rwSocket new Socket ipaddr toString portNumber catch UnknownHostException _ex System out println An error occurred while establish
17. Webpage Interface for the eZ80F91 MCU using Java EiL Controlling the LEDs on the Development Board When the button D1 or D2 is clicked on the webpage the actionPerformed method is invoked and a data string corresponding to the clicked button is stored in variable s public void actionPerformed ActionEvent ev System out println Enter Action Performed String label ev getActionCommand String s new String if label equals D1 s command 1 amp dummy 0 sendData s Jelse if label equals D2 s command 2 amp dummy 0 sendData s System out println Exit Action Performed The data in the string s is sent to the socket by the sendData method with an alert for any error that may occur After sending the data the socket is closed to complete the communication The HTTP layer of the webserver listening on Port 5000 parses and interprets this data and provides the requisite value to the CGI function switchinput cgi public void sendData String s System out println Enter SendData String sl null sl s sl GET switch cgi sl HTTP 1 1 r n r n System out println Data to send sl try System out println rwSocket rwSocket Creating the Webpage Application Note A Webpage Interface for the eZ80F91 MCU using Java M EiL Socket outSocket new Socket ipaddr portNumber os new DataOutputStream outSo
18. able on the ZiLOG web site C File Following C file is listed in this section e Switch c KKK KKK KKK KKK KK KKK Ck Ck AA A A Z AZ A Ck A A A KKK Ck A Ck A A4 KKK AZ AX AA A KKK KKK KKK Ax kx M File Switch c Description Function definition for Switch input Copyright 2004 ZiLOG Inc ALL RIGHTS RESERVED The source code in this file was written by an authorized ZiLOG employee or a licensed consultant The source code has been verified to the fullest extent possible Permission to use this code is granted on a royalty free basis However users are cautioned to authenticate the code contained herein ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE kckckckck ckck ckck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ck ckckckckckck ck ck ck ck ck ck ck ck ckck ck ck ckckckckckck ck ck KKK ky include lt kernel h gt include lt stdlib h gt include lt tcb h gt include lt dgram h gt include lt switch h gt Include header fil volatile char read switchSW1 Switch SW1 status volatile char read switchSW2 Switch SW2 status unsigned char switchonl Flag indicator for Switch SW1 unsigned char switchon2 Flag indicator for Switch SW2 void PortBInit void Initialize pin PBO PB_DR 0x1B PBO PB1 Input PB3 PB4 Output PB_DDR 0x03 AN017801 0304 Source Co
19. ack is available on the ZiLOG website and can be downloaded to a PC with a user registration key ZTP can be installed in any location as specified by the user its default location is c Program Files ZiLOG Note Before adding and integrating the application specific files to ZTP ensure that all the settings for the ZTP stack are at default values Perform the following steps to add and integrate the Demo files to the ZTP stack 1 Download ZTP browse to the location where ZTP is downloaded and open the website Acclaim folder 2 Download the ano178 sc01 zip file and extract its contents to a folder on your PC this folder is referred to as NJavawebCont rol folder in the rest of the Application Note Notice the two extracted folders within the NJavaWebControl folder NJWC Demo JWC_Website Acclaim 3 Select and copy the ntm class h andthe gif files in the NJavaWebControlNJWC Website Acclaim folder and paste them into the ZTP website Acclaim folder 4 Select and copy all the c and h files located in the NJavaWebControlNJWC Demo folder and paste them into the ZTP Demo directory 5 Launch ZDSII and open the project file website pro located in the path NZTPNwebsite Acclaim 6 Nowaddthe htm class h andthe git files located in the website Acclaim folder to the project using the sequence of steps Project Add Files The htm class h andthe gif files to be added are listed below
20. ava byte code in the webserver from which the applet object is created Visit www java sun com for information on the Java language Developing the Java based Webpage Interface Application This section discusses the implementation of the Java based Webpage Interface in detail The implementation of the operations that occur when a button is clicked on the webpage and when a switch on the Development Board is pressed are AN017801 0304 Java Applets and HTML Application Note A Webpage Interface for the eZ80F91 MCU using Java Eiko a explained in the following sections The section also includes instructions on how to interface the application specific files to the standard ZTP files The block diagram of eZ80F91 webserver setup for the Java based Webpage Interface application is shown in Figure 1 The eZ80F91 MCU is configured to work as a webserver and a client PC with a browser is used to control the GPIO pins on the eZ80F91 MCU via the webpages The switches SW1 SW2 and the LEDs DCD D1 RX D2 are on the Development Board and are used to demon strate the working of this application A browser is used to access the eZ80F91 webserver to obtain the current status of different GPIO pins or to change the status of the pins and thereby control the system over the Ethernet The locally networked devices are connected together in an intranet and are accessible to the outside world Internet through a gateway An overview of the communica
21. cclaim webpage to the Java based Webpage Interface Demo webpage amp nbsp amp nbsp lt a href switch htm target main gt Java Web Control lt a gt lt br gt Build the website pro project to obtain the new library file Acclaim website lib Copy the Acclaim_website 1ib library file to the path zTP libs Note Please note that the zTP 1libs folder already contains an 14 15 16 Acclaim website lib file and it must be replaced with the newly generated file Click Yes to replace the file Close the website pro project In ZDSII open the AcclaimDemo pro file available in the path ZTP Demo Add the c file located in the NavawebControlNJWC Demo folder to the project using the sequence of steps Project Add Files The c file to be added is switch c Adding and Integrating Application Specific Files to ZTP AN017801 0304 17 18 19 Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL Open the main c file of the AcclaimDemo project and add the following include file include lt switch h gt In the main c file observe the following Boot Info structure definition struct BootInfo Bootrecord 192 168 1 1 Defaul 192 168 1 4 Defaul 192 168 1 5 Defaul 192 168 1 6 Defaul wn IP address Gateway Timer Server ct cb ab oct File Server 192 168 1 7 Default Name Server wn
22. ce code in this file was written by an authorized ZiLOG employee or a licensed consultant The source code has been verified to the fullest extent possible HTML file for the Java Web Control webpage ED Permission to use this code is granted on a royalty free basis However users are cautioned to authenticate the code contained herein ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE head meta http equiv 2 Content Type title title head body p al appl lign center gt let CODE SwitchCtrlNew class WIDTH 350 lt param name bgcolor value 5563A4 gt lt applet gt lt p gt lt body gt lt html gt AN017801 0304 SOFTWARE H Er content text html charset iso 8859 1 EIGHT 200 HTML File Application Note A Webpage Interface for the eZ80F91 MCU using Java Java Source Code File VAR rik ga This section contains the Java source code file for the applet The following file is listed in this section e SwitchCtrl java File SwitchCtrl java Description Source code file for the applet P Copyright 2004 ZiLOG Inc PA The source code in this file was written by an authorized ZiLOG employee or a licensed consultant The source code has been verified to the fullest extent possible Permission to use this code is granted on a royalty free basis However user
23. cket getOutputStream os flush os write sl getBytes outSocket close catch IOException _ex System err printlin Write exception _ex System out println Exit Send Data The Java source code construction for the applet is now complete To compile this code the Java compiler version 1 1 must be installed on the PC PCs with a web browser such as Internet Explorer or Netscape already contain the Java VIrtual Machine that contains the Java compiler The following command at the DOS prompt is used to compile the Java code Javac deprecation target 1 1 SwitchCtrl java After successful compilation a class file Switcnctrl class Is created This class file is further converted to a SwitchCtrl class c file where the contents of the file are stored in the form of an array when the project is compiled using the ZiLOG s ZDSII compiler Controlling the LEDs on the Development Board AN017801 0304 In the Java based Webpage Interface application a CGI function switchinput cgi is used to call the ZTP HTTP CGI functions in order to read the user input from the HTML webpage when the button D1 or D2 is clicked on the webpage and to transmit that input data to the Development Board See the sec tion ZTP HTTP CGI Functions on page 2 The switchinput cgi function is declared as follows int switchinput cgi struct http request request This CGI function initially calls the ZTP HTTP API
24. de PB_ALT1 PB_ALT2 0x00 0x00 int task2 int cfd while 1 if switchonl if write cfd break else if write cfd break if switchon2 if write cfd break else if write cfd break sleep 2 close cfd task2 int taskl void int dev cfd int port 5000 if dev open TCP return SYSERR Application Note A Webpage Interface for the eZ80F91 MCU using Java amp LEDIon n 9 SYSERR amp LEDloffNn 10 Zi EiL a Lookout for a new client Send status of SW1 to Web page SYSERR Send default status amp LED20nNn 9 SYSERR amp LED20ffNn 10 no change Send status of SW2 to Web page SYSERR Send default status no change Close port on client disconnect or error ANYFPORT char port control dev TCPC_LISTENQ char 5 0 AN017801 0304 hf SYSERR Open an available port Report error on problem Open port in Listen mode C File Application Note A Webpage Interface for the eZ80F91 MCU using Java Z iLa while 1 cfd control dev TCPC_ACCEPT 0 0 Wait for a client connection if cfd SYSERR return SYSERR Report error on problem resume create procptr task2 1024 20 task2 1 cfd task1 int Switch Input void int dev cfd
25. en networked products and allows them to interchange data reliably over the Ethernet For this Java based Webpage Interface application a C program supports the webpages and helps the user interact with the webserver Using the ZTP HTTP user interface primarily involves writing user application code that calls the appropriate ZTP HTTP API functions It also involves integrat ing user webpages into the webserver using ZDSII ZTP HTTP CGI Functions Embedded systems typically do not contain a file system The lack of a file system means that embedded systems cannot save CGI scripts as separate cgi files Instead of saving CGI scripts as separate cgi files ZTP uses C function calls collectively called CGI functions When a CGI function is called the HTML code stored in the webserver is sent to the web browser It is in these function calls that HTTP Server in ZTP Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL a programmer writes code to read the information sent by a web browser This information is then processed as required by the application ZTP provides the following CGI functions to the user int http output reply http request request int reply char http find argument http request request char arg int http write http request request char buff int count In each ZTP CGI function the pointer to the request structure is used to keep the requests from different cli
26. ents separate The function http output reply is used to return an acknowledgement to the browser that made the request The http find argument function is used to extract parameters from the received data in the parsed browser request The macro http write is used to return data to the browser that sent the request that invoked the CGI function For detailed information on the protocols used in ZTP refer to the ZTP Program mer s Guide RM0008 available along with the ZTP software Java Applets and HTML A Java applet is a program that adheres to a set of conventions that allow it to run on Java compatible browsers Most of the standard HTML browsers support Java applet execution The standalone systems using Java applets must add a Java Virtual Machine JVM to run an applet Hypertext Markup Language HTML is used to display information in webbrows ers A webpage is basically coded in HTML which is interpreted at run time by the browser A webpage that can change its content depending on the information obtained by the server at run time is called dynamic A static page on the other hand displays fixed information Inserting an applet into the webpage allows the webpage to display dynamic information because the applet changes its content during run time The web browser creates the applet object when it encounters the applet tag in the HTML code the lt applet gt tag provides the name of the Java class file stored as J
27. haracters This value is then passed to the method updateBulbStatus try inSocket new Socket ip toString port is new DataInputStream inSocket getInputStream System out println InStream is gt gt is while true Str t while b is readByte amp while b is readByte n str str char b read bytes not Unicode characters System out println Input read is gt gt str Creating the Webpage 12 Application Note A Webpage Interface for the eZ80F91 MCU using Java Ll Eikga updateBulbStatus str catch Exception e System out println An error occurred while reading the response Try reloading the page Changing the Color of the Indicators The updateBulbStatus method which toggles the color of the indicators LED icons on the webpage between red and green is constructed as illustrated below public void updateBulbStatus String msg System out println Enter UpdateBulbStatus System out println Received String msg if msg equals LED1on redraw 1 Color red else if msg equals LEDloff redraw 1 Color green else if msg eguals LED2on redraw 2 Color red else if msg equals LED2o0ff redraw 2 Color green System out println Exit updateBulbStatus AN017801 0304 Creating the Webpage AN017801 0304 Application Note A
28. http init function to initial ize the webserver makes a TCP connection on the specified port and waits for a client request Upon receiving a request from the client the webserver provides a response according to the webserver configuration Controlling the LEDs on the Development Board Application Note A Webpage Interface for the eZ80F91 MCU using Java VAR EiL The CGI function then calls the ZTP HTTP CGI function http output reply to send an acknowledgement to the client browser The http_find_argument is called to search for the string command indicating which of the buttons D1 or D2 is pressed the respective LED on the Development Board is then switched on off See the flowchart illustrating the sequence of events in Figure 5 on page 27 Controlling the LED Icons on the Webpage The Port B of the eZ80F91 MCU is initialized with PBO and PB1 as input pins and PB3 and PB4 as output pins see Switch c file in the ANO178 SCO1 zip file avail able on the ZiLOG website Port B is continuously polled for any change in status in ZTP s main c file When the SW1 SW2 switch on the Development Board is pressed the change in the switch status is captured by the Switch Input function a flag is set or reset to indicate the status of the switches and an appropriate string is written for the switch The strings LEDon Or LEDoff are used to indicate whether the LED icons on the webpage must be displayed in green OFF or red
29. ing the communication with the server catch IOException _ex System out println Couldn t get I O for the connection to ipaddr Jcatch Exception e System out println An error occurred while reading the response Try reloading the page A new thread is then created and started with the following lines of code if readThread null Creating the Webpage AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java Z EiL readThread new Thread this readThread start Creating the Applet Heading The text or the heading for the Applet is printed using the paint Graphics method of the java awt Graphics package The paint Graphics method is coded as follows public void paint Graphics g System out printin Enter Graphics g g setColor Color black g fillRect 0 0 400 28 g drawImage imagel 0 0 this g setColor Color white g setFont new Font Arial 1 14 g drawString LED and Switch Control Demo 75 18 g setColor Color yellow g setFont new Font Arial 1 10 g drawString Press the switches on the board to activate the LEDs below 40 45 g setColor Color white g setFont new Font Arial 1 10 g drawString LED1 139 62 g drawString LED2 191 62 g setColor firstBulbColor g fillOval 130 70 40 40 g setColor secondBulbColor
30. ith this hardware the eZ80F91 MCU is ready to be used as an efficient webserver when ZiLOG s ZTP software is downloaded on it ZTP provides the software to drive the hardware used for TCP IP connections This hardware comprises SERIAL1 UART1 UART2 for PPP connections and the Ethernet Media Access Controller EMAC for Ethernet con nections among other peripherals The ZiLOG TCP IP Software Suite ZTP contains a set of libraries that implement an embedded TCP IP stack and includes a pre emptive multi tasking kernel The ZTP Applications Programming Interface API allows programmers using any member of the eZ80 family of processors including the eZ80Acclaim prod uct line to rapidly develop internet ready applications with minimal effort Abstract Application Note A Webpage Interface for the eZ80F91 MCU using Java Ei oa eZ80F91 Development Kit eZ80F910200ZC0 J4 ZDI eZ809 Development E Platform 4 Port HUB Ethernet Ethernet P2 Ethernet LAN WAN INTERNET Figure 1 General Setup with the eZ80F91 MCU as a Webserver HTTP Server in ZTP AN017801 0304 The implementation of Hyper TextTransfer Protocol HTTP in ZTP enables eZ80F91 microcontroller to work as an HTTP server The eZ80F91 MCU based products implemented as an HTTP server can store webpages and provide them to browsers on demand The HTTP layer also provides the facility of creating socket connections betwe
31. mage getDocumentBase logo gif Setting the Applet Background Colour The following piece of code is used to set the background color of the applet based on the color value received from the HTML page String s3 getParameter bgcolor if s3 null try setBackground new Color Integer parseInt s3 substring 1 16 Creating the Webpage AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL The catch method that is used to handle errors and exceptions in Java is used to handle invalid color values The error message is displayed on the Java Con sole that can be opened from the web browser Note The Java Console is available as an option under Tools in the web browser when the Java Runtime Environment JRE is installed on the client PC The JRE can be downloaded from the website http www java sun com catch NumberFormatException _ex System out println Invalid format for bgcolor s3 setLayout null Creating the Buttons To create buttons with text the method new Button is used The set Bounds method specifies the area the X and Y axis where the button is to be placed on the webpage and also specifies its width and height The aaa method adds the new button to the Applet The setEnabled method either activates or disables the button The button is activated only when the set Enabled method is true and disabled when it is false
32. n compiling the SwitchCtrl java file The Java file SwitchCtrl java is coded as detailed below The entire Java source code is available in Appendix C on page 29 Importing Relevant Java Packages In the SwitchCtrl java file the relevant packages that the main program uses are imported in the beginning of the file The packages are similar to the 1ib and n files of the C language In the program for the applet the following pack ages containing the relevant classes are defined as imported import java applet Applet import java awt import java io import java net import java awt event Creating the Webpage Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL The imported packages are part of the core Java APIs that every Java program uses in the Java run time environment The java applet package contains classes that are essential for Java applets The java awt package contains the most frequently used classes in the Abstract Window Toolkit AWT which pro vides the Java graphical user interface GUI properties A sub class to extend the properties provided to the applet by the packages is implemented next with the following lines of code public class SwitchCtrl extends Applet implements Runnable ActionListener The extends keyword indicates that switchctr1 is a subclass of the Applet class From the Applet class applets inherit a great deal of functionality the most impor
33. nchronized public System out print ip getCodeBas n Enter Destroy n Exit Destroy hreads void run n Enter RUN getHost System out print port 5000 System out print String str mT String rd byte b try inSocket is new Da ln IP Addr ip toString in PortNumber port new Socket ip toString port talnputStream inSocket getInputStream System out println InStream is is while true catch I str nns while b is readByte amp whil b is readByte n str str char b read bytes not Unicode characters System out println Input read is gt gt str updateBulbStatus str Exception e System out println An error occurred while reading the response Try AN017801 0304 reloading the page Java Source Code File Application Note A Webpage Interface for the eZ80F91 MCU using Java Z EiL a public void updateBulbStatus String msg System out println Enter UpdateBulbStatus System out println Received String msg BulbCanvas canvas this canvas if msg equals LEDlon redraw 1 Color red else i red msg equals LEDloff 1 Color green Hh rh W else i red msg eguals LED2on 2 Color red Hh rh W else if msg eguals LED2o0ff redraw 2 Colo
34. nt status of a pin on the eZ80F91 MCU can be Summary 24 AN017801 0304 Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL remotely viewed and controlled by using a Java applet in a webpage This type of simple interface utilizes the HTTP component of ZiLOG s ZTP stack and provides reliable transfer and control of data The details provided in this Application Note can be used to build more complex user interfaces for real world applications Summary 25 Application Note A Webpage Interface for the eZ80F91 MCU using Java 26 EiL Appendix A Reference Further details about the eZ80F91 MCU eZ80 CPU and ZTP can be found in the references listed in Table 1 Topic Table 1 List of References Document Name eZ80F91 MCU eZ80F91 Development Kit User Manual UMO1 42 eZ80F91 Flash MCU with Ethernet MAC Product Specifications PS0192 eZ80F91 Module Product Specifications PS0193 eZ80 CPU eZ80 CPU User Manual UM0077 ZiLOG s TCP IP Software Suite ZTP ZiLOG s TCP IP Software Suite Programmer s Guide Reference Manual RM0008 AN017801 0304 Appendix A Reference Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL Appendix B Flowcharts This appendix contains the flowcharts for the Java based Webpage Control Inter face implementation using the eZ80F91 MCU Figure 5 illustrates the flowchart for toggling the LEDs on the eZ8
35. on a royalty free basis However users ar code contained herein ZiLOG DOES NOT GUARANTEE The source code has been verified to the fullest i cautioned to authenticate the THE V ERACITY OF THE SOFTWARE KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK ifndef SWITCH H define SWITCH H include eZ280F91 h define SW10x01 define SW20x02 void PortBInit void int Switch Input void int task2 int cfd int task1 void endif PBO switchl input for PBl switch2 input for Initialize pin PBO Check SW1 Prototype function declarations EDiconl EDicon2 KOR KKK KK oko k oko k kok k oko k kok I Koko k kok k KCKCK kok k Koko K kok kok k Kk k kok k kok k Koko ke ke kk KKKKKKKKKKKKKKKKKKKKKKKKK KY End of EL LEk eR KKK KK KKK KK KK KKK KK KK KK KK KK KOKCKCKCKCKCKCkCk kCk Ck kCKCk kCkCk kCkCkCkCkCK Ck kCK Ck KCkCk kok Ck k kCk Ck kCK Ck K kok kk IK OR OK KK AN017801 0304 Header File Application Note A Webpage Interface for the eZ80F91 MCU using Java HTML File VAF rik ga The following HTML file is listed in this section e Switch htm lt html gt FF FF Xo X Xo Xo Xo Xo X F A gt Copyright 2004 ZiLOG Inc File Switch htm Description ALL RIGHTS RESERV The sour
36. on to ipaddr In An error occurred whilereading the response Try EDs setColor Color black fillRect 0 0 400 28 drawImage imagel 0 0 this SetColor Color white setFont new Font Arial 1 14 drawString LED and Switch Control Demo 75 18 setColor Color yellow SetFont new Font Arial 1 10 drawString Press the switches on the board to activate the LI 40 45 SetColor Color white SetFont new Font Arial 1 10 drawString LED1 139 62 drawString LED2 191 602 setColor firstBulbColor filloOval 130 70 40 40 SetColor secondBulbColor filloval 185 70 40 40 setColor Color yellow SetFont new Font Arial 1 10 drawString To switch ON OFF the LEDs on the board click the buttons 25 145 n Exit Graphics public void redraw int bulbNo Color bulbColor L else if bulbNo if bulbNo this fi 1M rstBulbColor bulbColor AN017801 0304 Java Source Code File this se repaint Stop the thread public void stop System out println Enter Stop System out println Exit Stop Application Note A Webpage Interface for the eZ80F91 MCU using Java ZI EiL a condBulbColor bulbColor Destroy the thread public void destroy System out print System out print synchronize the t sy
37. r green System out println Exit updateBulbStatus When the button is clicked send relevant information to control the LED on the board public void actionPerformed ActionEvent ev System out println Enter Action Performed String label ev getActionCommand String s new String if label equals D1 s command 1 amp dummy 0 sendData s Jelse if label equals D2 S command 2 amp dummy 0 sendData s System out println Exit Action Performed Send the data to the control program on the HTTP server public void sendData String s System out println Enter SendData String sl null sl s sl GET switch cgi sl HTTP 1 1 r n r n System out println Data to send sl try AN017801 0304 Java Source Code File Application Note A Webpage Interface for the eZ80F91 MCU using Java VAF Eikga System out printin rwSocket rwSocket System out println Received from Server numbStr Socket outSocket new Socket ipaddr portNumber os new DataOutputStream outSocket getOutputStream os flush os write sl getBytes outSocket close catch IOException _ex System err println Write exception _ex System out println Exit Send Data End of file AN017801 0304 Java Source Code File
38. s are cautioned to authenticate the code contained herein ZiLOG DOES NOT GUARANT ALL RIGHTS RESERVED T T THE VERACITY OF THE SOFTWARE E Import the various classes required to run the applet import java applet Applet import java awt import java io import java net import java awt event public class SwitchCtrlNew extends Applet implements Runnable ActionListener Declare the variables Socket rwSocket Socket inSocket Thread readThread String ipaddr null String ip null int portNumber int port Button xButton Button yButton DataOutputStream os DataInputStream is AN017801 0304 Java Source Code File Application Note A Webpage Interface for the eZ80F91 MCU using Java VAF Pik a Image imagel String numbStr Thread readThreadl Color firstBulbColor Color green Color secondBulbColor Color green Initialize the variables public void init System out println Enter init imagel getImage getDocumentBase logo gif setLayout null String s3 getParameter bgcolor if s3 null try setBackground new Color Integer parseInt s3 substring 1 10 catch NumberFormatException _ex System out prin setLay xButto xButto xButto out null n new But n setBounds add xButton yButto yButto yButto n new But n setBounds add yButton x
39. t to view the Web Switch Demo web pages Build the project and download the resulting file to the eZ80F91 Module on the eZ80 Development Board using ZDSII Run the Java based Webpage Interface Demo Refer to Running the Java based Webpage Interface Demo section below Running the Java based Webpage Interface Demo 1 Summary AN017801 0304 Launch the Internet browser on the PC Enter the IP address for the eZ80F91 Development Board specified in main c The Index html page is displayed The LEDs labeled DCD and RX on the Development Board light up to indicate an active link between the eZ80F91 webserver and the PC based client browser Click on the link Java Web Control located in the left side of the screen A new web page LED and Switch Control Demo opens displaying the buttons and the indicators LED icons Click on the button D1 Notice that the LED labeled DCD on the Development Board is switched off and this on off feature toggles on every mouse click The same procedure is performed on the D2 button for the LED labeled Rx Press the switch SW1 SW2 on the eZ80F91 Development Board The color of the indicator LED icons changes from red to green Subsequent clicking of the switches toggles the color of the LED icons on the webpage The eZ80F91 microcontroller is used for building Internet enabled products that are controlled over an Internet or Intranet using webpages This Application Note demonstrates how the curre
40. tch Control Demo Webpage Figure 4 is a close up of the Java applet display LED and Switch Control Demo LED2 Figure 4 Java Applet Component on HTML Webpage AN017801 0304 Developing the Java based Webpage Interface Application gt Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL Note By default the HTTP server closes the TCP connection as soon as the HTTP request is processed and therefore persistent connections are not possible The software implementation can be divided into the following sections e Designing the webpage which includes coding the Java applet for the GUI e Developing the functionality which comprises the following Implementing the functionality to control the LEDs on the Development Board Implementing the functionality to effect a change in the indicators LED icons on the webpage using the switches on the Development Board Creating the Webpage AN017801 0304 The source code for the HTML file Switch htm displays the webpage as shown in Figure 3 The HTML script contains a link to the Java applet using the lines of code as presented below applet width 340 height 250 code SwitchCtrl class gt lt param name bgcolor value FFFFFF gt lt applet gt The applet is executed from the Java class file Switchctrl class which is previ ously stored in the eZ80F91 webserver in the form of ASCII characters The SwitchCtrl class file is obtained upo
41. tion between eZ80F91 webserver and an HTML browser is illustrated in Figure 2 seen HTTP request Client Browser eZ80F91 Webserver started on a PC DI gt application hosting Java a applet in HTML file ZTP Transmits Client Browser HTML eZ80F91 Webserver ona PC host hosting Java applet in HTML file Establish socket Client B Connection on eZ80F91 Webserver ient Browser Port yyyy running applet CGI function sends ROSE ree ee eee HTTP 200 OK sm M Me CNN Send Command Client Browser z Request data eZ80F91 Webserver running applet CGI function controls E Gace D lt gt input output to webpage Bi directional communication established Figure 2 Communication between Client Browser and the eZ80F91 Webserver AN017801 0304 The webserver transmits an HTML file containing a link to the Java applet to the client browser The Java applet contains a graphical user interface GUI compo nent that is displayed on the webpage as shown in Figures 3 and 4 The webpage displays the buttons that control the LEDs and the indicators LED icons that are controlled by the switches on the Development Board Developing the Java based Webpage Interface Application Application Note A Webpage Interface for the eZ80F91 MCU using Java EiL issa ere AERE Se NLIS NMESILLG HESS ii EL E eam eH ee eed ips I NEMD Figure 3 LED and Swi
Download Pdf Manuals
Related Search
Related Contents
Manual de Instrucciones Operator`s Manual - Northern Tool + Equipment Fiche commerciale - Axe Samsung 3 Series NP3530EC notebook Swift™ FX Bella Gray GRUPPI TERMICI CYLINDER KITS GROUPES THERMIQUES www ACC KIT-615 Guida per l`utente 6833 tipo A60 6832 tipo A60i Duraflame DFI-550-0 Installation Guide Copyright © All rights reserved.
Failed to retrieve file