Flush FIFO finally works

This commit is contained in:
meepingsnesroms
2018-05-29 14:46:39 -07:00
parent bf9c55db66
commit 1655da847f
6 changed files with 26 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.6.1, 2018-05-29T11:40:09. -->
<!-- Written by QtCreator 4.6.1, 2018-05-29T14:46:07. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@@ -2,7 +2,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <stdexcept>
@@ -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;
}

View File

@@ -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();

View File

@@ -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')

View File

@@ -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");

View File

@@ -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());
}