1 package edu.berkeley.cs.obits;
3 import edu.berkeley.cs.obits.device.atmel.*;
4 import org.ibex.util.*;
9 public class AtmelSerial {
11 public static SerialPort detectObitsPort() throws Exception {
12 Enumeration e = CommPortIdentifier.getPortIdentifiers();
13 while(e.hasMoreElements()) {
14 CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
15 Log.info(AtmelSerial.class, "trying " + cpi.getName());
17 SerialPort ret = new RXTXPort("/dev/cu.usbserial-FTBUODP4");
18 Log.info(AtmelSerial.class, "returning " + ret);
22 public static void main(String[] s) throws Exception {
23 SerialPort sp = detectObitsPort();
24 sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
25 //sp.setFlowControlMode(sp.FLOWCONTROL_NONE);
26 OutputStream out = sp.getOutputStream();
27 InputStream in = sp.getInputStream();
29 PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
31 pw.println("Y38,N,8,1");
33 sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
45 try { Thread.sleep(3000); } catch (Exception e) { }
47 pw.println("GK\"IMG\"");
48 pw.println("GK\"IMG\"");
51 try { Thread.sleep(1000); } catch (Exception e) { }
56 int[] data = new int[104 * 104];
57 for(int i=0; i<104*104; i++) data[i] = 1;
58 for(int i=0; i<104; i++) data[i*104+i] = 0;
59 for(int i=0; i<104; i++) data[i*104+(104-i)] = 0;
60 ByteArrayOutputStream baos = new ByteArrayOutputStream();
61 PCX.dump(104, 104, data, new DataOutputStream(baos));
62 byte[] outb = baos.toByteArray();
63 int len = outb.length;
64 pw.println("GM\"IMG\""+len);
66 DataOutputStream dout = new DataOutputStream(out);
67 for(int i=0; i<len; i++) {
68 System.out.println("wrote " + i + "/"+outb.length);
69 dout.writeByte(outb[i]);
78 try { Thread.sleep(2000); } catch (Exception e) { }
85 pw.println("Q609,24");
88 pw.println("A170,5,0,1,5,5,N,\"WORLDWIDE\"");
89 pw.println("LO5,230,765,10");
90 pw.println("A10,265,0,1,3,3,R,\"MODEL:\"");
91 pw.println("A280,265,0,1,3,3,N,\"Bar Code Printer\"");
92 pw.println("A10,340,0,1,3,3,R,\" CODE: \"");
93 pw.println("B280,340,0,3C,2,6,120,B,\"BCP-1234\"");
94 pw.println("LO5,520,765,10");
95 pw.println("A100,550,0,1,2,2,N,\"ISO9000 Made In USA\"");
96 pw.println("GG0,0,\"IMG2\"");
102 //Log.debug(this, "consuming any leftover data on the serial port");
105 AvrDrone device = new AvrDrone(detectObitsPort());
108 long begin = System.currentTimeMillis();
109 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
110 for(String str = br.readLine(); str != null; str = br.readLine()) {
111 long foo = Long.parseLong(str, 16);
112 device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0));
114 if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets");
117 long end = System.currentTimeMillis();
118 Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
120 } catch (Exception e) { e.printStackTrace(); }