The code is difficult to debug because loop is too big to see the wood from the trees. One problem was that the compiler was getting confused because there were some brackets in the wrong place .
I suggest you move the functionality to check the incoming data into a separate function as per the example below.
The code used a single equals sign to test for equality, in C you use a double equal sign.
if(a=b) will always return true, it sets a equal to b
if(a== b) is what you want.
//serial handler
//dnear1
//june 12 2008
char RX[13];
char nextbyte;
boolean lostbyte;
void setup() {
Serial.begin(9600);
lostbyte=false;
}
void checkBytes(int numbytes) {
int temp;
// code to check bytes needs to be added here
// note that this could return a boolean value if you need to break out of your do loop as a result of calculations here
// remember that a check for equality is: if(a==b) not: if(a=b);
}
void loop() {
if(Serial.available() > 0) {
char temp;
char numbytes;
//my protocol is going to be 20 bb cc (xx xx xx) cs <- you had a brace here !!
//where bb is the number of bytes to be sent,
//cc is s command
//xx is any data being sent and
//cs is the checksum
do
{
if (lostbyte==true)//this may not be the best way to handle it.. <- this was: lostbyte=true!!
{
temp=nextbyte;
lostbyte=false;
//numbytes=RX[13];
}
else
{
temp= Serial.read();
};
numbytes=RX[13];
checkBytes(numbytes);
}
while (Serial.available() > 0);
//now we need to check and/or process incoming commands if a complete command is found.
//process incoming data
} // <- this was missing !!!
}