| 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 | 
          | 
          | 
                                 fcpProtocol.connect(InetAddress.getByName("192.168.1.222"), 0x3001);
  | 
      
      
         | 79 | 
          | 
          | 
                         } 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 | 
          | 
          | 
                         icapTools.synchIcap();
  | 
      
      
         | 87 | 
          | 
          | 
                 }
  | 
      
      
         | 88 | 
          | 
          | 
          
  | 
      
      
         | 89 | 
          | 
          | 
                 private void createActions() {
  | 
      
      
         | 90 | 
          | 
          | 
                         openLL = new QAction(tr("&Open LL File"), this);
  | 
      
      
         | 91 | 
          | 
          | 
                         openLL.setShortcut(tr("Ctrl+O"));
  | 
      
      
         | 92 | 
          | 
          | 
                         openLL.setStatusTip(tr("Open new LL file"));
  | 
      
      
         | 93 | 
          | 
          | 
                         openLL.triggered.connect(this, "openLL()");
  | 
      
      
         | 94 | 
          | 
          | 
          
  | 
      
      
         | 95 | 
          | 
          | 
                         exitAct = new QAction(tr("E&xit"), this);
  | 
      
      
         | 96 | 
          | 
          | 
                         exitAct.setShortcut(tr("Ctrl+Q"));
  | 
      
      
         | 97 | 
          | 
          | 
                         exitAct.setStatusTip(tr("Exit the application"));
  | 
      
      
         | 98 | 
          | 
          | 
                         exitAct.triggered.connect(this, "close()");
  | 
      
      
         | 99 | 
          | 
          | 
          
  | 
      
      
         | 100 | 
          | 
          | 
                         aboutAct = new QAction(tr("&About"), this);
  | 
      
      
         | 101 | 
          | 
          | 
                         aboutAct.setStatusTip(tr("Show the application's About box"));
  | 
      
      
         | 102 | 
          | 
          | 
                         aboutAct.triggered.connect(this, "about()");
  | 
      
      
         | 103 | 
          | 
          | 
          
  | 
      
      
         | 104 | 
          | 
          | 
                         aboutQtJambiAct = new QAction(tr("About &Qt Jambi"), this);
  | 
      
      
         | 105 | 
          | 
          | 
                         aboutQtJambiAct.setStatusTip(tr("Show the Qt Jambi's About box"));
  | 
      
      
         | 106 | 
          | 
          | 
                         aboutQtJambiAct.triggered.connect(QApplication.instance(), "aboutQtJambi()");
  | 
      
      
         | 107 | 
          | 
          | 
                 }
  | 
      
      
         | 108 | 
          | 
          | 
          
  | 
      
      
         | 109 | 
          | 
          | 
                 private void createMenus() {
  | 
      
      
         | 110 | 
          | 
          | 
                         fileMenu = menuBar().addMenu(tr("&File"));
  | 
      
      
         | 111 | 
          | 
          | 
                         fileMenu.addAction(openLL);
  | 
      
      
         | 112 | 
          | 
          | 
                         fileMenu.addAction(exitAct);
  | 
      
      
         | 113 | 
          | 
          | 
          
  | 
      
      
         | 114 | 
          | 
          | 
                         helpMenu = menuBar().addMenu(tr("&Help"));
  | 
      
      
         | 115 | 
          | 
          | 
                         helpMenu.addAction(aboutAct);
  | 
      
      
         | 116 | 
          | 
          | 
                         helpMenu.addAction(aboutQtJambiAct);
  | 
      
      
         | 117 | 
          | 
          | 
                 }
  | 
      
      
         | 118 | 
          | 
          | 
          
  | 
      
      
         | 119 | 
          | 
          | 
                 private void createWidgets() {
  | 
      
      
         | 120 | 
          | 
          | 
                         // Left Dock Net List
  | 
      
      
         | 121 | 
          | 
          | 
                         netListView = new QListView(this);
  | 
      
      
         | 122 | 
          | 
          | 
                         netListView.setSelectionMode(SelectionMode.ExtendedSelection);
  | 
      
      
         | 123 | 
          | 
          | 
                         QDockWidget dockWidget = new QDockWidget(tr("Net List"), this);
  | 
      
      
         | 124 | 
          | 
          | 
                         dockWidget.setAllowedAreas(DockWidgetArea.LeftDockWidgetArea);
  | 
      
      
         | 125 | 
          | 
          | 
                         dockWidget.setWidget(netListView);
  | 
      
      
         | 126 | 
          | 
          | 
                         addDockWidget(DockWidgetArea.LeftDockWidgetArea, dockWidget);
  | 
      
      
         | 127 | 
          | 
          | 
          
  | 
      
      
         | 128 | 
          | 
          | 
                         // Main area Frame -------------------------------------------------
  | 
      
      
         | 129 | 
          | 
          | 
                         QFrame mainFrame = new QFrame(this);
  | 
      
      
         | 130 | 
          | 
          | 
                         setCentralWidget(mainFrame);
  | 
      
      
         | 131 | 
          | 
          | 
                         netTableView = new QTableView(mainFrame);
  | 
      
      
         | 132 | 
          | 
          | 
                         QVBoxLayout mainLayout = new QVBoxLayout(mainFrame);
  | 
      
      
         | 133 | 
          | 
          | 
                         mainLayout.addWidget(netTableView);
  | 
      
      
         | 134 | 
          | 
          | 
                         buttonGetValue = new QPushButton(tr("Get Value"));
  | 
      
      
         | 135 | 
          | 
          | 
                         buttonGetValue.clicked.connect(this, "getNetValues()");
  | 
      
      
         | 136 | 
          | 
          | 
                         mainLayout.addWidget(buttonGetValue);
  | 
      
      
         | 137 | 
          | 
          | 
                         mainFrame.setLayout(mainLayout);
  | 
      
      
         | 138 | 
          | 
          | 
                 }
  | 
      
      
         | 139 | 
          | 
          | 
          
  | 
      
      
         | 140 | 
          | 
          | 
                 private void connectSignals() {
  | 
      
      
         | 141 | 
          | 
          | 
                         netListView.doubleClicked.connect(this, "openStatusWidget(QModelIndex)");
  | 
      
      
         | 142 | 
          | 
          | 
                 }
  | 
      
      
         | 143 | 
          | 
          | 
          
  | 
      
      
         | 144 | 
          | 
          | 
                 protected void openLL() {
  | 
      
      
         | 145 | 
          | 
          | 
                         String fName = QFileDialog.getOpenFileName(this, tr("Open LL File"), "", new QFileDialog.Filter(
  | 
      
      
         | 146 | 
          | 
          | 
                                         tr("LL Files (*.ll *.LL)")));
  | 
      
      
         | 147 | 
          | 
          | 
                         LogicalMapping llMapping = new LogicalMapping(fName);
  | 
      
      
         | 148 | 
          | 
          | 
                         netListModel = new NetListModel(llMapping);
  | 
      
      
         | 149 | 
          | 
          | 
                         listProxyModel = new QSortFilterProxyModel(this);
  | 
      
      
         | 150 | 
          | 
          | 
                         listProxyModel.setSourceModel(netListModel);
  | 
      
      
         | 151 | 
          | 
          | 
                         listProxyModel.sort(0);
  | 
      
      
         | 152 | 
          | 
          | 
                         netListView.setModel(listProxyModel);
  | 
      
      
         | 153 | 
          | 
          | 
                         netValueModel = new NetValueModel(new ArrayList<LatchRBEntry>(), icapReadback);
  | 
      
      
         | 154 | 
          | 
          | 
                         tableProxyModel = new QSortFilterProxyModel(this);
  | 
      
      
         | 155 | 
          | 
          | 
                         tableProxyModel.setSourceModel(netValueModel);
  | 
      
      
         | 156 | 
          | 
          | 
                         netTableView.setModel(tableProxyModel);
  | 
      
      
         | 157 | 
          | 
          | 
                         netTableView.setSelectionMode(SelectionMode.SingleSelection);
  | 
      
      
         | 158 | 
          | 
          | 
                         netListView.selectionModel().selectionChanged.connect(this,
  | 
      
      
         | 159 | 
          | 
          | 
                                         "netSelectionChanged(QItemSelection,QItemSelection)");
  | 
      
      
         | 160 | 
          | 
          | 
                 }
  | 
      
      
         | 161 | 
          | 
          | 
          
  | 
      
      
         | 162 | 
          | 
          | 
                 protected void about() {
  | 
      
      
         | 163 | 
          | 
          | 
                         QMessageBox.information(this, "Info", "It's your turn now :-)");
  | 
      
      
         | 164 | 
          | 
          | 
                 }
  | 
      
      
         | 165 | 
          | 
          | 
          
  | 
      
      
         | 166 | 
          | 
          | 
                 protected void openStatusWidget(QModelIndex index) {
  | 
      
      
         | 167 | 
          | 
          | 
                         QWidget statusWidget = new QWidget();
  | 
      
      
         | 168 | 
          | 
          | 
                         QLayout layout = new QBoxLayout(Direction.LeftToRight);
  | 
      
      
         | 169 | 
          | 
          | 
                         layout.addWidget(new QLabel(tr(listProxyModel.data(index).toString()), statusWidget));
  | 
      
      
         | 170 | 
          | 
          | 
                         statusWidget.setLayout(layout);
  | 
      
      
         | 171 | 
          | 
          | 
                         statusWidget.setWindowTitle(tr("Net Status"));
  | 
      
      
         | 172 | 
          | 
          | 
                         statusWidget.show();
  | 
      
      
         | 173 | 
          | 
          | 
                 }
  | 
      
      
         | 174 | 
          | 
          | 
          
  | 
      
      
         | 175 | 
          | 
          | 
                 protected void filterTableView(QModelIndex index) {
  | 
      
      
         | 176 | 
          | 
          | 
                         //tableProxyModel.setFilterFixedString(listProxyModel.data(index).toString());
  | 
      
      
         | 177 | 
          | 
          | 
                 }
  | 
      
      
         | 178 | 
          | 
          | 
          
  | 
      
      
         | 179 | 
          | 
          | 
                 protected void netSelectionChanged(QItemSelection deselected, QItemSelection selected) {
  | 
      
      
         | 180 | 
          | 
          | 
                         ArrayList<LatchRBEntry> entries = new ArrayList<LatchRBEntry>();
  | 
      
      
         | 181 | 
          | 
          | 
                         for (QModelIndex index : netListView.selectionModel().selection().indexes()) {
  | 
      
      
         | 182 | 
          | 
          | 
                                 entries.add(netListModel.getEntry(listProxyModel.mapToSource(index)));
  | 
      
      
         | 183 | 
          | 
          | 
                         }
  | 
      
      
         | 184 | 
          | 
          | 
                         netValueModel.replaceContents(entries);
  | 
      
      
         | 185 | 
          | 
          | 
                         tableProxyModel.sort(0);
  | 
      
      
         | 186 | 
          | 
          | 
                 }
  | 
      
      
         | 187 | 
          | 
          | 
          
  | 
      
      
         | 188 | 
          | 
          | 
                 protected void getNetValues() {
  | 
      
      
         | 189 | 
          | 
          | 
                         try {
  | 
      
      
         | 190 | 
          | 
          | 
                                 netValueModel.updateValues();
  | 
      
      
         | 191 | 
          | 
          | 
                                 tableProxyModel.sort(0);
  | 
      
      
         | 192 | 
          | 
          | 
                         } catch (FCPException e) {
  | 
      
      
         | 193 | 
          | 
          | 
                                 QMessageBox.critical(this, "FCP Error", "Error during FCP communication, connection closed");
  | 
      
      
         | 194 | 
          | 
          | 
                                 this.fcpProtocol.disconnect();
  | 
      
      
         | 195 | 
          | 
          | 
                                 this.close();
  | 
      
      
         | 196 | 
          | 
          | 
                         }
  | 
      
      
         | 197 | 
          | 
          | 
                 }
  | 
      
      
         | 198 | 
          | 
          | 
         }
  |