All pastes #476458 Raw Edit

Untitled

public java v1 · immutable
·published 2007-05-08 02:50 UTC
rendered paste body
package protocolo;import java.io.IOException;import java.io.InputStream;import java.nio.ByteBuffer;import serial.SerialConnection;/** * Classe que a todo instante está verificando o que está chegando/saindo * e dependendo do que for (mensagem ou arquivo) * faz o tratamento adequado. *  * @author Thomas Couto * @version 1.0 (06/05/2007 @ 20:26) */public class TrafficIO implements Runnable {		public TrafficIO(SerialConnection serialConnection) {		this.serialConnection = serialConnection;		new Thread(this).start();	}		public void run() {		try {			int b;			boolean recebendo = false;			is = serialConnection.getSerialPort().getInputStream();			while ((b = is.read()) != -1) {				if(((byte)b == INICIO_MENSAGEM) && (!recebendo)) {					System.out.println("é uma mensagem :)");					recebendo = true;				}			}		} catch (IOException e) {			e.printStackTrace();		}	}		public static final byte INICIO_ARQUIVO = (byte) 0xFF;	public static final byte FIM_ARQUIVO    = (byte) 0xFE;		public static final byte INICIO_MENSAGEM = (byte) 0xFD;	public static final byte FIM_MENSAGEM    = (byte) 0xFC;		private static InputStream is;		private ByteBuffer buf;	private Protocolo protocolo;	private SerialConnection serialConnection;}