I'm finding some good success fine tuning and debugging my code for processing the incoming commands for my ESC firmware. I added cout<< statements all over the place to report what is going on step by step so I can walk though the code slowly and make sure its all working in the console. There have been some minor tweaks here and there but the code has been pretty solid overall from the first writeup. I think I'm about half way through the debugging process. I am able to feed into the code example messages to see how it handles message that are cut off by the memory buffer size limits where the message would then loop back around to the start of the buffer for example. Here's a code snippet of how I'm doing that:
if (insertDummyArduinoIncomingCommandDirectlyForTesting == true)
{
/*-*/cout << "plugging in a test case receive buffer command to simulate reading/acting on it\n";
/*-*/system("Pause");
countNum = 0;
while (countNum < 256)
{
receiveBuffer[countNum] = 0;
countNum = countNum + 1;
}
// [ = 91 = 01011011
receiveBuffer[252] = 0;
receiveBuffer[253] = 1;
receiveBuffer[254] = 0;
receiveBuffer[255] = 1;
receiveBuffer[0] = 1;
receiveBuffer[1] = 0;
receiveBuffer[2] = 1;
receiveBuffer[3] = 1;
// F = 70 = 01000110
receiveBuffer[4] = 0;
receiveBuffer[5] = 1;
receiveBuffer[6] = 0;
receiveBuffer[7] = 0;
receiveBuffer[8] = 0;
receiveBuffer[9] = 1;
receiveBuffer[10] = 1;
receiveBuffer[11] = 0;
// ] = 93 = 01011101
receiveBuffer[12] = 0;
receiveBuffer[13] = 1;
receiveBuffer[14] = 0;
receiveBuffer[15] = 1;
receiveBuffer[16] = 1;
receiveBuffer[17] = 1;
receiveBuffer[18] = 0;
receiveBuffer[19] = 1;
}
And my console output is looking like this snippet:
need to grab more bits since we haven't grabbed 8 bits yet
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
need to grab more bits since we haven't grabbed 8 bits yet
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
we grabbed 8 bits now...
and the resulting character is: (int)receivedCharacter: 0...
and the resulting character is: (char)receivedCharacter: ...
Press any key to continue . . .
this was not the opening bracket...
Press any key to continue . . .
receiveBufferReadPosition = 240
Press any key to continue . . .
bufferPositionsCheckedCount = 240
Press any key to continue . . .
seeing if we have an opening bracket for a command from arduino
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
need to grab more bits since we haven't grabbed 8 bits yet
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
need to grab more bits since we haven't grabbed 8 bits yet
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
need to grab more bits since we haven't grabbed 8 bits yet
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
need to grab more bits since we haven't grabbed 8 bits yet
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
need to grab more bits since we haven't grabbed 8 bits yet
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
need to grab more bits since we haven't grabbed 8 bits yet
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
need to grab more bits since we haven't grabbed 8 bits yet
Press any key to continue . . .
grabbing a bit from receive message buffer
Press any key to continue . . .
the bit is: (int)receiveBuffer[receiveBufferCheckPosition]: 0
Press any key to continue . . .
we grabbed 8 bits now...
and the resulting character is: (int)receivedCharacter: 0...
and the resulting character is: (char)receivedCharacter: ...
Press any key to continue . . .
this was not the opening bracket...
Press any key to continue . . .
receiveBufferReadPosition = 241
Press any key to continue . . .
bufferPositionsCheckedCount = 241
Press any key to continue . . .
seeing if we have an opening bracket for a command from arduino
So anyways once I can fully test and validate all exception cases and ensure all the code works 100% perfectly for identifying the incoming commands, then I can test the code that validates the commands and determines what they are asking of the ESC and then I MIGHT test the interrupt handling code that receives the incoming signals for these commands. However, that section is pretty short so most likely has no bugs. So I might simply just do the motor behavioral code at that point which will conclude the coding of the firmware from the ESC side of things. I'd then need to code the arduino to do the sending of these commands to the ESC and debug that. Then at that point I can setup the workflow to get all of this uploaded onto the hardware in preparation for actual hardware tests on the MCUs. So it's moving along little by little here.