###Still problematic###
Still problematic
The code still has the following issues:
newVal
is set but not used:
while(value == 97 && counter < 3)
should be:
while(newVal == 97 && counter < 3)
Assuming the byte stream follows the protocol,
address()
will eat the first byte of the message. In other words, the byte following the97 97 97
header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.There is no recovery mechanism for if the byte stream stops following the protocol. The
address()
function doesn't look for a header, it just returns in the absence of a header.
###Rewrite###
Rewrite
I suggest this rewrite:
void loop(void)
{
// Check if data is available in serial buffer
while (RX.available()) {
// Search for start key
FindStartKey();
// Process data
for(int i = 0; i < 68; i++)
processBytes(RX.read());
}
}
void FindStartKey(void)
{
int counter = 0;
do {
if (RX.read() == 97)
counter++;
else
counter = 0;
} while (counter < 3);
}
###Still problematic###
The code still has the following issues:
newVal
is set but not used:
while(value == 97 && counter < 3)
should be:
while(newVal == 97 && counter < 3)
Assuming the byte stream follows the protocol,
address()
will eat the first byte of the message. In other words, the byte following the97 97 97
header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.There is no recovery mechanism for if the byte stream stops following the protocol. The
address()
function doesn't look for a header, it just returns in the absence of a header.
###Rewrite###
I suggest this rewrite:
void loop(void)
{
// Check if data is available in serial buffer
while (RX.available()) {
// Search for start key
FindStartKey();
// Process data
for(int i = 0; i < 68; i++)
processBytes(RX.read());
}
}
void FindStartKey(void)
{
int counter = 0;
do {
if (RX.read() == 97)
counter++;
else
counter = 0;
} while (counter < 3);
}
Still problematic
The code still has the following issues:
newVal
is set but not used:
while(value == 97 && counter < 3)
should be:
while(newVal == 97 && counter < 3)
Assuming the byte stream follows the protocol,
address()
will eat the first byte of the message. In other words, the byte following the97 97 97
header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.There is no recovery mechanism for if the byte stream stops following the protocol. The
address()
function doesn't look for a header, it just returns in the absence of a header.
Rewrite
I suggest this rewrite:
void loop(void)
{
// Check if data is available in serial buffer
while (RX.available()) {
// Search for start key
FindStartKey();
// Process data
for(int i = 0; i < 68; i++)
processBytes(RX.read());
}
}
void FindStartKey(void)
{
int counter = 0;
do {
if (RX.read() == 97)
counter++;
else
counter = 0;
} while (counter < 3);
}
###Still problematic###
The code still has the following issues:
newVal
is set but not used:
while(value == 97 && counter < 3)
should be:
while(newVal == 97 && counter < 3)
Assuming the byte stream follows the protocol,
address()
will eat the first byte of the message. In other words, the byte following the97 97 97
header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.There is no recovery mechanism for if the byte stream stops following the protocol. The
address()
function doesn't look for a header, it just returns in the absence of a header.
###Rewrite###
I suggest this rewrite:
void loop(void)
{
// Check if data is available in serial buffer
while (RX.available()) {
// Search for start key
FindStartKey();
// Process data
for(int i = 0; i < 68; i++)
processBytes(RX.read());
}
}
void FindStartKey(void)
{
int counter = 0;
do {
if (RX.read() == 97)
counter++;
else
counter = 0;
} while (counter < 3);
}
###Still problematic###
The code still has the following issues:
newVal
is set but not used:
while(value == 97 && counter < 3)
should be:
while(newVal == 97 && counter < 3)
Assuming the byte stream follows the protocol,
address()
will eat the first byte of the message. In other words, the byte following the97 97 97
header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.There is no recovery mechanism for if the byte stream stops following the protocol. The
address()
function doesn't look for a header, it just returns in the absence of a header.
###Still problematic###
The code still has the following issues:
newVal
is set but not used:
while(value == 97 && counter < 3)
should be:
while(newVal == 97 && counter < 3)
Assuming the byte stream follows the protocol,
address()
will eat the first byte of the message. In other words, the byte following the97 97 97
header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.There is no recovery mechanism for if the byte stream stops following the protocol. The
address()
function doesn't look for a header, it just returns in the absence of a header.
###Rewrite###
I suggest this rewrite:
void loop(void)
{
// Check if data is available in serial buffer
while (RX.available()) {
// Search for start key
FindStartKey();
// Process data
for(int i = 0; i < 68; i++)
processBytes(RX.read());
}
}
void FindStartKey(void)
{
int counter = 0;
do {
if (RX.read() == 97)
counter++;
else
counter = 0;
} while (counter < 3);
}
###Still problematic###
The code still has the following issues:
newVal
is set but not used:
while(value == 97 && counter < 3)
should be:
while(newVal == 97 && counter < 3)
Assuming the byte stream follows the protocol,
address()
will eat the first byte of the message. In other words, the byte following the97 97 97
header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.There is no recovery mechanism for if the byte stream stops following the protocol. The
address()
function doesn't look for a header, it just returns in the absence of a header.