From 1655da847ff7ab4d23e01d06161abdfbec8fbabf Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Tue, 29 May 2018 14:46:39 -0700 Subject: [PATCH] Flush FIFO finally works --- localTester/LocalTester/LocalTester.pro.user | 2 +- localTester/LocalTester/serialportio.cpp | 13 +++++++++---- localTester/LocalTester/serialportio.h | 1 + localTester/dependencyBlob.js | 10 ++-------- localTester/jsTests/relayFromSerialPort.js | 17 ++++++----------- localTester/jsTests/testerTest.js | 15 +++++++-------- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/localTester/LocalTester/LocalTester.pro.user b/localTester/LocalTester/LocalTester.pro.user index 8502bb7..bc060d5 100644 --- a/localTester/LocalTester/LocalTester.pro.user +++ b/localTester/LocalTester/LocalTester.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/localTester/LocalTester/serialportio.cpp b/localTester/LocalTester/serialportio.cpp index 7202c0b..f1591ed 100644 --- a/localTester/LocalTester/serialportio.cpp +++ b/localTester/LocalTester/serialportio.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -12,7 +11,7 @@ SerialPortIO::SerialPortIO(QString serialDeviceFilePath) : QObject(nullptr){ deviceFilePath = serialDeviceFilePath; - deviceFile = open(serialDeviceFilePath.toStdString().c_str(), O_RDWR | O_NOCTTY); + deviceFile = open(serialDeviceFilePath.toStdString().c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); if(deviceFile < 0) throw std::invalid_argument("Cant open file!"); } @@ -28,13 +27,19 @@ unsigned int SerialPortIO::bytesAvailable(){ return bytes; } +void SerialPortIO::flushFifo(){ + uint8_t data; + while(bytesAvailable()) + read(deviceFile, &data, 1); +} + void SerialPortIO::transmitUint8(unsigned int data){ uint8_t realData = data; - send(deviceFile, &realData, 1, MSG_DONTWAIT); + write(deviceFile, &realData, 1); } unsigned int SerialPortIO::receiveUint8(){ uint8_t data = 0x00; - recv(deviceFile, &data, 1, MSG_DONTWAIT); + read(deviceFile, &data, 1); return data; } diff --git a/localTester/LocalTester/serialportio.h b/localTester/LocalTester/serialportio.h index f94db71..e84f6c2 100644 --- a/localTester/LocalTester/serialportio.h +++ b/localTester/LocalTester/serialportio.h @@ -15,6 +15,7 @@ public: ~SerialPortIO(); Q_INVOKABLE unsigned int bytesAvailable(); + Q_INVOKABLE void flushFifo(); Q_INVOKABLE void transmitUint8(unsigned int data); Q_INVOKABLE unsigned int receiveUint8(); diff --git a/localTester/dependencyBlob.js b/localTester/dependencyBlob.js index 9cf1942..4436c5d 100644 --- a/localTester/dependencyBlob.js +++ b/localTester/dependencyBlob.js @@ -1197,6 +1197,7 @@ jsSystem.validDependencyBlob = function (version){ return false; } +/* serialPort.receiveBuffer = function (size){ var array = [0]; @@ -1205,14 +1206,7 @@ serialPort.receiveBuffer = function (size){ return array; } - -serialPort.flushFifo = function (){ - var buffer = [0]; - var size = serialPort.bytesAvailable(); - userIo.writeStringJs("Type of size:" + typeof size); - jsSystem.uSleep(16666 * 2); - serialPort.receiveBuffer(buffer, size); -} +*/ function isAlphanumeric(char){ if(typeof char === 'string') diff --git a/localTester/jsTests/relayFromSerialPort.js b/localTester/jsTests/relayFromSerialPort.js index 56fec0c..2cd727c 100644 --- a/localTester/jsTests/relayFromSerialPort.js +++ b/localTester/jsTests/relayFromSerialPort.js @@ -2,26 +2,21 @@ function main(args){ //copy 100 chars from the serial port to user output userIo.writeStringJs("Started, wating on serial port"); var string = ""; - //userIo.writeStringJs("Type of serialPort:" + typeof serialPort); - //userIo.writeStringJs(trapNameFromNumber[0xA474].toString()); - //userIo.writeStringJs("Type of serialPort.flushFifo:" + typeof serialPort.flushFifo); - //serialPort.flushFifo = 2; - //userIo.writeStringJs("Type of serialPort.flushFifo:" + typeof serialPort.flushFifo); userIo.writeStringJs("Blob is valid:" + jsSystem.validDependencyBlob(1.0).toString()); userIo.writeStringJs("Bytes in FIFO before flush:" + serialPort.bytesAvailable().toString()); serialPort.flushFifo(); userIo.writeStringJs("Bytes in FIFO after flush:" + serialPort.bytesAvailable().toString()); - for(var count = 0; count < 10000; count++){ - //if(serialPort.bytesAvailable() > 0){ + for(var count = 0; count < 100; count++){ + if(serialPort.bytesAvailable() > 0){ var letter = String.fromCharCode(serialPort.receiveUint8()); if(isAlphanumeric(letter)) string += letter; else string += " "; - //} - //else{ - // jsSystem.uSleep(16666); - //} + } + else{ + jsSystem.uSleep(16666); + } } userIo.writeStringJs(string); userIo.writeStringJs("Ended"); diff --git a/localTester/jsTests/testerTest.js b/localTester/jsTests/testerTest.js index a3e56ff..8a7c39e 100644 --- a/localTester/jsTests/testerTest.js +++ b/localTester/jsTests/testerTest.js @@ -9,17 +9,16 @@ function useFramebuffer(){ function main(args){ userIo.writeStringJs("Test Input Required"); - //jsSystem.testJsAttachment("DPRK is best Korea!"); - //jsSystem.uSleep(16666); while(!userIo.stringAvailableJs()) jsSystem.uSleep(16666); var inputTest = userIo.readStringJs(); userIo.writeStringJs("Test Input Received"); - if(typeof irdaCommands.IRDA_COMMAND_GET_BYTE == 'undefined'){ - userIo.writeStringJs("Not A Value"); + if(typeof irdaCommands == 'undefined'){ + userIo.writeStringJs("Dependency blob is missing!"); + } + else{ + useFramebuffer(); + var num = irdaCommands.IRDA_COMMAND_GET_BYTE; + userIo.writeStringJs(inputTest + num.toString()); } - useFramebuffer(); - var num = irdaCommands.IRDA_COMMAND_GET_BYTE; - userIo.writeStringJs(inputTest + num.toString()); - }