checkpoint
[slipway.git] / src / edu / berkeley / obits / AtmelSerial.java
1 package edu.berkeley.obits;
2
3 import edu.berkeley.obits.device.atmel.*;
4 import org.ibex.util.*;
5 import org.ibex.graphics.Picture;
6 import java.io.*;
7 import java.util.*;
8 import gnu.io.*;
9
10 public class AtmelSerial {
11
12     public static SerialPort detectObitsPort() throws Exception {
13         Enumeration e = CommPortIdentifier.getPortIdentifiers();
14         while(e.hasMoreElements()) {
15             CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
16             Log.info(AtmelSerial.class, "trying " + cpi.getName());
17         }
18         SerialPort ret = new RXTXPort("/dev/cu.usbserial-FTCBWI2P");
19         Log.info(AtmelSerial.class, "returning " + ret);
20         return ret;
21     }
22
23     public static void main(String[] s) throws Exception {
24         AvrDrone device = new AvrDrone(detectObitsPort());
25         int count = 0;
26         try {
27             long begin = System.currentTimeMillis();
28             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
29             for(String str = br.readLine(); str != null; str = br.readLine()) {
30                 long foo = Long.parseLong(str, 16);
31                 device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >>  8), (int)(foo >>  0));
32                 count++;
33                 if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets");
34             }
35             device.flush();
36             long end = System.currentTimeMillis();
37             Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
38             System.exit(0);
39         } catch (Exception e) { e.printStackTrace(); }
40     }
41
42 }