55502258e44c5dcae415dd2c624f41008b451f13
[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.Log;
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         AvrDrone device = new AvrDrone(detectObitsPort());
22         int count = 0;
23         try {
24             long begin = System.currentTimeMillis();
25             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
26             for(String str = br.readLine(); str != null; str = br.readLine()) {
27                 long foo = Long.parseLong(str, 16);
28                 device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >>  8), (int)(foo >>  0));
29                 count++;
30                 if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets");
31             }
32             device.flush();
33             long end = System.currentTimeMillis();
34             Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
35             System.exit(0);
36         } catch (Exception e) { e.printStackTrace(); }
37     }
38
39 }