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 return new RXTXPort("/dev/cu.usbserial-FTBUODP4");
20 public static void main(String[] s) throws Exception {
21 SerialPort sp = detectObitsPort();
22 sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
23 sp.setFlowControlMode(sp.FLOWCONTROL_NONE);
24 OutputStream out = sp.getOutputStream();
25 InputStream in = sp.getInputStream();
27 byte[] b = InputStreamToByteArray.convert(System.in);
28 PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
30 pw.println("Y38,N,8,1");
32 sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
41 pw.println("Q609,24");
46 pw.println("GK\"IMG\"");
47 pw.println("GM\"IMG\""+len);
48 System.out.println("flushing");
50 System.out.println("flushed");
51 DataOutputStream dos = new DataOutputStream(out);
56 pw.println("A170,5,0,1,5,5,N,\"WORLDWIDE\"");
57 pw.println("LO5,230,765,10");
58 pw.println("A10,265,0,1,3,3,R,\"MODEL:\"");
59 pw.println("A280,265,0,1,3,3,N,\"Bar Code Printer\"");
60 pw.println("A10,340,0,1,3,3,R,\" CODE: \"");
61 pw.println("B280,340,0,3C,2,6,120,B,\"BCP-1234\"");
62 pw.println("LO5,520,765,10");
63 pw.println("A100,550,0,1,2,2,N,\"ISO9000 Made In USA\"");
64 pw.println("GG650,535,\"CE_5M\"");
66 pw.println("GG0,0,\"IMG\"");
71 //Log.debug(this, "consuming any leftover data on the serial port");
74 AvrDrone device = new AvrDrone(detectObitsPort());
77 long begin = System.currentTimeMillis();
78 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
79 for(String str = br.readLine(); str != null; str = br.readLine()) {
80 long foo = Long.parseLong(str, 16);
81 device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0));
83 if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets");
86 long end = System.currentTimeMillis();
87 Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
89 } catch (Exception e) { e.printStackTrace(); }