693ae8ba8f4a7b97f1accace1bda3cbfc6fc22d3
[eltron.git] / src / edu / berkeley / cs / obits / AtmelSerial.java
1 package edu.berkeley.cs.obits;
2
3 import edu.berkeley.cs.obits.device.atmel.*;
4 import org.ibex.util.*;
5 import java.io.*;
6 import java.util.*;
7 import gnu.io.*;
8
9 public class AtmelSerial {
10
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());
16         }
17         return new RXTXPort("/dev/cu.usbserial-FTBUODP4");
18     }
19
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();
26         int count = 0;
27         byte[] b = InputStreamToByteArray.convert(System.in);
28         PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
29         /*
30         pw.println("Y38,N,8,1");
31         pw.flush();
32         sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
33
34         pw.println("GI");
35         pw.flush();
36         */
37         pw.println("OD");
38         pw.println("N");
39         pw.println("D14");
40         pw.println("S1");
41         pw.println("Q609,24");
42         pw.println("q754");
43         //pw.println("R0,0");
44
45         int len = 228;
46         pw.println("GK\"IMG\"");
47         pw.println("GM\"IMG\""+len);
48         System.out.println("flushing");
49         pw.flush();
50         System.out.println("flushed");
51         DataOutputStream dos = new DataOutputStream(out);
52         
53         dos.flush();
54
55         /*
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\"");
65         */
66         pw.println("GG0,0,\"IMG\"");
67         pw.println("P1");
68         pw.flush();
69         /*
70         */
71         //Log.debug(this, "consuming any leftover data on the serial port");
72
73         /*
74         AvrDrone device = new AvrDrone(detectObitsPort());
75         int count = 0;
76         try {
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));
82                 count++;
83                 if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets");
84             }
85             device.flush();
86             long end = System.currentTimeMillis();
87             Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
88             System.exit(0);
89         } catch (Exception e) { e.printStackTrace(); }
90         */
91         System.exit(0);
92     }
93
94 }