head	1.3;
access;
symbols
	bg2_23:1.3
	bg2_22:1.3
	bg2_21:1.3
	bg2_20:1.3
	bg2_16:1.3
	bg2_15:1.3
	bg2_12:1.3
	bg2_07:1.3
	isorc2008_submission:1.3
	handbook_alpha_edition:1.3
	jtres2007_submission:1.2
	bg1_07:1.1
	bg1_06:1.1
	bg1_05:1.1
	TAL_101:1.1
	TAL_100:1.1
	jtres_submission:1.1;
locks; strict;
comment	@# @;


1.3
date	2007.09.11.04.22.33;	author martin;	state Exp;
branches;
next	1.2;
commitid	7b1f46e618034567;

1.2
date	2007.01.24.19.59.07;	author martin;	state Exp;
branches;
next	1.1;
commitid	1fbe45b7ba8a4567;

1.1
date	2006.06.19.18.10.20;	author martin;	state Exp;
branches;
next	;
commitid	44104496e8894567;


desc
@@


1.3
log
@Simple Telnet server works with TCP/IP
@
text
@/*
 * 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 examples;


import joprt.RtThread;
import util.Dbg;
import util.Timer;
import ejip.*;

class MyServer extends UdpHandler {
	
	StringBuffer sb;

	// sorry, but the class intializer cannot
	// create objects (at the moment)
	public MyServer() {
		sb = new StringBuffer(100);
	}
	
	
	public void request(Packet p) {
		
		String answer = " Answer";
		
		System.out.print("reveived: ");
		// nasty manipulation of the int[] buffer
		// when dealing with byte characters :-(
		Ip.getData(p, Udp.DATA, sb);
		Dbg.wr(sb);
		System.out.println();
		sb.append(answer);
		Ip.setData(p, Udp.DATA, sb);
		// and return it to port 1234
		Udp.build(p, p.buf[3], 1234);
	};

}
/**
*	Simple UDP Server.
*/

	
public class UdpJOPServer {

	static Net net;
	static LinkLayer ipLink;

/**
*	Start network and enter forever loop.
*/
	public static void main(String[] args) {


		// use serial line for debugging
		Dbg.initSerWait();
		
		//
		//	create our simple UDP server
		//
		MyServer server = new MyServer();
		Udp.addHandler(1234, server);
		//
		//	start TCP/IP
		//
		net = Net.init();
		int[] eth = {0x00, 0xe0, 0x98, 0x33, 0xb0, 0xf8};
		int ip = (192<<24) + (168<<16) + (0<<8) + 123;
		ipLink = CS8900.init(eth, ip);

		//
		//	start device driver threads
		//

		new RtThread(5, 10000) {
			public void run() {
				for (;;) {
					waitForNextPeriod();
					net.loop();
				}
			}
		};
		new RtThread(5, 10000) {
			public void run() {
				for (;;) {
					waitForNextPeriod();
					ipLink.loop();
				}
			}
		};

		//
		//	WD thread has lowest priority to see if every timing will be met
		//

		RtThread.startMission();

		forever();
	}

	private static void forever() {

		//
		//	just do the WD blink with lowest priority
		//	=> if the other threads take to long (*3) there will be a reset
		//
		for (;;) {
			for (int i=0; i<10; ++i) {
				RtThread.sleepMs(50);
				Timer.wd();
				/*-
				int val = Native.rd(Const.IO_IN);
				Native.wr(val, Const.IO_LED);
				*/
				Timer.loop();
			}
			Timer.wd();
		}
	}
}
@


1.2
log
@use local eth and ip
@
text
@d57 1
a57 1
		Udp.getData(p, sb);
d61 1
a61 1
		Udp.setData(p, sb);
@


1.1
log
@no message
@
text
@d95 3
a97 1
		ipLink = CS8900.init(Net.eth, Net.ip);
@

