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


package util; 
 
/** 
*	serial output for debug on uart 1. 
*/ 
 
public abstract class Dbg { 
 
	abstract void dbgWr(int c); 
	abstract int dbgReadBuffer(int[] buf, int pos); 
 
	private static Dbg st; 
 
	private static final int MAX_TMP = 32; 
	private static int[] tmp;			// a generic buffer 
 
 
	/** init serial or UDP Debugging */ 
	public static void init() { 
 
		if (st==null) { 
			tmp = new int[MAX_TMP]; 
			// st = new DbgSerial(); 
			st = new DbgUdp(); 
		} 
	} 
 
	/** force serial Debugging */ 
	public static void initSer() { 
 
		if (st==null) { 
			tmp = new int[MAX_TMP]; 
			st = new DbgSerial(); 
		} 
	} 
 
	public static void wr(int c) { st.dbgWr(c); } 
 
	public static int readBuffer(int[] buf, int pos) { 
		return st.dbgReadBuffer(buf, pos); 
	} 
 
	public static void intVal(int val) { 
 
		int i; 
		if (val<0) { 
			wr('-'); 
			val = -val; 
		} 
		for (i=0; i=0; --val) { 
			wr(tmp[val]); 
		} 
		wr(' '); 
	} 
 
	public static void hexVal(int val) { 
 
		int i, j; 
		if (val<16) wr('0'); 
		for (i=0; i>>= 4; 
			if (val==0) break; 
		} 
		for (val=i; val>=0; --val) { 
			wr(tmp[val]); 
		} 
		wr(' '); 
	} 
 
	public static void byteVal(int val) { 
 
		int j; 
		j = (val>>4) & 0x0f; 
		if (j<10) { j += '0'; } else { j += 'a'-10; } 
		wr(j); 
		j = val & 0x0f; 
		if (j<10) { j += '0'; } else { j += 'a'-10; } 
		wr(j); 
		wr(' '); 
	} 
}