6c3ee4f3b2828eb0896bea890a7a8832dea45081
[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 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         SerialPort ret = new RXTXPort("/dev/cu.usbserial-FTCBWI2P");
18         Log.info(AtmelSerial.class, "returning " + ret);
19         return ret;
20     }
21
22     public static void main(String[] s) throws Exception {
23         AvrDrone device = new AvrDrone(detectObitsPort());
24         int count = 0;
25         try {
26             long begin = System.currentTimeMillis();
27             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
28             for(String str = br.readLine(); str != null; str = br.readLine()) {
29                 long foo = Long.parseLong(str, 16);
30                 device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >>  8), (int)(foo >>  0));
31                 count++;
32                 if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets");
33             }
34             device.flush();
35             long end = System.currentTimeMillis();
36             Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
37             System.exit(0);
38         } catch (Exception e) { e.printStackTrace(); }
39     }
40
41 }