X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fobits%2Fdevice%2Fatmel%2FAvrDrone.java;h=7860ad69206e26bfba387b7deda011c7b58f989a;hb=bb3326dd8253c36b342063dbbd1c24ef866c37b9;hp=5e5489b7a0a7ccc3e728c79f4b21e1b6479c2cef;hpb=cddd782397e118024c4b428263f969c57c0c2c29;p=slipway.git diff --git a/src/edu/berkeley/obits/device/atmel/AvrDrone.java b/src/edu/berkeley/obits/device/atmel/AvrDrone.java index 5e5489b..7860ad6 100644 --- a/src/edu/berkeley/obits/device/atmel/AvrDrone.java +++ b/src/edu/berkeley/obits/device/atmel/AvrDrone.java @@ -30,23 +30,28 @@ public class AvrDrone extends AtmelDevice { } private void init() throws IOException { - //Log.debug(this, "waiting for device to identify itself"); - /* - if (in.readByte() != (byte)'O') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'B') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'I') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'T') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'S') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'\n') throw new RuntimeException("didn't get the proper signature"); - */ - out.write(0); byte[] bytes = new byte[6]; - for(int i=0; i<6; i++) { - bytes[i] = in.readByte(); - //System.out.println("got " + (i+1) + " header bytes: " + (bytes[i] & 0xff) + " '" + ((char)bytes[i]) + "'"); - // FIXME + int i=0; + + out.write(0); + out.flush(); + + // read any crap that might be left in the buffer + while(true) { + System.arraycopy(bytes, 1, bytes, 0, 5); + bytes[5] = in.readByte(); + i++; + System.out.print("\rsignature: read \"" + new String(bytes) + "\" "); + if (bytes[0] == (byte)'O' && + bytes[1] == (byte)'B' && + bytes[2] == (byte)'I' && + bytes[3] == (byte)'T' && + bytes[4] == (byte)'S') { + System.out.println("\rsignature: got proper signature "); + break; + } } - //Log.info(this, "device correctly identified itself; ready for operation"); + } public synchronized void scanFPGA(boolean on) throws DeviceException {