It's easier to follow if you indent it properly. I'll do that, and add comments as I go:
void loop() {
if ( Serial.available() > 0 ) { // If there is something in the serial RX buffer
static char input[inputLength]; // Create a working string to store data in
static uint16_t i; // This is the current index in that working string
char c = Serial.read(); // Read the next character from serial
if ( c != '\n') // If it's not a "line feed" character...
input[i++] = c; // then store it in the input string and increment i
else { // Otherwise...
input[i] = '\0'; // Terminate the string with a NULL to make it valid C
i = 0; // Reset the index to 0 ready for next time
uint16_t array[80]; // Create an 80-int array (temporary)
uint16_t j = 0; // And an index variable
if ( !strncmp(input, "SEND", 4) ) { // If the string starts with SEND
char* p = input + 4; // create a "pointer" to the string that starts 4 characters in
while ( (p = strchr(p, ' ')) != NULL ) // While there is a space somewhere in the string
array[j++] = strtol(p, &p, 16); // convert the first portion to a number, store it in the array, and advance the pointer to the next space.
ir_start(array); // Send the array through IR
Serial.println("WURKS"); // Tell us it worked
}
}
}
}
So you see it receives data through serial and stores it, byte by byte, in input
until it receives \n
at which point it looks to see if it starts with SEND
, then effectively "cuts off" the SEND by only considering everything after the SEND. Then it slices the remainder of the string up by looking for the next space each time and convert each portion to an integer which it stores in an array.
It then sends that array.