This question is a follow up from my previous question.
I am working with some wireless communication in Arduino.
979797 is the address of the transmitter. I have written the following code to check the address first before processing the data. My main concern is speed of computation.
void printBuffer(const uint8_t *serialBuffer)
{
//print contents of buffer
for (int i = 0; i<100; i++)
Serial.println(serialBuffer[i]); //remove the print in binary option to decode
}
void processBytes(const uint8_t value)
{
static uint8_t serialBuffer[bufferSize]; //buffer to hold values
static unsigned int startPosition=0;
if(startPosition < bufferSize)
{
serialBuffer[startPosition] = value;
startPosition++;
}
else
{
printBuffer(serialBuffer);
startPosition = 0;
}
}//end of processBytes
void loop() {
//check if data is available in serial buffer
while(RX.available())
{
//check for start key
address(RX.read())
//process data
for(int i = 0; i< 68; i++)
processBytes(RX.read());
}
}
void address(const uint8_t value)
{
int counter = 0;
int newVal = value;
while(value == 97 && counter < 3)
{
counter++;
newVal = RX.read();
}
}
The data packet just has the following components: start key (979797) and 68 bytes of data(payload). There is no termination key. Also, the transmitter transmits one byte at a time. Thus, each value received is less than 256. Hence why I am saving the data into a uint8_t[] array.
Example of possible data:
97 97 97 (68 bytes of random positive integers all less than 256) 97 97 97
Other than the address()
method, most of it was borrowed from Gammon. Here is the reference page for the arduino commands I am using. Are there ways I can optimize this computation?