Better handling of live chunk receives in comms

This commit is contained in:
Josh Stewart 2017-10-08 11:07:49 +11:00
parent ef89229e27
commit 9af5534de4
2 changed files with 13 additions and 8 deletions

View File

@ -21,7 +21,7 @@ byte currentCommand;
bool cmdPending = false;
bool chunkPending = false;
uint16_t chunkComplete = 0;
int16_t chunkSize = 0;
uint16_t chunkSize = 0;
byte cmdGroup = 0;
byte cmdValue = 0;
int cmdCombined = 0; //the cmdgroup as high byte and cmdvalue as low byte

View File

@ -243,15 +243,20 @@ void command()
length2 = Serial.read(); // Length to be written (Should always be 1)
chunkSize = word(length2, length1);
//chunkPending = true;
for(int i = 0; i < chunkSize; i++)
{
while(Serial.available() == 0) { } //For chunk writes, we can safely loop here
receiveValue( (valueOffset + i), Serial.read());
}
cmdPending = false;
chunkPending = true;
chunkComplete = 0;
}
}
//This CANNOT be an else of the above if statement as chunkPending gets set to true above
if(chunkPending == true)
{
while( (Serial.available() > 0) && (chunkComplete < chunkSize) )
{
receiveValue( (valueOffset + chunkComplete), Serial.read());
chunkComplete++;
}
if(chunkComplete >= chunkSize) { cmdPending = false; chunkPending = false; }
}
break;
case 'Z': //Totally non-standard testing function. Will be removed once calibration testing is completed. This function takes 1.5kb of program space! :S