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

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.core.QModelIndex;
7
import com.trolltech.qt.core.Qt.DockWidgetArea;
8
import com.trolltech.qt.gui.*;
9
import com.trolltech.qt.gui.QAbstractItemView.SelectionMode;
10
import com.trolltech.qt.gui.QBoxLayout.Direction;
11
 
12
import edu.byu.cc.plieber.fpgaenet.debug.IcapReadback;
13
import edu.byu.cc.plieber.fpgaenet.debug.LogicalMapping;
14
import edu.byu.cc.plieber.fpgaenet.debug.llparse.LatchRBEntry;
15
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
16
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
17
import edu.byu.cc.plieber.fpgaenet.icapif.IcapInterface;
18
import edu.byu.cc.plieber.fpgaenet.icapif.IcapTools;
19
 
20
public class SignalMonitor extends QMainWindow{
21
 
22
        private QMenu fileMenu;
23
        private QMenu helpMenu;
24
 
25
        private QAction openLL;
26
        private QAction exitAct;
27
        private QAction aboutAct;
28
        private QAction aboutQtJambiAct;
29
 
30
        // Widgets
31
        private QLabel netLabel;
32
        private QLineEdit netValue;
33
        private QPushButton buttonGetValue;
34
 
35
        // Model/Views
36
        private QListView netListView;
37
        private QTableView netTableView;
38
        private NetListModel netListModel;
39
        private NetValueModel netValueModel;
40
        QSortFilterProxyModel tableProxyModel;
41
        QSortFilterProxyModel listProxyModel;
42
 
43
        // Connections
44
        FCPProtocol fcpProtocol;
45
        IcapInterface icapif;
46
        IcapTools icapTools;
47
        IcapReadback icapReadback;
48
        LatchRBEntry currentEntry;
49
 
50
        public static void main(String[] args) {
51
                QApplication.initialize(args);
52
 
53
                SignalMonitor signalMonitorGUI = new SignalMonitor(null);
54
                signalMonitorGUI.show();
55
 
56
                QApplication.exec();
57
 
58
                signalMonitorGUI.tearDown();
59
        }
60
 
61
        public  void tearDown() {
62
                fcpProtocol.disconnect();
63
        }
64
 
65
        public SignalMonitor(QWidget parent) {
66
                super(parent);
67
                setWindowTitle("Signal Monitor");
68
                createActions();
69
                createMenus();
70
                createWidgets();
71
                setupConnections();
72
                connectSignals();
73
        }
74
 
75
        private void setupConnections() {
76
                try {
77
                        fcpProtocol = new FCPProtocol();
78 7 peteralieb
                        fcpProtocol.connect(InetAddress.getByName("10.0.1.42"), 0x3001);
79 2 peteralieb
                } catch (IOException e) {
80
                        return;
81
                }
82
                icapif = new IcapInterface(fcpProtocol);
83
                icapTools = new IcapTools(icapif);
84
                icapReadback = new IcapReadback(icapTools);
85
                while(!fcpProtocol.isConnected());
86 7 peteralieb
                try {
87
                        icapTools.synchIcap();
88
                } catch (FCPException e) {
89
                        // TODO Auto-generated catch block
90
                        e.printStackTrace();
91
                }
92 2 peteralieb
        }
93
 
94
        private void createActions() {
95
                openLL = new QAction(tr("&Open LL File"), this);
96
                openLL.setShortcut(tr("Ctrl+O"));
97
                openLL.setStatusTip(tr("Open new LL file"));
98
                openLL.triggered.connect(this, "openLL()");
99
 
100
                exitAct = new QAction(tr("E&xit"), this);
101
                exitAct.setShortcut(tr("Ctrl+Q"));
102
                exitAct.setStatusTip(tr("Exit the application"));
103
                exitAct.triggered.connect(this, "close()");
104
 
105
                aboutAct = new QAction(tr("&About"), this);
106
                aboutAct.setStatusTip(tr("Show the application's About box"));
107
                aboutAct.triggered.connect(this, "about()");
108
 
109
                aboutQtJambiAct = new QAction(tr("About &Qt Jambi"), this);
110
                aboutQtJambiAct.setStatusTip(tr("Show the Qt Jambi's About box"));
111
                aboutQtJambiAct.triggered.connect(QApplication.instance(), "aboutQtJambi()");
112
        }
113
 
114
        private void createMenus() {
115
                fileMenu = menuBar().addMenu(tr("&File"));
116
                fileMenu.addAction(openLL);
117
                fileMenu.addAction(exitAct);
118
 
119
                helpMenu = menuBar().addMenu(tr("&Help"));
120
                helpMenu.addAction(aboutAct);
121
                helpMenu.addAction(aboutQtJambiAct);
122
        }
123
 
124
        private void createWidgets() {
125
                // Left Dock Net List
126
                netListView = new QListView(this);
127
                netListView.setSelectionMode(SelectionMode.ExtendedSelection);
128
                QDockWidget dockWidget = new QDockWidget(tr("Net List"), this);
129
                dockWidget.setAllowedAreas(DockWidgetArea.LeftDockWidgetArea);
130
                dockWidget.setWidget(netListView);
131
                addDockWidget(DockWidgetArea.LeftDockWidgetArea, dockWidget);
132
 
133
                // Main area Frame -------------------------------------------------
134
                QFrame mainFrame = new QFrame(this);
135
                setCentralWidget(mainFrame);
136
                netTableView = new QTableView(mainFrame);
137
                QVBoxLayout mainLayout = new QVBoxLayout(mainFrame);
138
                mainLayout.addWidget(netTableView);
139
                buttonGetValue = new QPushButton(tr("Get Value"));
140
                buttonGetValue.clicked.connect(this, "getNetValues()");
141
                mainLayout.addWidget(buttonGetValue);
142
                mainFrame.setLayout(mainLayout);
143
        }
144
 
145
        private void connectSignals() {
146
                netListView.doubleClicked.connect(this, "openStatusWidget(QModelIndex)");
147
        }
148
 
149
        protected void openLL() {
150
                String fName = QFileDialog.getOpenFileName(this, tr("Open LL File"), "", new QFileDialog.Filter(
151
                                tr("LL Files (*.ll *.LL)")));
152 7 peteralieb
                if (fName == null || fName.compareTo("") == 0) return;
153 2 peteralieb
                LogicalMapping llMapping = new LogicalMapping(fName);
154
                netListModel = new NetListModel(llMapping);
155
                listProxyModel = new QSortFilterProxyModel(this);
156
                listProxyModel.setSourceModel(netListModel);
157
                listProxyModel.sort(0);
158
                netListView.setModel(listProxyModel);
159
                netValueModel = new NetValueModel(new ArrayList<LatchRBEntry>(), icapReadback);
160
                tableProxyModel = new QSortFilterProxyModel(this);
161
                tableProxyModel.setSourceModel(netValueModel);
162
                netTableView.setModel(tableProxyModel);
163
                netTableView.setSelectionMode(SelectionMode.SingleSelection);
164
                netListView.selectionModel().selectionChanged.connect(this,
165
                                "netSelectionChanged(QItemSelection,QItemSelection)");
166
        }
167
 
168
        protected void about() {
169
                QMessageBox.information(this, "Info", "It's your turn now :-)");
170
        }
171
 
172
        protected void openStatusWidget(QModelIndex index) {
173
                QWidget statusWidget = new QWidget();
174
                QLayout layout = new QBoxLayout(Direction.LeftToRight);
175
                layout.addWidget(new QLabel(tr(listProxyModel.data(index).toString()), statusWidget));
176
                statusWidget.setLayout(layout);
177
                statusWidget.setWindowTitle(tr("Net Status"));
178
                statusWidget.show();
179
        }
180
 
181
        protected void filterTableView(QModelIndex index) {
182
                //tableProxyModel.setFilterFixedString(listProxyModel.data(index).toString());
183
        }
184
 
185
        protected void netSelectionChanged(QItemSelection deselected, QItemSelection selected) {
186
                ArrayList<LatchRBEntry> entries = new ArrayList<LatchRBEntry>();
187
                for (QModelIndex index : netListView.selectionModel().selection().indexes()) {
188
                        entries.add(netListModel.getEntry(listProxyModel.mapToSource(index)));
189
                }
190
                netValueModel.replaceContents(entries);
191
                tableProxyModel.sort(0);
192
        }
193
 
194
        protected void getNetValues() {
195
                try {
196
                        netValueModel.updateValues();
197
                        tableProxyModel.sort(0);
198
                } catch (FCPException e) {
199
                        QMessageBox.critical(this, "FCP Error", "Error during FCP communication, connection closed");
200
                        this.fcpProtocol.disconnect();
201
                        this.close();
202
                }
203
        }
204
}

powered by: WebSVN 2.1.0

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