[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/shockfish/tools/java/com/shockfish/tinyos/apps/demo Makefile, NONE, 1.1 OscopeDataCaptureServer.java, NONE, 1.1 OscopeDataCaptureServerThread.java, NONE, 1.1

rogmeier rogmeier at users.sourceforge.net
Mon Sep 11 08:47:33 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/shockfish/tools/java/com/shockfish/tinyos/apps/demo
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv18348/com/shockfish/tinyos/apps/demo

Added Files:
	Makefile OscopeDataCaptureServer.java 
	OscopeDataCaptureServerThread.java 
Log Message:
TC65/TinyNode Host support package. Includes bridge and demo server.

--- NEW FILE: Makefile ---
# Top-level Makefile for tools/java 


TOS = $(shell ncc -print-tosdir)
PACKAGE = com.shockfish.tinyos.apps.demo
APP = ${TOSROOT}/apps/Oscilloscope
MIG = mig  -target=tinynode -I ${TOSROOT}/contrib/shockfish/tos/platform/tinynode java

MSGS = OscopeMsg.java

all: cleanmig ${MSGS}


INITIAL_TARGETS = $(MSGS)
OTHER_CLEAN = cleanmig

OscopeMsg.java:
	$(MIG) -v -java-classname=$(PACKAGE).OscopeMsg ${APP}/OscopeMsg.h OscopeMsg -o $@

cleanmig:
	rm -f $(MSGS)
	

TOS = $(shell ncc -print-tosdir)
ROOT = $(TOS)/../tools/java


include $(ROOT)/Makefile.include
	

--- NEW FILE: OscopeDataCaptureServer.java ---
package com.shockfish.tinyos.apps.demo;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

//import com.shockfish.sapn.gatewayserver.ServerThread;
//import com.shockfish.sapn.gatewayserver.SocketServerManager;

public class OscopeDataCaptureServer {

    private ServerSocket oscopeServerSocket;

    public OscopeDataCaptureServer(int port) throws Exception {
         
        try {
            //InetAddress addressReceiver = InetAddress.getLocalHost();

            oscopeServerSocket = new ServerSocket(port);
            // not so nice exception handling...
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void close() {
        try {
            oscopeServerSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void start() {

        while (true) {

            Socket clientSocket;
            OscopeDataCaptureServerThread serverThread;
            try {
                System.out.println("Waiting for remote connection");
                clientSocket = oscopeServerSocket.accept();
                serverThread = new OscopeDataCaptureServerThread(clientSocket);
                //Thread thread = new Thread(serverThread);
                serverThread.start();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }

    public static void main(String args[]) throws Exception {
        OscopeDataCaptureServer server = new OscopeDataCaptureServer((new Integer(
                args[0])).intValue());
        server.start();

    }

}

--- NEW FILE: OscopeDataCaptureServerThread.java ---
package com.shockfish.tinyos.apps.demo;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import java.util.logging.Logger;



public class OscopeDataCaptureServerThread extends Thread {

    // lazy import from the TC65 code tree, ProtocolGateway
    protected final int NEW_VALUE = 60;
    private Socket socket;
    private DataInputStream in;
    private DataOutputStream out;



    public OscopeDataCaptureServerThread(Socket socket)  throws IOException {

        try {
            this.socket = socket;
            in = new DataInputStream(socket.getInputStream());
            //out = new DataOutputStream(socket.getOutputStream());
        } catch (IOException e) {
            throw e;
        }
    }

    public void run() {
        int packetCount = 0;
        //long depart = Calendar.getInstance().getTimeInMillis();
        try {
            String idBaseStation = in.readUTF();
            System.out.println("*** ID Basestation: " + idBaseStation);
            long timeStampBaseStation = in.readLong();
            System.out.println("*** Timestamp Basestation: "+timeStampBaseStation);
            // read a packet as long as new_value is received
            while (in.readUnsignedByte() == NEW_VALUE) {
                ++packetCount;
                byte[] data = new byte[OscopeMsg.DEFAULT_MESSAGE_SIZE];
                OscopeMsg msg;
                in.read(data, 0, OscopeMsg.DEFAULT_MESSAGE_SIZE);
                msg = new OscopeMsg();
                msg.dataSet(data);
                System.out.println(msg.toString());
            }
            this.close();
        } catch (Exception e) {
            e.printStackTrace();
            this.close();
        }
    }

    public void close() {
        try {
            in.close();
            //out.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



More information about the Tinyos-contrib-commits mailing list