//********************************************************************** // // get a value from MonkeyBoard // send a command in CMD_Bytes[] with length of CMD_Count // read up to 4 bytes into an unsigend long returm variable // returns System Status or // Command Status // loop Response_Loops times to avoid time outs // wait Response_Delay ms beteewn loops // //********************************************************************** // void Monkey_Value_Response( unsigned long &Response_Value, boolean &Response_Status, boolean &System_Status, byte Response_Loops, byte Response_Delay, byte CMD_Count, byte CMD_Bytes[], boolean Response_Debug ) // { unsigned int CMD_Index = 0; boolean Start_Response = false; boolean End_Response = false; unsigned int Response_Count = 0; unsigned int Response_Index = 0; byte Response_Character = 0; byte Response_Data_Bytes[19]; // 7 return bytes and up to 11 data bytes ( system commands may have up to 11 ) union Value_4_Bytes { unsigned long Response_Data; byte Data_Bytes[4]; }; Value_4_Bytes Return_4_Data_Bytes; // // initialize variables // CMD_Index = 0; Response_Count = 0; Response_Index = 0; Response_Value = 0; Response_Status = false; System_Status = false; Start_Response = false; End_Response = false; // // send command to MonkeyBoard // Serial1.write( START_CMD); // for ( CMD_Index = 0; CMD_Index < CMD_Count; CMD_Index ++) { Serial1.write( CMD_Bytes[ CMD_Index]); delay( 1); } Serial1.write( END_CMD ); // if ( Response_Debug == true ) { Serial.print ( " " ); for ( CMD_Index = 0; CMD_Index < CMD_Count; CMD_Index ++) { Serial.print ( CMD_Bytes[ CMD_Index], HEX ); Serial.print ( " " ); } Serial.println ( "" ); } // // get response, wait Response_Delay msec and try Response_loops time // CMD_Index = 0; Return_4_Data_Bytes.Response_Data = 0; do { // // clear loop values // End_Response = false; Start_Response = false; for ( Response_Index = 0; Response_Index < 19; Response_Index++) Response_Data_Bytes[ Response_Index ] = 0x00; Response_Index = 0; // // CMD_Index ++; while (Serial1.available()) // { Response_Character = Serial1.read(); if (( Response_Character == START_CMD )) { Response_Index = 0; Start_Response = true; } if (( Response_Character == END_CMD )) { End_Response = true; } if ( Response_Debug == true ) { Serial.print ( Response_Index ); Serial.print ( " " ); Serial.println( Response_Character, HEX ); } if ( Response_Index < 19 ) { Response_Data_Bytes[ Response_Index ] = Response_Character; Response_Index ++; } } if ( Response_Debug == true ) { Serial.print ( Response_Loops ); Serial.print ( " " ); Serial.print ( CMD_Index ); Serial.print ( " " ); Serial.print ( Start_Response ); Serial.print ( " " ); Serial.println( End_Response ); } if ( CMD_Index > Response_Loops ) // // force end condition // { Start_Response = true; End_Response = true; } delay( Response_Delay ); } while (( Start_Response == false ) || ( End_Response == false ));