1 package edu.berkeley.fleet.fpga;
3 import edu.berkeley.fleet.api.*;
7 import java.util.concurrent.*;
9 public class Client extends FleetProcess {
12 private BlockingQueue<Long> queue = new LinkedBlockingQueue<Long>();
14 public void invokeInstruction(Instruction i) {
15 throw new RuntimeException("not implemented");
18 public static long signExtend(long val) {
19 if ((val & (1L << 36)) != 0)
20 val = val | (0xffffffffffffffffL << 36);
24 public long readWord() {
26 throw new RuntimeException("this fleet has been terminated");
28 return signExtend(queue.take());
29 } catch (InterruptedException e) { throw new RuntimeException(e); }
32 protected void _terminate() {
35 } catch (Exception e) { e.printStackTrace(); }
38 public Client(String bitfile, byte[] program) throws IOException {
39 s = new Socket(InetAddress.getByName("bee441.megacz.com"), 3133);
40 OutputStream os = s.getOutputStream();
41 PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));
42 pw.print(Server.pass_string+" "+bitfile+"\n");
45 int numinstrs = (program.length / 6);
46 os.write((numinstrs >> (5*8)) & 0xff);
47 os.write((numinstrs >> (4*8)) & 0xff);
48 os.write((numinstrs >> (3*8)) & 0xff);
49 os.write((numinstrs >> (2*8)) & 0xff);
50 os.write((numinstrs >> (1*8)) & 0xff);
51 os.write((numinstrs >> (0*8)) & 0xff);
55 final InputStream is = s.getInputStream();
62 for(int i=0; i<6; i++) {
65 long val2 = (val & 0xffL);
66 val2 = val2 << (i * 8);
72 } catch (SocketException e) {
73 } catch (Exception e) { throw new RuntimeException(e);
74 } finally { terminate(); }
79 public static void main(String[] args) throws Exception {
80 ByteArrayOutputStream baos = new ByteArrayOutputStream();
81 byte[] buf = new byte[1024];
83 int numread = System.in.read(buf, 0, buf.length);
84 if (numread==-1) break;
85 baos.write(buf, 0, numread);
87 Client client = new Client(args.length==0 ? "main.bit" : args[0], baos.toByteArray());
89 long result = client.readWord();
90 System.err.print(result);
91 System.err.print(" 0x");
92 System.err.print(Long.toString(result, 16));