Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

###Still problematic###

Still problematic

The code still has the following issues:

  1. newVal is set but not used:
 while(value == 97 && counter < 3)

should be:

 while(newVal == 97 && counter < 3)
  1. Assuming the byte stream follows the protocol, address() will eat the first byte of the message. In other words, the byte following the 97 97 97 header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.

  2. 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:

  1. newVal is set but not used:
 while(value == 97 && counter < 3)

should be:

 while(newVal == 97 && counter < 3)
  1. Assuming the byte stream follows the protocol, address() will eat the first byte of the message. In other words, the byte following the 97 97 97 header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.

  2. 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:

  1. newVal is set but not used:
 while(value == 97 && counter < 3)

should be:

 while(newVal == 97 && counter < 3)
  1. Assuming the byte stream follows the protocol, address() will eat the first byte of the message. In other words, the byte following the 97 97 97 header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.

  2. 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);
}
added 596 characters in body
Source Link
JS1
  • 28.9k
  • 3
  • 41
  • 83

###Still problematic###

The code still has the following issues:

  1. newVal is set but not used:
 while(value == 97 && counter < 3)

should be:

 while(newVal == 97 && counter < 3)
  1. Assuming the byte stream follows the protocol, address() will eat the first byte of the message. In other words, the byte following the 97 97 97 header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.

  2. 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:

  1. newVal is set but not used:
 while(value == 97 && counter < 3)

should be:

 while(newVal == 97 && counter < 3)
  1. Assuming the byte stream follows the protocol, address() will eat the first byte of the message. In other words, the byte following the 97 97 97 header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.

  2. 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:

  1. newVal is set but not used:
 while(value == 97 && counter < 3)

should be:

 while(newVal == 97 && counter < 3)
  1. Assuming the byte stream follows the protocol, address() will eat the first byte of the message. In other words, the byte following the 97 97 97 header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.

  2. 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);
}
Source Link
JS1
  • 28.9k
  • 3
  • 41
  • 83

###Still problematic###

The code still has the following issues:

  1. newVal is set but not used:
 while(value == 97 && counter < 3)

should be:

 while(newVal == 97 && counter < 3)
  1. Assuming the byte stream follows the protocol, address() will eat the first byte of the message. In other words, the byte following the 97 97 97 header will be discarded. This will in turn cause the message processor to eat one byte of the next address section.

  2. 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.

lang-c

AltStyle によって変換されたページ (->オリジナル) /