X-Git-Url: http://git.megacz.com/?p=eltron.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fcs%2Fobits%2FAtmelSerial.java;h=b43d0f9e09b4cf1986c7f4fad0ad188c01be32de;hp=08b4e488474bc8474ae7cf66f0213337ee908dfa;hb=1d9331b6f051b7aca130f39b7d9fec6332447d81;hpb=ce8d526b132c30e3d89c9551b9ed7b56aac9f066 diff --git a/src/edu/berkeley/cs/obits/AtmelSerial.java b/src/edu/berkeley/cs/obits/AtmelSerial.java index 08b4e48..b43d0f9 100644 --- a/src/edu/berkeley/cs/obits/AtmelSerial.java +++ b/src/edu/berkeley/cs/obits/AtmelSerial.java @@ -1,5 +1,7 @@ package edu.berkeley.cs.obits; +import edu.berkeley.cs.obits.device.atmel.*; +import org.ibex.util.*; import java.io.*; import java.util.*; import gnu.io.*; @@ -10,52 +12,96 @@ public class AtmelSerial { Enumeration e = CommPortIdentifier.getPortIdentifiers(); while(e.hasMoreElements()) { CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement(); - System.err.println("trying " + cpi.getName()); + Log.info(AtmelSerial.class, "trying " + cpi.getName()); } - return new RXTXPort("/dev/cu.usbserial-FTBUODP4"); + SerialPort ret = new RXTXPort("/dev/cu.usbserial-FTBUODP4"); + Log.info(AtmelSerial.class, "returning " + ret); + return ret; } - public static class AvrDrone { - final DataInputStream in; - final DataOutputStream out; - final SerialPort sp; - public AvrDrone(SerialPort sp) throws IOException, UnsupportedCommOperationException, InterruptedException { - this.sp = sp; - sp.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); - sp.setFlowControlMode(sp.FLOWCONTROL_RTSCTS_OUT); - this.out = new DataOutputStream(sp.getOutputStream()); - this.in = new DataInputStream(sp.getInputStream()); - while(in.available() > 0) in.read(); - reset(); - System.err.println("waiting..."); - if (in.readByte() != (byte)'O') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'B') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'I') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'T') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'S') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'\n') throw new RuntimeException("didn't get the proper signature"); - System.err.println("ready."); - } - public void reset() throws InterruptedException { - sp.setDTR(true); - Thread.sleep(500); - sp.setDTR(false); - Thread.sleep(3000); - } - public void mode4(int z, int y, int x, int d) throws IOException { - out.writeByte(1); - out.writeByte(z); - out.writeByte(y); - out.writeByte(x); - out.writeByte(d); - } - public void flush() throws IOException { - out.flush(); + public static void main(String[] s) throws Exception { + SerialPort sp = detectObitsPort(); + sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); + //sp.setFlowControlMode(sp.FLOWCONTROL_NONE); + OutputStream out = sp.getOutputStream(); + InputStream in = sp.getInputStream(); + int count = 0; + PrintWriter pw = new PrintWriter(new OutputStreamWriter(out)); + /* + pw.println("Y38,N,8,1"); + pw.flush(); + sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); + + pw.println("GI"); + pw.flush(); + */ + + pw.println(); + pw.flush(); + pw.println("^@"); + pw.println("^@"); + pw.println("^@"); + pw.flush(); + try { Thread.sleep(3000); } catch (Exception e) { } + + pw.println("GK\"IMG\""); + pw.println("GK\"IMG\""); + pw.println(); + pw.flush(); + try { Thread.sleep(1000); } catch (Exception e) { } + /* + pw.println("GI"); + pw.flush(); + */ + int[] data = new int[104 * 104]; + for(int i=0; i<104*104; i++) data[i] = 1; + for(int i=0; i<104; i++) data[i*104+i] = 0; + for(int i=0; i<104; i++) data[i*104+(104-i)] = 0; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PCX.dump(104, 104, data, new DataOutputStream(baos)); + byte[] outb = baos.toByteArray(); + int len = outb.length; + pw.println("GM\"IMG\""+len); + pw.flush(); + DataOutputStream dout = new DataOutputStream(out); + for(int i=0; i> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0)); count++; - if (count % 100 == 0) System.err.println("wrote " + count + " configuration octets"); + if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets"); } device.flush(); long end = System.currentTimeMillis(); - System.err.println("finished in " + ((end-begin)/1000) + "s"); + Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s"); System.exit(0); } catch (Exception e) { e.printStackTrace(); } + */ + System.exit(0); } }