- public static class AvrDrone {
- final DataInputStream in;
- final DataOutputStream out;
- final SerialPort sp;
- public AvrDrone(SerialPort sp) throws IOException, UnsupportedCommOperationException, InterruptedException {
- this.sp = sp;
- sp.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
- sp.setFlowControlMode(sp.FLOWCONTROL_RTSCTS_OUT);
- this.out = new DataOutputStream(sp.getOutputStream());
- this.in = new DataInputStream(sp.getInputStream());
- while(in.available() > 0) in.read();
- reset();
- System.err.println("waiting...");
- 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");
- System.err.println("ready.");
- }
- public void reset() throws InterruptedException {
- sp.setDTR(true);
- Thread.sleep(500);
- sp.setDTR(false);
- Thread.sleep(3000);
- }
- public void mode4(int z, int y, int x, int d) throws IOException {
- out.writeByte(1);
- out.writeByte(z);
- out.writeByte(y);
- out.writeByte(x);
- out.writeByte(d);
- }
- public void flush() throws IOException {
- out.flush();
- }
- }
-
-