Working! Implemented a more reasonable serial reader.

This commit is contained in:
Rob French 2020-06-07 15:26:37 -05:00
parent f588a89ee7
commit 1a1e92a709

View File

@ -832,51 +832,53 @@ void Check_Cat(byte fromType)
static PrefixID readPrefix; static PrefixID readPrefix;
static uint8_t readLength; static uint8_t readLength;
static IOPMessage msg; static IOPMessage msg;
static bool read_in_progress = false;
//Check Serial Port Buffer //Check Serial Port Buffer
if (Serial.available() == 0) if (Serial.available() == 0 && !read_in_progress)
{ {
//Set Buffer Clear status //Set Buffer Clear status
rxBufferCheckCount = 0; //rxBufferCheckCount = 0;
return; return;
} }
// KC4UPR - IOP update: changed this to 6 characters, because we're going to have a // KC4UPR - IOP update: changed this to 6 characters, because we're going to have a
// first character which defines if this is CAT or IOP. // first character which defines if this is CAT or IOP.
else if (Serial.available() < 6) //5) else // if (Serial.available() < 6) //5)
{ {
//First Arrived if (!read_in_progress) {
if (rxBufferCheckCount == 0) byte first = Serial.read();
{ readPrefix = byteToPrefix(first);
readLength = byteToLength(first);
rxBufferCheckCount = Serial.available(); rxBufferCheckCount = Serial.available();
rxBufferArriveTime = millis() + CAT_RECEIVE_TIMEOUT; //Set time for timeout rxBufferArriveTime = millis() + CAT_RECEIVE_TIMEOUT;
}
else if (rxBufferArriveTime < millis()) //timeout
{
//Clear Buffer
for (i = 0; i < Serial.available(); i++)
rxBufferCheckCount = Serial.read();
rxBufferCheckCount = 0; read_in_progress = true;
} }
else if (rxBufferCheckCount < Serial.available()) //increase buffer count, slow arrived
{ if (Serial.available() < readLength) { // not ready to read everything yet (not enough bytes)
rxBufferCheckCount = Serial.available();
rxBufferArriveTime = millis() + CAT_RECEIVE_TIMEOUT; //Set time for timeout if (rxBufferCheckCount < Serial.available()) { // increase buffer count, slow arrival
rxBufferCheckCount = Serial.available();
rxBufferArriveTime = millis() + CAT_RECEIVE_TIMEOUT; // update time for timeout
} else if (rxBufferArriveTime < millis()) { // timeout, so clear buffer
for (i = 0; i < Serial.available(); i++)
rxBufferCheckCount = Serial.read();
rxBufferCheckCount = 0;
read_in_progress = false;
}
return;
}
for (int i = 0; i < readLength; i++) {
CAT_BUFF[i] = Serial.read();
} }
return;
} }
//Arived CAT DATA
// KC4UPR - IOP update - 6 characters; first character determines mode (CAT or IOP)
// Will adjust based on readlength
byte first = Serial.read();
readPrefix = byteToPrefix(first);
readLength = byteToLength(first);
for (int i = 0; i < readLength; i++) {
CAT_BUFF[i] = Serial.read();
}
// KC4UPR: I don't understand why this is here or how/when it will ever get called, but I will leave // KC4UPR: I don't understand why this is here or how/when it will ever get called, but I will leave
// it alone for now. // it alone for now.
if (isProcessCheck_Cat == 1) if (isProcessCheck_Cat == 1)
@ -1013,6 +1015,7 @@ void Check_Cat(byte fromType)
} }
isProcessCheck_Cat = 0; isProcessCheck_Cat = 0;
read_in_progress = false;
} }
void Init_Cat(long baud, int portConfig) void Init_Cat(long baud, int portConfig)