From 8ae2e32cbc2612c07dcead85f3206eb9b3c84dc4 Mon Sep 17 00:00:00 2001 From: Michael Carpenter Date: Sat, 23 Nov 2013 22:04:45 -0500 Subject: [PATCH] Addition of BenchTest Wizard, which starts/stops bench tests --- core/Wizards/BenchTest.qml | 507 ++++++++++++++++++++++++++++++ core/core.pro | 3 +- core/src/mainwindow.cpp | 17 +- lib/core/emscomms.h | 3 + plugins/freeems/freeemscomms.cpp | 70 ++++- plugins/freeems/freeemscomms.h | 3 + plugins/freeems/packet.h | 1 + plugins/freeems/packetdecoder.cpp | 4 +- 8 files changed, 602 insertions(+), 6 deletions(-) create mode 100644 core/Wizards/BenchTest.qml diff --git a/core/Wizards/BenchTest.qml b/core/Wizards/BenchTest.qml new file mode 100644 index 0000000..104998a --- /dev/null +++ b/core/Wizards/BenchTest.qml @@ -0,0 +1,507 @@ +// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5 +import QtQuick 1.1 + +Item { + width:800 + height:600 + Rectangle { + x:0 + y:0 + width: 800 + height: 600 + color: "grey" + Text { + x:10 + y:240 + color: "white" + text: "Events Per Cycle (1-255):" + } + Rectangle { + x:250 + y:240 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: eventspercycletext + anchors.fill:parent + color: "white" + text:"12" + } + } + } + Text { + x:370 + y:240 + color: "white" + text: "Number Of Cycles (0-65535):" + } + Rectangle { + x:600 + y:240 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: numberofcyclestext + anchors.fill:parent + color: "white" + text:"50" + } + } + } + Text { + x:10 + y:280 + color: "white" + text: "Ticks Per Event (0-65535):" + } + Rectangle { + x:250 + y:280 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: tickspereventtext + anchors.fill:parent + color: "white" + text:"10000" + } + } + } + Text { + x:10 + y:340 + color: "white" + text: "Events to Fire From (0-255):" + } + Rectangle { + x:250 + y:340 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: eventstofirefrom1 + anchors.fill:parent + color: "white" + text:"0" + } + } + } + + Rectangle { + x:250 + y:370 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: eventstofirefrom2 + anchors.fill:parent + color: "white" + text:"2" + } + } + } + + Rectangle { + x:250 + y:400 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: eventstofirefrom3 + anchors.fill:parent + color: "white" + text:"4" + } + } + } + + Rectangle { + x:250 + y:430 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: eventstofirefrom4 + anchors.fill:parent + color: "white" + text:"6" + } + } + } + + Rectangle { + x:250 + y:460 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: eventstofirefrom5 + anchors.fill:parent + color: "white" + text:"8" + } + } + } + + Rectangle { + x:250 + y:490 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: eventstofirefrom6 + anchors.fill:parent + color: "white" + text:"10" + } + } + } + + + Text { + x:370 + y:290 + color: "white" + text: "PW Source OR value (0-65535):" + } + Rectangle { + x:600 + y:290 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: sourcetext1 + anchors.fill:parent + color: "white" + text:"50000" + } + } + } + Rectangle { + x:600 + y:320 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: sourcetext2 + anchors.fill:parent + color: "white" + text:"50000" + } + } + } + Rectangle { + x:600 + y:350 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: sourcetext3 + anchors.fill:parent + color: "white" + text:"50000" + } + } + } + Rectangle { + x:600 + y:380 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: sourcetext4 + anchors.fill:parent + color: "white" + text:"50000" + } + } + } + Rectangle { + x:600 + y:410 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: sourcetext5 + anchors.fill:parent + color: "white" + text:"50000" + } + } + } + Rectangle { + x:600 + y:440 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: sourcetext6 + anchors.fill:parent + color: "white" + text:"50000" + } + } + } + + + Rectangle { + x: 10 + y: 10 + radius:5 + width:780 + height:220 + color: "white" + Rectangle { + x:5 + y:5 + width:770 + height:210 + radius:5 + color: "grey" + Text { + x:5 + y:5 + width:760 + height:200 + color:"white" + wrapMode: Text.WordWrap + //horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: "* Once you hit start, the ONLY way to stop the test is to clikc the \"Stop Test\" button. +* To determine how long your test will run, simply multiply the first three values together! +* To determine the duty cycle, divide the PW (if chosen explicitly) by the result of multiplying the \"Event Per \n\tCycle\" by \"Time Per Event\" together. +* Events To Fire equals to, or in excess of Events Per Cycle are considered off +* PW Source OR Value values have special meanings, 0 = OFF, 1 = RefPW, 2 = Dwell, higher = a literal PW. +* Time and PW literals are in 0.8us ticks, divide by 1250 for ms. +* PW = Pulse Width +* Please select appropriate values for your coils and/or injectors, then click start." + } + } + } + + Rectangle { + x:10 + y:550 + width:200 + height:30 + radius:5 + color:"white" + Rectangle { + x:5 + y:5 + width:190 + height:20 + radius:5 + color: "blue" + Text { + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: "Start" + MouseArea { + anchors.fill: parent + onClicked: { + console.log("Capture Clicked"); + var a2dArray = new Array(6) + a2dArray[0] = eventstofirefrom1.text; + a2dArray[1] = eventstofirefrom2.text; + a2dArray[2] = eventstofirefrom3.text; + a2dArray[3] = eventstofirefrom4.text; + a2dArray[4] = eventstofirefrom5.text; + a2dArray[5] = eventstofirefrom6.text; + var a2dArray2 = new Array(6) + a2dArray2[0] = sourcetext1.text; + a2dArray2[1] = sourcetext2.text; + a2dArray2[2] = sourcetext3.text; + a2dArray2[3] = sourcetext4.text; + a2dArray2[4] = sourcetext5.text; + a2dArray2[5] = sourcetext6.text; + emscomms.startBenchTest(eventspercycletext.text,numberofcyclestext.text,tickspereventtext.text,a2dArray,a2dArray2); + } + } + } + } + } + Rectangle { + x:210 + y:550 + width:200 + height:30 + radius:5 + color:"white" + Rectangle { + x:5 + y:5 + width:190 + height:20 + radius:5 + color: "blue" + Text { + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: "Stop" + MouseArea { + anchors.fill: parent + onClicked: { + emscomms.stopBenchTest(); + } + } + } + } + } + Rectangle { + x:440 + y:550 + width:100 + height:30 + radius:5 + color:"white" + Rectangle { + x:5 + y:5 + width:90 + height:20 + radius:5 + color: "blue" + Text { + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: "Bump" + MouseArea { + anchors.fill: parent + onClicked: { + emscomms.bumpBenchTest(benchtestbumpvaltext.text); + } + } + } + } + } + Rectangle { + x:560 + y:550 + width:100 + height:30 + color:"white" + Rectangle { + x:2 + y:2 + width:96 + height:26 + color:"grey" + TextEdit { + id: benchtestbumpvaltext + anchors.fill:parent + color: "white" + text:"50" + } + } + } + } +} diff --git a/core/core.pro b/core/core.pro index 5b09f1a..39cd07b 100644 --- a/core/core.pro +++ b/core/core.pro @@ -63,6 +63,7 @@ unix { target.path = /usr/bin dashboard.path = /usr/share/EMStudio/dashboards dashboard.files += src/gauges.qml + dashboard.files += Wizards/BenchTest.qml config.path = /usr/share/EMStudio/definitions config.files += freeems.config.json INSTALLS += target config dashboard @@ -176,4 +177,4 @@ FORMS += src/mainwindow.ui \ SUBDIRS += plugins OTHER_FILES += \ README.md \ - wizard.qml + Wizards/BenchTest.qml diff --git a/core/src/mainwindow.cpp b/core/src/mainwindow.cpp index bc5aefb..c362d9e 100644 --- a/core/src/mainwindow.cpp +++ b/core/src/mainwindow.cpp @@ -1562,7 +1562,7 @@ void MainWindow::emsCommsConnected() } view->setFile(emsComms,wizards.absoluteFilePath(file)); view->passConfig(m_memoryMetaData->configMetaData()); - view->setGeometry(0,0,400,300); + view->setGeometry(0,0,800,600); QAction *action = new QAction(this); action->setText(file.mid(0,file.lastIndexOf("."))); action->setCheckable(true); @@ -1635,6 +1635,21 @@ void MainWindow::interrogationComplete() { emsMdiWindow->show(); } + QList list; + QList list2; + list.append(0); + list.append(2); + list.append(4); + list.append(6); + list.append(8); + list.append(10); + list2.append(50000); + list2.append(50000); + list2.append(50000); + list2.append(50000); + list2.append(50000); + list2.append(50000); + //emsComms->startBenchTest(12,4000,10000,list,list2); } void MainWindow::interrogateTaskStart(QString task, int sequence) { diff --git a/lib/core/emscomms.h b/lib/core/emscomms.h index 5fe2238..071eda9 100644 --- a/lib/core/emscomms.h +++ b/lib/core/emscomms.h @@ -99,6 +99,9 @@ class EmsComms : public QThread virtual int getLocationIdList(unsigned char listtype, unsigned short listmask)=0; virtual int softReset()=0; virtual int hardReset()=0; + virtual int Q_INVOKABLE startBenchTest(unsigned char eventspercycle,unsigned short numcycles,unsigned short ticksperevent,QVariantList pineventmask,QVariantList pinmode)=0; + virtual int Q_INVOKABLE stopBenchTest()=0; + virtual int Q_INVOKABLE bumpBenchTest(unsigned char cyclenum)=0; virtual bool sendSimplePacket(unsigned short payload)=0; virtual void connectSerial(QString port,int baud)=0; virtual void disconnectSerial()=0; diff --git a/plugins/freeems/freeemscomms.cpp b/plugins/freeems/freeemscomms.cpp index 1e08112..5b23863 100644 --- a/plugins/freeems/freeemscomms.cpp +++ b/plugins/freeems/freeemscomms.cpp @@ -637,6 +637,54 @@ int FreeEmsComms::echoPacket(QByteArray packet) m_reqListMutex.unlock(); return m_sequenceNumber-1; } +int FreeEmsComms::startBenchTest(unsigned char eventspercycle,unsigned short numcycles,unsigned short ticksperevent,QVariantList pineventmask,QVariantList pinmode) +{ + m_reqListMutex.lock(); + RequestClass req; + req.type = BENCHTEST; + req.addArg(0x01,sizeof(char)); + req.addArg(eventspercycle,sizeof(eventspercycle)); + req.addArg(numcycles,sizeof(numcycles)); + req.addArg(ticksperevent,sizeof(ticksperevent)); + for (int i=0;i arglist,Q header.append((char)((payloadid) & 0xFF)); } QLOG_TRACE() << "About to send packet"; - if (serialPort->writeBytes(generatePacket(header,payload)) < 0) + if (serialPort->writeBytes(generatePacket(header,payload)) < 0) { return false; } - QLOG_TRACE() << "Sent packet" << "0x" + QString::number(payloadid,16).toUpper(); + QLOG_TRACE() << "Sent packet" << "0x" + QString::number(payloadid,16).toUpper() << header.size() << payload.size(); emit packetSent(payloadid,header,payload); return true; } @@ -1325,6 +1373,24 @@ void FreeEmsComms::run() } m_waitingInfoMutex.unlock(); } + else if (m_threadReqList[i].type == BENCHTEST) + { + m_waitingInfoMutex.lock(); + if (!m_waitingForResponse) + { + m_waitingForResponse = true; + m_timeoutMsecs = QDateTime::currentDateTime().currentMSecsSinceEpoch(); + m_currentWaitingRequest = m_threadReqList[i]; + m_payloadWaitingForResponse = BENCHTEST; + if (!sendPacket(m_threadReqList[i],true)) + { + QLOG_FATAL() << "Error writing packet. Quitting thread"; + return; + } + m_threadReqList.removeAt(i); + } + m_waitingInfoMutex.unlock(); + } else if (m_threadReqList[i].type == SOFT_RESET) { m_waitingInfoMutex.lock(); diff --git a/plugins/freeems/freeemscomms.h b/plugins/freeems/freeemscomms.h index 7d82b59..38430f4 100644 --- a/plugins/freeems/freeemscomms.h +++ b/plugins/freeems/freeemscomms.h @@ -69,6 +69,9 @@ class FreeEmsComms : public EmsComms int getCompilerVersion(); int getOperatingSystem(); int echoPacket(QByteArray packet); + Q_INVOKABLE int startBenchTest(unsigned char eventspercycle,unsigned short numcycles,unsigned short ticksperevent,QVariantList pineventmask,QVariantList pinmode); + Q_INVOKABLE int stopBenchTest(); + Q_INVOKABLE int bumpBenchTest(unsigned char cyclenum); int getLocationIdList(unsigned char listtype, unsigned short listmask); int softReset(); int hardReset(); diff --git a/plugins/freeems/packet.h b/plugins/freeems/packet.h index 5ef29b9..d047e90 100644 --- a/plugins/freeems/packet.h +++ b/plugins/freeems/packet.h @@ -33,6 +33,7 @@ enum RequestType RETRIEVE_BLOCK_IN_RAM=0x0104, RETRIEVE_BLOCK_IN_FLASH=0x0106, BURN_BLOCK_FROM_RAM_TO_FLASH=0x0108, + BENCHTEST=0x8888, GET_LOCATION_ID_LIST=0xDA5E, GET_DECODER_NAME=0xEEEE, GET_FIRMWARE_BUILD_DATE=0xEEF0, diff --git a/plugins/freeems/packetdecoder.cpp b/plugins/freeems/packetdecoder.cpp index f8b6f5c..54d8474 100644 --- a/plugins/freeems/packetdecoder.cpp +++ b/plugins/freeems/packetdecoder.cpp @@ -430,8 +430,8 @@ void PacketDecoder::parsePacket(Packet parsedPacket) { if (parsedPacket.isNAK) { - unsigned short errornum = parsedPacket.payload[0] << 8; - errornum += parsedPacket.payload[1]; + unsigned short errornum = ((unsigned char)parsedPacket.payload[0]) << 8; + errornum += ((unsigned char)parsedPacket.payload[1]); emit packetNaked(payloadid,parsedPacket.header,parsedPacket.payload,errornum); return; }