OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [java/] [src/] [edu/] [byu/] [cc/] [plieber/] [fpgaenet/] [icapif/] [IcapInterfaceTest.java] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
/**
2
 *
3
 */
4
package edu.byu.cc.plieber.fpgaenet.icapif;
5
 
6
import java.io.BufferedReader;
7
import java.io.File;
8
import java.io.FileInputStream;
9
import java.io.FileNotFoundException;
10
import java.io.IOException;
11
import java.io.InputStream;
12
import java.io.InputStreamReader;
13
import java.net.InetAddress;
14
import java.util.ArrayList;
15
 
16
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
17
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
18
import edu.byu.cc.plieber.util.StringUtil;
19
 
20
/**
21
 * @author Peter Lieber
22
 *
23
 */
24
public class IcapInterfaceTest {
25
 
26
        /**
27
         * @param args
28
         */
29
        public static void main(String[] args) {
30
 
31
                if (args.length != 3) {
32
                        System.out.println("usage: IcapInterfaceTest <IP Address> <input file> <num to read>");
33
                        return;
34
                }
35
                int numToRead = Integer.parseInt(args[2]);
36
 
37
                FCPProtocol protocol = null;
38
 
39
                try {
40
                        protocol = new FCPProtocol();
41
                        protocol.connect(InetAddress.getByName(args[0]), 0x3001);
42
                } catch (IOException e) {
43
                        System.err.println("IO Error, Exiting...");
44
                        return;
45
                } finally {
46
                        if (protocol == null) {
47
                                System.err.println("Error creating FCP, Exiting...");
48
                                return;
49
                        }
50
                }
51
                while (!protocol.isConnected());
52
                IcapInterface icapif = new IcapInterface(protocol);
53
 
54
                File file = new File(args[1]);
55
                InputStream is = null;
56
                try {
57
                        is = new FileInputStream(file);
58
                } catch (FileNotFoundException e) {
59
                        // TODO Auto-generated catch block
60
                        e.printStackTrace();
61
                } finally {
62
                        if (is == null) {
63
                                System.err.println("input stream null");
64
                                return;
65
                        }
66
                }
67
                long length = file.length();
68
                byte[] bytes = new byte[(int)length];
69
                try {
70
                        is.read(bytes);
71
                } catch (IOException e) {
72
                        // TODO Auto-generated catch block
73
                        e.printStackTrace();
74
                        return;
75
                }
76
 
77
                try {
78
                        icapif.sendIcapData(bytes, (int) length);
79
                } catch (FCPException e1) {
80
                        // TODO Auto-generated catch block
81
                        e1.printStackTrace();
82
                }
83
 
84
                if (numToRead > 0) {
85
                        ArrayList<Byte> readBytes = null;
86
                        try {
87
                                icapif.requestIcapData(numToRead);
88
                                readBytes = icapif.receiveIcapData();
89
                        } catch (FCPException e) {
90
                                // TODO Auto-generated catch block
91
                                e.printStackTrace();
92
                        }
93
                        System.out.println("Data received from ICAP: \n" + StringUtil.listToString(readBytes));
94
                }
95
 
96
                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
97
                try {
98
                        in.readLine();
99
                } catch (IOException e) {
100
                        // TODO Auto-generated catch block
101
                        e.printStackTrace();
102
                }
103
                protocol.disconnect();
104
        }
105
 
106
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.