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/] [examples/] [MD5GUI.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
package edu.byu.cc.plieber.fpgaenet.examples;
2
import java.io.IOException;
3
import java.net.InetAddress;
4
import java.util.ArrayList;
5
 
6
import com.trolltech.qt.gui.*;
7
import com.trolltech.qt.gui.QSizePolicy.Policy;
8
 
9
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
10
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
11
import edu.byu.cc.plieber.util.StringUtil;
12
 
13
public class MD5GUI extends QWidget{
14
 
15
    public static void main(String[] args) {
16
        QApplication.initialize(args);
17
 
18
        MD5GUI testMD5GUI = new MD5GUI(null);
19
        testMD5GUI.show();
20
 
21
        QApplication.exec();
22
 
23
        testMD5GUI.tearDown();
24
    }
25
 
26
    private QVBoxLayout mainLayout;
27
    private QHBoxLayout formatLayout;
28
 
29
    private QRadioButton radASCII;
30
    private QRadioButton radHex;
31
 
32
    private QLineEdit txtRead;
33
    private QPushButton btnCalculate;
34
    private QLineEdit txtResult;
35
 
36
    public MD5GUI(QWidget parent){
37
        super(parent);
38
        setWindowTitle("FPGA MD5 Calculator");
39
        makeConnections();
40
        createWidgets();
41
        connectSignalsAndSlots();
42
    }
43
 
44
    FCPProtocol fcpProtocol;
45
 
46
        private void makeConnections() {
47
                try {
48
                        fcpProtocol = new FCPProtocol();
49
                        fcpProtocol.connect(InetAddress.getByName("10.0.1.42"));
50
                        while(!fcpProtocol.isConnected());
51
                } catch (IOException e) {
52
                        return;
53
                }
54
        }
55
 
56
        private void createWidgets() {
57
                mainLayout = new QVBoxLayout(this);
58
                this.setLayout(mainLayout);
59
                formatLayout = new QHBoxLayout();
60
                mainLayout.addLayout(formatLayout);
61
                radASCII = new QRadioButton("ASCII");
62
                radASCII.setChecked(true);
63
                radHex = new QRadioButton("Hex");
64
                formatLayout.addWidget(radASCII);
65
                formatLayout.addWidget(radHex);
66
                txtRead = new QLineEdit();
67
                btnCalculate = new QPushButton("Calculate");
68
                btnCalculate.setSizePolicy(new QSizePolicy(Policy.Maximum, Policy.Maximum));
69
                txtResult = new QLineEdit();
70
                mainLayout.addWidget(txtRead);
71
                mainLayout.addWidget(btnCalculate);
72
                mainLayout.addWidget(txtResult);
73
 
74
        }
75
 
76
        private void connectSignalsAndSlots() {
77
                btnCalculate.clicked.connect(this, "calculate()");
78
        }
79
 
80
        @SuppressWarnings("unused")
81
        private void calculate() {
82
                String text = txtRead.text();
83
                ArrayList<Byte> pass;
84
                long len = 0;
85
                if (radASCII.isChecked()) {
86
                        pass = StringUtil.stringToByteList(text);
87
                        len = text.length();
88
                }
89
                else {
90
                        String[] tokens = text.split(" ");
91
                        pass = new ArrayList<Byte>();
92
                        for (String bytestr : tokens) {
93
                                pass.add((byte) Integer.parseInt(bytestr, 16));
94
                        }
95
                        len = pass.size();
96
                }
97
                pass.add(new Byte((byte)0x80));
98
                while (pass.size()*8 % 512 != 448) {
99
                        pass.add(new Byte((byte)0x00));
100
                }
101
                len = len * 8;
102
                pass.add(new Byte((byte)((len) & 0xff)));
103
                pass.add(new Byte((byte)((len >> 8) & 0xff)));
104
                pass.add(new Byte((byte)((len >> 16) & 0xff)));
105
                pass.add(new Byte((byte)((len >> 24) & 0xff)));
106
                pass.add(new Byte((byte)((len >> 32) & 0xff)));
107
                pass.add(new Byte((byte)((len >> 40) & 0xff)));
108
                pass.add(new Byte((byte)((len >> 48) & 0xff)));
109
                pass.add(new Byte((byte)((len >> 56) & 0xff)));
110
                try {
111
                        fcpProtocol.send(6, pass, pass.size());
112
                        fcpProtocol.sendDataRequest(6, 16);
113
                } catch (FCPException e) {
114
                        // TODO Auto-generated catch block
115
                        e.printStackTrace();
116
                }
117
                byte[] bytes = fcpProtocol.getDataResponse();
118
                txtResult.clear();
119
                txtResult.setText(StringUtil.arrayToHexString(bytes));
120
        }
121
 
122
        public void tearDown() {
123
                fcpProtocol.disconnect();
124
        }
125
}

powered by: WebSVN 2.1.0

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