www.pudn.com > ejip.zip > Html.java


/* 
 * Copyright (c) Martin Schoeberl, martin@jopdesign.com 
 * All rights reserved. 
 * 
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met: 
 * 1. Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright 
 *    notice, this list of conditions and the following disclaimer in the 
 *    documentation and/or other materials provided with the distribution. 
 * 3. All advertising materials mentioning features or use of this software 
 *    must display the following acknowledgement: 
 *	This product includes software developed by Martin Schoeberl 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 * SUCH DAMAGE. 
 * 
 */ 
 
package ejip; 
 
import com.jopdesign.sys.*; 
import util.*; 
 
/** 
*	a very SIMPLE HTML server class. 
*/ 
 
public class Html { 
 
	private static final int IO_INOUT = 0; 
 
	public static int[] prot; 
	public static int[] end; 
 
	public static int[] on; 
	public static int[] off; 
 
	public static int[] val; 
	public static int[] tmp; 
	private static int hits; 
	private static int outVal; 
 
	public static int[] msg; 
 
	private static final int MAX_MSG = 80; 
 
 
/** 
*	allocate buffers. 
*/ 
	public static void init() { 
 
		init1(); 
 
		val = new int[5]; 
		tmp = new int[1500]; 
		msg = new int[MAX_MSG]; 
		for (int i=0; i>>16); 
		i &= 0xffff; 
//		Dbg.wr('T'); 
//		Dbg.intVal(i); 
		i = (i-600)/17+27; 
//		Dbg.intVal(i); 
 
		if (i>99) i = 99; 
 
		if (i<0) { 
			i = -i; 
			val[0] = '-'; 
		} else { 
			val[0] = ' '; 
		} 
		val[1] = '0'+i/10; 
		val[2] = '0'+i%10; 
		val[3] = ' '; 
		val[4] = ' '; 
 
		return val; 
	} 
 
	private static void setInt(int val, int[] buf) { 
 
		int i; 
 
		for (i=buf.length-1; i>=0; --i) { 
			buf[i] = val%10+'0'; 
			val /= 10; 
			if (val==0) break; 
		} 
		--i; 
		for (; i>=0; --i) { 
			buf[i] = ' '; 
		} 
	} 
 
	private static int[] getAnalog(int channel) { 
 
		int i = Native.rd(IO_ADC); 
		if (channel==2) { 
			i >>>= 16; 
		} 
		i &= 0xffff; 
 
		// setInt(i, val); 
		i += 100; 
		i /= 201; 
		val[4] = ' '; 
		val[3] = '0'+i%10; 
		val[2] = '.'; 
		i /= 10; 
		val[1] = '0'+i%10; 
		val[0] = '0'+i/10; 
 
		return val; 
	} 
 
	private static int[] getHit() { 
 
		int j; 
 
		for (j=0; j<5; ++j) { 
			val[j] = ' '; 
		} 
		val[0] = '0'+hits/10000%10; 
		val[1] = '0'+hits/1000%10; 
		val[2] = '0'+hits/100%10; 
		val[3] = '0'+hits/10%10; 
		val[4] = '0'+hits%10; 
 
		return val; 
	} 
 
	private static int[] getDigital() { 
 
		setInt(Native.rd(IO_INOUT), val); 
		return val; 
	} 
 
	private static void setMsg(int[] buf, int pos) { 
 
		int i, j; 
		for (i=0; i>2)]; 
			tmp[i] = j>>>24; 
			tmp[i+1] = (j>>>16)&0xff; 
			tmp[i+2] = (j>>>8)&0xff; 
			tmp[i+3] = j&0xff; 
		} 
Dbg.wr('\n'); 
for (i=0; i>2; ++i) { 
			j = (tmp[k]<<24) + (tmp[k+1]<<16) + 
				(tmp[k+2]<<8) + tmp[k+3]; 
			buf[ret_pos+i] = j; 
			k += 4; 
		} 
		return ret; 
	} 
 
/** 
*	Handle one HTTP request. 
*/ 
	private static void processRequest(int[] buf, int pos) { 
 
		if (buf[pos+0]!='?') return;		// nothing to do! 
 
		int i = pos+1; 
 
		if (buf[i]=='m') { 
			setMsg(buf, i+2); 
		} else {							// set/reset outValuts 
			outVal = 0; 
			for(; i<100; ++i) { 
				if (buf[i]=='o') { 
					++i; 
					int j = buf[i]-'1'; 
					if (j>=0 && j<=3) { 
						outVal |= 1<