danadak
Thanks so much,
one last question,
1. How do I detect a video frame, is it when CS1,CS2,RD/WR is all low?
2. I don't know the commands forehand ? I should note them on a paper ?
This is my approach with comments
C:
void processCommandStream(uint8_t* data, size_t dataSize) {
State currentState = STATE_IDLE;
uint8_t currentCommand = 0;
uint8_t* currentData = NULL;
size_t currentDataSize = 0;
for (size_t i = 0; i < dataSize; ++i) {
switch (currentState) {
case STATE_IDLE:
// Look for the start of a command
if (data[i] == COMMAND_A || data[i] == COMMAND_B) {
currentCommand = data[i];
currentState = STATE_COMMAND_DETECTION;
}
break;
case STATE_COMMAND_DETECTION:
// Detect the command and transition to data gathering mode
currentData = &data[i];
currentDataSize = 0;
currentState = STATE_DATA_GATHERING;
break;
case STATE_DATA_GATHERING:
// Continue gathering data until the end of the frame or a new command is detected
currentDataSize++;
if (i + 1 == dataSize || data[i + 1] == COMMAND_A || data[i + 1] == COMMAND_B) {
// Process the command with the gathered data
processCommand(currentCommand, currentData, currentDataSize);
currentState = STATE_IDLE;
}
break;
}
}
}